refactor: split cmd.rs
This commit is contained in:
87
src/command/cmd/cell.rs
Normal file
87
src/command/cmd/cell.rs
Normal file
@ -0,0 +1,87 @@
|
||||
use crate::ui::effect::{self, Effect};
|
||||
|
||||
use super::core::{Cmd, CmdContext};
|
||||
|
||||
// ── Cell operations ──────────────────────────────────────────────────────────
|
||||
// All cell commands take an explicit CellKey. The interactive spec fills it
|
||||
// from ctx.cell_key(); the parser fills it from Cat/Item coordinate args.
|
||||
|
||||
/// Clear a cell.
|
||||
#[derive(Debug)]
|
||||
pub struct ClearCellCommand {
|
||||
pub key: crate::model::cell::CellKey,
|
||||
}
|
||||
impl Cmd for ClearCellCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"clear-cell"
|
||||
}
|
||||
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
vec![
|
||||
Box::new(effect::ClearCell(self.key.clone())),
|
||||
effect::mark_dirty(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// Yank (copy) a cell value.
|
||||
#[derive(Debug)]
|
||||
pub struct YankCell {
|
||||
pub key: crate::model::cell::CellKey,
|
||||
}
|
||||
impl Cmd for YankCell {
|
||||
fn name(&self) -> &'static str {
|
||||
"yank"
|
||||
}
|
||||
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
let value = ctx.model.evaluate_aggregated(&self.key, ctx.none_cats());
|
||||
vec![
|
||||
Box::new(effect::SetYanked(value)),
|
||||
effect::set_status("Yanked"),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// Paste the yanked value into a cell.
|
||||
#[derive(Debug)]
|
||||
pub struct PasteCell {
|
||||
pub key: crate::model::cell::CellKey,
|
||||
}
|
||||
impl Cmd for PasteCell {
|
||||
fn name(&self) -> &'static str {
|
||||
"paste"
|
||||
}
|
||||
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
if let Some(value) = ctx.yanked.clone() {
|
||||
vec![
|
||||
Box::new(effect::SetCell(self.key.clone(), value)),
|
||||
effect::mark_dirty(),
|
||||
]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── View commands ────────────────────────────────────────────────────────────
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TransposeAxes;
|
||||
impl Cmd for TransposeAxes {
|
||||
fn name(&self) -> &'static str {
|
||||
"transpose"
|
||||
}
|
||||
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
vec![Box::new(effect::TransposeAxes), effect::mark_dirty()]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SaveCmd;
|
||||
impl Cmd for SaveCmd {
|
||||
fn name(&self) -> &'static str {
|
||||
"save"
|
||||
}
|
||||
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
|
||||
vec![Box::new(effect::Save)]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user