mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-06-30 23:29:33 +00:00
Implement ref actions popup for ref labels
This commit is contained in:
parent
4507c0e2e7
commit
c4d21a3165
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user