mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
use anyhow crate, return id on insert
This commit is contained in:
parent
e859b97d79
commit
5effd63575
42 changed files with 496 additions and 1164 deletions
|
|
@ -11,6 +11,7 @@ use window::Window;
|
|||
|
||||
use crate::Profile;
|
||||
use adw::{prelude::AdwDialogExt, AboutDialog, Application};
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
gio::{Cancellable, File},
|
||||
prelude::GtkWindowExt,
|
||||
|
|
@ -109,70 +110,43 @@ impl Browser {
|
|||
|
||||
// Actions
|
||||
|
||||
pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
self.window.clean(transaction, record.id)?;
|
||||
self.widget.clean(transaction, record.id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.clean(transaction, &record.id)?; */
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to childs
|
||||
self.window.clean(transaction, record.id)?;
|
||||
self.widget.clean(transaction, record.id)?;
|
||||
/* @TODO
|
||||
self.header.clean(transaction, &record.id)?; */
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Delegate restore action to childs
|
||||
self.widget.restore(transaction, record.id)?;
|
||||
self.window.restore(transaction, record.id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.restore(transaction, &record.id)?; */
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_id)? {
|
||||
// Delegate restore action to childs
|
||||
self.widget.restore(transaction, record.id)?;
|
||||
self.window.restore(transaction, record.id)?;
|
||||
/* @TODO
|
||||
self.header.restore(transaction, &record.id)?; */
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::insert(transaction, app_id) {
|
||||
Ok(_) => {
|
||||
let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
self.widget.save(transaction, id)?;
|
||||
self.window.save(transaction, id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.save(transaction, &id)?; */
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
let id = database::insert(transaction, app_id)?;
|
||||
// Delegate save action to childs
|
||||
self.widget.save(transaction, id)?;
|
||||
self.window.save(transaction, id)?;
|
||||
/* @TODO
|
||||
self.header.save(transaction, &id)?; */
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init(&self, application: Option<&Application>) -> &Self {
|
||||
// Assign browser window to this application
|
||||
self.widget.application_window.set_application(application); // @TODO
|
||||
|
||||
// Init main window
|
||||
// Init main window
|
||||
self.window.init();
|
||||
self
|
||||
}
|
||||
|
|
@ -184,11 +158,9 @@ impl Browser {
|
|||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
/* @TODO
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_id: i64, not in use
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -15,14 +16,15 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_id`) REFERENCES `app`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(tx: &Transaction, app_id: i64) -> Result<usize, Error> {
|
||||
tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id])
|
||||
pub fn insert(tx: &Transaction, app_id: i64) -> Result<i64> {
|
||||
tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id])?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?;
|
||||
|
||||
let result = stmt.query_map([app_id], |row| {
|
||||
|
|
@ -42,10 +44,6 @@ pub fn select(tx: &Transaction, app_id: i64) -> Result<Vec<Table>, Error> {
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id])
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id])?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ mod database;
|
|||
|
||||
use super::Window;
|
||||
use adw::ApplicationWindow;
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
gio::SimpleActionGroup,
|
||||
glib::GString,
|
||||
|
|
@ -59,74 +60,44 @@ impl Widget {
|
|||
}
|
||||
|
||||
// Actions
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Restore widget
|
||||
self.application_window.set_maximized(record.is_maximized);
|
||||
self.application_window
|
||||
.set_default_size(record.default_width, record.default_height);
|
||||
pub fn restore(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_id)? {
|
||||
// Restore widget
|
||||
self.application_window.set_maximized(record.is_maximized);
|
||||
self.application_window
|
||||
.set_default_size(record.default_width, record.default_height);
|
||||
|
||||
// Delegate restore action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
// Delegate restore action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::insert(
|
||||
pub fn save(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
database::insert(
|
||||
transaction,
|
||||
app_browser_id,
|
||||
self.application_window.default_width(),
|
||||
self.application_window.default_height(),
|
||||
self.application_window.is_maximized(),
|
||||
) {
|
||||
Ok(_) => {
|
||||
// Delegate save action to childs
|
||||
// let id = self.database.last_insert_id(transaction);
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
database::init(tx)?;
|
||||
// Delegate migration to childs
|
||||
// nothing yet..
|
||||
|
||||
// Success
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
|
|
@ -8,8 +9,8 @@ pub struct Table {
|
|||
pub is_maximized: bool,
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_widget`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -21,7 +22,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_id`) REFERENCES `app_browser`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
|
|
@ -30,7 +31,7 @@ pub fn insert(
|
|||
default_width: i32,
|
||||
default_height: i32,
|
||||
is_maximized: bool,
|
||||
) -> Result<usize, Error> {
|
||||
) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_widget` (
|
||||
`app_browser_id`,
|
||||
|
|
@ -44,10 +45,11 @@ pub fn insert(
|
|||
default_height as i64,
|
||||
is_maximized as i64,
|
||||
],
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_id`,
|
||||
|
|
@ -76,11 +78,6 @@ pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>, Error
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])?)
|
||||
}
|
||||
|
||||
/* not in use
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
} */
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ mod database;
|
|||
mod header;
|
||||
pub mod tab;
|
||||
|
||||
use action::{Action, Position};
|
||||
use adw::ToolbarView;
|
||||
use header::Header;
|
||||
use sqlite::Transaction;
|
||||
use tab::Tab;
|
||||
|
||||
use super::Action as BrowserAction;
|
||||
use crate::Profile;
|
||||
use action::{Action, Position};
|
||||
use adw::ToolbarView;
|
||||
use anyhow::Result;
|
||||
use gtk::{prelude::BoxExt, Box, Orientation};
|
||||
use header::Header;
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
use tab::Tab;
|
||||
|
||||
pub struct Window {
|
||||
pub action: Rc<Action>,
|
||||
|
|
@ -145,52 +145,26 @@ impl Window {
|
|||
self.tab.escape();
|
||||
}
|
||||
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
self.tab.clean(transaction, record.id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to childs
|
||||
self.tab.clean(transaction, record.id)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Delegate restore action to childs
|
||||
self.tab.restore(transaction, record.id)?;
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn restore(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_id)? {
|
||||
// Delegate restore action to childs
|
||||
self.tab.restore(transaction, record.id)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_browser_id: i64) -> Result<(), String> {
|
||||
match database::insert(transaction, app_browser_id) {
|
||||
Ok(_) => {
|
||||
// Delegate save action to childs
|
||||
if let Err(e) = self
|
||||
.tab
|
||||
.save(transaction, database::last_insert_id(transaction))
|
||||
{
|
||||
return Err(e.to_string());
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_browser_id: i64) -> Result<()> {
|
||||
self.tab
|
||||
.save(transaction, database::insert(transaction, app_browser_id)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -200,11 +174,9 @@ impl Window {
|
|||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
tab::migrate(tx)?;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_browser_id: i64, not in use
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -15,17 +16,18 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_id`) REFERENCES `app_browser`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(tx: &Transaction, app_browser_id: i64) -> Result<usize, Error> {
|
||||
pub fn insert(tx: &Transaction, app_browser_id: i64) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)",
|
||||
[app_browser_id],
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_id` FROM `app_browser_window`
|
||||
|
|
@ -49,10 +51,6 @@ pub fn select(tx: &Transaction, app_browser_id: i64) -> Result<Vec<Table>, Error
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id])
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id])?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use super::{Action as WindowAction, BrowserAction, Position};
|
|||
use crate::Profile;
|
||||
use action::Action;
|
||||
use adw::{TabPage, TabView};
|
||||
use anyhow::Result;
|
||||
use error::Error;
|
||||
use gtk::{
|
||||
gio::Icon,
|
||||
|
|
@ -309,102 +310,68 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_id: i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
for (_, item) in self.index.borrow().iter() {
|
||||
item.clean(transaction, record.id)?
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_window_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to childs
|
||||
for (_, item) in self.index.borrow().iter() {
|
||||
item.clean(transaction, record.id)?
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_id: i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_id) {
|
||||
Ok(tab_records) => {
|
||||
for tab_record in tab_records {
|
||||
for item_record in item::restore(transaction, tab_record.id)? {
|
||||
// Generate new `TabPage` with blank `Widget`
|
||||
let (tab_page, target_child) = new_tab_page(
|
||||
&self.tab_view,
|
||||
Position::Number(item_record.page_position),
|
||||
);
|
||||
pub fn restore(&self, transaction: &Transaction, app_browser_window_id: i64) -> Result<()> {
|
||||
for tab_record in database::select(transaction, app_browser_window_id)? {
|
||||
for item_record in item::restore(transaction, tab_record.id)? {
|
||||
// Generate new `TabPage` with blank `Widget`
|
||||
let (tab_page, target_child) =
|
||||
new_tab_page(&self.tab_view, Position::Number(item_record.page_position));
|
||||
|
||||
// Init new tab item
|
||||
let item = Rc::new(Item::build(
|
||||
(&tab_page, &target_child),
|
||||
&self.profile,
|
||||
// Actions
|
||||
(&self.browser_action, &self.window_action, &self.action),
|
||||
// Options
|
||||
None,
|
||||
false,
|
||||
));
|
||||
// Init new tab item
|
||||
let item = Rc::new(Item::build(
|
||||
(&tab_page, &target_child),
|
||||
&self.profile,
|
||||
// Actions
|
||||
(&self.browser_action, &self.window_action, &self.action),
|
||||
// Options
|
||||
None,
|
||||
false,
|
||||
));
|
||||
|
||||
// Relate with GTK `TabPage` with app `Item`
|
||||
self.index
|
||||
.borrow_mut()
|
||||
.insert(item.tab_page.clone(), item.clone());
|
||||
// Relate with GTK `TabPage` with app `Item`
|
||||
self.index
|
||||
.borrow_mut()
|
||||
.insert(item.tab_page.clone(), item.clone());
|
||||
|
||||
// Setup
|
||||
self.tab_view
|
||||
.set_page_pinned(&item.tab_page, item_record.is_pinned);
|
||||
// Setup
|
||||
self.tab_view
|
||||
.set_page_pinned(&item.tab_page, item_record.is_pinned);
|
||||
|
||||
if item_record.is_selected {
|
||||
self.tab_view.set_selected_page(&item.tab_page);
|
||||
}
|
||||
|
||||
// Forcefully update global actions on HashMap index build complete
|
||||
// * `selected_page_notify` runs this action also, just before Item init @TODO
|
||||
update_actions(
|
||||
&self.tab_view,
|
||||
self.tab_view.selected_page().as_ref(),
|
||||
&self.index,
|
||||
&self.window_action,
|
||||
);
|
||||
|
||||
// Restore children components
|
||||
item.page.restore(transaction, item_record.id)?;
|
||||
}
|
||||
if item_record.is_selected {
|
||||
self.tab_view.set_selected_page(&item.tab_page);
|
||||
}
|
||||
|
||||
// Forcefully update global actions on HashMap index build complete
|
||||
// * `selected_page_notify` runs this action also, just before Item init @TODO
|
||||
update_actions(
|
||||
&self.tab_view,
|
||||
self.tab_view.selected_page().as_ref(),
|
||||
&self.index,
|
||||
&self.window_action,
|
||||
);
|
||||
|
||||
// Restore children components
|
||||
item.page.restore(transaction, item_record.id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_id: i64,
|
||||
) -> Result<(), String> {
|
||||
match database::insert(transaction, app_browser_window_id) {
|
||||
Ok(_) => {
|
||||
// Delegate save action to childs
|
||||
let id = database::last_insert_id(transaction);
|
||||
for (_, item) in self.index.borrow().iter() {
|
||||
item.save(transaction, id, self.tab_view.page_position(&item.tab_page))?;
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn save(&self, transaction: &Transaction, app_browser_window_id: i64) -> Result<()> {
|
||||
let id = database::insert(transaction, app_browser_window_id)?;
|
||||
for (_, item) in self.index.borrow().iter() {
|
||||
item.save(transaction, id, self.tab_view.page_position(&item.tab_page))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -430,11 +397,9 @@ impl Tab {
|
|||
|
||||
// Tools
|
||||
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
item::migrate(tx)?;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_browser_window_id: i64, not in use
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -15,19 +16,20 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_window_id`) REFERENCES `app_browser_window`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(tx: &Transaction, app_browser_window_id: i64) -> Result<usize, Error> {
|
||||
pub fn insert(tx: &Transaction, app_browser_window_id: i64) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab` (
|
||||
`app_browser_window_id`
|
||||
) VALUES (?)",
|
||||
[app_browser_window_id],
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_window_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_window_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_id` FROM `app_browser_window_tab`
|
||||
|
|
@ -51,10 +53,6 @@ pub fn select(tx: &Transaction, app_browser_window_id: i64) -> Result<Vec<Table>
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id])
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id])?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use super::{Action as TabAction, BrowserAction, WindowAction};
|
|||
use crate::Profile;
|
||||
use action::Action;
|
||||
use adw::TabPage;
|
||||
use anyhow::Result;
|
||||
use client::Client;
|
||||
use gtk::{
|
||||
prelude::{ActionExt, ActionMapExt, BoxExt},
|
||||
|
|
@ -164,26 +165,12 @@ impl Item {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_id: i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to the item childs
|
||||
self.page.clean(transaction, record.id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn clean(&self, transaction: &Transaction, app_browser_window_tab_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to the item childs
|
||||
self.page.clean(transaction, record.id)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -192,32 +179,23 @@ impl Item {
|
|||
transaction: &Transaction,
|
||||
app_browser_window_tab_id: i64,
|
||||
page_position: i32,
|
||||
) -> Result<(), String> {
|
||||
match database::insert(
|
||||
) -> Result<()> {
|
||||
let id = database::insert(
|
||||
transaction,
|
||||
app_browser_window_tab_id,
|
||||
page_position,
|
||||
self.tab_page.is_pinned(),
|
||||
self.tab_page.is_selected(),
|
||||
) {
|
||||
Ok(_) => {
|
||||
// Delegate save action to childs
|
||||
let id = database::last_insert_id(transaction);
|
||||
self.page.save(transaction, id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
)?;
|
||||
self.page.save(transaction, id)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
page::migrate(tx)?;
|
||||
|
|
@ -231,9 +209,6 @@ pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
|||
pub fn restore(
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_id: i64,
|
||||
) -> Result<Vec<database::Table>, String> {
|
||||
match database::select(transaction, app_browser_window_tab_id) {
|
||||
Ok(records) => Ok(records),
|
||||
Err(e) => Err(e.to_string()),
|
||||
}
|
||||
) -> Result<Vec<database::Table>> {
|
||||
database::select(transaction, app_browser_window_tab_id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
|
|
@ -8,8 +9,8 @@ pub struct Table {
|
|||
pub is_selected: bool,
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -21,7 +22,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_window_tab_id`) REFERENCES `app_browser_window_tab` (`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
|
|
@ -30,7 +31,7 @@ pub fn insert(
|
|||
page_position: i32,
|
||||
is_pinned: bool,
|
||||
is_selected: bool,
|
||||
) -> Result<usize, Error> {
|
||||
) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab_item` (
|
||||
`app_browser_window_tab_id`,
|
||||
|
|
@ -44,10 +45,11 @@ pub fn insert(
|
|||
is_pinned as i64,
|
||||
is_selected as i64,
|
||||
],
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_id`,
|
||||
|
|
@ -79,13 +81,9 @@ pub fn select(tx: &Transaction, app_browser_window_tab_id: i64) -> Result<Vec<Ta
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item` WHERE `id` = ?",
|
||||
[id],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
)?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ mod search;
|
|||
|
||||
use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowAction};
|
||||
use adw::TabPage;
|
||||
use anyhow::Result;
|
||||
use content::Content;
|
||||
use error::Error;
|
||||
use input::Input;
|
||||
|
|
@ -104,20 +105,11 @@ impl Page {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_id: i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_item_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to the item childs
|
||||
self.navigation.clean(transaction, &record.id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_item_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to the item childs
|
||||
self.navigation.clean(transaction, &record.id)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -127,25 +119,20 @@ impl Page {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_id: i64,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
// Begin page restore
|
||||
match database::select(transaction, app_browser_window_tab_item_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Restore `Self`
|
||||
if let Some(title) = record.title {
|
||||
self.set_title(title.as_str());
|
||||
}
|
||||
self.set_needs_attention(record.is_needs_attention);
|
||||
// Restore child components
|
||||
self.navigation.restore(transaction, &record.id)?;
|
||||
// Make initial page history snap using `navigation` values restored
|
||||
if let Some(uri) = self.navigation.uri() {
|
||||
self.profile.history.memory.request.set(uri);
|
||||
}
|
||||
}
|
||||
for record in database::select(transaction, app_browser_window_tab_item_id)? {
|
||||
// Restore `Self`
|
||||
if let Some(title) = record.title {
|
||||
self.set_title(title.as_str());
|
||||
}
|
||||
self.set_needs_attention(record.is_needs_attention);
|
||||
// Restore child components
|
||||
self.navigation.restore(transaction, &record.id)?;
|
||||
// Make initial page history snap using `navigation` values restored
|
||||
if let Some(uri) = self.navigation.uri() {
|
||||
self.profile.history.memory.request.set(uri);
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -155,10 +142,10 @@ impl Page {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_id: i64,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
// Keep value in memory until operation complete
|
||||
let title = self.tab_page.title();
|
||||
match database::insert(
|
||||
let id = database::insert(
|
||||
transaction,
|
||||
app_browser_window_tab_item_id,
|
||||
self.tab_page.needs_attention(),
|
||||
|
|
@ -166,15 +153,9 @@ impl Page {
|
|||
true => None,
|
||||
false => Some(title.as_str()),
|
||||
},
|
||||
) {
|
||||
Ok(_) => {
|
||||
let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
self.navigation.save(transaction, &id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
)?;
|
||||
// Delegate save action to childs
|
||||
self.navigation.save(transaction, &id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -198,11 +179,9 @@ impl Page {
|
|||
|
||||
// Tools
|
||||
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
navigation::migrate(tx)?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
|
|
@ -7,8 +8,8 @@ pub struct Table {
|
|||
pub title: Option<String>,
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -19,7 +20,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item` (`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
|
|
@ -27,7 +28,7 @@ pub fn insert(
|
|||
app_browser_window_tab_item_id: i64,
|
||||
is_needs_attention: bool,
|
||||
title: Option<&str>,
|
||||
) -> Result<usize, Error> {
|
||||
) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab_item_page` (
|
||||
`app_browser_window_tab_item_id`,
|
||||
|
|
@ -35,10 +36,11 @@ pub fn insert(
|
|||
`title`
|
||||
) VALUES (?, ?, ?)",
|
||||
(app_browser_window_tab_item_id, is_needs_attention, title),
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_item_id`,
|
||||
|
|
@ -67,13 +69,9 @@ pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result<V
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?",
|
||||
[id],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
)?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ mod reload;
|
|||
mod request;
|
||||
|
||||
use super::{ItemAction, Profile, TabAction, WindowAction};
|
||||
use anyhow::Result;
|
||||
use bookmark::Bookmark;
|
||||
use gtk::{
|
||||
glib::{GString, Uri},
|
||||
|
|
@ -72,22 +73,12 @@ impl Navigation {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(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
|
||||
self.request.clean(transaction, &record.id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_item_page_id)? {
|
||||
database::delete(transaction, &record.id)?;
|
||||
// Delegate clean action to the item childs
|
||||
self.request.clean(transaction, &record.id)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -95,17 +86,11 @@ impl Navigation {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_item_page_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Delegate restore action to the item childs
|
||||
self.request.restore(transaction, &record.id)?;
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_item_page_id)? {
|
||||
// Delegate restore action to the item childs
|
||||
self.request.restore(transaction, &record.id)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -113,17 +98,10 @@ impl Navigation {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::insert(transaction, app_browser_window_tab_item_page_id) {
|
||||
Ok(_) => {
|
||||
let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
self.request.save(transaction, &id)?;
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
) -> Result<()> {
|
||||
let id = database::insert(transaction, app_browser_window_tab_item_page_id)?;
|
||||
// Delegate save action to childs
|
||||
self.request.save(transaction, &id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -173,11 +151,9 @@ impl Navigation {
|
|||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
request::migrate(tx)?;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl Bookmark for Button {
|
|||
}
|
||||
|
||||
fn update(&self, profile: &Profile, request: &Entry) {
|
||||
let has_bookmark = profile.bookmark.get(&request.text()).is_ok();
|
||||
let has_bookmark = profile.bookmark.get(&request.text()).is_some();
|
||||
self.set_icon_name(icon_name(has_bookmark));
|
||||
self.set_tooltip_text(Some(tooltip_text(has_bookmark)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_browser_window_tab_item_page_id: i64, not in use
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -15,22 +16,20 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_window_tab_item_page_id`) REFERENCES `app_browser_window_tab_item_page`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<usize, Error> {
|
||||
pub fn insert(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<i64> {
|
||||
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],
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_item_page_id`
|
||||
|
|
@ -55,13 +54,9 @@ pub fn select(
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?",
|
||||
[id],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
)?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ mod identity;
|
|||
mod primary_icon;
|
||||
mod search;
|
||||
|
||||
use adw::{prelude::AdwDialogExt, AlertDialog};
|
||||
use primary_icon::PrimaryIcon;
|
||||
|
||||
use super::{ItemAction, Profile};
|
||||
use adw::{prelude::AdwDialogExt, AlertDialog};
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
glib::{gformat, GString, Uri, UriFlags},
|
||||
prelude::{EditableExt, EntryExt, WidgetExt},
|
||||
Entry, EntryIconPosition, StateFlags,
|
||||
};
|
||||
use primary_icon::PrimaryIcon;
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
|
||||
|
|
@ -29,19 +29,19 @@ pub trait Request {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String>;
|
||||
) -> Result<()>;
|
||||
|
||||
fn restore(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String>;
|
||||
) -> Result<()>;
|
||||
|
||||
fn save(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String>;
|
||||
) -> Result<()>;
|
||||
|
||||
fn update_primary_icon(&self, profile: &Profile);
|
||||
fn update_secondary_icon(&self);
|
||||
|
|
@ -147,22 +147,13 @@ impl Request for Entry {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_item_page_navigation_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()),
|
||||
) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_item_page_navigation_id)?
|
||||
{
|
||||
database::delete(transaction, &record.id)?;
|
||||
// Delegate clean action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -170,21 +161,15 @@ impl Request for Entry {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_item_page_navigation_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
if let Some(text) = record.text {
|
||||
self.set_text(&text);
|
||||
}
|
||||
|
||||
// Delegate restore action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
) -> Result<()> {
|
||||
for record in database::select(transaction, app_browser_window_tab_item_page_navigation_id)?
|
||||
{
|
||||
if let Some(text) = record.text {
|
||||
self.set_text(&text);
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
// Delegate restore action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -192,27 +177,19 @@ impl Request for Entry {
|
|||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
// Keep value in memory until operation complete
|
||||
let text = self.text();
|
||||
|
||||
match database::insert(
|
||||
let _id = database::insert(
|
||||
transaction,
|
||||
app_browser_window_tab_item_page_navigation_id,
|
||||
match text.is_empty() {
|
||||
true => None,
|
||||
false => Some(text.as_str()),
|
||||
},
|
||||
) {
|
||||
Ok(_) => {
|
||||
// let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
)?;
|
||||
// Delegate save action to childs
|
||||
// nothing yet..
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -369,11 +346,9 @@ impl Request for Entry {
|
|||
|
||||
// Tools
|
||||
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
// nothing yet..
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
use anyhow::Result;
|
||||
use sqlite::Transaction;
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
|
|
@ -6,8 +7,8 @@ pub struct Table {
|
|||
pub text: Option<String>, // can be stored as NULL
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn init(tx: &Transaction) -> Result<usize> {
|
||||
Ok( tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
|
@ -17,27 +18,28 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
FOREIGN KEY (`app_browser_window_tab_item_page_navigation_id`) REFERENCES `app_browser_window_tab_item_page_navigation`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
text: Option<&str>,
|
||||
) -> Result<usize, Error> {
|
||||
) -> Result<i64> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab_item_page_navigation_request` (
|
||||
`app_browser_window_tab_item_page_navigation_id`,
|
||||
`text`
|
||||
) VALUES (?, ?)",
|
||||
(app_browser_window_tab_item_page_navigation_id, text),
|
||||
)
|
||||
)?;
|
||||
Ok(tx.last_insert_rowid())
|
||||
}
|
||||
|
||||
pub fn select(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<Vec<Table>, Error> {
|
||||
) -> Result<Vec<Table>> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_item_page_navigation_id`,
|
||||
|
|
@ -64,14 +66,9 @@ pub fn select(
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize> {
|
||||
Ok(tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?",
|
||||
[id],
|
||||
)
|
||||
)?)
|
||||
}
|
||||
|
||||
/* not in use
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
} */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue