[gitg/wip/adwait/add-remotes: 2/2] Refactor Add remote feature whitespace reduntant popup function executing only on Remotes node Bette



commit be9f0fa6c0992157bb885a187d5c6d5958e5ffbd
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Wed Jul 3 18:30:24 2019 +0200

    Refactor Add remote feature
    whitespace
    reduntant popup function
    executing only on Remotes node
    Better naming on dialog (no need to use new_*)

 gitg/gitg-add-remote-action-dialog.vala  |  4 ++--
 gitg/gitg-add-remote-action.vala         | 26 ++++++++++++++------------
 gitg/history/gitg-history-refs-list.vala |  2 +-
 gitg/history/gitg-history.vala           | 26 ++++++++++----------------
 4 files changed, 27 insertions(+), 31 deletions(-)
---
diff --git a/gitg/gitg-add-remote-action-dialog.vala b/gitg/gitg-add-remote-action-dialog.vala
index 3b085105..f1008503 100644
--- a/gitg/gitg-add-remote-action-dialog.vala
+++ b/gitg/gitg-add-remote-action-dialog.vala
@@ -39,7 +39,7 @@ class AddRemoteActionDialog : Gtk.Dialog
                }
        }
 
-       public string new_remote_name
+       public string remote_name
        {
                owned get
                {
@@ -47,7 +47,7 @@ class AddRemoteActionDialog : Gtk.Dialog
                }
        }
 
-       public string new_remote_url
+       public string remote_url
        {
                owned get
                {
diff --git a/gitg/gitg-add-remote-action.vala b/gitg/gitg-add-remote-action.vala
index c6a8ad35..8da46e23 100644
--- a/gitg/gitg-add-remote-action.vala
+++ b/gitg/gitg-add-remote-action.vala
@@ -9,9 +9,9 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
        public GitgExt.Application? application { owned get; construct set; }
        Gitg.Remote? d_remote;
 
-       public AddRemoteAction(GitgExt.Application        application)
+       public AddRemoteAction(GitgExt.Application application)
        {
-               Object(application:      application);
+               Object(application: application);
        }
 
        public string id
@@ -29,7 +29,9 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
                owned get { return _("Adds remote to the remotes list"); }
        }
 
-       public async void fetch_remote( Gitg.Repository repo, string new_remote_name)
+       //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)
        {
                var notification = new RemoteNotification(d_remote);
                application.notifications.add(notification);
@@ -52,15 +54,15 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
                catch (Error e)
                {
                        try {
-                               repo.remove_remote(new_remote_name);
+                               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"),
-                                                                       e.message,
-                                                                       Gtk.MessageType.ERROR);
+                                                e.message,
+                                                Gtk.MessageType.ERROR);
                }
                finally
                {
@@ -90,12 +92,12 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
                                d_remote = null;
 
                                var repo = application.repository;
-                               var new_remote_name = dlg.new_remote_name;
+                               var remote_name = dlg.remote_name;
 
                                try
                                {
-                                       remote = repo.create_remote(new_remote_name,
-                                                                                               
dlg.new_remote_url);
+                                       remote = repo.create_remote(remote_name,
+                                                                   dlg.remote_url);
                                }
                                catch (Error e)
                                {
@@ -103,14 +105,14 @@ class AddRemoteAction : GitgExt.UIElement, GitgExt.Action, Object
                                        add_remote();
                                        application.show_infobar(_("Failed to add remote"),
                                                                 e.message,
-                                                                                        
Gtk.MessageType.ERROR);
+                                                                Gtk.MessageType.ERROR);
                                }
 
-                               d_remote = application.remote_lookup.lookup(new_remote_name);
+                               d_remote = application.remote_lookup.lookup(remote_name);
 
                                if (remote != null)
                                {
-                                       fetch_remote.begin(repo, new_remote_name, (obj,res) => {
+                                       fetch_remote.begin(repo, remote_name, (obj,res) => {
                                                fetch_remote.end(res);
                                        });
                                }
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index 75ecd438..18caa64c 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -1407,7 +1407,7 @@ public class RefsList : Gtk.ListBox
                row.begin_editing((owned)done);
        }
 
-       private int y_in_window(int y, Gdk.Window origin)
+       public int y_in_window(int y, Gdk.Window origin)
        {
                while (origin != get_window())
                {
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index d9efb9ed..3330acf6 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -588,9 +588,6 @@ namespace GitgHistory
                        d_refs_list_popup = new Gitg.PopupMenu(d_main.refs_list);
                        d_refs_list_popup.populate_menu.connect(on_refs_list_populate_menu);
 
-                       d_remote_header_popup = new Gitg.PopupMenu(d_main.refs_list);
-                       d_remote_header_popup.populate_menu.connect(on_remote_header_populate_menu);
-
                        d_refs_list_selection_id = 
d_main.refs_list.notify["selection"].connect(update_walker_idle);
                        d_refs_list_changed_id = d_main.refs_list.changed.connect(update_walker_idle);
 
@@ -978,9 +975,12 @@ namespace GitgHistory
 
                private Gtk.Menu? on_refs_list_populate_menu(Gdk.EventButton? event)
                {
+                       Gtk.ListBoxRow selection = null;
                        if (event != null)
                        {
-                               var row = d_main.refs_list.get_row_at_y((int)event.y);
+                       var y = d_main.refs_list.y_in_window((int)event.y, event.window);
+                               var row = d_main.refs_list.get_row_at_y(y);
+                               selection = row;
                                d_main.refs_list.select_row(row);
                        }
 
@@ -988,23 +988,17 @@ namespace GitgHistory
 
                        if (references.is_empty || references.first() != references.last())
                        {
-                               return null;
+                               //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();
+                               } else {
+                                       return null;
+                               }
                        }
 
                        return popup_menu_for_ref(references.first());
                }
 
-               private Gtk.Menu? on_remote_header_populate_menu(Gdk.EventButton? event)
-               {
-                       if (event != null)
-                       {
-                               var row = d_main.refs_list.get_row_at_y((int)event.y);
-                               d_main.refs_list.select_row(row);
-                       }
-
-                       return popup_menu_for_remote();
-               }
-
                private Ggit.OId? id_for_ref(Ggit.Ref r)
                {
                        Ggit.OId? id = null;


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