Merge pull request #867 from jasonrhansen/broken-favorites
Handle broken favorites in sidebar
This commit is contained in:
commit
c5c1b325f0
2 changed files with 64 additions and 2 deletions
|
|
@ -121,6 +121,16 @@ read-write = Read and write
|
||||||
### Mode 7
|
### Mode 7
|
||||||
read-write-execute = Read, write, and execute
|
read-write-execute = Read, write, and execute
|
||||||
|
|
||||||
|
## Favorite Path Error Dialog
|
||||||
|
favorite-path-error = Error opening directory
|
||||||
|
favorite-path-error-description =
|
||||||
|
Unable to open "{$path}".
|
||||||
|
It may not exist or you don't have permission to open it.
|
||||||
|
|
||||||
|
Would you like to remove it from the sidebar?
|
||||||
|
remove = Remove
|
||||||
|
keep = Keep
|
||||||
|
|
||||||
# Context Pages
|
# Context Pages
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
|
||||||
56
src/app.rs
56
src/app.rs
|
|
@ -480,6 +480,10 @@ pub enum DialogPage {
|
||||||
SetExecutableAndLaunch {
|
SetExecutableAndLaunch {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
},
|
},
|
||||||
|
FavoritePathError {
|
||||||
|
path: PathBuf,
|
||||||
|
entity: Entity,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FavoriteIndex(usize);
|
pub struct FavoriteIndex(usize);
|
||||||
|
|
@ -1911,8 +1915,33 @@ impl Application for App {
|
||||||
fn on_nav_select(&mut self, entity: Entity) -> Task<Self::Message> {
|
fn on_nav_select(&mut self, entity: Entity) -> Task<Self::Message> {
|
||||||
self.nav_model.activate(entity);
|
self.nav_model.activate(entity);
|
||||||
if let Some(location) = self.nav_model.data::<Location>(entity) {
|
if let Some(location) = self.nav_model.data::<Location>(entity) {
|
||||||
let message = Message::TabMessage(None, tab::Message::Location(location.clone()));
|
let should_open = match location {
|
||||||
return self.update(message);
|
Location::Path(path) => match path.try_exists() {
|
||||||
|
Ok(true) => true,
|
||||||
|
Ok(false) => {
|
||||||
|
log::warn!("failed to open favorite, path does not exist: {:?}", path);
|
||||||
|
self.dialog_pages.push_back(DialogPage::FavoritePathError {
|
||||||
|
path: path.clone(),
|
||||||
|
entity,
|
||||||
|
});
|
||||||
|
false
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::warn!("failed to open favorite for path: {:?}, {}", path, err);
|
||||||
|
self.dialog_pages.push_back(DialogPage::FavoritePathError {
|
||||||
|
path: path.clone(),
|
||||||
|
entity,
|
||||||
|
});
|
||||||
|
false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if should_open {
|
||||||
|
let message = Message::TabMessage(None, tab::Message::Location(location.clone()));
|
||||||
|
return self.update(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
|
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
|
||||||
|
|
@ -2289,6 +2318,16 @@ impl Application for App {
|
||||||
DialogPage::SetExecutableAndLaunch { path } => {
|
DialogPage::SetExecutableAndLaunch { path } => {
|
||||||
self.operation(Operation::SetExecutableAndLaunch { path });
|
self.operation(Operation::SetExecutableAndLaunch { path });
|
||||||
}
|
}
|
||||||
|
DialogPage::FavoritePathError { entity, .. } => {
|
||||||
|
if let Some(FavoriteIndex(favorite_i)) =
|
||||||
|
self.nav_model.data::<FavoriteIndex>(entity)
|
||||||
|
{
|
||||||
|
let mut favorites = self.config.favorites.clone();
|
||||||
|
favorites.remove(*favorite_i);
|
||||||
|
config_set!(favorites, favorites);
|
||||||
|
return self.update_config();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4497,6 +4536,19 @@ impl Application for App {
|
||||||
name = name
|
name = name
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
DialogPage::FavoritePathError { path, .. } => widget::dialog()
|
||||||
|
.title(fl!("favorite-path-error"))
|
||||||
|
.body(fl!(
|
||||||
|
"favorite-path-error-description",
|
||||||
|
path = path.as_os_str().to_str()
|
||||||
|
))
|
||||||
|
.icon(widget::icon::from_name("dialog-error").size(64))
|
||||||
|
.primary_action(
|
||||||
|
widget::button::destructive(fl!("remove")).on_press(Message::DialogComplete),
|
||||||
|
)
|
||||||
|
.secondary_action(
|
||||||
|
widget::button::standard(fl!("keep")).on_press(Message::DialogCancel),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(dialog.into())
|
Some(dialog.into())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue