mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
edit command from phrases list
This commit is contained in:
parent
88e5aed2cd
commit
051c3d3663
2 changed files with 27 additions and 22 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone)]
|
||||||
pub enum ArrangerCommand {
|
pub enum ArrangerCommand {
|
||||||
Focus(FocusCommand),
|
Focus(FocusCommand),
|
||||||
Transport(TransportCommand),
|
Transport(TransportCommand),
|
||||||
Phrases(PhrasePoolCommand),
|
Phrases(PhrasePoolCommand),
|
||||||
Editor(PhraseEditorCommand),
|
Editor(PhraseEditorCommand),
|
||||||
Arrangement(ArrangementCommand),
|
Arrangement(ArrangementCommand),
|
||||||
EditPhrase,
|
EditPhrase(Option<Arc<RwLock<Phrase>>>),
|
||||||
}
|
}
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum ArrangementCommand {
|
pub enum ArrangementCommand {
|
||||||
|
|
@ -56,13 +56,11 @@ impl<E: Engine> Command<Arranger<E>> for ArrangerCommand {
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
},
|
},
|
||||||
Self::EditPhrase => if let Some(phrase) = state.arrangement.phrase() {
|
Self::EditPhrase(phrase) => {
|
||||||
state.editor.phrase = Some(phrase.clone());
|
state.editor.phrase = phrase.clone();
|
||||||
state.focus(ArrangerFocus::PhraseEditor);
|
state.focus(ArrangerFocus::PhraseEditor);
|
||||||
state.focus_enter();
|
state.focus_enter();
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
state.show_phrase();
|
state.show_phrase();
|
||||||
|
|
|
||||||
|
|
@ -23,18 +23,6 @@ impl Handle<Tui> for Arranger<Tui> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle events for arrangement.
|
|
||||||
impl Handle<Tui> for Arrangement<Tui> {
|
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
||||||
Ok(if let Some(command) = ArrangementCommand::input_to_command(self, from) {
|
|
||||||
let _undo = command.execute(self)?;
|
|
||||||
Some(true)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InputToCommand<Tui, Arranger<Tui>> for ArrangerCommand {
|
impl InputToCommand<Tui, Arranger<Tui>> for ArrangerCommand {
|
||||||
fn input_to_command (state: &Arranger<Tui>, input: &TuiInput) -> Option<Self> {
|
fn input_to_command (state: &Arranger<Tui>, input: &TuiInput) -> Option<Self> {
|
||||||
use FocusCommand::*;
|
use FocusCommand::*;
|
||||||
|
|
@ -56,14 +44,19 @@ impl InputToCommand<Tui, Arranger<Tui>> for ArrangerCommand {
|
||||||
.map(|t|TransportCommand::input_to_command(&*t.read().unwrap(), input)
|
.map(|t|TransportCommand::input_to_command(&*t.read().unwrap(), input)
|
||||||
.map(Transport))
|
.map(Transport))
|
||||||
.flatten(),
|
.flatten(),
|
||||||
ArrangerFocus::PhrasePool =>
|
ArrangerFocus::PhrasePool => {
|
||||||
PhrasePoolCommand::input_to_command(&*state.phrases.read().unwrap(), input)
|
let phrases = state.phrases.read().unwrap();
|
||||||
.map(Phrases),
|
match input.event() {
|
||||||
|
key!(KeyCode::Char('e')) => Some(EditPhrase(Some(phrases.phrase().clone()))),
|
||||||
|
_ => PhrasePoolCommand::input_to_command(&*phrases, input)
|
||||||
|
.map(Phrases)
|
||||||
|
}
|
||||||
|
},
|
||||||
ArrangerFocus::PhraseEditor =>
|
ArrangerFocus::PhraseEditor =>
|
||||||
PhraseEditorCommand::input_to_command(&state.editor, input)
|
PhraseEditorCommand::input_to_command(&state.editor, input)
|
||||||
.map(Editor),
|
.map(Editor),
|
||||||
ArrangerFocus::Arrangement => match input.event() {
|
ArrangerFocus::Arrangement => match input.event() {
|
||||||
key!(KeyCode::Char('e')) => Some(EditPhrase),
|
key!(KeyCode::Char('e')) => Some(EditPhrase(state.arrangement.phrase())),
|
||||||
_ => ArrangementCommand::input_to_command(&state.arrangement, &input)
|
_ => ArrangementCommand::input_to_command(&state.arrangement, &input)
|
||||||
.map(Arrangement)
|
.map(Arrangement)
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +64,19 @@ impl InputToCommand<Tui, Arranger<Tui>> for ArrangerCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle events for arrangement.
|
||||||
|
impl Handle<Tui> for Arrangement<Tui> {
|
||||||
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
Ok(if let Some(command) = ArrangementCommand::input_to_command(self, from) {
|
||||||
|
let _undo = command.execute(self)?;
|
||||||
|
Some(true)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl InputToCommand<Tui, Arrangement<Tui>> for ArrangementCommand {
|
impl InputToCommand<Tui, Arrangement<Tui>> for ArrangementCommand {
|
||||||
fn input_to_command (_: &Arrangement<Tui>, input: &TuiInput) -> Option<Self> {
|
fn input_to_command (_: &Arrangement<Tui>, input: &TuiInput) -> Option<Self> {
|
||||||
use ArrangementCommand::*;
|
use ArrangementCommand::*;
|
||||||
|
|
@ -101,6 +107,7 @@ impl InputToCommand<Tui, Arrangement<Tui>> for ArrangementCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//impl Arranger<Tui> {
|
//impl Arranger<Tui> {
|
||||||
///// Helper for event passthru to focused component
|
///// Helper for event passthru to focused component
|
||||||
//fn handle_focused (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
//fn handle_focused (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue