macos: link to helpful resources from Help menu
This commit is contained in:
10 files changed
+59
-1
No files matched your search
@@ -65,7 +65,7 @@ metrics = { version="0.17", features=["std"]}
|
||||
mlua = {version="0.8.3", features=["send"]}
|
||||
mux = { path = "../mux" }
|
||||
mux-lua = { path = "../lua-api-crates/mux" }
|
||||
open = "3.0"
|
||||
open = "3.2"
|
||||
ordered-float = "3.0"
|
||||
parking_lot = "0.12"
|
||||
portable-pty = { path = "../pty", features = ["serde_support"]}
|
||||
|
||||
@@ -235,6 +235,30 @@ impl CommandDef {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,13 @@ impl GuiFrontEnd {
|
||||
// future.
|
||||
log::info!("perform: {action:?}");
|
||||
}
|
||||
ApplicationEvent::OpenInBrowser(url) => {
|
||||
std::thread::spawn(move || {
|
||||
if let Err(err) = open::that(&url) {
|
||||
log::error!("Error opening {}: {:#}", url, err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -879,6 +879,14 @@ 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)
|
||||
|
||||
@@ -85,6 +85,7 @@ impl MyWindow {
|
||||
| WindowEvent::DraggedFile(_)
|
||||
| WindowEvent::DroppedFile(_)
|
||||
| WindowEvent::PerformKeyAssignment(_)
|
||||
| WindowEvent::OpenInBrowser(_)
|
||||
| WindowEvent::MouseLeave => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ 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 {
|
||||
|
||||
@@ -189,6 +189,8 @@ 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 {
|
||||
|
||||
@@ -53,6 +53,11 @@ 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 => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ pub struct MenuItem {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum RepresentedItem {
|
||||
KeyAssignment(KeyAssignment),
|
||||
OpenInBrowser(String),
|
||||
}
|
||||
|
||||
impl MenuItem {
|
||||
|
||||
@@ -1922,6 +1922,14 @@ 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 => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user