Browse Source

close tab on middle button click, implement pin tab on double click

CPP-GTK4
yggverse 2 months ago
parent
commit
abe969742d
  1. 138
      src/app/browser/main/tab/label.cpp
  2. 9
      src/app/browser/main/tab/label.hpp

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

@ -15,50 +15,71 @@ 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;
// Setup label controller // Init widget
auto const EVENT__GESTURE_CLICK = Gtk::GestureClick::create(); set_ellipsize(
Pango::EllipsizeMode::END
);
set_has_tooltip(
true
);
set_single_line_mode(
true
);
set_width_chars(
WIDTH_CHARS
);
/* @TODO remove as default // Init primary button controller
controller->set_button( const auto EVENT__BUTTON_PRIMARY = Gtk::GestureClick::create();
EVENT__BUTTON_PRIMARY->set_button(
GDK_BUTTON_PRIMARY GDK_BUTTON_PRIMARY
);*/ );
add_controller(
EVENT__BUTTON_PRIMARY
);
EVENT__GESTURE_CLICK->signal_pressed().connect( // Connect events
EVENT__BUTTON_PRIMARY->signal_pressed().connect(
[this](int n, double x, double y) [this](int n, double x, double y)
{ {
if (n == 2) // double click if (n == 2) // double click
{ {
action__tab_close->activate(); pin(
!is_pinned // toggle
);
} }
} }
); );
add_controller( // Init middle button controller
EVENT__GESTURE_CLICK const auto EVENT__BUTTON_MIDDLE = Gtk::GestureClick::create();
);
// Init widget EVENT__BUTTON_MIDDLE->set_button(
set_ellipsize( GDK_BUTTON_MIDDLE
Pango::EllipsizeMode::END
);
/* @TODO require als set_xalign(0)
set_halign(
Gtk::Align::START
); */
set_has_tooltip(
true
); );
set_single_line_mode( add_controller(
true EVENT__BUTTON_MIDDLE
); );
set_width_chars( // Connect events
WIDTH_CHARS EVENT__BUTTON_MIDDLE->signal_pressed().connect(
[this](int n, double x, double y)
{
if (!is_pinned)
{
action__tab_close->activate();
}
}
); );
} }
@ -91,16 +112,16 @@ 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,
DB::SESSION::TEXT DB::SESSION::TEXT
) )
) ),
sqlite3_column_int(
statement,
DB::SESSION::IS_PINNED
) == 1
); );
// Restore children components here (on available) // Restore children components here (on available)
@ -122,31 +143,70 @@ int Label::session_save(
db, db,
APP_BROWSER_MAIN_TAB__SESSION__ID, APP_BROWSER_MAIN_TAB__SESSION__ID,
is_pinned, is_pinned,
get_text() text
); );
} }
void Label::update( void Label::pin(
const Glib::ustring & TEXT const bool & IS_PINNED
) { ) {
// Toggle status
is_pinned = IS_PINNED;
// Update widget
if (is_pinned)
{
set_width_chars(
1
);
set_text( set_text(
TEXT "" // @TODO GTK icon
); );
}
set_tooltip_text( else
TEXT // same value for tooltip (ellipsize mode) {
set_width_chars(
WIDTH_CHARS
);
set_text(
text
); );
}
} }
void Label::update( void Label::update(
const int & IS_PINNED,
const Glib::ustring & TEXT const Glib::ustring & TEXT
) { ) {
is_pinned = IS_PINNED; // Keep new value in memory (used for pin actions)
text = TEXT;
// Update widget
set_tooltip_text(
TEXT // same value for tooltip (ellipsize mode)
);
if (!is_pinned)
{
set_text(
TEXT
);
}
}
void Label::update(
const Glib::ustring & TEXT,
const int & IS_PINNED
) {
update( update(
TEXT TEXT
); );
pin(
IS_PINNED
);
} }
// Database model // Database model

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

@ -67,6 +67,7 @@ namespace app::browser::main::tab
// Extras // Extras
bool is_pinned; bool is_pinned;
Glib::ustring text;
// Defaults // Defaults
static const int WIDTH_CHARS = 16; static const int WIDTH_CHARS = 16;
@ -90,13 +91,17 @@ 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 update( void update(
const Glib::ustring & TEXT const Glib::ustring & TEXT
); );
void update( void update(
const int & IS_PINNED, const Glib::ustring & TEXT,
const Glib::ustring & TEXT const int & IS_PINNED
); );
}; };
} }

Loading…
Cancel
Save