diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-03-30 15:11:08 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-03-30 15:11:08 -0400 |
commit | 554f06d72aeb639548314336b2318e14f8ffcc7e (patch) | |
tree | 4f3346fdd7b9302ccaa82089cd7eceff4d8b28de /src/commands/mod.rs | |
parent | f56511becd2be285ff2ce74269113384856aaa95 (diff) |
move view struct out of Context and pass in as a separate argument
- rename static variables to all caps
- change index to be Option<usize> rather than i32 where -1 means
the directory is empty
Diffstat (limited to 'src/commands/mod.rs')
-rw-r--r-- | src/commands/mod.rs | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1185d93..7cfa311 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -17,7 +17,8 @@ mod tab_switch; pub use self::change_directory::ChangeDirectory; pub use self::cursor_move::{ - CursorMove, CursorMoveEnd, CursorMoveHome, CursorMovePageDown, CursorMovePageUp, + CursorMove, CursorMoveDec, CursorMoveEnd, CursorMoveHome, CursorMoveInc, CursorMovePageDown, + CursorMovePageUp, }; pub use self::delete_files::DeleteFiles; pub use self::file_operations::{CopyFiles, CutFiles, FileOperationThread, PasteFiles}; @@ -41,6 +42,7 @@ use std::path::PathBuf; use crate::context::JoshutoContext; use crate::structs; +use crate::window::JoshutoView; #[derive(Debug)] pub enum CommandKeybind { @@ -49,7 +51,7 @@ pub enum CommandKeybind { } pub trait JoshutoRunnable { - fn execute(&self, context: &mut JoshutoContext); + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView); } pub trait JoshutoCommand: JoshutoRunnable + std::fmt::Display + std::fmt::Debug {} @@ -89,12 +91,27 @@ pub fn from_args(command: &str, args: Option<&Vec<String>>) -> Option<Box<Joshut } "close_tab" => Some(Box::new(self::CloseTab::new())), "copy_files" => Some(Box::new(self::CopyFiles::new())), - "cursor_move" => { + "cursor_move_inc" => { if let Some(args) = args { if !args.is_empty() { - match args[0].parse::<i32>() { + match args[0].parse::<usize>() { + Ok(s) => { + return Some(Box::new(self::CursorMoveInc::new(s))); + } + Err(e) => { + eprintln!("{}", e); + } + } + } + } + None + } + "cursor_move_dec" => { + if let Some(args) = args { + if !args.is_empty() { + match args[0].parse::<usize>() { Ok(s) => { - return Some(Box::new(self::CursorMove::new(s))); + return Some(Box::new(self::CursorMoveDec::new(s))); } Err(e) => { eprintln!("{}", e); @@ -218,20 +235,21 @@ pub fn from_args(command: &str, args: Option<&Vec<String>>) -> Option<Box<Joshut } pub fn collect_selected_paths(dirlist: &structs::JoshutoDirList) -> Option<Vec<PathBuf>> { - if dirlist.index < 0 { - return None; - } - - let selected: Vec<PathBuf> = dirlist - .contents - .iter() - .filter(|entry| entry.selected) - .map(|entry| entry.path.clone()) - .collect(); - if !selected.is_empty() { - Some(selected) - } else { - Some(vec![dirlist.contents[dirlist.index as usize].path.clone()]) + match dirlist.index { + Some(index) => { + let selected: Vec<PathBuf> = dirlist + .contents + .iter() + .filter(|entry| entry.selected) + .map(|entry| entry.path.clone()) + .collect(); + if !selected.is_empty() { + Some(selected) + } else { + Some(vec![dirlist.contents[index].path.clone()]) + } + } + None => None, } } |