[gnome-builder] workbench: use of DzlShortcut classes



commit 7f17eec6afae954ba52f0e4f110441b3f2e4d451
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sat Aug 12 19:32:39 2017 +0200

    workbench: use of DzlShortcut classes
    
    Impacted shortcuts, the perspective switch ones:
    Alt 1
    Alt 3
    ALt ,
    Ctrl ,

 libide/meson.build                         |    1 +
 libide/workbench/ide-workbench-private.h   |    2 +
 libide/workbench/ide-workbench-shortcuts.c |   65 ++++++++++++++++++++++++++++
 libide/workbench/ide-workbench.c           |   14 +------
 4 files changed, 69 insertions(+), 13 deletions(-)
---
diff --git a/libide/meson.build b/libide/meson.build
index f697bf2..e5e06e0 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -570,6 +570,7 @@ libide_sources = libide_generated_headers + libide_public_sources + [
   'workbench/ide-omni-bar-row.h',
   'workbench/ide-workbench-actions.c',
   'workbench/ide-workbench-private.h',
+  'workbench/ide-workbench-shortcuts.c',
   'workers/ide-worker-manager.c',
   'workers/ide-worker-manager.h',
   'workers/ide-worker-process.c',
diff --git a/libide/workbench/ide-workbench-private.h b/libide/workbench/ide-workbench-private.h
index 1e470ff..c818a60 100644
--- a/libide/workbench/ide-workbench-private.h
+++ b/libide/workbench/ide-workbench-private.h
@@ -60,6 +60,8 @@ GObject *ide_workbench_get_selection_owner        (IdeWorkbench          *self);
 
 void     _ide_workbench_header_bar_set_fullscreen (IdeWorkbenchHeaderBar *self,
                                                    gboolean               fullscreen);
+void     _ide_workbench_add_perspective_shortcut  (IdeWorkbench          *self,
+                                                   IdePerspective        *perspective);
 
 G_END_DECLS
 
diff --git a/libide/workbench/ide-workbench-shortcuts.c b/libide/workbench/ide-workbench-shortcuts.c
new file mode 100644
index 0000000..2e4cedd
--- /dev/null
+++ b/libide/workbench/ide-workbench-shortcuts.c
@@ -0,0 +1,65 @@
+/* ide-workbench-shortcuts.c
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-workbench-shortcuts"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <dazzle.h>
+
+#include "ide-workbench-private.h"
+
+void
+_ide_workbench_add_perspective_shortcut (IdeWorkbench   *self,
+                                         IdePerspective *perspective)
+{
+  g_autofree gchar *accel= NULL;
+
+  g_assert (IDE_IS_WORKBENCH (self));
+  g_assert (IDE_IS_PERSPECTIVE (perspective));
+
+  accel = ide_perspective_get_accelerator (perspective);
+  if (accel != NULL)
+    {
+      DzlShortcutController *controller;
+      g_autofree gchar *id = ide_perspective_get_id (perspective);
+      g_autofree gchar *command_id = g_strdup_printf ("org.gnome.builder.workbench.perspective('%s')", id);
+      g_autofree gchar *action_name = g_strdup_printf ("win.perspective('%s')", id);
+      g_autofree gchar *shortcut_help = g_strdup_printf ("Switch to %s perspective", id);
+      const DzlShortcutEntry workbench_shortcut_entry[] = {
+        { command_id,
+          0, NULL,
+          N_("Workbench"),
+          N_("Perspectives"),
+          N_(shortcut_help) },
+      };
+
+      controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
+      dzl_shortcut_controller_add_command_action (controller,
+                                                  command_id,
+                                                  accel,
+                                                  DZL_SHORTCUT_PHASE_GLOBAL,
+                                                  action_name);
+
+      dzl_shortcut_manager_add_shortcut_entries (NULL,
+                                                 workbench_shortcut_entry,
+                                                 G_N_ELEMENTS (workbench_shortcut_entry),
+                                                 GETTEXT_PACKAGE);
+    }
+}
diff --git a/libide/workbench/ide-workbench.c b/libide/workbench/ide-workbench.c
index 6439103..19710d8 100644
--- a/libide/workbench/ide-workbench.c
+++ b/libide/workbench/ide-workbench.c
@@ -709,7 +709,6 @@ void
 ide_workbench_add_perspective (IdeWorkbench   *self,
                                IdePerspective *perspective)
 {
-  g_autofree gchar *accel= NULL;
   g_autofree gchar *icon_name = NULL;
   g_autofree gchar *id = NULL;
   g_autofree gchar *title = NULL;
@@ -736,18 +735,7 @@ ide_workbench_add_perspective (IdeWorkbench   *self,
                                        "name", id,
                                        NULL);
 
-  accel = ide_perspective_get_accelerator (perspective);
-
-  if (accel != NULL)
-    {
-      const gchar *accel_map[] = { accel, NULL };
-      g_autofree gchar *action_name = NULL;
-
-      action_name = g_strdup_printf ("win.perspective('%s')", id);
-      gtk_application_set_accels_for_action (GTK_APPLICATION (IDE_APPLICATION_DEFAULT),
-                                             action_name, accel_map);
-
-    }
+  _ide_workbench_add_perspective_shortcut (self, perspective);
 }
 
 void


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