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

shellext: coding style cleanup in ContextMenu.cpp

Changeset e214839bf369

Parent fa3706bd1bdc

by Adrian Buehlmann

Changes to one file · Browse files at e214839bf369 Showing diff from parent fa3706bd1bdc Diff from another changeset...

1
2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
 
 
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 
158
159
160
161
162
163
164
165
166
 
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
 
 
 
184
185
186
187
188
 
 
 
 
189
190
191
192
193
194
195
196
197
198
199
200
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
261
262
263
264
265
266
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
 
342
343
344
345
 
 
 
 
 
 
 
346
347
348
 
349
350
351
352
353
 
354
355
 
356
357
358
359
 
 
 
 
360
361
362
363
364
365
366
 
367
368
 
 
 
 
369
370
371
372
373
374
 
 
375
376
377
378
379
380
381
382
383
384
385
 
386
387
388
389
390
391
392
393
394
395
396
397
 
398
399
400
401
402
403
404
 
 
 
 
405
406
407
408
409
 
410
411
412
 
 
 
413
414
415
 
 
416
417
 
 
 
 
418
419
420
421
 
 
422
423
424
425
426
 
 
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
 
 
 
442
443
444
445
446
447
 
 
 
 
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
 
 
 
 
 
 
 
 
 
 
 
471
472
473
474
475
476
477
478
479
480
481
482
483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
 
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
 
528
529
530
531
532
533
534
535
536
537
 
 
 
 
 
 
 
538
539
540
541
542
 
 
 
 
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
1
2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
 
 
193
194
195
196
197
 
 
 
 
198
199
200
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
261
262
 
263
264
265
266
 
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
313
314
 
315
316
 
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
 
360
361
362
 
 
363
364
365
366
367
368
369
370
371
 
372
373
374
375
376
 
377
378
 
379
380
381
382
 
383
384
385
386
387
388
389
390
391
392
 
393
394
 
395
396
397
398
399
400
401
402
 
 
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
 
428
429
430
431
432
433
434
 
435
436
437
438
439
440
441
442
443
444
445
 
 
446
447
448
449
 
 
450
451
452
 
453
454
455
456
457
458
459
 
460
461
462
463
464
465
 
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
 
482
483
484
485
486
487
488
489
 
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
 
 
 
 
 
 
 
 
 
 
507
508
509
510
511
512
513
514
515
516
517
518
 
 
 
 
 
 
 
 
 
 
 
 
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
 
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
 
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
 
577
578
579
580
581
582
583
 
 
 
 
584
585
586
587
588
589
590
591
592
593
 
 
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
 #include "stdafx.h"  #include "ShellExt.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "Dirstatecache.h"  #include "Thgstatus.h" +#include "Winstat.h"   -typedef struct { +struct MenuDescription +{   std::string name;   std::string menuText;   std::string helpText;   std::string iconName;   UINT idCmd; -} MenuDescription; +};   -MenuDescription menuDescList[] = { +MenuDescription menuDescList[] = +{   {"commit", "Commit...",   "Commit changes in repository",   "menucommit.ico", 0},   {"init", "Create Repository Here",   "Create a new repository in this directory",   "menucreaterepos.ico", 0},   {"clone", "Clone a Repository",   "Create clone here from source",   "menuclone.ico", 0},   {"status", "View File Status",   "Repository status & changes",   "menushowchanged.ico", 0},   {"shelve", "Shelve Changes",   "Shelve or unshelve file changes",   "shelve.ico", 0},   {"add", "Add Files",   "Add files to version control",   "menuadd.ico", 0},   {"revert", "Revert Files",   "Revert file changes",   "menurevert.ico", 0},   {"remove", "Remove Files",   "Remove files from version control",   "menudelete.ico", 0},   {"rename", "Rename File",   "Rename file or directory",   "general.ico", 0},   {"log", "View Changelog",   "View change history in repository",   "menulog.ico", 0},   {"synch", "Synchronize",   "Synchronize with remote repository",   "menusynch.ico", 0},   {"serve", "Web Server",   "Start web server for this repository",   "proxy.ico", 0},   {"update", "Update To Revision",   "Update working directory",   "menucheckout.ico", 0},   {"recover", "Recovery...",   "General repair and recovery of repository",   "general.ico", 0},   {"thgstatus", "Update Icons",   "Update icons for this repository",   "menumerge.ico", 0},   {"userconf", "Global Settings",   "Configure user wide settings",   "settings_user.ico", 0},   {"repoconf", "Repository Settings",   "Configure repository settings",   "settings_repo.ico", 0},   {"about", "About...",   "Show About Dialog",   "menuabout.ico", 0},   {"datamine", "Annotate Files",   "Show changeset information per file line",   "menublame.ico", 0},   {"vdiff", "Visual Diff",   "View changes using GUI diff tool",   "TortoiseMerge.ico", 0},     /* Add new items here */     // template   {"", "", "", ".ico", 0},  };    /* These enumerations must match the order of menuDescList */ -enum menuDescListEntries { +enum menuDescListEntries +{   Commit, Init, Clone, Status, Shelve, Add, Revert, Remove, Rename,   Log, Synch, Serve, Update, Recover, Thgstatus, Userconf, Repoconf,   About, Datamine, VDiff,   /* Add new items here */   Separator, EndOfList  };   -menuDescListEntries RepoNoFilesMenu[] = { - Commit, Status, Shelve, VDiff, Separator, +menuDescListEntries RepoNoFilesMenu[] = +{ + Commit, Status, Shelve, VDiff, Separator,   Log, Separator,   Update, Separator,   Synch, Clone, Recover, Serve, Thgstatus, Separator,   Repoconf, Userconf, Separator,   About, EndOfList  };   -menuDescListEntries RepoFilesMenu[] = { +menuDescListEntries RepoFilesMenu[] = +{   Commit, Status, VDiff, Add, Revert, Rename, Remove, Separator,   Log, Datamine, Separator,   About, EndOfList  };   -menuDescListEntries NoRepoMenu[] = { +menuDescListEntries NoRepoMenu[] = +{   Clone, Init, Userconf, Thgstatus, Separator,   About, EndOfList  };    typedef std::map<std::string, MenuDescription> MenuDescriptionMap;  typedef std::map<UINT, MenuDescription> MenuIdCmdMap;    MenuDescriptionMap MenuDescMap;  MenuIdCmdMap MenuIdMap;   +  void AddMenuList(UINT idCmd, const std::string& name) -{ +{   TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name);   MenuIdMap[idCmd] = MenuDescMap[name];  }   +  void GetCMenuTranslation( - const std::string& lang, - const std::string& name, - std::string& menuText, - std::string& helpText) + const std::string& lang, + const std::string& name, + std::string& menuText, + std::string& helpText +)  {   std::string subkey = "Software\\TortoiseHg\\CMenu\\";   subkey += lang;   subkey += "\\";   subkey += name;     TDEBUG_TRACE("GetCMenuTranslation: " << subkey);     HKEY hkey = 0;   LONG rv = RegOpenKeyExA(   HKEY_CURRENT_USER, subkey.c_str(), 0, KEY_READ, &hkey);     if (rv != ERROR_SUCCESS || hkey == 0)   return;     BYTE Data[MAX_PATH] = "";   DWORD cbData = MAX_PATH * sizeof(BYTE);     rv = RegQueryValueExA(hkey, "menuText", 0, 0, Data, &cbData);   if (rv == ERROR_SUCCESS)   menuText = reinterpret_cast<const char*>(&Data);     cbData = MAX_PATH * sizeof(BYTE);   rv = RegQueryValueExA(hkey, "helpText", 0, 0, Data, &cbData);   if (rv == ERROR_SUCCESS)   helpText = reinterpret_cast<const char*>(&Data);  }   +  void InitMenuMaps()  {   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++) + for (std::size_t i = 0; i < sz; i++)   {   MenuDescription md = menuDescList[i];   TDEBUG_TRACE("InitMenuMaps: adding " << md.name);     // Look for translation of menu and help text   if( lang.size() )   GetCMenuTranslation(lang, md.name, md.menuText, md.helpText);     MenuDescMap[md.name] = md;   }   }     MenuIdMap.clear();  }   -void InsertMenuItemWithIcon(HMENU hMenu, UINT indexMenu, UINT idCmd, - const std::string& menuText, const std::string& iconName) + +void InsertMenuItemWithIcon( + HMENU hMenu, UINT indexMenu, UINT idCmd, + const std::string& menuText, const std::string& iconName)  { - MENUITEMINFO mi; - mi.cbSize = sizeof(mi); - mi.dwTypeData = const_cast<char*> (menuText.c_str()); - mi.cch = static_cast<UINT> (menuText.length()); + MENUITEMINFO mi; + mi.cbSize = sizeof(mi); + mi.dwTypeData = const_cast<char*>(menuText.c_str()); + mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;   mi.fType = MFT_STRING;     HICON h = GetTortoiseIcon(iconName);   if (h)   {   mi.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_DATA;   mi.dwItemData = (ULONG_PTR) h;   mi.hbmpItem = HBMMENU_CALLBACK;   }   else   { - TDEBUG_TRACE(" InsertMenuItemWithIcon: can't find " + iconName); + TDEBUG_TRACE(" InsertMenuItemWithIcon: can't find " + iconName);   mi.fMask = MIIM_TYPE | MIIM_ID;   }   InsertMenuItem(hMenu, indexMenu, TRUE, &mi);  }   -void InsertSubMenuItemWithIcon(HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd, - const std::string& menuText, const std::string& iconName) + +void InsertSubMenuItemWithIcon( + HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd, + const std::string& menuText, const std::string& iconName)  {   MENUITEMINFO mi;   mi.cbSize = sizeof(mi);   mi.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;   mi.fType = MFT_STRING; - mi.dwTypeData = const_cast<char*> (menuText.c_str()); - mi.cch = static_cast<UINT> (menuText.length()); + mi.dwTypeData = const_cast<char*>(menuText.c_str()); + mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;   mi.hSubMenu = hSubMenu;   HICON h = GetTortoiseIcon(iconName);   if (h)   {   mi.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_SUBMENU | MIIM_ID |   MIIM_BITMAP | MIIM_DATA;   mi.dwItemData = (ULONG_PTR) h;   mi.hbmpItem = HBMMENU_CALLBACK;   }   else   { - TDEBUG_TRACE(" InsertSubMenuItemWithIcon: can't find " + iconName); + TDEBUG_TRACE(" InsertSubMenuItemWithIcon: can't find " + iconName);   }   InsertMenuItem(hMenu, indexMenu, TRUE, &mi);  }   -void InsertMenuItemByName(HMENU hMenu, const std::string& name, UINT indexMenu, - UINT idCmd, UINT idCmdFirst, const std::string& prefix) + +void InsertMenuItemByName( + HMENU hMenu, const std::string& name, UINT indexMenu, + UINT idCmd, UINT idCmdFirst, const std::string& prefix)  {   TDEBUG_TRACE("InsertMenuItemByName: name = " << name);   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); - InsertMenuItemWithIcon(hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName); + InsertMenuItemWithIcon( + hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);  }   -// IContextMenu + +// IContextMenu  STDMETHODIMP -CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, - UINT idCmdLast, UINT uFlags) +CShellExt::QueryContextMenu( + HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)  {   TDEBUG_TRACE("CShellExt::QueryContextMenu");   InitMenuMaps(); - +   UINT idCmd = idCmdFirst; - BOOL bAppendItems = TRUE; + BOOL bAppendItems = TRUE;   - if((uFlags & 0x000F) == CMF_NORMAL) - bAppendItems = TRUE; - else if (uFlags & CMF_VERBSONLY) - bAppendItems = TRUE; - else if (uFlags & CMF_EXPLORE) - bAppendItems = TRUE; - else - bAppendItems = FALSE; + if ((uFlags & 0x000F) == CMF_NORMAL) + bAppendItems = TRUE; + else if (uFlags & CMF_VERBSONLY) + bAppendItems = TRUE; + else if (uFlags & CMF_EXPLORE) + bAppendItems = TRUE; + else + bAppendItems = FALSE;     if (!bAppendItems)   return NOERROR;     const std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription); - bool promoted[ sz ]; + bool promoted[sz];   memset(&promoted, 0, sizeof(promoted));     std::string cval = "commit"; // default value if key not found   GetRegistryConfig("PromotedItems", cval);     size_t found;   do   { - if( cval.empty() ) + 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++ ) + for (UINT i = 0; i < sz; i++)   { - if( !key.compare(menuDescList[i].name) ) + if (!key.compare(menuDescList[i].name))   {   promoted[i] = true;   break;   }   }   }   while (found != std::string::npos);     // check if target directory is a Mercurial repository   std::string cwd;   if (!myFolder.empty())   {   cwd = myFolder;   }   else if (myFiles.size() == 1 && IsDirectory(myFiles[0]))   {   myFolder = myFiles[0];   cwd = myFolder;   myFiles.clear();   }   else if (!myFiles.empty())   {   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);     menuDescListEntries *walk; - for( walk = entries; *walk != EndOfList; walk++ ) + for (walk = entries; *walk != EndOfList; walk++)   {   UINT idx = (UINT) *walk; - if( promoted[idx] ) - InsertMenuItemByName(hMenu, menuDescList[idx].name, indexMenu++, idCmd++, idCmdFirst, "HG "); + if (promoted[idx]) + { + InsertMenuItemByName( + hMenu, menuDescList[idx].name, indexMenu++, + idCmd++, idCmdFirst, "HG " + ); + }   }   - HMENU hSubMenu = CreatePopupMenu(); + const HMENU hSubMenu = CreatePopupMenu();   if (hSubMenu)   {   UINT indexSubMenu = 0;   bool isSeparator = true; - for( walk = entries; *walk != EndOfList; walk++ ) + for (walk = entries; *walk != EndOfList; walk++)   { - if( *walk == Separator) + if (*walk == Separator)   {   if (!isSeparator)   { - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); + InsertMenu( + hSubMenu, indexSubMenu++, + MF_SEPARATOR | MF_BYPOSITION, 0, NULL + );   isSeparator = true;   }   }   else   {   UINT idx = (UINT) *walk; - if( !promoted[idx] ) + if (!promoted[idx])   { - InsertMenuItemByName(hSubMenu, menuDescList[idx].name, indexSubMenu++, idCmd++, idCmdFirst, ""); + InsertMenuItemByName( + hSubMenu, menuDescList[idx].name, + indexSubMenu++, idCmd++, idCmdFirst, "" + );   isSeparator = false;   }   }   } - if (isSeparator && indexSubMenu>0) - RemoveMenu(hSubMenu, indexSubMenu-1, MF_BYPOSITION); + if (isSeparator && indexSubMenu > 0) + RemoveMenu(hSubMenu, indexSubMenu - 1, MF_BYPOSITION);   }     TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding main THG menu");   InsertSubMenuItemWithIcon(hMenu, hSubMenu, indexMenu++, idCmd++,   "TortoiseHG...", "hg.ico");     InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);     return ResultFromShort(idCmd - idCmdFirst);  }   +  STDMETHODIMP  CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)  {   TDEBUG_TRACE("CShellExt::InvokeCommand");     HRESULT hr = E_INVALIDARG;   if (!HIWORD(lpcmi->lpVerb))   {   UINT idCmd = LOWORD(lpcmi->lpVerb);   TDEBUG_TRACE("CShellExt::InvokeCommand: idCmd = " << idCmd);   MenuIdCmdMap::iterator iter = MenuIdMap.find(idCmd); - if(iter != MenuIdMap.end()) + if (iter != MenuIdMap.end())   {   DoHgtk(iter->second.name);   hr = NOERROR;   }   else   { - TDEBUG_TRACE("CShellExt::InvokeCommand: action not found for idCmd " << idCmd); + TDEBUG_TRACE( + "CShellExt::InvokeCommand: action not found for idCmd " + << idCmd + );   }   }   return hr;  }   +  STDMETHODIMP -CShellExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, - LPSTR pszName, UINT cchMax) +CShellExt::GetCommandString( + UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, + LPSTR pszName, UINT cchMax)  { - *pszName = 0; - char *psz; + *pszName = 0; + char *psz;   - TDEBUG_TRACE("CShellExt::GetCommandString: idCmd = " << idCmd << ", uFlags = " << uFlags); + TDEBUG_TRACE( + "CShellExt::GetCommandString: idCmd = " << idCmd + << ", uFlags = " << uFlags + );   MenuIdCmdMap::iterator iter = MenuIdMap.find(static_cast<UINT>(idCmd));   if (iter != MenuIdMap.end())   { - TDEBUG_TRACE("CShellExt::GetCommandString: name = " << iter->second.name); + TDEBUG_TRACE( + "CShellExt::GetCommandString: name = " << iter->second.name);   psz = (char*)iter->second.helpText.c_str();   }   else   { - TDEBUG_TRACE("CShellExt::GetCommandString: can't find idCmd " << idCmd); + TDEBUG_TRACE( + "CShellExt::GetCommandString: can't find idCmd " << idCmd);   psz = "";   }     if (uFlags & GCS_UNICODE)   {   wcscpy((wchar_t*)pszName, _WCSTR(psz));   }   else   {   strcpy((char*)pszName, psz);   }   return NOERROR;  }   -STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) + +STDMETHODIMP +CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)  {   LRESULT res;   return HandleMenuMsg2(uMsg, wParam, lParam, &res);  }   -STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult) + +STDMETHODIMP +CShellExt::HandleMenuMsg2( + UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)  {   TDEBUG_ENTER("CShellExt::HandleMenuMsg2");   // A great tutorial on owner drawn menus in shell extension can be found   // here: http://www.codeproject.com/shell/shellextguide7.asp     LRESULT res;   if (!pResult)   pResult = &res;   *pResult = FALSE;     switch (uMsg)   {   case WM_MEASUREITEM: - { - MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam; - if (lpmis==NULL) - break; - lpmis->itemWidth += 2; - if(lpmis->itemHeight < 16) - lpmis->itemHeight = 16; - *pResult = TRUE; - } - break; + { + MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam; + if (lpmis==NULL) + break; + lpmis->itemWidth += 2; + if(lpmis->itemHeight < 16) + lpmis->itemHeight = 16; + *pResult = TRUE; + } + break; +   case WM_DRAWITEM: - { - DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam; - if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData) - break; //not for a menu - DrawIconEx(lpdis->hDC, - lpdis->rcItem.left - 16, - lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2, - (HICON) lpdis->itemData, 16, 16, - 0, 0, DI_NORMAL); - *pResult = TRUE; - } - break; + { + DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam; + if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData) + break; //not for a menu + DrawIconEx( + lpdis->hDC, + lpdis->rcItem.left - 16, + lpdis->rcItem.top + + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2, + (HICON) lpdis->itemData, 16, 16, + 0, 0, DI_NORMAL + ); + *pResult = TRUE; + } + break; +   default:   return NOERROR;   }     return NOERROR;  }   -#include "Winstat.h"    void CShellExt::DoHgtk(const std::string &cmd)  {   std::string dir = GetTHgProgRoot();   if (dir.empty())   {   TDEBUG_TRACE("DoHgtk: THG root is empty");   return;   }   std::string hgcmd = dir + "\\hgtk.exe";     WIN32_FIND_DATAA data;   HANDLE hfind = FindFirstFileA(hgcmd.c_str(), &data);   if (hfind == INVALID_HANDLE_VALUE)   hgcmd = dir + "\\hgtk.cmd";   else   FindClose(hfind);     hgcmd = Quote(hgcmd) + " " + cmd; - +   std::string cwd;   if (!myFolder.empty())   {   cwd = myFolder;   }   else if (myFiles.size() == 1 && IsDirectory(myFiles[0]))   {   // Treat single selected directory as if cmenu were opened   // within that directory without files selected   cwd = myFiles[0];   }   else if (!myFiles.empty())   {   cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]);   - std::string tempfile = GetTemporaryFile(); + const std::string tempfile = GetTemporaryFile();   SECURITY_ATTRIBUTES sa;   memset(&sa, 0, sizeof(sa));   sa.nLength = sizeof(sa);   sa.bInheritHandle = TRUE;     TDEBUG_TRACE("DoHgtk: temp file = " << tempfile); - HANDLE tempfileHandle = CreateFileA(tempfile.c_str(), GENERIC_WRITE, - FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - for (std::vector<std::string>::size_type i=0; i<myFiles.size(); i++) + HANDLE tempfileHandle = CreateFileA( + tempfile.c_str(), GENERIC_WRITE, + FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 + ); + + typedef std::vector<std::string>::size_type ST; + for (ST i = 0; i < myFiles.size(); i++)   {   DWORD dwWritten;   TDEBUG_TRACE("DoHgtk: temp file adding " << myFiles[i]); - WriteFile(tempfileHandle, myFiles[i].c_str(), - static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0); + WriteFile( + tempfileHandle, myFiles[i].c_str(), + static_cast<DWORD>(myFiles[i].size()), &dwWritten, 0 + );   WriteFile(tempfileHandle, "\n", 1, &dwWritten, 0);   }   CloseHandle(tempfileHandle);   hgcmd += " --listfile " + Quote(tempfile);   }   else   {   TDEBUG_TRACE("DoHgtk: can't get cwd");   return;   }     if (cmd == "thgstatus")   {   Thgstatus::remove(cwd);   return;   }     LaunchCommand(hgcmd, cwd);  }