dialog: Implement view switching, part of #335
This commit is contained in:
parent
ff6f6c1e3a
commit
00bc311eaa
1 changed files with 36 additions and 0 deletions
|
|
@ -303,6 +303,7 @@ enum Message {
|
|||
Save(bool),
|
||||
TabMessage(tab::Message),
|
||||
TabRescan(Vec<tab::Item>),
|
||||
ViewSelect(segmented_button::Entity),
|
||||
}
|
||||
|
||||
pub struct MounterData(MounterKey, MounterItem);
|
||||
|
|
@ -347,6 +348,7 @@ struct App {
|
|||
replace_dialog: bool,
|
||||
tab: Tab,
|
||||
key_binds: HashMap<KeyBind, Action>,
|
||||
view_model: segmented_button::SingleSelectModel,
|
||||
watcher_opt: Option<(Debouncer<RecommendedWatcher, FileIdMap>, HashSet<PathBuf>)>,
|
||||
}
|
||||
|
||||
|
|
@ -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<Message>) {
|
||||
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<Element<Message>> {
|
||||
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<Element<message::Message<Self::Message>>> {
|
||||
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::<tab::View>(entity) {
|
||||
Some(view) => {
|
||||
self.tab.config.view = *view;
|
||||
self.view_model.activate(entity);
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
}
|
||||
|
||||
Command::none()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue