[gnome-builder/wip/gtk4-port: 130/343] libide/gui: add basic run menu port




commit f7aa443bfdf1f4f9e7961bb02e97b23891555006
Author: Christian Hergert <chergert redhat com>
Date:   Tue Mar 29 02:02:59 2022 -0700

    libide/gui: add basic run menu port

 src/libide/gui/ide-run-button.c  | 67 ++++++++++++++++++++++++----------------
 src/libide/gui/ide-run-button.h  | 10 +++++-
 src/libide/gui/ide-run-button.ui | 47 +++-------------------------
 src/libide/gui/libide-gui.h      |  1 +
 src/libide/gui/meson.build       |  4 +--
 5 files changed, 56 insertions(+), 73 deletions(-)
---
diff --git a/src/libide/gui/ide-run-button.c b/src/libide/gui/ide-run-button.c
index 9476a08af..799bd28bf 100644
--- a/src/libide/gui/ide-run-button.c
+++ b/src/libide/gui/ide-run-button.c
@@ -22,30 +22,23 @@
 
 #include "config.h"
 
-#include <dazzle.h>
 #include <glib/gi18n.h>
+
 #include <libide-foundry.h>
 
+#include "ide-application.h"
 #include "ide-gui-global.h"
 #include "ide-run-button.h"
-
 #include "ide-run-manager-private.h"
 
 struct _IdeRunButton
 {
-  GtkBox                parent_instance;
-
-  GtkButton            *button;
-  GtkImage             *button_image;
-  DzlMenuButton        *menu_button;
-  GtkShortcutsShortcut *run_shortcut;
-  GtkLabel             *run_tooltip_message;
-  DzlShortcutTooltip   *tooltip;
-
-  char *run_handler_icon_name;
+  GtkWidget       parent_instance;
+  AdwSplitButton *split_button;
+  char           *run_handler_icon_name;
 };
 
-G_DEFINE_FINAL_TYPE (IdeRunButton, ide_run_button, GTK_TYPE_BOX)
+G_DEFINE_FINAL_TYPE (IdeRunButton, ide_run_button, GTK_TYPE_WIDGET)
 
 static void
 ide_run_button_handler_set (IdeRunButton  *self,
@@ -69,7 +62,7 @@ ide_run_button_handler_set (IdeRunButton  *self,
       if (g_strcmp0 (info->id, handler) == 0)
         {
           self->run_handler_icon_name = g_strdup (info->icon_name);
-          g_object_set (self->button_image, "icon-name", info->icon_name, NULL);
+          g_object_set (self->split_button, "icon-name", info->icon_name, NULL);
           break;
         }
     }
@@ -97,8 +90,8 @@ on_run_busy_state_changed_cb (IdeRunButton  *self,
       action_name = "run-manager.stop";
     }
 
-  g_object_set (self->button_image, "icon-name", icon_name, NULL);
-  gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), action_name);
+  g_object_set (self->split_button, "icon-name", icon_name, NULL);
+  gtk_actionable_set_action_name (GTK_ACTIONABLE (self->split_button), action_name);
 }
 
 static void
@@ -175,7 +168,10 @@ ide_run_button_query_tooltip (IdeRunButton *self,
 
       if (g_strcmp0 (info->id, handler) == 0)
         {
+          g_autofree char *text = NULL;
+
           gboolean enabled;
+
           /* Figure out if the run action is enabled. If it
            * is not, then we should inform the user that
            * the project cannot be run yet because the
@@ -190,39 +186,56 @@ ide_run_button_query_tooltip (IdeRunButton *self,
 
           if (!enabled)
             {
-              gtk_tooltip_set_custom (tooltip, GTK_WIDGET (self->run_tooltip_message));
+              gtk_tooltip_set_text (tooltip, _("Invalid project configuration"));
               return TRUE;
             }
 
-          /* The shortcut tooltip will set this up after us */
-          dzl_shortcut_tooltip_set_accel (self->tooltip, info->accel);
-          dzl_shortcut_tooltip_set_title (self->tooltip, info->title);
+          if (info->accel && info->title)
+            text = g_strdup_printf ("%s %s", info->accel, info->title);
+          else if (info->title)
+            text = g_strdup (info->title);
+
+          gtk_tooltip_set_text (tooltip, text);
         }
     }
 
   return FALSE;
 }
 
+static void
+ide_run_button_dispose (GObject *object)
+{
+  IdeRunButton *self = (IdeRunButton *)object;
+
+  g_clear_pointer ((GtkWidget **)&self->split_button, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (ide_run_button_parent_class)->dispose (object);
+}
+
 static void
 ide_run_button_class_init (IdeRunButtonClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ide_run_button_dispose;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/libide-gui/ui/ide-run-button.ui");
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, button);
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, button_image);
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, menu_button);
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, run_shortcut);
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, run_tooltip_message);
-  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, tooltip);
+  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+  gtk_widget_class_bind_template_child (widget_class, IdeRunButton, split_button);
 }
 
 static void
 ide_run_button_init (IdeRunButton *self)
 {
+  GMenu *menu;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  g_signal_connect_object (self->button,
+  menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "run-menu");
+  adw_split_button_set_menu_model (self->split_button, G_MENU_MODEL (menu));
+
+  g_signal_connect_object (self->split_button,
                            "query-tooltip",
                            G_CALLBACK (ide_run_button_query_tooltip),
                            self,
diff --git a/src/libide/gui/ide-run-button.h b/src/libide/gui/ide-run-button.h
index f758c3adc..ac05a0ddc 100644
--- a/src/libide/gui/ide-run-button.h
+++ b/src/libide/gui/ide-run-button.h
@@ -20,14 +20,22 @@
 
 #pragma once
 
+#if !defined (IDE_GUI_INSIDE) && !defined (IDE_GUI_COMPILATION)
+# error "Only <libide-gui.h> can be included directly."
+#endif
+
 #include <gtk/gtk.h>
 
+#include <libide-core.h>
+
 G_BEGIN_DECLS
 
 #define IDE_TYPE_RUN_BUTTON (ide_run_button_get_type())
 
-G_DECLARE_FINAL_TYPE (IdeRunButton, ide_run_button, IDE, RUN_BUTTON, GtkBox)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeRunButton, ide_run_button, IDE, RUN_BUTTON, GtkWidget)
 
+IDE_AVAILABLE_IN_ALL
 GtkWidget *ide_run_button_new (void);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-run-button.ui b/src/libide/gui/ide-run-button.ui
index f75308b9f..fadbd879d 100644
--- a/src/libide/gui/ide-run-button.ui
+++ b/src/libide/gui/ide-run-button.ui
@@ -1,51 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <object class="GtkShortcutsShortcut" id="run_shortcut">
-  </object>
-  <object class="GtkLabel" id="run_tooltip_message">
-    <property name="label" translatable="yes">The project cannot be run while the build pipeline is being 
set up</property>
-    <property name="visible">true</property>
-  </object>
-  <template class="IdeRunButton" parent="GtkBox">
-    <property name="orientation">horizontal</property>
-    <style>
-      <class name="linked"/>
-    </style>
+  <requires lib="gtk" version="4.0"/>
+  <template class="IdeRunButton" parent="GtkWidget">
     <child>
-      <object class="GtkButton" id="button">
-        <property name="focus-on-click">false</property>
-        <property name="has-tooltip">true</property>
-        <property name="visible">true</property>
+      <object class="AdwSplitButton" id="split_button">
         <property name="action-name">run-manager.run</property>
-        <style>
-          <class name="image-button"/>
-        </style>
-        <child>
-          <object class="GtkImage" id="button_image">
-            <property name="icon-name">builder-run-start-symbolic</property>
-            <property name="visible">true</property>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child>
-      <object class="DzlMenuButton" id="menu_button">
-        <property name="focus-on-click">false</property>
-        <property name="icon-name">pan-down-symbolic</property>
-        <property name="menu-id">run-menu</property>
-        <property name="show-accels">true</property>
-        <property name="show-arrow">false</property>
-        <property name="show-icons">true</property>
-        <property name="tooltip-text" translatable="yes">Change run options</property>
-        <property name="visible">true</property>
-        <style>
-          <class name="image-button"/>
-          <class name="run-arrow-button"/>
-        </style>
+        <property name="icon-name">builder-run-start-symbolic</property>
       </object>
     </child>
   </template>
-  <object class="DzlShortcutTooltip" id="tooltip">
-    <property name="widget">button</property>
-  </object>
 </interface>
diff --git a/src/libide/gui/libide-gui.h b/src/libide/gui/libide-gui.h
index e2a2ebc37..38030fa78 100644
--- a/src/libide/gui/libide-gui.h
+++ b/src/libide/gui/libide-gui.h
@@ -48,6 +48,7 @@
 # include "ide-preferences-addin.h"
 # include "ide-preferences-window.h"
 # include "ide-primary-workspace.h"
+# include "ide-run-button.h"
 # include "ide-session-addin.h"
 # include "ide-workbench.h"
 # include "ide-workbench-addin.h"
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 7e3864f57..dc0c360a7 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -25,6 +25,7 @@ libide_gui_public_headers = [
   'ide-preferences-addin.h',
   'ide-preferences-window.h',
   'ide-primary-workspace.h',
+  'ide-run-button.h',
   'ide-session-addin.h',
   'ide-workbench.h',
   'ide-workbench-addin.h',
@@ -48,7 +49,6 @@ libide_gui_private_headers = [
   'ide-notification-view-private.h',
   'ide-preferences-builtin-private.h',
   'ide-primary-workspace-private.h',
-  'ide-run-button.h',
   'ide-session-private.h',
 ]
 
@@ -63,7 +63,6 @@ libide_gui_private_sources = [
   'ide-notification-view.c',
   'ide-preferences-builtin.c',
   'ide-primary-workspace-actions.c',
-  'ide-run-button.c',
   'ide-session.c',
   'ide-workspace-actions.c',
 ]
@@ -89,6 +88,7 @@ libide_gui_public_sources = [
   'ide-primary-workspace.c',
   'ide-preferences-addin.c',
   'ide-preferences-window.c',
+  'ide-run-button.c',
   'ide-session-addin.c',
   'ide-workbench.c',
   'ide-workbench-addin.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]