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

shellext: simplify menu code, add some missing commands

This can be further simplified, but it's a good start

Changeset 1d22d47e0bc5

Parent 1cccc26df039

by Steve Borho

Changes to 4 files · Browse files at 1d22d47e0bc5 Showing diff from parent 1cccc26df039 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
 
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
 
248
249
250
251
252
253
 
 
254
255
256
 
335
336
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
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
 
263
264
265
 
 
 
266
267
268
269
270
 
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
@@ -1,61 +1,73 @@
 #include "stdafx.h"  #include "ShellExt.h"  #include "TortoiseUtils.h" - -#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) -typedef STDMETHODIMP (CShellExt::*MenuAction) - (HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, - int iShowCmd); +#include "StringUtils.h"    typedef struct {   std::string name;   std::string menuText;   std::string helpText;   std::string iconName; - MenuAction action;   int idCmd; - ULONG flags;  } MenuDescription;   +MenuDescription menuDescList[] = { + {"commit", "HG Commit...", + "Commit changes in repository", + "menucommit.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}, + {"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", + "", 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}, + + // template + {"", "", "", ".ico", 0}, +}; +  typedef std::map<std::string, MenuDescription> MenuDescriptionMap;  typedef std::map<int, MenuDescription> MenuIdCmdMap;   - -MenuDescription menuDescList[] = { - {"commit", "HG Commit...", "Commit changes in repository", - "menucommit.ico", &CShellExt::CM_Commit, 0, 0}, - {"status", "View File Status", "Repository status & changes", - "menushowchanged.ico", &CShellExt::CM_Status, 0, 0}, - {"log", "View Changelog", "View change history in repository", - "menulog.ico", &CShellExt::CM_Log, 0, 0}, - {"synch", "Synchronize", "Synchronize with remote repository", - "menusynch.ico", &CShellExt::CM_Synch, 0, 0}, - {"serve", "Web Server", "Start web server for this repository", - "proxy.ico", &CShellExt::CM_Serve, 0, 0}, - {"update", "Update To Revision", "Update working directory", - "menucheckout.ico", &CShellExt::CM_Update, 0, 0}, - {"recover", "Recovery...", "General repair and recovery of repositor", - "general.ico", &CShellExt::CM_Recover, 0, 0}, - {"thgstatus", "Update Icons", "Update icons for this repository", - "", &CShellExt::CM_thgstatus, 0, 0}, - {"userconf", "Global Settings", "Configure user wide settings", - "settings_user.ico", &CShellExt::CM_Userconf, 0, 0}, - {"repoconf", "Repository Settings", "Configure settings local to this repository", - "settings_repo.ico", &CShellExt::CM_Repoconf, 0, 0}, - {"about", "About...", "Show About Dialog", - "menuabout.ico", &CShellExt::CM_About, 0, 0}, - - // template - {"", "", "", - ".ico", NULL, 0, 0}, -}; -  MenuDescriptionMap MenuDescMap;  MenuIdCmdMap MenuIdMap;   -extern HMENU hSubMenu; -extern HINSTANCE g_hmodThisDll; -  void AddMenuList(int idCmd, std::string name)  {   TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name); @@ -190,39 +202,42 @@
  InsertMenuItemByName(hMenu, "commit", indexMenu++, idCmd++, idCmdFirst);     TDEBUG_TRACE(" CShellExt::QueryContextMenu: adding sub menus"); +   HMENU hSubMenu = CreatePopupMenu(); - int indexSubMenu = 0; - if(hSubMenu) + if (hSubMenu)   { + int indexSubMenu = 0;   if (isHgrepo)   { - InsertMenuItemByName(hSubMenu, "status", indexSubMenu++, idCmd++, idCmdFirst); + if (myFiles.empty()) + { + InsertMenuItemByName(hSubMenu, "status", indexSubMenu++, idCmd++, idCmdFirst); + InsertMenuItemByName(hSubMenu, "shelve", indexSubMenu++, idCmd++, idCmdFirst); + 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); + } + InsertMenuItemByName(hSubMenu, "repoconf", indexSubMenu++, idCmd++, idCmdFirst); + }   - 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); - InsertMenuItemByName(hSubMenu, "userconf", indexSubMenu++, idCmd++, idCmdFirst); - } - - InsertMenuItemByName(hSubMenu, "repoconf", indexSubMenu++, idCmd++, idCmdFirst); - - InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, - 0, NULL); - + InsertMenuItemByName(hSubMenu, "userconf", indexSubMenu++, idCmd++, idCmdFirst); + InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);   InsertMenuItemByName(hSubMenu, "about", indexSubMenu++, idCmd++, idCmdFirst);   }   @@ -248,9 +263,8 @@
  MenuIdCmdMap::iterator iter = MenuIdMap.find(idCmd);   if(iter != MenuIdMap.end())   { - MenuAction action = MenuIdMap[idCmd].action; - hr = CALL_MEMBER_FN(*this, action)(lpcmi->hwnd, lpcmi->lpDirectory, - lpcmi->lpVerb, lpcmi->lpParameters, lpcmi->nShow); + DoHgtk(MenuIdMap[idCmd].name); + hr = NOERROR;   }   else   { @@ -335,3 +349,52 @@
    return NOERROR;  } + +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 = Quote(dir + "\\hgtk.exe") + " " + cmd; + + std::string cwd; + if (!myFolder.empty()) + { + cwd = myFolder; + } + else if (!myFiles.empty()) + { + cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]); + + 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 (int 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, "\n", 1, &dwWritten, 0); + } + CloseHandle(tempfileHandle); + hgcmd += " --listfile " + Quote(tempfile); + } + else + { + TDEBUG_TRACE("DoHgtk: can't get cwd"); + return; + } + + LaunchCommand(hgcmd, cwd); +}
 
7
8
9
10
11
12
13
 
7
8
9
 
10
11
12
@@ -7,7 +7,6 @@
 OBJECTS_THGSGELL = $(OBJECTS_DIRSTATE) \   ContextMenu.o \   IconOverlay.o \ - MenuActions.o \   ShellExt.o \   PipeUtils.o \   ShellUtils2.o \
Change 1 of 1 Show Entire File win32/​shellext/​MenuActions.cpp Stacked
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,145 +0,0 @@
-#include "stdafx.h" -#include "ShellExt.h" -#include "TortoiseUtils.h" -#include "StringUtils.h" - -#include <stdio.h> -#include <vector> - -void CShellExt::DoHgProc(const std::string &cmd) -{ - std::string dir = GetTHgProgRoot(); - TDEBUG_TRACE("DoHgProc: THG root = " << dir); - if (dir.empty()) - { - TDEBUG_TRACE("DoHgProc: THG root is empty"); - return; - } - std::string hgcmd = Quote(dir + "\\hgtk.exe") + " " + cmd; - - std::string cwd; - if (!myFolder.empty()) - { - cwd = myFolder; - } - else if (!myFiles.empty()) - { - cwd = IsDirectory(myFiles[0])? myFiles[0] : DirName(myFiles[0]); - - std::string tempfile = GetTemporaryFile(); - SECURITY_ATTRIBUTES sa; - memset(&sa, 0, sizeof(sa)); - sa.nLength = sizeof(sa); - sa.bInheritHandle = TRUE; - - TDEBUG_TRACE("DoHgProc: temp file = " << tempfile); - HANDLE tempfileHandle = CreateFileA(tempfile.c_str(), GENERIC_WRITE, - FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - for (int i=0; i<myFiles.size(); i++) - { - DWORD dwWritten; - TDEBUG_TRACE("DoHgProc: temp file adding " << myFiles[i]); - 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("DoHgProc: can't get cwd"); - return; - } - - LaunchCommand(hgcmd, cwd); -} - -STDMETHODIMP -CShellExt::CM_Commit(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("commit"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Status(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("status"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Log(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("log"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_About(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("about"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Synch(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("synch"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Serve(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("serve"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Update(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("update"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Recover(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("recovery"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Userconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("userconfig"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_Repoconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("repoconfig"); - return NOERROR; -} - -STDMETHODIMP -CShellExt::CM_thgstatus(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, - LPCSTR pszParam, int iShowCmd) -{ - DoHgProc("thgstatus"); - return NOERROR; -}
 
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
 
65
66
67
 
 
 
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
72
73
@@ -65,25 +65,9 @@
  LPTSTR *m_ppszFileUserClickedOn; // [MAX_PATH]   std::vector<std::string> myFiles;   std::string myFolder; - - protected: - void CShellExt::DoHgProc(const std::string &); + void CShellExt::DoHgtk(const std::string &);     public: - // context menu actions - STDMETHODIMP CM_Commit(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Status(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Log(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_About(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Serve(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Synch(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Update(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Recover(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Userconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_Repoconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - STDMETHODIMP CM_thgstatus(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd); - - public:   CShellExt(TortoiseOLEClass);   ~CShellExt();