mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
use separated widgets for tab label feature
This commit is contained in:
parent
1d8ec008d3
commit
4eb824594e
4 changed files with 85 additions and 96 deletions
4
Makefile
4
Makefile
|
|
@ -31,7 +31,9 @@ SRCS = src/app.cpp\
|
||||||
src/app/browser/main/tab/page/navigation/history/forward.cpp\
|
src/app/browser/main/tab/page/navigation/history/forward.cpp\
|
||||||
src/app/browser/main/tab/page/navigation/reload.cpp\
|
src/app/browser/main/tab/page/navigation/reload.cpp\
|
||||||
src/app/browser/main/tab/page/navigation/request.cpp\
|
src/app/browser/main/tab/page/navigation/request.cpp\
|
||||||
src/app/browser/main/tab/label.cpp
|
src/app/browser/main/tab/label.cpp\
|
||||||
|
src/app/browser/main/tab/label/pin.cpp\
|
||||||
|
src/app/browser/main/tab/label/title.cpp
|
||||||
|
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,6 @@ src/app/browser/main/tab/page/navigation/history/back.cpp
|
||||||
src/app/browser/main/tab/page/navigation/history/forward.cpp
|
src/app/browser/main/tab/page/navigation/history/forward.cpp
|
||||||
src/app/browser/main/tab/page/navigation/reload.cpp
|
src/app/browser/main/tab/page/navigation/reload.cpp
|
||||||
src/app/browser/main/tab/page/navigation/request.cpp
|
src/app/browser/main/tab/page/navigation/request.cpp
|
||||||
src/app/browser/main/tab/label.cpp
|
src/app/browser/main/tab/label.cpp
|
||||||
|
src/app/browser/main/tab/label/pin.cpp
|
||||||
|
src/app/browser/main/tab/label/title.cpp
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
#include "label.hpp"
|
#include "label.hpp"
|
||||||
|
#include "label/pin.hpp"
|
||||||
|
#include "label/title.hpp"
|
||||||
|
|
||||||
using namespace app::browser::main::tab;
|
using namespace app::browser::main::tab;
|
||||||
|
|
||||||
|
|
@ -15,26 +17,35 @@ Label::Label(
|
||||||
action__tab_close = ACTION__TAB_CLOSE;
|
action__tab_close = ACTION__TAB_CLOSE;
|
||||||
|
|
||||||
// Init extras
|
// Init extras
|
||||||
text = _("New page");
|
|
||||||
|
|
||||||
is_pinned = false;
|
is_pinned = false;
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
set_ellipsize(
|
set_orientation(
|
||||||
Pango::EllipsizeMode::END
|
Gtk::Orientation::HORIZONTAL
|
||||||
);
|
);
|
||||||
|
|
||||||
set_has_tooltip(
|
set_halign(
|
||||||
true
|
Gtk::Align::CENTER
|
||||||
);
|
);
|
||||||
|
|
||||||
set_single_line_mode(
|
// Init components
|
||||||
true
|
labelPin = Gtk::make_managed<label::Pin>();
|
||||||
);
|
|
||||||
|
|
||||||
set_width_chars(
|
labelPin->hide();
|
||||||
WIDTH_CHARS
|
|
||||||
);
|
append(
|
||||||
|
* labelPin
|
||||||
|
);
|
||||||
|
|
||||||
|
labelTitle = Gtk::make_managed<label::Title>();
|
||||||
|
|
||||||
|
set_tooltip_text(
|
||||||
|
labelTitle->get_text()
|
||||||
|
);
|
||||||
|
|
||||||
|
append(
|
||||||
|
* labelTitle
|
||||||
|
);
|
||||||
|
|
||||||
// Init primary button controller
|
// Init primary button controller
|
||||||
const auto EVENT__BUTTON_PRIMARY = Gtk::GestureClick::create();
|
const auto EVENT__BUTTON_PRIMARY = Gtk::GestureClick::create();
|
||||||
|
|
@ -53,7 +64,7 @@ Label::Label(
|
||||||
{
|
{
|
||||||
if (n == 2) // double click
|
if (n == 2) // double click
|
||||||
{
|
{
|
||||||
pin(
|
update(
|
||||||
!is_pinned // toggle
|
!is_pinned // toggle
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -112,12 +123,6 @@ int Label::session_restore(
|
||||||
{
|
{
|
||||||
// Restore widget data
|
// Restore widget data
|
||||||
update(
|
update(
|
||||||
reinterpret_cast<const char*>(
|
|
||||||
sqlite3_column_text(
|
|
||||||
statement,
|
|
||||||
Database::Session::TEXT
|
|
||||||
)
|
|
||||||
),
|
|
||||||
sqlite3_column_int(
|
sqlite3_column_int(
|
||||||
statement,
|
statement,
|
||||||
Database::Session::IS_PINNED
|
Database::Session::IS_PINNED
|
||||||
|
|
@ -125,6 +130,7 @@ int Label::session_restore(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Restore children components here (on available)
|
// Restore children components here (on available)
|
||||||
|
// @TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,76 +148,57 @@ int Label::session_save(
|
||||||
return Database::Session::add(
|
return Database::Session::add(
|
||||||
database,
|
database,
|
||||||
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
||||||
is_pinned,
|
is_pinned
|
||||||
text
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::pin(
|
|
||||||
const bool & IS_PINNED
|
|
||||||
) {
|
|
||||||
// Toggle status
|
|
||||||
is_pinned = IS_PINNED;
|
|
||||||
|
|
||||||
// Update widget
|
|
||||||
if (is_pinned)
|
|
||||||
{
|
|
||||||
set_width_chars(
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
set_text(
|
|
||||||
"•" // @TODO GTK icon
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
set_width_chars(
|
|
||||||
WIDTH_CHARS
|
|
||||||
);
|
|
||||||
|
|
||||||
set_text(
|
|
||||||
text
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Label::pin()
|
void Label::pin()
|
||||||
{
|
{
|
||||||
pin(
|
update(
|
||||||
!is_pinned
|
!is_pinned
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::update(
|
void Label::update(
|
||||||
const Glib::ustring & TEXT
|
const bool & IS_PINNED
|
||||||
) {
|
) {
|
||||||
// Keep new value in memory (used for pin actions)
|
// Toggle status
|
||||||
text = TEXT;
|
is_pinned = IS_PINNED;
|
||||||
|
|
||||||
// Update widget
|
if (is_pinned)
|
||||||
set_tooltip_text(
|
|
||||||
TEXT // same value for tooltip (ellipsize mode)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!is_pinned)
|
|
||||||
{
|
{
|
||||||
set_text(
|
labelPin->show();
|
||||||
TEXT
|
labelTitle->hide();
|
||||||
);
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
labelPin->hide();
|
||||||
|
labelTitle->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::update(
|
void Label::update(
|
||||||
const Glib::ustring & TEXT,
|
const Glib::ustring & TITLE
|
||||||
|
) {
|
||||||
|
set_tooltip_text(
|
||||||
|
TITLE
|
||||||
|
);
|
||||||
|
|
||||||
|
labelTitle->set_text(
|
||||||
|
TITLE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Label::update(
|
||||||
|
const Glib::ustring & TITLE,
|
||||||
const int & IS_PINNED
|
const int & IS_PINNED
|
||||||
) {
|
) {
|
||||||
update(
|
update(
|
||||||
TEXT
|
TITLE
|
||||||
);
|
);
|
||||||
|
|
||||||
pin(
|
update(
|
||||||
IS_PINNED
|
IS_PINNED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -229,8 +216,7 @@ int Label::Database::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,
|
`is_pinned` INTEGER NOT NULL
|
||||||
`text` VARCHAR (1024) NOT NULL
|
|
||||||
)
|
)
|
||||||
)SQL",
|
)SQL",
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
@ -298,8 +284,7 @@ int Label::Database::Session::clean(
|
||||||
sqlite3_int64 Label::Database::Session::add(
|
sqlite3_int64 Label::Database::Session::add(
|
||||||
sqlite3 * database,
|
sqlite3 * database,
|
||||||
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
|
||||||
const bool & IS_PINNED,
|
const bool & IS_PINNED
|
||||||
const Glib::ustring & TEXT
|
|
||||||
) {
|
) {
|
||||||
char * error; // @TODO
|
char * error; // @TODO
|
||||||
|
|
||||||
|
|
@ -309,17 +294,14 @@ sqlite3_int64 Label::Database::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`,
|
`is_pinned`
|
||||||
`text`
|
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'%d',
|
%d,
|
||||||
'%d',
|
%d
|
||||||
'%s'
|
|
||||||
)
|
)
|
||||||
)SQL",
|
)SQL",
|
||||||
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
||||||
IS_PINNED,
|
IS_PINNED
|
||||||
TEXT
|
|
||||||
).c_str(),
|
).c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,20 @@
|
||||||
#include <glibmm/i18n.h>
|
#include <glibmm/i18n.h>
|
||||||
#include <glibmm/refptr.h>
|
#include <glibmm/refptr.h>
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
|
#include <gtkmm/box.h>
|
||||||
#include <gtkmm/enums.h>
|
#include <gtkmm/enums.h>
|
||||||
#include <gtkmm/gestureclick.h>
|
#include <gtkmm/gestureclick.h>
|
||||||
#include <gtkmm/label.h>
|
|
||||||
#include <pangomm/layout.h>
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
namespace app::browser::main::tab
|
namespace app::browser::main::tab
|
||||||
{
|
{
|
||||||
class Label : public Gtk::Label
|
namespace label
|
||||||
|
{
|
||||||
|
class Pin;
|
||||||
|
class Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Label : public Gtk::Box
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -32,8 +37,7 @@ namespace app::browser::main::tab
|
||||||
ID,
|
ID,
|
||||||
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
APP_BROWSER_MAIN_TAB__SESSION__ID,
|
||||||
TIME,
|
TIME,
|
||||||
IS_PINNED,
|
IS_PINNED
|
||||||
TEXT
|
|
||||||
}; // table fields index
|
}; // table fields index
|
||||||
|
|
||||||
static int init(
|
static int init(
|
||||||
|
|
@ -48,8 +52,7 @@ namespace app::browser::main::tab
|
||||||
static sqlite3_int64 add(
|
static sqlite3_int64 add(
|
||||||
sqlite3 * database,
|
sqlite3 * database,
|
||||||
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID,
|
||||||
const bool & IS_PINNED,
|
const bool & IS_PINNED
|
||||||
const Glib::ustring & TEXT
|
|
||||||
); // return sqlite3_last_insert_rowid
|
); // return sqlite3_last_insert_rowid
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -67,10 +70,10 @@ namespace app::browser::main::tab
|
||||||
|
|
||||||
// Extras
|
// Extras
|
||||||
bool is_pinned;
|
bool is_pinned;
|
||||||
Glib::ustring text;
|
|
||||||
|
|
||||||
// Defaults
|
// Components
|
||||||
static const int WIDTH_CHARS = 16;
|
label::Pin * labelPin;
|
||||||
|
label::Title * labelTitle;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class API
|
* Class API
|
||||||
|
|
@ -91,18 +94,18 @@ namespace app::browser::main::tab
|
||||||
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
|
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
|
||||||
); // return sqlite3_finalize status code
|
); // return sqlite3_finalize status code
|
||||||
|
|
||||||
void pin(
|
|
||||||
const bool & IS_PINNED
|
|
||||||
);
|
|
||||||
|
|
||||||
void pin();
|
void pin();
|
||||||
|
|
||||||
void update(
|
void update(
|
||||||
const Glib::ustring & TEXT
|
const bool & IS_PINNED
|
||||||
);
|
);
|
||||||
|
|
||||||
void update(
|
void update(
|
||||||
const Glib::ustring & TEXT,
|
const Glib::ustring & TITLE
|
||||||
|
);
|
||||||
|
|
||||||
|
void update(
|
||||||
|
const Glib::ustring & TITLE,
|
||||||
const int & IS_PINNED
|
const int & IS_PINNED
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue