[gitg/wip/guyou/path-filtering: 40/119] Create a "path-activated" signal and connect it
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/guyou/path-filtering: 40/119] Create a "path-activated" signal and connect it
- Date: Mon, 7 Jan 2019 11:45:43 +0000 (UTC)
commit 4f7ba9ce1524af463e85502935f21883240c8d1e
Author: Guilhem Bonnefille <guilhem bonnefille gmail com>
Date: Sun Apr 26 11:12:27 2009 +0200
Create a "path-activated" signal and connect it
When activating the "Filter" action inside the Tree view, the selected path is used to filter the history
view.
gitg/gitg-revision-tree-view.c | 43 ++++++++++++++++++++++++++++++++++++++----
gitg/gitg-revision-tree-view.h | 2 ++
gitg/gitg-window.c | 15 ++++++++++++++-
3 files changed, 55 insertions(+), 5 deletions(-)
---
diff --git a/gitg/gitg-revision-tree-view.c b/gitg/gitg-revision-tree-view.c
index b24a46c9..6770ebad 100644
--- a/gitg/gitg-revision-tree-view.c
+++ b/gitg/gitg-revision-tree-view.c
@@ -43,6 +43,15 @@ enum {
PROP_REVISION
};
+/* Signals */
+enum
+{
+ PATH_ACTIVATED,
+ NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS];
+
struct _GitgRevisionTreeViewPrivate
{
GtkUIManager *ui_manager;
@@ -444,6 +453,16 @@ gitg_revision_tree_view_class_init(GitgRevisionTreeViewClass *klass)
GITG_TYPE_REVISION,
G_PARAM_READWRITE));
+ signals[PATH_ACTIVATED] =
+ g_signal_new("path-activated",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GitgRevisionTreeViewClass, path_activated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1, G_TYPE_POINTER);
+
g_type_class_add_private(object_class, sizeof(GitgRevisionTreeViewPrivate));
}
@@ -664,8 +683,11 @@ popup_tree_menu(GitgRevisionTreeView *tree_view, GdkEventButton *event)
GList *rows = gtk_tree_selection_get_selected_rows(selection, &model);
gint num = g_list_length(rows);
- if (num != 1)
+ /* We only support single selection for path filtering */
+ if (num != 1) {
+ g_list_free(rows);
return FALSE;
+ }
GtkWidget *wd = gtk_ui_manager_get_widget(tree_view->priv->ui_manager, "/ui/popup_file_tree");
@@ -704,10 +726,23 @@ on_filter_path(GtkAction *action, GitgRevisionTreeView *tree_view)
GList *rows = gtk_tree_selection_get_selected_rows(selection, &model);
gint num = g_list_length(rows);
- if (num == 0)
+ /* We only support single selection for path filtering */
+ if (num != 1) {
+ g_list_free(rows);
return;
- /* TODO */
- g_message("Not yet implemented");
+ }
+
+ /* Retrieve the selected file's path */
+ gchar *filter_path = NULL;
+ GtkTreePath *path = (GtkTreePath *)rows->data;
+ GtkTreeIter iter;
+ gtk_tree_model_get_iter(model, &iter, path);
+ filter_path = node_path(model, &iter);
+ gtk_tree_path_free(path);
+ g_list_free(rows);
+
+ /* Emit the signal */
+ g_signal_emit(tree_view, signals[PATH_ACTIVATED], 0, filter_path);
}
static void
diff --git a/gitg/gitg-revision-tree-view.h b/gitg/gitg-revision-tree-view.h
index ed69c2b7..f3406100 100644
--- a/gitg/gitg-revision-tree-view.h
+++ b/gitg/gitg-revision-tree-view.h
@@ -49,6 +49,8 @@ struct _GitgRevisionTreeView {
struct _GitgRevisionTreeViewClass {
GtkHPanedClass parent_class;
+
+ void (* path_activated) (GitgRevisionTreeView *revision_tree_view, gchar *path);
};
GType gitg_revision_tree_view_get_type (void) G_GNUC_CONST;
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index ee1fe262..84f177e9 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -326,6 +326,18 @@ on_path_activate(GtkEntry *entry, GitgWindow *window)
filter_repository(window);
}
+static void
+on_path_activated(GitgRevisionTreeView *view, gchar *path, GitgWindow *window)
+{
+ /* Set the path in the widget */
+ if (path == NULL)
+ path = "";
+ gtk_entry_set_text(window->priv->entry_path, path);
+
+ /* Fire the filtering */
+ filter_repository(window);
+}
+
static void
on_branches_combo_changed(GtkComboBox *combo, GitgWindow *window)
{
@@ -429,7 +441,8 @@ gitg_window_parser_finished(GtkBuildable *buildable, GtkBuilder *builder)
GtkTreeSelection *selection = gtk_tree_view_get_selection(window->priv->tree_view);
g_signal_connect(selection, "changed", G_CALLBACK(on_selection_changed), window);
g_signal_connect(window->priv->revision_view, "parent-activated", G_CALLBACK(on_parent_activated),
window);
-
+ g_signal_connect(window->priv->revision_tree_view, "path-activated", G_CALLBACK(on_path_activated),
window);
+
g_signal_connect(window->priv->entry_path, "activate", G_CALLBACK(on_path_activate), window);
g_signal_connect(window->priv->tree_view, "motion-notify-event", G_CALLBACK(on_tree_view_motion),
window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]