Use static method
[TortoiseGit.git] / src / TortoiseProc / Commands / Command.cpp
blob3e989ad1c5f021afee143875222969fc49a8ba0b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program 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.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "Command.h"
23 #include "AboutCommand.h"
24 #include "CommitCommand.h"
25 #include "LogCommand.h"
27 #include "CreateRepositoryCommand.h"
28 #include "CloneCommand.h"
29 #include "PrevDiffCommand.h"
30 #include "DiffCommand.h"
32 #include "RenameCommand.h"
33 #include "RepoStatusCommand.h"
35 #include "RevertCommand.h"
36 #include "RemoveCommand.h"
37 #include "PullCommand.h"
38 #include "FetchCommand.h"
39 #include "PushCommand.h"
40 #include "BranchCommand.h"
41 #include "TagCommand.h"
42 #include "MergeCommand.h"
43 #include "SwitchCommand.h"
44 #include "ExportCommand.h"
45 #include "AddCommand.h"
46 #include "IgnoreCommand.h"
47 #include "FormatPatchCommand.h"
48 #include "ImportPatchCommand.h"
49 #include "BlameCommand.h"
50 #include "SettingsCommand.h"
51 #include "ConflictEditorCommand.h"
52 #include "CleanupCommand.h"
53 #include "RebaseCommand.h"
54 #include "ResolveCommand.h"
55 #include "DropMoveCommand.h"
56 #include "DropCopyAddCommand.h"
57 #include "DropCopyCommand.h"
58 #include "HelpCommand.h"
59 #include "StashCommand.h"
60 #include "SubmoduleCommand.h"
61 #include "ReflogCommand.h"
62 #include "SendMailCommand.h"
63 #include "CatCommand.h"
64 #include "RefBrowseCommand.h"
65 #include "SVNDCommitCommand.h"
66 #include "SVNRebaseCommand.h"
67 #include "SVNFetchCommand.h"
68 #include "SyncCommand.h"
69 #include "RequestPullCommand.h"
70 #include "UpdateCheckCommand.h"
71 #include "PasteCopyCommand.h"
72 #include "PasteMoveCommand.h"
73 #include "SVNIgnoreCommand.h"
74 #include "BisectCommand.h"
75 #include "RepositoryBrowserCommand.h"
76 #include "RevisiongraphCommand.h"
77 #include "ShowCompareCommand.h"
79 #if 0
82 #include "CopyCommand.h"
83 #include "CrashCommand.h"
89 #include "PropertiesCommand.h"
90 #include "RebuildIconCacheCommand.h"
91 #include "RemoveCommand.h"
95 #include "RevertCommand.h"
96 #include "RTFMCommand.h"
98 #include "UnIgnoreCommand.h"
100 #endif
101 typedef enum
103 cmdAbout,
104 cmdAdd,
105 cmdBlame,
106 cmdBranch,
107 cmdCat,
108 cmdCleanup,
109 cmdClone,
110 cmdCommit,
111 cmdConflictEditor,
112 cmdCopy,
113 cmdCrash,
114 cmdDiff,
115 cmdDropCopy,
116 cmdDropCopyAdd,
117 cmdDropMove,
118 cmdFetch,
119 cmdFormatPatch,
120 cmdExport,
121 cmdHelp,
122 cmdIgnore,
123 cmdImportPatch,
124 cmdLog,
125 cmdMerge,
126 cmdPasteCopy,
127 cmdPasteMove,
128 cmdPrevDiff,
129 cmdProperties,
130 cmdPull,
131 cmdPush,
132 cmdRTFM,
133 cmdRebuildIconCache,
134 cmdRemove,
135 cmdRebase,
136 cmdRename,
137 cmdRepoCreate,
138 cmdRepoStatus,
139 cmdResolve,
140 cmdRevert,
141 cmdSendMail,
142 cmdSettings,
143 cmdShowCompare,
144 cmdSwitch,
145 cmdTag,
146 cmdUnIgnore,
147 cmdUpdateCheck,
148 cmdStashSave,
149 cmdStashApply,
150 cmdStashPop,
151 cmdStashList,
152 cmdSubAdd,
153 cmdSubUpdate,
154 cmdSubSync,
155 cmdRefLog,
156 cmdRefBrowse,
157 cmdSVNDCommit,
158 cmdSVNRebase,
159 cmdSVNFetch,
160 cmdSVNIgnore,
161 cmdSync,
162 cmdRequestPull,
163 cmdBisect,
164 cmdRepoBrowser,
165 cmdRevisionGraph,
166 } TGitCommand;
168 static const struct CommandInfo
170 TGitCommand command;
171 LPCTSTR pCommandName;
172 } commandInfo[] =
174 { cmdAbout, _T("about") },
175 { cmdAdd, _T("add") },
176 { cmdBlame, _T("blame") },
177 { cmdBranch, _T("branch") },
178 { cmdCat, _T("cat") },
179 { cmdCleanup, _T("cleanup") },
180 { cmdClone, _T("clone") },
181 { cmdCommit, _T("commit") },
182 { cmdConflictEditor, _T("conflicteditor") },
183 { cmdCopy, _T("copy") },
184 { cmdCrash, _T("crash") },
185 { cmdDiff, _T("diff") },
186 { cmdDropCopy, _T("dropcopy") },
187 { cmdDropCopyAdd, _T("dropcopyadd") },
188 { cmdDropMove, _T("dropmove") },
189 { cmdFetch, _T("fetch") },
190 { cmdFormatPatch, _T("formatpatch") },
191 { cmdExport, _T("export") },
192 { cmdHelp, _T("help") },
193 { cmdIgnore, _T("ignore") },
194 { cmdImportPatch, _T("importpatch") },
195 { cmdLog, _T("log") },
196 { cmdMerge, _T("merge") },
197 { cmdPasteCopy, _T("pastecopy") },
198 { cmdPasteMove, _T("pastemove") },
199 { cmdPrevDiff, _T("prevdiff") },
200 { cmdProperties, _T("properties") },
201 { cmdPull, _T("pull") },
202 { cmdPush, _T("push") },
203 { cmdRTFM, _T("rtfm") },
204 { cmdRebuildIconCache,_T("rebuildiconcache") },
205 { cmdRemove, _T("remove") },
206 { cmdRebase, _T("rebase") },
207 { cmdRename, _T("rename") },
208 { cmdRepoCreate, _T("repocreate") },
209 { cmdRepoStatus, _T("repostatus") },
210 { cmdResolve, _T("resolve") },
211 { cmdRevert, _T("revert") },
212 { cmdSendMail, _T("sendmail") },
213 { cmdSettings, _T("settings") },
214 { cmdShowCompare, _T("showcompare") },
215 { cmdSwitch, _T("switch") },
216 { cmdTag, _T("tag") },
217 { cmdUnIgnore, _T("unignore") },
218 { cmdUpdateCheck, _T("updatecheck") },
219 { cmdStashSave, _T("stashsave") },
220 { cmdStashApply, _T("stashapply") },
221 { cmdStashPop, _T("stashpop") },
222 { cmdStashList, _T("stashlist") },
223 { cmdSubAdd, _T("subadd") },
224 { cmdSubUpdate, _T("subupdate") },
225 { cmdSubSync, _T("subsync") },
226 { cmdRefLog, _T("reflog") },
227 { cmdRefBrowse, _T("refbrowse") },
228 { cmdSVNDCommit, _T("svndcommit") },
229 { cmdSVNRebase, _T("svnrebase") },
230 { cmdSVNFetch, _T("svnfetch") },
231 { cmdSVNIgnore, _T("svnignore") },
232 { cmdSync, _T("sync") },
233 { cmdRequestPull, _T("requestpull") },
234 { cmdBisect, _T("bisect") },
235 { cmdRepoBrowser, _T("repobrowser") },
236 { cmdRevisionGraph, _T("revisiongraph") },
240 Command * CommandServer::GetCommand(const CString& sCmd)
242 // Look up the command
243 TGitCommand command = cmdAbout; // Something harmless as a default
244 for (int nCommand = 0; nCommand < _countof(commandInfo); ++nCommand)
246 if (sCmd.Compare(commandInfo[nCommand].pCommandName) == 0)
248 // We've found the command
249 command = commandInfo[nCommand].command;
250 // If this fires, you've let the enum get out of sync with the commandInfo array
251 ASSERT((int)command == nCommand);
252 break;
256 // CBrowseRefsDlg dialog
257 switch (command)
259 case cmdAbout:
260 return new AboutCommand;
261 case cmdCommit:
262 return new CommitCommand;
263 case cmdLog:
264 return new LogCommand;
265 case cmdRepoCreate:
266 return new CreateRepositoryCommand;
267 case cmdClone:
268 return new CloneCommand;
269 case cmdPrevDiff:
270 return new PrevDiffCommand;
271 case cmdDiff:
272 return new DiffCommand;
273 case cmdRename:
274 return new RenameCommand;
275 case cmdRepoStatus:
276 return new RepoStatusCommand;
277 case cmdRemove:
278 return new RemoveCommand;
279 case cmdRevert:
280 return new RevertCommand;
281 case cmdPull:
282 return new PullCommand;
283 case cmdFetch:
284 return new FetchCommand;
285 case cmdPush:
286 return new PushCommand;
287 case cmdBranch:
288 return new BranchCommand;
289 case cmdTag:
290 return new TagCommand;
291 case cmdMerge:
292 return new MergeCommand;
293 case cmdSwitch:
294 return new SwitchCommand;
295 case cmdExport:
296 return new ExportCommand;
297 case cmdAdd:
298 return new AddCommand;
299 case cmdIgnore:
300 return new IgnoreCommand;
301 case cmdFormatPatch:
302 return new FormatPatchCommand;
303 case cmdImportPatch:
304 return new ImportPatchCommand;
305 case cmdBlame:
306 return new BlameCommand;
307 case cmdSettings:
308 return new SettingsCommand;
309 case cmdConflictEditor:
310 return new ConflictEditorCommand;
311 case cmdCleanup:
312 return new CleanupCommand;
313 case cmdRebase:
314 return new RebaseCommand;
315 case cmdResolve:
316 return new ResolveCommand;
317 case cmdDropMove:
318 return new DropMoveCommand;
319 case cmdDropCopy:
320 return new DropCopyCommand;
321 case cmdDropCopyAdd:
322 return new DropCopyAddCommand;
323 case cmdHelp:
324 return new HelpCommand;
325 case cmdStashSave:
326 return new StashSaveCommand;
327 case cmdStashApply:
328 return new StashApplyCommand;
329 case cmdStashPop:
330 return new StashPopCommand;
331 case cmdSubAdd:
332 return new SubmoduleAddCommand;
333 case cmdSubUpdate:
334 return new SubmoduleUpdateCommand;
335 case cmdRefLog:
336 return new RefLogCommand;
337 case cmdSubSync:
338 return new SubmoduleSyncCommand;
339 case cmdSendMail:
340 return new SendMailCommand;
341 case cmdCat:
342 return new CatCommand;
343 case cmdRefBrowse:
344 return new RefBrowseCommand;
345 case cmdSVNDCommit:
346 return new SVNDCommitCommand;
347 case cmdSVNRebase:
348 return new SVNRebaseCommand;
349 case cmdSVNFetch:
350 return new SVNFetchCommand;
351 case cmdSync:
352 return new SyncCommand;
353 case cmdRequestPull:
354 return new RequestPullCommand;
355 case cmdUpdateCheck:
356 return new UpdateCheckCommand;
357 case cmdPasteCopy:
358 return new PasteCopyCommand;
359 case cmdPasteMove:
360 return new PasteMoveCommand;
361 case cmdSVNIgnore:
362 return new SVNIgnoreCommand;
363 case cmdBisect:
364 return new BisectCommand;
365 case cmdRepoBrowser:
366 return new RepositoryBrowserCommand;
367 case cmdRevisionGraph:
368 return new RevisionGraphCommand;
369 case cmdShowCompare:
370 return new ShowCompareCommand;
372 #if 0
376 case cmdCopy:
377 return new CopyCommand;
378 case cmdCrash:
379 return new CrashCommand;
383 case cmdPrevDiff:
384 return new PrevDiffCommand;
385 case cmdProperties:
386 return new PropertiesCommand;
387 case cmdRTFM:
388 return new RTFMCommand;
389 case cmdRebuildIconCache:
390 return new RebuildIconCacheCommand;
391 case cmdUnIgnore:
392 return new UnIgnoreCommand;
393 #endif
394 default:
395 CMessageBox::Show(hWndExplorer, _T("Command not implemented"), _T("TortoiseGit"), MB_ICONERROR);
396 return new AboutCommand;