Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

cmenu: make items promoteable via settings dialog

Changeset 2f2b788a4d80

Parent b2952bb0498d

by Steve Borho

Changes to one file · Browse files at 2f2b788a4d80 Showing diff from parent b2952bb0498d Diff from another changeset...

 
68
69
70
 
 
71
72
73
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
76
77
 
96
97
98
99
 
100
101
102
 
190
191
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
194
195
196
197
 
201
202
203
 
204
205
206
 
 
 
 
 
 
 
 
 
 
 
207
208
209
 
210
211
212
213
214
 
 
 
 
 
 
 
215
216
217
218
219
220
 
221
222
223
224
225
 
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
 
 
 
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
 
294
295
296
297
298
299
300
301
 
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
127
128
129
 
130
131
132
133
 
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
 
261
262
263
 
267
268
269
270
271
272
 
273
274
275
276
277
278
279
280
281
282
283
284
 
 
285
286
 
 
 
 
287
288
289
290
291
292
293
294
295
296
297
298
 
299
300
 
 
 
 
301
302
 
 
 
 
 
 
 
 
 
 
303
304
 
 
 
 
 
 
305
306
307
308
 
309
 
 
 
 
 
 
 
 
 
 
310
311
312
 
346
347
348
 
 
349
350
351
@@ -68,10 +68,41 @@
  "Show About Dialog",   "menuabout.ico", 0},   + /* Add new items here */ +   // template   {"", "", "", ".ico", 0},  };   +/* These enumerations must match the order of menuDescList */ +enum menuDescListEntries { + Commit, Init, Clone, Status, Shelve, Add, Revert, Remove, Rename, + Log, Synch, Serve, Update, Recover, Thgstatus, Userconf, Repoconf, + About, + /* Add new items here */ + Separator, EndOfList +}; + +menuDescListEntries RepoNoFilesMenu[] = { + Commit, Status, Shelve, Separator, + Log, Separator, + Update, Separator, + Synch, Clone, Recover, Serve, Thgstatus, Separator, + Repoconf, Userconf, Separator, + About, EndOfList +}; + +menuDescListEntries RepoFilesMenu[] = { + Commit, Log, Add, Revert, Rename, Remove, Separator, + Repoconf, Userconf, Separator, + About, EndOfList +}; + +menuDescListEntries NoRepoMenu[] = { + Clone, Init, Userconf, Separator, + About, EndOfList +}; +  typedef std::map<std::string, MenuDescription> MenuDescriptionMap;  typedef std::map<int, MenuDescription> MenuIdCmdMap;   @@ -96,7 +127,7 @@
  MenuDescMap[md.name] = md;   }   } - +   MenuIdMap.clear();  }   @@ -190,8 +221,43 @@
  if (!bAppendItems)   return NOERROR;   + int sz = sizeof(menuDescList) / sizeof(MenuDescription); + bool promoted[ sz ]; + memset(&promoted, 0, sizeof(promoted)); + + std::string cval; + if (GetRegistryConfig("PromotedItems", cval) != 0 && cval == "0") + return S_FALSE; + + size_t found; + do + { + if( cval.empty() ) + break; + + found = cval.find_first_of(','); + + std::string key; + if( found == std::string::npos ) + key = cval; + else + { + key = cval.substr(0, found); + cval = cval.substr(found+1); + } + + for( UINT i = 0 ; i < sz ; i++ ) + { + if( !key.compare(menuDescList[i].name) ) + { + promoted[i] = true; + break; + } + } + } + while (found != std::string::npos); +   // check if target directory is a Mercurial repository - bool isHgrepo = false;   std::string cwd;   if (!myFolder.empty())   { @@ -201,60 +267,46 @@
  {   cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]);   } + bool isHgrepo = false;   if (!cwd.empty())   isHgrepo = IsHgRepo(cwd); - + + /* We have three menu types: files-selected, no-files-selected, no-repo */ + menuDescListEntries *entries; + if (isHgrepo) + if (myFiles.empty()) + entries = RepoNoFilesMenu; + else + entries = RepoFilesMenu; + else + entries = NoRepoMenu; +   // start building TortoiseHg menus and submenus - InsertMenu(hMenu, indexMenu, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - indexMenu++; + InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);   - if (isHgrepo) - InsertMenuItemByName(hMenu, "commit", indexMenu++, idCmd++, idCmdFirst); - - TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding sub menus"); + menuDescListEntries *walk; + for( walk = entries ; *walk != EndOfList ; walk++ ) + { + UINT idx = (UINT) *walk; + if( promoted[idx] ) + InsertMenuItemByName(hMenu, menuDescList[idx].name, indexMenu++, idCmd++, idCmdFirst); + }     HMENU hSubMenu = CreatePopupMenu();   if (hSubMenu)   {   int indexSubMenu = 0; - if (isHgrepo) + for( walk = entries ; *walk != EndOfList ; walk++ )   { - if (myFiles.empty()) - { - InsertMenuItemByName(hSubMenu, "status", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "shelve", indexSubMenu++, idCmd++, idCmdFirst); + if( *walk == Separator )   InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - InsertMenuItemByName(hSubMenu, "log", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - InsertMenuItemByName(hSubMenu, "update", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - InsertMenuItemByName(hSubMenu, "synch", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "recover", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "serve", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "thgstatus", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - }   else   { - InsertMenuItemByName(hSubMenu, "log", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "add", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "revert", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "rename", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenuItemByName(hSubMenu, "remove", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); + UINT idx = (UINT) *walk; + if( !promoted[idx] ) + InsertMenuItemByName(hSubMenu, menuDescList[idx].name, indexSubMenu++, idCmd++, idCmdFirst);   } - InsertMenuItemByName(hSubMenu, "repoconf", indexSubMenu++, idCmd++, idCmdFirst);   } - else - { - InsertMenuItemByName(hSubMenu, "init", indexSubMenu++, idCmd++, idCmdFirst); - } - - InsertMenuItemByName(hSubMenu, "userconf", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - InsertMenuItemByName(hSubMenu, "clone", indexSubMenu++, idCmd++, idCmdFirst); - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); - InsertMenuItemByName(hSubMenu, "about", indexSubMenu++, idCmd++, idCmdFirst);   }     TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding main THG menu"); @@ -294,8 +346,6 @@
 CShellExt::GetCommandString(UINT idCmd, UINT uFlags, UINT FAR *reserved,   LPSTR pszName, UINT cchMax)  { - TDEBUG_TRACE("CShellExt::GetCommandString"); -   *pszName = 0;   char *psz;