1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoError;
use crate::window::JoshutoView;
#[derive(Debug, Clone)]
pub struct SelectFiles {
toggle: bool,
all: bool,
}
impl SelectFiles {
pub fn new(toggle: bool, all: bool) -> Self {
SelectFiles { toggle, all }
}
pub const fn command() -> &'static str {
"select_files"
}
}
impl JoshutoCommand for SelectFiles {}
impl std::fmt::Display for SelectFiles {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(Self::command()).unwrap();
if self.toggle {
f.write_str(" --toggle").unwrap();
}
if self.all {
f.write_str(" --all").unwrap();
}
f.write_str("")
}
}
impl JoshutoRunnable for SelectFiles {
fn execute(
&self,
context: &mut JoshutoContext,
view: &JoshutoView,
) -> Result<(), JoshutoError> {
let curr_tab = &mut context.tabs[context.curr_tab_index];
if self.toggle {
if !self.all {
let curr_list = &mut curr_tab.curr_list;
if let Some(s) = curr_list.get_curr_mut() {
s.set_selected(!s.is_selected());
CursorMoveDown::new(1).execute(context, view)?;
}
} else {
let curr_list = &mut curr_tab.curr_list;
for curr in &mut curr_list.contents {
curr.set_selected(!curr.is_selected());
}
curr_tab.refresh_curr(&view.mid_win, &context.config_t);
ncurses::doupdate();
}
} else if !self.all {
let curr_list = &mut curr_tab.curr_list;
if let Some(s) = curr_list.get_curr_mut() {
s.set_selected(true);
CursorMoveDown::new(1).execute(context, view)?;
}
} else {
let curr_list = &mut curr_tab.curr_list;
for curr in &mut curr_list.contents {
curr.set_selected(true);
}
curr_tab.refresh_curr(&view.mid_win, &context.config_t);
ncurses::doupdate();
}
Ok(())
}
}
|