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,
TabClose(Option<segmented_button::Entity>),
TabConfig(TabConfig),
TabContextAction(segmented_button::Entity, Action),
TabMessage(Option<segmented_button::Entity>, tab::Message),
TabNew,
TabRescan(segmented_button::Entity, Vec<tab::Item>),
@ -848,19 +847,6 @@ impl Application for App {
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) => {
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::<Tab>(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::<Tab>(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 => {

View file

@ -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) => {

View file

@ -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<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 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
}
}