OSDN Git Service

*Read Index File Directory. Overlay basic working. include "conflict, modified and...
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / ContextMenu.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "ShellExt.h"\r
21 #include "ItemIDList.h"\r
22 #include "PreserveChdir.h"\r
23 #include "UnicodeUtils.h"\r
24 //#include "GitProperties.h"\r
25 #include "GitStatus.h"\r
26 #include "TGitPath.h"\r
27 \r
28 #define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])\r
29 #define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])\r
30 \r
31 int g_shellidlist=RegisterClipboardFormat(CFSTR_SHELLIDLIST);\r
32 \r
33 CShellExt::MenuInfo CShellExt::menuInfo[] =\r
34 {       \r
35         { ShellMenuClone,                                               MENUCLONE,                      IDI_CLONE,                              IDS_MENUCLONE,                  IDS_MENUDESCCHECKOUT,\r
36         ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
37 \r
38         { ShellMenuPull,                                                MENUPULL,                       IDI_PULL,                               IDS_MENUPULL,                   IDS_MENUPULL,\r
39         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
40 \r
41         { ShellMenuFetch,                                               MENUFETCH,                      IDI_PULL,                               IDS_MENUFETCH,                  IDS_MENUFETCH,\r
42         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
43 \r
44         { ShellMenuPush,                                                MENUPUSH,                       IDI_PUSH,                               IDS_MENUPUSH,                   IDS_MENUPULL,\r
45         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
46 \r
47 //      { ShellMenuCheckout,                                    MENUCHECKOUT,           IDI_CHECKOUT,                   IDS_MENUCHECKOUT,                       IDS_MENUDESCCHECKOUT,\r
48 //      ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
49 \r
50 //      { ShellMenuUpdate,                                              MENUUPDATE,                     IDI_UPDATE,                             IDS_MENUUPDATE,                         IDS_MENUDESCUPDATE,                             \r
51 //      ITEMIS_INSVN,   ITEMIS_ADDED, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
52 \r
53         { ShellMenuCommit,                                              MENUCOMMIT,                     IDI_COMMIT,                             IDS_MENUCOMMIT,                         IDS_MENUDESCCOMMIT,\r
54         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
55 \r
56         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
57 \r
58         { ShellMenuDiff,                                                MENUDIFF,                       IDI_DIFF,                               IDS_MENUDIFF,                           IDS_MENUDESCDIFF,\r
59         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },\r
60 \r
61         { ShellMenuPrevDiff,                                    MENUPREVDIFF,                   IDI_DIFF,                               IDS_MENUPREVDIFF,                       IDS_MENUDESCPREVDIFF,\r
62         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
63 \r
64 //      { ShellMenuUrlDiff,                                             MENUURLDIFF,            IDI_DIFF,                               IDS_MENUURLDIFF,                        IDS_MENUDESCURLDIFF,\r
65 //      ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
66 \r
67         { ShellMenuLog,                                                 MENULOG,                        IDI_LOG,                                IDS_MENULOG,                            IDS_MENUDESCLOG,\r
68         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },\r
69 \r
70 //      { ShellMenuRepoBrowse,                                  MENUREPOBROWSE,         IDI_REPOBROWSE,                 IDS_MENUREPOBROWSE,                     IDS_MENUDESCREPOBROWSE,\r
71 //      ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
72 \r
73         { ShellMenuShowChanged,                                 MENUSHOWCHANGED,        IDI_SHOWCHANGED,                IDS_MENUSHOWCHANGED,            IDS_MENUDESCSHOWCHANGED,\r
74         ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},\r
75 \r
76 //      { ShellMenuRevisionGraph,                               MENUREVISIONGRAPH,      IDI_REVISIONGRAPH,              IDS_MENUREVISIONGRAPH,          IDS_MENUDESCREVISIONGRAPH,\r
77 //      ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},\r
78 \r
79         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
80 \r
81         { ShellMenuConflictEditor,                              MENUCONFLICTEDITOR,     IDI_CONFLICT,                   IDS_MENUCONFLICT,                       IDS_MENUDESCCONFLICT,\r
82         ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
83 \r
84 //      { ShellMenuResolve,                                             MENURESOLVE,            IDI_RESOLVE,                    IDS_MENURESOLVE,                        IDS_MENUDESCRESOLVE,\r
85 //      ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },\r
86 \r
87 //      { ShellMenuUpdateExt,                                   MENUUPDATEEXT,          IDI_UPDATE,                             IDS_MENUUPDATEEXT,                      IDS_MENUDESCUPDATEEXT,\r
88 //      ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },\r
89 \r
90         { ShellMenuRename,                                              MENURENAME,                     IDI_RENAME,                             IDS_MENURENAME,                         IDS_MENUDESCRENAME,\r
91         ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },\r
92 \r
93         { ShellMenuRemove,                                              MENUREMOVE,                     IDI_DELETE,                             IDS_MENUREMOVE,                         IDS_MENUDESCREMOVE,\r
94         ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
95 \r
96         { ShellMenuRemoveKeep,                                  MENUREMOVE,                     IDI_DELETE,                             IDS_MENUREMOVEKEEP,                     IDS_MENUDESCREMOVEKEEP,\r
97         ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
98 \r
99         { ShellMenuRevert,                                              MENUREVERT,                     IDI_REVERT,                             IDS_MENUREVERT,                         IDS_MENUDESCREVERT,\r
100         ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },\r
101 \r
102         { ShellMenuRevert,                                              MENUREVERT,                     IDI_REVERT,                             IDS_MENUUNDOADD,                        IDS_MENUDESCUNDOADD,\r
103         ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },\r
104 \r
105         { ShellMenuDelUnversioned,                              MENUDELUNVERSIONED,     IDI_DELUNVERSIONED,             IDS_MENUDELUNVERSIONED,         IDS_MENUDESCDELUNVERSIONED,\r
106         ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
107 \r
108         { ShellMenuCleanup,                                             MENUCLEANUP,            IDI_CLEANUP,                    IDS_MENUCLEANUP,                        IDS_MENUDESCCLEANUP,\r
109         ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },\r
110 \r
111 //      { ShellMenuLock,                                                MENULOCK,                       IDI_LOCK,                               IDS_MENU_LOCK,                          IDS_MENUDESC_LOCK,\r
112 //      ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },\r
113 \r
114 //      { ShellMenuUnlock,                                              MENUUNLOCK,                     IDI_UNLOCK,                             IDS_MENU_UNLOCK,                        IDS_MENUDESC_UNLOCK,\r
115 //      ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },\r
116 \r
117 //      { ShellMenuUnlockForce,                                 MENUUNLOCK,                     IDI_UNLOCK,                             IDS_MENU_UNLOCKFORCE,           IDS_MENUDESC_UNLOCKFORCE,\r
118 //      ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
119 \r
120         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
121 \r
122 //      { ShellMenuCopy,                                                MENUCOPY,                       IDI_COPY,                               IDS_MENUBRANCH,                         IDS_MENUDESCCOPY,\r
123 //      ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
124 \r
125         { ShellMenuSwitch,                                              MENUSWITCH,                     IDI_SWITCH,                             IDS_MENUSWITCH,                         IDS_MENUDESCSWITCH,\r
126         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
127 \r
128         { ShellMenuMerge,                                               MENUMERGE,                      IDI_MERGE,                              IDS_MENUMERGE,                          IDS_MENUDESCMERGE,\r
129         ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
130         { ShellMenuMergeAll,                                    MENUMERGEALL,           IDI_MERGE,                              IDS_MENUMERGEALL,                       IDS_MENUDESCMERGEALL,\r
131         ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },\r
132 \r
133         { ShellMenuBranch,                                              MENUCOPY,                       IDI_COPY,                               IDS_MENUBRANCH,                         IDS_MENUDESCCOPY,\r
134         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
135         { ShellMenuTag,                                                 MENUTAG,                        IDI_TAG,                                IDS_MENUTAG,                            IDS_MENUDESCCOPY,\r
136         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
137 \r
138         { ShellMenuExport,                                              MENUEXPORT,                     IDI_EXPORT,                             IDS_MENUEXPORT,                         IDS_MENUDESCEXPORT,\r
139         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
140 \r
141 //      { ShellMenuRelocate,                                    MENURELOCATE,           IDI_RELOCATE,                   IDS_MENURELOCATE,                       IDS_MENUDESCRELOCATE,\r
142 //      ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },\r
143 \r
144         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
145 \r
146         { ShellMenuCreateRepos,                                 MENUCREATEREPOS,        IDI_CREATEREPOS,                IDS_MENUCREATEREPOS,            IDS_MENUDESCCREATEREPOS,\r
147         ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },\r
148 \r
149         { ShellMenuAdd,                                                 MENUADD,                        IDI_ADD,                                IDS_MENUADD,                            IDS_MENUDESCADD,\r
150         ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },\r
151 \r
152 //      { ShellMenuAddAsReplacement,                    MENUADD,                        IDI_ADD,                                IDS_MENUADDASREPLACEMENT,       IDS_MENUADDASREPLACEMENT,\r
153 //      ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },\r
154 \r
155 //      { ShellMenuImport,                                              MENUIMPORT,                     IDI_IMPORT,                             IDS_MENUIMPORT,                         IDS_MENUDESCIMPORT,\r
156 //      ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },\r
157 \r
158         { ShellMenuBlame,                                               MENUBLAME,                      IDI_BLAME,                              IDS_MENUBLAME,                          IDS_MENUDESCBLAME,\r
159         ITEMIS_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },\r
160 \r
161         { ShellMenuIgnoreSub,                                   MENUIGNORE,                     IDI_IGNORE,                             IDS_MENUIGNORE,                         IDS_MENUDESCIGNORE,\r
162         ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },\r
163 \r
164         { ShellMenuUnIgnoreSub,                                 MENUIGNORE,                     IDI_IGNORE,                             IDS_MENUUNIGNORE,                       IDS_MENUDESCUNIGNORE,\r
165         ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },\r
166 \r
167         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
168 \r
169 //      { ShellMenuCherryPick,                                  MENUCHERRYPICK,         IDI_CREATEPATCH,                IDS_MENUCHERRYPICK,             IDS_MENUDESCCREATEPATCH,\r
170 //      ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
171 \r
172         { ShellMenuFormatPatch,                                 MENUFORMATPATCH,        IDI_CREATEPATCH,                IDS_MENUFORMATPATCH,            IDS_MENUDESCCREATEPATCH,\r
173         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
174 \r
175         { ShellMenuImportPatch,                                 MENUIMPORTPATCH,        IDI_PATCH,                              IDS_MENUIMPORTPATCH,            IDS_MENUDESCCREATEPATCH,\r
176         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
177 \r
178 \r
179         { ShellMenuCreatePatch,                                 MENUCREATEPATCH,        IDI_CREATEPATCH,                IDS_MENUCREATEPATCH,            IDS_MENUDESCCREATEPATCH,\r
180         ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
181 \r
182         { ShellMenuApplyPatch,                                  MENUAPPLYPATCH,         IDI_PATCH,                              IDS_MENUAPPLYPATCH,                     IDS_MENUDESCAPPLYPATCH,\r
183         ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },\r
184 \r
185         { ShellMenuProperties,                                  MENUPROPERTIES,         IDI_PROPERTIES,                 IDS_MENUPROPERTIES,                     IDS_MENUDESCPROPERTIES,\r
186         ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
187 \r
188         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
189 //      { ShellMenuClipPaste,                                   MENUCLIPPASTE,          IDI_CLIPPASTE,                  IDS_MENUCLIPPASTE,                      IDS_MENUDESCCLIPPASTE,\r
190 //      ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },\r
191 \r
192         { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
193 \r
194         { ShellMenuSettings,                                    MENUSETTINGS,           IDI_SETTINGS,                   IDS_MENUSETTINGS,                       IDS_MENUDESCSETTINGS,\r
195         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
196         { ShellMenuHelp,                                                MENUHELP,                       IDI_HELP,                               IDS_MENUHELP,                           IDS_MENUDESCHELP,\r
197         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
198         { ShellMenuAbout,                                               MENUABOUT,                      IDI_ABOUT,                              IDS_MENUABOUT,                          IDS_MENUDESCABOUT,\r
199         ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },\r
200 \r
201         // the sub menus - they're not added like the the commands, therefore the menu ID is zero\r
202         // but they still need to be in here, because we use the icon and string information anyway.\r
203         { ShellSubMenu,                                                 NULL,                           IDI_APP,                                IDS_MENUSUBMENU,                        0,\r
204         0, 0, 0, 0, 0, 0, 0, 0 },\r
205         { ShellSubMenuFile,                                             NULL,                           IDI_MENUFILE,                   IDS_MENUSUBMENU,                        0,\r
206         0, 0, 0, 0, 0, 0, 0, 0 },\r
207         { ShellSubMenuFolder,                                   NULL,                           IDI_MENUFOLDER,                 IDS_MENUSUBMENU,                        0,\r
208         0, 0, 0, 0, 0, 0, 0, 0 },\r
209         { ShellSubMenuLink,                                             NULL,                           IDI_MENULINK,                   IDS_MENUSUBMENU,                        0,\r
210         0, 0, 0, 0, 0, 0, 0, 0 },\r
211         { ShellSubMenuMultiple,                                 NULL,                           IDI_MENUMULTIPLE,               IDS_MENUSUBMENU,                        0,\r
212         0, 0, 0, 0, 0, 0, 0, 0 },\r
213         // mark the last entry to tell the loop where to stop iterating over this array\r
214         { ShellMenuLastEntry,                                   0,                                      0,                                              0,                                                      0,\r
215         0, 0, 0, 0, 0, 0, 0, 0 },\r
216 };\r
217 \r
218 \r
219 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,\r
220                                    LPDATAOBJECT pDataObj,\r
221                                    HKEY /* hRegKey */)\r
222 {\r
223 \r
224         ATLTRACE("Shell :: Initialize\n");\r
225         PreserveChdir preserveChdir;\r
226         files_.clear();\r
227         folder_.erase();\r
228         uuidSource.erase();\r
229         uuidTarget.erase();\r
230         itemStates = 0;\r
231         itemStatesFolder = 0;\r
232         stdstring statuspath;\r
233         git_wc_status_kind fetchedstatus = git_wc_status_none;\r
234         // get selected files/folders\r
235         if (pDataObj)\r
236         {\r
237                 STGMEDIUM medium;\r
238                 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,\r
239                         (DVTARGETDEVICE FAR *)NULL, \r
240                         DVASPECT_CONTENT, \r
241                         -1, \r
242                         TYMED_HGLOBAL};\r
243                 HRESULT hres = pDataObj->GetData(&fmte, &medium);\r
244 \r
245                 if (SUCCEEDED(hres) && medium.hGlobal)\r
246                 {\r
247                         if (m_State == FileStateDropHandler)\r
248                         {\r
249 \r
250                                 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };\r
251                                 STGMEDIUM stg = { TYMED_HGLOBAL };\r
252                                 if ( FAILED( pDataObj->GetData ( &etc, &stg )))\r
253                                 {\r
254                                         ReleaseStgMedium ( &medium );\r
255                                         return E_INVALIDARG;\r
256                                 }\r
257 \r
258 \r
259                                 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);\r
260                                 if ( NULL == drop )\r
261                                 {\r
262                                         ReleaseStgMedium ( &stg );\r
263                                         ReleaseStgMedium ( &medium );\r
264                                         return E_INVALIDARG;\r
265                                 }\r
266 \r
267                                 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);\r
268                                 if (count == 1)\r
269                                         itemStates |= ITEMIS_ONLYONE;\r
270                                 for (int i = 0; i < count; i++)\r
271                                 {\r
272                                         // find the path length in chars\r
273                                         UINT len = DragQueryFile(drop, i, NULL, 0);\r
274                                         if (len == 0)\r
275                                                 continue;\r
276                                         TCHAR * szFileName = new TCHAR[len+1];\r
277                                         if (0 == DragQueryFile(drop, i, szFileName, len+1))\r
278                                         {\r
279                                                 delete [] szFileName;\r
280                                                 continue;\r
281                                         }\r
282                                         stdstring str = stdstring(szFileName);\r
283                                         delete [] szFileName;\r
284                                         if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))\r
285                                         {\r
286                                                 if (itemStates & ITEMIS_ONLYONE)\r
287                                                 {\r
288                                                         CTGitPath strpath;\r
289                                                         strpath.SetFromWin(str.c_str());\r
290                                                         itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;\r
291                                                         itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;\r
292                                                 }\r
293                                                 files_.push_back(str);\r
294                                                 if (i == 0)\r
295                                                 {\r
296                                                         //get the Subversion status of the item\r
297                                                         git_wc_status_kind status = git_wc_status_none;\r
298                                                         CTGitPath askedpath;\r
299                                                         askedpath.SetFromWin(str.c_str());\r
300                                                         try\r
301                                                         {\r
302                                                                 GitStatus stat;\r
303                                                                 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);\r
304                                                                 if (stat.status)\r
305                                                                 {\r
306                                                                         statuspath = str;\r
307                                                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
308                                                                         fetchedstatus = status;\r
309                                                                         //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
310                                                                         //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
311                                                                         if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
312                                                                         {\r
313                                                                                 itemStates |= ITEMIS_FOLDER;\r
314                                                                                 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
315                                                                                         itemStates |= ITEMIS_FOLDERINSVN;\r
316                                                                         }\r
317                                                                         //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
318                                                                         //{\r
319                                                                         //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
320                                                                         //              itemStates |= ITEMIS_NEEDSLOCK;\r
321                                                                         //}\r
322                                                                         //if ((stat.status->entry)&&(stat.status->entry->uuid))\r
323                                                                         //      uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
324                                                                 }\r
325                                                                 else\r
326                                                                 {\r
327                                                                         // sometimes, git_client_status() returns with an error.\r
328                                                                         // in that case, we have to check if the working copy is versioned\r
329                                                                         // anyway to show the 'correct' context menu\r
330                                                                         if (askedpath.HasAdminDir())\r
331                                                                                 status = git_wc_status_normal;\r
332                                                                 }\r
333                                                         }\r
334                                                         catch ( ... )\r
335                                                         {\r
336                                                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
337                                                         }\r
338 \r
339                                                         if ( askedpath.IsDirectory() )\r
340                                                         {\r
341                                                                 if (askedpath.HasAdminDir())\r
342                                                                         itemStates |= ITEMIS_INSVN;\r
343                                                         }\r
344                                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
345                                                         //if (askedpath.HasAdminDir())\r
346                                                                 itemStates |= ITEMIS_INSVN;\r
347                                                         if (status == git_wc_status_ignored)\r
348                                                                 itemStates |= ITEMIS_IGNORED;\r
349                                                         if (status == git_wc_status_normal)\r
350                                                                 itemStates |= ITEMIS_NORMAL;\r
351                                                         if (status == git_wc_status_conflicted)\r
352                                                                 itemStates |= ITEMIS_CONFLICTED;\r
353                                                         if (status == git_wc_status_added)\r
354                                                                 itemStates |= ITEMIS_ADDED;\r
355                                                         if (status == git_wc_status_deleted)\r
356                                                                 itemStates |= ITEMIS_DELETED;\r
357                                                 }\r
358                                         }\r
359                                 } // for (int i = 0; i < count; i++)\r
360                                 GlobalUnlock ( drop );\r
361                                 ReleaseStgMedium ( &stg );\r
362 \r
363                         } // if (m_State == FileStateDropHandler) \r
364                         else\r
365                         {\r
366 \r
367                                 //Enumerate PIDLs which the user has selected\r
368                                 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);\r
369                                 ItemIDList parent( GetPIDLFolder (cida));\r
370 \r
371                                 int count = cida->cidl;\r
372                                 BOOL statfetched = FALSE;\r
373                                 for (int i = 0; i < count; ++i)\r
374                                 {\r
375                                         ItemIDList child (GetPIDLItem (cida, i), &parent);\r
376                                         stdstring str = child.toString();\r
377                                         if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))\r
378                                         {\r
379                                                 //check if our menu is requested for a subversion admin directory\r
380                                                 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))\r
381                                                         continue;\r
382 \r
383                                                 files_.push_back(str);\r
384                                                 CTGitPath strpath;\r
385                                                 strpath.SetFromWin(str.c_str());\r
386                                                 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;\r
387                                                 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;\r
388                                                 if (!statfetched)\r
389                                                 {\r
390                                                         //get the Subversion status of the item\r
391                                                         git_wc_status_kind status = git_wc_status_none;\r
392                                                         if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))\r
393                                                         {\r
394                                                                 if (strpath.HasAdminDir())\r
395                                                                         status = git_wc_status_normal;\r
396                                                         }\r
397                                                         else\r
398                                                         {\r
399                                                                 try\r
400                                                                 {\r
401                                                                         GitStatus stat;\r
402                                                                         if (strpath.HasAdminDir())\r
403                                                                                 stat.GetStatus(strpath, false, true, true);\r
404                                                                         statuspath = str;\r
405                                                                         if (stat.status)\r
406                                                                         {\r
407                                                                                 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
408                                                                                 fetchedstatus = status;\r
409                                                                                 //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
410                                                                                 //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
411                                                                                 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
412                                                                                 {\r
413                                                                                         itemStates |= ITEMIS_FOLDER;\r
414                                                                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
415                                                                                                 itemStates |= ITEMIS_FOLDERINSVN;\r
416                                                                                 }\r
417                                                                                 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?\r
418                                                                                 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))\r
419                                                                                         itemStates |= ITEMIS_CONFLICTED;\r
420                                                                                 //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
421                                                                                 //{\r
422                                                                                 //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
423                                                                                 //              itemStates |= ITEMIS_NEEDSLOCK;\r
424                                                                                 //}\r
425                                                                                 //if ((stat.status->entry)&&(stat.status->entry->uuid))\r
426                                                                                 //      uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
427                                                                         }       \r
428                                                                         else\r
429                                                                         {\r
430                                                                                 // sometimes, git_client_status() returns with an error.\r
431                                                                                 // in that case, we have to check if the working copy is versioned\r
432                                                                                 // anyway to show the 'correct' context menu\r
433                                                                                 if (strpath.HasAdminDir())\r
434                                                                                 {\r
435                                                                                         status = git_wc_status_normal;\r
436                                                                                         fetchedstatus = status;\r
437                                                                                 }\r
438                                                                         }\r
439                                                                         statfetched = TRUE;\r
440                                                                 }\r
441                                                                 catch ( ... )\r
442                                                                 {\r
443                                                                         ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
444                                                                 }\r
445                                                         }\r
446 \r
447                                                         if ( strpath.IsDirectory() )\r
448                                                         {\r
449                                                                 if (strpath.HasAdminDir())\r
450                                                                         itemStates |= ITEMIS_INSVN;\r
451                                                         }\r
452                                                         if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
453                                                         //if (strpath.HasAdminDir())\r
454                                                                 itemStates |= ITEMIS_INSVN;\r
455                                                         if (status == git_wc_status_ignored)\r
456                                                         {\r
457                                                                 itemStates |= ITEMIS_IGNORED;\r
458                                                                 // the item is ignored. Get the svn:ignored properties so we can (maybe) later\r
459                                                                 // offer a 'remove from ignored list' entry\r
460 //                                                              GitProperties props(strpath.GetContainingDirectory(), false);\r
461 //                                                              ignoredprops.empty();\r
462 //                                                              for (int p=0; p<props.GetCount(); ++p)\r
463 //                                                              {\r
464 //                                                                      if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)\r
465 //                                                                      {\r
466 //                                                                              std::string st = props.GetItemValue(p);\r
467 //                                                                              ignoredprops = MultibyteToWide(st.c_str());\r
468 //                                                                              // remove all escape chars ('\\')\r
469 //                                                                              std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');\r
470 //                                                                              break;\r
471 //                                                                      }\r
472 //                                                              }\r
473                                                         }\r
474                                                         if (status == git_wc_status_normal)\r
475                                                                 itemStates |= ITEMIS_NORMAL;\r
476                                                         if (status == git_wc_status_conflicted)\r
477                                                                 itemStates |= ITEMIS_CONFLICTED;\r
478                                                         if (status == git_wc_status_added)\r
479                                                                 itemStates |= ITEMIS_ADDED;\r
480                                                         if (status == git_wc_status_deleted)\r
481                                                                 itemStates |= ITEMIS_DELETED;\r
482                                                 }\r
483                                         }\r
484                                 } // for (int i = 0; i < count; ++i)\r
485                                 ItemIDList child (GetPIDLItem (cida, 0), &parent);\r
486                                 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))\r
487                                         itemStates |= ITEMIS_INVERSIONEDFOLDER;\r
488                                 GlobalUnlock(medium.hGlobal);\r
489 \r
490                                 // if the item is a versioned folder, check if there's a patch file\r
491                                 // in the clipboard to be used in "Apply Patch"\r
492                                 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));\r
493                                 if (cFormatDiff)\r
494                                 {\r
495                                         if (IsClipboardFormatAvailable(cFormatDiff)) \r
496                                                 itemStates |= ITEMIS_PATCHINCLIPBOARD;\r
497                                 }\r
498                                 if (IsClipboardFormatAvailable(CF_HDROP)) \r
499                                         itemStates |= ITEMIS_PATHINCLIPBOARD;\r
500 \r
501                         }\r
502 \r
503                         ReleaseStgMedium ( &medium );\r
504                         if (medium.pUnkForRelease)\r
505                         {\r
506                                 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;\r
507                                 relInterface->Release();\r
508                         }\r
509                 }\r
510         }\r
511 \r
512         // get folder background\r
513         if (pIDFolder)\r
514         {\r
515 \r
516                 ItemIDList list(pIDFolder);\r
517                 folder_ = list.toString();\r
518                 git_wc_status_kind status = git_wc_status_none;\r
519                 if (IsClipboardFormatAvailable(CF_HDROP)) \r
520                         itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;\r
521                 \r
522                 CTGitPath askedpath;\r
523                 askedpath.SetFromWin(folder_.c_str());\r
524 \r
525                 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))\r
526                 {\r
527                         \r
528                         try\r
529                         {\r
530                                 GitStatus stat;\r
531                                 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);\r
532                                 if (stat.status)\r
533                                 {\r
534                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
535 //                                      if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
536 //                                              itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
537 //                                      if ((stat.status->entry)&&(stat.status->entry->present_props))\r
538 //                                      {\r
539 //                                              if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
540 //                                                      itemStatesFolder |= ITEMIS_NEEDSLOCK;\r
541 //                                      }\r
542 //                                      if ((stat.status->entry)&&(stat.status->entry->uuid))\r
543 //                                              uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
544                                 \r
545                                 }\r
546                                 else\r
547                                 {\r
548                                         // sometimes, git_client_status() returns with an error.\r
549                                         // in that case, we have to check if the working copy is versioned\r
550                                         // anyway to show the 'correct' context menu\r
551                                         if (askedpath.HasAdminDir())\r
552                                                 status = git_wc_status_normal;\r
553                                 }\r
554                                 \r
555                                 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
556                                 if (askedpath.HasAdminDir())\r
557                                         itemStatesFolder |= ITEMIS_INSVN;\r
558                                 if (status == git_wc_status_normal)\r
559                                         itemStatesFolder |= ITEMIS_NORMAL;\r
560                                 if (status == git_wc_status_conflicted)\r
561                                         itemStatesFolder |= ITEMIS_CONFLICTED;\r
562                                 if (status == git_wc_status_added)\r
563                                         itemStatesFolder |= ITEMIS_ADDED;\r
564                                 if (status == git_wc_status_deleted)\r
565                                         itemStatesFolder |= ITEMIS_DELETED;\r
566 \r
567                         }\r
568                         catch ( ... )\r
569                         {\r
570                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
571                         }\r
572                 }\r
573                 else\r
574                 {\r
575                         status = fetchedstatus;\r
576                 }\r
577                 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
578                 if (askedpath.HasAdminDir())\r
579                 {\r
580                         itemStatesFolder |= ITEMIS_FOLDERINSVN;\r
581                 }\r
582                 if (status == git_wc_status_ignored)\r
583                         itemStatesFolder |= ITEMIS_IGNORED;\r
584                 itemStatesFolder |= ITEMIS_FOLDER;\r
585                 if (files_.size() == 0)\r
586                         itemStates |= ITEMIS_ONLYONE;\r
587                 if (m_State != FileStateDropHandler)\r
588                         itemStates |= itemStatesFolder;\r
589 \r
590         }\r
591         if (files_.size() == 2)\r
592                 itemStates |= ITEMIS_TWO;\r
593         if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))\r
594         {\r
595 \r
596                 itemStates |= ITEMIS_ONLYONE;\r
597                 if (m_State != FileStateDropHandler)\r
598                 {\r
599                         if (PathIsDirectory(files_.front().c_str()))\r
600                         {\r
601                                 folder_ = files_.front();\r
602                                 git_wc_status_kind status = git_wc_status_none;\r
603                                 CTGitPath askedpath;\r
604                                 askedpath.SetFromWin(folder_.c_str());\r
605 \r
606                                 if (folder_.compare(statuspath)!=0)\r
607                                 {                               \r
608                                         try\r
609                                         {\r
610                                                 GitStatus stat;\r
611                                                 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);\r
612                                                 if (stat.status)\r
613                                                 {\r
614                                                         status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);\r
615 //                                                      if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
616 //                                                              itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
617 //                                                      if ((stat.status->entry)&&(stat.status->entry->present_props))\r
618 //                                                      {\r
619 //                                                              if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
620 //                                                                      itemStates |= ITEMIS_NEEDSLOCK;\r
621 //                                                      }\r
622 //                                                      if ((stat.status->entry)&&(stat.status->entry->uuid))\r
623 //                                                              uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);\r
624                                                 }\r
625                                         }\r
626                                         catch ( ... )\r
627                                         {\r
628                                                 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));\r
629                                         }\r
630                                 }\r
631                                 else\r
632                                 {\r
633                                         status = fetchedstatus;\r
634                                 }\r
635                                 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
636                                 if (askedpath.HasAdminDir())\r
637                                         itemStates |= ITEMIS_FOLDERINSVN;\r
638                                 if (status == git_wc_status_ignored)\r
639                                         itemStates |= ITEMIS_IGNORED;\r
640                                 itemStates |= ITEMIS_FOLDER;\r
641                                 if (status == git_wc_status_added)\r
642                                         itemStates |= ITEMIS_ADDED;\r
643                                 if (status == git_wc_status_deleted)\r
644                                         itemStates |= ITEMIS_DELETED;\r
645                         }\r
646                 }\r
647         \r
648         }\r
649         \r
650         return NOERROR;\r
651 }\r
652 \r
653 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)\r
654 {\r
655         TCHAR menutextbuffer[255] = {0};\r
656         TCHAR verbsbuffer[255] = {0};\r
657         MAKESTRING(stringid);\r
658 \r
659         if (istop)\r
660         {\r
661                 //menu entry for the top context menu, so append an "Git " before\r
662                 //the menu text to indicate where the entry comes from\r
663                 _tcscpy_s(menutextbuffer, 255, _T("Git "));\r
664         }\r
665         _tcscat_s(menutextbuffer, 255, stringtablebuffer);\r
666         if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
667         {\r
668                 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);\r
669                 if (fullver >= 0x500)\r
670                 {\r
671                         // on win2k, the context menu does not work properly if we use\r
672                         // icon bitmaps. At least the menu text is empty in the context menu\r
673                         // for folder backgrounds (seems like a win2k bug).\r
674                         HBITMAP bmp = IconToBitmap(icon); \r
675                         SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);\r
676                 }\r
677         }\r
678         else\r
679         {\r
680                 MENUITEMINFO menuiteminfo = {0};\r
681                 menuiteminfo.cbSize = sizeof(menuiteminfo);\r
682                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;\r
683                 menuiteminfo.fType = MFT_STRING;\r
684                 menuiteminfo.dwTypeData = menutextbuffer;\r
685                 if (icon)\r
686                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;\r
687                 menuiteminfo.wID = id;\r
688                 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);\r
689         }\r
690 \r
691         if (istop)\r
692         {\r
693                 //menu entry for the top context menu, so append an "Git " before\r
694                 //the menu text to indicate where the entry comes from\r
695                 _tcscpy_s(menutextbuffer, 255, _T("Git "));\r
696         }\r
697         LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));\r
698         _tcscat_s(menutextbuffer, 255, verbsbuffer);\r
699         stdstring verb = stdstring(menutextbuffer);\r
700         if (verb.find('&') != -1)\r
701         {\r
702                 verb.erase(verb.find('&'),1);\r
703         }\r
704         myVerbsMap[verb] = id - idCmdFirst;\r
705         myVerbsMap[verb] = id;\r
706         myVerbsIDMap[id - idCmdFirst] = verb;\r
707         myVerbsIDMap[id] = verb;\r
708         // We store the relative and absolute diameter\r
709         // (drawitem callback uses absolute, others relative)\r
710         myIDMap[id - idCmdFirst] = com;\r
711         myIDMap[id] = com;\r
712         if (!istop)\r
713                 mySubMenuMap[pos] = com;\r
714 }\r
715 \r
716 HBITMAP CShellExt::IconToBitmap(UINT uIcon)\r
717 {\r
718         std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);\r
719         if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)\r
720                 return bitmap_it->second;\r
721 \r
722         HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);\r
723         if (!hIcon)\r
724                 return NULL;\r
725 \r
726         RECT rect;\r
727 \r
728         rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);\r
729         rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);\r
730 \r
731         rect.left = rect.top = 0;\r
732 \r
733         HWND desktop = ::GetDesktopWindow();\r
734         if (desktop == NULL)\r
735         {\r
736                 DestroyIcon(hIcon);\r
737                 return NULL;\r
738         }\r
739 \r
740         HDC screen_dev = ::GetDC(desktop);\r
741         if (screen_dev == NULL)\r
742         {\r
743                 DestroyIcon(hIcon);\r
744                 return NULL;\r
745         }\r
746 \r
747         // Create a compatible DC\r
748         HDC dst_hdc = ::CreateCompatibleDC(screen_dev);\r
749         if (dst_hdc == NULL)\r
750         {\r
751                 DestroyIcon(hIcon);\r
752                 ::ReleaseDC(desktop, screen_dev); \r
753                 return NULL;\r
754         }\r
755 \r
756         // Create a new bitmap of icon size\r
757         HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);\r
758         if (bmp == NULL)\r
759         {\r
760                 DestroyIcon(hIcon);\r
761                 ::DeleteDC(dst_hdc);\r
762                 ::ReleaseDC(desktop, screen_dev); \r
763                 return NULL;\r
764         }\r
765 \r
766         // Select it into the compatible DC\r
767         HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);\r
768         if (old_dst_bmp == NULL)\r
769         {\r
770                 DestroyIcon(hIcon);\r
771                 return NULL;\r
772         }\r
773 \r
774         // Fill the background of the compatible DC with the white color\r
775         // that is taken by menu routines as transparent\r
776         ::SetBkColor(dst_hdc, RGB(255, 255, 255));\r
777         ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);\r
778 \r
779         // Draw the icon into the compatible DC\r
780         ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);\r
781 \r
782         // Restore settings\r
783         ::SelectObject(dst_hdc, old_dst_bmp);\r
784         ::DeleteDC(dst_hdc);\r
785         ::ReleaseDC(desktop, screen_dev); \r
786         DestroyIcon(hIcon);\r
787         if (bmp)\r
788                 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));\r
789         return bmp;\r
790 }\r
791 \r
792 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)\r
793 {\r
794         bool bRet = true;\r
795         tempfile = stdstring();\r
796         //write all selected files and paths to a temporary file\r
797         //for TortoiseProc.exe to read out again.\r
798         DWORD written = 0;\r
799         DWORD pathlength = GetTempPath(0, NULL);\r
800         TCHAR * path = new TCHAR[pathlength+1];\r
801         TCHAR * tempFile = new TCHAR[pathlength + 100];\r
802         GetTempPath (pathlength+1, path);\r
803         GetTempFileName (path, _T("git"), 0, tempFile);\r
804         tempfile = stdstring(tempFile);\r
805 \r
806         HANDLE file = ::CreateFile (tempFile,\r
807                 GENERIC_WRITE, \r
808                 FILE_SHARE_READ, \r
809                 0, \r
810                 CREATE_ALWAYS, \r
811                 FILE_ATTRIBUTE_TEMPORARY,\r
812                 0);\r
813 \r
814         delete [] path;\r
815         delete [] tempFile;\r
816         if (file == INVALID_HANDLE_VALUE)\r
817                 return false;\r
818 \r
819         if (!IsClipboardFormatAvailable(CF_HDROP))\r
820                 return false;\r
821         if (!OpenClipboard(NULL))\r
822                 return false;\r
823 \r
824         stdstring sClipboardText;\r
825         HGLOBAL hglb = GetClipboardData(CF_HDROP);\r
826         HDROP hDrop = (HDROP)GlobalLock(hglb);\r
827         if(hDrop != NULL)\r
828         {\r
829                 TCHAR szFileName[MAX_PATH];\r
830                 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); \r
831                 for(UINT i = 0; i < cFiles; ++i)\r
832                 {\r
833                         DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));\r
834                         stdstring filename = szFileName;\r
835                         ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);\r
836                         ::WriteFile (file, _T("\n"), 2, &written, 0);\r
837                 }\r
838                 GlobalUnlock(hDrop);\r
839         }\r
840         else bRet = false;\r
841         GlobalUnlock(hglb);\r
842 \r
843         CloseClipboard();\r
844         ::CloseHandle(file);\r
845 \r
846         return bRet;\r
847 }\r
848 \r
849 stdstring CShellExt::WriteFileListToTempFile()\r
850 {\r
851         //write all selected files and paths to a temporary file\r
852         //for TortoiseProc.exe to read out again.\r
853         DWORD pathlength = GetTempPath(0, NULL);\r
854         TCHAR * path = new TCHAR[pathlength+1];\r
855         TCHAR * tempFile = new TCHAR[pathlength + 100];\r
856         GetTempPath (pathlength+1, path);\r
857         GetTempFileName (path, _T("git"), 0, tempFile);\r
858         stdstring retFilePath = stdstring(tempFile);\r
859         \r
860         HANDLE file = ::CreateFile (tempFile,\r
861                                                                 GENERIC_WRITE, \r
862                                                                 FILE_SHARE_READ, \r
863                                                                 0, \r
864                                                                 CREATE_ALWAYS, \r
865                                                                 FILE_ATTRIBUTE_TEMPORARY,\r
866                                                                 0);\r
867 \r
868         delete [] path;\r
869         delete [] tempFile;\r
870         if (file == INVALID_HANDLE_VALUE)\r
871                 return stdstring();\r
872                 \r
873         DWORD written = 0;\r
874         if (files_.empty())\r
875         {\r
876                 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);\r
877                 ::WriteFile (file, _T("\n"), 2, &written, 0);\r
878         }\r
879 \r
880         for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)\r
881         {\r
882                 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);\r
883                 ::WriteFile (file, _T("\n"), 2, &written, 0);\r
884         }\r
885         ::CloseHandle(file);\r
886         return retFilePath;\r
887 }\r
888 \r
889 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)\r
890 {\r
891         PreserveChdir preserveChdir;\r
892         LoadLangDll();\r
893 \r
894         if ((uFlags & CMF_DEFAULTONLY)!=0)\r
895                 return NOERROR;                                 //we don't change the default action\r
896 \r
897         if ((files_.size() == 0)||(folder_.size() == 0))\r
898                 return NOERROR;\r
899 \r
900         if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))\r
901                 return NOERROR;\r
902 \r
903         bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();\r
904 \r
905         //the drop handler only has eight commands, but not all are visible at the same time:\r
906         //if the source file(s) are under version control then those files can be moved\r
907         //to the new location or they can be moved with a rename, \r
908         //if they are unversioned then they can be added to the working copy\r
909         //if they are versioned, they also can be exported to an unversioned location\r
910         UINT idCmd = idCmdFirst;\r
911 \r
912         // Git move here\r
913         // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added\r
914         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))\r
915                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);\r
916 \r
917         // Git move and rename here\r
918         // available if source is a single, versioned but not added item, target is versioned, source and target from same repository or target folder is added\r
919         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))\r
920                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);\r
921 \r
922         // Git copy here\r
923         // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added\r
924         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))\r
925                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);\r
926 \r
927         // Git copy and rename here, source and target from same repository\r
928         // available if source is a single, versioned but not added item, target is versioned or target folder is added\r
929         if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))\r
930                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);\r
931 \r
932         // Git add here\r
933         // available if target is versioned and source is either unversioned or from another repository\r
934         if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))\r
935                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);\r
936 \r
937         // Git export here\r
938         // available if source is versioned and a folder\r
939         if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))\r
940                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);\r
941 \r
942         // Git export all here\r
943         // available if source is versioned and a folder\r
944         if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))\r
945                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);\r
946 \r
947         // apply patch\r
948         // available if source is a patchfile\r
949         if (itemStates & ITEMIS_PATCHFILE)\r
950                 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);\r
951 \r
952         // separator\r
953         if (idCmd != idCmdFirst)\r
954                 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); \r
955 \r
956         return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));\r
957 }\r
958 \r
959 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,\r
960                                          UINT indexMenu,\r
961                                          UINT idCmdFirst,\r
962                                          UINT /*idCmdLast*/,\r
963                                          UINT uFlags)\r
964 {\r
965         ATLTRACE("Shell :: QueryContextMenu\n");\r
966         PreserveChdir preserveChdir;\r
967         \r
968         //first check if our drop handler is called\r
969         //and then (if true) provide the context menu for the\r
970         //drop handler\r
971         if (m_State == FileStateDropHandler)\r
972         {\r
973                 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);\r
974         }\r
975 \r
976         if ((uFlags & CMF_DEFAULTONLY)!=0)\r
977                 return NOERROR;                                 //we don't change the default action\r
978 \r
979         if ((files_.size() == 0)&&(folder_.size() == 0))\r
980                 return NOERROR;\r
981 \r
982         if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))\r
983                 return NOERROR;\r
984 \r
985         int csidlarray[] = \r
986         {\r
987                 CSIDL_BITBUCKET,\r
988                 CSIDL_CDBURN_AREA,\r
989                 CSIDL_COMMON_FAVORITES,\r
990                 CSIDL_COMMON_STARTMENU,\r
991                 CSIDL_COMPUTERSNEARME,\r
992                 CSIDL_CONNECTIONS,\r
993                 CSIDL_CONTROLS,\r
994                 CSIDL_COOKIES,\r
995                 CSIDL_FAVORITES,\r
996                 CSIDL_FONTS,\r
997                 CSIDL_HISTORY,\r
998                 CSIDL_INTERNET,\r
999                 CSIDL_INTERNET_CACHE,\r
1000                 CSIDL_NETHOOD,\r
1001                 CSIDL_NETWORK,\r
1002                 CSIDL_PRINTERS,\r
1003                 CSIDL_PRINTHOOD,\r
1004                 CSIDL_RECENT,\r
1005                 CSIDL_SENDTO,\r
1006                 CSIDL_STARTMENU,\r
1007                 0\r
1008         };\r
1009         if (IsIllegalFolder(folder_, csidlarray))\r
1010                 return NOERROR;\r
1011 \r
1012         if (folder_.empty())\r
1013         {\r
1014                 // folder is empty, but maybe files are selected\r
1015                 if (files_.size() == 0)\r
1016                         return NOERROR; // nothing selected - we don't have a menu to show\r
1017                 // check whether a selected entry is an UID - those are namespace extensions\r
1018                 // which we can't handle\r
1019                 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)\r
1020                 {\r
1021                         if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)\r
1022                                 return NOERROR;\r
1023                 }\r
1024         }\r
1025 \r
1026         //check if our menu is requested for a subversion admin directory\r
1027         if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))\r
1028                 return NOERROR;\r
1029 \r
1030         if (uFlags & CMF_EXTENDEDVERBS)\r
1031                 itemStates |= ITEMIS_EXTENDED;\r
1032 \r
1033         const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);\r
1034         if ( bShortcut && (files_.size()==1))\r
1035         {\r
1036                 // Don't show the context menu for a link if the\r
1037                 // destination is not part of a working copy.\r
1038                 // It would only show the standard menu items\r
1039                 // which are already shown for the lnk-file.\r
1040                 CString path = files_.front().c_str();\r
1041                 if ( !g_GitAdminDir.HasAdminDir(path) )\r
1042                 {\r
1043                         return NOERROR;\r
1044                 }\r
1045         }\r
1046 \r
1047         //check if we already added our menu entry for a folder.\r
1048         //we check that by iterating through all menu entries and check if \r
1049         //the dwItemData member points to our global ID string. That string is set\r
1050         //by our shell extension when the folder menu is inserted.\r
1051         TCHAR menubuf[MAX_PATH];\r
1052         int count = GetMenuItemCount(hMenu);\r
1053         for (int i=0; i<count; ++i)\r
1054         {\r
1055                 MENUITEMINFO miif;\r
1056                 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));\r
1057                 miif.cbSize = sizeof(MENUITEMINFO);\r
1058                 miif.fMask = MIIM_DATA;\r
1059                 miif.dwTypeData = menubuf;\r
1060                 miif.cch = sizeof(menubuf)/sizeof(TCHAR);\r
1061                 GetMenuItemInfo(hMenu, i, TRUE, &miif);\r
1062                 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)\r
1063                         return NOERROR;\r
1064         }\r
1065 \r
1066         LoadLangDll();\r
1067         UINT idCmd = idCmdFirst;\r
1068 \r
1069         //create the sub menu\r
1070         HMENU subMenu = CreateMenu();\r
1071         int indexSubMenu = 0;\r
1072 \r
1073         unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();\r
1074         unsigned __int64 menumask = g_ShellCache.GetMenuMask();\r
1075 \r
1076         int menuIndex = 0;\r
1077         bool bAddSeparator = false;\r
1078         bool bMenuEntryAdded = false;\r
1079         bool bMenuEmpty = true;\r
1080         // insert separator at start\r
1081         InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
1082         bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));\r
1083         // ?? TortoiseSVN had this as (fullver <= 0x0500) this disabled icons in win2k, but icons work fine in win2k\r
1084         if (fullver < 0x0500)\r
1085                 bShowIcons = false;\r
1086         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
1087         {\r
1088                 if (menuInfo[menuIndex].command == ShellSeparator)\r
1089                 {\r
1090                         // we don't add a separator immediately. Because there might not be\r
1091                         // another 'normal' menu entry after we insert a separator.\r
1092                         // we simply set a flag here, indicating that before the next\r
1093                         // 'normal' menu entry, a separator should be added.\r
1094                         if (!bMenuEmpty)\r
1095                                 bAddSeparator = true;\r
1096                 }\r
1097                 else\r
1098                 {\r
1099                         // check the conditions whether to show the menu entry or not\r
1100                         bool bInsertMenu = false;\r
1101 \r
1102                         if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)\r
1103                         {\r
1104                                 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)\r
1105                                         &&\r
1106                                         ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))\r
1107                                         bInsertMenu = true;\r
1108                         }\r
1109                         else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))\r
1110                                 bInsertMenu = true;\r
1111                         else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))\r
1112                                 bInsertMenu = true;\r
1113 \r
1114                         if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)\r
1115                         {\r
1116                                 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)\r
1117                                         &&\r
1118                                         ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))\r
1119                                         bInsertMenu = true;\r
1120                         }\r
1121                         else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))\r
1122                                 bInsertMenu = true;\r
1123                         else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))\r
1124                                 bInsertMenu = true;\r
1125 \r
1126                         if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)\r
1127                         {\r
1128                                 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)\r
1129                                         &&\r
1130                                         ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))\r
1131                                         bInsertMenu = true;\r
1132                         }\r
1133                         else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))\r
1134                                 bInsertMenu = true;\r
1135                         else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))\r
1136                                 bInsertMenu = true;\r
1137 \r
1138                         if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)\r
1139                         {\r
1140                                 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)\r
1141                                         &&\r
1142                                         ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))\r
1143                                         bInsertMenu = true;\r
1144                         }\r
1145                         else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))\r
1146                                 bInsertMenu = true;\r
1147                         else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))\r
1148                                 bInsertMenu = true;\r
1149 \r
1150                         if (menuInfo[menuIndex].menuID & (~menumask))\r
1151                         {\r
1152                                 if (bInsertMenu)\r
1153                                 {\r
1154                                         // insert a separator\r
1155                                         if ((bMenuEntryAdded)&&(bAddSeparator))\r
1156                                         {\r
1157                                                 bAddSeparator = false;\r
1158                                                 bMenuEntryAdded = false;\r
1159                                                 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); \r
1160                                                 idCmd++;\r
1161                                         }\r
1162                                         \r
1163                                         // handle special cases (sub menus)\r
1164                                         if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))\r
1165                                         {\r
1166                                                 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);\r
1167                                                 bMenuEntryAdded = true;\r
1168                                                 bMenuEmpty = false;\r
1169                                         }\r
1170                                         else\r
1171                                         {\r
1172                                                 // the 'get lock' command is special\r
1173                                                 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);\r
1174                                                 if (menuInfo[menuIndex].command == ShellMenuLock)\r
1175                                                 {\r
1176                                                         if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())\r
1177                                                                 bIsTop = true;\r
1178                                                 }\r
1179                                                 // insert the menu entry\r
1180                                                 InsertGitMenu(  bIsTop,\r
1181                                                                                 bIsTop ? hMenu : subMenu,\r
1182                                                                                 bIsTop ? indexMenu++ : indexSubMenu++,\r
1183                                                                                 idCmd++,\r
1184                                                                                 menuInfo[menuIndex].menuTextID,\r
1185                                                                                 bShowIcons ? menuInfo[menuIndex].iconID : 0,\r
1186                                                                                 idCmdFirst,\r
1187                                                                                 menuInfo[menuIndex].command,\r
1188                                                                                 uFlags);\r
1189                                                 if (!bIsTop)\r
1190                                                 {\r
1191                                                         bMenuEntryAdded = true;\r
1192                                                         bMenuEmpty = false;\r
1193                                                 }\r
1194                                         }\r
1195                                 }\r
1196                         }\r
1197                 }\r
1198                 menuIndex++;\r
1199         }\r
1200 \r
1201         //add sub menu to main context menu\r
1202         //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.\r
1203         //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.\r
1204         MAKESTRING(IDS_MENUSUBMENU);\r
1205         MENUITEMINFO menuiteminfo;\r
1206         SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
1207         menuiteminfo.cbSize = sizeof(menuiteminfo);\r
1208         menuiteminfo.fType = MFT_STRING;\r
1209         menuiteminfo.dwTypeData = stringtablebuffer;\r
1210 \r
1211         UINT uIcon = bShowIcons ? IDI_APP : 0;\r
1212         if (folder_.size())\r
1213         {\r
1214                 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;\r
1215                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;\r
1216                 myIDMap[idCmd] = ShellSubMenuFolder;\r
1217                 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;\r
1218         }\r
1219         else if (!bShortcut && (files_.size()==1))\r
1220         {\r
1221                 uIcon = bShowIcons ? IDI_MENUFILE : 0;\r
1222                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;\r
1223                 myIDMap[idCmd] = ShellSubMenuFile;\r
1224         }\r
1225         else if (bShortcut && (files_.size()==1))\r
1226         {\r
1227                 uIcon = bShowIcons ? IDI_MENULINK : 0;\r
1228                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;\r
1229                 myIDMap[idCmd] = ShellSubMenuLink;\r
1230         }\r
1231         else if (files_.size() > 1)\r
1232         {\r
1233                 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;\r
1234                 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;\r
1235                 myIDMap[idCmd] = ShellSubMenuMultiple;\r
1236         }\r
1237         else\r
1238         {\r
1239                 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;\r
1240                 myIDMap[idCmd] = ShellSubMenu;\r
1241         }\r
1242         HBITMAP bmp = NULL;\r
1243         if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
1244         {\r
1245                 bmp = IconToBitmap(uIcon);\r
1246                 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;\r
1247         }\r
1248         else\r
1249         {\r
1250                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
1251                 if (bShowIcons)\r
1252                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;\r
1253         }\r
1254         menuiteminfo.hbmpChecked = bmp;\r
1255         menuiteminfo.hbmpUnchecked = bmp;\r
1256         menuiteminfo.hSubMenu = subMenu;\r
1257         menuiteminfo.wID = idCmd++;\r
1258         InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);\r
1259 \r
1260         //separator after\r
1261         InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
1262 \r
1263         //return number of menu items added\r
1264         return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));\r
1265 }\r
1266 \r
1267 \r
1268 // This is called when you invoke a command on the menu:\r
1269 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)\r
1270 {\r
1271         PreserveChdir preserveChdir;\r
1272         HRESULT hr = E_INVALIDARG;\r
1273         if (lpcmi == NULL)\r
1274                 return hr;\r
1275 \r
1276         std::string command;\r
1277         std::string parent;\r
1278         std::string file;\r
1279 \r
1280         if ((files_.size() > 0)||(folder_.size() > 0))\r
1281         {\r
1282                 UINT idCmd = LOWORD(lpcmi->lpVerb);\r
1283 \r
1284                 if (HIWORD(lpcmi->lpVerb))\r
1285                 {\r
1286                         stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));\r
1287                         std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);\r
1288                         if (verb_it != myVerbsMap.end() && verb_it->first == verb)\r
1289                                 idCmd = verb_it->second;\r
1290                         else\r
1291                                 return hr;\r
1292                 }\r
1293 \r
1294                 // See if we have a handler interface for this id\r
1295                 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);\r
1296                 if (id_it != myIDMap.end() && id_it->first == idCmd)\r
1297                 {\r
1298                         STARTUPINFO startup;\r
1299                         PROCESS_INFORMATION process;\r
1300                         memset(&startup, 0, sizeof(startup));\r
1301                         startup.cb = sizeof(startup);\r
1302                         memset(&process, 0, sizeof(process));\r
1303                         CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);\r
1304                         CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);\r
1305 \r
1306                         //TortoiseProc expects a command line of the form:\r
1307                         //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile\r
1308                         // or\r
1309                         //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>\r
1310                         //\r
1311                         //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)\r
1312                         //* pathfile is a path to a temporary file which contains a list of file paths\r
1313                         stdstring svnCmd = _T(" /command:");\r
1314                         stdstring tempfile;\r
1315                         switch (id_it->second)\r
1316                         {\r
1317                                 //#region case\r
1318                         case ShellMenuCheckout:\r
1319                                 svnCmd += _T("checkout /path:\"");\r
1320                                 svnCmd += folder_;\r
1321                                 svnCmd += _T("\"");\r
1322                                 break;\r
1323                         case ShellMenuUpdate:\r
1324                                 tempfile = WriteFileListToTempFile();\r
1325                                 svnCmd += _T("update /pathfile:\"");\r
1326                                 svnCmd += tempfile;\r
1327                                 svnCmd += _T("\"");\r
1328                                 svnCmd += _T(" /deletepathfile");\r
1329                                 break;\r
1330                         case ShellMenuUpdateExt:\r
1331                                 tempfile = WriteFileListToTempFile();\r
1332                                 svnCmd += _T("update /pathfile:\"");\r
1333                                 svnCmd += tempfile;\r
1334                                 svnCmd += _T("\"");\r
1335                                 svnCmd += _T(" /deletepathfile");\r
1336                                 svnCmd += _T(" /rev");\r
1337                                 break;\r
1338                         case ShellMenuCommit:\r
1339                                 tempfile = WriteFileListToTempFile();\r
1340                                 svnCmd += _T("commit /pathfile:\"");\r
1341                                 svnCmd += tempfile;\r
1342                                 svnCmd += _T("\"");\r
1343                                 svnCmd += _T(" /deletepathfile");\r
1344                                 break;\r
1345                         case ShellMenuAdd:\r
1346                         case ShellMenuAddAsReplacement:\r
1347                                 tempfile = WriteFileListToTempFile();\r
1348                                 svnCmd += _T("add /pathfile:\"");\r
1349                                 svnCmd += tempfile;\r
1350                                 svnCmd += _T("\"");\r
1351                                 svnCmd += _T(" /deletepathfile");\r
1352                                 break;\r
1353                         case ShellMenuIgnore:\r
1354                                 tempfile = WriteFileListToTempFile();\r
1355                                 svnCmd += _T("ignore /pathfile:\"");\r
1356                                 svnCmd += tempfile;\r
1357                                 svnCmd += _T("\"");\r
1358                                 svnCmd += _T(" /deletepathfile");\r
1359                                 break;\r
1360                         case ShellMenuIgnoreCaseSensitive:\r
1361                                 tempfile = WriteFileListToTempFile();\r
1362                                 svnCmd += _T("ignore /pathfile:\"");\r
1363                                 svnCmd += tempfile;\r
1364                                 svnCmd += _T("\"");\r
1365                                 svnCmd += _T(" /deletepathfile");\r
1366                                 svnCmd += _T(" /onlymask");\r
1367                                 break;\r
1368                         case ShellMenuUnIgnore:\r
1369                                 tempfile = WriteFileListToTempFile();\r
1370                                 svnCmd += _T("unignore /pathfile:\"");\r
1371                                 svnCmd += tempfile;\r
1372                                 svnCmd += _T("\"");\r
1373                                 svnCmd += _T(" /deletepathfile");\r
1374                                 break;\r
1375                         case ShellMenuUnIgnoreCaseSensitive:\r
1376                                 tempfile = WriteFileListToTempFile();\r
1377                                 svnCmd += _T("unignore /pathfile:\"");\r
1378                                 svnCmd += tempfile;\r
1379                                 svnCmd += _T("\"");\r
1380                                 svnCmd += _T(" /deletepathfile");\r
1381                                 svnCmd += _T(" /onlymask");\r
1382                                 break;\r
1383                         case ShellMenuRevert:\r
1384                                 tempfile = WriteFileListToTempFile();\r
1385                                 svnCmd += _T("revert /pathfile:\"");\r
1386                                 svnCmd += tempfile;\r
1387                                 svnCmd += _T("\"");\r
1388                                 svnCmd += _T(" /deletepathfile");\r
1389                                 break;\r
1390                         case ShellMenuDelUnversioned:\r
1391                                 svnCmd += _T("delunversioned /path:\"");\r
1392                                 svnCmd += folder_;\r
1393                                 svnCmd += _T("\"");\r
1394                                 break;\r
1395                         case ShellMenuCleanup:\r
1396                                 tempfile = WriteFileListToTempFile();\r
1397                                 svnCmd += _T("cleanup /pathfile:\"");\r
1398                                 svnCmd += tempfile;\r
1399                                 svnCmd += _T("\"");\r
1400                                 svnCmd += _T(" /deletepathfile");\r
1401                                 break;\r
1402                         case ShellMenuResolve:\r
1403                                 tempfile = WriteFileListToTempFile();\r
1404                                 svnCmd += _T("resolve /pathfile:\"");\r
1405                                 svnCmd += tempfile;\r
1406                                 svnCmd += _T("\"");\r
1407                                 svnCmd += _T(" /deletepathfile");\r
1408                                 break;\r
1409                         case ShellMenuSwitch:\r
1410                                 svnCmd += _T("switch /path:\"");\r
1411                                 if (files_.size() > 0)\r
1412                                         svnCmd += files_.front();\r
1413                                 else\r
1414                                         svnCmd += folder_;\r
1415                                 svnCmd += _T("\"");\r
1416                                 break;\r
1417                         case ShellMenuImport:\r
1418                                 svnCmd += _T("import /path:\"");\r
1419                                 svnCmd += folder_;\r
1420                                 svnCmd += _T("\"");\r
1421                                 break;\r
1422                         case ShellMenuExport:\r
1423                                 svnCmd += _T("export /path:\"");\r
1424                                 svnCmd += folder_;\r
1425                                 svnCmd += _T("\"");\r
1426                                 break;\r
1427                         case ShellMenuAbout:\r
1428                                 svnCmd += _T("about");\r
1429                                 break;\r
1430                         case ShellMenuCreateRepos:\r
1431                                 svnCmd += _T("repocreate /path:\"");\r
1432                                 svnCmd += folder_;\r
1433                                 svnCmd += _T("\"");\r
1434                                 break;\r
1435                         case ShellMenuMerge:\r
1436                                 svnCmd += _T("merge /path:\"");\r
1437                                 if (files_.size() > 0)\r
1438                                         svnCmd += files_.front();\r
1439                                 else\r
1440                                         svnCmd += folder_;\r
1441                                 svnCmd += _T("\"");\r
1442                                 break;\r
1443                         case ShellMenuMergeAll:\r
1444                                 svnCmd += _T("mergeall /path:\"");\r
1445                                 if (files_.size() > 0)\r
1446                                         svnCmd += files_.front();\r
1447                                 else\r
1448                                         svnCmd += folder_;\r
1449                                 svnCmd += _T("\"");\r
1450                                 break;\r
1451                         case ShellMenuCopy:\r
1452                                 svnCmd += _T("copy /path:\"");\r
1453                                 if (files_.size() > 0)\r
1454                                         svnCmd += files_.front();\r
1455                                 else\r
1456                                         svnCmd += folder_;\r
1457                                 svnCmd += _T("\"");\r
1458                                 break;\r
1459                         case ShellMenuSettings:\r
1460                                 svnCmd += _T("settings");\r
1461                                 break;\r
1462                         case ShellMenuHelp:\r
1463                                 svnCmd += _T("help");\r
1464                                 break;\r
1465                         case ShellMenuRename:\r
1466                                 svnCmd += _T("rename /path:\"");\r
1467                                 if (files_.size() > 0)\r
1468                                         svnCmd += files_.front();\r
1469                                 else\r
1470                                         svnCmd += folder_;\r
1471                                 svnCmd += _T("\"");\r
1472                                 break;\r
1473                         case ShellMenuRemove:\r
1474                                 tempfile = WriteFileListToTempFile();\r
1475                                 svnCmd += _T("remove /pathfile:\"");\r
1476                                 svnCmd += tempfile;\r
1477                                 svnCmd += _T("\"");\r
1478                                 svnCmd += _T(" /deletepathfile");\r
1479                                 break;\r
1480                         case ShellMenuRemoveKeep:\r
1481                                 tempfile = WriteFileListToTempFile();\r
1482                                 svnCmd += _T("remove /pathfile:\"");\r
1483                                 svnCmd += tempfile;\r
1484                                 svnCmd += _T("\"");\r
1485                                 svnCmd += _T(" /deletepathfile");\r
1486                                 svnCmd += _T(" /keep");\r
1487                                 break;\r
1488                         case ShellMenuDiff:\r
1489                                 svnCmd += _T("diff /path:\"");\r
1490                                 if (files_.size() == 1)\r
1491                                         svnCmd += files_.front();\r
1492                                 else if (files_.size() == 2)\r
1493                                 {\r
1494                                         std::vector<stdstring>::iterator I = files_.begin();\r
1495                                         svnCmd += *I;\r
1496                                         I++;\r
1497                                         svnCmd += _T("\" /path2:\"");\r
1498                                         svnCmd += *I;\r
1499                                 }\r
1500                                 else\r
1501                                         svnCmd += folder_;\r
1502                                 svnCmd += _T("\"");\r
1503                                 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)\r
1504                                         svnCmd += _T(" /alternative");\r
1505                                 break;\r
1506                         case ShellMenuPrevDiff:\r
1507                                 svnCmd += _T("prevdiff /path:\"");\r
1508                                 if (files_.size() == 1)\r
1509                                         svnCmd += files_.front();\r
1510                                 else\r
1511                                         svnCmd += folder_;\r
1512                                 svnCmd += _T("\"");\r
1513                                 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)\r
1514                                         svnCmd += _T(" /alternative");\r
1515                                 break;\r
1516                         case ShellMenuUrlDiff:\r
1517                                 svnCmd += _T("urldiff /path:\"");\r
1518                                 if (files_.size() == 1)\r
1519                                         svnCmd += files_.front();\r
1520                                 else\r
1521                                         svnCmd += folder_;\r
1522                                 svnCmd += _T("\"");\r
1523                                 break;\r
1524                         case ShellMenuDropCopyAdd:\r
1525                                 tempfile = WriteFileListToTempFile();\r
1526                                 svnCmd += _T("dropcopyadd /pathfile:\"");\r
1527                                 svnCmd += tempfile;\r
1528                                 svnCmd += _T("\"");\r
1529                                 svnCmd += _T(" /deletepathfile");\r
1530                                 svnCmd += _T(" /droptarget:\"");\r
1531                                 svnCmd += folder_;\r
1532                                 svnCmd += _T("\"";)\r
1533                                         break;\r
1534                         case ShellMenuDropCopy:\r
1535                                 tempfile = WriteFileListToTempFile();\r
1536                                 svnCmd += _T("dropcopy /pathfile:\"");\r
1537                                 svnCmd += tempfile;\r
1538                                 svnCmd += _T("\"");\r
1539                                 svnCmd += _T(" /deletepathfile");\r
1540                                 svnCmd += _T(" /droptarget:\"");\r
1541                                 svnCmd += folder_;\r
1542                                 svnCmd += _T("\"";)\r
1543                                         break;\r
1544                         case ShellMenuDropCopyRename:\r
1545                                 tempfile = WriteFileListToTempFile();\r
1546                                 svnCmd += _T("dropcopy /pathfile:\"");\r
1547                                 svnCmd += tempfile;\r
1548                                 svnCmd += _T("\"");\r
1549                                 svnCmd += _T(" /deletepathfile");\r
1550                                 svnCmd += _T(" /droptarget:\"");\r
1551                                 svnCmd += folder_;\r
1552                                 svnCmd += _T("\" /rename";)\r
1553                                         break;\r
1554                         case ShellMenuDropMove:\r
1555                                 tempfile = WriteFileListToTempFile();\r
1556                                 svnCmd += _T("dropmove /pathfile:\"");\r
1557                                 svnCmd += tempfile;\r
1558                                 svnCmd += _T("\"");\r
1559                                 svnCmd += _T(" /deletepathfile");\r
1560                                 svnCmd += _T(" /droptarget:\"");\r
1561                                 svnCmd += folder_;\r
1562                                 svnCmd += _T("\"");\r
1563                                 break;\r
1564                         case ShellMenuDropMoveRename:\r
1565                                 tempfile = WriteFileListToTempFile();\r
1566                                 svnCmd += _T("dropmove /pathfile:\"");\r
1567                                 svnCmd += tempfile;\r
1568                                 svnCmd += _T("\"");\r
1569                                 svnCmd += _T(" /deletepathfile");\r
1570                                 svnCmd += _T(" /droptarget:\"");\r
1571                                 svnCmd += folder_;\r
1572                                 svnCmd += _T("\" /rename";)\r
1573                                 break;\r
1574                         case ShellMenuDropExport:\r
1575                                 tempfile = WriteFileListToTempFile();\r
1576                                 svnCmd += _T("dropexport /pathfile:\"");\r
1577                                 svnCmd += tempfile;\r
1578                                 svnCmd += _T("\"");\r
1579                                 svnCmd += _T(" /deletepathfile");\r
1580                                 svnCmd += _T(" /droptarget:\"");\r
1581                                 svnCmd += folder_;\r
1582                                 svnCmd += _T("\"");\r
1583                                 break;\r
1584                         case ShellMenuDropExportExtended:\r
1585                                 tempfile = WriteFileListToTempFile();\r
1586                                 svnCmd += _T("dropexport /pathfile:\"");\r
1587                                 svnCmd += tempfile;\r
1588                                 svnCmd += _T("\"");\r
1589                                 svnCmd += _T(" /deletepathfile");\r
1590                                 svnCmd += _T(" /droptarget:\"");\r
1591                                 svnCmd += folder_;\r
1592                                 svnCmd += _T("\"");\r
1593                                 svnCmd += _T(" /extended");\r
1594                                 break;\r
1595                         case ShellMenuLog:\r
1596                                 svnCmd += _T("log /path:\"");\r
1597                                 if (files_.size() > 0)\r
1598                                         svnCmd += files_.front();\r
1599                                 else\r
1600                                         svnCmd += folder_;\r
1601                                 svnCmd += _T("\"");\r
1602                                 break;\r
1603                         case ShellMenuConflictEditor:\r
1604                                 svnCmd += _T("conflicteditor /path:\"");\r
1605                                 if (files_.size() > 0)\r
1606                                         svnCmd += files_.front();\r
1607                                 else\r
1608                                         svnCmd += folder_;\r
1609                                 svnCmd += _T("\"");\r
1610                                 break;\r
1611                         case ShellMenuRelocate:\r
1612                                 svnCmd += _T("relocate /path:\"");\r
1613                                 if (files_.size() > 0)\r
1614                                         svnCmd += files_.front();\r
1615                                 else\r
1616                                         svnCmd += folder_;\r
1617                                 svnCmd += _T("\"");\r
1618                                 break;\r
1619                         case ShellMenuShowChanged:\r
1620                                 if (files_.size() > 1)\r
1621                 {\r
1622                                     tempfile = WriteFileListToTempFile();\r
1623                                     svnCmd += _T("repostatus /pathfile:\"");\r
1624                                     svnCmd += tempfile;\r
1625                                 svnCmd += _T("\"");\r
1626                                 svnCmd += _T(" /deletepathfile");\r
1627                 }\r
1628                 else\r
1629                 {\r
1630                     svnCmd += _T("repostatus /path:\"");\r
1631                                     if (files_.size() > 0)\r
1632                                             svnCmd += files_.front();\r
1633                                     else\r
1634                                             svnCmd += folder_;\r
1635                                 svnCmd += _T("\"");\r
1636                 }\r
1637                                 break;\r
1638                         case ShellMenuRepoBrowse:\r
1639                                 svnCmd += _T("repobrowser /path:\"");\r
1640                                 if (files_.size() > 0)\r
1641                                         svnCmd += files_.front();\r
1642                                 else\r
1643                                         svnCmd += folder_;\r
1644                                 svnCmd += _T("\"");\r
1645                                 break;\r
1646                         case ShellMenuBlame:\r
1647                                 svnCmd += _T("blame /path:\"");\r
1648                                 if (files_.size() > 0)\r
1649                                         svnCmd += files_.front();\r
1650                                 else\r
1651                                         svnCmd += folder_;\r
1652                                 svnCmd += _T("\"");\r
1653                                 break;\r
1654                         case ShellMenuCreatePatch:\r
1655                                 tempfile = WriteFileListToTempFile();\r
1656                                 svnCmd += _T("createpatch /pathfile:\"");\r
1657                                 svnCmd += tempfile;\r
1658                                 svnCmd += _T("\"");\r
1659                                 svnCmd += _T(" /deletepathfile");\r
1660                                 break;\r
1661                         case ShellMenuApplyPatch:\r
1662                                 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))\r
1663                                 {\r
1664                                         // if there's a patch file in the clipboard, we save it\r
1665                                         // to a temporary file and tell TortoiseMerge to use that one\r
1666                                         UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));\r
1667                                         if ((cFormat)&&(OpenClipboard(NULL)))\r
1668                                         { \r
1669                                                 HGLOBAL hglb = GetClipboardData(cFormat); \r
1670                                                 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb); \r
1671 \r
1672                                                 DWORD len = GetTempPath(0, NULL);\r
1673                                                 TCHAR * path = new TCHAR[len+1];\r
1674                                                 TCHAR * tempF = new TCHAR[len+100];\r
1675                                                 GetTempPath (len+1, path);\r
1676                                                 GetTempFileName (path, TEXT("git"), 0, tempF);\r
1677                                                 std::wstring sTempFile = std::wstring(tempF);\r
1678                                                 delete [] path;\r
1679                                                 delete [] tempF;\r
1680 \r
1681                                                 FILE * outFile;\r
1682                                                 size_t patchlen = strlen(lpstr);\r
1683                                                 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));\r
1684                                                 if(outFile)\r
1685                                                 {\r
1686                                                         size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);\r
1687                                                         if (size == patchlen)\r
1688                                                         {\r
1689                                                                 itemStates |= ITEMIS_PATCHFILE;\r
1690                                                                 files_.clear();\r
1691                                                                 files_.push_back(sTempFile);\r
1692                                                         }\r
1693                                                         fclose(outFile);\r
1694                                                 }\r
1695                                                 GlobalUnlock(hglb); \r
1696                                                 CloseClipboard(); \r
1697                                         } \r
1698                                 }\r
1699                                 if (itemStates & ITEMIS_PATCHFILE)\r
1700                                 {\r
1701                                         svnCmd = _T(" /diff:\"");\r
1702                                         if (files_.size() > 0)\r
1703                                         {\r
1704                                                 svnCmd += files_.front();\r
1705                                                 if (itemStatesFolder & ITEMIS_FOLDERINSVN)\r
1706                                                 {\r
1707                                                         svnCmd += _T("\" /patchpath:\"");\r
1708                                                         svnCmd += folder_;\r
1709                                                 }\r
1710                                         }\r
1711                                         else\r
1712                                                 svnCmd += folder_;\r
1713                                         if (itemStates & ITEMIS_INVERSIONEDFOLDER)\r
1714                                                 svnCmd += _T("\" /wc");\r
1715                                         else\r
1716                                                 svnCmd += _T("\"");\r
1717                                 }\r
1718                                 else\r
1719                                 {\r
1720                                         svnCmd = _T(" /patchpath:\"");\r
1721                                         if (files_.size() > 0)\r
1722                                                 svnCmd += files_.front();\r
1723                                         else\r
1724                                                 svnCmd += folder_;\r
1725                                         svnCmd += _T("\"");\r
1726                                 }\r
1727                                 myIDMap.clear();\r
1728                                 myVerbsIDMap.clear();\r
1729                                 myVerbsMap.clear();\r
1730                                 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)\r
1731                                 {\r
1732                                         LPVOID lpMsgBuf;\r
1733                                         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
1734                                                 FORMAT_MESSAGE_FROM_SYSTEM | \r
1735                                                 FORMAT_MESSAGE_IGNORE_INSERTS,\r
1736                                                 NULL,\r
1737                                                 GetLastError(),\r
1738                                                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\r
1739                                                 (LPTSTR) &lpMsgBuf,\r
1740                                                 0,\r
1741                                                 NULL \r
1742                                                 );\r
1743                                         MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );\r
1744                                         LocalFree( lpMsgBuf );\r
1745                                 }\r
1746                                 CloseHandle(process.hThread);\r
1747                                 CloseHandle(process.hProcess);\r
1748                                 return NOERROR;\r
1749                                 break;\r
1750                         case ShellMenuRevisionGraph:\r
1751                                 svnCmd += _T("revisiongraph /path:\"");\r
1752                                 if (files_.size() > 0)\r
1753                                         svnCmd += files_.front();\r
1754                                 else\r
1755                                         svnCmd += folder_;\r
1756                                 svnCmd += _T("\"");\r
1757                                 break;\r
1758                         case ShellMenuLock:\r
1759                                 tempfile = WriteFileListToTempFile();\r
1760                                 svnCmd += _T("lock /pathfile:\"");\r
1761                                 svnCmd += tempfile;\r
1762                                 svnCmd += _T("\"");\r
1763                                 svnCmd += _T(" /deletepathfile");\r
1764                                 break;\r
1765                         case ShellMenuUnlock:\r
1766                                 tempfile = WriteFileListToTempFile();\r
1767                                 svnCmd += _T("unlock /pathfile:\"");\r
1768                                 svnCmd += tempfile;\r
1769                                 svnCmd += _T("\"");\r
1770                                 svnCmd += _T(" /deletepathfile");\r
1771                                 break;\r
1772                         case ShellMenuUnlockForce:\r
1773                                 tempfile = WriteFileListToTempFile();\r
1774                                 svnCmd += _T("unlock /pathfile:\"");\r
1775                                 svnCmd += tempfile;\r
1776                                 svnCmd += _T("\"");\r
1777                                 svnCmd += _T(" /deletepathfile");\r
1778                                 svnCmd += _T(" /force");\r
1779                                 break;\r
1780                         case ShellMenuProperties:\r
1781                                 tempfile = WriteFileListToTempFile();\r
1782                                 svnCmd += _T("properties /pathfile:\"");\r
1783                                 svnCmd += tempfile;\r
1784                                 svnCmd += _T("\"");\r
1785                                 svnCmd += _T(" /deletepathfile");\r
1786                                 break;\r
1787                         case ShellMenuClipPaste:\r
1788                                 if (WriteClipboardPathsToTempFile(tempfile))\r
1789                                 {\r
1790                                         bool bCopy = true;\r
1791                                         UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));\r
1792                                         if (cPrefDropFormat)\r
1793                                         {\r
1794                                                 if (OpenClipboard(lpcmi->hwnd))\r
1795                                                 {\r
1796                                                         HGLOBAL hglb = GetClipboardData(cPrefDropFormat);\r
1797                                                         if (hglb)\r
1798                                                         {\r
1799                                                                 DWORD* effect = (DWORD*) GlobalLock(hglb);\r
1800                                                                 if (*effect == DROPEFFECT_MOVE)\r
1801                                                                         bCopy = false;\r
1802                                                                 GlobalUnlock(hglb);\r
1803                                                         }\r
1804                                                         CloseClipboard();\r
1805                                                 }\r
1806                                         }\r
1807 \r
1808                                         if (bCopy)\r
1809                                                 svnCmd += _T("pastecopy /pathfile:\"");\r
1810                                         else\r
1811                                                 svnCmd += _T("pastemove /pathfile:\"");\r
1812                                         svnCmd += tempfile;\r
1813                                         svnCmd += _T("\"");\r
1814                                         svnCmd += _T(" /deletepathfile");\r
1815                                         svnCmd += _T(" /droptarget:\"");\r
1816                                         svnCmd += folder_;\r
1817                                         svnCmd += _T("\"");\r
1818                                 }\r
1819                                 else return NOERROR;\r
1820                                 break;\r
1821                         case ShellMenuClone:\r
1822                                 svnCmd += _T("clone /path:\"");\r
1823                                 svnCmd += folder_;\r
1824                                 svnCmd += _T("\"");\r
1825                                 break;\r
1826                         case ShellMenuPull:\r
1827                                 svnCmd += _T("pull /path:\"");\r
1828                                 if (files_.size() > 0)\r
1829                                         svnCmd += files_.front();\r
1830                                 else\r
1831                                         svnCmd += folder_;\r
1832                                 svnCmd += _T("\"");\r
1833                                 break;\r
1834                         case ShellMenuPush:\r
1835                                 svnCmd += _T("push /path:\"");\r
1836                                 if (files_.size() > 0)\r
1837                                         svnCmd += files_.front();\r
1838                                 else\r
1839                                         svnCmd += folder_;\r
1840                                 svnCmd += _T("\"");\r
1841                                 break;\r
1842                         case ShellMenuBranch:\r
1843                                 svnCmd += _T("branch /path:\"");\r
1844                                 if (files_.size() > 0)\r
1845                                         svnCmd += files_.front();\r
1846                                 else\r
1847                                         svnCmd += folder_;\r
1848                                 svnCmd += _T("\"");\r
1849                                 break;\r
1850                         \r
1851                         case ShellMenuTag:\r
1852                                 svnCmd += _T("tag /path:\"");\r
1853                                 if (files_.size() > 0)\r
1854                                         svnCmd += files_.front();\r
1855                                 else\r
1856                                         svnCmd += folder_;\r
1857                                 svnCmd += _T("\"");\r
1858                                 break;\r
1859 \r
1860                         case ShellMenuFormatPatch:\r
1861                                 svnCmd += _T("formatpatch /path:\"");\r
1862                                 if (files_.size() > 0)\r
1863                                         svnCmd += files_.front();\r
1864                                 else\r
1865                                         svnCmd += folder_;\r
1866                                 svnCmd += _T("\"");\r
1867                                 break;\r
1868 \r
1869                         case ShellMenuImportPatch:\r
1870                                 svnCmd += _T("importpatch /path:\"");\r
1871                                 if (files_.size() > 0)\r
1872                                         svnCmd += files_.front();\r
1873                                 else\r
1874                                         svnCmd += folder_;\r
1875                                 svnCmd += _T("\"");\r
1876                                 break;\r
1877 \r
1878                         case ShellMenuCherryPick:\r
1879                                 svnCmd += _T("cherrypick /path:\"");\r
1880                                 if (files_.size() > 0)\r
1881                                         svnCmd += files_.front();\r
1882                                 else\r
1883                                         svnCmd += folder_;\r
1884                                 svnCmd += _T("\"");\r
1885                                 break;\r
1886                         case ShellMenuFetch:\r
1887                                 svnCmd += _T("fetch /path:\"");\r
1888                                 if (files_.size() > 0)\r
1889                                         svnCmd += files_.front();\r
1890                                 else\r
1891                                         svnCmd += folder_;\r
1892                                 svnCmd += _T("\"");\r
1893                                 break;\r
1894 \r
1895                         default:\r
1896                                 break;\r
1897                                 //#endregion\r
1898                         } // switch (id_it->second) \r
1899                         svnCmd += _T(" /hwnd:");\r
1900                         TCHAR buf[30];\r
1901                         _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);\r
1902                         svnCmd += buf;\r
1903                         myIDMap.clear();\r
1904                         myVerbsIDMap.clear();\r
1905                         myVerbsMap.clear();\r
1906                         if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)\r
1907                         {\r
1908                                 LPVOID lpMsgBuf;\r
1909                                 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r
1910                                         FORMAT_MESSAGE_FROM_SYSTEM | \r
1911                                         FORMAT_MESSAGE_IGNORE_INSERTS,\r
1912                                         NULL,\r
1913                                         GetLastError(),\r
1914                                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\r
1915                                         (LPTSTR) &lpMsgBuf,\r
1916                                         0,\r
1917                                         NULL \r
1918                                         );\r
1919                                 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );\r
1920                                 LocalFree( lpMsgBuf );\r
1921                         }\r
1922                         CloseHandle(process.hThread);\r
1923                         CloseHandle(process.hProcess);\r
1924                         hr = NOERROR;\r
1925                 } // if (id_it != myIDMap.end() && id_it->first == idCmd) \r
1926         } // if ((files_.size() > 0)||(folder_.size() > 0)) \r
1927         return hr;\r
1928 \r
1929 }\r
1930 \r
1931 // This is for the status bar and things like that:\r
1932 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,\r
1933                                          UINT uFlags,\r
1934                                          UINT FAR * /*reserved*/,\r
1935                                          LPSTR pszName,\r
1936                                          UINT cchMax)\r
1937 {\r
1938         PreserveChdir preserveChdir;\r
1939         //do we know the id?\r
1940         std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);\r
1941         if (id_it == myIDMap.end() || id_it->first != idCmd)\r
1942         {\r
1943                 return E_INVALIDARG;            //no, we don't\r
1944         }\r
1945 \r
1946         LoadLangDll();\r
1947         HRESULT hr = E_INVALIDARG;\r
1948 \r
1949         MAKESTRING(IDS_MENUDESCDEFAULT);\r
1950         int menuIndex = 0;\r
1951         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
1952         {\r
1953                 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)\r
1954                 {\r
1955                         MAKESTRING(menuInfo[menuIndex].menuDescID);\r
1956                         break;\r
1957                 }\r
1958                 menuIndex++;\r
1959         }\r
1960 \r
1961         const TCHAR * desc = stringtablebuffer;\r
1962         switch(uFlags)\r
1963         {\r
1964         case GCS_HELPTEXTA:\r
1965                 {\r
1966                         std::string help = WideToMultibyte(desc);\r
1967                         lstrcpynA(pszName, help.c_str(), cchMax);\r
1968                         hr = S_OK;\r
1969                         break; \r
1970                 }\r
1971         case GCS_HELPTEXTW: \r
1972                 {\r
1973                         wide_string help = desc;\r
1974                         lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax); \r
1975                         hr = S_OK;\r
1976                         break; \r
1977                 }\r
1978         case GCS_VERBA:\r
1979                 {\r
1980                         std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);\r
1981                         if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)\r
1982                         {\r
1983                                 std::string help = WideToMultibyte(verb_id_it->second);\r
1984                                 lstrcpynA(pszName, help.c_str(), cchMax);\r
1985                                 hr = S_OK;\r
1986                         }\r
1987                 }\r
1988                 break;\r
1989         case GCS_VERBW:\r
1990                 {\r
1991                         std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);\r
1992                         if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)\r
1993                         {\r
1994                                 wide_string help = verb_id_it->second;\r
1995                                 ATLTRACE("verb : %ws\n", help.c_str());\r
1996                                 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax); \r
1997                                 hr = S_OK;\r
1998                         }\r
1999                 }\r
2000                 break;\r
2001         }\r
2002         return hr;\r
2003 }\r
2004 \r
2005 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
2006 {\r
2007         LRESULT res;\r
2008         return HandleMenuMsg2(uMsg, wParam, lParam, &res);\r
2009 }\r
2010 \r
2011 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)\r
2012 {\r
2013         PreserveChdir preserveChdir;\r
2014 \r
2015         LRESULT res;\r
2016         if (pResult == NULL)\r
2017                 pResult = &res;\r
2018         *pResult = FALSE;\r
2019 \r
2020         LoadLangDll();\r
2021         switch (uMsg)\r
2022         {\r
2023         case WM_MEASUREITEM:\r
2024                 {\r
2025                         MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;\r
2026                         if (lpmis==NULL)\r
2027                                 break;\r
2028                         lpmis->itemWidth += 2;\r
2029                         if (lpmis->itemHeight < 16)\r
2030                                 lpmis->itemHeight = 16;\r
2031                         *pResult = TRUE;\r
2032                 }\r
2033                 break;\r
2034         case WM_DRAWITEM:\r
2035                 {\r
2036                         LPCTSTR resource;\r
2037                         DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;\r
2038                         if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))\r
2039                                 return S_OK;            //not for a menu\r
2040                         resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);\r
2041                         if (resource == NULL)\r
2042                                 return S_OK;\r
2043                         HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);\r
2044                         if (hIcon == NULL)\r
2045                                 return S_OK;\r
2046                         DrawIconEx(lpdis->hDC,\r
2047                                 lpdis->rcItem.left - 16,\r
2048                                 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,\r
2049                                 hIcon, 16, 16,\r
2050                                 0, NULL, DI_NORMAL);\r
2051                         DestroyIcon(hIcon);\r
2052                         *pResult = TRUE;\r
2053                 }\r
2054                 break;\r
2055         case WM_MENUCHAR:\r
2056                 {\r
2057                         LPCTSTR resource;\r
2058                         TCHAR *szItem;\r
2059                         if (HIWORD(wParam) != MF_POPUP)\r
2060                                 return NOERROR;\r
2061                         int nChar = LOWORD(wParam);\r
2062                         if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))\r
2063                                 nChar = tolower(nChar);\r
2064                         // we have the char the user pressed, now search that char in all our\r
2065                         // menu items\r
2066                         std::vector<int> accmenus;\r
2067                         for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)\r
2068                         {\r
2069                                 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);\r
2070                                 if (resource == NULL)\r
2071                                         continue;\r
2072                                 szItem = stringtablebuffer;\r
2073                                 TCHAR * amp = _tcschr(szItem, '&');\r
2074                                 if (amp == NULL)\r
2075                                         continue;\r
2076                                 amp++;\r
2077                                 int ampChar = LOWORD(*amp);\r
2078                                 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))\r
2079                                         ampChar = tolower(ampChar);\r
2080                                 if (ampChar == nChar)\r
2081                                 {\r
2082                                         // yep, we found a menu which has the pressed key\r
2083                                         // as an accelerator. Add that menu to the list to\r
2084                                         // process later.\r
2085                                         accmenus.push_back(It->first);\r
2086                                 }\r
2087                         }\r
2088                         if (accmenus.size() == 0)\r
2089                         {\r
2090                                 // no menu with that accelerator key.\r
2091                                 *pResult = MAKELONG(0, MNC_IGNORE);\r
2092                                 return NOERROR;\r
2093                         }\r
2094                         if (accmenus.size() == 1)\r
2095                         {\r
2096                                 // Only one menu with that accelerator key. We're lucky!\r
2097                                 // So just execute that menu entry.\r
2098                                 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);\r
2099                                 return NOERROR;\r
2100                         }\r
2101                         if (accmenus.size() > 1)\r
2102                         {\r
2103                                 // we have more than one menu item with this accelerator key!\r
2104                                 MENUITEMINFO mif;\r
2105                                 mif.cbSize = sizeof(MENUITEMINFO);\r
2106                                 mif.fMask = MIIM_STATE;\r
2107                                 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)\r
2108                                 {\r
2109                                         GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);\r
2110                                         if (mif.fState == MFS_HILITE)\r
2111                                         {\r
2112                                                 // this is the selected item, so select the next one\r
2113                                                 ++it;\r
2114                                                 if (it == accmenus.end())\r
2115                                                         *pResult = MAKELONG(accmenus[0], MNC_SELECT);\r
2116                                                 else\r
2117                                                         *pResult = MAKELONG(*it, MNC_SELECT);\r
2118                                                 return NOERROR;\r
2119                                         }\r
2120                                 }\r
2121                                 *pResult = MAKELONG(accmenus[0], MNC_SELECT);\r
2122                         }\r
2123                 }\r
2124                 break;\r
2125         default:\r
2126                 return NOERROR;\r
2127         }\r
2128 \r
2129         return NOERROR;\r
2130 }\r
2131 \r
2132 LPCTSTR CShellExt::GetMenuTextFromResource(int id)\r
2133 {\r
2134         TCHAR textbuf[255];\r
2135         LPCTSTR resource = NULL;\r
2136         unsigned __int64 layout = g_ShellCache.GetMenuLayout();\r
2137         space = 6;\r
2138 \r
2139         int menuIndex = 0;\r
2140         while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
2141         {\r
2142                 if (menuInfo[menuIndex].command == id)\r
2143                 {\r
2144                         MAKESTRING(menuInfo[menuIndex].menuTextID);\r
2145                         resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);\r
2146                         switch (id)\r
2147                         {\r
2148                         case ShellMenuLock:\r
2149                                 // menu lock is special because it can be set to the top\r
2150                                 // with a separate option in the registry\r
2151                                 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;\r
2152                                 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))\r
2153                                 {\r
2154                                         _tcscpy_s(textbuf, 255, _T("Git "));\r
2155                                         _tcscat_s(textbuf, 255, stringtablebuffer);\r
2156                                         _tcscpy_s(stringtablebuffer, 255, textbuf);\r
2157                                 }\r
2158                                 break;\r
2159                                 // the sub menu entries are special because they're *always* on the top level menu\r
2160                         case ShellSubMenuMultiple:\r
2161                         case ShellSubMenuLink:\r
2162                         case ShellSubMenuFolder:\r
2163                         case ShellSubMenuFile:\r
2164                         case ShellSubMenu:\r
2165                                 space = 0;\r
2166                                 break;\r
2167                         default:\r
2168                                 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;\r
2169                                 if (layout & (menuInfo[menuIndex].menuID)) \r
2170                                 {\r
2171                                         _tcscpy_s(textbuf, 255, _T("Git "));\r
2172                                         _tcscat_s(textbuf, 255, stringtablebuffer);\r
2173                                         _tcscpy_s(stringtablebuffer, 255, textbuf);\r
2174                                 }\r
2175                                 break;\r
2176                         }\r
2177                         return resource;\r
2178                 }\r
2179                 menuIndex++;\r
2180         }\r
2181         return NULL;\r
2182 }\r
2183 \r
2184 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)\r
2185 {\r
2186         int i=0;\r
2187         TCHAR buf[MAX_PATH];    //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!\r
2188         LPITEMIDLIST pidl = NULL;\r
2189         while (cslidarray[i])\r
2190         {\r
2191                 ++i;\r
2192                 pidl = NULL;\r
2193                 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)\r
2194                         continue;\r
2195                 if (!SHGetPathFromIDList(pidl, buf))\r
2196                 {\r
2197                         // not a file system path, definitely illegal for our use\r
2198                         CoTaskMemFree(pidl);\r
2199                         continue;\r
2200                 }\r
2201                 CoTaskMemFree(pidl);\r
2202                 if (_tcslen(buf)==0)\r
2203                         continue;\r
2204                 if (_tcscmp(buf, folder.c_str())==0)\r
2205                         return true;\r
2206         }\r
2207         return false;\r
2208 }\r
2209 \r
2210 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)\r
2211 {\r
2212         HMENU ignoresubmenu = NULL;\r
2213         int indexignoresub = 0;\r
2214         bool bShowIgnoreMenu = false;\r
2215         TCHAR maskbuf[MAX_PATH];                // MAX_PATH is ok, since this only holds a filename\r
2216         TCHAR ignorepath[MAX_PATH];             // MAX_PATH is ok, since this only holds a filename\r
2217         if (files_.size() == 0)\r
2218                 return;\r
2219         UINT icon = bShowIcons ? IDI_IGNORE : 0;\r
2220 \r
2221         std::vector<stdstring>::iterator I = files_.begin();\r
2222         if (_tcsrchr(I->c_str(), '\\'))\r
2223                 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);\r
2224         else\r
2225                 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());\r
2226         if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))\r
2227         {\r
2228                 // check if the item name is ignored or the mask\r
2229                 size_t p = 0;\r
2230                 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )\r
2231                 {\r
2232                         if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))\r
2233                                 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )\r
2234                         {\r
2235                                 break;\r
2236                         }\r
2237                         p++;\r
2238                 }\r
2239                 if (p!=-1)\r
2240                 {\r
2241                         ignoresubmenu = CreateMenu();\r
2242                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2243                         stdstring verb = stdstring(ignorepath);\r
2244                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2245                         myVerbsMap[verb] = idCmd;\r
2246                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2247                         myVerbsIDMap[idCmd] = verb;\r
2248                         myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;\r
2249                         myIDMap[idCmd++] = ShellMenuUnIgnore;\r
2250                         bShowIgnoreMenu = true;\r
2251                 }\r
2252                 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));\r
2253                 if (_tcsrchr(ignorepath, '.'))\r
2254                 {\r
2255                         _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));\r
2256                         p = ignoredprops.find(maskbuf);\r
2257                         if ((p!=-1) &&\r
2258                                 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))\r
2259                         {\r
2260                                 if (ignoresubmenu==NULL)\r
2261                                         ignoresubmenu = CreateMenu();\r
2262 \r
2263                                 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);\r
2264                                 stdstring verb = stdstring(maskbuf);\r
2265                                 myVerbsMap[verb] = idCmd - idCmdFirst;\r
2266                                 myVerbsMap[verb] = idCmd;\r
2267                                 myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2268                                 myVerbsIDMap[idCmd] = verb;\r
2269                                 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;\r
2270                                 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;\r
2271                                 bShowIgnoreMenu = true;\r
2272                         }\r
2273                 }\r
2274         }\r
2275         else if ((itemStates & ITEMIS_IGNORED) == 0)\r
2276         {\r
2277                 bShowIgnoreMenu = true;\r
2278                 ignoresubmenu = CreateMenu();\r
2279                 if (itemStates & ITEMIS_ONLYONE)\r
2280                 {\r
2281                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2282                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;\r
2283                         myIDMap[idCmd++] = ShellMenuIgnore;\r
2284 \r
2285                         _tcscpy_s(maskbuf, MAX_PATH, _T("*"));\r
2286                         if (_tcsrchr(ignorepath, '.'))\r
2287                         {\r
2288                                 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));\r
2289                                 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);\r
2290                                 stdstring verb = stdstring(maskbuf);\r
2291                                 myVerbsMap[verb] = idCmd - idCmdFirst;\r
2292                                 myVerbsMap[verb] = idCmd;\r
2293                                 myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2294                                 myVerbsIDMap[idCmd] = verb;\r
2295                                 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;\r
2296                                 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;\r
2297                         }\r
2298                 }\r
2299                 else\r
2300                 {\r
2301                         MAKESTRING(IDS_MENUIGNOREMULTIPLE);\r
2302                         _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());\r
2303                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2304                         stdstring verb = stdstring(ignorepath);\r
2305                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2306                         myVerbsMap[verb] = idCmd;\r
2307                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2308                         myVerbsIDMap[idCmd] = verb;\r
2309                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;\r
2310                         myIDMap[idCmd++] = ShellMenuIgnore;\r
2311 \r
2312                         MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);\r
2313                         _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());\r
2314                         InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);\r
2315                         verb = stdstring(ignorepath);\r
2316                         myVerbsMap[verb] = idCmd - idCmdFirst;\r
2317                         myVerbsMap[verb] = idCmd;\r
2318                         myVerbsIDMap[idCmd - idCmdFirst] = verb;\r
2319                         myVerbsIDMap[idCmd] = verb;\r
2320                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;\r
2321                         myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;\r
2322                 }\r
2323         }\r
2324 \r
2325         if (bShowIgnoreMenu)\r
2326         {\r
2327                 MENUITEMINFO menuiteminfo;\r
2328                 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
2329                 menuiteminfo.cbSize = sizeof(menuiteminfo);\r
2330                 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
2331                 menuiteminfo.fType = MFT_STRING;\r
2332                 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);\r
2333                 if (icon)\r
2334                         menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;\r
2335                 menuiteminfo.hbmpChecked = bmp;\r
2336                 menuiteminfo.hbmpUnchecked = bmp;\r
2337                 menuiteminfo.hSubMenu = ignoresubmenu;\r
2338                 menuiteminfo.wID = idCmd;\r
2339                 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));\r
2340                 if (itemStates & ITEMIS_IGNORED)\r
2341                         GetMenuTextFromResource(ShellMenuUnIgnoreSub);\r
2342                 else\r
2343                         GetMenuTextFromResource(ShellMenuIgnoreSub);\r
2344                 menuiteminfo.dwTypeData = stringtablebuffer;\r
2345                 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);\r
2346 \r
2347                 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);\r
2348                 if (itemStates & ITEMIS_IGNORED)\r
2349                 {\r
2350                         myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;\r
2351                         myIDMap[idCmd++] = ShellMenuUnIgnoreSub;\r
2352                 }\r
2353                 else\r
2354                 {\r
2355                         myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;\r
2356                         myIDMap[idCmd++] = ShellMenuIgnoreSub;\r
2357                 }\r
2358         }\r
2359 }\r
2360 \r
2361 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)\r
2362 {\r
2363         std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);\r
2364         if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)\r
2365                 return bitmap_it->second;\r
2366 \r
2367         HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);\r
2368         if (!hIcon)\r
2369                 return NULL;\r
2370 \r
2371         if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)\r
2372                 return NULL;\r
2373 \r
2374         SIZE sizIcon;\r
2375         sizIcon.cx = GetSystemMetrics(SM_CXSMICON);\r
2376         sizIcon.cy = GetSystemMetrics(SM_CYSMICON);\r
2377 \r
2378         RECT rcIcon;\r
2379         SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);\r
2380         HBITMAP hBmp = NULL;\r
2381 \r
2382         HDC hdcDest = CreateCompatibleDC(NULL);\r
2383         if (hdcDest)\r
2384         {\r
2385                 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))\r
2386                 {\r
2387                         HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);\r
2388                         if (hbmpOld)\r
2389                         {\r
2390                                 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };\r
2391                                 BP_PAINTPARAMS paintParams = {0};\r
2392                                 paintParams.cbSize = sizeof(paintParams);\r
2393                                 paintParams.dwFlags = BPPF_ERASE;\r
2394                                 paintParams.pBlendFunction = &bfAlpha;\r
2395 \r
2396                                 HDC hdcBuffer;\r
2397                                 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);