Blame SOURCES/0033-Enable-Disable-GSimpleAction-instead-of-button-sensi.patch

121cca
From a116b319adf51d4eafcb264de027647244340708 Mon Sep 17 00:00:00 2001
121cca
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
121cca
Date: Wed, 15 Jul 2020 17:32:45 +0200
121cca
Subject: [PATCH 33/65] Enable/Disable GSimpleAction instead of button
121cca
 sensitivity
121cca
121cca
This also fixes the Save menu item not having been disabled properly.
121cca
---
121cca
 src/gui/engine.cc   | 24 +++++++-----------------
121cca
 src/gui/gtk-lshw.c  |  7 +++++++
121cca
 src/gui/gtk-lshw.ui |  2 --
121cca
 src/gui/stock.c     |  4 ----
121cca
 4 files changed, 14 insertions(+), 23 deletions(-)
121cca
121cca
diff --git a/src/gui/engine.cc b/src/gui/engine.cc
121cca
index ff06074..2962ec8 100644
121cca
--- a/src/gui/engine.cc
121cca
+++ b/src/gui/engine.cc
121cca
@@ -37,10 +37,10 @@ static hwNode *selected3 = NULL;
121cca
 extern GtkWidget *mainwindow;
121cca
 extern GtkWidget *list1, *list2, *list3;
121cca
 extern GtkWidget *description;
121cca
-extern GtkWidget *go_up_button;
121cca
-extern GtkWidget *save_button;
121cca
 extern GtkWidget *statusbar;
121cca
 extern GHashTable *pixbufs;
121cca
+extern GSimpleAction *go_up_action;
121cca
+extern GSimpleAction *save_action;
121cca
 
121cca
 enum
121cca
 {
121cca
@@ -251,14 +251,11 @@ void refresh(GtkWidget *mainwindow)
121cca
 {
121cca
   hwNode computer("computer", hw::system);
121cca
   static bool lock = false;
121cca
-  //GtkWidget * menu = lookup_widget(mainwindow, "menu");
121cca
-  //GtkWidget * save_menuitem = lookup_widget(menu, "save");
121cca
 
121cca
   if(lock) return;
121cca
 
121cca
   lock = true;
121cca
-  gtk_widget_set_sensitive(save_button, FALSE);
121cca
-  //gtk_widget_set_sensitive(save_menuitem, FALSE);
121cca
+  g_simple_action_set_enabled(save_action, FALSE);
121cca
 
121cca
   populate_sublist(list1, NULL);
121cca
   populate_sublist(list2, NULL);
121cca
@@ -273,9 +270,8 @@ void refresh(GtkWidget *mainwindow)
121cca
   status(NULL);
121cca
   displayed = container.addChild(computer);
121cca
 
121cca
-  gtk_widget_set_sensitive(go_up_button, FALSE);
121cca
-  gtk_widget_set_sensitive(save_button, TRUE);
121cca
-  //gtk_widget_set_sensitive(save_menuitem, TRUE);
121cca
+  g_simple_action_set_enabled(go_up_action, FALSE);
121cca
+  g_simple_action_set_enabled(save_action, TRUE);
121cca
 
121cca
   selected1 = NULL;
121cca
   selected2 = NULL;
121cca
@@ -379,10 +375,7 @@ void browse(unsigned list, GtkTreeView *treeview)
121cca
       break;
121cca
   }
121cca
 
121cca
-  if(selected1 && (find_parent(selected1, &container)!= &container))
121cca
-    gtk_widget_set_sensitive(go_up_button, 1);
121cca
-  else
121cca
-    gtk_widget_set_sensitive(go_up_button, 0);
121cca
+  g_simple_action_set_enabled(go_up_action, selected1 && (find_parent(selected1, &container)!= &container));
121cca
 
121cca
   (void) &::id;                                   // avoid warning "id defined but not used"
121cca
 }
121cca
@@ -404,10 +397,7 @@ void go_back(GtkWidget *mainwindow)
121cca
       displayed = find_parent(displayed, &container);
121cca
   }
121cca
 
121cca
-  if(selected1 && (find_parent(selected1, &container)!= &container))
121cca
-    gtk_widget_set_sensitive(go_up_button, 1);
121cca
-  else
121cca
-    gtk_widget_set_sensitive(go_up_button, 0);
121cca
+  g_simple_action_set_enabled(go_up_action, selected1 && (find_parent(selected1, &container)!= &container));
121cca
 
121cca
   display(mainwindow);
121cca
 }
121cca
diff --git a/src/gui/gtk-lshw.c b/src/gui/gtk-lshw.c
121cca
index 0dc3aff..7b91ec5 100644
121cca
--- a/src/gui/gtk-lshw.c
121cca
+++ b/src/gui/gtk-lshw.c
121cca
@@ -11,6 +11,8 @@
121cca
 static char *id = "@(#) $Id$";
121cca
 
121cca
 extern GtkWidget *mainwindow;
121cca
+GSimpleAction *go_up_action;
121cca
+GSimpleAction *save_action;
121cca
 
121cca
 static GActionEntry app_entries[] =
121cca
 {
121cca
@@ -48,6 +50,11 @@ activate (GApplication *app,
121cca
   g_action_map_add_action_entries (G_ACTION_MAP (app),
121cca
                                    app_entries, G_N_ELEMENTS (app_entries),
121cca
                                    app);
121cca
+  go_up_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "go_up"));
121cca
+  save_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "save"));
121cca
+
121cca
+  g_simple_action_set_enabled(go_up_action, FALSE);
121cca
+  g_simple_action_set_enabled(save_action, FALSE);
121cca
 
121cca
   lshw_gtk_stock_init();
121cca
   lshw_ui_init();
121cca
diff --git a/src/gui/gtk-lshw.ui b/src/gui/gtk-lshw.ui
121cca
index d24e05c..76fcd19 100644
121cca
--- a/src/gui/gtk-lshw.ui
121cca
+++ b/src/gui/gtk-lshw.ui
121cca
@@ -222,7 +222,6 @@
121cca
             <child>
121cca
               <object class="GtkToolButton" id="upbutton">
121cca
                 <property name="visible">True</property>
121cca
-                <property name="sensitive">False</property>
121cca
                 <property name="can_focus">False</property>
121cca
                 <property name="stock_id">gtk-go-up</property>
121cca
                 <property name="action_name">app.go_up</property>
121cca
@@ -248,7 +247,6 @@
121cca
             <child>
121cca
               <object class="GtkToolButton" id="savebutton">
121cca
                 <property name="visible">True</property>
121cca
-                <property name="sensitive">False</property>
121cca
                 <property name="can_focus">False</property>
121cca
                 <property name="stock_id">gtk-save</property>
121cca
                 <property name="action_name">app.save</property>
121cca
diff --git a/src/gui/stock.c b/src/gui/stock.c
121cca
index 9e7c366..fa18f9e 100644
121cca
--- a/src/gui/stock.c
121cca
+++ b/src/gui/stock.c
121cca
@@ -13,8 +13,6 @@ GtkWidget *list1 = NULL;
121cca
 GtkWidget *list2 = NULL;
121cca
 GtkWidget *list3 = NULL;
121cca
 GtkWidget *description = NULL;
121cca
-GtkWidget *go_up_button = NULL;
121cca
-GtkWidget *save_button = NULL;
121cca
 GtkWidget *statusbar = NULL;
121cca
 GHashTable *pixbufs = NULL;
121cca
 
121cca
@@ -151,8 +149,6 @@ void lshw_ui_init(void)
121cca
   list2 = GTK_WIDGET(gtk_builder_get_object( builder, "treeview2"));
121cca
   list3 = GTK_WIDGET(gtk_builder_get_object( builder, "treeview3"));
121cca
   description = GTK_WIDGET(gtk_builder_get_object( builder, "description"));
121cca
-  go_up_button = GTK_WIDGET(gtk_builder_get_object( builder, "upbutton"));
121cca
-  save_button = GTK_WIDGET(gtk_builder_get_object( builder, "savebutton"));
121cca
   statusbar = GTK_WIDGET(gtk_builder_get_object( builder, "statusbar"));
121cca
   gtk_builder_connect_signals( builder, mainwindow );
121cca
   g_object_unref( G_OBJECT( builder ) );
121cca
-- 
121cca
2.33.1
121cca