Implement "Open in new window" for Trash, Recents, Network
This commit is contained in:
parent
7d111169e0
commit
cfedaef0cb
2 changed files with 38 additions and 9 deletions
43
src/app.rs
43
src/app.rs
|
|
@ -50,7 +50,8 @@ use slotmap::Key as SlotMapKey;
|
|||
use std::{
|
||||
any::TypeId,
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque},
|
||||
env, fmt, fs, io,
|
||||
env,
|
||||
fmt, fs, io,
|
||||
num::NonZeroU16,
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
|
|
@ -3487,15 +3488,39 @@ impl Application for App {
|
|||
}
|
||||
|
||||
// Open the selected path in a new cosmic-files window.
|
||||
NavMenuAction::OpenInNewWindow(entity) => {
|
||||
if let Some(Location::Path(path)) = self.nav_model.data::<Location>(entity) {
|
||||
NavMenuAction::OpenInNewWindow(entity) => 'open_in_new_window: {
|
||||
if let Some(location) = self.nav_model.data::<Location>(entity) {
|
||||
match env::current_exe() {
|
||||
Ok(exe) => match process::Command::new(&exe).arg(path).spawn() {
|
||||
Ok(_child) => {}
|
||||
Err(err) => {
|
||||
log::error!("failed to execute {:?}: {}", exe, err);
|
||||
}
|
||||
},
|
||||
Ok(exe) => {
|
||||
let mut command = process::Command::new(&exe);
|
||||
match location {
|
||||
Location::Path(path) => {
|
||||
command.arg(path);
|
||||
}
|
||||
Location::Trash => {
|
||||
command.arg("--trash");
|
||||
}
|
||||
Location::Network(..) => {
|
||||
command.arg("--network");
|
||||
}
|
||||
Location::Recents => {
|
||||
command.arg("--recents");
|
||||
}
|
||||
_ => {
|
||||
log::error!(
|
||||
"unsupported location for open in new window: {:?}",
|
||||
location
|
||||
);
|
||||
break 'open_in_new_window;
|
||||
}
|
||||
};
|
||||
match command.spawn() {
|
||||
Ok(_child) => {}
|
||||
Err(err) => {
|
||||
log::error!("failed to execute {:?}: {}", exe, err);
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("failed to get current executable path: {}", err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
continue;
|
||||
} else if &arg == "--trash" {
|
||||
Location::Trash
|
||||
} else if &arg == "--recents" {
|
||||
Location::Recents
|
||||
} else if &arg == "--network" {
|
||||
Location::Network("network:///".to_string(), fl!("networks"))
|
||||
} else {
|
||||
//TODO: support more URLs
|
||||
let path = match url::Url::parse(&arg) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue