Browse Source

update menu build

CPP-GTK4
yggverse 2 months ago
parent
commit
f23a54c58a
  1. 2
      po/POTFILES.in
  2. 13
      src/app/browser.cpp
  3. 43
      src/app/browser/header.cpp
  4. 11
      src/app/browser/header.hpp
  5. 246
      src/app/browser/header/menu.cpp
  6. 40
      src/app/browser/header/menu.hpp

2
po/POTFILES.in

@ -4,6 +4,8 @@ src/app/browser/header/main.cpp
src/app/browser/header/main/subtitle.cpp src/app/browser/header/main/subtitle.cpp
src/app/browser/header/main/title.cpp src/app/browser/header/main/title.cpp
src/app/browser/header/menu.cpp src/app/browser/header/menu.cpp
src/app/browser/header/menu/tab.cpp
src/app/browser/header/menu/tools.cpp
src/app/browser/header/tab.cpp src/app/browser/header/tab.cpp
src/app/browser/main.cpp src/app/browser/main.cpp
src/app/browser/main/tab.cpp src/app/browser/main/tab.cpp

13
src/app/browser.cpp

@ -22,7 +22,7 @@ Browser::Browser(
} }
); );
add_action( const auto ACTION__DEBUG = add_action(
"debug", "debug",
[this] [this]
{ {
@ -38,7 +38,7 @@ Browser::Browser(
"<Primary>i" "<Primary>i"
); );
add_action( const auto ACTION__MAIN_TAB_APPEND = add_action(
"main_tab_append", "main_tab_append",
[this] [this]
{ {
@ -151,7 +151,14 @@ Browser::Browser(
); );
// Init components // Init components
browserHeader = Gtk::make_managed<browser::Header>(); browserHeader = Gtk::make_managed<browser::Header>(
ACTION__DEBUG,
ACTION__MAIN_TAB_APPEND,
ACTION__MAIN_TAB_CLOSE,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
);
set_titlebar( set_titlebar(
* browserHeader * browserHeader

43
src/app/browser/header.cpp

@ -5,33 +5,44 @@
using namespace app::browser; using namespace app::browser;
Header::Header() Header::Header(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__DEBUG,
// Init header bar const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_APPEND,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
) {
// Init widget
set_show_title_buttons( set_show_title_buttons(
SHOW_TITLE_BUTTONS SHOW_TITLE_BUTTONS
); );
// Init menu // Init components
headerMenu = Gtk::make_managed<header::Menu>(); headerMenu = Gtk::make_managed<header::Menu>(
ACTION__DEBUG,
pack_start( ACTION__MAIN_TAB_APPEND,
* headerMenu ACTION__MAIN_TAB_CLOSE,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
); );
// Init tab pack_start(
* headerMenu
);
headerTab = Gtk::make_managed<header::Tab>(); headerTab = Gtk::make_managed<header::Tab>();
pack_start( pack_start(
* headerTab * headerTab
); );
// Init main widget
headerMain = Gtk::make_managed<header::Main>(); headerMain = Gtk::make_managed<header::Main>();
set_title_widget( set_title_widget(
* headerMain * headerMain
); );
} }
void Header::refresh( void Header::refresh(

11
src/app/browser/header.hpp

@ -1,6 +1,8 @@
#ifndef APP_BROWSER_HEADER_HPP #ifndef APP_BROWSER_HEADER_HPP
#define APP_BROWSER_HEADER_HPP #define APP_BROWSER_HEADER_HPP
#include <giomm/simpleaction.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/headerbar.h> #include <gtkmm/headerbar.h>
#include <gtkmm/object.h> #include <gtkmm/object.h>
@ -26,7 +28,14 @@ namespace app::browser
public: public:
Header(); Header(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__DEBUG,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_APPEND,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
);
void refresh( void refresh(
const Glib::ustring & TITLE, const Glib::ustring & TITLE,

246
src/app/browser/header/menu.cpp

@ -2,158 +2,144 @@
using namespace app::browser::header; using namespace app::browser::header;
Menu::Menu() Menu::Menu(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__DEBUG,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_APPEND,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
) {
// Init widget
set_tooltip_text( set_tooltip_text(
_("Menu") _("Menu")
); );
set_menu_model( // Init components @TODO make builder
main( const auto MENU__MAIN = Gio::Menu::create();
main_tab(
main_tab_page(
main_tab_page_navigation(
main_tab_page_navigation_history()
)
),
main_tab_close()
),
main_tools()
)
);
}
Glib::RefPtr<Gio::Menu> Menu::main(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB,
const Glib::RefPtr<Gio::Menu> & MAIN_TOOLS
) {
auto menu = Gio::Menu::create();
menu->append_submenu(
_("Tab"),
MAIN_TAB
);
menu->append_submenu(
_("Tools"),
MAIN_TOOLS
);
menu->append( const auto MENU__MAIN_TAB = Gio::Menu::create();
_("Quit"),
"app.quit"
);
return menu; MENU__MAIN_TAB->append(
} _("New.."),
get_action_detailed_name(
ACTION__MAIN_TAB_APPEND
)
);
Glib::RefPtr<Gio::Menu> Menu::main_tab( const auto MENU__MAIN_TAB_PAGE = Gio::Menu::create();
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE,
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_CLOSE
) {
auto menu = Gio::Menu::create();
menu->append( const auto MENU__MAIN_TAB_PAGE_NAVIGATION = Gio::Menu::create();
_("New.."),
"win.main_tab_append"
);
menu->append_submenu( const auto MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY = Gio::Menu::create();
_("Page"),
MAIN_TAB_PAGE
);
menu->append_submenu( MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY->append(
_("Close"), _("Back"),
MAIN_TAB_CLOSE get_action_detailed_name(
); ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK
)
);
return menu; MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY->append(
} _("Forward"),
get_action_detailed_name(
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD
)
);
Glib::RefPtr<Gio::Menu> Menu::main_tab_page( MENU__MAIN_TAB_PAGE_NAVIGATION->append_submenu(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION _("History"),
) { MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY
auto menu = Gio::Menu::create(); );
menu->append_submenu( MENU__MAIN_TAB_PAGE_NAVIGATION->append(
_("Navigation"), _("Update"),
MAIN_TAB_PAGE_NAVIGATION get_action_detailed_name(
); ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
)
);
return menu; MENU__MAIN_TAB_PAGE->append_submenu(
} _("Navigation"),
MENU__MAIN_TAB_PAGE_NAVIGATION
);
Glib::RefPtr<Gio::Menu> Menu::main_tab_page_navigation( MENU__MAIN_TAB->append_submenu(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION_HISTORY _("Page"),
) { MENU__MAIN_TAB_PAGE
auto menu = Gio::Menu::create(); );
menu->append_submenu( const auto MENU__MAIN_TAB_CLOSE = Gio::Menu::create();
_("History"),
MAIN_TAB_PAGE_NAVIGATION_HISTORY
);
menu->append( MENU__MAIN_TAB_CLOSE->append(
_("Update"), _("Active tab"),
"win.main_tab_page_navigation_update" get_action_detailed_name(
); ACTION__MAIN_TAB_CLOSE
)
return menu; );
}
// @TODO
Glib::RefPtr<Gio::Menu> Menu::main_tab_page_navigation_history() /*
{ MENU__MAIN_TAB_CLOSE->append(
auto menu = Gio::Menu::create(); _("All tabs to left"),
get_action_detailed_name(
menu->append( ACTION__MAIN_TAB_CLOSE
_("Back"), )
"win.main_tab_page_navigation_history_back" );
);
menu->append(
_("Forward"),
"win.main_tab_page_navigation_history_forward"
);
return menu;
}
Glib::RefPtr<Gio::Menu> Menu::main_tab_close()
{
auto menu = Gio::Menu::create();
menu->append(
_("Active tab"),
"win.main_tab_close"
);
menu->append( MENU__MAIN_TAB_CLOSE->append(
_("All tabs to left"), _("All tabs to right"),
"win.main_tab_close_left" get_action_detailed_name(
); ACTION__MAIN_TAB_CLOSE
)
);
menu->append( MENU__MAIN_TAB_CLOSE->append(
_("All tabs to right"), _("All tabs"),
"win.main_tab_close_right" get_action_detailed_name(
); ACTION__MAIN_TAB_CLOSE
)
);
*/
MENU__MAIN_TAB->append_submenu(
_("Close"),
MENU__MAIN_TAB_CLOSE
);
MENU__MAIN->append_submenu(
_("Tab"),
MENU__MAIN_TAB
);
const auto MENU__MAIN_TOOLS = Gio::Menu::create();
MENU__MAIN_TOOLS->append(
_("Debug"),
get_action_detailed_name(
ACTION__DEBUG
)
);
MENU__MAIN->append_submenu(
_("Tools"),
MENU__MAIN_TOOLS
);
MENU__MAIN->append(
_("Quit"),
"app.quit" // @TODO
);
menu->append( set_menu_model(
_("All tabs"), MENU__MAIN
"win.main_tab_close_all"
); );
return menu;
} }
Glib::RefPtr<Gio::Menu> Menu::main_tools() Glib::ustring Menu::get_action_detailed_name(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION
auto menu = Gio::Menu::create(); ) {
return Glib::ustring::sprintf(
menu->append( "win.%s", ACTION->get_name()
_("Debug"),
"win.debug"
); );
return menu;
} }

40
src/app/browser/header/menu.hpp

@ -2,45 +2,29 @@
#define APP_BROWSER_HEADER_MENU_HPP #define APP_BROWSER_HEADER_MENU_HPP
#include <giomm/menu.h> #include <giomm/menu.h>
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/menubutton.h> #include <gtkmm/menubutton.h>
namespace app::browser::header namespace app::browser::header
{ {
class Menu : public Gtk::MenuButton class Menu : public Gtk::MenuButton
{ {
// 1 level static Glib::ustring get_action_detailed_name(
static Glib::RefPtr<Gio::Menu> main( const Glib::RefPtr<Gio::SimpleAction> & ACTION
const Glib::RefPtr<Gio::Menu> & MAIN_TAB,
const Glib::RefPtr<Gio::Menu> & MAIN_TOOLS
); );
// 2 level
static Glib::RefPtr<Gio::Menu> main_tab(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE,
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_CLOSE
);
// 3 level
static Glib::RefPtr<Gio::Menu> main_tab_page(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION
);
// 4 level
static Glib::RefPtr<Gio::Menu> main_tab_page_navigation(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION_HISTORY
);
// 5 level
static Glib::RefPtr<Gio::Menu> main_tab_page_navigation_history();
static Glib::RefPtr<Gio::Menu> main_tab_close();
static Glib::RefPtr<Gio::Menu> main_tools();
public: public:
Menu(); Menu(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__DEBUG,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_APPEND,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE
);
}; };
} }

Loading…
Cancel
Save