[regexxer] Add an AppMenu
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [regexxer] Add an AppMenu
- Date: Sun, 23 Feb 2014 13:33:14 +0000 (UTC)
commit 3ebb5e177819fe31b4153a77625d72696aa2c9c9
Author: Fabien Parent <parent f gmail com>
Date: Sun Feb 23 14:11:39 2014 +0100
Add an AppMenu
Makefile.am | 2 +-
configure.ac | 2 +-
src/globalstrings.h | 2 ++
src/main.cc | 6 ++++--
src/mainwindow.cc | 41 +++++++++++++++++++++++++++++++++++++++--
src/mainwindow.h | 11 ++++++++---
ui/app-menu.xml | 23 +++++++++++++++++++++++
7 files changed, 78 insertions(+), 9 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e027347..3929ed0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -78,7 +78,7 @@ AM_CPPFLAGS = $(global_defs) -I$(top_builddir) $(REGEXXER_MODULES_CFLAGS) $(REGE
src_regexxer_LDADD = $(REGEXXER_MODULES_LIBS) $(INTLLIBS)
-dist_pkgdata_DATA = ui/mainwindow.ui ui/prefdialog.ui
+dist_pkgdata_DATA = ui/mainwindow.ui ui/prefdialog.ui ui/app-menu.xml
iconthemedir = $(datadir)/icons/hicolor
appicondir = $(iconthemedir)/48x48/apps
diff --git a/configure.ac b/configure.ac
index 0dcf4d8..8300edb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,7 @@ AM_GNU_GETTEXT_VERSION([0.11])
AM_GLIB_GNU_GETTEXT
PKG_CHECK_MODULES([REGEXXER_MODULES],
- [gtkmm-3.0 >= 3.0.0 glibmm-2.4 >= 2.27.94
+ [gtkmm-3.0 >= 3.4 glibmm-2.4 >= 2.27.94
gtksourceviewmm-3.0 >= 2.91.5])
DK_PKG_PATH_PROG([GDK_PIXBUF_CSOURCE], [gdk-pixbuf-2.0], [gdk-pixbuf-csource])
diff --git a/src/globalstrings.h b/src/globalstrings.h
index e51ab22..8720462 100644
--- a/src/globalstrings.h
+++ b/src/globalstrings.h
@@ -54,6 +54,8 @@ const char *const ui_mainwindow_filename = REGEXXER_PKGDATADIR G_DIR_SEPAR
"mainwindow.ui";
const char *const ui_prefdialog_filename = REGEXXER_PKGDATADIR G_DIR_SEPARATOR_S
"prefdialog.ui";
+const char *const ui_appmenu_filename = REGEXXER_PKGDATADIR G_DIR_SEPARATOR_S
+ "app-menu.xml";
} // namespace Regexxer
diff --git a/src/main.cc b/src/main.cc
index d57753a..625b1f7 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -32,7 +32,7 @@
#include <gtkmm/main.h>
#include <gtkmm/stock.h>
#include <gtkmm/stockitem.h>
-#include <gtkmm/window.h>
+#include <gtkmm/applicationwindow.h>
#include <gtksourceviewmm/init.h>
#include <giomm/init.h>
@@ -205,6 +205,7 @@ int main(int argc, char** argv)
options->context().parse(argc, argv);
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv, Regexxer::conf_schema);
+
Gsv::init();
Gio::init();
@@ -214,9 +215,10 @@ int main(int argc, char** argv)
Regexxer::MainWindow window;
- window.initialize(options->init_state());
+ window.initialize(app, options->init_state());
options.reset();
+ //app->register_application();
app->run(*window.get_window());
return 0;
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index be1fffb..b10cda4 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -229,7 +229,8 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{}
-void MainWindow::initialize(const InitState& init)
+void MainWindow::initialize(const Glib::RefPtr<Gtk::Application>& application,
+ const InitState& init)
{
Glib::RefPtr<Gio::Settings> settings = Settings::instance();
int width = settings->get_int(conf_key_window_width);
@@ -240,6 +241,12 @@ void MainWindow::initialize(const InitState& init)
bool maximized = settings->get_boolean(conf_key_window_maximized);
+ application_ = application;
+ application->signal_startup().connect
+ (sigc::mem_fun(*this, &MainWindow::on_startup));
+ application->register_application();
+
+ window_->set_application(application_);
window_->resize(width, height);
window_->move(x, y);
if (maximized)
@@ -321,11 +328,41 @@ void MainWindow::initialize(const InitState& init)
/**** Regexxer::MainWindow -- private **************************************/
+void MainWindow::on_startup()
+{
+ static struct
+ {
+ const char* const name;
+ sigc::slot<void> slot;
+ } appmenu_actions[] =
+ {
+ {"preferences", sigc::mem_fun(*this, &MainWindow::on_preferences)},
+ {"about", sigc::mem_fun(*this, &MainWindow::on_about)},
+ {"quit", sigc::mem_fun(*this, &MainWindow::on_quit)},
+ {0},
+ };
+
+ Glib::RefPtr<Gtk::Builder> builder =
+ Gtk::Builder::create_from_file(ui_appmenu_filename);
+
+ for (int i = 0; appmenu_actions[i].name; i++)
+ {
+ Glib::RefPtr<Gio::SimpleAction> action =
+ Gio::SimpleAction::create(appmenu_actions[i].name);
+ application_->add_action(action);
+ action->signal_activate().connect(sigc::hide(appmenu_actions[i].slot));
+ }
+
+ Glib::RefPtr<Gio::MenuModel> appmenu =
+ Glib::RefPtr<Gio::MenuModel>::cast_static(builder->get_object("appmenu"));
+ application_->set_app_menu(appmenu);
+}
+
void MainWindow::load_xml()
{
const Glib::RefPtr<Gtk::Builder> xml = Gtk::Builder::create_from_file(ui_mainwindow_filename);
- Gtk::Window* mainwindow = 0;
+ Gtk::ApplicationWindow* mainwindow = 0;
xml->get_widget("mainwindow", mainwindow);
window_.reset(mainwindow);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index e5d2f2c..850a2c8 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -29,6 +29,7 @@
#include <sigc++/sigc++.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
+#include <gtkmm/applicationwindow.h>
#include <list>
#include <memory>
#include <vector>
@@ -41,6 +42,7 @@ class Dialog;
class Entry;
class FileChooser;
class Toolbar;
+class ApplicationWindow;
class Window;
class ComboBox;
class ComboBoxText;
@@ -86,13 +88,15 @@ public:
MainWindow();
virtual ~MainWindow();
- void initialize(const InitState& init);
- Gtk::Window* get_window() { return window_.get(); }
+ void initialize(const Glib::RefPtr<Gtk::Application>& application,
+ const InitState& init);
+ Gtk::Window* get_window() { return static_cast<Gtk::Window*>(window_.get()); }
private:
class BusyAction;
- std::auto_ptr<Gtk::Window> window_;
+ Glib::RefPtr<Gtk::Application> application_;
+ std::auto_ptr<Gtk::ApplicationWindow> window_;
Controller controller_;
Gtk::Box* vbox_main_;
@@ -139,6 +143,7 @@ private:
std::auto_ptr<Gtk::Dialog> about_dialog_;
std::auto_ptr<PrefDialog> pref_dialog_;
+ void on_startup();
void load_xml();
void connect_signals();
bool autorun_idle();
diff --git a/ui/app-menu.xml b/ui/app-menu.xml
new file mode 100644
index 0000000..06957dc
--- /dev/null
+++ b/ui/app-menu.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">app.preferences</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]