move OpenInBrowser -> KeyAssignment

This allows defining those help actions that open URLs in the main
commands list, and not just for the macOS Help menu.

refs: https://github.com/wez/wezterm/issues/1485
This commit is contained in:
Wez Furlong committed 2022-12-21 07:04:51 -07:00
1 parent 4b3660d166
commit 37b5dd91a5
10 files changed
+43 -64

No files matched your search

+1
View File
@@ -535,6 +535,7 @@ pub enum KeyAssignment {
CharSelect(CharSelectArguments),
ResetTerminal,
OpenUri(String),
}
impl_lua_conversion_dynamic!(KeyAssignment);
+34 -30
View File
@@ -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"],
},
];
-7
View File
@@ -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);
}
});
}
}
}
+8 -8
View File
@@ -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)
}
-1
View File
@@ -85,7 +85,6 @@ impl MyWindow {
| WindowEvent::DraggedFile(_)
| WindowEvent::DroppedFile(_)
| WindowEvent::PerformKeyAssignment(_)
| WindowEvent::OpenInBrowser(_)
| WindowEvent::MouseLeave => {}
}
}
-2
View File
@@ -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 {
-2
View File
@@ -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 {
-5
View File
@@ -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 => {}
}
}
-1
View File
@@ -111,7 +111,6 @@ pub struct MenuItem {
#[derive(Clone, Debug)]
pub enum RepresentedItem {
KeyAssignment(KeyAssignment),
OpenInBrowser(String),
}
impl MenuItem {
-8
View File
@@ -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 => {}
}
}