[gnome-builder] project tree: move to DzlShortcut classes



commit f9f748d660a1c8795ff1347503bff6d1595087db
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Mon Aug 14 19:37:13 2017 +0200

    project tree: move to DzlShortcut classes
    
    corresponding keys: F2 and Delete
    
    Problem left for now: dynamic update of the accelerator
    label in the tree contextual menu

 data/keybindings/default.css                     |    4 -
 data/keybindings/emacs.css                       |    3 +-
 data/keybindings/shared.css                      |    6 --
 data/keybindings/vim.css                         |    3 +-
 plugins/project-tree/gb-project-tree-private.h   |    2 +
 plugins/project-tree/gb-project-tree-shortcuts.c |   71 ++++++++++++++++++++++
 plugins/project-tree/gb-project-tree.c           |    1 +
 plugins/project-tree/meson.build                 |    1 +
 8 files changed, 77 insertions(+), 14 deletions(-)
---
diff --git a/data/keybindings/default.css b/data/keybindings/default.css
index 1cf15da..1598479 100644
--- a/data/keybindings/default.css
+++ b/data/keybindings/default.css
@@ -48,7 +48,3 @@
 idesourceviewmode.default {
   -gtk-key-bindings: default-ide-source-view;
 }
-
-treeview.project-tree {
-  -gtk-key-bindings: builder-gb-project-tree;
-}
diff --git a/data/keybindings/emacs.css b/data/keybindings/emacs.css
index 3d443d2..6194ee0 100644
--- a/data/keybindings/emacs.css
+++ b/data/keybindings/emacs.css
@@ -216,6 +216,5 @@ listbox {
 }
 
 treeview.project-tree {
-  -gtk-key-bindings: builder-emacs-tree-view,
-                     builder-gb-project-tree;
+  -gtk-key-bindings: builder-emacs-tree-view;
 }
diff --git a/data/keybindings/shared.css b/data/keybindings/shared.css
index f54bd89..5884852 100644
--- a/data/keybindings/shared.css
+++ b/data/keybindings/shared.css
@@ -1,9 +1,3 @@
-@binding-set builder-gb-project-tree
-{
-  bind "Delete" { "action" ("project-tree", "move-to-trash", "") };
-  bind "F2" { "action" ("project-tree", "rename-file", "") };
-}
-
 @binding-set builder-command-bar-entry
 {
   bind "<ctrl>a" { "move-cursor" (paragraph-ends, -1, 0) };
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 5052d52..a313213 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -2792,8 +2792,7 @@ treeview {
 
 treeview.project-tree {
   -gtk-key-bindings: builder-vim-tree-view,
-                     builder-gb-project-tree-vim,
-                     builder-gb-project-tree;
+                     builder-gb-project-tree-vim;
 }
 
 list {
diff --git a/plugins/project-tree/gb-project-tree-private.h b/plugins/project-tree/gb-project-tree-private.h
index cdcefba..e6d3366 100644
--- a/plugins/project-tree/gb-project-tree-private.h
+++ b/plugins/project-tree/gb-project-tree-private.h
@@ -33,6 +33,8 @@ struct _GbProjectTree
   guint      show_ignored_files : 1;
 };
 
+void      _gb_project_tree_init_shortcuts       (GbProjectTree *self);
+
 G_END_DECLS
 
 #endif /* GB_PROJECT_TREE_PRIVATE_H */
diff --git a/plugins/project-tree/gb-project-tree-shortcuts.c 
b/plugins/project-tree/gb-project-tree-shortcuts.c
new file mode 100644
index 0000000..b694c92
--- /dev/null
+++ b/plugins/project-tree/gb-project-tree-shortcuts.c
@@ -0,0 +1,71 @@
+/* gb-project-tree-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 "gb-project-tree-shortcuts"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <dazzle.h>
+
+#include "gb-project-tree.h"
+
+#define I_(s) g_intern_static_string(s)
+
+static const DzlShortcutEntry gb_project_tree_entries[] = {
+  { "org.gnome.builder.project-tree.rename-file",
+    0, NULL,
+    N_("Project Tree"),
+    N_("General"),
+    N_("Rename a file") },
+
+  { "org.gnome.builder.project-tree.move-to-trah",
+    0, NULL,
+    N_("Project Tree"),
+    N_("General"),
+    N_("Move a file to the trash") },
+};
+
+void
+_gb_project_tree_init_shortcuts (GbProjectTree *self)
+{
+  DzlShortcutController *controller;
+
+  g_assert (GB_IS_PROJECT_TREE (self));
+
+  controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.project-tree.rename-file"),
+                                              I_("F2"),
+                                              DZL_SHORTCUT_PHASE_CAPTURE,
+                                              I_("project-tree.rename-file"));
+
+  dzl_shortcut_controller_add_command_action (controller,
+                                              I_("org.gnome.builder.project-tree.move-to-trah"),
+                                              I_("Delete"),
+                                              DZL_SHORTCUT_PHASE_CAPTURE,
+                                              I_("project-tree.move-to-trash"));
+
+  dzl_shortcut_manager_add_shortcut_entries (NULL,
+                                             gb_project_tree_entries,
+                                             G_N_ELEMENTS (gb_project_tree_entries),
+                                             GETTEXT_PACKAGE);
+
+  /* TODO: remove accel from menu.ui and add API to update this from dzl classes */
+}
diff --git a/plugins/project-tree/gb-project-tree.c b/plugins/project-tree/gb-project-tree.c
index a1782a9..b2d733b 100644
--- a/plugins/project-tree/gb-project-tree.c
+++ b/plugins/project-tree/gb-project-tree.c
@@ -338,6 +338,7 @@ gb_project_tree_init (GbProjectTree *self)
                     NULL);
 
   gb_project_tree_actions_init (self);
+  _gb_project_tree_init_shortcuts (self);
 
   menu = dzl_application_get_menu_by_id (DZL_APPLICATION_DEFAULT, "gb-project-tree-popup-menu");
   dzl_tree_set_context_menu (DZL_TREE (self), G_MENU_MODEL (menu));
diff --git a/plugins/project-tree/meson.build b/plugins/project-tree/meson.build
index 2962607..8e1ee12 100644
--- a/plugins/project-tree/meson.build
+++ b/plugins/project-tree/meson.build
@@ -22,6 +22,7 @@ project_tree_sources = [
   'gb-project-tree-editor-addin.c',
   'gb-project-tree-editor-addin.h',
   'gb-project-tree-private.h',
+  'gb-project-tree-shortcuts.c',
   'gb-rename-file-popover.c',
   'gb-rename-file-popover.h',
   'gb-project-tree-addin.c',


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