mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-11 02:44:15 +00:00
implement navigation session restore
This commit is contained in:
parent
ac14f5dea7
commit
d7b781f604
@ -467,7 +467,7 @@ impl Page {
|
|||||||
match Database::delete(transaction, &record.id) {
|
match Database::delete(transaction, &record.id) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Delegate clean action to the item childs
|
// Delegate clean action to the item childs
|
||||||
// nothing yet..
|
self.navigation.clean(transaction, &record.id)?;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
}
|
}
|
||||||
@ -486,9 +486,9 @@ impl Page {
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match Database::records(transaction, app_browser_window_tab_item_id) {
|
match Database::records(transaction, app_browser_window_tab_item_id) {
|
||||||
Ok(records) => {
|
Ok(records) => {
|
||||||
for _record in records {
|
for record in records {
|
||||||
// Delegate restore action to the item childs
|
// Delegate restore action to the item childs
|
||||||
// nothing yet..
|
self.navigation.restore(transaction, &record.id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
@ -504,10 +504,10 @@ impl Page {
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match Database::add(transaction, app_browser_window_tab_item_id) {
|
match Database::add(transaction, app_browser_window_tab_item_id) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// let id = Database::last_insert_id(transaction);
|
let id = Database::last_insert_id(transaction);
|
||||||
|
|
||||||
// Delegate save action to childs
|
// Delegate save action to childs
|
||||||
// nothing yet..
|
self.navigation.save(transaction, &id)?;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
}
|
}
|
||||||
@ -546,12 +546,12 @@ impl Page {
|
|||||||
// Tools
|
// Tools
|
||||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||||
// Migrate self components
|
// Migrate self components
|
||||||
if let Err(e) = Database::init(&tx) {
|
if let Err(e) = Database::init(tx) {
|
||||||
return Err(e.to_string());
|
return Err(e.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delegate migration to childs
|
// Delegate migration to childs
|
||||||
// nothing yet..
|
Navigation::migrate(tx)?;
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -65,8 +65,7 @@ impl Database {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not in use
|
|
||||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||||
tx.last_insert_rowid()
|
tx.last_insert_rowid()
|
||||||
} */
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
mod base;
|
mod base;
|
||||||
mod bookmark;
|
mod bookmark;
|
||||||
|
mod database;
|
||||||
mod history;
|
mod history;
|
||||||
mod reload;
|
mod reload;
|
||||||
mod request;
|
mod request;
|
||||||
|
|
||||||
use base::Base;
|
use base::Base;
|
||||||
use bookmark::Bookmark;
|
use bookmark::Bookmark;
|
||||||
|
use database::Database;
|
||||||
use history::History;
|
use history::History;
|
||||||
use reload::Reload;
|
use reload::Reload;
|
||||||
use request::Request;
|
use request::Request;
|
||||||
@ -16,6 +18,7 @@ use gtk::{
|
|||||||
prelude::{BoxExt, WidgetExt},
|
prelude::{BoxExt, WidgetExt},
|
||||||
Box, DirectionType, Orientation,
|
Box, DirectionType, Orientation,
|
||||||
};
|
};
|
||||||
|
use sqlite::Transaction;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -106,6 +109,65 @@ impl Navigation {
|
|||||||
self.bookmark.update();
|
self.bookmark.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clean(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match Database::records(transaction, app_browser_window_tab_item_page_id) {
|
||||||
|
Ok(records) => {
|
||||||
|
for record in records {
|
||||||
|
match Database::delete(transaction, &record.id) {
|
||||||
|
Ok(_) => {
|
||||||
|
// Delegate clean action to the item childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn restore(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match Database::records(transaction, app_browser_window_tab_item_page_id) {
|
||||||
|
Ok(records) => {
|
||||||
|
for _record in records {
|
||||||
|
// Delegate restore action to the item childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match Database::add(transaction, app_browser_window_tab_item_page_id) {
|
||||||
|
Ok(_) => {
|
||||||
|
// let id = Database::last_insert_id(transaction);
|
||||||
|
|
||||||
|
// Delegate save action to childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
pub fn set_request_text(&self, value: &GString) {
|
pub fn set_request_text(&self, value: &GString) {
|
||||||
// Focus out from content area on activate the link @TODO
|
// Focus out from content area on activate the link @TODO
|
||||||
@ -126,4 +188,18 @@ impl Navigation {
|
|||||||
pub fn request_text(&self) -> GString {
|
pub fn request_text(&self) -> GString {
|
||||||
self.request.text()
|
self.request.text()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tools
|
||||||
|
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||||
|
// Migrate self components
|
||||||
|
if let Err(e) = Database::init(&tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegate migration to childs
|
||||||
|
// nothing yet..
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
75
src/app/browser/window/tab/item/page/navigation/database.rs
Normal file
75
src/app/browser/window/tab/item/page/navigation/database.rs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
use sqlite::{Error, Transaction};
|
||||||
|
|
||||||
|
pub struct Table {
|
||||||
|
pub id: i64,
|
||||||
|
// pub app_browser_window_tab_item_page_id: i64, not in use
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Database {
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation`
|
||||||
|
(
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`app_browser_window_tab_item_page_id` INTEGER NOT NULL
|
||||||
|
)",
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add(
|
||||||
|
tx: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_id: &i64,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"INSERT INTO `app_browser_window_tab_item_page_navigation` (
|
||||||
|
`app_browser_window_tab_item_page_id`
|
||||||
|
) VALUES (?)",
|
||||||
|
[app_browser_window_tab_item_page_id],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn records(
|
||||||
|
tx: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_id: &i64,
|
||||||
|
) -> Result<Vec<Table>, Error> {
|
||||||
|
let mut stmt = tx.prepare(
|
||||||
|
"SELECT `id`,
|
||||||
|
`app_browser_window_tab_item_page_id`
|
||||||
|
FROM `app_browser_window_tab_item_page_navigation`
|
||||||
|
WHERE `app_browser_window_tab_item_page_id` = ?",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| {
|
||||||
|
Ok(Table {
|
||||||
|
id: row.get(0)?,
|
||||||
|
// app_browser_window_tab_item_page_id: row.get(1)?, not in use
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut records = Vec::new();
|
||||||
|
|
||||||
|
for record in result {
|
||||||
|
let table = record?;
|
||||||
|
records.push(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(records)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?",
|
||||||
|
[id],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not in use
|
||||||
|
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||||
|
tx.last_insert_rowid()
|
||||||
|
} */
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user