summaryrefslogtreecommitdiffstats
path: root/src/commands/file_ops/cut.rs
blob: 0fcbc0ed4c3aeda052ded25764a6bef612577011 (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
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::{JoshutoContext, LocalStateContext};
use crate::error::JoshutoResult;
use crate::io::FileOp;
use crate::ui::TuiBackend;

#[derive(Clone, Debug)]
pub struct CutFiles;

impl CutFiles {
    pub fn new() -> Self {
        CutFiles
    }
    pub const fn command() -> &'static str {
        "cut_files"
    }
}

impl JoshutoCommand for CutFiles {}

impl std::fmt::Display for CutFiles {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(Self::command())
    }
}

impl JoshutoRunnable for CutFiles {
    fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
        if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() {
            let iter = list
                .iter()
                .filter(|e| e.is_selected())
                .map(|e| e.file_path());

            let mut local_state = LocalStateContext::new();
            local_state.set_paths(iter);
            local_state.set_file_op(FileOp::Cut);

            context.set_local_state(local_state);
        }
        Ok(())
    }
}