1/*
2 * This file is part of gitg
3 *
4 * Copyright (C) 2015 - Jesse van den Kieboom
5 *
6 * gitg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * gitg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gitg. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20namespace GitgHistory
21{
22
23class CommandLine : Object, GitgExt.CommandLine
24{
25	// Do this to pull in config.h before glib.h (for gettext...)
26	private const string version = Gitg.Config.VERSION;
27
28	private static string? s_select_reference;
29	private static bool s_all_commits;
30	private static bool s_all_branches;
31	private static bool s_all_remotes;
32	private static bool s_all_tags;
33
34	private string? d_select_reference;
35	private bool d_all_commits;
36	private bool d_all_branches;
37	private bool d_all_remotes;
38	private bool d_all_tags;
39
40	private const OptionEntry[] s_entries = {
41		{ "all", 'a', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_commits,
42		  N_("Select all commits by default in the history activity"), null },
43		{ "branches", 'b', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_branches,
44		  N_("Select all branches by default in the history activity"), null },
45		{ "remotes", 'r', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_remotes,
46		  N_("Select all remotes by default in the history activity"), null },
47		{ "tags", 't', OptionFlags.IN_MAIN, OptionArg.NONE, ref s_all_tags,
48		  N_("Select all tags by default in the history activity"), null },
49		{ "select-reference", 's', OptionFlags.IN_MAIN, OptionArg.STRING, ref s_select_reference,
50		  N_("Select the specified reference by default in the history activity"), N_("REFERENCE") },
51
52		{null}
53	};
54
55	public OptionGroup get_option_group()
56	{
57		var group = new OptionGroup("", "", "");
58		group.add_entries(s_entries);
59
60		return group;
61	}
62
63	public void parse_finished()
64	{
65		d_select_reference = s_select_reference;
66		d_all_commits = s_all_commits;
67		d_all_branches = s_all_branches;
68		d_all_remotes = s_all_remotes;
69		d_all_tags = s_all_tags;
70	}
71
72	public void apply(GitgExt.Application application)
73	{
74		var history = application.get_activity_by_id("/org/gnome/gitg/Activities/History") as Activity;
75
76		if (history == null)
77		{
78			return;
79		}
80
81		if (d_all_commits)
82		{
83			history.refs_list.select_all_commits();
84		}
85		else if (d_all_branches)
86		{
87			history.refs_list.select_all_branches();
88		}
89		else if (d_all_remotes)
90		{
91			history.refs_list.select_all_remotes();
92		}
93		else if (d_all_tags)
94		{
95			history.refs_list.select_all_tags();
96		}
97		else if (d_select_reference != null)
98		{
99			try
100			{
101				history.refs_list.select_ref(application.repository.lookup_reference_dwim(d_select_reference));
102			}
103			catch (Error e)
104			{
105				stderr.printf("Failed to lookup reference %s: %s\n", d_select_reference, e.message);
106			}
107		}
108	}
109}
110
111}
112
113// ex: ts=4 noet
114