[gnome-system-monitor] Port to Application menu
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Port to Application menu
- Date: Sun, 30 Sep 2012 20:45:31 +0000 (UTC)
commit 86290b6aaa4243ea89a04bbe40ca08d5c7d2a51f
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Sep 30 23:44:22 2012 +0300
Port to Application menu
Makefile.am | 3 +-
configure.ac | 2 +-
data/interface.ui | 70 ++++++++++++++++++++++++++++++++-
data/menus.ui | 30 ++++++++++++++
po/POTFILES.in | 1 +
src/interface.cpp | 105 ++++++++++++++++----------------------------------
src/procman-app.cpp | 52 +++++++++++++++++++++++++
src/procman-app.h | 6 +++
8 files changed, 193 insertions(+), 76 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e4159d6..375aee0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,8 @@ ui_DATA = data/preferences.ui \
data/renice.ui \
data/lsof.ui \
data/openfiles.ui \
- data/interface.ui
+ data/interface.ui \
+ data/menus.ui
EXTRA_DIST = \
$(ui_DATA) \
diff --git a/configure.ac b/configure.ac
index fc9f990..ca10f50 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@ LT_INIT
GLIB_REQUIRED=2.28.0
LIBWNCK_REQUIRED=2.91.0
LIBGTOP_REQUIRED=2.28.2
-GTK_REQUIRED=3.0
+GTK_REQUIRED=3.5.12
GNOME_ICON_THEME_REQUIRED=2.31
GTKMM_REQUIRED=3.3.18
GIOMM_REQUIRED=2.27
diff --git a/data/interface.ui b/data/interface.ui
index 6264492..b527b47 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -54,10 +54,74 @@
<property name="orientation">vertical</property>
<property name="spacing">18</property>
<child>
- <object class="GtkLabel" id="load_avg_label">
+ <object class="GtkBox" id="proc_top_box">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">start</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkLabel" id="load_avg_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="refreshbutton">
+ <property name="label">Refresh</property>
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkMenuButton" id="viewmenubutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">View</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkArrow" id="arrow1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="arrow_type">down</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/data/menus.ui b/data/menus.ui
new file mode 100644
index 0000000..94b7ba6
--- /dev/null
+++ b/data/menus.ui
@@ -0,0 +1,30 @@
+<interface>
+ <menu id='app-menu'>
+ <section>
+ <item>
+ <attribute name='label' translatable='yes'>Search for Open Files</attribute>
+ <attribute name='action'>app.lsof</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name='label' translatable='yes'>Preferences</attribute>
+ <attribute name='action'>app.preferences</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name='label' translatable='yes'>Help</attribute>
+ <attribute name='action'>app.help</attribute>
+ </item>
+ <item>
+ <attribute name='label' translatable='yes'>About</attribute>
+ <attribute name='action'>win.about</attribute>
+ </item>
+ <item>
+ <attribute name='label' translatable='yes'>Quit</attribute>
+ <attribute name='action'>app.quit</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4ddd698..c95f5e8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@
gnome-system-monitor.desktop.in.in
[type: gettext/glade]data/interface.ui
[type: gettext/glade]data/lsof.ui
+[type: gettext/glade]data/menus.ui
[type: gettext/glade]data/openfiles.ui
[type: gettext/glade]data/preferences.ui
[type: gettext/glade]data/renice.ui
diff --git a/src/interface.cpp b/src/interface.cpp
index ddfdcc9..114ea28 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -46,18 +46,7 @@ static void cb_proc_goto_tab (gint tab);
static const GtkActionEntry menu_entries[] =
{
- // xgettext: noun, top level menu.
- // "File" did not make sense for system-monitor
- { "Monitor", NULL, N_("_Monitor") },
- { "Edit", NULL, N_("_Edit") },
{ "View", NULL, N_("_View") },
- { "Help", NULL, N_("_Help") },
-
- { "Lsof", GTK_STOCK_FIND, N_("Search for _Open Files"), "<control>O",
- N_("Search for open files"), G_CALLBACK(cb_show_lsof) },
- { "Quit", GTK_STOCK_QUIT, NULL, NULL,
- N_("Quit the program"), G_CALLBACK (cb_app_exit) },
-
{ "StopProcess", NULL, N_("_Stop Process"), "<control>S",
N_("Stop process"), G_CALLBACK(cb_kill_sigstop) },
@@ -70,8 +59,6 @@ static const GtkActionEntry menu_entries[] =
N_("Force process to finish immediately"), G_CALLBACK (cb_kill_process) },
{ "ChangePriority", NULL, N_("_Change Priority"), NULL,
N_("Change the order of priority of process"), NULL },
- { "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL,
- N_("Configure the application"), G_CALLBACK (cb_edit_preferences) },
{ "Refresh", GTK_STOCK_REFRESH, N_("_Refresh"), "<control>R",
N_("Refresh the process list"), G_CALLBACK(cb_user_refresh) },
@@ -83,12 +70,6 @@ static const GtkActionEntry menu_entries[] =
N_("View the files opened by a process"), G_CALLBACK (cb_show_open_files) },
{ "ProcessProperties", NULL, N_("_Properties"), NULL,
N_("View additional information about a process"), G_CALLBACK (cb_show_process_properties) },
-
-
- { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1",
- N_("Open the manual"), G_CALLBACK (cb_help_contents) },
- { "About", GTK_STOCK_ABOUT, NULL, NULL,
- N_("About this application"), G_CALLBACK (cb_about) }
};
static const GtkToggleActionEntry toggle_menu_entries[] =
@@ -127,49 +108,6 @@ static const GtkRadioActionEntry priority_menu_entries[] =
static const char ui_info[] =
- " <menubar name=\"MenuBar\">"
- " <menu name=\"MonitorMenu\" action=\"Monitor\">"
- " <menuitem name=\"MonitorLsofMenu\" action=\"Lsof\" />"
- " <menuitem name=\"MonitorQuitMenu\" action=\"Quit\" />"
- " </menu>"
- " <menu name=\"EditMenu\" action=\"Edit\">"
- " <menuitem name=\"EditStopProcessMenu\" action=\"StopProcess\" />"
- " <menuitem name=\"EditContProcessMenu\" action=\"ContProcess\" />"
- " <separator />"
- " <menuitem name=\"EditEndProcessMenu\" action=\"EndProcess\" />"
- " <menuitem name=\"EditKillProcessMenu\" action=\"KillProcess\" />"
- " <separator />"
- " <menu name=\"EditChangePriorityMenu\" action=\"ChangePriority\" >"
- " <menuitem action=\"VeryHigh\" />"
- " <menuitem action=\"High\" />"
- " <menuitem action=\"Normal\" />"
- " <menuitem action=\"Low\" />"
- " <menuitem action=\"VeryLow\" />"
- " <separator />"
- " <menuitem action=\"Custom\"/>"
- " </menu>"
- " <separator />"
- " <menuitem name=\"EditPreferencesMenu\" action=\"Preferences\" />"
- " </menu>"
- " <menu name=\"ViewMenu\" action=\"View\">"
- " <menuitem name=\"ViewActiveProcesses\" action=\"ShowActiveProcesses\" />"
- " <menuitem name=\"ViewAllProcesses\" action=\"ShowAllProcesses\" />"
- " <menuitem name=\"ViewMyProcesses\" action=\"ShowMyProcesses\" />"
- " <separator />"
- " <menuitem name=\"ViewDependenciesMenu\" action=\"ShowDependencies\" />"
- " <separator />"
- " <menuitem name=\"ViewMemoryMapsMenu\" action=\"MemoryMaps\" />"
- " <menuitem name=\"ViewOpenFilesMenu\" action=\"OpenFiles\" />"
- " <separator />"
- " <menuitem name=\"ViewProcessPropertiesMenu\" action=\"ProcessProperties\" />"
- " <separator />"
- " <menuitem name=\"ViewRefresh\" action=\"Refresh\" />"
- " </menu>"
- " <menu name=\"HelpMenu\" action=\"Help\">"
- " <menuitem name=\"HelpContentsMenu\" action=\"HelpContents\" />"
- " <menuitem name=\"HelpAboutMenu\" action=\"About\" />"
- " </menu>"
- " </menubar>"
" <popup name=\"PopupMenu\" action=\"Popup\">"
" <menuitem action=\"StopProcess\" />"
" <menuitem action=\"ContProcess\" />"
@@ -191,7 +129,13 @@ static const char ui_info[] =
" <menuitem action=\"OpenFiles\" />"
" <separator />"
" <menuitem action=\"ProcessProperties\" />"
-
+ " </popup>"
+ " <popup name=\"ViewMenu\" action=\"View\">"
+ " <menuitem name=\"ViewActiveProcesses\" action=\"ShowActiveProcesses\" />"
+ " <menuitem name=\"ViewAllProcesses\" action=\"ShowAllProcesses\" />"
+ " <menuitem name=\"ViewMyProcesses\" action=\"ShowMyProcesses\" />"
+ " <separator />"
+ " <menuitem name=\"ViewDependencies\" action=\"ShowDependencies\" />"
" </popup>";
@@ -216,6 +160,9 @@ create_proc_view(ProcData *procdata, GtkBuilder * builder)
{
GtkWidget *proctree;
GtkWidget *scrolled;
+ GtkWidget *viewmenu;
+ GtkWidget *button;
+ GtkAction *action;
char* string;
/* create the processes tab */
@@ -233,6 +180,15 @@ create_proc_view(ProcData *procdata, GtkBuilder * builder)
g_signal_connect (G_OBJECT (procdata->endprocessbutton), "clicked",
G_CALLBACK (cb_end_process_button_pressed), procdata);
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "viewmenubutton"));
+ viewmenu = gtk_ui_manager_get_widget (procdata->uimanager, "/ViewMenu");
+ gtk_widget_set_halign (viewmenu, GTK_ALIGN_END);
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), viewmenu);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "refreshbutton"));
+ action = gtk_action_group_get_action (procdata->action_group, "Refresh");
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
+
/* create popup_menu for the processes tab */
procdata->popup_menu = gtk_ui_manager_get_widget (procdata->uimanager, "/PopupMenu");
}
@@ -393,6 +349,12 @@ create_sys_view (ProcData *procdata, GtkBuilder * builder)
}
+static void
+on_activate_about (GSimpleAction *, GVariant *, gpointer data)
+{
+ cb_about (NULL, data);
+}
+
void
create_main_window (ProcData *procdata, GtkApplication *application)
{
@@ -400,8 +362,6 @@ create_main_window (ProcData *procdata, GtkApplication *application)
gint width, height, xpos, ypos;
GtkWidget *app;
GtkAction *action;
- GtkWidget *menubar;
- GtkWidget *main_box;
GtkWidget *notebook;
gchar* filename = g_build_filename (GSM_DATA_DIR, "interface.ui", NULL);
@@ -412,7 +372,15 @@ create_main_window (ProcData *procdata, GtkApplication *application)
app = GTK_WIDGET (gtk_builder_get_object (builder, "main_window"));
gtk_window_set_application (GTK_WINDOW (app), application);
- main_box = GTK_WIDGET (gtk_builder_get_object (builder, "main_box"));
+ GActionEntry win_action_entries[] = {
+ { "about", on_activate_about, NULL, NULL, NULL }
+ };
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ win_action_entries,
+ G_N_ELEMENTS (win_action_entries),
+ procdata);
+
GdkScreen* screen = gtk_widget_get_screen(app);
GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
@@ -430,7 +398,6 @@ create_main_window (ProcData *procdata, GtkApplication *application)
gtk_window_maximize(GTK_WINDOW(app));
}
- /* create the menubar */
procdata->uimanager = gtk_ui_manager_new ();
gtk_window_add_accel_group (GTK_WINDOW (app),
@@ -472,10 +439,6 @@ create_main_window (ProcData *procdata, GtkApplication *application)
procdata->action_group,
0);
- menubar = gtk_ui_manager_get_widget (procdata->uimanager, "/MenuBar");
- gtk_box_pack_start (GTK_BOX (main_box), menubar, FALSE, FALSE, 0);
-
-
/* create the main notebook */
procdata->notebook = notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook"));
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index d4e43aa..9215cc6 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -1,3 +1,5 @@
+#include <config.h>
+
#include <glib/gi18n.h>
#include <glibtop.h>
#include <glibtop/close.h>
@@ -407,10 +409,60 @@ int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>&
return 0;
}
+void
+ProcmanApp::on_help_activate(const Glib::VariantBase&)
+{
+ cb_help_contents (NULL, NULL);
+}
+
+void
+ProcmanApp::on_lsof_activate(const Glib::VariantBase&)
+{
+ cb_show_lsof (NULL, procdata);
+}
+
+void
+ProcmanApp::on_preferences_activate(const Glib::VariantBase&)
+{
+ cb_edit_preferences (NULL, procdata);
+}
+
+void
+ProcmanApp::on_quit_activate(const Glib::VariantBase&)
+{
+ this->quit();
+}
+
+
void ProcmanApp::on_startup()
{
Gtk::Application::on_startup();
+ Glib::RefPtr<Gio::SimpleAction> action;
+
+ action = Gio::SimpleAction::create("quit");
+ action->signal_activate().connect(sigc::mem_fun(*this, &ProcmanApp::on_quit_activate));
+ add_action(action);
+
+ action = Gio::SimpleAction::create("help");
+ action->signal_activate().connect(sigc::mem_fun(*this, &ProcmanApp::on_help_activate));
+ add_action(action);
+
+ action = Gio::SimpleAction::create("lsof");
+ action->signal_activate().connect(sigc::mem_fun(*this, &ProcmanApp::on_lsof_activate));
+ add_action(action);
+
+ action = Gio::SimpleAction::create("preferences");
+ action->signal_activate().connect(sigc::mem_fun(*this, &ProcmanApp::on_preferences_activate));
+ add_action(action);
+
+ char* filename = g_build_filename (GSM_DATA_DIR, "menus.ui", NULL);
+ Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file(filename);
+ g_free (filename);
+
+ Glib::RefPtr<Gio::Menu> menu = Glib::RefPtr<Gio::Menu>::cast_static(builder->get_object ("app-menu"));
+ set_app_menu (menu);
+
GSettings *settings;
Gtk::Window::set_default_icon_name ("utilities-system-monitor");
diff --git a/src/procman-app.h b/src/procman-app.h
index 0a883df..b1e24e7 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -7,7 +7,13 @@
class ProcmanApp : public Gtk::Application
{
+private:
ProcData *procdata;
+
+ void on_preferences_activate(const Glib::VariantBase&);
+ void on_lsof_activate(const Glib::VariantBase&);
+ void on_help_activate(const Glib::VariantBase&);
+ void on_quit_activate(const Glib::VariantBase&);
protected:
ProcmanApp();
public:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]