mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
reenable more phrase commands
This commit is contained in:
parent
964a4fec8f
commit
35944cf684
3 changed files with 22 additions and 20 deletions
|
|
@ -9,7 +9,6 @@ pub trait HasPhrases {
|
||||||
pub enum PhrasePoolCommand {
|
pub enum PhrasePoolCommand {
|
||||||
Add(usize, Phrase),
|
Add(usize, Phrase),
|
||||||
Delete(usize),
|
Delete(usize),
|
||||||
Duplicate(usize),
|
|
||||||
Swap(usize, usize),
|
Swap(usize, usize),
|
||||||
Color(usize, ItemColor),
|
Color(usize, ItemColor),
|
||||||
Import(usize, String),
|
Import(usize, String),
|
||||||
|
|
@ -33,22 +32,17 @@ impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
||||||
return Ok(Some(Self::Delete(index)))
|
return Ok(Some(Self::Delete(index)))
|
||||||
},
|
},
|
||||||
Self::Delete(index) => {
|
Self::Delete(index) => {
|
||||||
//if view.phrase > 0 {
|
let phrase = model.phrases_mut().remove(index);
|
||||||
//view.model.phrases.remove(view.phrase);
|
//view.phrase = view.phrase.min(view.model.phrases.len().saturating_sub(1));
|
||||||
//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;
|
|
||||||
},
|
},
|
||||||
Self::Swap(index, other) => {
|
Self::Swap(index, other) => {
|
||||||
model.phrases_mut().swap(index, other);
|
model.phrases_mut().swap(index, other);
|
||||||
|
return Ok(Some(Self::Swap(index, other)))
|
||||||
},
|
},
|
||||||
Self::Color(index, color) => {
|
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) => {
|
Self::Import(index, path) => {
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -117,11 +117,6 @@ pub trait PhrasesControl: HasPhrases {
|
||||||
PhrasesMode::Length(self.phrase_index(), length, PhraseLengthFocus::Bar)
|
PhrasesMode::Length(self.phrase_index(), length, PhraseLengthFocus::Bar)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn new_phrase (name: Option<&str>, color: Option<ItemColorTriplet>) -> Arc<RwLock<Phrase>> {
|
|
||||||
Arc::new(RwLock::new(Phrase::new(
|
|
||||||
String::from(name.unwrap_or("(new)")), true, 4 * PPQ, None, color
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
fn index_of (&self, phrase: &Phrase) -> Option<usize> {
|
fn index_of (&self, phrase: &Phrase) -> Option<usize> {
|
||||||
for i in 0..self.phrases().len() {
|
for i in 0..self.phrases().len() {
|
||||||
if *self.phrases()[i].read().unwrap() == *phrase { return Some(i) }
|
if *self.phrases()[i].read().unwrap() == *phrase { return Some(i) }
|
||||||
|
|
|
||||||
|
|
@ -272,9 +272,22 @@ impl<T: PhrasesControl> InputToCommand<Tui, T> for PhrasesCommand {
|
||||||
} else {
|
} else {
|
||||||
return None
|
return None
|
||||||
},
|
},
|
||||||
key!(Char('a')) => Self::Phrase(Pool::Add(count, Phrase::default())),
|
key!(Char('a')) => Self::Phrase(Pool::Add(
|
||||||
key!(Char('i')) => Self::Phrase(Pool::Add(index + 1, Phrase::default())),
|
count,
|
||||||
key!(Char('d')) => Self::Phrase(Pool::Duplicate(index)),
|
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('c')) => Self::Phrase(Pool::Color(index, ItemColor::random())),
|
||||||
key!(Char('n')) => Self::Rename(Rename::Begin),
|
key!(Char('n')) => Self::Rename(Rename::Begin),
|
||||||
key!(Char('t')) => Self::Length(Length::Begin),
|
key!(Char('t')) => Self::Length(Length::Begin),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue