diff --git a/src/dialog.rs b/src/dialog.rs index da9c580..10f7bb4 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -303,6 +303,7 @@ enum Message { Save(bool), TabMessage(tab::Message), TabRescan(Vec), + ViewSelect(segmented_button::Entity), } pub struct MounterData(MounterKey, MounterItem); @@ -347,6 +348,7 @@ struct App { replace_dialog: bool, tab: Tab, key_binds: HashMap, + view_model: segmented_button::SingleSelectModel, watcher_opt: Option<(Debouncer, HashSet)>, } @@ -531,6 +533,7 @@ impl Application for App { /// Creates the application, and optionally emits command on initialize. fn init(mut core: Core, flags: Self::Flags) -> (Self, Command) { + core.window.show_close = false; core.window.show_maximize = false; core.window.show_minimize = false; @@ -555,6 +558,18 @@ impl Application for App { let mut tab = Tab::new(location, tab_config); tab.dialog = Some(flags.kind.clone()); + let view_model = segmented_button::SingleSelectModel::builder() + .insert(|b| { + b.icon(widget::icon::from_name("view-grid-symbolic")) + .data(tab::View::Grid) + }) + .insert(|b| { + b.icon(widget::icon::from_name("view-list-symbolic")) + .data(tab::View::List) + .activate() + }) + .build(); + let mut app = App { core, flags, @@ -572,6 +587,7 @@ impl Application for App { replace_dialog: false, tab, key_binds: HashMap::new(), + view_model, watcher_opt: None, }; @@ -609,6 +625,19 @@ impl Application for App { None } + fn header_end(&self) -> Vec> { + vec![ + /*TODO: search and new folder buttons + widget::button::icon(widget::icon::from_name("system-search-symbolic")).into(), + widget::button::icon(widget::icon::from_name("folder-new-symbolic")).into(), + */ + widget::segmented_control::horizontal(&self.view_model) + .on_activate(Message::ViewSelect) + .width(Length::Shrink) + .into(), + ] + } + fn nav_bar(&self) -> Option>> { if !self.core().nav_bar_active() { return None; @@ -1042,6 +1071,13 @@ impl Application for App { // Reset focus on location change return widget::text_input::focus(self.filename_id.clone()); } + Message::ViewSelect(entity) => match self.view_model.data::(entity) { + Some(view) => { + self.tab.config.view = *view; + self.view_model.activate(entity); + } + None => {} + }, } Command::none()