[gitg/wip/guyou/path-filtering: 39/119] Add a context menu on file in "Tree" sub-view
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/guyou/path-filtering: 39/119] Add a context menu on file in "Tree" sub-view
- Date: Mon, 7 Jan 2019 11:45:38 +0000 (UTC)
commit c3bb1e4a81f2a8f77ae78380a9a03bb95a07510b
Author: Guilhem Bonnefille <guilhem bonnefille gmail com>
Date: Sun Apr 26 09:39:43 2009 +0200
Add a context menu on file in "Tree" sub-view
gitg/gitg-revision-tree-view.c | 68 ++++++++++++++++++++++++++++++++++++++++++
gitg/gitg-ui.xml | 15 +++++++++-
2 files changed, 82 insertions(+), 1 deletion(-)
---
diff --git a/gitg/gitg-revision-tree-view.c b/gitg/gitg-revision-tree-view.c
index 30d4fd19..b24a46c9 100644
--- a/gitg/gitg-revision-tree-view.c
+++ b/gitg/gitg-revision-tree-view.c
@@ -45,6 +45,7 @@ enum {
struct _GitgRevisionTreeViewPrivate
{
+ GtkUIManager *ui_manager;
GtkTreeView *tree_view;
GtkSourceView *contents;
GitgRunner *content_runner;
@@ -59,6 +60,11 @@ struct _GitgRevisionTreeViewPrivate
GtkTreePath *load_path;
};
+static gboolean popup_tree_menu(GitgRevisionTreeView *view, GdkEventButton *event);
+static void on_tree_button_press(GtkWidget *widget, GdkEventButton *event, GitgRevisionTreeView *view);
+static gboolean on_tree_popup_menu(GtkWidget *widget, GitgRevisionTreeView *view);
+static void on_filter_path(GtkAction *action, GitgRevisionTreeView *view);
+
static void gitg_revision_tree_view_buildable_iface_init(GtkBuildableIface *iface);
static void load_node(GitgRevisionTreeView *view, GtkTreeIter *parent);
static gchar *node_identity(GitgRevisionTreeView *view, GtkTreeIter *iter);
@@ -372,6 +378,7 @@ gitg_revision_tree_view_parser_finished(GtkBuildable *buildable, GtkBuilder *bui
// Store widgets
GitgRevisionTreeView *tree_view = GITG_REVISION_TREE_VIEW(buildable);
+ tree_view->priv->ui_manager = g_object_ref(gtk_builder_get_object(builder, "uiman"));
tree_view->priv->tree_view = GTK_TREE_VIEW(gtk_builder_get_object(builder, "revision_tree"));
tree_view->priv->contents = GTK_SOURCE_VIEW(gtk_builder_get_object(builder,
"revision_tree_contents"));
@@ -398,6 +405,12 @@ gitg_revision_tree_view_parser_finished(GtkBuildable *buildable, GtkBuilder *bui
g_signal_connect(tree_view->priv->tree_view, "drag-data-get", G_CALLBACK(on_drag_data_get),
tree_view);
g_signal_connect(tree_view->priv->tree_view, "drag-end", G_CALLBACK(on_drag_end), tree_view);
g_signal_connect(selection, "changed", G_CALLBACK(on_selection_changed), tree_view);
+
+ g_signal_connect(tree_view->priv->tree_view, "event-after", G_CALLBACK(on_tree_button_press),
tree_view);
+
+ g_signal_connect(tree_view->priv->tree_view, "popup-menu", G_CALLBACK(on_tree_popup_menu), tree_view);
+
+ g_signal_connect(gtk_builder_get_object(builder, "FilterOnPathAction"), "activate",
G_CALLBACK(on_filter_path), tree_view);
}
static void
@@ -642,6 +655,61 @@ on_contents_update(GitgRunner *runner, gchar **buffer, GitgRevisionTreeView *tre
}
}
+static gboolean
+popup_tree_menu(GitgRevisionTreeView *tree_view, GdkEventButton *event)
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view->priv->tree_view);
+ GtkTreeModel *model;
+
+ GList *rows = gtk_tree_selection_get_selected_rows(selection, &model);
+ gint num = g_list_length(rows);
+
+ if (num != 1)
+ return FALSE;
+
+ GtkWidget *wd = gtk_ui_manager_get_widget(tree_view->priv->ui_manager, "/ui/popup_file_tree");
+
+ gtk_menu_popup(GTK_MENU(wd), NULL, NULL,
+ /*gitg_utils_menu_position_under_tree_view*/NULL,
+ tree_view->priv->tree_view, 0,
+ gtk_get_current_event_time());
+
+ return TRUE;
+}
+
+static gboolean
+on_tree_popup_menu(GtkWidget *widget, GitgRevisionTreeView *view)
+{
+ return popup_tree_menu(view, NULL);
+}
+
+static void
+on_tree_button_press(GtkWidget *widget, GdkEventButton *event, GitgRevisionTreeView *view)
+{
+ if (event->type != GDK_BUTTON_PRESS)
+ return;
+
+ if (event->button == 3)
+ {
+ popup_tree_menu(view, event);
+ }
+}
+
+static void
+on_filter_path(GtkAction *action, GitgRevisionTreeView *tree_view)
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view->priv->tree_view);
+ GtkTreeModel *model;
+
+ GList *rows = gtk_tree_selection_get_selected_rows(selection, &model);
+ gint num = g_list_length(rows);
+
+ if (num == 0)
+ return;
+ /* TODO */
+ g_message("Not yet implemented");
+}
+
static void
gitg_revision_tree_view_init(GitgRevisionTreeView *self)
{
diff --git a/gitg/gitg-ui.xml b/gitg/gitg-ui.xml
index 03274064..0474bc39 100644
--- a/gitg/gitg-ui.xml
+++ b/gitg/gitg-ui.xml
@@ -126,7 +126,17 @@
</child>
</object>
</child>
- <ui>
+ <child>
+ <object class="GtkActionGroup" id="action_group_file_tree_context">
+ <child>
+ <object class="GtkAction" id="FilterOnPathAction">
+ <property name="label" translatable="yes">Filter</property>
+ <property name="tooltip" translatable="yes">Filter on this path</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <ui>
<menubar name="menubar_main">
<menu action="FileAction">
<menuitem action="FileOpenAction"/>
@@ -156,6 +166,9 @@
<popup name="popup_commit_unstage">
<menuitem action="UnstageChangesAction"/>
</popup>
+ <popup name="popup_file_tree">
+ <menuitem action="FilterOnPathAction"/>
+ </popup>
</ui>
</object>
<object class="GtkAdjustment" id="adjustment_context">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]