[gitg] dash: add repository to the list if it does not exists yet
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] dash: add repository to the list if it does not exists yet
- Date: Wed, 13 Mar 2013 14:31:35 +0000 (UTC)
commit 8d97243715b5af96a6779b1774bce8db5e372ace
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Mar 13 15:31:13 2013 +0100
dash: add repository to the list if it does not exists yet
gitg/gitg-window.vala | 1 +
libgitg-gtk/gitg-gtk-dash-view.vala | 119 ++++++++++++++++++++--------------
2 files changed, 71 insertions(+), 49 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index cbdba9c..6f4fb64 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -106,6 +106,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
d_commit_view_switcher.show();
d_button_dash.show();
d_button_open_repository.hide();
+ d_dash_view.add_repository(d_repository);
}
else
{
diff --git a/libgitg-gtk/gitg-gtk-dash-view.vala b/libgitg-gtk/gitg-gtk-dash-view.vala
index 7bbd925..85fa617 100644
--- a/libgitg-gtk/gitg-gtk-dash-view.vala
+++ b/libgitg-gtk/gitg-gtk-dash-view.vala
@@ -97,7 +97,7 @@ namespace GitgGtk
{
var data_a = a.get_data<RepositoryData>("data");
var data_b = b.get_data<RepositoryData>("data");
- return data_a.time.compare(data_b.time);
+ return - data_a.time.compare(data_b.time);
}
private void add_recent_info(RecentInfo info)
@@ -129,68 +129,89 @@ namespace GitgGtk
add_repository(repo);
}
- private void add_repository(Gitg.Repository repository)
+ public void add_repository(Gitg.Repository repository)
{
- var data = new RepositoryData();
- data.repository = repository;
- data.time = new DateTime.now_local();
- data.grid = new Grid();
- data.grid.margin = 12;
- data.grid.column_spacing = 10;
-
- data.repository_label = new Label(null);
- File? repo_file = repository.get_location();
- File? workdir = repository.get_workdir();
- var label_text = (workdir != null) ? workdir.get_basename() :
repo_file.get_basename();
- data.repository_label.set_markup("<b>%s</b>".printf(label_text));
- data.repository_label.ellipsize = Pango.EllipsizeMode.END;
- data.repository_label.valign = Align.START;
- data.repository_label.halign = Align.START;
- data.repository_label.hexpand = true;
- data.grid.attach(data.repository_label, 0, 0, 1, 1);
-
- data.branch_label = new Label("");
- data.branch_label.ellipsize = Pango.EllipsizeMode.END;
- data.branch_label.valign = Align.START;
- data.branch_label.halign = Align.START;
- data.grid.attach(data.branch_label, 0, 1, 1, 1);
-
- Gitg.Ref? head = null;
- try
+ RepositoryData? data = null;
+
+ foreach (var child in d_listbox.get_children())
{
- head = repository.get_head();
+ var d = child.get_data<RepositoryData>("data");
+ if (d.repository == repository)
+ {
+ data = d;
+ break;
+ }
}
- catch {}
- // show the active branch
- if (head != null)
+ if (data == null)
{
+ data = new RepositoryData();
+ data.repository = repository;
+ data.time = new DateTime.now_local();
+ data.grid = new Grid();
+ data.grid.margin = 12;
+ data.grid.column_spacing = 10;
+
+ data.repository_label = new Label(null);
+ File? repo_file = repository.get_location();
+ File? workdir = repository.get_workdir();
+ var label_text = (workdir != null) ? workdir.get_basename() :
repo_file.get_basename();
+ data.repository_label.set_markup("<b>%s</b>".printf(label_text));
+ data.repository_label.ellipsize = Pango.EllipsizeMode.END;
+ data.repository_label.valign = Align.START;
+ data.repository_label.halign = Align.START;
+ data.repository_label.hexpand = true;
+ data.grid.attach(data.repository_label, 0, 0, 1, 1);
+
+ data.branch_label = new Label("");
+ data.branch_label.ellipsize = Pango.EllipsizeMode.END;
+ data.branch_label.valign = Align.START;
+ data.branch_label.halign = Align.START;
+ data.grid.attach(data.branch_label, 0, 1, 1, 1);
+
+ Gitg.Ref? head = null;
try
{
- repository.branches_foreach(Ggit.BranchType.LOCAL, (branch_name,
branch_type) => {
- try
- {
- Ref? reference =
repository.lookup_reference("refs/heads/" + branch_name);
+ head = repository.get_head();
+ }
+ catch {}
- if (reference != null &&
reference.get_target().equal(head.get_target()))
+ // show the active branch
+ if (head != null)
+ {
+ try
+ {
+ repository.branches_foreach(Ggit.BranchType.LOCAL,
(branch_name, branch_type) => {
+ try
{
- data.branch_label.set_text(branch_name);
- return 1;
+ Ref? reference =
repository.lookup_reference("refs/heads/" + branch_name);
+
+ if (reference != null &&
reference.get_target().equal(head.get_target()))
+ {
+
data.branch_label.set_text(branch_name);
+ return 1;
+ }
}
- }
- catch {}
+ catch {}
- return 0;
- });
+ return 0;
+ });
+ }
+ catch {}
}
- catch {}
- }
- data.grid.attach(new Arrow(ArrowType.RIGHT, ShadowType.NONE), 1, 0, 1, 2);
+ data.grid.attach(new Arrow(ArrowType.RIGHT, ShadowType.NONE), 1, 0, 1, 2);
- data.grid.set_data<RepositoryData>("data", data);
- data.grid.show_all();
- d_listbox.add(data.grid);
+ data.grid.set_data<RepositoryData>("data", data);
+ data.grid.show_all();
+ d_listbox.add(data.grid);
+ }
+ else
+ {
+ // to get the item sorted to the beginning of the list
+ data.time = new DateTime.now_local();
+ d_listbox.resort();
+ }
}
public void filter_text(string? text)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]