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

stable shellext: use wide strings for UI texts in ContextMenu.cpp

Changeset d5f1924005b9

Parent c9fe49a41307

by Adrian Buehlmann

Changes to 4 files · Browse files at d5f1924005b9 Showing diff from parent c9fe49a41307 Diff from another changeset...

 
12
13
14
15
16
 
 
17
18
19
 
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
 
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
 
193
194
195
196
 
197
198
199
 
204
205
206
207
 
208
209
 
210
211
 
 
212
213
 
214
215
216
 
224
225
226
227
 
228
229
230
 
 
 
 
231
232
233
234
 
235
236
 
237
238
 
 
239
240
241
242
 
243
244
245
 
253
254
255
256
 
257
258
 
 
 
 
259
260
261
262
263
264
 
265
266
267
 
272
273
274
275
 
276
277
278
 
384
385
386
387
 
388
389
390
 
414
415
416
417
 
418
419
420
 
425
426
427
428
429
 
 
430
431
432
 
472
473
474
475
 
 
476
477
478
 
507
508
509
510
 
511
512
 
513
514
515
 
521
522
523
 
 
 
 
 
 
524
525
526
 
549
550
551
552
 
553
554
555
556
557
 
 
 
558
559
560
 
562
563
564
 
 
 
565
566
567
568
569
570
571
572
 
12
13
14
 
 
15
16
17
18
19
 
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
 
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
 
196
197
198
 
199
200
201
202
 
207
208
209
 
210
211
 
212
213
 
214
215
216
 
217
218
219
220
 
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
 
261
262
263
 
264
265
 
266
267
268
269
270
271
272
273
274
 
275
276
277
278
 
283
284
285
 
286
287
288
289
 
395
396
397
 
398
399
400
401
 
425
426
427
 
428
429
430
431
 
436
437
438
 
 
439
440
441
442
443
 
483
484
485
 
486
487
488
489
490
 
519
520
521
 
522
523
 
524
525
526
527
 
533
534
535
536
537
538
539
540
541
542
543
544
 
567
568
569
 
570
571
572
573
574
575
576
577
578
579
580
581
 
583
584
585
586
587
588
589
590
 
 
 
591
592
593
@@ -12,8 +12,8 @@
 struct MenuDescription  {   std::string name; - std::string menuText; - std::string helpText; + std::wstring menuText; + std::wstring helpText;   std::string iconName;   UINT idCmd;  }; @@ -23,80 +23,80 @@
   MenuDescription menuDescList[] =  { - {"commit", "Commit...", - "Commit changes in repository", + {"commit", L"Commit...", + L"Commit changes in repository",   "menucommit.ico", 0}, - {"init", "Create Repository Here", - "Create a new repository", + {"init", L"Create Repository Here", + L"Create a new repository",   "menucreaterepos.ico", 0}, - {"clone", "Clone a Repository", - "Create clone here from source", + {"clone", L"Clone a Repository", + L"Create clone here from source",   "menuclone.ico", 0}, - {"status", "View File Status", - "Repository status & changes", + {"status", L"View File Status", + L"Repository status & changes",   "menushowchanged.ico", 0}, - {"shelve", "Shelve Changes", - "Shelve or unshelve file changes", + {"shelve", L"Shelve Changes", + L"Shelve or unshelve file changes",   "shelve.ico", 0}, - {"add", "Add Files", - "Add files to version control", + {"add", L"Add Files", + L"Add files to version control",   "menuadd.ico", 0}, - {"revert", "Revert Files", - "Revert file changes", + {"revert", L"Revert Files", + L"Revert file changes",   "menurevert.ico", 0}, - {"remove", "Remove Files", - "Remove files from version control", + {"remove", L"Remove Files", + L"Remove files from version control",   "menudelete.ico", 0}, - {"rename", "Rename File", - "Rename file or directory", + {"rename", L"Rename File", + L"Rename file or directory",   "general.ico", 0}, - {"log", "View Changelog", - "View change history in repository", + {"log", L"View Changelog", + L"View change history in repository",   "menulog.ico", 0}, - {"synch", "Synchronize", - "Synchronize with remote repository", + {"synch", L"Synchronize", + L"Synchronize with remote repository",   "menusynch.ico", 0}, - {"serve", "Web Server", - "Start web server for this repository", + {"serve", L"Web Server", + L"Start web server for this repository",   "proxy.ico", 0}, - {"update", "Update To Revision", - "Update working directory", + {"update", L"Update To Revision", + L"Update working directory",   "menucheckout.ico", 0}, - {"recover", "Recovery...", - "Repair and recovery of repository", + {"recover", L"Recovery...", + L"Repair and recovery of repository",   "general.ico", 0}, - {"thgstatus", "Update Icons", - "Update icons for this repository", + {"thgstatus", L"Update Icons", + L"Update icons for this repository",   "refresh_overlays.ico", 0}, - {"userconf", "Global Settings", - "Configure user wide settings", + {"userconf", L"Global Settings", + L"Configure user wide settings",   "settings_user.ico", 0}, - {"repoconf", "Repository Settings", - "Configure repository settings", + {"repoconf", L"Repository Settings", + L"Configure repository settings",   "settings_repo.ico", 0}, - {"about", "About...", - "Show About Dialog", + {"about", L"About...", + L"Show About Dialog",   "menuabout.ico", 0}, - {"datamine", "Annotate Files", - "Changeset information per file line", + {"datamine", L"Annotate Files", + L"Changeset information per file line",   "menublame.ico", 0}, - {"vdiff", "Visual Diff", - "View changes using GUI diff tool", + {"vdiff", L"Visual Diff", + L"View changes using GUI diff tool",   "TortoiseMerge.ico", 0}, - {"hgignore", "Edit Ignore Filter", - "Edit repository ignore filter", + {"hgignore", L"Edit Ignore Filter", + L"Edit repository ignore filter",   "ignore.ico", 0}, - {"guess", "Guess Renames", - "Detect renames and copies", + {"guess", L"Guess Renames", + L"Detect renames and copies",   "detect_rename.ico", 0}, - {"grep", "Search History", - "Search file revisions for patterns", + {"grep", L"Search History", + L"Search file revisions for patterns",   "menurepobrowse.ico", 0},     /* Add new items here */     // template - {"", "", "", ".ico", 0}, + {"", L"", L"", ".ico", 0},  };    /* These enumerations must match the order of menuDescList */ @@ -149,29 +149,32 @@
 void GetCMenuTranslation(   const std::string& lang,   const std::string& name, - std::string& menuText, - std::string& helpText + std::wstring& menuText, + std::wstring& helpText  )  { - std::string subkey = "Software\\TortoiseHg\\CMenu\\"; - subkey += lang; - subkey += "\\"; - subkey += name; + std::wstring subkey = L"Software\\TortoiseHg\\CMenu\\"; + subkey += _WCSTR(lang.c_str()); + subkey += L"\\"; + subkey += _WCSTR(name.c_str());   - TDEBUG_TRACE("GetCMenuTranslation: " << subkey); + TDEBUG_TRACEW(L"GetCMenuTranslation: " << subkey);     HKEY hkey = 0; - LONG rv = RegOpenKeyExA( + LONG rv = RegOpenKeyExW(   HKEY_CURRENT_USER, subkey.c_str(), 0, KEY_READ, &hkey);     if (rv == ERROR_SUCCESS && hkey)   { - GetRegSZValue(hkey, "menuText", menuText); - GetRegSZValue(hkey, "helpText", helpText); + GetRegSZValueW(hkey, L"menuText", menuText); + GetRegSZValueW(hkey, L"helpText", helpText);   }   else   { - TDEBUG_TRACE("GetCMenuTranslation: RegOpenKeyExA(" << subkey << ") failed"); + TDEBUG_TRACEW( + L"GetCMenuTranslation: RegOpenKeyExW(\"" + << subkey << "\") failed" + );   }     if (hkey) @@ -193,7 +196,7 @@
  TDEBUG_TRACE("InitMenuMaps: adding " << md.name);     // Look for translation of menu and help text - if( lang.size() ) + if (lang.size())   GetCMenuTranslation(lang, md.name, md.menuText, md.helpText);     MenuDescMap[md.name] = md; @@ -204,13 +207,14 @@
 }     -void InsertMenuItemWithIcon( +void InsertMenuItemWithIcon1(   HMENU hMenu, UINT indexMenu, UINT idCmd, - const std::string& menuText, const std::string& iconName) + const std::wstring& menuText, const std::string& iconName)  { - MENUITEMINFO mi; + MENUITEMINFOW mi; + memset(&mi, 0, sizeof(mi));   mi.cbSize = sizeof(mi); - mi.dwTypeData = const_cast<char*>(menuText.c_str()); + mi.dwTypeData = const_cast<wchar_t*>(menuText.c_str());   mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;   mi.fType = MFT_STRING; @@ -224,22 +228,26 @@
  }   else   { - TDEBUG_TRACE(" InsertMenuItemWithIcon: can't find " + iconName); + TDEBUG_TRACE(" InsertMenuItemWithIcon1: can't find " + iconName);   mi.fMask = MIIM_TYPE | MIIM_ID;   } - InsertMenuItem(hMenu, indexMenu, TRUE, &mi); + InsertMenuItemW(hMenu, indexMenu, TRUE, &mi); + + TDEBUG_TRACEW( + L"InsertMenuItemWithIcon1(\"" << menuText << L"\") finished");  }     -void InsertSubMenuItemWithIcon( +void InsertSubMenuItemWithIcon2(   HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd, - const std::string& menuText, const std::string& iconName) + const std::wstring& menuText, const std::string& iconName)  { - MENUITEMINFO mi; + MENUITEMINFOW mi; + memset(&mi, 0, sizeof(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.dwTypeData = const_cast<wchar_t*>(menuText.c_str());   mi.cch = static_cast<UINT>(menuText.length());   mi.wID = idCmd;   mi.hSubMenu = hSubMenu; @@ -253,15 +261,18 @@
  }   else   { - TDEBUG_TRACE(" InsertSubMenuItemWithIcon: can't find " + iconName); + TDEBUG_TRACE(" InsertSubMenuItemWithIcon2: can't find " + iconName);   } - InsertMenuItem(hMenu, indexMenu, TRUE, &mi); + InsertMenuItemW(hMenu, indexMenu, TRUE, &mi); + + TDEBUG_TRACEW( + L"InsertMenuItemWithIcon2(\"" << menuText << L"\") finished");  }      void InsertMenuItemByName(   HMENU hMenu, const std::string& name, UINT indexMenu, - UINT idCmd, UINT idCmdFirst, const std::string& prefix) + UINT idCmd, UINT idCmdFirst, const std::wstring& prefix)  {   MenuDescriptionMap::iterator iter = MenuDescMap.find(name);   if (iter == MenuDescMap.end()) @@ -272,7 +283,7 @@
    MenuDescription md = iter->second;   AddMenuList(idCmd - idCmdFirst, name); - InsertMenuItemWithIcon( + InsertMenuItemWithIcon1(   hMenu, indexMenu, idCmd, prefix + md.menuText, md.iconName);  }   @@ -384,7 +395,7 @@
  {   InsertMenuItemByName(   hMenu, menuDescList[idx].name, indexMenu++, - idCmd++, idCmdFirst, "HG " + idCmd++, idCmdFirst, L"HG "   );   }   } @@ -414,7 +425,7 @@
  {   InsertMenuItemByName(   hSubMenu, menuDescList[idx].name, - indexSubMenu++, idCmd++, idCmdFirst, "" + indexSubMenu++, idCmd++, idCmdFirst, L""   );   isSeparator = false;   } @@ -425,8 +436,8 @@
  }     TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding main THG menu"); - InsertSubMenuItemWithIcon(hMenu, hSubMenu, indexMenu++, idCmd++, - "TortoiseHG...", "hg.ico"); + InsertSubMenuItemWithIcon2(hMenu, hSubMenu, indexMenu++, idCmd++, + L"TortoiseHG...", "hg.ico");     InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);   @@ -472,7 +483,8 @@
    HRESULT res = S_FALSE;   - const char *psz = ""; + const char* psz = ""; + const wchar_t* pszw = 0;     std::string sflags = "?";   switch (uFlags) @@ -507,9 +519,9 @@
  TDEBUG_TRACE(   "CShellExt::GetCommandString: name = \"" << iter->second.name << "\"");   - if (uFlags == GCS_HELPTEXTW || uFlags == GCS_HELPTEXTA) + if (uFlags == GCS_HELPTEXTW)   { - psz = iter->second.helpText.c_str(); + pszw = iter->second.helpText.c_str();   res = S_OK;     size_t size = iter->second.helpText.size(); @@ -521,6 +533,12 @@
  << ", which is not reasonably short (<40)");   }   } + else if (uFlags == GCS_HELPTEXTA) + { + // we don't provide ansi help texts + psz = ""; + res = S_OK; + }   else if (uFlags == GCS_VERBW || uFlags == GCS_VERBA)   {  #if 0 @@ -549,12 +567,15 @@
  if (uFlags & GCS_UNICODE)   {   wchar_t* const dest = reinterpret_cast<wchar_t*>(pszName); - const wchar_t* const src = _WCSTR(psz); + const wchar_t* const src = pszw ? pszw : _WCSTR(psz);     wcsncpy(dest, src, cchMax-1);   *(dest + cchMax-1) = 0;     size = wcslen(src); + + TDEBUG_TRACEW(L"CShellExt::GetCommandString: res = " << int(res) + << L", pszName (wide) = \"" << dest << L"\"");   }   else   { @@ -562,11 +583,11 @@
  *(pszName + cchMax-1) = 0;     size = strlen(psz); + + TDEBUG_TRACE("CShellExt::GetCommandString: res = " << int(res) + << ", pszName = \"" << psz << "\"");   }   - TDEBUG_TRACE("CShellExt::GetCommandString: res = " << res - << ", pszName = \"" << psz << "\""); -   if (size > cchMax-1)   {   TDEBUG_TRACE(
 
297
298
299
 
 
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
304
305
 
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
@@ -297,9 +297,36 @@
  return 1;   }   + TDEBUG_TRACE("GetRegSZValue(" << name << ") failed"); +   return 0;  }   +// read string value from registry, wide version +int GetRegSZValueW(HKEY hkey, const wchar_t* name, std::wstring& res) +{ + res = L""; + + if (!hkey) + return 0; + + std::vector<BYTE> Data(600); + DWORD cbData = Data.size(); + + LONG rv = ::RegQueryValueExW(hkey, name, 0, 0, &Data[0], &cbData); + + if (rv == ERROR_SUCCESS) + { + res = reinterpret_cast<wchar_t*>(&Data[0]); + return 1; + } + + TDEBUG_TRACEW(L"GetRegSZValueW(\"" << name << L"\") failed"); + + return 0; +} + +  // true if a starts with b  bool StartsWith(const std::string& a, const std::string& b)  {
 
24
25
26
 
27
28
29
 
24
25
26
27
28
29
30
@@ -24,6 +24,7 @@
 int GetRegistryConfig(const std::string& name, std::string& res);  FILE* fopenReadRenameAllowed(const char* path);  int GetRegSZValue(HKEY hkey, const char* name, std::string& res); +int GetRegSZValueW(HKEY hkey, const wchar_t* name, std::wstring& res);  bool StartsWith(const std::string& a, const std::string& b);    #endif
 
28
29
30
31
 
 
 
 
 
 
 
32
33
34
 
28
29
30
 
31
32
33
34
35
36
37
38
39
40
@@ -28,7 +28,13 @@
  std::stringstream _the_msg; \   _the_msg << "[THG] " << s; \   std::string _the_str = _the_msg.str(); \ - OutputDebugString(_the_str.c_str()); \ + OutputDebugStringA(_the_str.c_str()); \ + } while (0) + #define TDEBUG_TRACEW(s) do { \ + std::basic_stringstream<wchar_t> _the_msg; \ + _the_msg << L"[THG] " << s; \ + std::wstring _the_str = _the_msg.str(); \ + OutputDebugStringW(_the_str.c_str()); \   } while (0)   #define TDEBUG_ENTER TDEBUG_TRACE  #else