mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-08-27 20:09:23 +00:00
Keep the selected navigation reference during reloading
This commit is contained in:
parent
ef329ed44c
commit
3430656538
|
@ -30,6 +30,7 @@ namespace GitgHistory
|
||||||
private enum Column
|
private enum Column
|
||||||
{
|
{
|
||||||
ICON_NAME,
|
ICON_NAME,
|
||||||
|
NAME,
|
||||||
TEXT,
|
TEXT,
|
||||||
HEADER,
|
HEADER,
|
||||||
HINT,
|
HINT,
|
||||||
|
@ -74,12 +75,15 @@ namespace GitgHistory
|
||||||
private uint d_sections;
|
private uint d_sections;
|
||||||
private Activated[] d_callbacks;
|
private Activated[] d_callbacks;
|
||||||
private Gitg.Repository? d_repository;
|
private Gitg.Repository? d_repository;
|
||||||
|
private string? d_selected_head;
|
||||||
|
private Gtk.TreeIter? d_selected_iter;
|
||||||
|
|
||||||
public signal void ref_activated(Gitg.Ref? r);
|
public signal void ref_activated(Gitg.Ref? r);
|
||||||
|
|
||||||
public Navigation(Gitg.Repository repo)
|
public Navigation(Gitg.Repository repo)
|
||||||
{
|
{
|
||||||
set_column_types({typeof(string),
|
set_column_types({typeof(string),
|
||||||
|
typeof(string),
|
||||||
typeof(string),
|
typeof(string),
|
||||||
typeof(string),
|
typeof(string),
|
||||||
typeof(uint),
|
typeof(uint),
|
||||||
|
@ -103,6 +107,12 @@ namespace GitgHistory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Gtk.TreeIter? selected_iter
|
||||||
|
{
|
||||||
|
get { return d_selected_iter; }
|
||||||
|
set { d_selected_iter = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private static int sort_refs(Gitg.Ref a, Gitg.Ref b)
|
private static int sort_refs(Gitg.Ref a, Gitg.Ref b)
|
||||||
{
|
{
|
||||||
return a.parsed_name.shortname.ascii_casecmp(b.parsed_name.shortname);
|
return a.parsed_name.shortname.ascii_casecmp(b.parsed_name.shortname);
|
||||||
|
@ -174,11 +184,11 @@ namespace GitgHistory
|
||||||
|
|
||||||
if (CommandLine.all)
|
if (CommandLine.all)
|
||||||
{
|
{
|
||||||
append_default(_("All commits"), null, (nc) => ref_activated(null));
|
append_default(_("All commits"), null, null, (nc) => activate_ref(null));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
append(_("All commits"), null, (nc) => ref_activated(null));
|
append(_("All commits"), null, null, (nc) => activate_ref(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Branches
|
// Branches
|
||||||
|
@ -207,14 +217,16 @@ namespace GitgHistory
|
||||||
if (isdef)
|
if (isdef)
|
||||||
{
|
{
|
||||||
append_default(item.parsed_name.shortname,
|
append_default(item.parsed_name.shortname,
|
||||||
|
item.parsed_name.name,
|
||||||
icon,
|
icon,
|
||||||
(nc) => ref_activated(item));
|
(nc) => activate_ref(item));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
append(item.parsed_name.shortname,
|
append(item.parsed_name.shortname,
|
||||||
|
item.parsed_name.name,
|
||||||
icon,
|
icon,
|
||||||
(nc) => ref_activated(item));
|
(nc) => activate_ref(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +248,9 @@ namespace GitgHistory
|
||||||
var it = rref;
|
var it = rref;
|
||||||
|
|
||||||
append(rref.parsed_name.remote_branch,
|
append(rref.parsed_name.remote_branch,
|
||||||
|
rref.parsed_name.name,
|
||||||
null,
|
null,
|
||||||
(nc) => ref_activated(it));
|
(nc) => activate_ref(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
end_header();
|
end_header();
|
||||||
|
@ -253,8 +266,9 @@ namespace GitgHistory
|
||||||
var it = item;
|
var it = item;
|
||||||
|
|
||||||
append(item.parsed_name.shortname,
|
append(item.parsed_name.shortname,
|
||||||
|
item.parsed_name.name,
|
||||||
null,
|
null,
|
||||||
(nc) => ref_activated(it));
|
(nc) => activate_ref(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
end_header();
|
end_header();
|
||||||
|
@ -283,6 +297,7 @@ namespace GitgHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
private void append_one(string text,
|
private void append_one(string text,
|
||||||
|
string? name,
|
||||||
string? icon_name,
|
string? icon_name,
|
||||||
uint hint,
|
uint hint,
|
||||||
owned NavigationActivated? callback,
|
owned NavigationActivated? callback,
|
||||||
|
@ -299,31 +314,40 @@ namespace GitgHistory
|
||||||
|
|
||||||
@set(iter,
|
@set(iter,
|
||||||
Column.ICON_NAME, icon_name,
|
Column.ICON_NAME, icon_name,
|
||||||
|
Column.NAME, name,
|
||||||
hint == Hint.HEADER ? Column.HEADER : Column.TEXT, text,
|
hint == Hint.HEADER ? Column.HEADER : Column.TEXT, text,
|
||||||
Column.HINT, hint,
|
Column.HINT, hint,
|
||||||
Column.SECTION, d_sections,
|
Column.SECTION, d_sections,
|
||||||
Column.OID, d_oid);
|
Column.OID, d_oid);
|
||||||
|
|
||||||
|
if (d_selected_head == name && name != null ||
|
||||||
|
d_selected_head == "--ALL REFS--" && text == _("All commits"))
|
||||||
|
{
|
||||||
|
d_selected_iter = iter;
|
||||||
|
}
|
||||||
|
|
||||||
d_callbacks += new Activated((owned)callback);
|
d_callbacks += new Activated((owned)callback);
|
||||||
++d_oid;
|
++d_oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new Navigation append(string text,
|
public new Navigation append(string text,
|
||||||
|
string? name,
|
||||||
string? icon_name,
|
string? icon_name,
|
||||||
owned NavigationActivated? callback)
|
owned NavigationActivated? callback)
|
||||||
{
|
{
|
||||||
Gtk.TreeIter iter;
|
Gtk.TreeIter iter;
|
||||||
append_one(text, icon_name, Hint.NONE, (owned)callback, out iter);
|
append_one(text, name, icon_name, Hint.NONE, (owned)callback, out iter);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new Navigation append_default(string text,
|
public new Navigation append_default(string text,
|
||||||
|
string? name,
|
||||||
string? icon_name,
|
string? icon_name,
|
||||||
owned NavigationActivated? callback)
|
owned NavigationActivated? callback)
|
||||||
{
|
{
|
||||||
Gtk.TreeIter iter;
|
Gtk.TreeIter iter;
|
||||||
append_one(text, icon_name, Hint.DEFAULT, (owned)callback, out iter);
|
append_one(text, name, icon_name, Hint.DEFAULT, (owned)callback, out iter);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +355,7 @@ namespace GitgHistory
|
||||||
public new Navigation append_separator()
|
public new Navigation append_separator()
|
||||||
{
|
{
|
||||||
Gtk.TreeIter iter;
|
Gtk.TreeIter iter;
|
||||||
append_one("", null, Hint.SEPARATOR, null, out iter);
|
append_one("", null, null, Hint.SEPARATOR, null, out iter);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -341,7 +365,7 @@ namespace GitgHistory
|
||||||
{
|
{
|
||||||
Gtk.TreeIter iter;
|
Gtk.TreeIter iter;
|
||||||
|
|
||||||
append_one(text, icon_name, Hint.HEADER, null, out iter);
|
append_one(text, null, icon_name, Hint.HEADER, null, out iter);
|
||||||
d_parents.prepend(iter);
|
d_parents.prepend(iter);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -429,6 +453,18 @@ namespace GitgHistory
|
||||||
d_callbacks[oid].activate(numclick);
|
d_callbacks[oid].activate(numclick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void activate_ref(Gitg.Ref? r) {
|
||||||
|
if (r != null)
|
||||||
|
{
|
||||||
|
d_selected_head = r.parsed_name.name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d_selected_head = "--ALL REFS--";
|
||||||
|
}
|
||||||
|
ref_activated(r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NavigationView : Gtk.TreeView
|
public class NavigationView : Gtk.TreeView
|
||||||
|
@ -558,6 +594,18 @@ namespace GitgHistory
|
||||||
select_first_in(null, true) || select_first_in(null, false);
|
select_first_in(null, true) || select_first_in(null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void select()
|
||||||
|
{
|
||||||
|
if (model.selected_iter != null) {
|
||||||
|
get_selection().select_iter(model.selected_iter);
|
||||||
|
model.selected_iter = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
select_first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void row_activated(Gtk.TreePath path, Gtk.TreeViewColumn col)
|
protected override void row_activated(Gtk.TreePath path, Gtk.TreeViewColumn col)
|
||||||
{
|
{
|
||||||
Gtk.TreeIter iter;
|
Gtk.TreeIter iter;
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace GitgHistory
|
||||||
d_navigation_model.reload();
|
d_navigation_model.reload();
|
||||||
d_navigation.set_model(d_navigation_model);
|
d_navigation.set_model(d_navigation_model);
|
||||||
d_navigation.expand_all();
|
d_navigation.expand_all();
|
||||||
d_navigation.select_first();
|
d_navigation.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build_ui()
|
private void build_ui()
|
||||||
|
|
Loading…
Reference in a new issue