From 35944cf684931acfdf1a1c3e99db686e549bba73 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 24 Nov 2024 00:47:07 +0100 Subject: [PATCH] reenable more phrase commands --- crates/tek_api/src/api_phrase.rs | 18 ++++++------------ crates/tek_tui/src/tui_control.rs | 5 ----- crates/tek_tui/src/tui_input.rs | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/tek_api/src/api_phrase.rs b/crates/tek_api/src/api_phrase.rs index eaf48c6f..8de378de 100644 --- a/crates/tek_api/src/api_phrase.rs +++ b/crates/tek_api/src/api_phrase.rs @@ -9,7 +9,6 @@ pub trait HasPhrases { pub enum PhrasePoolCommand { Add(usize, Phrase), Delete(usize), - Duplicate(usize), Swap(usize, usize), Color(usize, ItemColor), Import(usize, String), @@ -33,22 +32,17 @@ impl Command for PhrasePoolCommand { return Ok(Some(Self::Delete(index))) }, Self::Delete(index) => { - //if view.phrase > 0 { - //view.model.phrases.remove(view.phrase); - //view.phrase = view.phrase.min(view.model.phrases.len().saturating_sub(1)); - //} - }, - Self::Duplicate(index) => { - //let mut phrase = view.phrase().read().unwrap().duplicate(); - //phrase.color = ItemColorTriplet::random_near(phrase.color, 0.25); - //view.phrases.insert(view.phrase + 1, Arc::new(RwLock::new(phrase))); - //view.phrase += 1; + let phrase = model.phrases_mut().remove(index); + //view.phrase = view.phrase.min(view.model.phrases.len().saturating_sub(1)); }, Self::Swap(index, other) => { model.phrases_mut().swap(index, other); + return Ok(Some(Self::Swap(index, other))) }, Self::Color(index, color) => { - //view.phrase().write().unwrap().color = ItemColorTriplet::random(); + let mut color = ItemColorTriplet::from(color); + std::mem::swap(&mut color, &mut model.phrases()[index].write().unwrap().color); + return Ok(Some(Self::Color(index, color.base))) }, Self::Import(index, path) => { }, diff --git a/crates/tek_tui/src/tui_control.rs b/crates/tek_tui/src/tui_control.rs index 224ca03c..e5640d8a 100644 --- a/crates/tek_tui/src/tui_control.rs +++ b/crates/tek_tui/src/tui_control.rs @@ -117,11 +117,6 @@ pub trait PhrasesControl: HasPhrases { PhrasesMode::Length(self.phrase_index(), length, PhraseLengthFocus::Bar) ) } - fn new_phrase (name: Option<&str>, color: Option) -> Arc> { - Arc::new(RwLock::new(Phrase::new( - String::from(name.unwrap_or("(new)")), true, 4 * PPQ, None, color - ))) - } fn index_of (&self, phrase: &Phrase) -> Option { for i in 0..self.phrases().len() { if *self.phrases()[i].read().unwrap() == *phrase { return Some(i) } diff --git a/crates/tek_tui/src/tui_input.rs b/crates/tek_tui/src/tui_input.rs index d15eb1f1..ecc56990 100644 --- a/crates/tek_tui/src/tui_input.rs +++ b/crates/tek_tui/src/tui_input.rs @@ -272,9 +272,22 @@ impl InputToCommand for PhrasesCommand { } else { return None }, - key!(Char('a')) => Self::Phrase(Pool::Add(count, Phrase::default())), - key!(Char('i')) => Self::Phrase(Pool::Add(index + 1, Phrase::default())), - key!(Char('d')) => Self::Phrase(Pool::Duplicate(index)), + key!(Char('a')) => Self::Phrase(Pool::Add( + count, + Phrase::new( + String::from("(new)"), true, 4 * PPQ, None, Some(ItemColorTriplet::random()) + ) + )), + key!(Char('i')) => Self::Phrase(Pool::Add( + index + 1, + Phrase::new( + String::from("(new)"), true, 4 * PPQ, None, Some(ItemColorTriplet::random()) + ) + )), + key!(Char('d')) => Self::Phrase(Pool::Add( + index + 1, + state.phrases()[index].read().unwrap().duplicate() + )), key!(Char('c')) => Self::Phrase(Pool::Color(index, ItemColor::random())), key!(Char('n')) => Self::Rename(Rename::Begin), key!(Char('t')) => Self::Length(Length::Begin),