[gitg] Add checkout branch action
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Add checkout branch action
- Date: Sun, 9 Aug 2015 19:13:41 +0000 (UTC)
commit fe18998588b0c4d4a29789517106f1b686f39d19
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sun Aug 9 21:12:29 2015 +0200
Add checkout branch action
https://bugzilla.gnome.org/show_bug.cgi?id=748573
gitg/Makefile.am | 1 +
gitg/gitg-ref-action-checkout.vala | 119 +++++++++++++++++++++++
gitg/history/gitg-history-action-interface.vala | 11 ++
gitg/history/gitg-history-refs-list.vala | 7 +-
gitg/history/gitg-history.vala | 14 +++-
libgitg-ext/gitg-ext-ref-action-interface.vala | 1 +
6 files changed, 147 insertions(+), 6 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index a821c3d..08a5b76 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -71,6 +71,7 @@ gitg_gitg_VALASOURCES = \
gitg/gitg-popup-menu.vala \
gitg/gitg-recursive-monitor.vala \
gitg/gitg-recursive-scanner.vala \
+ gitg/gitg-ref-action-checkout.vala \
gitg/gitg-ref-action-copy-name.vala \
gitg/gitg-ref-action-delete.vala \
gitg/gitg-ref-action-fetch.vala \
diff --git a/gitg/gitg-ref-action-checkout.vala b/gitg/gitg-ref-action-checkout.vala
new file mode 100644
index 0000000..651f70b
--- /dev/null
+++ b/gitg/gitg-ref-action-checkout.vala
@@ -0,0 +1,119 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2015 - Jesse van den Kieboom
+ *
+ * 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/>.
+ */
+
+namespace Gitg
+{
+
+class RefActionCheckout : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Object
+{
+ // Do this to pull in config.h before glib.h (for gettext...)
+ private const string version = Gitg.Config.VERSION;
+
+ public GitgExt.Application? application { owned get; construct set; }
+ public GitgExt.RefActionInterface action_interface { get; construct set; }
+ public Gitg.Ref reference { get; construct set; }
+
+ public RefActionCheckout(GitgExt.Application application,
+ GitgExt.RefActionInterface action_interface,
+ Gitg.Ref reference)
+ {
+ Object(application: application,
+ action_interface: action_interface,
+ reference: reference);
+ }
+
+ public string id
+ {
+ owned get { return "/org/gnome/gitg/ref-actions/checkout"; }
+ }
+
+ public string display_name
+ {
+ owned get { return _("Checkout"); }
+ }
+
+ public string description
+ {
+ owned get { return _("Checkout the selected reference"); }
+ }
+
+ public bool enabled
+ {
+ get
+ {
+ try
+ {
+ var head = application.repository.get_head();
+
+ if (head != null && head.get_name() == reference.get_name())
+ {
+ return false;
+ }
+ }
+ catch {}
+
+ return reference.is_branch();
+ }
+ }
+
+ public void activate()
+ {
+ var repo = application.repository;
+ Commit commit;
+
+ try
+ {
+ commit = reference.resolve().lookup() as Gitg.Commit;
+ }
+ catch (Error e)
+ {
+ action_interface.application.show_infobar(_("Failed to lookup reference"),
+ e.message,
+ Gtk.MessageType.ERROR);
+ return;
+ }
+
+ try
+ {
+ var opts = new Ggit.CheckoutOptions();
+ opts.set_strategy(Ggit.CheckoutStrategy.SAFE);
+
+ repo.checkout_tree(commit.get_tree(), opts);
+ }
+ catch (Error e)
+ {
+ action_interface.application.show_infobar(_("Failed to checkout branch"),
+ e.message,
+ Gtk.MessageType.ERROR);
+
+ return;
+ }
+
+ try
+ {
+ application.repository.set_head(reference.get_name());
+ } catch {}
+
+ action_interface.refresh();
+ }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/gitg/history/gitg-history-action-interface.vala b/gitg/history/gitg-history-action-interface.vala
index 77a0746..09e4149 100644
--- a/gitg/history/gitg-history-action-interface.vala
+++ b/gitg/history/gitg-history-action-interface.vala
@@ -26,6 +26,8 @@ class ActionInterface : Object, GitgExt.RefActionInterface
private RefsList d_refs_list;
+ public signal void updated();
+
public ActionInterface(GitgExt.Application application, RefsList refs_list)
{
Object(application: application);
@@ -37,18 +39,21 @@ class ActionInterface : Object, GitgExt.RefActionInterface
{
application.repository.clear_refs_cache();
d_refs_list.add_ref(reference);
+ updated();
}
public void remove_ref(Gitg.Ref reference)
{
application.repository.clear_refs_cache();
d_refs_list.remove_ref(reference);
+ updated();
}
public void replace_ref(Gitg.Ref old_ref, Gitg.Ref new_ref)
{
application.repository.clear_refs_cache();
d_refs_list.replace_ref(old_ref, new_ref);
+ updated();
}
public void set_busy(Gitg.Ref reference, bool busy)
@@ -60,6 +65,12 @@ class ActionInterface : Object, GitgExt.RefActionInterface
{
d_refs_list.edit(reference, (owned)done);
}
+
+ public void refresh()
+ {
+ d_refs_list.repository = application.repository;
+ updated();
+ }
}
}
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index ca40b76..a25cdb5 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -520,11 +520,8 @@ public class RefsList : Gtk.ListBox
get { return d_repository; }
set
{
- if (d_repository != value)
- {
- d_repository = value;
- refresh();
- }
+ d_repository = value;
+ refresh();
}
}
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 7571802..205f543 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -54,6 +54,7 @@ namespace GitgHistory
private Gitg.PopupMenu d_commit_list_popup;
private string[] d_mainline;
+ private bool d_ignore_external;
private Gitg.UIElements<GitgExt.HistoryPanel> d_panels;
@@ -154,7 +155,7 @@ namespace GitgHistory
private void repository_changed_externally(GitgExt.ExternalChangeHint hint)
{
- if (d_main != null && (hint & GitgExt.ExternalChangeHint.REFS) != 0)
+ if (d_main != null && (hint & GitgExt.ExternalChangeHint.REFS) != 0 &&
!d_ignore_external)
{
d_reload_when_mapped = new Gitg.WhenMapped(d_main);
@@ -162,6 +163,8 @@ namespace GitgHistory
reload();
}, this);
}
+
+ d_ignore_external = false;
}
public override void dispose()
@@ -651,6 +654,10 @@ namespace GitgHistory
var af = new ActionInterface(application, d_main.refs_list);
+ af.updated.connect(() => {
+ d_ignore_external = true;
+ });
+
var actions = new Gee.LinkedList<GitgExt.CommitAction>();
add_commit_action(actions,
@@ -705,6 +712,11 @@ namespace GitgHistory
var af = new ActionInterface(application, d_main.refs_list);
+ af.updated.connect(() => {
+ d_ignore_external = true;
+ });
+
+ add_ref_action(actions, new Gitg.RefActionCheckout(application, af, reference));
add_ref_action(actions, new Gitg.RefActionRename(application, af, reference));
add_ref_action(actions, new Gitg.RefActionDelete(application, af, reference));
add_ref_action(actions, new Gitg.RefActionCopyName(application, af, reference));
diff --git a/libgitg-ext/gitg-ext-ref-action-interface.vala b/libgitg-ext/gitg-ext-ref-action-interface.vala
index 30ce09a..4a34991 100644
--- a/libgitg-ext/gitg-ext-ref-action-interface.vala
+++ b/libgitg-ext/gitg-ext-ref-action-interface.vala
@@ -31,6 +31,7 @@ public interface RefActionInterface : Object
public abstract void replace_ref(Gitg.Ref old_ref, Gitg.Ref new_ref);
public abstract void set_busy(Gitg.Ref reference, bool busy);
public abstract void edit_ref_name(Gitg.Ref reference, owned RefNameEditingDone callback);
+ public abstract void refresh();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]