[gitg/wip/adwait/add-remotes: 76/77] TODOs
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/adwait/add-remotes: 76/77] TODOs
- Date: Mon, 9 Dec 2019 20:59:51 +0000 (UTC)
commit cbff636c23dc0ca7fb80228ccf55a389fc6bec75
Author: Adwait Rawat <adwait rawat gmail com>
Date: Thu Jul 4 17:56:35 2019 +0900
TODOs
gitg/gitg-add-remote-action.vala | 26 ++++++++++++++------------
gitg/history/gitg-history-refs-list.vala | 14 ++++++++++++++
gitg/history/gitg-history.vala | 32 ++++++++++++++++++++++++++++----
libgitg-ext/gitg-ext-action.vala | 4 ++++
4 files changed, 60 insertions(+), 16 deletions(-)
---
diff --git a/gitg/gitg-add-remote-action.vala b/gitg/gitg-add-remote-action.vala
index 8da46e23..4b12bee6 100644
--- a/gitg/gitg-add-remote-action.vala
+++ b/gitg/gitg-add-remote-action.vala
@@ -8,6 +8,8 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
public GitgExt.Application? application { owned get; construct set; }
Gitg.Remote? d_remote;
+ Gitg.Repository? repo;
+ string? remote_name;
public AddRemoteAction(GitgExt.Application application)
{
@@ -30,8 +32,8 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
}
//TODO: This code is copy&paste fromGitg.RefActionFetch, would be better to
- //abstract the code to call it from both places
- public async void fetch_remote(Gitg.Repository repo, string remote_name)
+ //abstract the code to call it from both places
+ public async bool fetch()
{
var notification = new RemoteNotification(d_remote);
application.notifications.add(notification);
@@ -45,8 +47,6 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
updates.add(@"%s (%s)".printf(name, _("new")));
});
- var fetched = true;
-
try
{
yield d_remote.fetch(null, null);
@@ -56,8 +56,6 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
try {
repo.remove_remote(remote_name);
notification.error(_("Failed to fetch from %s:
%s").printf(d_remote.get_url(), e.message));
-
- fetched = false;
}
catch {}
application.show_infobar(_("Failed to fetch added remote"),
@@ -69,15 +67,19 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
((Object)d_remote).disconnect(tip_updated_id);
}
- if (fetched)
+ if (updates.size != 0)
{
notification.success(_("Fetched from %s: %s").printf(d_remote.get_url(),
string.joinv(", ", updates.to_array())));
- ((Gtk.ApplicationWindow)application).activate_action("reload", null);
}
else
{
add_remote();
+
+ return false;
}
+
+ ((Gtk.ApplicationWindow)application).activate_action("reload", null);
+ return true;
}
public void add_remote()
@@ -91,8 +93,8 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
Ggit.Remote? remote = null;
d_remote = null;
- var repo = application.repository;
- var remote_name = dlg.remote_name;
+ repo = application.repository;
+ remote_name = dlg.remote_name;
try
{
@@ -112,8 +114,8 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
if (remote != null)
{
- fetch_remote.begin(repo, remote_name, (obj,res) => {
- fetch_remote.end(res);
+ fetch.begin((obj,res) => {
+ fetch.end(res);
});
}
}
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index c4fc1b59..a9559ff0 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -456,6 +456,20 @@ private class RefHeader : RefTyped, Gtk.ListBoxRow
get { return d_name; }
}
+ public Gee.LinkedList<GitgExt.Action> get_actions (GitgExt.Application application)
+ {
+ var actions = new Gee.LinkedList<GitgExt.Action>();
+ if (d_rtype == Gitg.RefType.REMOTE)
+ {
+ actions.add(new Gitg.AddRemoteAction(application));
+ }
+ else {
+ actions = null;
+ }
+
+ return actions;
+ }
+
public RefHeader(Gitg.RefType rtype, string name)
{
var escaped = Markup.escape_text(name);
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 2fad3e87..d1050e00 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -53,7 +53,6 @@ namespace GitgHistory
private Paned d_main;
private Gitg.PopupMenu d_refs_list_popup;
- private Gitg.PopupMenu d_remote_header_popup;
private Gitg.PopupMenu d_commit_list_popup;
private string[] d_mainline;
@@ -985,12 +984,37 @@ namespace GitgHistory
}
var references = d_main.refs_list.selection;
+ var actions = new Gee.LinkedList<GitgExt.Action>();
if (references.is_empty || references.first() != references.last())
{
- //TODO: Would be better to make the RefHeader to provide the actions it can
execute
- if (selection != null && selection.get_type () == typeof(RefHeader) &&
((RefHeader)selection).ref_name == _("Remotes")) {
- return popup_menu_for_remote();
+ if (selection != null && selection.get_type () == typeof(RefHeader)) {
+ actions = ((RefHeader)selection).get_actions (application);
+
+ if (actions != null)
+ {
+ var menu = new Gtk.Menu();
+
+ foreach (var ac in actions)
+ {
+ if (ac != null)
+ {
+ ac.populate_menu(menu);
+ }
+ else
+ {
+ var sep = new Gtk.SeparatorMenuItem();
+ sep.show();
+ menu.append(sep);
+ }
+ }
+
+ menu.set_data("gitg-ext-actions", actions);
+ return menu;
+ }
+ else{
+ return null;
+ }
} else {
return null;
}
diff --git a/libgitg-ext/gitg-ext-action.vala b/libgitg-ext/gitg-ext-action.vala
index b05808ce..caddc864 100644
--- a/libgitg-ext/gitg-ext-action.vala
+++ b/libgitg-ext/gitg-ext-action.vala
@@ -46,6 +46,10 @@ public interface Action : UIElement
item.show();
menu.append(item);
}
+
+ public virtual async bool fetch(){
+ return true;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]