[gitg] Use simple notification for checkout action
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Use simple notification for checkout action
- Date: Thu, 13 Aug 2015 06:20:02 +0000 (UTC)
commit abffafe7570431d65efaff7a2f0326e3b0c44255
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Thu Aug 13 08:09:02 2015 +0200
Use simple notification for checkout action
gitg/gitg-ref-action-checkout.vala | 93 +++++++++++++++++++++--------------
1 files changed, 56 insertions(+), 37 deletions(-)
---
diff --git a/gitg/gitg-ref-action-checkout.vala b/gitg/gitg-ref-action-checkout.vala
index 651f70b..3b57109 100644
--- a/gitg/gitg-ref-action-checkout.vala
+++ b/gitg/gitg-ref-action-checkout.vala
@@ -59,58 +59,77 @@ class RefActionCheckout : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction,
{
try
{
- var head = application.repository.get_head();
+ return reference.is_branch() && !((Ggit.Branch)reference).is_head();
+ } catch {}
- if (head != null && head.get_name() == reference.get_name())
- {
- return false;
- }
- }
- catch {}
-
- return reference.is_branch();
+ return false;
}
}
- public void activate()
+ public async bool checkout()
{
var repo = application.repository;
- Commit commit;
+ var notification = new SimpleNotification(_("Checkout
%s").printf(reference.parsed_name.shortname));
+ bool retval = false;
- 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;
- }
+ application.notifications.add(notification);
try
{
- var opts = new Ggit.CheckoutOptions();
- opts.set_strategy(Ggit.CheckoutStrategy.SAFE);
+ yield Async.thread(() => {
+ Commit commit;
- repo.checkout_tree(commit.get_tree(), opts);
- }
- catch (Error e)
- {
- action_interface.application.show_infobar(_("Failed to checkout branch"),
- e.message,
- Gtk.MessageType.ERROR);
+ try
+ {
+ commit = reference.resolve().lookup() as Gitg.Commit;
+ }
+ catch (Error e)
+ {
+ notification.error(_("Failed to lookup commit:
%s").printf(e.message));
+ return;
+ }
- return;
- }
+ try
+ {
+ var opts = new Ggit.CheckoutOptions();
+ opts.set_strategy(Ggit.CheckoutStrategy.SAFE);
- try
- {
- application.repository.set_head(reference.get_name());
+ repo.checkout_tree(commit.get_tree(), opts);
+ }
+ catch (Error e)
+ {
+ notification.error(_("Failed to checkout branch:
%s").printf(e.message));
+ return;
+ }
+
+ try
+ {
+ repo.set_head(reference.get_name());
+ }
+ catch (Error e)
+ {
+ notification.error(_("Failed to update HEAD: %s").printf(e.message));
+ return;
+ }
+
+ retval = true;
+ });
} catch {}
- action_interface.refresh();
+ if (retval)
+ {
+ notification.success(_("Successfully checked out branch to working directory"));
+ action_interface.refresh();
+ }
+
+ return retval;
+ }
+
+ public void activate()
+ {
+ checkout.begin((obj, res) => {
+ checkout.end(res);
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]