mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement tab session db actions
This commit is contained in:
parent
68d0798aea
commit
82d8dff95d
@ -48,10 +48,7 @@ impl Database {
|
|||||||
app_browser_id,
|
app_browser_id,
|
||||||
&(*default_width as i64),
|
&(*default_width as i64),
|
||||||
&(*default_height as i64),
|
&(*default_height as i64),
|
||||||
match is_maximized {
|
&(*is_maximized as i64),
|
||||||
true => &1,
|
|
||||||
false => &0,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,12 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Init empty HashMap index as no tabs appended yet
|
||||||
|
let index = RefCell::new(HashMap::new());
|
||||||
|
|
||||||
|
// Init widget
|
||||||
|
let widget = Arc::new(Widget::new());
|
||||||
|
|
||||||
// Return non activated struct
|
// Return non activated struct
|
||||||
Self {
|
Self {
|
||||||
database,
|
database,
|
||||||
@ -90,9 +96,9 @@ impl Tab {
|
|||||||
action_tab_page_navigation_reload,
|
action_tab_page_navigation_reload,
|
||||||
action_update,
|
action_update,
|
||||||
// Init empty HashMap index as no tabs appended yet
|
// Init empty HashMap index as no tabs appended yet
|
||||||
index: RefCell::new(HashMap::new()),
|
index,
|
||||||
// GTK
|
// GTK
|
||||||
widget: Arc::new(Widget::new()),
|
widget,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +260,7 @@ impl Tab {
|
|||||||
match self.database.records(tx, app_browser_window_id) {
|
match self.database.records(tx, app_browser_window_id) {
|
||||||
Ok(records) => {
|
Ok(records) => {
|
||||||
for record in records {
|
for record in records {
|
||||||
self.append(None, true /*@ TODO record.is_current_page */);
|
self.append(None, record.is_current);
|
||||||
// Delegate restore action to childs
|
// Delegate restore action to childs
|
||||||
// nothing yet..
|
// nothing yet..
|
||||||
}
|
}
|
||||||
@ -264,16 +270,29 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self, tx: &Transaction, app_browser_window_id: &i64) {
|
pub fn save(&self, tx: &Transaction, app_browser_window_id: &i64) {
|
||||||
for (id, item) in self.index.take().iter() {
|
let mut page_number = 0;
|
||||||
match self.database.add(tx, app_browser_window_id) {
|
|
||||||
|
for (_, _) in self.index.take().iter() {
|
||||||
|
match self.database.add(
|
||||||
|
tx,
|
||||||
|
app_browser_window_id,
|
||||||
|
&match self.widget.gobject().current_page() {
|
||||||
|
Some(number) => number == page_number,
|
||||||
|
None => false,
|
||||||
|
},
|
||||||
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Delegate save action to childs
|
// Delegate save action to childs
|
||||||
let id = self.database.last_insert_id(tx);
|
// let id = self.database.last_insert_id(tx);
|
||||||
|
|
||||||
|
// @TODO
|
||||||
// item.label.save()
|
// item.label.save()
|
||||||
// item.page.save()
|
// item.page.save()
|
||||||
}
|
}
|
||||||
Err(e) => todo!("{e}"),
|
Err(e) => todo!("{e}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page_number += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ use sqlite::{Error, Transaction};
|
|||||||
pub struct Table {
|
pub struct Table {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
// pub app_browser_window_id: i64, not in use
|
// pub app_browser_window_id: i64, not in use
|
||||||
|
pub is_current: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
@ -15,7 +16,8 @@ impl Database {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`app_browser_window_id` INTEGER NOT NULL
|
`app_browser_window_id` INTEGER NOT NULL,
|
||||||
|
`is_current` INTEGER NOT NULL
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)?;
|
||||||
@ -23,10 +25,18 @@ impl Database {
|
|||||||
Ok(Self {})
|
Ok(Self {})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&self, tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> {
|
pub fn add(
|
||||||
|
&self,
|
||||||
|
tx: &Transaction,
|
||||||
|
app_browser_window_id: &i64,
|
||||||
|
is_current: &bool,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT INTO `app_browser_window_tab` (`app_browser_window_id`) VALUES (?)",
|
"INSERT INTO `app_browser_window_tab` (
|
||||||
[app_browser_window_id],
|
`app_browser_window_id`,
|
||||||
|
`is_current`
|
||||||
|
) VALUES (?,?)",
|
||||||
|
[app_browser_window_id, &(*is_current as i64)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,14 +45,18 @@ impl Database {
|
|||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
app_browser_window_id: &i64,
|
app_browser_window_id: &i64,
|
||||||
) -> Result<Vec<Table>, Error> {
|
) -> Result<Vec<Table>, Error> {
|
||||||
let mut stmt = tx.prepare("SELECT `id`,
|
let mut stmt = tx.prepare(
|
||||||
`app_browser_window_id` FROM `app_browser_window_tab`
|
"SELECT `id`,
|
||||||
WHERE `app_browser_window_id` = ?")?;
|
`app_browser_window_id`,
|
||||||
|
`is_current` FROM `app_browser_window_tab`
|
||||||
|
WHERE `app_browser_window_id` = ?",
|
||||||
|
)?;
|
||||||
|
|
||||||
let result = stmt.query_map([app_browser_window_id], |row| {
|
let result = stmt.query_map([app_browser_window_id], |row| {
|
||||||
Ok(Table {
|
Ok(Table {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
// app_browser_window_id: row.get(1)?, not in use
|
// app_browser_window_id: row.get(1)?, not in use
|
||||||
|
is_current: row.get(2)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -60,7 +74,8 @@ impl Database {
|
|||||||
tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id])
|
tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* not in use
|
||||||
pub fn last_insert_id(&self, tx: &Transaction) -> i64 {
|
pub fn last_insert_id(&self, tx: &Transaction) -> i64 {
|
||||||
tx.last_insert_rowid()
|
tx.last_insert_rowid()
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ pub struct Widget {
|
|||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let gobject = Notebook::builder().scrollable(true).build();
|
Self {
|
||||||
|
gobject: Notebook::builder().scrollable(true).build(),
|
||||||
Self { gobject }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user