[gitg/wip/actions] Implemented delete action for tags and branches



commit 4b6c8618a60a29e5e6fd6d9bb622653592d52504
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Jan 20 13:17:57 2014 +0100

    Implemented delete action for tags and branches

 gitg/gitg-ref-action-delete.vala |   82 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/gitg/gitg-ref-action-delete.vala b/gitg/gitg-ref-action-delete.vala
index e0016a1..02b10aa 100644
--- a/gitg/gitg-ref-action-delete.vala
+++ b/gitg/gitg-ref-action-delete.vala
@@ -55,6 +55,88 @@ class RefActionDelete : GitgExt.Action, GitgExt.RefAction, Object
 
        public void activated()
        {
+               var query = new GitgExt.UserQuery();
+
+               var name = reference.get_shorthand();
+
+               if (reference.is_branch())
+               {
+                       query.title = (_("Delete branch %s")).printf(name);
+                       query.message = (_("Are you sure that you want to permanently delete the branch 
%s?")).printf(name);
+               }
+               else if (reference.is_tag())
+               {
+                       query.title = (_("Delete tag %s")).printf(name);
+                       query.message = (_("Are you sure that you want to permanently delete the tag 
%s?")).printf(name);
+               }
+               else
+               {
+                       query.title = (_("Delete remote branch %s")).printf(name);
+                       query.message = (_("Are you sure that you want to permanently delete the remote 
branch %s?")).printf(name);
+               }
+
+               query.responses = new GitgExt.UserQueryResponse[] {
+                       new GitgExt.UserQueryResponse(_("Delete"), Gtk.ResponseType.OK),
+                       new GitgExt.UserQueryResponse(_("Cancel"), Gtk.ResponseType.CANCEL)
+               };
+
+               query.default_response = Gtk.ResponseType.OK;
+               query.response.connect(on_response);
+
+               action_interface.application.user_query(query);
+       }
+
+       private void on_response(Gtk.ResponseType response)
+       {
+               if (response != Gtk.ResponseType.OK)
+               {
+                       return;
+               }
+
+               if (reference.is_remote())
+               {
+                       // TODO
+                       return;
+               }
+               else
+               {
+                       try
+                       {
+                               reference.delete();
+                       }
+                       catch (Error e)
+                       {
+                               string title;
+                               string message;
+
+                               var name = reference.get_shorthand();
+
+                               if (reference.is_tag())
+                               {
+                                       // Translators: %s is the name of the tag
+                                       title = _("Failed to delete tag %s").printf(name);
+
+                                       // Translators: the first %s is the name of the tag, the second is an 
error message
+                                       message = _("The tag %s could not be deleted: %s").printf(name, 
e.message);
+                               }
+                               else
+                               {
+                                       // Translators: %s is the name of the branch
+                                       title = _("Failed to delete branch %s").printf(name);
+
+                                       // Translators: the first %s is the name of the branch, the second is 
an error message
+                                       message = _("The branch %s could not be deleted: %s").printf(name, 
e.message);
+                               }
+
+                               action_interface.application.show_infobar(title,
+                                                                         message,
+                                                                         Gtk.MessageType.ERROR);
+
+                               return;
+                       }
+               }
+
+               action_interface.remove_ref(reference);
        }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]