Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9.3, 2.0, and 2.0.1

stable cmenu: Changes to CShellExtCMenu to support subclass that creates similar menus

Changeset 7b0b3f373832

Parent 6cd590e11b58

by Daniel Atallah

Changes to 2 files · Browse files at 7b0b3f373832 Showing diff from parent 6cd590e11b58 Diff from another changeset...

 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
33
34
35
 
110
111
112
113
 
114
115
116
 
120
121
122
123
 
124
125
126
127
128
129
130
 
131
132
133
134
135
136
137
138
139
140
141
 
 
142
143
144
 
145
146
147
 
148
149
150
 
183
184
185
 
 
 
 
186
187
 
188
189
 
 
190
191
192
193
194
195
196
197
 
198
199
200
 
208
209
210
211
 
212
 
213
214
215
 
314
315
316
317
 
318
319
320
321
322
 
 
 
 
 
323
324
325
326
327
 
328
329
 
330
331
332
 
442
443
444
445
 
446
447
448
 
883
884
885
886
887
888
 
889
890
891
892
893
894
 
923
924
925
 
 
 
 
 
 
 
 
926
927
928
 
984
985
986
987
988
 
989
990
991
 
12
13
14
 
 
15
16
 
 
 
 
 
 
 
 
 
 
17
18
19
 
20
21
22
23
 
98
99
100
 
101
102
103
104
 
108
109
110
 
111
112
113
114
115
116
117
 
118
119
120
121
122
123
124
 
125
126
 
 
127
128
129
 
 
130
131
132
 
133
134
135
136
 
169
170
171
172
173
174
175
176
 
177
178
 
179
180
181
182
183
184
 
185
186
 
187
188
189
190
 
198
199
200
 
201
202
203
204
205
206
 
305
306
307
 
308
309
310
311
 
 
312
313
314
315
316
317
318
319
320
321
322
323
 
324
325
326
327
 
437
438
439
 
440
441
442
443
 
878
879
880
 
 
 
881
882
 
 
883
884
885
 
914
915
916
917
918
919
920
921
922
923
924
925
926
927
 
983
984
985
 
 
986
987
988
989
@@ -12,24 +12,12 @@
   #include "Msi.h"   -#include <map> -  #include "CShellExtCMenu.h"   - -struct MenuDescription -{ - std::string name; - std::wstring menuText; - std::wstring helpText; - std::string iconName; - UINT idCmd; -}; -  // According to http://msdn.microsoft.com/en-us/library/bb776094%28VS.85%29.aspx  // the help texts for the commands should be reasonably short (under 40 characters)   -MenuDescription menuDescList[] = +static MenuDescription CMenuMenuDescList[] =  {   {"commit", L"Commit...",   L"Commit changes in repository", @@ -110,7 +98,7 @@
  //{"", L"", L"", ".ico", 0},  };   -const char* const RepoNoFilesMenu = +static const char* const RepoNoFilesMenu =   "commit status shelve vdiff sep"   " add revert rename forget remove sep"   " workbench update grep sep" @@ -120,31 +108,29 @@
  " about"  ;   -const char* const RepoFilesMenu = +static const char* const RepoFilesMenu =   "commit status vdiff sep"   " add revert rename forget remove sep"   " log sep"   " about"  ;   -const char* const NoRepoMenu = +static const char* const NoRepoMenu =   "clone init shellconf userconf thgstatus sep"   " workbench sep"   " about"  ;     -typedef std::map<std::string, MenuDescription> MenuDescriptionMap;  typedef std::map<UINT, MenuDescription> MenuIdCmdMap;   -MenuDescriptionMap MenuDescMap; -MenuIdCmdMap MenuIdMap; +static MenuDescriptionMap CMenuMenuDescMap; +static MenuIdCmdMap MenuIdMap;   - -void AddMenuList(UINT idCmd, const std::string& name) +void AddMenuList(UINT idCmd, const std::string& name, MenuDescriptionMap& menuDescMap)  {   TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name); - MenuIdMap[idCmd] = MenuDescMap[name]; + MenuIdMap[idCmd] = menuDescMap[name];  }     @@ -183,18 +169,22 @@
  RegCloseKey(hkey);  }   +MenuDescriptionMap& CShellExtCMenu::GetMenuDescriptionMap() +{ + return CMenuMenuDescMap; +}   -void InitMenuMaps() +void CShellExtCMenu::InitMenuMaps(MenuDescription *menuDescs, std::size_t sz)  { - if (MenuDescMap.empty()) + MenuDescriptionMap& menuDescMap = GetMenuDescriptionMap(); + if (menuDescMap.empty())   {   std::string lang;   GetRegistryConfig("CMenuLang", lang);   - std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription);   for (std::size_t i = 0; i < sz; i++)   { - MenuDescription md = menuDescList[i]; + MenuDescription md = menuDescs[i];     if (md.name.empty())   { @@ -208,8 +198,9 @@
  if (!lang.empty())   GetCMenuTranslation(lang, md.name, md.menuText, md.helpText);   - MenuDescMap[md.name] = md; + menuDescMap[md.name] = md;   } +   }     MenuIdMap.clear(); @@ -314,19 +305,23 @@
 }     -void InsertMenuItemByName( +void CShellExtCMenu::InsertMenuItemByName(   HMENU hMenu, const std::string& name, UINT indexMenu,   UINT idCmd, UINT idCmdFirst, const std::wstring& prefix)  { - MenuDescriptionMap::iterator iter = MenuDescMap.find(name); - if (iter == MenuDescMap.end()) + + MenuDescriptionMap& menuDescMap = GetMenuDescriptionMap(); + + MenuDescriptionMap::iterator iter = menuDescMap.find(name); + if (iter == menuDescMap.end())   {   TDEBUG_TRACE("***** InsertMenuItemByName: can't find menu info for " << name);   return;   }   +   MenuDescription md = iter->second; - AddMenuList(idCmd - idCmdFirst, name); + AddMenuList(idCmd - idCmdFirst, name, menuDescMap);   InsertMenuItemWithIcon1(   hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);  } @@ -442,7 +437,7 @@
  return S_OK;   }   - InitMenuMaps(); + InitMenuMaps(CMenuMenuDescList, sizeof(CMenuMenuDescList) / sizeof(MenuDescription));     typedef std::vector<std::string> entriesT;   typedef entriesT::const_iterator entriesIter; @@ -883,12 +878,8 @@
  InitStatus::check();  }   - -STDMETHODIMP CShellExtCMenu::Initialize( - LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) +void CShellExtCMenu::PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj)  { - TCHAR name[MAX_PATH+1]; -   TDEBUG_TRACE("CShellExtCMenu::Initialize");     // get installed MSI product id (for debugging purposes for now) @@ -923,6 +914,14 @@
    TDEBUG_TRACE(" pIDFolder: " << pIDFolder);   TDEBUG_TRACE(" pDataObj: " << pDataObj); +} + +STDMETHODIMP CShellExtCMenu::Initialize( + LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) +{ + TCHAR name[MAX_PATH+1]; + + PrintDebugHeader(pIDFolder, pDataObj);     myFolder.clear();   myFiles.clear(); @@ -984,8 +983,7 @@
 }     -CShellExtCMenu::CShellExtCMenu(char dummy) : - m_ppszFileUserClickedOn(0) +CShellExtCMenu::CShellExtCMenu(const char dummy)  {   m_cRef = 0L;   CShellExt::IncDllRef();
 
3
4
5
 
6
 
 
 
 
 
 
 
 
 
 
7
8
9
 
 
10
11
12
13
14
15
16
 
 
 
17
 
 
 
 
 
18
19
20
 
21
22
23
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
 
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
41
@@ -3,21 +3,39 @@
   #include <vector>  #include <string> +#include <map>   +struct MenuDescription +{ + std::string name; + std::wstring menuText; + std::wstring helpText; + std::string iconName; + UINT idCmd; +}; + +typedef std::map<std::string, MenuDescription> MenuDescriptionMap;    class CShellExtCMenu: public IContextMenu3, IShellExtInit  { + +protected:   ULONG m_cRef; - - LPTSTR* m_ppszFileUserClickedOn; // [MAX_PATH]   std::vector<std::string> myFiles;   std::string myFolder;   - void RunDialog(const std::string&); + virtual void RunDialog(const std::string&); + virtual MenuDescriptionMap& GetMenuDescriptionMap(); +   void TweakMenuForVista(HMENU menu); + void PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj); + void InitMenuMaps(MenuDescription *menuDescs, std::size_t sz); + void InsertMenuItemByName( + HMENU hMenu, const std::string& name, UINT indexMenu, + UINT idCmd, UINT idCmdFirst, const std::wstring& prefix);    public: - explicit CShellExtCMenu(char dummy); + explicit CShellExtCMenu(const char dummy);   ~CShellExtCMenu();     // IUnknown