From 4e77e398f2d722c8255babc2e7a6bc0addcec804 Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Wed, 12 Nov 2025 22:18:53 +0100 Subject: [PATCH] add option to copy path when pressing down shift --- i18n/en/cosmic_files.ftl | 1 + src/app.rs | 10 ++++++++++ src/key_bind.rs | 1 + src/menu.rs | 12 ++++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 03bfc32..361756a 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -354,6 +354,7 @@ quit = Quit edit = Edit cut = Cut copy = Copy +copy-path = Copy path paste = Paste select-all = Select all diff --git a/src/app.rs b/src/app.rs index 8a9feed..d9fc9b7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -146,6 +146,7 @@ pub enum Action { AddToSidebar, Compress, Copy, + CopyPath, CopyTo, Cut, CosmicSettingsDesktop, @@ -215,6 +216,7 @@ impl Action { Self::AddToSidebar => Message::AddToSidebar(entity_opt), Self::Compress => Message::Compress(entity_opt), Self::Copy => Message::Copy(entity_opt), + Self::CopyPath => Message::CopyPath(entity_opt), Self::CopyTo => Message::CopyTo(entity_opt), Self::Cut => Message::Cut(entity_opt), Self::CosmicSettingsDesktop => Message::CosmicSettings("desktop"), @@ -340,6 +342,7 @@ pub enum Message { Compress(Option), Config(Config), Copy(Option), + CopyPath(Option), CopyTo(Option), CopyToResult(DialogResult), CosmicSettings(&'static str), @@ -2744,6 +2747,13 @@ impl Application for App { let contents = ClipboardCopy::new(ClipboardKind::Copy, paths); return clipboard::write_data(contents); } + Message::CopyPath(entity_opt) => { + let paths = self.selected_paths(entity_opt); + let path_strings: Vec = + paths.into_iter().map(|p| p.display().to_string()).collect(); + let text = path_strings.join("\n"); + return clipboard::write(text); + } Message::CopyTo(entity_opt) => { let selected_paths: Box<[_]> = self.selected_paths(entity_opt).collect(); return self.copy_to(&selected_paths); diff --git a/src/key_bind.rs b/src/key_bind.rs index 3e7b4c6..3736a7c 100644 --- a/src/key_bind.rs +++ b/src/key_bind.rs @@ -67,6 +67,7 @@ pub fn key_binds(mode: &tab::Mode) -> HashMap { // App and desktop only keys if matches!(mode, tab::Mode::App | tab::Mode::Desktop) { bind!([Ctrl], Key::Character("c".into()), Copy); + bind!([Ctrl, Shift], Key::Character("c".into()), CopyPath); bind!([Ctrl], Key::Character("x".into()), Cut); bind!([], Key::Named(Named::Delete), Delete); bind!([Shift], Key::Named(Named::Delete), PermanentlyDelete); diff --git a/src/menu.rs b/src/menu.rs index fe4aafa..c6a7b12 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -174,7 +174,11 @@ pub fn context_menu<'a>( children.push(divider::horizontal::light().into()); children.push(menu_item(fl!("rename"), Action::Rename).into()); children.push(menu_item(fl!("cut"), Action::Cut).into()); - children.push(menu_item(fl!("copy"), Action::Copy).into()); + if modifiers.shift() && !modifiers.control() { + children.push(menu_item(fl!("copy-path"), Action::CopyPath).into()); + } else { + children.push(menu_item(fl!("copy"), Action::Copy).into()); + } // Should this simply bypass trash and remove the shortcut? children.push(menu_item(fl!("move-to-trash"), Action::Delete).into()); } else if selected > 0 { @@ -204,7 +208,11 @@ pub fn context_menu<'a>( children.push(menu_item(fl!("rename"), Action::Rename).into()); children.push(menu_item(fl!("cut"), Action::Cut).into()); } - children.push(menu_item(fl!("copy"), Action::Copy).into()); + if modifiers.shift() && !modifiers.control() { + children.push(menu_item(fl!("copy-path"), Action::CopyPath).into()); + } else { + children.push(menu_item(fl!("copy"), Action::Copy).into()); + } if selected_mount_point == 0 { children.push(menu_item(fl!("move-to"), Action::MoveTo).into()); }