Commit 3ebb5e17 authored by Fabien Parent's avatar Fabien Parent
Browse files

Add an AppMenu

parent cde8995c
......@@ -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
......
......@@ -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])
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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();
......
<?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>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment