1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

macos: remove about dialog

Replace it with a menu item that shows the version number, and
that you can click to copy the version number.

closes: https://github.com/wez/wezterm/issues/3507
This commit is contained in:
Wez Furlong 2023-04-24 11:08:18 -07:00
parent 26090da81e
commit dc2cd706dc
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
4 changed files with 35 additions and 44 deletions

View File

@ -477,6 +477,10 @@ pub enum KeyAssignment {
SpawnWindow,
ToggleFullScreen,
CopyTo(ClipboardCopyDestination),
CopyTextTo {
text: String,
destination: ClipboardCopyDestination,
},
PasteFrom(ClipboardPasteSource),
ActivateTabRelative(isize),
ActivateTabRelativeNoWrap(isize),

View File

@ -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<Comm
menubar: &["Edit"],
icon: Some("mdi_content_paste"),
},
CopyTo(ClipboardCopyDestination::PrimarySelection) => 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<Comm
menubar: &["Edit"],
icon: Some("mdi_content_copy"),
},
CopyTo(ClipboardCopyDestination::Clipboard) => 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<Comm
menubar: &["Edit"],
icon: Some("mdi_content_copy"),
},
CopyTo(ClipboardCopyDestination::ClipboardAndPrimarySelection) => 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())],

View File

@ -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);
}

View File

@ -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