[gitg/wip/fetch: 5/9] Add RefActionFetch



commit 0bdd143e5002828bddf891f4d4933f630e156213
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Dec 21 22:01:06 2014 +0100

    Add RefActionFetch

 gitg/Makefile.am                |    1 +
 gitg/gitg-ref-action-fetch.vala |   94 +++++++++++++++++++++++++++++++++++++++
 gitg/history/gitg-history.vala  |    5 ++
 3 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 0cb6f42..7654b40 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -63,6 +63,7 @@ gitg_gitg_VALASOURCES =                                               \
        gitg/gitg-ref-action-rename.vala                        \
        gitg/gitg-ref-action-delete.vala                        \
        gitg/gitg-ref-action-copy-name.vala                     \
+       gitg/gitg-ref-action-fetch.vala                         \
        gitg/gitg-commit-action-create-branch.vala              \
        gitg/gitg-create-branch-dialog.vala                     \
        gitg/gitg-commit-action-create-tag.vala                 \
diff --git a/gitg/gitg-ref-action-fetch.vala b/gitg/gitg-ref-action-fetch.vala
new file mode 100644
index 0000000..e936e60
--- /dev/null
+++ b/gitg/gitg-ref-action-fetch.vala
@@ -0,0 +1,94 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * 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 RefActionFetch : 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; }
+  private Gitg.Ref? d_remote;
+
+  public RefActionFetch(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 = branch.get_upstream() as Gitg.Ref;
+      } catch {}
+    }
+    else if (reference.parsed_name.remote_name != null)
+    {
+      d_remote = reference;
+    }
+  }
+
+  public string id
+  {
+    owned get { return "/org/gnome/gitg/ref-actions/fetch"; }
+  }
+
+  public string display_name
+  {
+    owned get
+    {
+      if (d_remote != null)
+      {
+        return _("Fetch from %s").printf(d_remote.parsed_name.remote_name);
+      }
+      else
+      {
+        return "";
+      }
+    }
+  }
+
+  public string description
+  {
+    owned get { return _("Fetch remote objects from %s").printf(d_remote.parsed_name.remote_name); }
+  }
+
+  public bool available
+  {
+    get { return d_remote != null; }
+  }
+
+  public void activate()
+  {
+    // TODO
+  }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 5324962..1a7f36f 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -551,6 +551,7 @@ namespace GitgHistory
                        add_ref_action(actions, new Gitg.RefActionRename(application, af, reference));
                        add_ref_action(actions, new Gitg.RefActionDelete(application, af, reference));
                        add_ref_action(actions, new Gitg.RefActionCopyName(application, af, reference));
+                       add_ref_action(actions, new Gitg.RefActionFetch(application, af, reference));
 
                        var exts = new Peas.ExtensionSet(Gitg.PluginsEngine.get_default(),
                                                         typeof(GitgExt.RefAction),
@@ -577,6 +578,10 @@ namespace GitgHistory
                                ac.populate_menu(menu);
                        }
 
+                       var sep = new Gtk.SeparatorMenuItem();
+                       sep.show();
+                       menu.append(sep);
+
                        var item = new Gtk.CheckMenuItem.with_label(_("Mainline"));
                        int pos = 0;
 


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