From a7bd2ae078f4a28d9bb96228d8d367ee30925db1 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 12 Aug 2024 17:43:18 +0300 Subject: [PATCH] implement page close on tab label double click --- src/app/browser/main/tab.cpp | 47 +++++++++++++++++++++++++++++++----- src/app/browser/main/tab.hpp | 10 ++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 49ccda1b..7afe429a 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -1,5 +1,4 @@ #include "tab.hpp" -#include "gtkmm/label.h" using namespace app::browser::main; @@ -17,13 +16,36 @@ void Tab::append( bool open, bool focus ) { - Gtk::Label * data = new Gtk::Label("data"); // @TODO + // Init new tab label + Gtk::Label * name = new Gtk::Label( + LABEL + ); + + // Setup label controller + auto controller = Gtk::GestureClick::create(); + + /* @TODO remove as default + controller->set_button( + GDK_BUTTON_PRIMARY + );*/ + + controller->signal_pressed().connect( + sigc::mem_fun( + * this, + & Tab::on_label_click + ) + ); + + name->add_controller( + controller + ); + + // Init tab data container @TODO + Gtk::Label * data = new Gtk::Label("data"); append_page( * data, - * new Gtk::Label( - LABEL - ) + * name ); set_tab_reorderable( @@ -39,4 +61,17 @@ void Tab::append( ) ); } -}; \ No newline at end of file +}; + +void Tab::on_label_click( + int n, + double x, + double y +) { + if (n == 2) // double click + { + remove_page( + get_current_page() + ); + } +} \ No newline at end of file diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index c4272423..f2bfd731 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -2,12 +2,22 @@ #define APP_BROWSER_MAIN_TAB_H #include +#include +#include #include namespace app::browser::main { class Tab : public Gtk::Notebook { + private: + + void on_label_click( + int n, + double x, + double y + ); + public: const bool SCROLLABLE = true;