[gnome-builder] ls: add some accelerators for ls page
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] ls: add some accelerators for ls page
- Date: Wed, 1 May 2019 22:51:27 +0000 (UTC)
commit a8324adf74628b542e01946d1fc49e13a4faa08a
Author: Christian Hergert <chergert redhat com>
Date: Wed May 1 15:50:56 2019 -0700
ls: add some accelerators for ls page
We should probably eventually move more from GbpLsPage into the
GbpLsTreeView subclass to allow us to add more features as necessary.
src/plugins/ls/gbp-ls-page.c | 3 ++
src/plugins/ls/gbp-ls-page.ui | 2 +-
src/plugins/ls/gbp-ls-tree-view.c | 101 ++++++++++++++++++++++++++++++++++++++
src/plugins/ls/gbp-ls-tree-view.h | 31 ++++++++++++
src/plugins/ls/meson.build | 1 +
5 files changed, 137 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/ls/gbp-ls-page.c b/src/plugins/ls/gbp-ls-page.c
index f833383c6..111b98334 100644
--- a/src/plugins/ls/gbp-ls-page.c
+++ b/src/plugins/ls/gbp-ls-page.c
@@ -27,6 +27,7 @@
#include "gbp-ls-model.h"
#include "gbp-ls-page.h"
+#include "gbp-ls-tree-view.h"
struct _GbpLsPage
{
@@ -246,6 +247,8 @@ gbp_ls_page_class_init (GbpLsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GbpLsPage, size_column);
gtk_widget_class_bind_template_child (widget_class, GbpLsPage, scroller);
gtk_widget_class_bind_template_child (widget_class, GbpLsPage, tree_view);
+
+ g_type_ensure (GBP_TYPE_LS_TREE_VIEW);
}
static void
diff --git a/src/plugins/ls/gbp-ls-page.ui b/src/plugins/ls/gbp-ls-page.ui
index 38a50a7d3..ac03eb568 100644
--- a/src/plugins/ls/gbp-ls-page.ui
+++ b/src/plugins/ls/gbp-ls-page.ui
@@ -6,7 +6,7 @@
<property name="vexpand">true</property>
<property name="visible">true</property>
<child>
- <object class="GtkTreeView" id="tree_view">
+ <object class="GbpLsTreeView" id="tree_view">
<property name="vexpand">true</property>
<property name="headers-visible">true</property>
<property name="visible">true</property>
diff --git a/src/plugins/ls/gbp-ls-tree-view.c b/src/plugins/ls/gbp-ls-tree-view.c
new file mode 100644
index 000000000..fe43fa0d1
--- /dev/null
+++ b/src/plugins/ls/gbp-ls-tree-view.c
@@ -0,0 +1,101 @@
+/* gbp-ls-tree-view.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-ls-tree-view"
+
+#include "config.h"
+
+#include "gbp-ls-model.h"
+#include "gbp-ls-tree-view.h"
+
+struct _GbpLsTreeView
+{
+ GtkTreeView parent_instance;
+};
+
+enum {
+ GO_UP,
+ N_SIGNALS
+};
+
+static guint signals [N_SIGNALS];
+
+G_DEFINE_TYPE (GbpLsTreeView, gbp_ls_tree_view, GTK_TYPE_TREE_VIEW)
+
+static void
+gbp_ls_tree_view_go_up (GbpLsTreeView *self)
+{
+ g_autoptr(GFile) parent = NULL;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GFile *directory;
+
+ g_assert (GBP_IS_LS_TREE_VIEW (self));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+
+ if (!GBP_IS_LS_MODEL (model) ||
+ !(directory = gbp_ls_model_get_directory (GBP_LS_MODEL (model))) ||
+ !(parent = g_file_get_parent (directory)))
+ return;
+
+ if (gtk_tree_model_get_iter_first (model, &iter))
+ {
+ g_autoptr(GtkTreePath) path = gtk_tree_model_get_path (model, &iter);
+ GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 0);
+
+ gtk_tree_selection_select_iter (selection, &iter);
+ gtk_tree_view_row_activated (GTK_TREE_VIEW (self), path, column);
+ }
+}
+
+static void
+gbp_ls_tree_view_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gbp_ls_tree_view_parent_class)->finalize (object);
+}
+
+static void
+gbp_ls_tree_view_class_init (GbpLsTreeViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkBindingSet *binding_set = gtk_binding_set_by_class (klass);
+
+ object_class->finalize = gbp_ls_tree_view_finalize;
+
+ signals [GO_UP] =
+ g_signal_new_class_handler ("go-up",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (gbp_ls_tree_view_go_up),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK, "go-up", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0, "go-up", 0);
+}
+
+static void
+gbp_ls_tree_view_init (GbpLsTreeView *self)
+{
+}
diff --git a/src/plugins/ls/gbp-ls-tree-view.h b/src/plugins/ls/gbp-ls-tree-view.h
new file mode 100644
index 000000000..e904f4edc
--- /dev/null
+++ b/src/plugins/ls/gbp-ls-tree-view.h
@@ -0,0 +1,31 @@
+/* gbp-ls-tree-view.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_LS_TREE_VIEW (gbp_ls_tree_view_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpLsTreeView, gbp_ls_tree_view, GBP, LS_TREE_VIEW, GtkTreeView)
+
+G_END_DECLS
diff --git a/src/plugins/ls/meson.build b/src/plugins/ls/meson.build
index b4afd4aa9..e74df7ebe 100644
--- a/src/plugins/ls/meson.build
+++ b/src/plugins/ls/meson.build
@@ -3,6 +3,7 @@ plugins_sources += files([
'gbp-ls-page.c',
'gbp-ls-editor-page-addin.c',
'gbp-ls-workbench-addin.c',
+ 'gbp-ls-tree-view.c',
'ls-plugin.c',
])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]