parent
a6f7a70f3d
commit
a9daddb1b0
3 changed files with 41 additions and 13 deletions
11
src/app.rs
11
src/app.rs
|
|
@ -772,7 +772,7 @@ impl App {
|
||||||
} else if let Some(file_name) = path.file_name().and_then(|x| x.to_str()) {
|
} else if let Some(file_name) = path.file_name().and_then(|x| x.to_str()) {
|
||||||
file_name.to_string()
|
file_name.to_string()
|
||||||
} else {
|
} else {
|
||||||
continue;
|
fl!("filesystem")
|
||||||
};
|
};
|
||||||
nav_model = nav_model.insert(move |b| {
|
nav_model = nav_model.insert(move |b| {
|
||||||
b.text(name.clone())
|
b.text(name.clone())
|
||||||
|
|
@ -2509,6 +2509,15 @@ impl Application for App {
|
||||||
self.set_show_context(true);
|
self.set_show_context(true);
|
||||||
self.set_context_title(self.context_page.title());
|
self.set_context_title(self.context_page.title());
|
||||||
}
|
}
|
||||||
|
tab::Command::AddToSidebar(path) => {
|
||||||
|
let mut favorites = self.config.favorites.clone();
|
||||||
|
let favorite = Favorite::from_path(path);
|
||||||
|
if !favorites.iter().any(|f| f == &favorite) {
|
||||||
|
favorites.push(favorite);
|
||||||
|
}
|
||||||
|
config_set!(favorites, favorites);
|
||||||
|
commands.push(self.update_config());
|
||||||
|
}
|
||||||
tab::Command::ChangeLocation(tab_title, tab_path, selection_path) => {
|
tab::Command::ChangeLocation(tab_title, tab_path, selection_path) => {
|
||||||
self.activate_nav_model_location(&tab_path);
|
self.activate_nav_model_location(&tab_path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -603,6 +603,7 @@ pub fn menu_bar<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn location_context_menu<'a>(ancestor_index: usize) -> Element<'a, tab::Message> {
|
pub fn location_context_menu<'a>(ancestor_index: usize) -> Element<'a, tab::Message> {
|
||||||
|
//TODO: only add some of these when in App mode
|
||||||
let children = vec![
|
let children = vec![
|
||||||
menu_button!(text::body(fl!("open-in-new-tab")))
|
menu_button!(text::body(fl!("open-in-new-tab")))
|
||||||
.on_press(tab::Message::LocationMenuAction(
|
.on_press(tab::Message::LocationMenuAction(
|
||||||
|
|
@ -620,6 +621,12 @@ pub fn location_context_menu<'a>(ancestor_index: usize) -> Element<'a, tab::Mess
|
||||||
LocationMenuAction::Preview(ancestor_index),
|
LocationMenuAction::Preview(ancestor_index),
|
||||||
))
|
))
|
||||||
.into(),
|
.into(),
|
||||||
|
divider::horizontal::light().into(),
|
||||||
|
menu_button!(text::body(fl!("add-to-sidebar")))
|
||||||
|
.on_press(tab::Message::LocationMenuAction(
|
||||||
|
LocationMenuAction::AddToSidebar(ancestor_index),
|
||||||
|
))
|
||||||
|
.into(),
|
||||||
];
|
];
|
||||||
|
|
||||||
container(column::with_children(children))
|
container(column::with_children(children))
|
||||||
|
|
|
||||||
36
src/tab.rs
36
src/tab.rs
|
|
@ -450,18 +450,18 @@ pub fn item_from_entry(
|
||||||
|
|
||||||
pub fn item_from_path<P: Into<PathBuf>>(path: P, sizes: IconSizes) -> Result<Item, String> {
|
pub fn item_from_path<P: Into<PathBuf>>(path: P, sizes: IconSizes) -> Result<Item, String> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let name_os = path
|
let name = match path.file_name() {
|
||||||
.file_name()
|
Some(name_os) => name_os
|
||||||
.ok_or_else(|| format!("failed to get file name from path {:?}", path))?;
|
.to_str()
|
||||||
let name = name_os
|
.ok_or_else(|| {
|
||||||
.to_str()
|
format!(
|
||||||
.ok_or_else(|| {
|
"failed to parse file name for {:?}: {:?} is not valid UTF-8",
|
||||||
format!(
|
path, name_os
|
||||||
"failed to parse file name for {:?}: {:?} is not valid UTF-8",
|
)
|
||||||
path, name_os
|
})?
|
||||||
)
|
.to_string(),
|
||||||
})?
|
None => fl!("filesystem"),
|
||||||
.to_string();
|
};
|
||||||
let metadata = fs::metadata(&path)
|
let metadata = fs::metadata(&path)
|
||||||
.map_err(|err| format!("failed to read metadata for {:?}: {}", path, err))?;
|
.map_err(|err| format!("failed to read metadata for {:?}: {}", path, err))?;
|
||||||
Ok(item_from_entry(path, name, metadata, sizes))
|
Ok(item_from_entry(path, name, metadata, sizes))
|
||||||
|
|
@ -942,6 +942,7 @@ impl Location {
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Action(Action),
|
Action(Action),
|
||||||
AddNetworkDrive,
|
AddNetworkDrive,
|
||||||
|
AddToSidebar(PathBuf),
|
||||||
ChangeLocation(String, Location, Option<PathBuf>),
|
ChangeLocation(String, Location, Option<PathBuf>),
|
||||||
DropFiles(PathBuf, ClipboardPaste),
|
DropFiles(PathBuf, ClipboardPaste),
|
||||||
EmptyTrash,
|
EmptyTrash,
|
||||||
|
|
@ -1014,6 +1015,7 @@ pub enum LocationMenuAction {
|
||||||
OpenInNewTab(usize),
|
OpenInNewTab(usize),
|
||||||
OpenInNewWindow(usize),
|
OpenInNewWindow(usize),
|
||||||
Preview(usize),
|
Preview(usize),
|
||||||
|
AddToSidebar(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MenuAction for LocationMenuAction {
|
impl MenuAction for LocationMenuAction {
|
||||||
|
|
@ -2200,6 +2202,16 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LocationMenuAction::AddToSidebar(ancestor_index) => {
|
||||||
|
if let Some(path) = path_for_index(ancestor_index) {
|
||||||
|
commands.push(Command::AddToSidebar(path));
|
||||||
|
} else {
|
||||||
|
log::warn!(
|
||||||
|
"no ancestor {ancestor_index} for location {:?}",
|
||||||
|
self.location
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Drag(rect_opt) => match rect_opt {
|
Message::Drag(rect_opt) => match rect_opt {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue