diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index acfeb2bbf..0c4ee60d0 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -477,6 +477,10 @@ pub enum KeyAssignment { SpawnWindow, ToggleFullScreen, CopyTo(ClipboardCopyDestination), + CopyTextTo { + text: String, + destination: ClipboardCopyDestination, + }, PasteFrom(ClipboardPasteSource), ActivateTabRelative(isize), ActivateTabRelativeNoWrap(isize), diff --git a/wezterm-gui/src/commands.rs b/wezterm-gui/src/commands.rs index dba9ec506..56915de81 100644 --- a/wezterm-gui/src/commands.rs +++ b/wezterm-gui/src/commands.rs @@ -437,11 +437,20 @@ impl CommandDef { } else if cmd.menubar[0] == "WezTerm" { menu.assign_as_app_menu(); - menu.add_item(&MenuItem::new_with( - "About WezTerm", - Some(sel!(weztermShowAbout:)), + let about_item = MenuItem::new_with( + &format!("WezTerm {}", config::wezterm_version()), + Some(wezterm_perform_key_assignment_sel), "", + ); + about_item.set_tool_tip("Click to copy version number"); + about_item.set_represented_item(RepresentedItem::KeyAssignment( + KeyAssignment::CopyTextTo { + text: config::wezterm_version().to_string(), + destination: ClipboardCopyDestination::ClipboardAndPrimarySelection, + }, )); + + menu.add_item(&about_item); menu.add_item(&MenuItem::new_separator()); // FIXME: when we set this as the services menu, @@ -614,7 +623,11 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option CommandDef { + CopyTextTo { + text: _, + destination: ClipboardCopyDestination::PrimarySelection, + } + | CopyTo(ClipboardCopyDestination::PrimarySelection) => CommandDef { brief: "Copy to primary selection".into(), doc: "Copies text to the primary selection".into(), keys: vec![(Modifiers::CTRL, "Insert".into())], @@ -622,7 +635,11 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option CommandDef { + CopyTextTo { + text: _, + destination: ClipboardCopyDestination::Clipboard, + } + | CopyTo(ClipboardCopyDestination::Clipboard) => CommandDef { brief: "Copy to clipboard".into(), doc: "Copies text to the clipboard".into(), keys: vec![ @@ -633,7 +650,11 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option CommandDef { + CopyTextTo { + text: _, + destination: ClipboardCopyDestination::ClipboardAndPrimarySelection, + } + | CopyTo(ClipboardCopyDestination::ClipboardAndPrimarySelection) => CommandDef { brief: "Copy to clipboard and primary selection".into(), doc: "Copies text to the clipboard and the primary selection".into(), keys: vec![(Modifiers::CTRL, "Insert".into())], diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 4a5a6ccce..99dc925d0 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -2512,6 +2512,9 @@ impl TermWindow { let text = self.selection_text(pane); self.copy_to_clipboard(*dest, text); } + CopyTextTo { text, destination } => { + self.copy_to_clipboard(*destination, text.clone()); + } PasteFrom(source) => { self.paste_from_clipboard(pane, *source); } diff --git a/window/src/os/macos/app.rs b/window/src/os/macos/app.rs index dae2147b5..8f6c72f12 100644 --- a/window/src/os/macos/app.rs +++ b/window/src/os/macos/app.rs @@ -3,7 +3,7 @@ use crate::macos::menu::RepresentedItem; use crate::macos::{nsstring, nsstring_to_str}; use crate::menu::{Menu, MenuItem}; use crate::{ApplicationEvent, Connection}; -use cocoa::appkit::{NSApp, NSApplicationTerminateReply}; +use cocoa::appkit::NSApplicationTerminateReply; use cocoa::base::id; use cocoa::foundation::NSInteger; use config::keyassignment::KeyAssignment; @@ -14,16 +14,6 @@ use objc::*; const CLS_NAME: &str = "WezTermAppDelegate"; -#[allow(unused)] -#[link(name = "AppKit", kind = "framework")] -extern "C" { - pub static NSAboutPanelOptionCredits: id; - pub static NSAboutPanelOptionApplicationName: id; - pub static NSAboutPanelOptionApplicationIcon: id; - pub static NSAboutPanelOptionVersion: id; - pub static NSAboutPanelOptionApplicationVersion: id; -} - extern "C" fn application_should_terminate( _self: &mut Object, _sel: Sel, @@ -112,29 +102,6 @@ extern "C" fn wezterm_perform_key_assignment( } } -/// Show an about dialog with the version information -extern "C" fn wezterm_show_about(_self: &mut Object, _sel: Sel, _menu_item: *mut Object) { - unsafe { - let ns_app = NSApp(); - - let credits = nsstring("Copyright (c) 2018-Present Wez Furlong"); - let credits = { - let attr: id = msg_send![class!(NSAttributedString), alloc]; - let () = msg_send![attr, initWithString:*credits]; - attr - }; - let version = nsstring(config::wezterm_version()); - - let dict: id = msg_send![class!(NSMutableDictionary), alloc]; - let dict: id = msg_send![dict, init]; - let () = msg_send![dict, setObject:*version forKey:NSAboutPanelOptionVersion]; - let () = msg_send![dict, setObject:*version forKey:NSAboutPanelOptionApplicationVersion]; - let () = msg_send![dict, setObject:credits forKey:NSAboutPanelOptionCredits]; - - let () = msg_send![ns_app, orderFrontStandardAboutPanelWithOptions: dict]; - } -} - extern "C" fn application_open_file( this: &mut Object, _sel: Sel, @@ -198,10 +165,6 @@ fn get_class() -> &'static Class { sel!(weztermPerformKeyAssignment:), wezterm_perform_key_assignment as extern "C" fn(&mut Object, Sel, *mut Object), ); - cls.add_method( - sel!(weztermShowAbout:), - wezterm_show_about as extern "C" fn(&mut Object, Sel, *mut Object), - ); cls.add_method( sel!(applicationOpenUntitledFile:), application_open_untitled_file