|
|
121cca |
From bc5046d9917fe9cf84dd899f90aef5b90b7d4b04 Mon Sep 17 00:00:00 2001
|
|
|
121cca |
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
121cca |
Date: Wed, 15 Jul 2020 16:54:27 +0200
|
|
|
121cca |
Subject: [PATCH 34/65] Move from GtkMenuBar to GMenu
|
|
|
121cca |
|
|
|
121cca |
This moves forward with gtk4 support, while also allowing a global menu
|
|
|
121cca |
for environments which use one, such as GNOME.
|
|
|
121cca |
|
|
|
121cca |
I also added shortcuts so that users can press ^Q, ^R and ^S to quit,
|
|
|
121cca |
refresh and save.
|
|
|
121cca |
---
|
|
|
121cca |
src/gui/gtk-lshw.c | 2 +-
|
|
|
121cca |
src/gui/gtk-lshw.ui | 138 ++++++++++++--------------------------------
|
|
|
121cca |
src/gui/stock.c | 6 +-
|
|
|
121cca |
src/gui/stock.h | 4 +-
|
|
|
121cca |
4 files changed, 47 insertions(+), 103 deletions(-)
|
|
|
121cca |
|
|
|
121cca |
diff --git a/src/gui/gtk-lshw.c b/src/gui/gtk-lshw.c
|
|
|
121cca |
index 7b91ec5..d3e531c 100644
|
|
|
121cca |
--- a/src/gui/gtk-lshw.c
|
|
|
121cca |
+++ b/src/gui/gtk-lshw.c
|
|
|
121cca |
@@ -57,7 +57,7 @@ activate (GApplication *app,
|
|
|
121cca |
g_simple_action_set_enabled(save_action, FALSE);
|
|
|
121cca |
|
|
|
121cca |
lshw_gtk_stock_init();
|
|
|
121cca |
- lshw_ui_init();
|
|
|
121cca |
+ lshw_ui_init(GTK_APPLICATION(app));
|
|
|
121cca |
|
|
|
121cca |
if(!mainwindow)
|
|
|
121cca |
return;
|
|
|
121cca |
diff --git a/src/gui/gtk-lshw.ui b/src/gui/gtk-lshw.ui
|
|
|
121cca |
index 76fcd19..cf9d678 100644
|
|
|
121cca |
--- a/src/gui/gtk-lshw.ui
|
|
|
121cca |
+++ b/src/gui/gtk-lshw.ui
|
|
|
121cca |
@@ -103,7 +103,6 @@
|
|
|
121cca |
</action-widgets>
|
|
|
121cca |
</object>
|
|
|
121cca |
<object class="GtkApplicationWindow" id="mainwindow">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
<property name="can_focus">False</property>
|
|
|
121cca |
<property name="title" translatable="yes">lshw</property>
|
|
|
121cca |
<property name="default_width">700</property>
|
|
|
121cca |
@@ -115,105 +114,6 @@
|
|
|
121cca |
<property name="visible">True</property>
|
|
|
121cca |
<property name="can_focus">False</property>
|
|
|
121cca |
<property name="orientation">GTK_ORIENTATION_VERTICAL</property>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkMenuBar" id="menubar1">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkMenuItem" id="menuitem1">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="label" translatable="yes">_File</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <child type="submenu">
|
|
|
121cca |
- <object class="GtkMenu" id="menu1">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkImageMenuItem" id="savemenu">
|
|
|
121cca |
- <property name="label">gtk-save</property>
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <property name="use_stock">True</property>
|
|
|
121cca |
- <property name="action_name">app.save</property>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkImageMenuItem" id="imagemenuitem5">
|
|
|
121cca |
- <property name="label">gtk-quit</property>
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <property name="use_stock">True</property>
|
|
|
121cca |
- <property name="action_name">app.quit</property>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkMenuItem" id="menuitem3">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="label" translatable="yes">_View</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <child type="submenu">
|
|
|
121cca |
- <object class="GtkMenu" id="menu2">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkImageMenuItem" id="refresh1">
|
|
|
121cca |
- <property name="label">gtk-refresh</property>
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <property name="use_stock">True</property>
|
|
|
121cca |
- <property name="action_name">app.refresh</property>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkMenuItem" id="menuitem4">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="label" translatable="yes">_Help</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <child type="submenu">
|
|
|
121cca |
- <object class="GtkMenu" id="menu3">
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <child>
|
|
|
121cca |
- <object class="GtkImageMenuItem" id="imagemenuitem10">
|
|
|
121cca |
- <property name="label">gtk-about</property>
|
|
|
121cca |
- <property name="visible">True</property>
|
|
|
121cca |
- <property name="can_focus">False</property>
|
|
|
121cca |
- <property name="use_underline">True</property>
|
|
|
121cca |
- <property name="use_stock">True</property>
|
|
|
121cca |
- <property name="action_name">app.about</property>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- </child>
|
|
|
121cca |
- </object>
|
|
|
121cca |
- <packing>
|
|
|
121cca |
- <property name="expand">False</property>
|
|
|
121cca |
- <property name="fill">True</property>
|
|
|
121cca |
- <property name="position">0</property>
|
|
|
121cca |
- </packing>
|
|
|
121cca |
- </child>
|
|
|
121cca |
<child>
|
|
|
121cca |
<object class="GtkToolbar" id="toolbar1">
|
|
|
121cca |
<property name="visible">True</property>
|
|
|
121cca |
@@ -423,4 +323,42 @@
|
|
|
121cca |
</object>
|
|
|
121cca |
</child>
|
|
|
121cca |
</object>
|
|
|
121cca |
+ <menu id="menubar">
|
|
|
121cca |
+ <submenu>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_File</attribute>
|
|
|
121cca |
+ <section>
|
|
|
121cca |
+ <item>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_Save</attribute>
|
|
|
121cca |
+ <attribute name="action">app.save</attribute>
|
|
|
121cca |
+ <attribute name="accel"><Control>s</attribute>
|
|
|
121cca |
+ </item>
|
|
|
121cca |
+ </section>
|
|
|
121cca |
+ <section>
|
|
|
121cca |
+ <item>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_Quit</attribute>
|
|
|
121cca |
+ <attribute name="action">app.quit</attribute>
|
|
|
121cca |
+ <attribute name="accel"><Control>q</attribute>
|
|
|
121cca |
+ </item>
|
|
|
121cca |
+ </section>
|
|
|
121cca |
+ </submenu>
|
|
|
121cca |
+ <submenu>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_View</attribute>
|
|
|
121cca |
+ <section>
|
|
|
121cca |
+ <item>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_Refresh</attribute>
|
|
|
121cca |
+ <attribute name="action">app.refresh</attribute>
|
|
|
121cca |
+ <attribute name="accel"><Control>r</attribute>
|
|
|
121cca |
+ </item>
|
|
|
121cca |
+ </section>
|
|
|
121cca |
+ </submenu>
|
|
|
121cca |
+ <submenu>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_Help</attribute>
|
|
|
121cca |
+ <section>
|
|
|
121cca |
+ <item>
|
|
|
121cca |
+ <attribute name="label" translatable="yes">_About</attribute>
|
|
|
121cca |
+ <attribute name="action">app.about</attribute>
|
|
|
121cca |
+ </item>
|
|
|
121cca |
+ </section>
|
|
|
121cca |
+ </submenu>
|
|
|
121cca |
+ </menu>
|
|
|
121cca |
</interface>
|
|
|
121cca |
diff --git a/src/gui/stock.c b/src/gui/stock.c
|
|
|
121cca |
index fa18f9e..ce0b42a 100644
|
|
|
121cca |
--- a/src/gui/stock.c
|
|
|
121cca |
+++ b/src/gui/stock.c
|
|
|
121cca |
@@ -14,6 +14,7 @@ GtkWidget *list2 = NULL;
|
|
|
121cca |
GtkWidget *list3 = NULL;
|
|
|
121cca |
GtkWidget *description = NULL;
|
|
|
121cca |
GtkWidget *statusbar = NULL;
|
|
|
121cca |
+GMenuModel *menubar = NULL;
|
|
|
121cca |
GHashTable *pixbufs = NULL;
|
|
|
121cca |
|
|
|
121cca |
static struct StockIcon
|
|
|
121cca |
@@ -118,7 +119,7 @@ lshw_gtk_stock_init(void)
|
|
|
121cca |
(void) &id; /* avoid "id defined but not used" warning */
|
|
|
121cca |
}
|
|
|
121cca |
|
|
|
121cca |
-void lshw_ui_init(void)
|
|
|
121cca |
+void lshw_ui_init(GtkApplication *app)
|
|
|
121cca |
{
|
|
|
121cca |
GError *error = NULL;
|
|
|
121cca |
GtkBuilder *builder = NULL;
|
|
|
121cca |
@@ -151,6 +152,9 @@ void lshw_ui_init(void)
|
|
|
121cca |
description = GTK_WIDGET(gtk_builder_get_object( builder, "description"));
|
|
|
121cca |
statusbar = GTK_WIDGET(gtk_builder_get_object( builder, "statusbar"));
|
|
|
121cca |
gtk_builder_connect_signals( builder, mainwindow );
|
|
|
121cca |
+ menubar = G_MENU_MODEL( gtk_builder_get_object( builder, "menubar"));
|
|
|
121cca |
+ gtk_window_set_application( GTK_WINDOW( mainwindow ), app );
|
|
|
121cca |
+ gtk_application_set_menubar( app, menubar );
|
|
|
121cca |
g_object_unref( G_OBJECT( builder ) );
|
|
|
121cca |
|
|
|
121cca |
icon = g_hash_table_lookup(pixbufs, LSHW_STOCK_LOGO);
|
|
|
121cca |
diff --git a/src/gui/stock.h b/src/gui/stock.h
|
|
|
121cca |
index 58f788e..1c732df 100644
|
|
|
121cca |
--- a/src/gui/stock.h
|
|
|
121cca |
+++ b/src/gui/stock.h
|
|
|
121cca |
@@ -45,6 +45,8 @@
|
|
|
121cca |
*/
|
|
|
121cca |
#define LSHW_DEFAULT_ICON_SIZE 40
|
|
|
121cca |
|
|
|
121cca |
+typedef struct _GtkApplication GtkApplication;
|
|
|
121cca |
+
|
|
|
121cca |
void lshw_gtk_stock_init(void);
|
|
|
121cca |
-void lshw_ui_init(void);
|
|
|
121cca |
+void lshw_ui_init(GtkApplication *);
|
|
|
121cca |
#endif /* _STOCK_H_ */
|
|
|
121cca |
--
|
|
|
121cca |
2.33.1
|
|
|
121cca |
|