make item id optional as queued for database insert, rename item constructor, add comments

This commit is contained in:
yggverse 2025-03-11 15:15:28 +02:00
parent 841bb171bd
commit 0bd7131937
2 changed files with 12 additions and 4 deletions

View file

@ -30,7 +30,7 @@ impl History {
pub fn open(&self, request: GString, title: Option<GString>) { pub fn open(&self, request: GString, title: Option<GString>) {
let mut memory = self.memory.borrow_mut(); let mut memory = self.memory.borrow_mut();
if !memory.open(&request) { if !memory.open(&request) {
memory.add(Item::create(0, request, title)) // @TODO memory.add(Item::init(request, title))
} }
} }

View file

@ -2,19 +2,27 @@ use gtk::glib::{DateTime, GString};
#[derive(Clone)] #[derive(Clone)]
pub struct Item { pub struct Item {
pub id: i64, /// Queued for DB insert on value is `None` (e.g. on app close)
pub id: Option<i64>,
/// The value for navigation request entry
pub request: GString, pub request: GString,
/// Some history items may contain title (e.g. gemtext documents and system tabs)
/// * used as the additional criteria for search in the navbar suggestions widget
pub title: Option<GString>, pub title: Option<GString>,
/// Collect opened count with event time
/// * used for sort order search results in the navbar suggestions widget
pub opened: Vec<DateTime>, pub opened: Vec<DateTime>,
/// Collect tab closed count with event time
/// * used in recently closed pages menu
pub closed: Vec<DateTime>, pub closed: Vec<DateTime>,
} }
impl Item { impl Item {
// Constructors // Constructors
pub fn create(id: i64, request: GString, title: Option<GString>) -> Self { pub fn init(request: GString, title: Option<GString>) -> Self {
Self { Self {
id, id: None,
request, request,
title, title,
opened: vec![now()], opened: vec![now()],