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

use super::local_state::LocalState;

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

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

impl JoshutoCommand for CopyFiles {}

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

impl JoshutoRunnable for CopyFiles {
    fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
        let curr_tab = context.curr_tab_ref();
        if let Some(list) = curr_tab.curr_list_ref() {
            LocalState::repopulate(list)?;
            LocalState::set_file_op(FileOp::Copy);
        }
        Ok(())
    }
}