1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009, 2011, 2013-2014, 2016 - TortoiseGit
4 // Copyright (C) 2007 - 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.
21 #include "TortoiseProc.h"
22 #include "CmdLineParser.h"
29 * \ingroup TortoiseProc
30 * Interface for all command line commands TortoiseProc can execute.
36 * Executes the command.
38 virtual bool Execute() = 0;
40 // allow sub-classes to execute code during destruction
41 virtual ~Command() {};
43 void SetParser(const CCmdLineParser
& p
) {parser
= p
;}
44 void SetPaths(const CTGitPathList
& plist
, const CTGitPath
&path
)
46 orgCmdLinePath
= path
;
47 CString WinPath
=path
.GetWinPath();
48 if (CStringUtils::StartsWith(WinPath
, g_Git
.m_CurrentDir
))
50 if (g_Git
.m_CurrentDir
[g_Git
.m_CurrentDir
.GetLength() - 1] == L
'\\')
51 cmdLinePath
.SetFromWin( WinPath
.Right(WinPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()));
53 cmdLinePath
.SetFromWin( WinPath
.Right(WinPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()-1));
56 for (int i
= 0; i
< plist
.GetCount(); ++i
)
58 WinPath
=plist
[i
].GetWinPath();
60 if (CStringUtils::StartsWith(WinPath
, g_Git
.m_CurrentDir
))
62 if (g_Git
.m_CurrentDir
[g_Git
.m_CurrentDir
.GetLength() - 1] == L
'\\')
63 p
.SetFromWin( WinPath
.Right(WinPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()));
65 p
.SetFromWin( WinPath
.Right(WinPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()-1));
73 void SetExplorerHwnd(HWND hWnd
) {hwndExplorer
= hWnd
;}
75 CCmdLineParser parser
;
76 CTGitPathList pathList
;
77 CTGitPathList orgPathList
;
78 CTGitPath cmdLinePath
;
79 CTGitPath orgCmdLinePath
;
84 * \ingroup TortoiseProc
85 * Factory for the different commands which TortoiseProc executes from the
92 Command
* GetCommand(const CString
& sCmd
);