Fix actions

This commit is contained in:
Jeremy Soller 2024-02-26 12:51:22 -07:00
parent c8f4eb9d34
commit 0ce43dfcf5
3 changed files with 38 additions and 39 deletions

View file

@ -125,7 +125,6 @@ pub enum Message {
TabPrev, TabPrev,
TabClose(Option<segmented_button::Entity>), TabClose(Option<segmented_button::Entity>),
TabConfig(TabConfig), TabConfig(TabConfig),
TabContextAction(segmented_button::Entity, Action),
TabMessage(Option<segmented_button::Entity>, tab::Message), TabMessage(Option<segmented_button::Entity>, tab::Message),
TabNew, TabNew,
TabRescan(segmented_button::Entity, Vec<tab::Item>), TabRescan(segmented_button::Entity, Vec<tab::Item>),
@ -848,19 +847,6 @@ impl Application for App {
return Command::batch(commands); return Command::batch(commands);
} }
} }
Message::TabContextAction(entity, action) => {
match self.tab_model.data_mut::<Tab>(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) => { Message::TabMessage(entity_opt, tab_message) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); 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; self.core.window.show_context = false;
} }
let mut update_opt = None; let tab_command = match self.tab_model.data_mut::<Tab>(entity) {
match self.tab_model.data_mut::<Tab>(entity) { Some(tab) => tab.update(tab_message, self.modifiers),
Some(tab) => { _ => tab::Command::None,
if tab.update(tab_message, self.modifiers) { };
update_opt = Some((tab.title(), tab.location.clone())); 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 => { Message::TabNew => {

View file

@ -479,7 +479,7 @@ impl Application for App {
_ => None, _ => 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 // Update filename box when anything is selected
if let DialogKind::SaveFile { filename } = &mut self.flags.kind { if let DialogKind::SaveFile { filename } = &mut self.flags.kind {
@ -494,8 +494,14 @@ impl Application for App {
} }
} }
if updated { match tab_command {
return Command::batch([self.update_watcher(), self.rescan_tab()]); 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) => { Message::TabRescan(mut items) => {

View file

@ -390,6 +390,13 @@ impl Location {
} }
} }
#[derive(Clone, Debug)]
pub enum Command {
None,
Action(Action),
ChangeLocation(String, Location),
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Message { pub enum Message {
Click(Option<usize>), Click(Option<usize>),
@ -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 cd = None;
let mut history_i_opt = None; let mut history_i_opt = None;
match message { match message {
@ -662,8 +669,7 @@ impl Tab {
// Close context menu // Close context menu
self.context_menu = None; self.context_menu = None;
// TODO: run actions message return Command::Action(action);
println!("TODO {:?}", action);
} }
Message::ContextMenu(point_opt) => { Message::ContextMenu(point_opt) => {
self.context_menu = point_opt; self.context_menu = point_opt;
@ -787,14 +793,14 @@ impl Tab {
// Push to the front of history // Push to the front of history
self.history_i = self.history.len(); self.history_i = self.history.len();
self.history.push(location); self.history.push(location.clone());
} }
true Command::ChangeLocation(self.title(), location)
} else { } else {
false Command::None
} }
} else { } else {
false Command::None
} }
} }