Debian Codegraph @

git/gitentry.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : gitentry.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 //////////////////////////////////////////////////////////////////////////////
27 //////////////////////////////////////////////////////////////////////////////
28 //
29 // copyright : (C) 2011 by René Kraus (aka upCASE)
30 //
31 //////////////////////////////////////////////////////////////////////////////
32
33 #ifndef __gitentry__
34 #define __gitentry__
35
36 #include "cl_config.h"
37 #include "wxStringHash.h"
38
39 #include <map>
40 #include <vector>
41 #include <wx/colour.h>
42 #include <wx/event.h>
43
44 struct GitLabelCommand {
45 GitLabelCommand() {}
46
47 GitLabelCommand(const wxString& l, const wxString& c)
48 : label(l)
49 , command(c)
50 {
51 }
52
53 wxString label; // The menu label
54 wxString command; // The command string, without the initial 'git' or the extras like --no-pager
55 };
56
57 typedef std::vector<GitLabelCommand> vGitLabelCommands_t;
58 class GitCommandsEntries // Holds a command-list for a particular git command e.g. 'git pull' might be that, or 'git
59 // pull --rebase'
60 {
61 protected:
62 vGitLabelCommands_t m_commands;
63 wxString m_commandName;
64 int m_lastUsed;
65
66 public:
67 GitCommandsEntries() {}
68 GitCommandsEntries(const wxString& commandName)
69 : m_commandName(commandName)
70 , m_lastUsed(-1)
71 {
72 }
73 GitCommandsEntries(const GitCommandsEntries& gce)
74 : m_commands(gce.m_commands)
75 , m_commandName(gce.m_commandName)
76 , m_lastUsed(gce.m_lastUsed)
77 {
78 }
79
80 virtual ~GitCommandsEntries() {}
81 void FromJSON(const JSONItem& json);
82 void ToJSON(JSONItem& arr) const;
83
84 const wxString& GetCommandname() const { return m_commandName; }
85
86 const vGitLabelCommands_t& GetCommands() const { return m_commands; }
87
88 void SetCommands(const vGitLabelCommands_t& commands) { m_commands = commands; }
89
90 const wxString GetDefaultCommand() const
91 {
92 wxString str;
93 if(m_lastUsed >= 0 && m_lastUsed < (int)m_commands.size()) {
94 str = m_commands.at(m_lastUsed).command;
95 }
96 return str;
97 }
98
99 int GetLastUsedCommandIndex() const { return m_lastUsed; }
100
101 void SetLastUsedCommandIndex(int index) { m_lastUsed = index; }
102 };
103
104 typedef std::unordered_map<wxString, GitCommandsEntries> GitCommandsEntriesMap_t;
105
106 class GitWorkspace
107 {
108 public:
109 GitWorkspace() {}
110 GitWorkspace(const wxString& name)
111 : m_name(name)
112 {
113 }
114
115 const wxString& GetWorkspaceName() const { return m_name; }
116 void SetWorkspaceName(const wxString& name) { m_name = name; }
117 const wxString GetProjectUserEnteredRepoPath(const wxString& projectName);
118 void SetProjectUserEnteredRepoPath(const wxString& projectName, const wxString& userEnteredRepoPath);
119
120 void FromJSON(const JSONItem& json);
121 void ToJSON(JSONItem& arr) const;
122
123 protected:
124 wxString m_name;
125 wxStringMap_t m_projectData;
126 wxStringMap_t m_userEnteredRepoPath;
127 };
128
129 typedef std::unordered_map<wxString, GitWorkspace> GitWorkspaceMap_t;
130
131 extern const wxEventType wxEVT_GIT_CONFIG_CHANGED;
132 class GitEntry : public clConfigItem
133 {
134 wxColour m_colourTrackedFile;
135 wxColour m_colourDiffFile;
136 wxString m_pathGIT;
137 wxString m_pathGITK;
138 wxStringMap_t m_entries;
139 GitCommandsEntriesMap_t m_commandsMap;
140 GitWorkspaceMap_t m_workspacesMap;
141 size_t m_flags;
142 int m_gitDiffDlgSashPos;
143 int m_gitDiffChooseDlgRadioSel1;
144 int m_gitDiffChooseDlgRadioSel2;
145 wxArrayString m_gitDiffChooseDlgCBoxValues1;
146 wxArrayString m_gitDiffChooseDlgCBoxValues2;
147 int m_gitConsoleSashPos;
148 int m_gitCommitDlgHSashPos;
149 int m_gitCommitDlgVSashPos;
150 wxArrayString m_recentCommits;
151 wxString m_gitShellCommand;
152 bool m_gitBlameShowLogControls;
153 bool m_gitBlameShowParentCommit;
154 int m_gitBlameDlgMainSashPos;
155 int m_gitBlameDlgHSashPos;
156 int m_gitBlameDlgVSashPos;
157
158 public:
159 enum {
160 Git_Verbose_Log = (1 << 0),
161 Git_Show_Terminal = (1 << 1),
162 Git_Colour_Tree_View = (1 << 2),
163 Git_Show_Commit_Info = (1 << 4),
164 };
165
166 struct GitProperties {
167 wxString global_username;
168 wxString global_email;
169 wxString local_username;
170 wxString local_email;
171 };
172
173 public:
174 GitEntry();
175 virtual ~GitEntry();
176
177 public:
178 static GitEntry::GitProperties ReadGitProperties(const wxString& localRepoPath = "");
179 static void WriteGitProperties(const wxString& localRepoPath, const GitEntry::GitProperties& props);
180
181 void EnableFlag(size_t flag, bool b)
182 {
183 if(b) {
184 m_flags |= flag;
185 } else {
186 m_flags &= ~flag;
187 }
188 }
189
190 void Save();
191 GitEntry& Load();
192 wxArrayString& GetRecentCommit() { return m_recentCommits; }
193 void AddRecentCommit(const wxString& commitMessage);
194
195 void SetGitShellCommand(const wxString& gitShellCommand) { this->m_gitShellCommand = gitShellCommand; }
196 const wxString& GetGitShellCommand() const { return m_gitShellCommand; }
197 void SetGitCommitDlgHSashPos(int gitCommitDlgHSashPos) { this->m_gitCommitDlgHSashPos = gitCommitDlgHSashPos; }
198 void SetGitCommitDlgVSashPos(int gitCommitDlgVSashPos) { this->m_gitCommitDlgVSashPos = gitCommitDlgVSashPos; }
199 int GetGitCommitDlgHSashPos() const { return m_gitCommitDlgHSashPos; }
200 int GetGitCommitDlgVSashPos() const { return m_gitCommitDlgVSashPos; }
201 void SetGitDiffDlgSashPos(int gitDiffDlgSashPos) { this->m_gitDiffDlgSashPos = gitDiffDlgSashPos; }
202 int GetGitDiffDlgSashPos() const { return m_gitDiffDlgSashPos; }
203 void SetGitDiffChooseDlgRadioSel1(int sel) { this->m_gitDiffChooseDlgRadioSel1 = sel; }
204 int GetGitDiffChooseDlgRadioSel1() const { return m_gitDiffChooseDlgRadioSel1; }
205 void SetGitDiffChooseDlgRadioSel2(int sel) { this->m_gitDiffChooseDlgRadioSel2 = sel; }
206 int GetGitDiffChooseDlgRadioSel2() const { return m_gitDiffChooseDlgRadioSel2; }
207 void SetGitDiffChooseDlgCBoxValues1(const wxArrayString& arr) { this->m_gitDiffChooseDlgCBoxValues1 = arr; }
208 wxArrayString& GetGitDiffChooseDlgCBoxValues1() { return m_gitDiffChooseDlgCBoxValues1; }
209 void SetGitDiffChooseDlgCBoxValues2(const wxArrayString& arr) { this->m_gitDiffChooseDlgCBoxValues2 = arr; }
210 wxArrayString& GetGitDiffChooseDlgCBoxValues2() { return m_gitDiffChooseDlgCBoxValues2; }
211 void SetEntries(const wxStringMap_t& entries) { this->m_entries = entries; }
212 void SetFlags(size_t flags) { this->m_flags = flags; }
213 const wxStringMap_t& GetEntries() const { return m_entries; }
214 size_t GetFlags() const { return m_flags; }
215 void SetEntry(const wxString& workspace, const wxString& repo) { this->m_entries[workspace] = repo; }
216 void DeleteEntry(const wxString& workspace);
217
218 GitCommandsEntriesMap_t GetCommandsMap() const { return m_commandsMap; }
219 void SetTrackedFileColour(const wxColour& colour) { this->m_colourTrackedFile = colour; }
220 void SetDiffFileColour(const wxColour& colour) { this->m_colourDiffFile = colour; }
221 void SetGITExecutablePath(const wxString& exe) { this->m_pathGIT = exe; }
222 void SetGITKExecutablePath(const wxString& exe) { this->m_pathGITK = exe; }
223 const wxString& GetPath(const wxString& workspace) { return m_entries[workspace]; }
224 const wxColour& GetTrackedFileColour() { return this->m_colourTrackedFile; }
225 const wxColour& GetDiffFileColour() { return this->m_colourDiffFile; }
226 wxString GetGITExecutablePath() const;
227 wxString GetGITKExecutablePath() const;
228 void SetGitConsoleSashPos(int gitConsoleSashPos) { this->m_gitConsoleSashPos = gitConsoleSashPos; }
229 int GetGitConsoleSashPos() const { return m_gitConsoleSashPos; }
230 void SetGitBlameShowLogControls(bool gitBlameShowLogControls)
231 {
232 this->m_gitBlameShowLogControls = gitBlameShowLogControls;
233 }
234 bool GetGitBlameShowLogControls() const { return m_gitBlameShowLogControls; }
235 void SetGitBlameShowParentCommit(bool gitBlameShowParentCommit)
236 {
237 this->m_gitBlameShowParentCommit = gitBlameShowParentCommit;
238 }
239 bool GetGitBlameShowParentCommit() const { return m_gitBlameShowParentCommit; }
240 void SetGitBlameDlgMainSashPos(int MainSashPos) { this->m_gitBlameDlgMainSashPos = MainSashPos; }
241 void SetGitBlameDlgHSashPos(int HSashPos) { this->m_gitBlameDlgHSashPos = HSashPos; }
242 void SetGitBlameDlgVSashPos(int VSashPos) { this->m_gitBlameDlgVSashPos = VSashPos; }
243 int GetGitBlameDlgMainSashPos() const { return m_gitBlameDlgMainSashPos; }
244 int GetGitBlameDlgHSashPos() const { return m_gitBlameDlgHSashPos; }
245 int GetGitBlameDlgVSashPos() const { return m_gitBlameDlgVSashPos; }
246
247 GitCommandsEntries& GetGitCommandsEntries(const wxString& entryName);
248
249 void AddGitCommandsEntry(GitCommandsEntries& entries, const wxString& entryName);
250 void DeleteGitCommandsEntry(const wxString& entryName) { m_commandsMap.erase(entryName); }
251
252 wxString GetProjectUserEnteredRepoPath(const wxString& nameHash);
253 void SetProjectUserEnteredRepoPath(const wxString& userEnteredRepoPath, const wxString& nameHash);
254
255 virtual void FromJSON(const JSONItem& json);
256 virtual JSONItem ToJSON() const;
257
258 bool IsShowBlameInfoInStatusBar() const { return m_flags & Git_Show_Commit_Info; }
259 };
260 #endif