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/tab_switch.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/tab_switch.rs')
-rw-r--r-- | src/commands/tab_switch.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs index 7e782be..b0102b5 100644 --- a/src/commands/tab_switch.rs +++ b/src/commands/tab_switch.rs @@ -4,6 +4,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::preview; use crate::ui; +use crate::window::JoshutoView; #[derive(Clone, Debug)] pub struct TabSwitch { @@ -18,7 +19,7 @@ impl TabSwitch { "tab_switch" } - pub fn tab_switch(new_index: i32, context: &mut JoshutoContext) { + pub fn tab_switch(new_index: i32, context: &mut JoshutoContext, view: &JoshutoView) { context.curr_tab_index = new_index as usize; let path = &context.curr_tab_ref().curr_path; match env::set_current_dir(path) { @@ -27,17 +28,17 @@ impl TabSwitch { let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); curr_tab.refresh( - &context.views, + view, &context.config_t, &context.username, &context.hostname, ); } - ui::redraw_tab_view(&context.views.tab_win, &context); + ui::redraw_tab_view(&view.tab_win, &context); let curr_tab = &mut context.tabs[context.curr_tab_index]; - preview::preview_file(curr_tab, &context.views, &context.config_t); + preview::preview_file(curr_tab, view, &context.config_t); } - Err(e) => ui::wprint_err(&context.views.left_win, e.to_string().as_str()), + Err(e) => ui::wprint_err(&view.left_win, e.to_string().as_str()), } } } @@ -51,7 +52,7 @@ impl std::fmt::Display for TabSwitch { } impl JoshutoRunnable for TabSwitch { - fn execute(&self, context: &mut JoshutoContext) { + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { let mut new_index = context.curr_tab_index as i32 + self.movement; let tab_len = context.tabs.len() as i32; while new_index < 0 { @@ -60,7 +61,7 @@ impl JoshutoRunnable for TabSwitch { while new_index >= tab_len { new_index -= tab_len; } - Self::tab_switch(new_index, context); + Self::tab_switch(new_index, context, view); ncurses::doupdate(); } } |