Get rid of magic numbers
[TortoiseGit.git] / src / TortoiseShell / ShellExt.h
blob62326849d943474890416e864f15ed63a039c34f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2018 - TortoiseGit
4 // Copyright (C) 2003-2012, 2014 - 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
22 #include "Globals.h"
23 #include "registry.h"
24 #include "resource.h"
25 #include "ShellCache.h"
26 #include "RemoteCacheLink.h"
27 #include "GitStatus.h"
28 #include "GitFolderStatus.h"
29 #include "IconBitmapUtils.h"
30 #include "MenuInfo.h"
32 extern volatile LONG g_cRefThisDll; // Reference count of this DLL.
33 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
34 extern ShellCache g_ShellCache; // caching of registry entries, ...
35 extern DWORD g_langid;
36 extern ULONGLONG g_langTimeout;
37 extern HINSTANCE g_hResInst;
38 extern std::wstring g_filepath;
39 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
40 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
41 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
43 extern bool g_normalovlloaded;
44 extern bool g_modifiedovlloaded;
45 extern bool g_conflictedovlloaded;
46 extern bool g_readonlyovlloaded;
47 extern bool g_deletedovlloaded;
48 extern bool g_lockedovlloaded;
49 extern bool g_addedovlloaded;
50 extern bool g_ignoredovlloaded;
51 extern bool g_unversionedovlloaded;
52 extern LPCTSTR g_MenuIDString;
54 extern void LoadLangDll();
55 extern CComCriticalSection g_csGlobalCOMGuard;
56 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
58 // The actual OLE Shell context menu handler
59 /**
60 * \ingroup TortoiseShell
61 * The main class of our COM object / Shell Extension.
62 * It contains all Interfaces we implement for the shell to use.
63 * \remark The implementations of the different interfaces are
64 * split into several *.cpp files to keep them in a reasonable size.
66 class CShellExt : public IContextMenu3,
67 IPersistFile,
68 IShellExtInit,
69 IShellIconOverlayIdentifier,
70 IShellPropSheetExt,
71 ICopyHookW
74 protected:
76 FileState m_State;
77 volatile ULONG m_cRef;
78 //std::map<int,std::string> verbMap;
79 std::map<UINT_PTR, UINT_PTR> myIDMap;
80 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
81 std::map<std::wstring, UINT_PTR> myVerbsMap;
82 std::map<UINT_PTR, std::wstring> myVerbsIDMap;
83 std::wstring folder_;
84 std::vector<std::wstring> files_;
85 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
86 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
87 std::wstring uuidSource;
88 std::wstring uuidTarget;
89 int space;
90 TCHAR stringtablebuffer[255];
91 std::wstring ignoredprops;
92 CRegStdString regDiffLater;
94 GitFolderStatus m_CachedStatus; // status cache
95 CRemoteCacheLink m_remoteCacheLink;
96 IconBitmapUtils m_iconBitmapUtils;
98 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(L"Software\\TortoiseGit\\LanguageID", MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
99 private:
100 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
101 bool InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
102 std::wstring WriteFileListToTempFile();
103 bool WriteClipboardPathsToTempFile(std::wstring& tempfile);
104 LPCTSTR GetMenuTextFromResource(int id);
105 bool ShouldInsertItem(const MenuInfo& pair) const;
106 bool ShouldEnableMenu(const YesNoPair& pair) const;
107 void TweakMenu(HMENU menu);
108 void AddPathCommand(tstring& gitCmd, LPCTSTR command, bool bFilesAllowed);
109 void AddPathFileCommand(tstring& gitCmd, LPCTSTR command);
110 void AddPathFileDropCommand(tstring& gitCmd, LPCTSTR command);
111 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
112 bool IsIllegalFolder(const std::wstring& folder, int* cslidarray);
113 static void RunCommand(const tstring& path, const tstring& command, LPCTSTR errorMessage);
115 public:
116 CShellExt(FileState state);
117 virtual ~CShellExt();
119 /** \name IUnknown
120 * IUnknown members
122 //@{
123 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *) override;
124 STDMETHODIMP_(ULONG) AddRef() override;
125 STDMETHODIMP_(ULONG) Release() override;
126 //@}
128 /** \name IContextMenu2
129 * IContextMenu2 members
131 //@{
132 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override;
133 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) override;
134 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax) override;
135 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
136 //@}
138 /** \name IContextMenu3
139 * IContextMenu3 members
141 //@{
142 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult) override;
143 //@}
145 /** \name IShellExtInit
146 * IShellExtInit methods
148 //@{
149 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID) override;
150 //@}
152 /** \name IPersistFile
153 * IPersistFile methods
155 //@{
156 STDMETHODIMP GetClassID(CLSID *pclsid) override;
157 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode) override;
158 STDMETHODIMP IsDirty(void) override { return S_OK; };
159 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) override { return S_OK; };
160 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) override { return S_OK; };
161 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) override { return S_OK; };
162 //@}
164 /** \name IShellIconOverlayIdentifier
165 * IShellIconOverlayIdentifier methods
167 //@{
168 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags) override;
169 STDMETHODIMP GetPriority(int *pPriority) override;
170 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib) override;
171 //@}
173 /** \name IShellPropSheetExt
174 * IShellPropSheetExt methods
176 //@{
177 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam) override;
178 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM) override;
179 //@}
181 /** \name ICopyHook
182 * ICopyHook members
184 //@{
185 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs) override;
186 //@}