diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index 625d557a1..43e62c459 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -535,6 +535,7 @@ pub enum KeyAssignment { CharSelect(CharSelectArguments), ResetTerminal, + OpenUri(String), } impl_lua_conversion_dynamic!(KeyAssignment); diff --git a/wezterm-gui/src/commands.rs b/wezterm-gui/src/commands.rs index da7da38b3..f67ead130 100644 --- a/wezterm-gui/src/commands.rs +++ b/wezterm-gui/src/commands.rs @@ -212,6 +212,8 @@ impl CommandDef { menu.add_item(&MenuItem::new_separator()); } + } else if cmd.menubar[0] == "Help" { + menu.assign_as_help_menu(); } }); @@ -229,36 +231,6 @@ impl CommandDef { submenu.add_item(&item); } } - - let help_menu = Menu::new_with_title("Help"); - let help_item = MenuItem::new_with("Help", None, ""); - main_menu.add_item(&help_item); - help_item.set_sub_menu(&help_menu); - help_menu.assign_as_help_menu(); - - for (caption, url) in [ - ("Documentation", "https://wezfurlong.org/wezterm/"), - /* Omitted because the underlying `open` utility rewrites the `#` to `%23` - * and matrix's URL parser doesn't like that, despite it being a core - * part of how URLs work. - ( - "Discuss in realtime on Matrix", - "https://matrix.to/#/#wezterm:matrix.org", - ), - */ - ( - "Discuss on GitHub", - "https://github.com/wez/wezterm/discussions", - ), - ( - "Search or report issue on GitHub", - "https://github.com/wez/wezterm/issues", - ), - ] { - let item = MenuItem::new_with(caption, Some(sel!(weztermPerformKeyAssignment:)), ""); - item.set_represented_item(RepresentedItem::OpenInBrowser(url.to_string())); - help_menu.add_item(&item); - } } } @@ -934,4 +906,36 @@ static DEFS: &[CommandDef] = &[ args: &[ArgType::ActivePane], menubar: &["Shell"], }, + CommandDef { + brief: "Documentation", + doc: "Visit the wezterm documentation website", + exp: |exp| exp.push(OpenUri("https://wezfurlong.org/wezterm/".to_string())), + keys: &[], + args: &[], + menubar: &["Help"], + }, + CommandDef { + brief: "Discuss on GitHub", + doc: "Visit wezterm's GitHub discussion", + exp: |exp| { + exp.push(OpenUri( + "https://github.com/wez/wezterm/discussions/".to_string(), + )) + }, + keys: &[], + args: &[], + menubar: &["Help"], + }, + CommandDef { + brief: "Search or report issue on GitHub", + doc: "Visit wezterm's GitHub issues", + exp: |exp| { + exp.push(OpenUri( + "https://github.com/wez/wezterm/issues/".to_string(), + )) + }, + keys: &[], + args: &[], + menubar: &["Help"], + }, ]; diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index f425252c7..fee11dc0e 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -256,13 +256,6 @@ impl GuiFrontEnd { } } } - ApplicationEvent::OpenInBrowser(url) => { - std::thread::spawn(move || { - if let Err(err) = open::that(&url) { - log::error!("Error opening {}: {:#}", url, err); - } - }); - } } } diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index d66234a04..f0c5ff8c0 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -879,14 +879,6 @@ impl TermWindow { } Ok(true) } - WindowEvent::OpenInBrowser(url) => { - std::thread::spawn(move || { - if let Err(err) = open::that(&url) { - log::error!("Error opening {}: {:#}", url, err); - } - }); - Ok(true) - } WindowEvent::FocusChanged(focused) => { self.focus_changed(focused, window); Ok(true) @@ -2778,6 +2770,14 @@ impl TermWindow { termwiz::escape::Esc::Code(termwiz::escape::EscCode::FullReset), )]); } + OpenUri(link) => { + let link = link.clone(); + std::thread::spawn(move || { + if let Err(err) = open::that(&link) { + log::error!("Error opening {}: {:#}", link, err); + } + }); + } }; Ok(PerformAssignmentResult::Handled) } diff --git a/window/examples/async.rs b/window/examples/async.rs index 24a218d38..50afe6784 100644 --- a/window/examples/async.rs +++ b/window/examples/async.rs @@ -85,7 +85,6 @@ impl MyWindow { | WindowEvent::DraggedFile(_) | WindowEvent::DroppedFile(_) | WindowEvent::PerformKeyAssignment(_) - | WindowEvent::OpenInBrowser(_) | WindowEvent::MouseLeave => {} } } diff --git a/window/src/connection.rs b/window/src/connection.rs index 288e79e81..4fdd10dbd 100644 --- a/window/src/connection.rs +++ b/window/src/connection.rs @@ -24,8 +24,6 @@ pub enum ApplicationEvent { /// The system wants to open a command in the terminal OpenCommandScript(String), PerformKeyAssignment(KeyAssignment), - /// A request to open a URL in the browser - OpenInBrowser(String), } pub trait ConnectionOps { diff --git a/window/src/lib.rs b/window/src/lib.rs index 718805c6a..24dd53992 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -189,8 +189,6 @@ pub enum WindowEvent { /// Called by menubar dispatching stuff on some systems PerformKeyAssignment(config::keyassignment::KeyAssignment), - /// Called by menubar dispatching stuff on some systems - OpenInBrowser(String), } pub struct WindowEventSender { diff --git a/window/src/os/macos/app.rs b/window/src/os/macos/app.rs index c6e34b2c4..8f5f0e085 100644 --- a/window/src/os/macos/app.rs +++ b/window/src/os/macos/app.rs @@ -53,11 +53,6 @@ extern "C" fn wezterm_perform_key_assignment( conn.dispatch_app_event(ApplicationEvent::PerformKeyAssignment(action)); } } - Some(RepresentedItem::OpenInBrowser(url)) => { - if let Some(conn) = Connection::get() { - conn.dispatch_app_event(ApplicationEvent::OpenInBrowser(url)); - } - } None => {} } } diff --git a/window/src/os/macos/menu.rs b/window/src/os/macos/menu.rs index 8f1e550f7..064206871 100644 --- a/window/src/os/macos/menu.rs +++ b/window/src/os/macos/menu.rs @@ -111,7 +111,6 @@ pub struct MenuItem { #[derive(Clone, Debug)] pub enum RepresentedItem { KeyAssignment(KeyAssignment), - OpenInBrowser(String), } impl MenuItem { diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 6c5cb1483..ab6f5b99c 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1922,14 +1922,6 @@ impl WindowView { .dispatch(WindowEvent::PerformKeyAssignment(action)); } } - Some(RepresentedItem::OpenInBrowser(url)) => { - if let Some(this) = Self::get_this(this) { - this.inner - .borrow_mut() - .events - .dispatch(WindowEvent::OpenInBrowser(url)); - } - } None => {} } }