mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
reenable adding phrases with new command system
This commit is contained in:
parent
398f676ae3
commit
d5a37229b9
2 changed files with 107 additions and 71 deletions
|
|
@ -7,7 +7,7 @@ pub trait HasPhrases {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PhrasePoolCommand {
|
||||
Add(usize),
|
||||
Add(usize, Phrase),
|
||||
Delete(usize),
|
||||
Duplicate(usize),
|
||||
Swap(usize, usize),
|
||||
|
|
@ -21,9 +21,16 @@ pub enum PhrasePoolCommand {
|
|||
impl<T: HasPhrases> Command<T> for PhrasePoolCommand {
|
||||
fn execute (self, model: &mut T) -> Perhaps<Self> {
|
||||
match self {
|
||||
Self::Add(index) => {
|
||||
//Self::Append => { view.append_new(None, None) },
|
||||
//Self::Insert => { view.insert_new(None, None) },
|
||||
Self::Add(mut index, phrase) => {
|
||||
let phrase = Arc::new(RwLock::new(phrase));
|
||||
let phrases = model.phrases_mut();
|
||||
if index >= phrases.len() {
|
||||
index = phrases.len();
|
||||
phrases.push(phrase)
|
||||
} else {
|
||||
phrases.insert(index, phrase);
|
||||
}
|
||||
return Ok(Some(Self::Delete(index)))
|
||||
},
|
||||
Self::Delete(index) => {
|
||||
//if view.phrase > 0 {
|
||||
|
|
@ -125,6 +132,7 @@ impl Phrase {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Phrase {
|
||||
fn default () -> Self {
|
||||
Self::new("(empty)", false, 0, None, Some(ItemColor::from(Color::Rgb(0, 0, 0)).into()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue