[gitg] Make actions implement UIElement



commit 242e23fac106e1681d32b1ae7627dc5dc4aecd7d
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Jul 20 10:54:46 2014 +0300

    Make actions implement UIElement

 gitg/gitg-ref-action-delete.vala |   36 ++++++++++++++++++++++++++++--------
 gitg/gitg-ref-action-rename.vala |   36 ++++++++++++++++++++++++++++--------
 gitg/history/gitg-history.vala   |    8 +++++---
 libgitg-ext/gitg-ext-action.vala |   20 +++++++++-----------
 4 files changed, 70 insertions(+), 30 deletions(-)
---
diff --git a/gitg/gitg-ref-action-delete.vala b/gitg/gitg-ref-action-delete.vala
index 86e8fbc..6f08323 100644
--- a/gitg/gitg-ref-action-delete.vala
+++ b/gitg/gitg-ref-action-delete.vala
@@ -20,22 +20,37 @@
 namespace Gitg
 {
 
-class RefActionDelete : GitgExt.Action, GitgExt.RefAction, Object
+class RefActionDelete : 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; }
 
-       public RefActionDelete(GitgExt.RefActionInterface action_interface, Gitg.Ref reference)
+       public RefActionDelete(GitgExt.Application        application,
+                              GitgExt.RefActionInterface action_interface,
+                              Gitg.Ref                   reference)
        {
-               Object(action_interface: action_interface, reference: reference);
+               Object(application:      application,
+                      action_interface: action_interface,
+                      reference:        reference);
        }
 
-       public string label
+       public string id
        {
-               get { return _("Delete"); }
+               owned get { return "/org/gnome/gitg/ref-actions/delete"; }
+       }
+
+       public string display_name
+       {
+               owned get { return _("Delete"); }
+       }
+
+       public string description
+       {
+               owned get { return _("Delete the selected reference"); }
        }
 
        public bool enabled
@@ -47,12 +62,17 @@ class RefActionDelete : GitgExt.Action, GitgExt.RefAction, Object
                }
        }
 
-       public bool visible
+       public Gtk.Widget? widget
+       {
+               owned get { return null; }
+       }
+
+       public string? icon
        {
-               get { return true; }
+               owned get { return null; }
        }
 
-       public void activated()
+       public void activate()
        {
                var query = new GitgExt.UserQuery();
 
diff --git a/gitg/gitg-ref-action-rename.vala b/gitg/gitg-ref-action-rename.vala
index d02b12e..475bf04 100644
--- a/gitg/gitg-ref-action-rename.vala
+++ b/gitg/gitg-ref-action-rename.vala
@@ -20,27 +20,37 @@
 namespace Gitg
 {
 
-class RefActionRename : GitgExt.Action, GitgExt.RefAction, Object
+class RefActionRename : 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; }
 
-       public RefActionRename(GitgExt.RefActionInterface action_interface, Gitg.Ref reference)
+       public RefActionRename(GitgExt.Application        application,
+                              GitgExt.RefActionInterface action_interface,
+                              Gitg.Ref                   reference)
        {
-               Object(action_interface: action_interface, reference: reference);
+               Object(application:      application,
+                      action_interface: action_interface,
+                      reference:        reference);
        }
 
-       public string label
+       public string id
        {
-               get { return _("Rename"); }
+               owned get { return "/org/gnome/gitg/ref-actions/rename"; }
        }
 
-       public bool visible
+       public string display_name
        {
-               get { return true; }
+               owned get { return _("Rename"); }
+       }
+
+       public string description
+       {
+               owned get { return _("Rename the selected reference"); }
        }
 
        public bool enabled
@@ -52,7 +62,17 @@ class RefActionRename : GitgExt.Action, GitgExt.RefAction, Object
                }
        }
 
-       public void activated()
+       public Gtk.Widget? widget
+       {
+               owned get { return null; }
+       }
+
+       public string? icon
+       {
+               owned get { return null; }
+       }
+
+       public void activate()
        {
                action_interface.edit_ref_name(reference, on_ref_name_editing_done);
        }
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index a9609f8..6639c8b 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -365,7 +365,7 @@ namespace GitgHistory
 
                private void add_ref_action(Gee.LinkedList<GitgExt.RefAction> actions, GitgExt.RefAction? 
action)
                {
-                       if (action.visible)
+                       if (action.available)
                        {
                                actions.add(action);
                        }
@@ -391,11 +391,13 @@ namespace GitgHistory
 
                        var af = new ActionInterface(application, d_main.refs_list);
 
-                       add_ref_action(actions, new Gitg.RefActionRename(af, reference));
-                       add_ref_action(actions, new Gitg.RefActionDelete(af, reference));
+                       add_ref_action(actions, new Gitg.RefActionRename(application, af, reference));
+                       add_ref_action(actions, new Gitg.RefActionDelete(application, af, reference));
 
                        var exts = new Peas.ExtensionSet(Gitg.PluginsEngine.get_default(),
                                                         typeof(GitgExt.RefAction),
+                                                        "application",
+                                                        application,
                                                         "action_interface",
                                                         af,
                                                         "reference",
diff --git a/libgitg-ext/gitg-ext-action.vala b/libgitg-ext/gitg-ext-action.vala
index d44fa05..b05808c 100644
--- a/libgitg-ext/gitg-ext-action.vala
+++ b/libgitg-ext/gitg-ext-action.vala
@@ -20,24 +20,22 @@
 namespace GitgExt
 {
 
-public interface Action : Object
+public interface Action : UIElement
 {
-       public abstract string label { get; }
-       public abstract bool enabled { get; }
-       public abstract bool visible { get; }
-
-       public virtual signal void activated()
-       {
-       }
-
        public virtual void populate_menu(Gtk.Menu menu)
        {
-               var item = new Gtk.MenuItem.with_label(label);
+               if (!available)
+               {
+                       return;
+               }
+
+               var item = new Gtk.MenuItem.with_label(display_name);
+               item.tooltip_text = description;
 
                if (enabled)
                {
                        item.activate.connect(() => {
-                               activated();
+                               activate();
                        });
                }
                else


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