diff --git a/README.md b/README.md index d8cfc3e..481cb18 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ fn run() -> (IcyBrowser, Task) { IcyBrowser::new() .with_tab_bar() .with_nav_bar() - .with_bookmark_bar(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")]) + .bookmarks(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")]) + .with_bookmark_bar() .build(), Task::none(), ) diff --git a/examples/basic_browser.rs b/examples/basic_browser.rs index ee8d680..c9f01fe 100644 --- a/examples/basic_browser.rs +++ b/examples/basic_browser.rs @@ -8,7 +8,8 @@ fn run() -> (IcyBrowser, Task) { IcyBrowser::new() .with_tab_bar() .with_nav_bar() - .with_bookmark_bar(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")]) + .bookmarks(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")]) + .with_bookmark_bar() .build(), Task::none(), ) diff --git a/examples/keyboard_driven.rs b/examples/keyboard_driven.rs index c171250..3efe10a 100644 --- a/examples/keyboard_driven.rs +++ b/examples/keyboard_driven.rs @@ -50,7 +50,7 @@ impl Default for Browser { let widgets = IcyBrowser::new() .with_custom_shortcuts(shortcuts) .with_tab_bar() - .with_bookmark_bar(&[ + .bookmarks(&[ Bookmark::new("https://www.rust-lang.org", "rust-lang.org"), Bookmark::new( "https://github.com/LegitCamper/icy_browser", @@ -58,6 +58,7 @@ impl Default for Browser { ), Bookmark::new("https://docs.rs/iced/latest/iced/", "iced docs"), ]) + .with_bookmark_bar() .build(); Self { diff --git a/src/engines/ultralight.rs b/src/engines/ultralight.rs index fbd43f8..f39a6b8 100644 --- a/src/engines/ultralight.rs +++ b/src/engines/ultralight.rs @@ -874,7 +874,7 @@ fn iced_key_to_ultralight_key( #[cfg(windows)] 189, #[cfg(unix)] - 12, + 74, ), "+" => ( VirtualKeyCode::OemPlus, diff --git a/src/widgets/command_palatte.rs b/src/widgets/command_palatte.rs index 97624c6..d24aea5 100644 --- a/src/widgets/command_palatte.rs +++ b/src/widgets/command_palatte.rs @@ -17,7 +17,7 @@ impl ResultType { pub fn inner_name(&self) -> String { match self { ResultType::Commands(command) => command.to_string(), - ResultType::Bookmarks(bookmark) => format!("Go to: {}", bookmark.url()), + ResultType::Bookmarks(bookmark) => format!("{} -> {}", bookmark.name(), bookmark.url()), } } } @@ -40,6 +40,17 @@ impl CommandWindowState { Message::Refresh, Message::GoHome, Message::CloseCurrentTab, + Message::CreateTab, + Message::HideOverlay, + Message::ToggleTabBar, + Message::ShowTabBar, + Message::HideTabBar, + Message::ToggleNavBar, + Message::ShowNavBar, + Message::HideNavBar, + Message::ToggleBookmarkBar, + Message::ShowBookmarkBar, + Message::HideBookmarkBar, ] .into_iter() .map(ResultType::Commands), diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 40ef06f..1a6f86d 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -67,6 +67,24 @@ pub enum Message { ShowOverlay, #[strum(to_string = "Hide Command Palatte")] HideOverlay, + #[strum(to_string = "Toggle Tab Bar")] + ToggleTabBar, + #[strum(to_string = "Show Tab Bar")] + ShowTabBar, + #[strum(to_string = "Hide Tab Bar")] + HideTabBar, + #[strum(to_string = "Toggle Nav Bar")] + ToggleNavBar, + #[strum(to_string = "Show Nav Bar")] + ShowNavBar, + #[strum(to_string = "Hide Nav Bar")] + HideNavBar, + #[strum(to_string = "Toggle Bookmark Bar")] + ToggleBookmarkBar, + #[strum(to_string = "Show Bookmark Bar")] + ShowBookmarkBar, + #[strum(to_string = "Hide Bookmark Bar")] + HideBookmarkBar, // Internal only - for widgets Update, @@ -95,10 +113,11 @@ impl Default for TabSelectionType { pub struct IcyBrowser { engine: Engine, home: Url, - nav_bar_state: Option, + nav_bar_state: NavBarState, command_window_state: CommandWindowState, with_tab_bar: bool, with_nav_bar: bool, + with_bookmark_bar: bool, bookmarks: Option, show_overlay: bool, shortcuts: Shortcuts, @@ -111,10 +130,11 @@ impl Default for IcyBrowser { Self { engine: Engine::new(), home, - nav_bar_state: None, + nav_bar_state: NavBarState::new(), command_window_state: CommandWindowState::new(None), with_tab_bar: false, with_nav_bar: false, + with_bookmark_bar: false, bookmarks: None, show_overlay: false, shortcuts: Shortcuts::default(), @@ -142,16 +162,21 @@ impl IcyBrowser { pub fn with_nav_bar(mut self) -> Self { self.with_nav_bar = true; - self.nav_bar_state = Some(NavBarState::new()); + self.nav_bar_state = NavBarState::new(); self } - pub fn with_bookmark_bar(mut self, bookmarks: &[Bookmark]) -> Self { + pub fn bookmarks(mut self, bookmarks: &[Bookmark]) -> Self { self.bookmarks = Some(bookmarks.to_vec()); self.command_window_state = CommandWindowState::new(self.bookmarks.clone()); self } + pub fn with_bookmark_bar(mut self) -> Self { + self.with_bookmark_bar = true; + self + } + pub fn with_custom_shortcuts(mut self, shortcuts: Shortcuts) -> Self { self.shortcuts = shortcuts; self @@ -235,9 +260,7 @@ impl IcyBrowser { TabSelectionType::Index(index) => self.engine.get_tabs().index_to_id(index), }; self.engine.get_tabs_mut().set_current_id(id); - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.engine.get_tabs().get_current().url(); - } + self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); Task::none() } Message::CloseCurrentTab => Task::done(Message::CloseTab(TabSelectionType::Id( @@ -254,15 +277,11 @@ impl IcyBrowser { TabSelectionType::Index(index) => self.engine.get_tabs().index_to_id(index), }; self.engine.get_tabs_mut().remove(id); - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.engine.get_tabs().get_current().url(); - } + self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); Task::none() } Message::CreateTab => { - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.home.to_string(); - } + self.nav_bar_state.0 = self.home.to_string(); let home = self.home.clone(); let bounds = self.view_size; let tab = self.engine.new_tab( @@ -278,16 +297,12 @@ impl IcyBrowser { } Message::GoBackward => { self.engine.go_back(); - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.engine.get_tabs().get_current().url(); - } + self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); Task::none() } Message::GoForward => { self.engine.go_forward(); - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.engine.get_tabs().get_current().url(); - } + self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); Task::none() } Message::Refresh => { @@ -303,17 +318,61 @@ impl IcyBrowser { Task::none() } Message::UpdateUrl => { - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = self.engine.get_tabs().get_current().url(); - } + self.nav_bar_state.0 = self.engine.get_tabs().get_current().url(); Task::none() } Message::UrlChanged(url) => { - if let Some(state) = self.nav_bar_state.as_mut() { - state.0 = url; + self.nav_bar_state.0 = url; + Task::none() + } + Message::ToggleTabBar => { + if self.with_tab_bar { + self.with_tab_bar = false; + } else { + self.with_tab_bar = true; } Task::none() } + Message::ShowTabBar => { + self.with_tab_bar = true; + Task::none() + } + Message::HideTabBar => { + self.with_tab_bar = false; + Task::none() + } + Message::ToggleNavBar => { + if self.with_nav_bar { + self.with_nav_bar = false; + } else { + self.with_nav_bar = true; + } + Task::none() + } + Message::ShowNavBar => { + self.with_nav_bar = true; + Task::none() + } + Message::HideNavBar => { + self.with_nav_bar = false; + Task::none() + } + Message::ToggleBookmarkBar => { + if self.with_bookmark_bar { + self.with_bookmark_bar = false; + } else { + self.with_bookmark_bar = true; + } + Task::none() + } + Message::ShowBookmarkBar => { + self.with_bookmark_bar = true; + Task::none() + } + Message::HideBookmarkBar => { + self.with_bookmark_bar = false; + Task::none() + } Message::CommandPalatteQueryChanged(query) => { self.command_window_state.query = query.clone(); self.command_window_state.filtered_results = self @@ -501,13 +560,13 @@ impl IcyBrowser { column = column.push(tab_bar(self.engine.get_tabs())) } if self.with_nav_bar { - column = column.push( - hoverable(nav_bar(self.nav_bar_state.as_ref().unwrap())) - .on_focus_change(Message::UpdateUrl), - ) + column = column + .push(hoverable(nav_bar(&self.nav_bar_state)).on_focus_change(Message::UpdateUrl)) } - if let Some(bookmarks) = self.bookmarks.as_ref() { - column = column.push(bookmark_bar(bookmarks)) + if self.with_bookmark_bar { + if let Some(bookmarks) = self.bookmarks.as_ref() { + column = column.push(bookmark_bar(bookmarks)) + } } let browser_view = browser_view(self.engine.get_tabs().get_current().get_view());