Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseProc / Commands / Command.h
blob948cb1b1d5f50c802099defd6de00157f44e6a07
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.
20 #pragma once
21 #include "TortoiseProc.h"
22 #include "CmdLineParser.h"
23 #include "TGitPath.h"
24 #include "Git.h"
28 /**
29 * \ingroup TortoiseProc
30 * Interface for all command line commands TortoiseProc can execute.
32 class Command
34 public:
35 /**
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()));
52 else
53 cmdLinePath.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1));
55 orgPathList = plist;
56 for (int i = 0; i < plist.GetCount(); ++i)
58 WinPath=plist[i].GetWinPath();
59 CTGitPath p;
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()));
64 else
65 p.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1));
67 else
68 p=plist[i];
69 pathList.AddPath(p);
73 void SetExplorerHwnd(HWND hWnd) {hwndExplorer = hWnd;}
74 protected:
75 CCmdLineParser parser;
76 CTGitPathList pathList;
77 CTGitPathList orgPathList;
78 CTGitPath cmdLinePath;
79 CTGitPath orgCmdLinePath;
80 HWND hwndExplorer;
83 /**
84 * \ingroup TortoiseProc
85 * Factory for the different commands which TortoiseProc executes from the
86 * command line.
88 class CommandServer
90 public:
92 Command * GetCommand(const CString& sCmd);