diff options
Diffstat (limited to 'src')
32 files changed, 599 insertions, 740 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index cd2dcf8..c2e127f 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -7,7 +7,7 @@ use rand::Rng; use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList}; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; #[derive(Clone, Debug)] pub struct BulkRename; @@ -62,8 +62,6 @@ impl BulkRename { let time = std::time::SystemTime::now(); /* exit curses and launch program */ { - ncurses::savetty(); - ncurses::endwin(); let mut handle = command.spawn()?; handle.wait()?; } @@ -121,11 +119,6 @@ impl BulkRename { std::io::stdin().read_line(&mut user_input)?; std::fs::remove_file(file_path)?; - - /* restore ncurses */ - ncurses::resetty(); - ncurses::refresh(); - ncurses::doupdate(); Ok(()) } } @@ -139,12 +132,9 @@ impl std::fmt::Display for BulkRename { } impl JoshutoRunnable for BulkRename { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { Self::bulk_rename(context)?; ReloadDirList::reload(context.curr_tab_index, context)?; - let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.refresh(view, &context.config_t); - ncurses::doupdate(); Ok(()) } } diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index d62964e..48cf901 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -1,10 +1,10 @@ use std::path; -use crate::commands::{JoshutoCommand, JoshutoRunnable}; +use crate::commands::{JoshutoCommand, JoshutoRunnable, LoadChild}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; use crate::history::DirectoryHistory; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; #[derive(Clone, Debug)] pub struct ChangeDirectory { @@ -19,30 +19,27 @@ impl ChangeDirectory { "cd" } - pub fn change_directory( - path: &path::PathBuf, + pub fn cd( + path: &path::Path, context: &mut JoshutoContext, - view: &JoshutoView, ) -> std::io::Result<()> { - std::env::set_current_dir(path.as_path())?; + std::env::set_current_dir(path)?; let curr_tab = &mut context.tabs[context.curr_tab_index]; - let mut curr_list = curr_tab - .history - .pop_or_create(&path, &context.config_t.sort_option)?; + curr_tab.curr_path = path.to_path_buf(); - std::mem::swap(&mut curr_tab.curr_list, &mut curr_list); + Ok(()) + } - curr_tab - .history - .insert(curr_list.file_path().clone(), curr_list); - curr_tab.curr_path = path.clone(); + pub fn change_directories(path: &path::Path, + context: &mut JoshutoContext, + backend: &mut TuiBackend, + ) -> std::io::Result<()> { + Self::cd(path, context)?; - curr_tab - .history - .populate_to_root(path, &context.config_t.sort_option)?; + let curr_tab = &mut context.tabs[context.curr_tab_index]; + curr_tab.history.populate_to_root(&path, &context.config_t.sort_option)?; - curr_tab.refresh(view, &context.config_t); Ok(()) } } @@ -56,9 +53,10 @@ impl std::fmt::Display for ChangeDirectory { } impl JoshutoRunnable for ChangeDirectory { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - Self::change_directory(&self.path, context, view)?; - ncurses::doupdate(); + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + Self::change_directories(&self.path, context, backend)?; + LoadChild::load_child(context, backend); + Ok(()) } } diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs index 4f67ee8..3376f83 100644 --- a/src/commands/command_line.rs +++ b/src/commands/command_line.rs @@ -1,9 +1,9 @@ use crate::commands::{self, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::textfield::JoshutoTextField; +use crate::textfield::TextField; use crate::ui; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; #[derive(Clone, Debug)] pub struct CommandLine { @@ -19,20 +19,13 @@ impl CommandLine { "console" } - pub fn readline(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - const PROMPT: &str = ":"; - let (term_rows, term_cols) = ui::getmaxyx(); - let user_input: Option<String> = { - let textfield = JoshutoTextField::new( - 1, - term_cols, - (term_rows as usize - 1, 0), - PROMPT, - &self.prefix, - &self.suffix, - ); - textfield.readline() - }; + pub fn readline( + &self, + context: &mut JoshutoContext, + backend: &mut TuiBackend, + ) -> JoshutoResult<()> { + // let mut textfield = TextField::new(&mut terminal, &context.events); + let user_input: Option<String> = None; //textfield.readline(); if let Some(s) = user_input { let trimmed = s.trim_start(); @@ -41,11 +34,10 @@ impl CommandLine { let (command, xs) = trimmed.split_at(ind); let xs = xs.trim_start(); let args: Vec<String> = vec![String::from(xs)]; - commands::from_args(String::from(command), args)?.execute(context, view) - } - None => { - commands::from_args(String::from(trimmed), Vec::new())?.execute(context, view) + commands::from_args(String::from(command), args)?.execute(context, backend) } + None => commands::from_args(String::from(trimmed), Vec::new())? + .execute(context, backend), } } else { Ok(()) @@ -62,8 +54,8 @@ impl std::fmt::Display for CommandLine { } impl JoshutoRunnable for CommandLine { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - let res = self.readline(context, view); + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + let res = self.readline(context, backend); ncurses::doupdate(); res } diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index adc7266..5fee941 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -1,34 +1,38 @@ +use std::path::PathBuf; + use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::window::JoshutoView; +use crate::history::DirectoryHistory; +use crate::ui::TuiBackend; -pub fn cursor_move(mut new_index: usize, context: &mut JoshutoContext, view: &JoshutoView) { +pub fn cursor_move(new_index: usize, context: &mut JoshutoContext, backend: &mut TuiBackend) { + let mut new_index = new_index; let curr_tab = &mut context.tabs[context.curr_tab_index]; - match curr_tab.curr_list.index { - None => return, - Some(_) => { - let dir_len = curr_tab.curr_list.contents.len(); - /* - if index == dir_len - 1 { - return; - } - */ + let mut path: Option<PathBuf> = None; + + if let Some(curr_list) = curr_tab.curr_list_mut() { + if let Some(index) = curr_list.index { + let dir_len = curr_list.contents.len(); if new_index >= dir_len { new_index = dir_len - 1; } - curr_tab.curr_list.index = Some(new_index); + curr_list.index = Some(new_index); + + let entry = &curr_list.contents[new_index]; + path = Some(entry.file_path().clone()) } } - curr_tab.refresh_curr(&view.mid_win, &context.config_t); - if context.config_t.show_preview { - curr_tab.refresh_preview(&view.right_win, &context.config_t); + // get preview + if let Some(path) = path { + if path.is_dir() { + curr_tab + .history + .create_or_update(path.as_path(), &context.config_t.sort_option); + } } - curr_tab.refresh_path_status(&view.top_win, &context.config_t); - curr_tab.refresh_file_status(&view.bot_win); - ncurses::doupdate(); } #[derive(Clone, Debug)] @@ -54,13 +58,14 @@ impl std::fmt::Display for CursorMoveDown { } impl JoshutoRunnable for CursorMoveDown { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - let movement: Option<usize> = { - let curr_list = &mut context.curr_tab_mut().curr_list; - curr_list.index.map(|idx| idx + self.movement) + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + let movement = match context.curr_tab_ref().curr_list_ref() { + Some(curr_list) => curr_list.index.map(|idx| idx + self.movement), + None => None, }; + if let Some(s) = movement { - cursor_move(s, context, view) + cursor_move(s, context, backend) } Ok(()) } @@ -89,16 +94,20 @@ impl std::fmt::Display for CursorMoveUp { } impl JoshutoRunnable for CursorMoveUp { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - let movement: Option<usize> = context.curr_tab_mut().curr_list.index.map(|idx| { - if idx > self.movement { - idx - self.movement - } else { - 0 - } - }); + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + let movement = match context.curr_tab_ref().curr_list_ref() { + Some(curr_list) => curr_list.index.map(|idx| { + if idx > self.movement { + idx - self.movement + } else { + 0 + } + }), + None => None, + }; + if let Some(s) = movement { - cursor_move(s, context, view); + cursor_move(s, context, backend) } Ok(()) } @@ -125,16 +134,19 @@ impl std::fmt::Display for CursorMovePageUp { } impl JoshutoRunnable for CursorMovePageUp { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - let movement: Option<usize> = { - let curr_list = &mut context.curr_tab_mut().curr_list; - let half_page = view.mid_win.cols as usize / 2; - curr_list - .index - .map(|x| if x > half_page { x - half_page } else { 0 }) + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + let movement = match context.curr_tab_ref().curr_list_ref() { + Some(curr_list) => { + let half_page = 10; + curr_list + .index + .map(|idx| if idx > half_page { idx - half_page } else { 0 }) + } + None => None, }; + if let Some(s) = movement { - cursor_move(s, context, view); + cursor_move(s, context, backend); } Ok(()) } @@ -161,22 +173,24 @@ impl std::fmt::Display for CursorMovePageDown { } impl JoshutoRunnable for CursorMovePageDown { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - let movement: Option<usize> = { - let curr_list = &mut context.curr_tab_mut().curr_list; - let dir_len = curr_list.contents.len(); - let half_page = view.mid_win.cols as usize / 2; - curr_list.index.map(|x| { - if x + half_page > dir_len - 1 { - dir_len - 1 - } else { - x + half_page - } - }) + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + let movement = match context.curr_tab_ref().curr_list_ref() { + Some(curr_list) => { + let dir_len = curr_list.contents.len(); + let half_page = 10; + curr_list.index.map(|idx| { + if idx + half_page > dir_len - 1 { + dir_len - 1 + } else { + idx + half_page + } + }) + } + None => None, }; if let Some(s) = movement { - cursor_move(s, context, view); + cursor_move(s, context, backend); } Ok(()) } @@ -203,7 +217,7 @@ impl std::fmt::Display for CursorMoveHome { } impl JoshutoRunnable for CursorMoveHome { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { let movement: Option<usize> = { let len = context.curr_tab_mut().curr_list.contents.len(); if len == 0 { @@ -214,7 +228,7 @@ impl JoshutoRunnable for CursorMoveHome { }; if let Some(s) = movement { - cursor_move(s, context, view); + cursor_move(s, context, backend); } Ok(()) } @@ -241,7 +255,7 @@ impl std::fmt::Display for CursorMoveEnd { } impl JoshutoRunnable for CursorMoveEnd { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { let movement: Option<usize> = { let len = context.curr_tab_mut().curr_list.contents.len(); if len == 0 { @@ -252,7 +266,7 @@ impl JoshutoRunnable for CursorMoveEnd { }; if let Some(s) = movement { - cursor_move(s, context, view); + cursor_move(s, context, backend); } Ok(()) } diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index 8233ce2..ed35630 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -4,11 +4,8 @@ use std::path; use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::ui; +use crate::ui::TuiBackend; use crate::util::event::Event; -use crate::window::JoshutoView; - -use crate::KEYMAP_T; #[derive(Clone, Debug)] pub struct DeleteFiles; @@ -34,10 +31,7 @@ impl DeleteFiles { Ok(()) } - fn delete_files(context: &mut JoshutoContext, view: &JoshutoView) -> std::io::Result<()> { - ui::wprint_msg(&view.bot_win, "Delete selected files? (Y/n)"); - ncurses::doupdate(); - + fn delete_files(context: &mut JoshutoContext, backend: &mut TuiBackend) -> std::io::Result<()> { let curr_tab = &mut context.tabs[context.curr_tab_index]; let paths = curr_tab.curr_list.get_selected_paths(); if paths.is_empty() { @@ -51,11 +45,10 @@ impl DeleteFiles { while let Ok(evt) = context.events.next() { match evt { Event::Input(key) => { - if key == termion::event::Key::Char('y') || - key == termion::event::Key::Char('\n') { + if key == termion::event::Key::Char('y') + || key == termion::event::Key::Char('\n') + { if paths.len() > 1 { - ui::wprint_msg(&view.bot_win, "Are you sure? (y/N)"); - ncurses::doupdate(); while let Ok(evt) = context.events.next() { match evt { Event::Input(key) => { @@ -77,7 +70,6 @@ impl DeleteFiles { if ch == termion::event::Key::Char('y') { Self::remove_files(&paths)?; - ui::wprint_msg(&view.bot_win, "Deleted files"); ReloadDirList::reload(context.curr_tab_index, context)?; } Ok(()) @@ -93,16 +85,8 @@ impl std::fmt::Display for DeleteFiles { } impl JoshutoRunnable for DeleteFiles { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - Self::delete_files(context, view)?; - let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.refresh_curr(&view.mid_win, &context.config_t); - if context.config_t.show_preview { - curr_tab.refresh_preview(&view.right_win, &context.config_t); - } - curr_tab.refresh_path_status(&view.top_win, &context.config_t); - curr_tab.refresh_file_status(&view.bot_win); - ncurses::doupdate(); + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + Self::delete_files(context, backend)?; Ok(()) } } diff --git a/src/commands/file_ops/copy.rs b/src/commands/file_ops/copy.rs index a1a562e..2551321 100644 --- a/src/commands/file_ops/copy.rs +++ b/src/commands/file_ops/copy.rs @@ -1,7 +1,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; use super::local_state::{FileOp, LocalState}; @@ -26,7 +26,7 @@ impl std::fmt::Display for CopyFiles { } impl JoshutoRunnable for CopyFiles { - fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let curr_tab = context.curr_tab_ref(); LocalState::repopulated_selected_files(&curr_tab.curr_list)?; LocalState::set_file_op(FileOp::Copy); diff --git a/src/commands/file_ops/cut.rs b/src/commands/file_ops/cut.rs index f466ca7..d77f157 100644 --- a/src/commands/file_ops/cut.rs +++ b/src/commands/file_ops/cut.rs @@ -1,7 +1,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; use super::local_state::{FileOp, LocalState}; @@ -26,7 +26,7 @@ impl std::fmt::Display for CutFiles { } impl JoshutoRunnable for CutFiles { - fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let curr_tab = context.curr_tab_ref(); LocalState::repopulated_selected_files(&curr_tab.curr_list)?; LocalState::set_file_op(FileOp::Cut); diff --git a/src/commands/file_ops/paste.rs b/src/commands/file_ops/paste.rs index ba5dc43..74136c6 100644 --- a/src/commands/file_ops/paste.rs +++ b/src/commands/file_ops/paste.rs @@ -2,7 +2,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; use crate::io::Options; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; use super::local_state::{FileOp, LocalState}; use super::paste_copy::paste_copy; @@ -33,7 +33,7 @@ impl std::fmt::Debug for PasteFiles { } impl JoshutoRunnable for PasteFiles { - fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { let file_operation = LocalState::get_file_operation(); let thread = match file_operation { FileOp::Copy => paste_copy(context, self.options.clone()), diff --git a/src/commands/load_child.rs b/src/commands/load_child.rs new file mode 100644 index 0000000..d70314c --- /dev/null +++ b/src/commands/load_child.rs @@ -0,0 +1,32 @@ +use std::path::PathBuf; + +use crate::commands::{JoshutoCommand, JoshutoRunnable}; +use crate::context::JoshutoContext; +use crate::error::JoshutoResult; +use crate::history::DirectoryHistory; +use crate::ui::TuiBackend; + +pub struct LoadChild {} + +impl LoadChild { + pub fn load_child(context: &mut JoshutoContext, backend: &mut TuiBackend) { + let curr_tab = &mut context.tabs[context.curr_tab_index]; + let mut path: Option<PathBuf> = None; + + if let Some(curr_list) = curr_tab.curr_list_ref() { + if let Some(index) = curr_list.index { + let entry = &curr_list.contents[index]; + path = Some(entry.file_path().clone()) + } + } + + // get preview + if let Some(path) = path { + if path.is_dir() { + curr_tab + .history + .create_or_update(path.as_path(), &context.config_t.sort_option); + } + } + } +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index eecf257..0c395e6 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -4,6 +4,7 @@ mod command_line; mod cursor_move; mod delete_files; mod file_ops; +mod load_child; mod new_directory; mod open_file; mod parent_directory; @@ -26,8 +27,9 @@ pub use self::cursor_move::{ }; pub use self::delete_files::DeleteFiles; pub use self::file_ops::{CopyFiles, CutFiles, PasteFiles}; +pub use self::load_child::LoadChild; pub use self::new_directory::NewDirectory; -pub use self::open_file::{OpenFile, OpenFileWith}; +pub use self::open_file::OpenFile; //, OpenFileWith}; pub use self::parent_directory::ParentDirectory; pub use self::quit::ForceQuit; pub use self::quit::Quit; @@ -46,7 +48,7 @@ use crate::config::JoshutoCommandMapping; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::io::Options; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; use crate::HOME_DIR; @@ -66,7 +68,7 @@ impl std::fmt::Display for CommandKeybind { } pub trait JoshutoRunnable { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()>; + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()>; } pub trait JoshutoCommand: JoshutoRunnable + std::fmt::Display + std::fmt::Debug {} @@ -154,8 +156,11 @@ pub fn from_args(command: String, args: Vec<String>) -> JoshutoResult<Box<dyn Jo } } "new_tab" => Ok(Box::new(self::NewTab::new())), + "open_file" => Ok(Box::new(self::OpenFile::new())), - "open_file_with" => Ok(Box::new(self::OpenFileWith::new())), + /* + "open_file_with" => Ok(Box::new(self::OpenFileWith::new())), + */ "paste_files" => { let mut options = Options::default(); for arg in args { diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs index 3684b0a..2a72c38 100644 --- a/src/commands/new_directory.rs +++ b/src/commands/new_directory.rs @@ -3,7 +3,7 @@ use std::path; use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; -use crate::window::JoshutoView; +use crate::ui::TuiBackend; #[derive(Clone, Debug)] pub struct NewDirectory { @@ -28,14 +28,11 @@ impl std::fmt::Display for NewDirectory { } impl JoshutoRunnable for NewDirectory { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { for path in &self.paths { std::fs::create_dir_all(path)?; } ReloadDirList::reload(context.curr_tab_index, context)?; - let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.refresh(view, &context.config_t); - ncurses::doupdate(); Ok(()) } } diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 60dafe5..a6439cd 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -1,14 +1,13 @@ use std::path::{Path, PathBuf}; -use crate::commands::{JoshutoCommand, JoshutoRunnable}; +use crate::commands::{ChangeDirectory, JoshutoCommand, JoshutoRunnable, LoadChild}; use crate::config::mimetype::JoshutoMimetypeEntry; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::history::DirectoryHistory; -use crate::textfield::JoshutoTextField; -use crate::ui; +use crate::textfield::TextField; +use crate::ui::TuiBackend; use crate::window; -use crate::window::JoshutoView; use crate::MIMETYPE_T; @@ -36,81 +35,30 @@ impl OpenFile { mimetype_options } - fn open(context: &mut JoshutoContext, view: &JoshutoView) -> std::io::Result<()> { - let mut path: Option<PathBuf> = None; - { - let curr_list = &context.tabs[context.curr_tab_index].curr_list; - if let Some(entry) = curr_list.get_curr_ref() { - if entry.file_path().is_dir() { - path = Some(entry.file_path().clone()); + fn open(context: &mut JoshutoContext, backend: &mut TuiBackend) -> std::io::Result<()> { + let mut dirpath = None; + let mut filepaths = None; + + if let Some(curr_list) = context.tabs[context.curr_tab_index].curr_list_ref() { + if let Some(index) = curr_list.index { + let child_path = curr_list.contents[index].file_path(); + if child_path.is_dir() { + dirpath = Some(child_path.clone()); + } else { + filepaths = Some(curr_list.get_selected_paths()); } } } - if let Some(path) = path { - Self::open_directory(&path, context)?; - let curr_tab = &mut context.tabs[context.curr_tab_index]; - if curr_tab.curr_list.need_update() { - curr_tab - .curr_list - .reload_contents(&context.config_t.sort_option)?; - curr_tab - .curr_list - .sort(context.config_t.sort_option.compare_func()); - } - curr_tab.refresh(view, &context.config_t); - } else { - let curr_tab = &context.tabs[context.curr_tab_index]; - let paths = curr_tab.curr_list.get_selected_paths(); - - if paths.is_empty() { - let err = std::io::Error::new(std::io::ErrorKind::NotFound, "No f |