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({
let tab = tab.clone();
move |position| {
if tab.bookmark(position).is_err() {
todo!()
}
}
move |position| tab.bookmark(position)
});
action.pin.connect_activate({

View File

@ -1,6 +1,5 @@
mod action;
mod database;
mod error;
mod item;
mod menu;
@ -9,7 +8,6 @@ use crate::Profile;
use action::Action;
use adw::{TabPage, TabView};
use anyhow::Result;
use error::Error;
use gtk::{
gio::Icon,
glib::{DateTime, Propagation},
@ -257,16 +255,11 @@ impl Tab {
}
}
/// Toggle `Bookmark` in current `Profile` 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>) -> Result<bool, Error> {
/// Toggle `Bookmark` for `Page` at given `position` (current page on `None`)
pub fn bookmark(&self, page_position: Option<i32>) {
if let Some(item) = self.item(page_position) {
return match item.page.bookmark() {
Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark),
};
item.page.bookmark()
}
Err(Error::PageNotFound)
}
/// 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 database;
mod error;
mod input;
mod navigation;
mod search;
@ -9,7 +8,6 @@ use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowActio
use adw::TabPage;
use anyhow::Result;
use content::Content;
use error::Error;
use input::Input;
use navigation::Navigation;
use search::Search;
@ -76,18 +74,12 @@ impl Page {
// Actions
/// Toggle bookmark for current `profile` by navigation request value
/// * return `true` on bookmark created, `false` on deleted
pub fn bookmark(&self) -> Result<bool, Error> {
let result = match self
.profile
/// Toggle bookmark for current navigation request
pub fn bookmark(&self) {
self.profile
.bookmark
.toggle(self.navigation.request().as_str())
{
Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark), // @TODO
};
result
.toggle(&self.navigation.request())
.unwrap(); // @TODO
}
/// Request `Escape` action for all page components

View File

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