[gitg/vala] Add dash view and test
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/vala] Add dash view and test
- Date: Thu, 12 Jul 2012 15:23:29 +0000 (UTC)
commit c70b058bbe641344f76d85fd082be34d63e56183
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jul 10 16:32:48 2012 +0200
Add dash view and test
libgitg-gtk/Makefile.am | 1 +
libgitg-gtk/gitg-gtk-dash-view.vala | 147 +++++++++++++++++++++++++++++++++++
tests/Makefile.am | 6 +-
tests/dash-view.vala | 27 +++++++
4 files changed, 180 insertions(+), 1 deletions(-)
---
diff --git a/libgitg-gtk/Makefile.am b/libgitg-gtk/Makefile.am
index 8420778..847c277 100644
--- a/libgitg-gtk/Makefile.am
+++ b/libgitg-gtk/Makefile.am
@@ -49,6 +49,7 @@ VALA_FILES = \
gitg-gtk-diff-view-request.vala \
gitg-gtk-diff-view-request-resource.vala \
gitg-gtk-diff-view-request-diff.vala \
+ gitg-gtk-dash-view.vala \
egg-list-box/egg-list-box.vala
# Ignore all warnings for vala code...
diff --git a/libgitg-gtk/gitg-gtk-dash-view.vala b/libgitg-gtk/gitg-gtk-dash-view.vala
new file mode 100644
index 0000000..a030a5e
--- /dev/null
+++ b/libgitg-gtk/gitg-gtk-dash-view.vala
@@ -0,0 +1,147 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gitg;
+using Gtk;
+
+namespace GitgGtk
+{
+ public class DashView : ListBox
+ {
+ private class RepositoryData
+ {
+ public Repository repository;
+ public Grid grid;
+ public Label branch_label;
+ }
+
+ public virtual signal void repository_activated(Repository repository)
+ {
+ }
+
+ construct
+ {
+ set_activate_on_single_click(false);
+
+ var recent_manager = RecentManager.get_default();
+ var items = recent_manager.get_items();
+
+ foreach (var item in items)
+ {
+ if (item.has_group("gitg"))
+ {
+ add_repository(item);
+ }
+ }
+ }
+
+ private void add_repository(RecentInfo info)
+ {
+ File info_file = File.new_for_uri(info.get_uri());
+ File repo_file;
+
+ try
+ {
+ repo_file = Ggit.Repository.discover(info_file);
+ }
+ catch
+ {
+ // TODO: remove from the recent manager
+ return;
+ }
+
+ Gitg.Repository repo;
+
+ try
+ {
+ repo = new Gitg.Repository(repo_file, null);
+ }
+ catch
+ {
+ return;
+ }
+
+ var data = new RepositoryData();
+ data.repository = repo;
+ data.grid = new Grid();
+ data.grid.margin = 12;
+ data.grid.set_column_spacing(10);
+
+ File? workdir = repo.get_workdir();
+ var label = new Label((workdir != null) ? workdir.get_path() : repo_file.get_path());
+ label.set_ellipsize(Pango.EllipsizeMode.END);
+ label.set_valign(Align.START);
+ label.set_halign(Align.START);
+ data.grid.attach(label, 0, 0, 1, 1);
+
+ data.branch_label = new Label("");
+ data.branch_label.set_ellipsize(Pango.EllipsizeMode.END);
+ data.branch_label.set_valign(Align.START);
+ data.branch_label.set_halign(Align.START);
+ data.grid.attach(data.branch_label, 0, 1, 1, 1);
+
+ Gitg.Ref? head = null;
+ try
+ {
+ head = repo.get_head();
+ }
+ catch {}
+
+ // show the active branch
+ if (head != null)
+ {
+ try
+ {
+ repo.branches_foreach(Ggit.BranchType.LOCAL, (branch_name, branch_type) => {
+ try
+ {
+ Ref? reference = repo.lookup_reference("refs/heads/" + branch_name);
+
+ if (reference != null && reference.get_id().equal(head.get_id()))
+ {
+ data.branch_label.set_text(branch_name);
+ return 1;
+ }
+ }
+ catch {}
+
+ return 0;
+ });
+ }
+ catch {}
+ }
+
+ data.grid.set_data<RepositoryData>("data", data);
+ data.grid.show_all();
+ add(data.grid);
+ }
+
+ public override void child_activated(Widget? child)
+ {
+ var data = child.get_data<RepositoryData>("data");
+
+ if (data != null)
+ {
+ repository_activated(data.repository);
+ }
+ }
+ }
+}
+
+// ex:ts=4 noet
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b87dffb..c18166e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,12 +4,16 @@ noinst_PROGRAMS = $(TEST_PROGS) $(DEMO_PROGS)
VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS)
-DEMO_PROGS = diff-view
+DEMO_PROGS = diff-view dash-view
diff_view_SOURCES = diff-view.vala
diff_view_LDADD = $(GITG_PLUGIN_LIBS)
diff_view_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w
+dash_view_SOURCES = dash-view.vala
+dash_view_LDADD = $(GITG_PLUGIN_LIBS)
+dash_view_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w
+
TESTS = $(TEST_PROGS)
BUILT_SOURCES = \
diff --git a/tests/dash-view.vala b/tests/dash-view.vala
new file mode 100644
index 0000000..a7e9fb9
--- /dev/null
+++ b/tests/dash-view.vala
@@ -0,0 +1,27 @@
+using Gtk;
+using GitgGtk;
+
+class TestDashView
+{
+ public static int main(string[] args)
+ {
+ Gtk.init(ref args);
+ Gitg.init();
+
+ var window = new Window();
+ window.set_default_size(300, 300);
+ window.add(new DashView());
+ window.show_all();
+
+ window.delete_event.connect((w, ev) => {
+ Gtk.main_quit();
+ return true;
+ });
+
+ Gtk.main();
+
+ return 0;
+ }
+}
+
+// vi:ts=4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]