Browse Source

update menu build

CPP-GTK4
yggverse 4 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 @@ -4,6 +4,8 @@ src/app/browser/header/main.cpp
src/app/browser/header/main/subtitle.cpp
src/app/browser/header/main/title.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/main.cpp
src/app/browser/main/tab.cpp

13
src/app/browser.cpp

@ -22,7 +22,7 @@ Browser::Browser( @@ -22,7 +22,7 @@ Browser::Browser(
}
);
add_action(
const auto ACTION__DEBUG = add_action(
"debug",
[this]
{
@ -38,7 +38,7 @@ Browser::Browser( @@ -38,7 +38,7 @@ Browser::Browser(
"<Primary>i"
);
add_action(
const auto ACTION__MAIN_TAB_APPEND = add_action(
"main_tab_append",
[this]
{
@ -151,7 +151,14 @@ Browser::Browser( @@ -151,7 +151,14 @@ Browser::Browser(
);
// 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(
* browserHeader

43
src/app/browser/header.cpp

@ -5,33 +5,44 @@ @@ -5,33 +5,44 @@
using namespace app::browser;
Header::Header()
{
// Init header bar
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
) {
// Init widget
set_show_title_buttons(
SHOW_TITLE_BUTTONS
);
// Init menu
headerMenu = Gtk::make_managed<header::Menu>();
pack_start(
* headerMenu
// Init components
headerMenu = Gtk::make_managed<header::Menu>(
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
);
// Init tab
pack_start(
* headerMenu
);
headerTab = Gtk::make_managed<header::Tab>();
pack_start(
* headerTab
);
pack_start(
* headerTab
);
// Init main widget
headerMain = Gtk::make_managed<header::Main>();
set_title_widget(
* headerMain
);
set_title_widget(
* headerMain
);
}
void Header::refresh(

11
src/app/browser/header.hpp

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
#ifndef APP_BROWSER_HEADER_HPP
#define APP_BROWSER_HEADER_HPP
#include <giomm/simpleaction.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/headerbar.h>
#include <gtkmm/object.h>
@ -26,7 +28,14 @@ namespace app::browser @@ -26,7 +28,14 @@ namespace app::browser
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(
const Glib::ustring & TITLE,

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

@ -2,158 +2,144 @@ @@ -2,158 +2,144 @@
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(
_("Menu")
);
set_menu_model(
main(
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
);
// Init components @TODO make builder
const auto MENU__MAIN = Gio::Menu::create();
menu->append(
_("Quit"),
"app.quit"
);
const auto MENU__MAIN_TAB = Gio::Menu::create();
return menu;
}
MENU__MAIN_TAB->append(
_("New.."),
get_action_detailed_name(
ACTION__MAIN_TAB_APPEND
)
);
Glib::RefPtr<Gio::Menu> Menu::main_tab(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE,
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_CLOSE
) {
auto menu = Gio::Menu::create();
const auto MENU__MAIN_TAB_PAGE = Gio::Menu::create();
menu->append(
_("New.."),
"win.main_tab_append"
);
const auto MENU__MAIN_TAB_PAGE_NAVIGATION = Gio::Menu::create();
menu->append_submenu(
_("Page"),
MAIN_TAB_PAGE
);
const auto MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY = Gio::Menu::create();
menu->append_submenu(
_("Close"),
MAIN_TAB_CLOSE
);
MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY->append(
_("Back"),
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(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION
) {
auto menu = Gio::Menu::create();
MENU__MAIN_TAB_PAGE_NAVIGATION->append_submenu(
_("History"),
MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY
);
menu->append_submenu(
_("Navigation"),
MAIN_TAB_PAGE_NAVIGATION
);
MENU__MAIN_TAB_PAGE_NAVIGATION->append(
_("Update"),
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(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB_PAGE_NAVIGATION_HISTORY
) {
auto menu = Gio::Menu::create();
MENU__MAIN_TAB->append_submenu(
_("Page"),
MENU__MAIN_TAB_PAGE
);
menu->append_submenu(
_("History"),
MAIN_TAB_PAGE_NAVIGATION_HISTORY
);
const auto MENU__MAIN_TAB_CLOSE = Gio::Menu::create();
menu->append(
_("Update"),
"win.main_tab_page_navigation_update"
);
return menu;
}
Glib::RefPtr<Gio::Menu> Menu::main_tab_page_navigation_history()
{
auto menu = Gio::Menu::create();
menu->append(
_("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__MAIN_TAB_CLOSE->append(
_("Active tab"),
get_action_detailed_name(
ACTION__MAIN_TAB_CLOSE
)
);
// @TODO
/*
MENU__MAIN_TAB_CLOSE->append(
_("All tabs to left"),
get_action_detailed_name(
ACTION__MAIN_TAB_CLOSE
)
);
menu->append(
_("All tabs to left"),
"win.main_tab_close_left"
);
MENU__MAIN_TAB_CLOSE->append(
_("All tabs to right"),
get_action_detailed_name(
ACTION__MAIN_TAB_CLOSE
)
);
menu->append(
_("All tabs to right"),
"win.main_tab_close_right"
);
MENU__MAIN_TAB_CLOSE->append(
_("All tabs"),
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(
_("All tabs"),
"win.main_tab_close_all"
set_menu_model(
MENU__MAIN
);
return menu;
}
Glib::RefPtr<Gio::Menu> Menu::main_tools()
{
auto menu = Gio::Menu::create();
menu->append(
_("Debug"),
"win.debug"
Glib::ustring Menu::get_action_detailed_name(
const Glib::RefPtr<Gio::SimpleAction> & ACTION
) {
return Glib::ustring::sprintf(
"win.%s", ACTION->get_name()
);
return menu;
}

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

@ -2,45 +2,29 @@ @@ -2,45 +2,29 @@
#define APP_BROWSER_HEADER_MENU_HPP
#include <giomm/menu.h>
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/menubutton.h>
namespace app::browser::header
{
class Menu : public Gtk::MenuButton
{
// 1 level
static Glib::RefPtr<Gio::Menu> main(
const Glib::RefPtr<Gio::Menu> & MAIN_TAB,
const Glib::RefPtr<Gio::Menu> & MAIN_TOOLS
static Glib::ustring get_action_detailed_name(
const Glib::RefPtr<Gio::SimpleAction> & ACTION
);
// 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:
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