Open history and settings pages
This commit is contained in:
@@ -14,7 +14,9 @@ actions!(
|
||||
FocusAddressBar,
|
||||
FocusCommandMode,
|
||||
OpenDownloads,
|
||||
OpenHistory,
|
||||
OpenNewTab,
|
||||
OpenSettings,
|
||||
Quit,
|
||||
RestoreClosedTab,
|
||||
SelectNextTab,
|
||||
@@ -33,6 +35,10 @@ fn main() {
|
||||
KeyBinding::new("ctrl-t", OpenNewTab, None),
|
||||
KeyBinding::new("cmd-shift-j", OpenDownloads, None),
|
||||
KeyBinding::new("ctrl-shift-j", OpenDownloads, None),
|
||||
KeyBinding::new("cmd-y", OpenHistory, None),
|
||||
KeyBinding::new("ctrl-h", OpenHistory, None),
|
||||
KeyBinding::new("cmd-,", OpenSettings, None),
|
||||
KeyBinding::new("ctrl-,", OpenSettings, None),
|
||||
KeyBinding::new("cmd-l", FocusAddressBar, None),
|
||||
KeyBinding::new("ctrl-l", FocusAddressBar, None),
|
||||
KeyBinding::new("cmd-w", CloseCurrentTab, None),
|
||||
@@ -70,6 +76,8 @@ fn main() {
|
||||
MenuItem::action("Restore Closed Tab", RestoreClosedTab),
|
||||
MenuItem::separator(),
|
||||
MenuItem::action("Open Downloads", OpenDownloads),
|
||||
MenuItem::action("Open History", OpenHistory),
|
||||
MenuItem::action("Open Settings", OpenSettings),
|
||||
MenuItem::separator(),
|
||||
MenuItem::action("Toggle Pin", TogglePinnedTab),
|
||||
],
|
||||
|
||||
@@ -6,8 +6,9 @@ use gpui::{App, AppContext, Context, Entity, FocusHandle, Focusable, Subscriptio
|
||||
use gpui_component::input::{InputEvent, InputState, SelectAll};
|
||||
|
||||
use crate::{
|
||||
CloseCurrentTab, FocusAddressBar, FocusCommandMode, OpenDownloads, OpenNewTab,
|
||||
RestoreClosedTab, SelectNextTab, SelectPreviousTab, ToggleFavoriteTab, TogglePinnedTab,
|
||||
CloseCurrentTab, FocusAddressBar, FocusCommandMode, OpenDownloads, OpenHistory, OpenNewTab,
|
||||
OpenSettings, RestoreClosedTab, SelectNextTab, SelectPreviousTab, ToggleFavoriteTab,
|
||||
TogglePinnedTab,
|
||||
};
|
||||
|
||||
enum ShellState {
|
||||
@@ -80,19 +81,24 @@ impl ElyShell {
|
||||
}
|
||||
|
||||
fn open_new_tab(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& let Ok(url) = UrlText::parse("ely://new-tab")
|
||||
{
|
||||
core.open_tab(url);
|
||||
self.sync_address_input(window, cx);
|
||||
self.focus_address_bar(window, cx);
|
||||
cx.notify();
|
||||
}
|
||||
self.open_internal_tab("ely://new-tab", window, cx);
|
||||
}
|
||||
|
||||
fn open_downloads(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.open_internal_tab("ely://downloads", window, cx);
|
||||
}
|
||||
|
||||
fn open_history(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.open_internal_tab("ely://history", window, cx);
|
||||
}
|
||||
|
||||
fn open_settings(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.open_internal_tab("ely://settings", window, cx);
|
||||
}
|
||||
|
||||
fn open_internal_tab(&mut self, url_text: &str, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& let Ok(url) = UrlText::parse("ely://downloads")
|
||||
&& let Ok(url) = UrlText::parse(url_text)
|
||||
{
|
||||
core.open_tab(url);
|
||||
self.sync_address_input(window, cx);
|
||||
@@ -244,6 +250,14 @@ impl ElyShell {
|
||||
self.open_downloads(window, cx);
|
||||
}
|
||||
|
||||
fn on_open_history(&mut self, _: &OpenHistory, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.open_history(window, cx);
|
||||
}
|
||||
|
||||
fn on_open_settings(&mut self, _: &OpenSettings, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.open_settings(window, cx);
|
||||
}
|
||||
|
||||
fn on_restore_closed_tab(
|
||||
&mut self,
|
||||
_: &RestoreClosedTab,
|
||||
|
||||
@@ -39,7 +39,9 @@ impl ElyShell {
|
||||
.on_action(cx.listener(Self::on_focus_address_bar))
|
||||
.on_action(cx.listener(Self::on_focus_command_mode))
|
||||
.on_action(cx.listener(Self::on_open_downloads))
|
||||
.on_action(cx.listener(Self::on_open_history))
|
||||
.on_action(cx.listener(Self::on_open_new_tab))
|
||||
.on_action(cx.listener(Self::on_open_settings))
|
||||
.on_action(cx.listener(Self::on_restore_closed_tab))
|
||||
.on_action(cx.listener(Self::on_select_next_tab))
|
||||
.on_action(cx.listener(Self::on_select_previous_tab))
|
||||
|
||||
@@ -17,6 +17,8 @@ fn internal_page_title(url: &str) -> Option<&'static str> {
|
||||
match url {
|
||||
"ely://new-tab" => Some("New Tab"),
|
||||
"ely://downloads" => Some("Downloads"),
|
||||
"ely://history" => Some("History"),
|
||||
"ely://settings" => Some("Settings"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -69,5 +71,17 @@ pub(crate) fn search_url(query: &str) -> Result<UrlText, CoreError> {
|
||||
}
|
||||
|
||||
pub(crate) fn downloads_url() -> Result<UrlText, CoreError> {
|
||||
UrlText::parse("ely://downloads").map_err(CoreError::from)
|
||||
internal_page_url("ely://downloads")
|
||||
}
|
||||
|
||||
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://history")
|
||||
}
|
||||
|
||||
pub(crate) fn settings_url() -> Result<UrlText, CoreError> {
|
||||
internal_page_url("ely://settings")
|
||||
}
|
||||
|
||||
fn internal_page_url(value: &str) -> Result<UrlText, CoreError> {
|
||||
UrlText::parse(value).map_err(CoreError::from)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use ely_domain::{CommandIntent, CommandScope, ProfileId, ProfileKind, SpaceId};
|
||||
use crate::{
|
||||
CoreError,
|
||||
navigation::{
|
||||
downloads_url, move_tab_space_name, new_profile_name, new_space_name, search_url,
|
||||
space_icon, switch_profile_name,
|
||||
downloads_url, history_url, move_tab_space_name, new_profile_name, new_space_name,
|
||||
search_url, settings_url, space_icon, switch_profile_name,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -89,6 +89,14 @@ impl BrowserCore {
|
||||
self.open_tab(downloads_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"history" | "open-history" | "open history" => {
|
||||
self.open_tab(history_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"settings" | "open-settings" | "open settings" => {
|
||||
self.open_tab(settings_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"close-tab" => {
|
||||
self.close_active_tab()?;
|
||||
Ok(true)
|
||||
|
||||
@@ -66,6 +66,36 @@ fn open_downloads_command_opens_downloads_page() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_history_command_opens_history_page() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
core.set_command_query(">open-history");
|
||||
let intent = core.submit_command()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("open-history".to_string())));
|
||||
assert_eq!(active_tab.title(), "History");
|
||||
assert_eq!(active_tab.url().as_str(), "ely://history");
|
||||
assert_eq!(core.snapshot()?.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_settings_command_opens_settings_page() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
core.set_command_query(">open-settings");
|
||||
let intent = core.submit_command()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("open-settings".to_string())));
|
||||
assert_eq!(active_tab.title(), "Settings");
|
||||
assert_eq!(active_tab.url().as_str(), "ely://settings");
|
||||
assert_eq!(core.snapshot()?.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_space_command_creates_and_selects_named_space() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user