[gitg] Implement ref actions popup for ref labels
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Implement ref actions popup for ref labels
- Date: Sun, 14 Dec 2014 16:21:09 +0000 (UTC)
commit c4d21a316514a33822e33e13f17d1b89f9988de3
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Dec 14 17:20:47 2014 +0100
Implement ref actions popup for ref labels
gitg/history/gitg-history-paned.vala | 4 +-
gitg/history/gitg-history.vala | 79 ++++++++++++++++++++++++++-------
libgitg/gitg-cell-renderer-lanes.vala | 22 +++++++++-
libgitg/gitg-commit-list-view.vala | 33 ++++++++++++++
4 files changed, 118 insertions(+), 20 deletions(-)
---
diff --git a/gitg/history/gitg-history-paned.vala b/gitg/history/gitg-history-paned.vala
index 276a949..700791a 100644
--- a/gitg/history/gitg-history-paned.vala
+++ b/gitg/history/gitg-history-paned.vala
@@ -36,7 +36,7 @@ class Paned : Gitg.AnimatedPaned
private RefsList d_refs_list;
[GtkChild]
- private Gtk.TreeView d_commit_list_view;
+ private Gitg.CommitListView d_commit_list_view;
[GtkChild]
private Gtk.Stack d_stack_panel;
@@ -198,7 +198,7 @@ class Paned : Gitg.AnimatedPaned
get { return d_refs_list; }
}
- public Gtk.TreeView commit_list_view
+ public Gitg.CommitListView commit_list_view
{
get { return d_commit_list_view; }
}
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 7a9a869..3b72922 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -372,10 +372,51 @@ namespace GitgHistory
BindingFlags.BIDIRECTIONAL);
}
+ private Gtk.Menu? popup_on_ref(Gdk.EventButton? event)
+ {
+ int cell_x;
+ int cell_y;
+ int cell_w;
+ Gtk.TreePath path;
+ Gtk.TreeViewColumn column;
+
+ if (!d_main.commit_list_view.get_path_at_pos((int)event.x,
+ (int)event.y,
+ out path,
+ out column,
+ out cell_x,
+ out cell_y))
+ {
+ return null;
+ }
+
+ var cell = d_main.commit_list_view.find_cell_at_pos(column, path, cell_x, out cell_w)
as Gitg.CellRendererLanes;
+
+ if (cell == null)
+ {
+ return null;
+ }
+
+ var reference = cell.get_ref_at_pos(d_main.commit_list_view, cell_x, cell_w, null);
+
+ if (reference == null)
+ {
+ return null;
+ }
+
+ return popup_menu_for_ref(reference);
+ }
+
private Gtk.Menu? on_commit_list_populate_menu(Gdk.EventButton? event)
{
- selectable_mode = GitgExt.SelectionMode.SELECTION;
- return null;
+ var ret = popup_on_ref(event);
+
+ if (ret == null)
+ {
+ selectable_mode = GitgExt.SelectionMode.SELECTION;
+ }
+
+ return ret;
}
private void add_ref_action(Gee.LinkedList<GitgExt.RefAction> actions,
@@ -387,23 +428,9 @@ namespace GitgHistory
}
}
- private Gtk.Menu? on_refs_list_populate_menu(Gdk.EventButton? event)
+ private Gtk.Menu? popup_menu_for_ref(Gitg.Ref reference)
{
- if (event != null)
- {
- var row = d_main.refs_list.get_row_at_y((int)event.y);
- d_main.refs_list.select_row(row);
- }
-
var actions = new Gee.LinkedList<GitgExt.RefAction>();
- var references = d_main.refs_list.selection;
-
- if (references.is_empty || references.first() != references.last())
- {
- return null;
- }
-
- var reference = references.first();
var af = new ActionInterface(application, d_main.refs_list);
@@ -441,6 +468,24 @@ namespace GitgHistory
return menu;
}
+ private Gtk.Menu? on_refs_list_populate_menu(Gdk.EventButton? event)
+ {
+ if (event != null)
+ {
+ var row = d_main.refs_list.get_row_at_y((int)event.y);
+ d_main.refs_list.select_row(row);
+ }
+
+ var references = d_main.refs_list.selection;
+
+ if (references.is_empty || references.first() != references.last())
+ {
+ return null;
+ }
+
+ return popup_menu_for_ref(references.first());
+ }
+
private void update_walker()
{
d_selected.clear();
diff --git a/libgitg/gitg-cell-renderer-lanes.vala b/libgitg/gitg-cell-renderer-lanes.vala
index ac150dd..c3f5e6a 100644
--- a/libgitg/gitg-cell-renderer-lanes.vala
+++ b/libgitg/gitg-cell-renderer-lanes.vala
@@ -19,7 +19,7 @@
namespace Gitg
{
- class CellRendererLanes : Gtk.CellRendererText
+ public class CellRendererLanes : Gtk.CellRendererText
{
public Commit? commit { get; set; }
public Commit? next_commit { get; set; }
@@ -290,6 +290,26 @@ namespace Gitg
base.render(context, widget, narea, ncell_area, flags);
}
+
+ public Ref? get_ref_at_pos(Gtk.Widget widget,
+ int x,
+ int cell_w,
+ out int hot_x)
+ {
+ var rtl = (widget.get_style_context().get_state() & Gtk.StateFlags.DIR_RTL) != 0;
+ var offset = (int)(labels.length() * lane_width);
+
+ if (rtl)
+ {
+ x = cell_w - x;
+ }
+
+ return LabelRenderer.get_ref_at_pos(widget,
+ font_desc,
+ labels,
+ x - offset,
+ out hot_x);
+ }
}
}
diff --git a/libgitg/gitg-commit-list-view.vala b/libgitg/gitg-commit-list-view.vala
index f4df91a..5e15ce7 100644
--- a/libgitg/gitg-commit-list-view.vala
+++ b/libgitg/gitg-commit-list-view.vala
@@ -31,6 +31,39 @@ namespace Gitg
this(new CommitModel(repository));
}
+ public Gtk.CellRenderer? find_cell_at_pos(Gtk.TreeViewColumn column,
+ Gtk.TreePath path,
+ int x,
+ out int width)
+ {
+ Gtk.TreeIter iter;
+
+ model.get_iter(out iter, path);
+ column.cell_set_cell_data(model, iter, false, false);
+
+ var cells = column.get_cells();
+
+ foreach (var cell in cells)
+ {
+ int start;
+ int cellw;
+
+ if (!column.cell_get_position(cell, out start, out cellw))
+ {
+ continue;
+ }
+
+ if (x >= start && x <= start + cellw)
+ {
+ width = cellw;
+ return cell;
+ }
+ }
+
+ width = 0;
+ return null;
+ }
+
private void lanes_data_func(Gtk.CellLayout layout,
Gtk.CellRenderer cell,
Gtk.TreeModel model,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]