1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseGit
\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
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
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
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
28 #define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
\r
29 #define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
\r
31 int g_shellidlist=RegisterClipboardFormat(CFSTR_SHELLIDLIST);
\r
33 CShellExt::MenuInfo CShellExt::menuInfo[] =
\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
38 { ShellMenuPull, MENUPULL, IDI_PULL, IDS_MENUPULL,
\r
39 ITEMIS_INSVN, ITEMIS_INSVN, ITEMIS_FOLDERINSVN, 0,0,0, 0,0,0},
\r
40 { ShellMenuPush, MENUPUSH, IDI_PUSH, IDS_MENUPUSH,
\r
41 ITEMIS_INSVN, ITEMIS_INSVN, ITEMIS_FOLDERINSVN, 0,0,0, 0,0,0},
\r
43 // { ShellMenuCheckout, MENUCHECKOUT, IDI_CHECKOUT, IDS_MENUCHECKOUT, IDS_MENUDESCCHECKOUT,
\r
44 // ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
46 // { ShellMenuUpdate, MENUUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
\r
47 // ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
49 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
50 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
52 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
54 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
55 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
57 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
58 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
60 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
61 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
63 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
64 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
66 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
67 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
69 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
70 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
72 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
73 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
75 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
77 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
78 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
80 // { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
81 // ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
83 // { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
84 // ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
86 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
87 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
89 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
90 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
92 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
93 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
95 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
96 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
98 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
99 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
101 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
102 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
104 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
105 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
107 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
108 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
110 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
111 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
113 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
114 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
116 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
118 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
119 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
121 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
122 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
124 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
125 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
126 { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
127 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
129 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
130 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0, 0, 0 },
\r
132 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
133 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
135 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
137 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
138 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
140 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
141 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
143 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
144 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
146 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
147 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
149 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
150 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
152 // { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
153 // ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
155 // { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
156 // ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
158 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
160 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
161 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
163 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
164 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },
\r
166 { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
167 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
169 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
170 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
171 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
173 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
175 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
176 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
177 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
178 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
179 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
180 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
182 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
183 // but they still need to be in here, because we use the icon and string information anyway.
\r
184 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
185 0, 0, 0, 0, 0, 0, 0, 0 },
\r
186 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
187 0, 0, 0, 0, 0, 0, 0, 0 },
\r
188 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
189 0, 0, 0, 0, 0, 0, 0, 0 },
\r
190 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
191 0, 0, 0, 0, 0, 0, 0, 0 },
\r
192 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
193 0, 0, 0, 0, 0, 0, 0, 0 },
\r
194 // mark the last entry to tell the loop where to stop iterating over this array
\r
195 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
196 0, 0, 0, 0, 0, 0, 0, 0 },
\r
200 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
201 LPDATAOBJECT pDataObj,
\r
202 HKEY /* hRegKey */)
\r
205 ATLTRACE("Shell :: Initialize\n");
\r
206 PreserveChdir preserveChdir;
\r
209 uuidSource.erase();
\r
210 uuidTarget.erase();
\r
212 itemStatesFolder = 0;
\r
213 stdstring statuspath;
\r
214 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
215 // get selected files/folders
\r
219 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
220 (DVTARGETDEVICE FAR *)NULL,
\r
224 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
226 if (SUCCEEDED(hres) && medium.hGlobal)
\r
228 if (m_State == FileStateDropHandler)
\r
231 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
232 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
233 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
235 ReleaseStgMedium ( &medium );
\r
236 return E_INVALIDARG;
\r
240 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
241 if ( NULL == drop )
\r
243 ReleaseStgMedium ( &stg );
\r
244 ReleaseStgMedium ( &medium );
\r
245 return E_INVALIDARG;
\r
248 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
250 itemStates |= ITEMIS_ONLYONE;
\r
251 for (int i = 0; i < count; i++)
\r
253 // find the path length in chars
\r
254 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
257 TCHAR * szFileName = new TCHAR[len+1];
\r
258 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
260 delete [] szFileName;
\r
263 stdstring str = stdstring(szFileName);
\r
264 delete [] szFileName;
\r
265 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
267 if (itemStates & ITEMIS_ONLYONE)
\r
270 strpath.SetFromWin(str.c_str());
\r
271 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
272 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
274 files_.push_back(str);
\r
277 //get the Subversion status of the item
\r
278 git_wc_status_kind status = git_wc_status_none;
\r
279 CTGitPath askedpath;
\r
280 askedpath.SetFromWin(str.c_str());
\r
284 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
288 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
289 fetchedstatus = status;
\r
290 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
291 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
292 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
294 // itemStates |= ITEMIS_FOLDER;
\r
295 // if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
296 // itemStates |= ITEMIS_FOLDERINGit;
\r
298 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
300 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
301 // itemStates |= ITEMIS_NEEDSLOCK;
\r
303 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
304 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
308 // sometimes, git_client_status() returns with an error.
\r
309 // in that case, we have to check if the working copy is versioned
\r
310 // anyway to show the 'correct' context menu
\r
311 if (askedpath.HasAdminDir())
\r
312 status = git_wc_status_normal;
\r
317 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
319 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
320 itemStates |= ITEMIS_INSVN;
\r
321 if (status == git_wc_status_ignored)
\r
322 itemStates |= ITEMIS_IGNORED;
\r
323 if (status == git_wc_status_normal)
\r
324 itemStates |= ITEMIS_NORMAL;
\r
325 if (status == git_wc_status_conflicted)
\r
326 itemStates |= ITEMIS_CONFLICTED;
\r
327 if (status == git_wc_status_added)
\r
328 itemStates |= ITEMIS_ADDED;
\r
329 if (status == git_wc_status_deleted)
\r
330 itemStates |= ITEMIS_DELETED;
\r
333 } // for (int i = 0; i < count; i++)
\r
334 GlobalUnlock ( drop );
\r
335 ReleaseStgMedium ( &stg );
\r
337 } // if (m_State == FileStateDropHandler)
\r
341 //Enumerate PIDLs which the user has selected
\r
342 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
343 ItemIDList parent( GetPIDLFolder (cida));
\r
345 int count = cida->cidl;
\r
346 BOOL statfetched = FALSE;
\r
347 for (int i = 0; i < count; ++i)
\r
349 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
350 stdstring str = child.toString();
\r
351 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
353 //check if our menu is requested for a subversion admin directory
\r
354 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
357 files_.push_back(str);
\r
359 strpath.SetFromWin(str.c_str());
\r
360 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
361 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
364 //get the Subversion status of the item
\r
365 git_wc_status_kind status = git_wc_status_none;
\r
366 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
368 if (strpath.HasAdminDir())
\r
369 status = git_wc_status_normal;
\r
376 if (strpath.HasAdminDir())
\r
377 stat.GetStatus(strpath, false, true, true);
\r
381 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
382 fetchedstatus = status;
\r
383 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
384 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
385 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
387 // itemStates |= ITEMIS_FOLDER;
\r
388 // if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
389 // itemStates |= ITEMIS_FOLDERINGit;
\r
391 //if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
392 // itemStates |= ITEMIS_CONFLICTED;
\r
393 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
395 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
396 // itemStates |= ITEMIS_NEEDSLOCK;
\r
398 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
399 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
403 // sometimes, git_client_status() returns with an error.
\r
404 // in that case, we have to check if the working copy is versioned
\r
405 // anyway to show the 'correct' context menu
\r
406 if (strpath.HasAdminDir())
\r
408 status = git_wc_status_normal;
\r
409 fetchedstatus = status;
\r
412 statfetched = TRUE;
\r
416 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
419 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
420 itemStates |= ITEMIS_INSVN;
\r
421 if (status == git_wc_status_ignored)
\r
423 itemStates |= ITEMIS_IGNORED;
\r
424 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
425 // offer a 'remove from ignored list' entry
\r
426 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
427 // ignoredprops.empty();
\r
428 // for (int p=0; p<props.GetCount(); ++p)
\r
430 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
432 // std::string st = props.GetItemValue(p);
\r
433 // ignoredprops = MultibyteToWide(st.c_str());
\r
434 // // remove all escape chars ('\\')
\r
435 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
440 if (status == git_wc_status_normal)
\r
441 itemStates |= ITEMIS_NORMAL;
\r
442 if (status == git_wc_status_conflicted)
\r
443 itemStates |= ITEMIS_CONFLICTED;
\r
444 if (status == git_wc_status_added)
\r
445 itemStates |= ITEMIS_ADDED;
\r
446 if (status == git_wc_status_deleted)
\r
447 itemStates |= ITEMIS_DELETED;
\r
450 } // for (int i = 0; i < count; ++i)
\r
451 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
452 // if (g_ShellCache.HasGitAdminDir(child.toString().c_str(), FALSE))
\r
453 // itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
454 GlobalUnlock(medium.hGlobal);
\r
456 // if the item is a versioned folder, check if there's a patch file
\r
457 // in the clipboard to be used in "Apply Patch"
\r
458 UINT cFormatDiff = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
461 if (IsClipboardFormatAvailable(cFormatDiff))
\r
462 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
464 if (IsClipboardFormatAvailable(CF_HDROP))
\r
465 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
469 ReleaseStgMedium ( &medium );
\r
470 if (medium.pUnkForRelease)
\r
472 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
473 relInterface->Release();
\r
478 // get folder background
\r
482 ItemIDList list(pIDFolder);
\r
483 folder_ = list.toString();
\r
484 git_wc_status_kind status = git_wc_status_none;
\r
485 if (IsClipboardFormatAvailable(CF_HDROP))
\r
486 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
487 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
489 CTGitPath askedpath;
\r
490 askedpath.SetFromWin(folder_.c_str());
\r
494 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
497 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
498 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
499 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
500 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
502 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
503 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
505 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
506 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
507 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
508 itemStatesFolder |= ITEMIS_INSVN;
\r
509 if (status == git_wc_status_normal)
\r
510 itemStatesFolder |= ITEMIS_NORMAL;
\r
511 if (status == git_wc_status_conflicted)
\r
512 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
513 if (status == git_wc_status_added)
\r
514 itemStatesFolder |= ITEMIS_ADDED;
\r
515 if (status == git_wc_status_deleted)
\r
516 itemStatesFolder |= ITEMIS_DELETED;
\r
520 // sometimes, git_client_status() returns with an error.
\r
521 // in that case, we have to check if the working copy is versioned
\r
522 // anyway to show the 'correct' context menu
\r
523 if (askedpath.HasAdminDir())
\r
524 status = git_wc_status_normal;
\r
529 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
534 status = fetchedstatus;
\r
536 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
538 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
540 if (status == git_wc_status_ignored)
\r
541 itemStatesFolder |= ITEMIS_IGNORED;
\r
542 itemStatesFolder |= ITEMIS_FOLDER;
\r
543 if (files_.size() == 0)
\r
544 itemStates |= ITEMIS_ONLYONE;
\r
545 if (m_State != FileStateDropHandler)
\r
546 itemStates |= itemStatesFolder;
\r
549 if (files_.size() == 2)
\r
550 itemStates |= ITEMIS_TWO;
\r
551 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
554 itemStates |= ITEMIS_ONLYONE;
\r
555 if (m_State != FileStateDropHandler)
\r
557 if (PathIsDirectory(files_.front().c_str()))
\r
559 folder_ = files_.front();
\r
560 git_wc_status_kind status = git_wc_status_none;
\r
561 if (folder_.compare(statuspath)!=0)
\r
563 CTGitPath askedpath;
\r
564 askedpath.SetFromWin(folder_.c_str());
\r
568 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
571 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
572 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
573 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
574 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
576 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
577 // itemStates |= ITEMIS_NEEDSLOCK;
\r
579 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
580 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
585 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
590 status = fetchedstatus;
\r
592 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
593 itemStates |= ITEMIS_FOLDERINSVN;
\r
594 if (status == git_wc_status_ignored)
\r
595 itemStates |= ITEMIS_IGNORED;
\r
596 itemStates |= ITEMIS_FOLDER;
\r
597 if (status == git_wc_status_added)
\r
598 itemStates |= ITEMIS_ADDED;
\r
599 if (status == git_wc_status_deleted)
\r
600 itemStates |= ITEMIS_DELETED;
\r
609 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
611 TCHAR menutextbuffer[255] = {0};
\r
612 TCHAR verbsbuffer[255] = {0};
\r
613 MAKESTRING(stringid);
\r
617 //menu entry for the top context menu, so append an "Git " before
\r
618 //the menu text to indicate where the entry comes from
\r
619 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
621 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
622 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
624 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
625 if (fullver >= 0x500)
\r
627 // on win2k, the context menu does not work properly if we use
\r
628 // icon bitmaps. At least the menu text is empty in the context menu
\r
629 // for folder backgrounds (seems like a win2k bug).
\r
630 HBITMAP bmp = IconToBitmap(icon);
\r
631 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
636 MENUITEMINFO menuiteminfo = {0};
\r
637 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
638 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
639 menuiteminfo.fType = MFT_STRING;
\r
640 menuiteminfo.dwTypeData = menutextbuffer;
\r
642 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
643 menuiteminfo.wID = id;
\r
644 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
649 //menu entry for the top context menu, so append an "Git " before
\r
650 //the menu text to indicate where the entry comes from
\r
651 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
653 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
654 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
655 stdstring verb = stdstring(menutextbuffer);
\r
656 if (verb.find('&') != -1)
\r
658 verb.erase(verb.find('&'),1);
\r
660 myVerbsMap[verb] = id - idCmdFirst;
\r
661 myVerbsMap[verb] = id;
\r
662 myVerbsIDMap[id - idCmdFirst] = verb;
\r
663 myVerbsIDMap[id] = verb;
\r
664 // We store the relative and absolute diameter
\r
665 // (drawitem callback uses absolute, others relative)
\r
666 myIDMap[id - idCmdFirst] = com;
\r
669 mySubMenuMap[pos] = com;
\r
672 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
674 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
675 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
676 return bitmap_it->second;
\r
678 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
684 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
685 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
687 rect.left = rect.top = 0;
\r
689 HWND desktop = ::GetDesktopWindow();
\r
690 if (desktop == NULL)
\r
692 DestroyIcon(hIcon);
\r
696 HDC screen_dev = ::GetDC(desktop);
\r
697 if (screen_dev == NULL)
\r
699 DestroyIcon(hIcon);
\r
703 // Create a compatible DC
\r
704 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
705 if (dst_hdc == NULL)
\r
707 DestroyIcon(hIcon);
\r
708 ::ReleaseDC(desktop, screen_dev);
\r
712 // Create a new bitmap of icon size
\r
713 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
716 DestroyIcon(hIcon);
\r
717 ::DeleteDC(dst_hdc);
\r
718 ::ReleaseDC(desktop, screen_dev);
\r
722 // Select it into the compatible DC
\r
723 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
724 if (old_dst_bmp == NULL)
\r
726 DestroyIcon(hIcon);
\r
730 // Fill the background of the compatible DC with the white color
\r
731 // that is taken by menu routines as transparent
\r
732 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
733 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
735 // Draw the icon into the compatible DC
\r
736 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
738 // Restore settings
\r
739 ::SelectObject(dst_hdc, old_dst_bmp);
\r
740 ::DeleteDC(dst_hdc);
\r
741 ::ReleaseDC(desktop, screen_dev);
\r
742 DestroyIcon(hIcon);
\r
744 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
748 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
751 tempfile = stdstring();
\r
752 //write all selected files and paths to a temporary file
\r
753 //for TortoiseProc.exe to read out again.
\r
755 DWORD pathlength = GetTempPath(0, NULL);
\r
756 TCHAR * path = new TCHAR[pathlength+1];
\r
757 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
758 GetTempPath (pathlength+1, path);
\r
759 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
760 tempfile = stdstring(tempFile);
\r
762 HANDLE file = ::CreateFile (tempFile,
\r
767 FILE_ATTRIBUTE_TEMPORARY,
\r
771 delete [] tempFile;
\r
772 if (file == INVALID_HANDLE_VALUE)
\r
775 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
777 if (!OpenClipboard(NULL))
\r
780 stdstring sClipboardText;
\r
781 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
782 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
785 TCHAR szFileName[MAX_PATH];
\r
786 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
787 for(UINT i = 0; i < cFiles; ++i)
\r
789 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
790 stdstring filename = szFileName;
\r
791 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
792 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
794 GlobalUnlock(hDrop);
\r
797 GlobalUnlock(hglb);
\r
800 ::CloseHandle(file);
\r
805 stdstring CShellExt::WriteFileListToTempFile()
\r
807 //write all selected files and paths to a temporary file
\r
808 //for TortoiseProc.exe to read out again.
\r
809 DWORD pathlength = GetTempPath(0, NULL);
\r
810 TCHAR * path = new TCHAR[pathlength+1];
\r
811 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
812 GetTempPath (pathlength+1, path);
\r
813 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
814 stdstring retFilePath = stdstring(tempFile);
\r
816 HANDLE file = ::CreateFile (tempFile,
\r
821 FILE_ATTRIBUTE_TEMPORARY,
\r
825 delete [] tempFile;
\r
826 if (file == INVALID_HANDLE_VALUE)
\r
827 return stdstring();
\r
830 if (files_.empty())
\r
832 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
833 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
836 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
838 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
839 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
841 ::CloseHandle(file);
\r
842 return retFilePath;
\r
845 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
847 PreserveChdir preserveChdir;
\r
850 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
851 return NOERROR; //we don't change the default action
\r
853 if ((files_.size() == 0)||(folder_.size() == 0))
\r
856 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
859 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
861 //the drop handler only has eight commands, but not all are visible at the same time:
\r
862 //if the source file(s) are under version control then those files can be moved
\r
863 //to the new location or they can be moved with a rename,
\r
864 //if they are unversioned then they can be added to the working copy
\r
865 //if they are versioned, they also can be exported to an unversioned location
\r
866 UINT idCmd = idCmdFirst;
\r
869 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
870 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
871 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
873 // Git move and rename here
\r
874 // 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
875 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
876 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
879 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
880 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
881 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
883 // Git copy and rename here, source and target from same repository
\r
884 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
885 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
886 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
889 // available if target is versioned and source is either unversioned or from another repository
\r
890 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
891 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
894 // available if source is versioned and a folder
\r
895 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
896 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
898 // Git export all here
\r
899 // available if source is versioned and a folder
\r
900 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
901 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
904 // available if source is a patchfile
\r
905 if (itemStates & ITEMIS_PATCHFILE)
\r
906 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
909 if (idCmd != idCmdFirst)
\r
910 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
912 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
915 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
918 UINT /*idCmdLast*/,
\r
921 ATLTRACE("Shell :: QueryContextMenu\n");
\r
922 PreserveChdir preserveChdir;
\r
924 //first check if our drop handler is called
\r
925 //and then (if true) provide the context menu for the
\r
927 if (m_State == FileStateDropHandler)
\r
929 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
932 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
933 return NOERROR; //we don't change the default action
\r
935 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
938 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
941 int csidlarray[] =
\r
945 CSIDL_COMMON_FAVORITES,
\r
946 CSIDL_COMMON_STARTMENU,
\r
947 CSIDL_COMPUTERSNEARME,
\r
955 CSIDL_INTERNET_CACHE,
\r
965 if (IsIllegalFolder(folder_, csidlarray))
\r
968 if (folder_.empty())
\r
970 // folder is empty, but maybe files are selected
\r
971 if (files_.size() == 0)
\r
972 return NOERROR; // nothing selected - we don't have a menu to show
\r
973 // check whether a selected entry is an UID - those are namespace extensions
\r
974 // which we can't handle
\r
975 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
977 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
982 //check if our menu is requested for a subversion admin directory
\r
983 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
986 if (uFlags & CMF_EXTENDEDVERBS)
\r
987 itemStates |= ITEMIS_EXTENDED;
\r
989 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
990 if ( bShortcut && (files_.size()==1))
\r
992 // Don't show the context menu for a link if the
\r
993 // destination is not part of a working copy.
\r
994 // It would only show the standard menu items
\r
995 // which are already shown for the lnk-file.
\r
996 CString path = files_.front().c_str();
\r
997 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1003 //check if we already added our menu entry for a folder.
\r
1004 //we check that by iterating through all menu entries and check if
\r
1005 //the dwItemData member points to our global ID string. That string is set
\r
1006 //by our shell extension when the folder menu is inserted.
\r
1007 TCHAR menubuf[MAX_PATH];
\r
1008 int count = GetMenuItemCount(hMenu);
\r
1009 for (int i=0; i<count; ++i)
\r
1011 MENUITEMINFO miif;
\r
1012 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1013 miif.cbSize = sizeof(MENUITEMINFO);
\r
1014 miif.fMask = MIIM_DATA;
\r
1015 miif.dwTypeData = menubuf;
\r
1016 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1017 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1018 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1023 UINT idCmd = idCmdFirst;
\r
1025 //create the sub menu
\r
1026 HMENU subMenu = CreateMenu();
\r
1027 int indexSubMenu = 0;
\r
1029 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1030 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1032 int menuIndex = 0;
\r
1033 bool bAddSeparator = false;
\r
1034 bool bMenuEntryAdded = false;
\r
1035 // insert separator at start
\r
1036 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1037 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1038 if (fullver <= 0x0500)
\r
1039 bShowIcons = false;
\r
1040 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1042 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1044 // we don't add a separator immediately. Because there might not be
\r
1045 // another 'normal' menu entry after we insert a separator.
\r
1046 // we simply set a flag here, indicating that before the next
\r
1047 // 'normal' menu entry, a separator should be added.
\r
1048 bAddSeparator = true;
\r
1052 // check the conditions whether to show the menu entry or not
\r
1053 bool bInsertMenu = false;
\r
1055 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1057 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1059 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1060 bInsertMenu = true;
\r
1062 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1063 bInsertMenu = true;
\r
1064 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1065 bInsertMenu = true;
\r
1067 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1069 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1071 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1072 bInsertMenu = true;
\r
1074 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1075 bInsertMenu = true;
\r
1076 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1077 bInsertMenu = true;
\r
1079 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1081 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1083 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1084 bInsertMenu = true;
\r
1086 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1087 bInsertMenu = true;
\r
1088 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1089 bInsertMenu = true;
\r
1091 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1093 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1095 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1096 bInsertMenu = true;
\r
1098 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1099 bInsertMenu = true;
\r
1100 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1101 bInsertMenu = true;
\r
1103 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1107 // insert a separator
\r
1108 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1110 bAddSeparator = false;
\r
1111 bMenuEntryAdded = false;
\r
1112 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1116 // handle special cases (sub menus)
\r
1117 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1119 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1120 bMenuEntryAdded = true;
\r
1124 // the 'get lock' command is special
\r
1125 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1126 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1128 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1131 // insert the menu entry
\r
1132 InsertGitMenu( bIsTop,
\r
1133 bIsTop ? hMenu : subMenu,
\r
1134 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1136 menuInfo[menuIndex].menuTextID,
\r
1137 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1139 menuInfo[menuIndex].command,
\r
1142 bMenuEntryAdded = true;
\r
1150 //add sub menu to main context menu
\r
1151 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1152 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1153 MAKESTRING(IDS_MENUSUBMENU);
\r
1154 MENUITEMINFO menuiteminfo;
\r
1155 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1156 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1157 menuiteminfo.fType = MFT_STRING;
\r
1158 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1160 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1161 if (folder_.size())
\r
1163 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1164 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1165 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1166 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1168 else if (!bShortcut && (files_.size()==1))
\r
1170 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1171 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1172 myIDMap[idCmd] = ShellSubMenuFile;
\r
1174 else if (bShortcut && (files_.size()==1))
\r
1176 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1177 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1178 myIDMap[idCmd] = ShellSubMenuLink;
\r
1180 else if (files_.size() > 1)
\r
1182 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1183 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1184 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1188 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1189 myIDMap[idCmd] = ShellSubMenu;
\r
1191 HBITMAP bmp = NULL;
\r
1192 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1194 bmp = IconToBitmap(uIcon);
\r
1195 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1199 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1201 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1203 menuiteminfo.hbmpChecked = bmp;
\r
1204 menuiteminfo.hbmpUnchecked = bmp;
\r
1205 menuiteminfo.hSubMenu = subMenu;
\r
1206 menuiteminfo.wID = idCmd++;
\r
1207 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1210 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1212 //return number of menu items added
\r
1213 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1217 // This is called when you invoke a command on the menu:
\r
1218 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1220 PreserveChdir preserveChdir;
\r
1221 HRESULT hr = E_INVALIDARG;
\r
1222 if (lpcmi == NULL)
\r
1225 std::string command;
\r
1226 std::string parent;
\r
1229 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1231 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1233 if (HIWORD(lpcmi->lpVerb))
\r
1235 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1236 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1237 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1238 idCmd = verb_it->second;
\r
1243 // See if we have a handler interface for this id
\r
1244 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1245 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1247 STARTUPINFO startup;
\r
1248 PROCESS_INFORMATION process;
\r
1249 memset(&startup, 0, sizeof(startup));
\r
1250 startup.cb = sizeof(startup);
\r
1251 memset(&process, 0, sizeof(process));
\r
1252 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1253 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1255 //TortoiseProc expects a command line of the form:
\r
1256 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1258 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1260 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1261 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1262 stdstring svnCmd = _T(" /command:");
\r
1263 stdstring tempfile;
\r
1264 switch (id_it->second)
\r
1267 case ShellMenuCheckout:
\r
1268 svnCmd += _T("checkout /path:\"");
\r
1269 svnCmd += folder_;
\r
1270 svnCmd += _T("\"");
\r
1272 case ShellMenuUpdate:
\r
1273 tempfile = WriteFileListToTempFile();
\r
1274 svnCmd += _T("update /pathfile:\"");
\r
1275 svnCmd += tempfile;
\r
1276 svnCmd += _T("\"");
\r
1277 svnCmd += _T(" /deletepathfile");
\r
1279 case ShellMenuUpdateExt:
\r
1280 tempfile = WriteFileListToTempFile();
\r
1281 svnCmd += _T("update /pathfile:\"");
\r
1282 svnCmd += tempfile;
\r
1283 svnCmd += _T("\"");
\r
1284 svnCmd += _T(" /deletepathfile");
\r
1285 svnCmd += _T(" /rev");
\r
1287 case ShellMenuCommit:
\r
1288 tempfile = WriteFileListToTempFile();
\r
1289 svnCmd += _T("commit /pathfile:\"");
\r
1290 svnCmd += tempfile;
\r
1291 svnCmd += _T("\"");
\r
1292 svnCmd += _T(" /deletepathfile");
\r
1294 case ShellMenuAdd:
\r
1295 case ShellMenuAddAsReplacement:
\r
1296 tempfile = WriteFileListToTempFile();
\r
1297 svnCmd += _T("add /pathfile:\"");
\r
1298 svnCmd += tempfile;
\r
1299 svnCmd += _T("\"");
\r
1300 svnCmd += _T(" /deletepathfile");
\r
1302 case ShellMenuIgnore:
\r
1303 tempfile = WriteFileListToTempFile();
\r
1304 svnCmd += _T("ignore /pathfile:\"");
\r
1305 svnCmd += tempfile;
\r
1306 svnCmd += _T("\"");
\r
1307 svnCmd += _T(" /deletepathfile");
\r
1309 case ShellMenuIgnoreCaseSensitive:
\r
1310 tempfile = WriteFileListToTempFile();
\r
1311 svnCmd += _T("ignore /pathfile:\"");
\r
1312 svnCmd += tempfile;
\r
1313 svnCmd += _T("\"");
\r
1314 svnCmd += _T(" /deletepathfile");
\r
1315 svnCmd += _T(" /onlymask");
\r
1317 case ShellMenuUnIgnore:
\r
1318 tempfile = WriteFileListToTempFile();
\r
1319 svnCmd += _T("unignore /pathfile:\"");
\r
1320 svnCmd += tempfile;
\r
1321 svnCmd += _T("\"");
\r
1322 svnCmd += _T(" /deletepathfile");
\r
1324 case ShellMenuUnIgnoreCaseSensitive:
\r
1325 tempfile = WriteFileListToTempFile();
\r
1326 svnCmd += _T("unignore /pathfile:\"");
\r
1327 svnCmd += tempfile;
\r
1328 svnCmd += _T("\"");
\r
1329 svnCmd += _T(" /deletepathfile");
\r
1330 svnCmd += _T(" /onlymask");
\r
1332 case ShellMenuRevert:
\r
1333 tempfile = WriteFileListToTempFile();
\r
1334 svnCmd += _T("revert /pathfile:\"");
\r
1335 svnCmd += tempfile;
\r
1336 svnCmd += _T("\"");
\r
1337 svnCmd += _T(" /deletepathfile");
\r
1339 case ShellMenuDelUnversioned:
\r
1340 svnCmd += _T("delunversioned /path:\"");
\r
1341 svnCmd += folder_;
\r
1342 svnCmd += _T("\"");
\r
1344 case ShellMenuCleanup:
\r
1345 tempfile = WriteFileListToTempFile();
\r
1346 svnCmd += _T("cleanup /pathfile:\"");
\r
1347 svnCmd += tempfile;
\r
1348 svnCmd += _T("\"");
\r
1349 svnCmd += _T(" /deletepathfile");
\r
1351 case ShellMenuResolve:
\r
1352 tempfile = WriteFileListToTempFile();
\r
1353 svnCmd += _T("resolve /pathfile:\"");
\r
1354 svnCmd += tempfile;
\r
1355 svnCmd += _T("\"");
\r
1356 svnCmd += _T(" /deletepathfile");
\r
1358 case ShellMenuSwitch:
\r
1359 svnCmd += _T("switch /path:\"");
\r
1360 if (files_.size() > 0)
\r
1361 svnCmd += files_.front();
\r
1363 svnCmd += folder_;
\r
1364 svnCmd += _T("\"");
\r
1366 case ShellMenuImport:
\r
1367 svnCmd += _T("import /path:\"");
\r
1368 svnCmd += folder_;
\r
1369 svnCmd += _T("\"");
\r
1371 case ShellMenuExport:
\r
1372 svnCmd += _T("export /path:\"");
\r
1373 svnCmd += folder_;
\r
1374 svnCmd += _T("\"");
\r
1376 case ShellMenuAbout:
\r
1377 svnCmd += _T("about");
\r
1379 case ShellMenuCreateRepos:
\r
1380 svnCmd += _T("repocreate /path:\"");
\r
1381 svnCmd += folder_;
\r
1382 svnCmd += _T("\"");
\r
1384 case ShellMenuMerge:
\r
1385 svnCmd += _T("merge /path:\"");
\r
1386 if (files_.size() > 0)
\r
1387 svnCmd += files_.front();
\r
1389 svnCmd += folder_;
\r
1390 svnCmd += _T("\"");
\r
1392 case ShellMenuMergeAll:
\r
1393 svnCmd += _T("mergeall /path:\"");
\r
1394 if (files_.size() > 0)
\r
1395 svnCmd += files_.front();
\r
1397 svnCmd += folder_;
\r
1398 svnCmd += _T("\"");
\r
1400 case ShellMenuCopy:
\r
1401 svnCmd += _T("copy /path:\"");
\r
1402 if (files_.size() > 0)
\r
1403 svnCmd += files_.front();
\r
1405 svnCmd += folder_;
\r
1406 svnCmd += _T("\"");
\r
1408 case ShellMenuSettings:
\r
1409 svnCmd += _T("settings");
\r
1411 case ShellMenuHelp:
\r
1412 svnCmd += _T("help");
\r
1414 case ShellMenuRename:
\r
1415 svnCmd += _T("rename /path:\"");
\r
1416 if (files_.size() > 0)
\r
1417 svnCmd += files_.front();
\r
1419 svnCmd += folder_;
\r
1420 svnCmd += _T("\"");
\r
1422 case ShellMenuRemove:
\r
1423 tempfile = WriteFileListToTempFile();
\r
1424 svnCmd += _T("remove /pathfile:\"");
\r
1425 svnCmd += tempfile;
\r
1426 svnCmd += _T("\"");
\r
1427 svnCmd += _T(" /deletepathfile");
\r
1429 case ShellMenuRemoveKeep:
\r
1430 tempfile = WriteFileListToTempFile();
\r
1431 svnCmd += _T("remove /pathfile:\"");
\r
1432 svnCmd += tempfile;
\r
1433 svnCmd += _T("\"");
\r
1434 svnCmd += _T(" /deletepathfile");
\r
1435 svnCmd += _T(" /keep");
\r
1437 case ShellMenuDiff:
\r
1438 svnCmd += _T("diff /path:\"");
\r
1439 if (files_.size() == 1)
\r
1440 svnCmd += files_.front();
\r
1441 else if (files_.size() == 2)
\r
1443 std::vector<stdstring>::iterator I = files_.begin();
\r
1446 svnCmd += _T("\" /path2:\"");
\r
1450 svnCmd += folder_;
\r
1451 svnCmd += _T("\"");
\r
1452 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1453 svnCmd += _T(" /alternative");
\r
1455 case ShellMenuPrevDiff:
\r
1456 svnCmd += _T("prevdiff /path:\"");
\r
1457 if (files_.size() == 1)
\r
1458 svnCmd += files_.front();
\r
1460 svnCmd += folder_;
\r
1461 svnCmd += _T("\"");
\r
1462 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1463 svnCmd += _T(" /alternative");
\r
1465 case ShellMenuUrlDiff:
\r
1466 svnCmd += _T("urldiff /path:\"");
\r
1467 if (files_.size() == 1)
\r
1468 svnCmd += files_.front();
\r
1470 svnCmd += folder_;
\r
1471 svnCmd += _T("\"");
\r
1473 case ShellMenuDropCopyAdd:
\r
1474 tempfile = WriteFileListToTempFile();
\r
1475 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1476 svnCmd += tempfile;
\r
1477 svnCmd += _T("\"");
\r
1478 svnCmd += _T(" /deletepathfile");
\r
1479 svnCmd += _T(" /droptarget:\"");
\r
1480 svnCmd += folder_;
\r
1481 svnCmd += _T("\"";)
\r
1483 case ShellMenuDropCopy:
\r
1484 tempfile = WriteFileListToTempFile();
\r
1485 svnCmd += _T("dropcopy /pathfile:\"");
\r
1486 svnCmd += tempfile;
\r
1487 svnCmd += _T("\"");
\r
1488 svnCmd += _T(" /deletepathfile");
\r
1489 svnCmd += _T(" /droptarget:\"");
\r
1490 svnCmd += folder_;
\r
1491 svnCmd += _T("\"";)
\r
1493 case ShellMenuDropCopyRename:
\r
1494 tempfile = WriteFileListToTempFile();
\r
1495 svnCmd += _T("dropcopy /pathfile:\"");
\r
1496 svnCmd += tempfile;
\r
1497 svnCmd += _T("\"");
\r
1498 svnCmd += _T(" /deletepathfile");
\r
1499 svnCmd += _T(" /droptarget:\"");
\r
1500 svnCmd += folder_;
\r
1501 svnCmd += _T("\" /rename";)
\r
1503 case ShellMenuDropMove:
\r
1504 tempfile = WriteFileListToTempFile();
\r
1505 svnCmd += _T("dropmove /pathfile:\"");
\r
1506 svnCmd += tempfile;
\r
1507 svnCmd += _T("\"");
\r
1508 svnCmd += _T(" /deletepathfile");
\r
1509 svnCmd += _T(" /droptarget:\"");
\r
1510 svnCmd += folder_;
\r
1511 svnCmd += _T("\"");
\r
1513 case ShellMenuDropMoveRename:
\r
1514 tempfile = WriteFileListToTempFile();
\r
1515 svnCmd += _T("dropmove /pathfile:\"");
\r
1516 svnCmd += tempfile;
\r
1517 svnCmd += _T("\"");
\r
1518 svnCmd += _T(" /deletepathfile");
\r
1519 svnCmd += _T(" /droptarget:\"");
\r
1520 svnCmd += folder_;
\r
1521 svnCmd += _T("\" /rename";)
\r
1523 case ShellMenuDropExport:
\r
1524 tempfile = WriteFileListToTempFile();
\r
1525 svnCmd += _T("dropexport /pathfile:\"");
\r
1526 svnCmd += tempfile;
\r
1527 svnCmd += _T("\"");
\r
1528 svnCmd += _T(" /deletepathfile");
\r
1529 svnCmd += _T(" /droptarget:\"");
\r
1530 svnCmd += folder_;
\r
1531 svnCmd += _T("\"");
\r
1533 case ShellMenuDropExportExtended:
\r
1534 tempfile = WriteFileListToTempFile();
\r
1535 svnCmd += _T("dropexport /pathfile:\"");
\r
1536 svnCmd += tempfile;
\r
1537 svnCmd += _T("\"");
\r
1538 svnCmd += _T(" /deletepathfile");
\r
1539 svnCmd += _T(" /droptarget:\"");
\r
1540 svnCmd += folder_;
\r
1541 svnCmd += _T("\"");
\r
1542 svnCmd += _T(" /extended");
\r
1544 case ShellMenuLog:
\r
1545 svnCmd += _T("log /path:\"");
\r
1546 if (files_.size() > 0)
\r
1547 svnCmd += files_.front();
\r
1549 svnCmd += folder_;
\r
1550 svnCmd += _T("\"");
\r
1552 case ShellMenuConflictEditor:
\r
1553 svnCmd += _T("conflicteditor /path:\"");
\r
1554 if (files_.size() > 0)
\r
1555 svnCmd += files_.front();
\r
1557 svnCmd += folder_;
\r
1558 svnCmd += _T("\"");
\r
1560 case ShellMenuRelocate:
\r
1561 svnCmd += _T("relocate /path:\"");
\r
1562 if (files_.size() > 0)
\r
1563 svnCmd += files_.front();
\r
1565 svnCmd += folder_;
\r
1566 svnCmd += _T("\"");
\r
1568 case ShellMenuShowChanged:
\r
1569 if (files_.size() > 1)
\r
1571 tempfile = WriteFileListToTempFile();
\r
1572 svnCmd += _T("repostatus /pathfile:\"");
\r
1573 svnCmd += tempfile;
\r
1574 svnCmd += _T("\"");
\r
1575 svnCmd += _T(" /deletepathfile");
\r
1579 svnCmd += _T("repostatus /path:\"");
\r
1580 if (files_.size() > 0)
\r
1581 svnCmd += files_.front();
\r
1583 svnCmd += folder_;
\r
1584 svnCmd += _T("\"");
\r
1587 case ShellMenuRepoBrowse:
\r
1588 svnCmd += _T("repobrowser /path:\"");
\r
1589 if (files_.size() > 0)
\r
1590 svnCmd += files_.front();
\r
1592 svnCmd += folder_;
\r
1593 svnCmd += _T("\"");
\r
1595 case ShellMenuBlame:
\r
1596 svnCmd += _T("blame /path:\"");
\r
1597 if (files_.size() > 0)
\r
1598 svnCmd += files_.front();
\r
1600 svnCmd += folder_;
\r
1601 svnCmd += _T("\"");
\r
1603 case ShellMenuCreatePatch:
\r
1604 tempfile = WriteFileListToTempFile();
\r
1605 svnCmd += _T("createpatch /pathfile:\"");
\r
1606 svnCmd += tempfile;
\r
1607 svnCmd += _T("\"");
\r
1608 svnCmd += _T(" /deletepathfile");
\r
1610 case ShellMenuApplyPatch:
\r
1611 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1613 // if there's a patch file in the clipboard, we save it
\r
1614 // to a temporary file and tell TortoiseMerge to use that one
\r
1615 UINT cFormat = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
1616 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1618 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1619 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1621 DWORD len = GetTempPath(0, NULL);
\r
1622 TCHAR * path = new TCHAR[len+1];
\r
1623 TCHAR * tempF = new TCHAR[len+100];
\r
1624 GetTempPath (len+1, path);
\r
1625 GetTempFileName (path, TEXT("svn"), 0, tempF);
\r
1626 std::wstring sTempFile = std::wstring(tempF);
\r
1631 size_t patchlen = strlen(lpstr);
\r
1632 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1635 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1636 if (size == patchlen)
\r
1638 itemStates |= ITEMIS_PATCHFILE;
\r
1640 files_.push_back(sTempFile);
\r
1644 GlobalUnlock(hglb);
\r
1645 CloseClipboard();
\r
1648 if (itemStates & ITEMIS_PATCHFILE)
\r
1650 svnCmd = _T(" /diff:\"");
\r
1651 if (files_.size() > 0)
\r
1653 svnCmd += files_.front();
\r
1654 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1656 svnCmd += _T("\" /patchpath:\"");
\r
1657 svnCmd += folder_;
\r
1661 svnCmd += folder_;
\r
1662 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1663 svnCmd += _T("\" /wc");
\r
1665 svnCmd += _T("\"");
\r
1669 svnCmd = _T(" /patchpath:\"");
\r
1670 if (files_.size() > 0)
\r
1671 svnCmd += files_.front();
\r
1673 svnCmd += folder_;
\r
1674 svnCmd += _T("\"");
\r
1677 myVerbsIDMap.clear();
\r
1678 myVerbsMap.clear();
\r
1679 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1682 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1683 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1684 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1687 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1688 (LPTSTR) &lpMsgBuf,
\r
1692 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1693 LocalFree( lpMsgBuf );
\r
1695 CloseHandle(process.hThread);
\r
1696 CloseHandle(process.hProcess);
\r
1699 case ShellMenuRevisionGraph:
\r
1700 svnCmd += _T("revisiongraph /path:\"");
\r
1701 if (files_.size() > 0)
\r
1702 svnCmd += files_.front();
\r
1704 svnCmd += folder_;
\r
1705 svnCmd += _T("\"");
\r
1707 case ShellMenuLock:
\r
1708 tempfile = WriteFileListToTempFile();
\r
1709 svnCmd += _T("lock /pathfile:\"");
\r
1710 svnCmd += tempfile;
\r
1711 svnCmd += _T("\"");
\r
1712 svnCmd += _T(" /deletepathfile");
\r
1714 case ShellMenuUnlock:
\r
1715 tempfile = WriteFileListToTempFile();
\r
1716 svnCmd += _T("unlock /pathfile:\"");
\r
1717 svnCmd += tempfile;
\r
1718 svnCmd += _T("\"");
\r
1719 svnCmd += _T(" /deletepathfile");
\r
1721 case ShellMenuUnlockForce:
\r
1722 tempfile = WriteFileListToTempFile();
\r
1723 svnCmd += _T("unlock /pathfile:\"");
\r
1724 svnCmd += tempfile;
\r
1725 svnCmd += _T("\"");
\r
1726 svnCmd += _T(" /deletepathfile");
\r
1727 svnCmd += _T(" /force");
\r
1729 case ShellMenuProperties:
\r
1730 tempfile = WriteFileListToTempFile();
\r
1731 svnCmd += _T("properties /pathfile:\"");
\r
1732 svnCmd += tempfile;
\r
1733 svnCmd += _T("\"");
\r
1734 svnCmd += _T(" /deletepathfile");
\r
1736 case ShellMenuClipPaste:
\r
1737 if (WriteClipboardPathsToTempFile(tempfile))
\r
1739 bool bCopy = true;
\r
1740 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1741 if (cPrefDropFormat)
\r
1743 if (OpenClipboard(lpcmi->hwnd))
\r
1745 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1748 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1749 if (*effect == DROPEFFECT_MOVE)
\r
1751 GlobalUnlock(hglb);
\r
1758 svnCmd += _T("pastecopy /pathfile:\"");
\r
1760 svnCmd += _T("pastemove /pathfile:\"");
\r
1761 svnCmd += tempfile;
\r
1762 svnCmd += _T("\"");
\r
1763 svnCmd += _T(" /deletepathfile");
\r
1764 svnCmd += _T(" /droptarget:\"");
\r
1765 svnCmd += folder_;
\r
1766 svnCmd += _T("\"");
\r
1768 else return NOERROR;
\r
1770 case ShellMenuClone:
\r
1771 svnCmd += _T("clone /path:\"");
\r
1772 svnCmd += folder_;
\r
1773 svnCmd += _T("\"");
\r
1775 case ShellMenuPull:
\r
1776 tempfile = WriteFileListToTempFile();
\r
1777 svnCmd += _T("pull /pathfile:\"");
\r
1778 svnCmd += tempfile;
\r
1779 svnCmd += _T("\"");
\r
1780 svnCmd += _T(" /deletepathfile");
\r
1782 case ShellMenuPush:
\r
1783 tempfile = WriteFileListToTempFile();
\r
1784 svnCmd += _T("push /pathfile:\"");
\r
1785 svnCmd += tempfile;
\r
1786 svnCmd += _T("\"");
\r
1787 svnCmd += _T(" /deletepathfile");
\r
1792 } // switch (id_it->second)
\r
1793 svnCmd += _T(" /hwnd:");
\r
1795 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1798 myVerbsIDMap.clear();
\r
1799 myVerbsMap.clear();
\r
1800 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1803 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1804 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1805 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1808 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1809 (LPTSTR) &lpMsgBuf,
\r
1813 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1814 LocalFree( lpMsgBuf );
\r
1816 CloseHandle(process.hThread);
\r
1817 CloseHandle(process.hProcess);
\r
1819 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1820 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1825 // This is for the status bar and things like that:
\r
1826 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1828 UINT FAR * /*reserved*/,
\r
1832 PreserveChdir preserveChdir;
\r
1833 //do we know the id?
\r
1834 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1835 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1837 return E_INVALIDARG; //no, we don't
\r
1841 HRESULT hr = E_INVALIDARG;
\r
1843 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1844 int menuIndex = 0;
\r
1845 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1847 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1849 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1855 const TCHAR * desc = stringtablebuffer;
\r
1858 case GCS_HELPTEXTA:
\r
1860 std::string help = WideToMultibyte(desc);
\r
1861 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1865 case GCS_HELPTEXTW:
\r
1867 wide_string help = desc;
\r
1868 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1874 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1875 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1877 std::string help = WideToMultibyte(verb_id_it->second);
\r
1878 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1885 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1886 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1888 wide_string help = verb_id_it->second;
\r
1889 ATLTRACE("verb : %ws\n", help.c_str());
\r
1890 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1899 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1902 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
1905 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
1907 PreserveChdir preserveChdir;
\r
1910 if (pResult == NULL)
\r
1917 case WM_MEASUREITEM:
\r
1919 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
1922 lpmis->itemWidth += 2;
\r
1923 if (lpmis->itemHeight < 16)
\r
1924 lpmis->itemHeight = 16;
\r
1931 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
1932 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
1933 return S_OK; //not for a menu
\r
1934 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
1935 if (resource == NULL)
\r
1937 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
1938 if (hIcon == NULL)
\r
1940 DrawIconEx(lpdis->hDC,
\r
1941 lpdis->rcItem.left - 16,
\r
1942 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
1944 0, NULL, DI_NORMAL);
\r
1945 DestroyIcon(hIcon);
\r
1953 if (HIWORD(wParam) != MF_POPUP)
\r
1955 int nChar = LOWORD(wParam);
\r
1956 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
1957 nChar = tolower(nChar);
\r
1958 // we have the char the user pressed, now search that char in all our
\r
1960 std::vector<int> accmenus;
\r
1961 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
1963 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
1964 if (resource == NULL)
\r
1966 szItem = stringtablebuffer;
\r
1967 TCHAR * amp = _tcschr(szItem, '&');
\r
1971 int ampChar = LOWORD(*amp);
\r
1972 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
1973 ampChar = tolower(ampChar);
\r
1974 if (ampChar == nChar)
\r
1976 // yep, we found a menu which has the pressed key
\r
1977 // as an accelerator. Add that menu to the list to
\r
1979 accmenus.push_back(It->first);
\r
1982 if (accmenus.size() == 0)
\r
1984 // no menu with that accelerator key.
\r
1985 *pResult = MAKELONG(0, MNC_IGNORE);
\r
1988 if (accmenus.size() == 1)
\r
1990 // Only one menu with that accelerator key. We're lucky!
\r
1991 // So just execute that menu entry.
\r
1992 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
1995 if (accmenus.size() > 1)
\r
1997 // we have more than one menu item with this accelerator key!
\r
1999 mif.cbSize = sizeof(MENUITEMINFO);
\r
2000 mif.fMask = MIIM_STATE;
\r
2001 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2003 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2004 if (mif.fState == MFS_HILITE)
\r
2006 // this is the selected item, so select the next one
\r
2008 if (it == accmenus.end())
\r
2009 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2011 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2015 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2026 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2028 TCHAR textbuf[255];
\r
2029 LPCTSTR resource = NULL;
\r
2030 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2033 int menuIndex = 0;
\r
2034 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2036 if (menuInfo[menuIndex].command == id)
\r
2038 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2039 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2042 case ShellMenuLock:
\r
2043 // menu lock is special because it can be set to the top
\r
2044 // with a separate option in the registry
\r
2045 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2046 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2048 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2049 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2050 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2053 // the sub menu entries are special because they're *always* on the top level menu
\r
2054 case ShellSubMenuMultiple:
\r
2055 case ShellSubMenuLink:
\r
2056 case ShellSubMenuFolder:
\r
2057 case ShellSubMenuFile:
\r
2058 case ShellSubMenu:
\r
2062 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2063 if (layout & (menuInfo[menuIndex].menuID))
\r
2065 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2066 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2067 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2078 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2081 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2082 LPITEMIDLIST pidl = NULL;
\r
2083 while (cslidarray[i])
\r
2087 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2089 if (!SHGetPathFromIDList(pidl, buf))
\r
2091 // not a file system path, definitely illegal for our use
\r
2092 CoTaskMemFree(pidl);
\r
2095 CoTaskMemFree(pidl);
\r
2096 if (_tcslen(buf)==0)
\r
2098 if (_tcscmp(buf, folder.c_str())==0)
\r
2104 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2106 HMENU ignoresubmenu = NULL;
\r
2107 int indexignoresub = 0;
\r
2108 bool bShowIgnoreMenu = false;
\r
2109 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2110 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2111 if (files_.size() == 0)
\r
2113 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2115 std::vector<stdstring>::iterator I = files_.begin();
\r
2116 if (_tcsrchr(I->c_str(), '\\'))
\r
2117 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2119 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2120 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2122 // check if the item name is ignored or the mask
\r
2124 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2126 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2127 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2135 ignoresubmenu = CreateMenu();
\r
2136 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2137 stdstring verb = stdstring(ignorepath);
\r
2138 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2139 myVerbsMap[verb] = idCmd;
\r
2140 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2141 myVerbsIDMap[idCmd] = verb;
\r
2142 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2143 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2144 bShowIgnoreMenu = true;
\r
2146 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2147 if (_tcsrchr(ignorepath, '.'))
\r
2149 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2150 p = ignoredprops.find(maskbuf);
\r
2152 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2154 if (ignoresubmenu==NULL)
\r
2155 ignoresubmenu = CreateMenu();
\r
2157 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2158 stdstring verb = stdstring(maskbuf);
\r
2159 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2160 myVerbsMap[verb] = idCmd;
\r
2161 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2162 myVerbsIDMap[idCmd] = verb;
\r
2163 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2164 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2165 bShowIgnoreMenu = true;
\r
2169 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2171 bShowIgnoreMenu = true;
\r
2172 ignoresubmenu = CreateMenu();
\r
2173 if (itemStates & ITEMIS_ONLYONE)
\r
2175 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2176 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2177 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2179 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2180 if (_tcsrchr(ignorepath, '.'))
\r
2182 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2183 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2184 stdstring verb = stdstring(maskbuf);
\r
2185 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2186 myVerbsMap[verb] = idCmd;
\r
2187 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2188 myVerbsIDMap[idCmd] = verb;
\r
2189 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2190 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2195 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2196 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2197 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2198 stdstring verb = stdstring(ignorepath);
\r
2199 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2200 myVerbsMap[verb] = idCmd;
\r
2201 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2202 myVerbsIDMap[idCmd] = verb;
\r
2203 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2204 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2206 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2207 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2208 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2209 verb = stdstring(ignorepath);
\r
2210 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2211 myVerbsMap[verb] = idCmd;
\r
2212 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2213 myVerbsIDMap[idCmd] = verb;
\r
2214 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2215 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2219 if (bShowIgnoreMenu)
\r
2221 MENUITEMINFO menuiteminfo;
\r
2222 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2223 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2224 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2225 menuiteminfo.fType = MFT_STRING;
\r
2226 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2228 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2229 menuiteminfo.hbmpChecked = bmp;
\r
2230 menuiteminfo.hbmpUnchecked = bmp;
\r
2231 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2232 menuiteminfo.wID = idCmd;
\r
2233 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2234 if (itemStates & ITEMIS_IGNORED)
\r
2235 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2237 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2238 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2239 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2241 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2242 if (itemStates & ITEMIS_IGNORED)
\r
2244 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2245 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2249 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2250 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2255 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2257 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2258 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2259 return bitmap_it->second;
\r
2261 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2265 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2269 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2270 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2273 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2274 HBITMAP hBmp = NULL;
\r
2276 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2279 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2281 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2284 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2285 BP_PAINTPARAMS paintParams = {0};
\r
2286 paintParams.cbSize = sizeof(paintParams);
\r
2287 paintParams.dwFlags = BPPF_ERASE;
\r
2288 paintParams.pBlendFunction = &bfAlpha;
\r
2291 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2294 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2296 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2297 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2300 // This will write the buffer contents to the destination bitmap
\r
2301 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2304 SelectObject(hdcDest, hbmpOld);
\r
2308 DeleteDC(hdcDest);
\r
2311 DestroyIcon(hIcon);
\r
2314 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2318 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2323 ZeroMemory(&bmi, sizeof(bmi));
\r
2324 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2325 bmi.bmiHeader.biPlanes = 1;
\r
2326 bmi.bmiHeader.biCompression = BI_RGB;
\r
2328 bmi.bmiHeader.biWidth = psize->cx;
\r
2329 bmi.bmiHeader.biHeight = psize->cy;
\r
2330 bmi.bmiHeader.biBitCount = 32;
\r
2332 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2335 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2336 if (hdc != hdcUsed)
\r
2338 ReleaseDC(NULL, hdcUsed);
\r
2341 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2344 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2346 RGBQUAD *prgbQuad;
\r
2348 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2349 if (SUCCEEDED(hr))
\r
2351 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2352 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2355 if (GetIconInfo(hicon, &info))
\r
2359 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2362 DeleteObject(info.hbmColor);
\r
2363 DeleteObject(info.hbmMask);
\r
2371 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2373 ULONG cxDelta = cxRow - sizImage.cx;
\r
2374 for (ULONG y = sizImage.cy; y; --y)
\r
2376 for (ULONG x = sizImage.cx; x; --x)
\r
2378 if (*pargb++ & 0xFF000000)
\r
2390 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2393 ZeroMemory(&bmi, sizeof(bmi));
\r
2394 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2395 bmi.bmiHeader.biPlanes = 1;
\r
2396 bmi.bmiHeader.biCompression = BI_RGB;
\r
2398 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2399 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2400 bmi.bmiHeader.biBitCount = 32;
\r
2402 HRESULT hr = E_OUTOFMEMORY;
\r
2403 HANDLE hHeap = GetProcessHeap();
\r
2404 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2407 hr = E_UNEXPECTED;
\r
2408 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2410 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2411 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2413 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2415 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2419 // transparent pixel
\r
2425 *pargb++ |= 0xFF000000;
\r
2435 HeapFree(hHeap, 0, pvBits);
\r