diff --git a/src/app.rs b/src/app.rs index 53d9703..fa3b37f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -125,7 +125,6 @@ pub enum Message { TabPrev, TabClose(Option), TabConfig(TabConfig), - TabContextAction(segmented_button::Entity, Action), TabMessage(Option, tab::Message), TabNew, TabRescan(segmented_button::Entity, Vec), @@ -848,19 +847,6 @@ impl Application for App { return Command::batch(commands); } } - Message::TabContextAction(entity, action) => { - match self.tab_model.data_mut::(entity) { - Some(tab) => { - // Close context menu - { - tab.context_menu = None; - } - // Run action's message - return self.update(action.message(Some(entity))); - } - _ => {} - } - } Message::TabMessage(entity_opt, tab_message) => { let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); @@ -869,22 +855,23 @@ impl Application for App { self.core.window.show_context = false; } - let mut update_opt = None; - match self.tab_model.data_mut::(entity) { - Some(tab) => { - if tab.update(tab_message, self.modifiers) { - update_opt = Some((tab.title(), tab.location.clone())); - } + let tab_command = match self.tab_model.data_mut::(entity) { + Some(tab) => tab.update(tab_message, self.modifiers), + _ => tab::Command::None, + }; + match tab_command { + tab::Command::None => {} + tab::Command::Action(action) => { + return self.update(action.message(Some(entity))); + } + tab::Command::ChangeLocation(tab_title, tab_path) => { + self.tab_model.text_set(entity, tab_title); + return Command::batch([ + self.update_title(), + self.update_watcher(), + self.rescan_tab(entity, tab_path), + ]); } - _ => (), - } - if let Some((tab_title, tab_path)) = update_opt { - self.tab_model.text_set(entity, tab_title); - return Command::batch([ - self.update_title(), - self.update_watcher(), - self.rescan_tab(entity, tab_path), - ]); } } Message::TabNew => { diff --git a/src/dialog.rs b/src/dialog.rs index 5835aa9..59fac89 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -479,7 +479,7 @@ impl Application for App { _ => None, }; - let updated = self.tab.update(tab_message, self.modifiers); + let tab_command = self.tab.update(tab_message, self.modifiers); // Update filename box when anything is selected if let DialogKind::SaveFile { filename } = &mut self.flags.kind { @@ -494,8 +494,14 @@ impl Application for App { } } - if updated { - return Command::batch([self.update_watcher(), self.rescan_tab()]); + match tab_command { + tab::Command::None => {} + tab::Command::Action(action) => { + log::warn!("Action {:?} not supported in dialog", action); + } + tab::Command::ChangeLocation(_tab_title, _tab_path) => { + return Command::batch([self.update_watcher(), self.rescan_tab()]); + } } } Message::TabRescan(mut items) => { diff --git a/src/tab.rs b/src/tab.rs index f0483b0..10ca22f 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -390,6 +390,13 @@ impl Location { } } +#[derive(Clone, Debug)] +pub enum Command { + None, + Action(Action), + ChangeLocation(String, Location), +} + #[derive(Clone, Debug)] pub enum Message { Click(Option), @@ -605,7 +612,7 @@ impl Tab { } } - pub fn update(&mut self, message: Message, modifiers: Modifiers) -> bool { + pub fn update(&mut self, message: Message, modifiers: Modifiers) -> Command { let mut cd = None; let mut history_i_opt = None; match message { @@ -662,8 +669,7 @@ impl Tab { // Close context menu self.context_menu = None; - // TODO: run actions message - println!("TODO {:?}", action); + return Command::Action(action); } Message::ContextMenu(point_opt) => { self.context_menu = point_opt; @@ -787,14 +793,14 @@ impl Tab { // Push to the front of history self.history_i = self.history.len(); - self.history.push(location); + self.history.push(location.clone()); } - true + Command::ChangeLocation(self.title(), location) } else { - false + Command::None } } else { - false + Command::None } }