Do not pass big read-only parameters per value
[TortoiseGit.git] / src / TortoiseProc / Commands / Command.h
bloba2234fb572e46b2e07f3b359bc4e3380a9c34306
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2011,2013 - 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 void SetParser(const CCmdLineParser& p) {parser = p;}
41 void SetPaths(const CTGitPathList& plist, const CTGitPath &path)
43 orgCmdLinePath = path;
44 CString WinPath=path.GetWinPath();
45 if(WinPath.Left(g_Git.m_CurrentDir.GetLength())==g_Git.m_CurrentDir)
47 if(g_Git.m_CurrentDir[g_Git.m_CurrentDir.GetLength()-1] == _T('\\'))
49 cmdLinePath.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()));
51 else
53 cmdLinePath.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1));
56 orgPathList = plist;
57 for (int i = 0; i < plist.GetCount(); ++i)
59 WinPath=plist[i].GetWinPath();
60 CTGitPath p;
61 if(WinPath.Left(g_Git.m_CurrentDir.GetLength())==g_Git.m_CurrentDir)
63 if(g_Git.m_CurrentDir[g_Git.m_CurrentDir.GetLength()-1] == _T('\\'))
65 p.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()));
67 else
69 p.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1));
72 else
73 p=plist[i];
74 pathList.AddPath(p);
78 void SetExplorerHwnd(HWND hWnd) {hwndExplorer = hWnd;}
79 protected:
80 CCmdLineParser parser;
81 CTGitPathList pathList;
82 CTGitPathList orgPathList;
83 CTGitPath cmdLinePath;
84 CTGitPath orgCmdLinePath;
85 HWND hwndExplorer;
88 /**
89 * \ingroup TortoiseProc
90 * Factory for the different commands which TortoiseProc executes from the
91 * command line.
93 class CommandServer
95 public:
97 Command * GetCommand(const CString& sCmd);