Implement unmount button
This commit is contained in:
parent
8c3af501ca
commit
37a6f37f7f
5 changed files with 77 additions and 29 deletions
28
src/app.rs
28
src/app.rs
|
|
@ -182,6 +182,7 @@ pub enum Message {
|
|||
Modifiers(Modifiers),
|
||||
MoveToTrash(Option<Entity>),
|
||||
MounterItems(MounterKey, MounterItems),
|
||||
NavBarClose(Entity),
|
||||
NavBarContext(Entity),
|
||||
NavMenuAction(NavMenuAction),
|
||||
NewItem(Option<Entity>, bool),
|
||||
|
|
@ -734,7 +735,13 @@ impl Application for App {
|
|||
cosmic::app::Message::App(Message::DndDropNav(entity, data, action))
|
||||
})
|
||||
.on_context(|entity| cosmic::app::Message::App(Message::NavBarContext(entity)))
|
||||
.on_close(|entity| cosmic::app::Message::App(Message::NavBarClose(entity)))
|
||||
.context_menu(self.nav_context_menu(self.nav_bar_context_id))
|
||||
.close_icon(
|
||||
widget::icon::from_name("media-eject-symbolic")
|
||||
.size(16)
|
||||
.icon(),
|
||||
)
|
||||
.into_container();
|
||||
|
||||
if !self.core().is_condensed() {
|
||||
|
|
@ -1065,15 +1072,7 @@ impl Application for App {
|
|||
let mut entity = self
|
||||
.nav_model
|
||||
.insert()
|
||||
.text(format!(
|
||||
"{} ({})",
|
||||
item.name(),
|
||||
if item.is_mounted() {
|
||||
"mounted"
|
||||
} else {
|
||||
"not mounted"
|
||||
}
|
||||
))
|
||||
.text(item.name())
|
||||
.data(MounterData(key, item.clone()));
|
||||
if let Some(path) = item.path() {
|
||||
entity = entity.data(Location::Path(path.clone()));
|
||||
|
|
@ -1081,6 +1080,9 @@ impl Application for App {
|
|||
if let Some(icon) = item.icon() {
|
||||
entity = entity.icon(widget::icon::icon(icon).size(16));
|
||||
}
|
||||
if item.is_mounted() {
|
||||
entity = entity.closable();
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::NewItem(entity_opt, dir) => {
|
||||
|
|
@ -1650,6 +1652,14 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
|
||||
Message::NavBarClose(entity) => {
|
||||
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
|
||||
if let Some(mounter) = self.mounters.get(&data.0) {
|
||||
return mounter.unmount(data.1.clone()).map(|_| message::none());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tracks which nav bar item to show a context menu for.
|
||||
Message::NavBarContext(entity) => {
|
||||
self.nav_bar_context_id = entity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue