Allow to remove remotes

Selected remote can be removed from the remotes list
This commit is contained in:
Adwait Rawat 2019-06-19 20:03:11 +09:00 committed by Alberto Fanjul
parent be22b5370c
commit af79bba862
3 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,129 @@
/*
* This file is part of gitg
*
* Copyright (C) 2022 - Adwait Rawat
*
* 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 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

View file

@ -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)

View file

@ -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',