[gitg] Add command line arguments to select all branches, remotes and tags



commit 36146039c4bbe759403d7deed373c4f6b765569d
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Aug 5 22:27:49 2015 +0200

    Add command line arguments to select all branches, remotes and tags
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737749

 gitg/history/gitg-history-command-line.vala |   50 ++++++++++++++++++--------
 gitg/history/gitg-history-refs-list.vala    |   52 ++++++++++++++++++++-------
 2 files changed, 74 insertions(+), 28 deletions(-)
---
diff --git a/gitg/history/gitg-history-command-line.vala b/gitg/history/gitg-history-command-line.vala
index a9053ef..0375585 100644
--- a/gitg/history/gitg-history-command-line.vala
+++ b/gitg/history/gitg-history-command-line.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of gitg
  *
- * Copyright (C) 2014 - Jesse van den Kieboom
+ * Copyright (C) 2015 - 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
@@ -26,22 +26,26 @@ class CommandLine : Object, GitgExt.CommandLine
        private const string version = Gitg.Config.VERSION;
 
        private static string? s_select_reference;
-       private string? d_select_reference;
-
-       public string select_reference
-       {
-               get { return d_select_reference; }
-       }
+       private static bool s_all_commits;
+       private static bool s_all_branches;
+       private static bool s_all_remotes;
+       private static bool s_all_tags;
 
-       private static bool select_all_commits()
-       {
-               s_select_reference = "*";
-               return true;
-       }
+       private string? d_select_reference;
+       private bool d_all_commits;
+       private bool d_all_branches;
+       private bool d_all_remotes;
+       private bool d_all_tags;
 
        private static const OptionEntry[] s_entries = {
-               { "all", 'a', OptionFlags.IN_MAIN | OptionFlags.NO_ARG, OptionArg.CALLBACK, (void 
*)select_all_commits,
-                 N_("Select all commits by default in the history activity (shorthand for --select-reference 
'*')"), null },
+               { "all", 'a', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_commits,
+                 N_("Select all commits by default in the history activity"), null },
+               { "branches", 'b', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_branches,
+                 N_("Select all branches by default in the history activity"), null },
+               { "remotes", 'r', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_remotes,
+                 N_("Select all remotes by default in the history activity"), null },
+               { "tags", 't', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_tags,
+                 N_("Select all tags by default in the history activity"), null },
                { "select-reference", 's', OptionFlags.IN_MAIN, OptionArg.STRING, ref s_select_reference,
                  N_("Select the specified reference by default in the history activity"), N_("REFERENCE") },
 
@@ -59,6 +63,10 @@ class CommandLine : Object, GitgExt.CommandLine
        public void parse_finished()
        {
                d_select_reference = s_select_reference;
+               d_all_commits = s_all_commits;
+               d_all_branches = s_all_branches;
+               d_all_remotes = s_all_remotes;
+               d_all_tags = s_all_tags;
        }
 
        public void apply(GitgExt.Application application)
@@ -70,10 +78,22 @@ class CommandLine : Object, GitgExt.CommandLine
                        return;
                }
 
-               if (d_select_reference == "*")
+               if (d_all_commits)
                {
                        history.refs_list.select_all_commits();
                }
+               else if (d_all_branches)
+               {
+                       history.refs_list.select_all_branches();
+               }
+               else if (d_all_remotes)
+               {
+                       history.refs_list.select_all_remotes();
+               }
+               else if (d_all_tags)
+               {
+                       history.refs_list.select_all_tags();
+               }
                else if (d_select_reference != null)
                {
                        try
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index 33fed66..7691809 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -425,6 +425,9 @@ public class RefsList : Gtk.ListBox
        private Gtk.ListBoxRow? d_selected_row;
        private Gitg.Remote[] d_remotes;
        private RefRow? d_all_commits;
+       private RefHeader? d_all_branches;
+       private RefHeader? d_all_remotes;
+       private RefHeader? d_all_tags;
 
        public signal void changed();
 
@@ -530,6 +533,9 @@ public class RefsList : Gtk.ListBox
        private void clear()
        {
                d_all_commits = null;
+               d_all_branches = null;
+               d_all_remotes = null;
+               d_all_tags = null;
 
                d_header_map = new Gee.HashMap<string, RemoteHeader>();
                d_ref_map = new Gee.HashMap<Gitg.Ref, RefRow>();
@@ -601,12 +607,13 @@ public class RefsList : Gtk.ListBox
                reselect_row(row);
        }
 
-       private void add_header(Gitg.RefType ref_type, string name)
+       private RefHeader add_header(Gitg.RefType ref_type, string name)
        {
                var header = new RefHeader(ref_type, name);
                header.show();
 
                add(header);
+               return header;
        }
 
        private void on_tip_updated(Ggit.Remote remote,
@@ -818,17 +825,37 @@ public class RefsList : Gtk.ListBox
                return false;
        }
 
-       public bool select_all_commits()
+       private bool select_nullable_row(Gtk.ListBoxRow? row)
        {
-               if (d_all_commits != null)
+               if (row == null)
                {
-                       select_row(d_all_commits);
-                       scroll_to_row(d_all_commits);
-
-                       return true;
+                       return false;
                }
 
-               return false;
+               select_row(row);
+               scroll_to_row(row);
+
+               return true;
+       }
+
+       public bool select_all_commits()
+       {
+               return select_nullable_row(d_all_commits);
+       }
+
+       public bool select_all_branches()
+       {
+               return select_nullable_row(d_all_branches);
+       }
+
+       public bool select_all_remotes()
+       {
+               return select_nullable_row(d_all_remotes);
+       }
+
+       public bool select_all_tags()
+       {
+               return select_nullable_row(d_all_tags);
        }
 
        public bool select_ref(Gitg.Ref reference)
@@ -868,10 +895,9 @@ public class RefsList : Gtk.ListBox
                }
 
                d_all_commits = add_ref_row(null);
-
-               add_header(Gitg.RefType.BRANCH, _("Branches"));
-               add_header(Gitg.RefType.REMOTE, _("Remotes"));
-               add_header(Gitg.RefType.TAG, _("Tags"));
+               d_all_branches = add_header(Gitg.RefType.BRANCH, _("Branches"));
+               d_all_remotes = add_header(Gitg.RefType.REMOTE, _("Remotes"));
+               d_all_tags = add_header(Gitg.RefType.TAG, _("Tags"));
 
                RefRow? head = null;
 
@@ -1120,7 +1146,7 @@ public class RefsList : Gtk.ListBox
                return ret;
        }
 
-       private void scroll_to_row(RefRow row)
+       private void scroll_to_row(Gtk.ListBoxRow row)
        {
                var adj = get_adjustment();
 


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