mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
cmdsys: delegate handling
This commit is contained in:
parent
9b770c468f
commit
c551f83d5c
6 changed files with 72 additions and 57 deletions
|
|
@ -33,37 +33,31 @@ pub enum ArrangementCommand {
|
|||
GoLeft,
|
||||
GoRight,
|
||||
}
|
||||
|
||||
impl<E: Engine> Command<Arranger<E>> for ArrangerCommand {
|
||||
fn execute (self, state: &mut Arranger<E>) -> Perhaps<Self> {
|
||||
use ArrangerCommand::*;
|
||||
use FocusCommand::*;
|
||||
match self {
|
||||
Focus(command) => match command {
|
||||
Next => { state.focus_next(); },
|
||||
Prev => { state.focus_prev(); },
|
||||
Up => { state.focus_up(); },
|
||||
Down => { state.focus_down(); },
|
||||
Left => { state.focus_left(); },
|
||||
Right => { state.focus_right(); },
|
||||
Enter => { unimplemented!() },
|
||||
Exit => { unimplemented!() },
|
||||
let undo = match self {
|
||||
Self::Focus(cmd) => {
|
||||
delegate(Self::Focus, state, cmd)
|
||||
},
|
||||
Transport(cmd) => if let Some(ref transport) = state.transport {
|
||||
return cmd.execute(&mut*transport.write().unwrap()).map(|x|x.map(Transport))
|
||||
Self::Transport(cmd) => if let Some(ref transport) = state.transport {
|
||||
delegate(Self::Transport, &mut*transport.write().unwrap(), cmd)
|
||||
} else {
|
||||
Ok(None)
|
||||
},
|
||||
Phrases(cmd) => {
|
||||
return cmd.execute(&mut*state.phrases.write().unwrap()).map(|x|x.map(Phrases))
|
||||
Self::Phrases(cmd) => {
|
||||
delegate(Self::Phrases, &mut*state.phrases.write().unwrap(), cmd)
|
||||
},
|
||||
Editor(cmd) => {
|
||||
return cmd.execute(&mut state.editor).map(|x|x.map(Editor))
|
||||
Self::Editor(cmd) => {
|
||||
delegate(Self::Editor, &mut state.editor, cmd)
|
||||
},
|
||||
Arrangement(cmd) => {
|
||||
return cmd.execute(&mut state.arrangement).map(|x|x.map(Arrangement))
|
||||
Self::Arrangement(cmd) => {
|
||||
delegate(Self::Arrangement, &mut state.arrangement, cmd)
|
||||
},
|
||||
}
|
||||
}?;
|
||||
state.show_phrase();
|
||||
state.update_status();
|
||||
Ok(None)
|
||||
return Ok(undo);
|
||||
}
|
||||
}
|
||||
impl<E: Engine> Command<Arrangement<E>> for ArrangementCommand {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue