update bookmarks handler

This commit is contained in:
yggverse 2025-03-08 11:33:16 +02:00
parent f150e716b9
commit a874bd8106
5 changed files with 9 additions and 37 deletions

View file

@ -48,11 +48,7 @@ impl Window {
action.bookmark.connect_activate({ action.bookmark.connect_activate({
let tab = tab.clone(); let tab = tab.clone();
move |position| { move |position| tab.bookmark(position)
if tab.bookmark(position).is_err() {
todo!()
}
}
}); });
action.pin.connect_activate({ action.pin.connect_activate({

View file

@ -1,6 +1,5 @@
mod action; mod action;
mod database; mod database;
mod error;
mod item; mod item;
mod menu; mod menu;
@ -9,7 +8,6 @@ use crate::Profile;
use action::Action; use action::Action;
use adw::{TabPage, TabView}; use adw::{TabPage, TabView};
use anyhow::Result; use anyhow::Result;
use error::Error;
use gtk::{ use gtk::{
gio::Icon, gio::Icon,
glib::{DateTime, Propagation}, glib::{DateTime, Propagation},
@ -257,16 +255,11 @@ impl Tab {
} }
} }
/// Toggle `Bookmark` in current `Profile` for `Page` at given `position` (current page on `None`) /// Toggle `Bookmark` for `Page` at given `position` (current page on `None`)
/// * return `true` on bookmark created, `false` on deleted; `Error` otherwise. pub fn bookmark(&self, page_position: Option<i32>) {
pub fn bookmark(&self, page_position: Option<i32>) -> Result<bool, Error> {
if let Some(item) = self.item(page_position) { if let Some(item) = self.item(page_position) {
return match item.page.bookmark() { item.page.bookmark()
Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark),
};
} }
Err(Error::PageNotFound)
} }
/// Toggle pin for page at given `position`, `None` to pin selected page (if available) /// Toggle pin for page at given `position`, `None` to pin selected page (if available)

View file

@ -1,5 +0,0 @@
#[derive(Debug)]
pub enum Error {
Bookmark,
PageNotFound,
}

View file

@ -1,6 +1,5 @@
mod content; mod content;
mod database; mod database;
mod error;
mod input; mod input;
mod navigation; mod navigation;
mod search; mod search;
@ -9,7 +8,6 @@ use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowActio
use adw::TabPage; use adw::TabPage;
use anyhow::Result; use anyhow::Result;
use content::Content; use content::Content;
use error::Error;
use input::Input; use input::Input;
use navigation::Navigation; use navigation::Navigation;
use search::Search; use search::Search;
@ -76,18 +74,12 @@ impl Page {
// Actions // Actions
/// Toggle bookmark for current `profile` by navigation request value /// Toggle bookmark for current navigation request
/// * return `true` on bookmark created, `false` on deleted pub fn bookmark(&self) {
pub fn bookmark(&self) -> Result<bool, Error> { self.profile
let result = match self
.profile
.bookmark .bookmark
.toggle(self.navigation.request().as_str()) .toggle(&self.navigation.request())
{ .unwrap(); // @TODO
Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark), // @TODO
};
result
} }
/// Request `Escape` action for all page components /// Request `Escape` action for all page components

View file

@ -1,4 +0,0 @@
#[derive(Debug)]
pub enum Error {
Bookmark,
}