blob: bbb90c2dbc4ff21fc7dd048aef5f3d05a078ca49 (
plain)
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
|
use std::path;
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
use crate::ui::TuiBackend;
use crate::util::load_child::LoadChild;
use crate::util::sort::SortType;
use crate::HOME_DIR;
#[derive(Clone, Debug)]
pub struct Sort {
sort_method: SortType,
}
impl Sort {
pub fn new(sort_method: SortType) -> Self {
Self { sort_method }
}
pub const fn command() -> &'static str {
"sort"
}
}
impl JoshutoCommand for Sort {}
impl std::fmt::Display for Sort {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{} {}", Self::command(), self.sort_method.as_str())
}
}
impl JoshutoRunnable for Sort {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
context.config_t.sort_option.sort_method = self.sort_method;
for tab in context.tabs.iter_mut() {
tab.history.depreciate_all_entries();
}
ReloadDirList::soft_reload(context.curr_tab_index, context)?;
LoadChild::load_child(context)?;
Ok(())
}
}
|