Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: display shortcut keys in help dialog

Changeset 4f3600acf4ab

Parent a36c4cad9d3d

by David Golub

Changes to 3 files · Browse files at 4f3600acf4ab Showing diff from parent a36c4cad9d3d Diff from another changeset...

 
202
203
204
205
 
206
207
208
 
202
203
204
 
205
206
207
208
@@ -202,7 +202,7 @@
  { "commit", 'C', KSF_CONTROL | KSF_SHIFT },   { "forget", 'F', KSF_CONTROL | KSF_SHIFT },   { "rename", 'M', KSF_CONTROL | KSF_SHIFT }, - { "synchronize", 'S', KSF_CONTROL | KSF_SHIFT }, + { "synch", 'S', KSF_CONTROL | KSF_SHIFT },   { "update", 'U', KSF_CONTROL | KSF_SHIFT },   { "revert", 'V', KSF_CONTROL | KSF_SHIFT },   { "workbench", 'W', KSF_CONTROL | KSF_SHIFT },
 
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
 
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
 
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
 
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
@@ -17,6 +17,53 @@
   #include "KeyboardHelpDialog.h"  #include "RegistryConfig.h" +#include "GlobalData.h" + +static CString GetKeyName(UINT uKey, bool bExtended = false) +{ + UINT uScanCode = ::MapVirtualKey(uKey, MAPVK_VK_TO_VSC); + LONG lParam = (LONG)uScanCode << 16; + + // Adding this flag prevents a distinction from being made between the left and + // right Alt, Control, or Shift keys. + lParam |= (1 << 25); + + // Adding this flag is necessary for certain keys (e.g. Insert, Delete) to be + // handled properly. However, it prevents other keys (e.g. Shift) from being + // handled properly. Therefore, only use it when necessary. + if (bExtended) lParam |= (1 << 24); + + // Get the name of the key. + TCHAR szKeyName[20]; + ::GetKeyNameText(lParam, szKeyName, 20); + return szKeyName; +} + +static CStringW LookupMenuText(CString strName, CString strLang) +{ + // Search the context menu list to find the menu text for the specified command. + // Then, attempt to find a localized string in the registry. + for (int i = 0; i < MenuDescListCount; i++) + { + if (MenuDescList[i].strName == strName) + { + CStringW strMenuText = MenuDescList[i].strMenuText; + if (!strLang.IsEmpty()) + { + CStringW strDummy; + GetCMenuTranslation(strLang, MenuDescList[i].strName, strMenuText, + strDummy); + } + if (strMenuText.Right(3) == "...") + { + // Strip off any trailing ellipsis from the name. + strMenuText.Truncate(strMenuText.GetLength() - 3); + } + return strMenuText; + } + } + return ""; +}    LRESULT CKeyboardHelpDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&)  { @@ -34,6 +81,31 @@
  if (!strHelpText.IsEmpty()) ::SetDlgItemTextW(m_hWnd, IDC_TOPTEXT, strHelpText);   }   + // Set tab stops for the list box. + int nTabStop = 100; + SendDlgItemMessage(IDC_KEYLIST, LB_SETTABSTOPS, 1, (LPARAM)&nTabStop); + + // Get the names of the Alt, Control, and Shift keys. + CString strAlt = GetKeyName(VK_MENU); + CString strControl = GetKeyName(VK_CONTROL); + CString strShift = GetKeyName(VK_SHIFT); + strAlt += '+'; + strControl += '+'; + strShift += '+'; + + // Add each keyboard shortcut to the list box. + for (int i = 0; i < KeyShortcutListCount; i++) + { + CString strKey; + WORD wFlags = KeyShortcutList[i].wFlags; + if (wFlags & KSF_CONTROL) strKey += strControl; + if (wFlags & KSF_ALT) strKey += strAlt; + if (wFlags & KSF_SHIFT) strKey += strShift; + strKey += GetKeyName(KeyShortcutList[i].wKey, true); + strKey += '\t'; + strKey += LookupMenuText(KeyShortcutList[i].strName, strLang); + SendDlgItemMessage(IDC_KEYLIST, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)strKey); + }   return 1L;  }  
 
70
71
72
73
 
74
75
76
 
70
71
72
 
73
74
75
76
@@ -70,7 +70,7 @@
 BEGIN   DEFPUSHBUTTON "OK",IDOK,97,146,50,14   LTEXT "The following shortcut keys are available when using TortoiseHg from Windows Explorer.",IDC_TOPTEXT,7,7,229,16 - LISTBOX IDC_KEYLIST,7,34,229,101,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_KEYLIST,7,34,229,101,LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP  END