Randomize Sync Dialog startup position
[TortoiseGit.git] / src / TortoiseShell / ShellExt.h
blobaa78cf27f5c7d18f4c9d4b395c075b81d7d95b3a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #include "Globals.h"
22 #include "registry.h"
23 #include "resource.h"
24 #include "ShellCache.h"
25 #include "RemoteCacheLink.h"
26 #include "GitStatus.h"
27 #include "GitFolderStatus.h"
28 #include "IconBitmapUtils.h"
29 #include "MenuInfo.h"
30 #include "CrashReport.h"
31 #include "../version.h"
33 extern volatile LONG g_cRefThisDll; // Reference count of this DLL.
34 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
35 extern ShellCache g_ShellCache; // caching of registry entries, ...
36 extern DWORD g_langid;
37 extern DWORD g_langTimeout;
38 extern HINSTANCE g_hResInst;
39 extern stdstring g_filepath;
40 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
41 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
42 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
44 extern bool g_normalovlloaded;
45 extern bool g_modifiedovlloaded;
46 extern bool g_conflictedovlloaded;
47 extern bool g_readonlyovlloaded;
48 extern bool g_deletedovlloaded;
49 extern bool g_lockedovlloaded;
50 extern bool g_addedovlloaded;
51 extern bool g_ignoredovlloaded;
52 extern bool g_unversionedovlloaded;
53 extern LPCTSTR g_MenuIDString;
55 extern void LoadLangDll();
56 extern CComCriticalSection g_csGlobalCOMGuard;
57 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
59 // The actual OLE Shell context menu handler
60 /**
61 * \ingroup TortoiseShell
62 * The main class of our COM object / Shell Extension.
63 * It contains all Interfaces we implement for the shell to use.
64 * \remark The implementations of the different interfaces are
65 * split into several *.cpp files to keep them in a reasonable size.
67 class CShellExt : public IContextMenu3,
68 IPersistFile,
69 IColumnProvider,
70 IShellExtInit,
71 IShellIconOverlayIdentifier,
72 IShellPropSheetExt,
73 ICopyHookW
75 // COMPILER ERROR? You need the latest version of the
76 // platform SDK which has references to IColumnProvider
77 // in the header files. Download it here:
78 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
80 protected:
82 FileState m_State;
83 ULONG m_cRef;
84 //std::map<int,std::string> verbMap;
85 std::map<UINT_PTR, UINT_PTR> myIDMap;
86 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
87 std::map<stdstring, UINT_PTR> myVerbsMap;
88 std::map<UINT_PTR, stdstring> myVerbsIDMap;
89 stdstring folder_;
90 std::vector<stdstring> files_;
91 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
92 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
93 stdstring uuidSource;
94 stdstring uuidTarget;
95 int space;
96 TCHAR stringtablebuffer[255];
97 stdstring columnfilepath; ///< holds the last file/dir path for the column provider
98 stdstring columnauthor; ///< holds the corresponding author of the file/dir above
99 stdstring itemurl;
100 stdstring itemshorturl;
101 stdstring ignoredprops;
102 git_revnum_t columnrev; ///< holds the corresponding revision to the file/dir above
103 git_wc_status_kind filestatus;
105 GitFolderStatus m_CachedStatus; // status cache
106 CRemoteCacheLink m_remoteCacheLink;
107 IconBitmapUtils m_iconBitmapUtils;
109 #if ENABLE_CRASHHANLDER
110 CCrashReportTGit m_crasher;
111 #endif
113 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
114 private:
115 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
116 bool InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
117 stdstring WriteFileListToTempFile();
118 bool WriteClipboardPathsToTempFile(stdstring& tempfile);
119 LPCTSTR GetMenuTextFromResource(int id);
120 void GetColumnStatus(const TCHAR * path, BOOL bIsDir);
121 void GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci, UINT characterCount, UINT title, UINT description);
122 bool ShouldInsertItem(const MenuInfo& pair) const;
123 bool ShouldEnableMenu(const YesNoPair& pair) const;
124 void TweakMenu(HMENU menu);
125 void AddPathCommand(tstring& gitCmd, LPCTSTR command, bool bFilesAllowed);
126 void AddPathFileCommand(tstring& gitCmd, LPCTSTR command);
127 void AddPathFileDropCommand(tstring& gitCmd, LPCTSTR command);
128 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
129 bool IsIllegalFolder(std::wstring folder, int * cslidarray);
130 static void RunCommand(const tstring& path, const tstring& command, LPCTSTR errorMessage);
132 /** \name IContextMenu2 wrappers
133 * IContextMenu2 wrapper functions to catch exceptions and send crash reports
135 //@{
136 STDMETHODIMP QueryContextMenu_Wrap(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
137 STDMETHODIMP InvokeCommand_Wrap(LPCMINVOKECOMMANDINFO lpcmi);
138 STDMETHODIMP GetCommandString_Wrap(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
139 STDMETHODIMP HandleMenuMsg_Wrap(UINT uMsg, WPARAM wParam, LPARAM lParam);
140 //@}
142 /** \name IContextMenu3 wrappers
143 * IContextMenu3 wrapper functions to catch exceptions and send crash reports
145 //@{
146 STDMETHODIMP HandleMenuMsg2_Wrap(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
147 //@}
149 /** \name IColumnProvider wrappers
150 * IColumnProvider wrapper functions to catch exceptions and send crash reports
152 //@{
153 STDMETHODIMP GetColumnInfo_Wrap(DWORD dwIndex, SHCOLUMNINFO *psci);
154 STDMETHODIMP GetItemData_Wrap(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
155 STDMETHODIMP Initialize_Wrap(LPCSHCOLUMNINIT psci);
156 //@}
158 /** \name IShellExtInit wrappers
159 * IShellExtInit wrapper functions to catch exceptions and send crash reports
161 //@{
162 STDMETHODIMP Initialize_Wrap(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
163 //@}
165 /** \name IShellIconOverlayIdentifier wrappers
166 * IShellIconOverlayIdentifier wrapper functions to catch exceptions and send crash reports
168 //@{
169 STDMETHODIMP GetOverlayInfo_Wrap(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
170 STDMETHODIMP GetPriority_Wrap(int *pPriority);
171 STDMETHODIMP IsMemberOf_Wrap(LPCWSTR pwszPath, DWORD dwAttrib);
172 //@}
174 /** \name IShellPropSheetExt wrappers
175 * IShellPropSheetExt wrapper functions to catch exceptions and send crash reports
177 //@{
178 STDMETHODIMP AddPages_Wrap(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
179 //STDMETHODIMP ReplacePage_Wrap(UINT, LPFNADDPROPSHEETPAGE, LPARAM);
180 //@}
182 /** \name ICopyHook wrapper
183 * ICopyHook wrapper functions to catch exceptions and send crash reports
185 //@{
186 STDMETHODIMP_(UINT) CopyCallback_Wrap(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
187 //@}
189 public:
190 CShellExt(FileState state);
191 virtual ~CShellExt();
193 /** \name IUnknown
194 * IUnknown members
196 //@{
197 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
198 STDMETHODIMP_(ULONG) AddRef();
199 STDMETHODIMP_(ULONG) Release();
200 //@}
202 /** \name IContextMenu2
203 * IContextMenu2 members
205 //@{
206 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
207 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
208 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
209 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
210 //@}
212 /** \name IContextMenu3
213 * IContextMenu3 members
215 //@{
216 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
217 //@}
219 /** \name IColumnProvider
220 * IColumnProvider members
222 //@{
223 STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);
224 STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
225 STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci);
226 //@}
228 /** \name IShellExtInit
229 * IShellExtInit methods
231 //@{
232 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
233 //@}
235 /** \name IPersistFile
236 * IPersistFile methods
238 //@{
239 STDMETHODIMP GetClassID(CLSID *pclsid);
240 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
241 STDMETHODIMP IsDirty(void) { return S_OK; };
242 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };
243 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };
244 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };
245 //@}
247 /** \name IShellIconOverlayIdentifier
248 * IShellIconOverlayIdentifier methods
250 //@{
251 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
252 STDMETHODIMP GetPriority(int *pPriority);
253 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);
254 //@}
256 /** \name IShellPropSheetExt
257 * IShellPropSheetExt methods
259 //@{
260 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
261 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);
262 //@}
264 /** \name ICopyHook
265 * ICopyHook members
267 //@{
268 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
269 //@}