From c6eecbddd87d06fafdd07692a50aec1a8eeea183 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 1 Feb 2024 17:34:22 -0700 Subject: [PATCH] Add open/cancel buttons to dialog --- i18n/en/cosmic_files.ftl | 4 ++++ src/dialog.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 49dcd98..0deca5d 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -4,6 +4,10 @@ filesystem = Filesystem home = Home trash = Trash +# Dialog +cancel = Cancel +open = Open + # List view name = Name modified = Modified diff --git a/src/dialog.rs b/src/dialog.rs index 53e7a20..a6b5a02 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -29,9 +29,11 @@ pub struct Flags {} /// Messages that are used specifically by our [`App`]. #[derive(Clone, Debug)] pub enum Message { + Cancel, Modifiers(Modifiers), NotifyEvent(notify::Event), NotifyWatcher(WatcherWrapper), + Open, SelectAll(Option), TabActivate(segmented_button::Entity), TabClose(Option), @@ -271,6 +273,9 @@ impl Application for App { /// Handle application events here. fn update(&mut self, message: Self::Message) -> Command { match message { + Message::Cancel => { + println!("CANCEL"); + } Message::Modifiers(modifiers) => { self.modifiers = modifiers; } @@ -312,6 +317,20 @@ impl Application for App { log::warn!("message did not contain notify watcher"); } }, + Message::Open => { + let mut paths = Vec::new(); + let entity = self.tab_model.active(); + if let Some(tab) = self.tab_model.data_mut::(entity) { + if let Some(ref mut items) = tab.items_opt { + for item in items.iter_mut() { + if item.selected { + paths.push(item.path.clone()); + } + } + } + } + println!("OPEN {:?}", paths); + } Message::SelectAll(entity_opt) => { let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); if let Some(tab) = self.tab_model.data_mut::(entity) { @@ -409,7 +428,7 @@ impl Application for App { match self.tab_model.data::(entity) { Some(tab) => { tab_column = tab_column.push( - tab.list_view(self.core()) + tab.view(self.core()) .map(move |message| Message::TabMessage(Some(entity), message)), ); } @@ -418,6 +437,20 @@ impl Application for App { } } + tab_column = tab_column.push( + widget::row::with_children(vec![ + widget::horizontal_space(Length::Fill).into(), + widget::button(widget::text(fl!("cancel"))) + .on_press(Message::Cancel) + .into(), + widget::button(widget::text(fl!("open"))) + .on_press(Message::Open) + .into(), + ]) + .padding(space_xxs) + .spacing(space_xxs), + ); + let content: Element<_> = tab_column.into(); // Uncomment to debug layout: