[gitg/remote-operations: 1/3] Allow to remove remotes




commit 3991095dc47180b81cee2c20a1340b76dfe65a38
Author: Adwait Rawat <adwait rawat gmail com>
Date:   Wed Jun 19 20:03:11 2019 +0900

    Allow to remove remotes
    
    Selected remote can be removed from the remotes list

 gitg/gitg-ref-action-remove-remote.vala | 110 ++++++++++++++++++++++++++++++++
 gitg/history/gitg-history.vala          |   9 +++
 gitg/meson.build                        |   1 +
 3 files changed, 120 insertions(+)
---
diff --git a/gitg/gitg-ref-action-remove-remote.vala b/gitg/gitg-ref-action-remove-remote.vala
new file mode 100644
index 00000000..26adbb81
--- /dev/null
+++ b/gitg/gitg-ref-action-remove-remote.vala
@@ -0,0 +1,110 @@
+namespace Gitg
+{
+
+class RefActionRemoveRemote : 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; }
+       Gitg.Ref? d_remote_ref;
+       Gitg.Remote? d_remote;
+
+       public RefActionRemoveRemote(GitgExt.Application        application,
+                                                                GitgExt.RefActionInterface action_interface,
+                                                                Gitg.Ref                   reference)
+       {
+               Object(application:      application,
+                      action_interface: action_interface,
+                          reference:        reference);
+
+               var branch = reference as Ggit.Branch;
+
+               if (branch != null)
+               {
+                       try
+                       {
+                               d_remote_ref = branch.get_upstream() as Gitg.Ref;
+                       } catch {}
+               }
+               else if (reference.parsed_name.remote_name != null)
+               {
+                       d_remote_ref = reference;
+               }
+
+               if (d_remote_ref != null)
+               {
+                       d_remote = application.remote_lookup.lookup(d_remote_ref.parsed_name.remote_name);
+               }
+       }
+
+       public string id
+       {
+               owned get { return "/org/gnome/gitg/ref-actions/remove-remote"; }
+       }
+
+       public string display_name
+       {
+               owned get { return _("Remove remote"); }
+       }
+
+       public string description
+       {
+               owned get { return _("Removes remote from the remotes list"); }
+       }
+
+       public bool available
+       {
+               get { return d_remote != null; }
+       }
+
+       public void activate()
+       {
+        var query = new GitgExt.UserQuery();
+
+               var remote_name = d_remote_ref.parsed_name.remote_name;
+
+               query.title = (_("Delete remote %s")).printf(remote_name);
+               query.message = (_("Are you sure that you want to remove the remote 
%s?")).printf(remote_name);
+
+               query.set_responses(new GitgExt.UserQueryResponse[] {
+                       new GitgExt.UserQueryResponse(_("Cancel"), Gtk.ResponseType.CANCEL),
+                       new GitgExt.UserQueryResponse(_("Remove"), Gtk.ResponseType.OK)
+        });
+
+        query.default_response = Gtk.ResponseType.OK;
+               query.response.connect(on_response);
+
+               action_interface.application.user_query(query);
+    }
+
+       private bool on_response(Gtk.ResponseType response)
+       {
+               if (response != Gtk.ResponseType.OK)
+               {
+                       return true;
+               }
+
+               var repo = application.repository;
+
+               try
+               {
+                       repo.remove_remote(d_remote.get_name());
+               }
+               catch (Error e)
+               {
+                       application.show_infobar(_("Failed to remove remote"),
+                                                                        e.message,
+                                                Gtk.MessageType.ERROR);
+               }
+
+               ((Gtk.ApplicationWindow)application).activate_action("reload", null);
+               return true;
+       }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index ef27bb9a..1f156b86 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -871,6 +871,15 @@ namespace GitgHistory
                        add_ref_action(actions, new Gitg.RefActionDelete(application, af, reference));
                        add_ref_action(actions, new Gitg.RefActionCopyName(application, af, reference));
 
+                       var remove_remote = new Gitg.RefActionRemoveRemote(application, af, reference);
+
+                       if (remove_remote.available)
+                       {
+                               actions.add(null);
+                       }
+
+                       add_ref_action(actions, remove_remote);
+
                        var fetch = new Gitg.RefActionFetch(application, af, reference);
 
                        if (fetch.available)
diff --git a/gitg/meson.build b/gitg/meson.build
index 937a01a3..b9d8c0be 100644
--- a/gitg/meson.build
+++ b/gitg/meson.build
@@ -45,6 +45,7 @@ sources = gitg_sources + files(
   'gitg-ref-action-delete.vala',
   'gitg-ref-action-fetch.vala',
   'gitg-ref-action-push.vala',
+  'gitg-ref-action-remove-remote.vala',
   'gitg-ref-action-rename.vala',
   'gitg-add-remote-action-dialog.vala',
   'gitg-add-remote-action.vala',


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