Browse Source

init tab pin feature

CPP-GTK4
yggverse 2 months ago
parent
commit
2804809643
  1. 24
      src/app/browser/main/tab/label.cpp
  2. 10
      src/app/browser/main/tab/label.hpp

24
src/app/browser/main/tab/label.cpp

@ -14,6 +14,9 @@ Label::Label(
// Init actions // Init actions
action__tab_close = ACTION__TAB_CLOSE; action__tab_close = ACTION__TAB_CLOSE;
// Init extras
is_pinned = false;
// Setup label controller // Setup label controller
auto const EVENT__GESTURE_CLICK = Gtk::GestureClick::create(); auto const EVENT__GESTURE_CLICK = Gtk::GestureClick::create();
@ -88,6 +91,10 @@ int Label::session_restore(
{ {
// Restore widget data // Restore widget data
update( update(
sqlite3_column_int(
statement,
DB::SESSION::IS_PINNED
) == 1,
reinterpret_cast<const char*>( reinterpret_cast<const char*>(
sqlite3_column_text( sqlite3_column_text(
statement, statement,
@ -114,6 +121,7 @@ int Label::session_save(
return DB::SESSION::add( return DB::SESSION::add(
db, db,
APP_BROWSER_MAIN_TAB__SESSION__ID, APP_BROWSER_MAIN_TAB__SESSION__ID,
is_pinned,
get_text() get_text()
); );
} }
@ -130,6 +138,17 @@ void Label::update(
); );
} }
void Label::update(
const int & IS_PINNED,
const Glib::ustring & TEXT
) {
is_pinned = IS_PINNED;
update(
TEXT
);
}
// Database model // Database model
int Label::DB::SESSION::init( int Label::DB::SESSION::init(
sqlite3 * db sqlite3 * db
@ -143,6 +162,7 @@ int Label::DB::SESSION::init(
( (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab__session__id` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab__session__id` INTEGER NOT NULL,
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, `time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_pinned` INTEGER NOT NULL,
`text` VARCHAR (1024) NOT NULL `text` VARCHAR (1024) NOT NULL
) )
)SQL", )SQL",
@ -211,6 +231,7 @@ int Label::DB::SESSION::clean(
sqlite3_int64 Label::DB::SESSION::add( sqlite3_int64 Label::DB::SESSION::add(
sqlite3 * db, sqlite3 * db,
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID, const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
const bool & IS_PINNED,
const Glib::ustring & TEXT const Glib::ustring & TEXT
) { ) {
char * error; // @TODO char * error; // @TODO
@ -221,13 +242,16 @@ sqlite3_int64 Label::DB::SESSION::add(
R"SQL( R"SQL(
INSERT INTO `app_browser_main_tab_label__session` ( INSERT INTO `app_browser_main_tab_label__session` (
`app_browser_main_tab__session__id`, `app_browser_main_tab__session__id`,
`is_pinned`,
`text` `text`
) VALUES ( ) VALUES (
'%d',
'%d', '%d',
'%s' '%s'
) )
)SQL", )SQL",
APP_BROWSER_MAIN_TAB__SESSION__ID, APP_BROWSER_MAIN_TAB__SESSION__ID,
IS_PINNED,
TEXT TEXT
).c_str(), ).c_str(),
nullptr, nullptr,

10
src/app/browser/main/tab/label.hpp

@ -32,6 +32,7 @@ namespace app::browser::main::tab
ID, ID,
APP_BROWSER_MAIN_TAB__SESSION__ID, APP_BROWSER_MAIN_TAB__SESSION__ID,
TIME, TIME,
IS_PINNED,
TEXT TEXT
}; // table fields index }; // table fields index
@ -47,6 +48,7 @@ namespace app::browser::main::tab
static sqlite3_int64 add( static sqlite3_int64 add(
sqlite3 * db, sqlite3 * db,
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID, const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
const bool & IS_PINNED,
const Glib::ustring & TEXT const Glib::ustring & TEXT
); // return sqlite3_last_insert_rowid ); // return sqlite3_last_insert_rowid
}; };
@ -63,6 +65,9 @@ namespace app::browser::main::tab
// Actions // Actions
Glib::RefPtr<Gio::SimpleAction> action__tab_close; Glib::RefPtr<Gio::SimpleAction> action__tab_close;
// Extras
bool is_pinned;
// Defaults // Defaults
static const int WIDTH_CHARS = 16; static const int WIDTH_CHARS = 16;
@ -88,6 +93,11 @@ namespace app::browser::main::tab
void update( void update(
const Glib::ustring & TEXT const Glib::ustring & TEXT
); );
void update(
const int & IS_PINNED,
const Glib::ustring & TEXT
);
}; };
} }

Loading…
Cancel
Save