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 { ShellMenuCheckout, MENUCHECKOUT, IDI_CHECKOUT, IDS_MENUCHECKOUT, IDS_MENUDESCCHECKOUT,
\r
36 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
38 { ShellMenuUpdate, MENUUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
\r
39 ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
41 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
42 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
44 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
46 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
47 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
49 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
50 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
52 { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
53 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
55 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
56 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
58 { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
59 ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
61 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
62 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
64 { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
65 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
67 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
69 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
70 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
72 { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
73 ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
75 { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
76 ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
78 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
79 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
81 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
82 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
84 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
85 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
87 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
88 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
90 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
91 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
93 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
94 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
96 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
97 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
99 { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
100 ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
102 { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
103 ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
105 { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
106 ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
108 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
110 { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
111 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
113 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
114 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
116 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
117 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
118 { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
119 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
121 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
122 ITEMIS_FOLDER|ITEMIS_ONLYONE, 0, 0, 0, 0, 0, 0, 0 },
\r
124 { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
125 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
127 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
129 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
130 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
132 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
133 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
135 { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
136 ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
138 { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
139 ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
141 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
142 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
144 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
145 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
147 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
148 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
150 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
152 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
153 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
155 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
156 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },
\r
158 { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
159 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
161 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
162 { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
163 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
165 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
167 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
168 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
169 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
170 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
171 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
172 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
174 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
175 // but they still need to be in here, because we use the icon and string information anyway.
\r
176 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
177 0, 0, 0, 0, 0, 0, 0, 0 },
\r
178 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
179 0, 0, 0, 0, 0, 0, 0, 0 },
\r
180 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
181 0, 0, 0, 0, 0, 0, 0, 0 },
\r
182 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
183 0, 0, 0, 0, 0, 0, 0, 0 },
\r
184 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
185 0, 0, 0, 0, 0, 0, 0, 0 },
\r
186 // mark the last entry to tell the loop where to stop iterating over this array
\r
187 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
188 0, 0, 0, 0, 0, 0, 0, 0 },
\r
192 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
193 LPDATAOBJECT pDataObj,
\r
194 HKEY /* hRegKey */)
\r
197 ATLTRACE("Shell :: Initialize\n");
\r
198 PreserveChdir preserveChdir;
\r
201 uuidSource.erase();
\r
202 uuidTarget.erase();
\r
204 itemStatesFolder = 0;
\r
205 stdstring statuspath;
\r
206 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
207 // get selected files/folders
\r
211 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
212 (DVTARGETDEVICE FAR *)NULL,
\r
216 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
218 if (SUCCEEDED(hres) && medium.hGlobal)
\r
220 if (m_State == FileStateDropHandler)
\r
222 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
223 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
224 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
226 ReleaseStgMedium ( &medium );
\r
227 return E_INVALIDARG;
\r
231 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
232 if ( NULL == drop )
\r
234 ReleaseStgMedium ( &stg );
\r
235 ReleaseStgMedium ( &medium );
\r
236 return E_INVALIDARG;
\r
239 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
241 itemStates |= ITEMIS_ONLYONE;
\r
242 for (int i = 0; i < count; i++)
\r
244 // find the path length in chars
\r
245 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
248 TCHAR * szFileName = new TCHAR[len+1];
\r
249 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
251 delete [] szFileName;
\r
254 stdstring str = stdstring(szFileName);
\r
255 delete [] szFileName;
\r
256 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
258 if (itemStates & ITEMIS_ONLYONE)
\r
261 strpath.SetFromWin(str.c_str());
\r
262 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
263 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
265 files_.push_back(str);
\r
268 //get the Subversion status of the item
\r
269 git_wc_status_kind status = git_wc_status_none;
\r
270 CTGitPath askedpath;
\r
271 askedpath.SetFromWin(str.c_str());
\r
275 //stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
279 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
280 fetchedstatus = status;
\r
281 if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
282 itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
283 if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
285 itemStates |= ITEMIS_FOLDER;
\r
286 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
287 itemStates |= ITEMIS_FOLDERINGit;
\r
289 if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
291 if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
292 itemStates |= ITEMIS_NEEDSLOCK;
\r
294 if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
295 uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
299 // sometimes, git_client_status() returns with an error.
\r
300 // in that case, we have to check if the working copy is versioned
\r
301 // anyway to show the 'correct' context menu
\r
302 if (askedpath.HasAdminDir())
\r
303 status = git_wc_status_normal;
\r
308 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
310 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
311 itemStates |= ITEMIS_INGit;
\r
312 if (status == git_wc_status_ignored)
\r
313 itemStates |= ITEMIS_IGNORED;
\r
314 if (status == git_wc_status_normal)
\r
315 itemStates |= ITEMIS_NORMAL;
\r
316 if (status == git_wc_status_conflicted)
\r
317 itemStates |= ITEMIS_CONFLICTED;
\r
318 if (status == git_wc_status_added)
\r
319 itemStates |= ITEMIS_ADDED;
\r
320 if (status == git_wc_status_deleted)
\r
321 itemStates |= ITEMIS_DELETED;
\r
324 } // for (int i = 0; i < count; i++)
\r
325 GlobalUnlock ( drop );
\r
326 ReleaseStgMedium ( &stg );
\r
327 } // if (m_State == FileStateDropHandler)
\r
330 //Enumerate PIDLs which the user has selected
\r
331 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
332 ItemIDList parent( GetPIDLFolder (cida));
\r
334 int count = cida->cidl;
\r
335 BOOL statfetched = FALSE;
\r
336 for (int i = 0; i < count; ++i)
\r
338 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
339 stdstring str = child.toString();
\r
340 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
342 //check if our menu is requested for a subversion admin directory
\r
343 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
346 files_.push_back(str);
\r
348 strpath.SetFromWin(str.c_str());
\r
349 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
350 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
353 //get the Subversion status of the item
\r
354 git_wc_status_kind status = git_wc_status_none;
\r
355 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
357 if (strpath.HasAdminDir())
\r
358 status = git_wc_status_normal;
\r
365 if (strpath.HasAdminDir())
\r
366 stat.GetStatus(strpath, false, true, true);
\r
370 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
371 fetchedstatus = status;
\r
372 if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
373 itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
374 if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
376 itemStates |= ITEMIS_FOLDER;
\r
377 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
378 itemStates |= ITEMIS_FOLDERINGit;
\r
380 if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
381 itemStates |= ITEMIS_CONFLICTED;
\r
382 if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
384 if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
385 itemStates |= ITEMIS_NEEDSLOCK;
\r
387 if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
388 uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
392 // sometimes, git_client_status() returns with an error.
\r
393 // in that case, we have to check if the working copy is versioned
\r
394 // anyway to show the 'correct' context menu
\r
395 if (strpath.HasAdminDir())
\r
397 status = git_wc_status_normal;
\r
398 fetchedstatus = status;
\r
401 statfetched = TRUE;
\r
405 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
408 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
409 itemStates |= ITEMIS_INGit;
\r
410 if (status == git_wc_status_ignored)
\r
412 itemStates |= ITEMIS_IGNORED;
\r
413 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
414 // offer a 'remove from ignored list' entry
\r
415 GitProperties props(strpath.GetContainingDirectory(), false);
\r
416 ignoredprops.empty();
\r
417 for (int p=0; p<props.GetCount(); ++p)
\r
419 if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
421 std::string st = props.GetItemValue(p);
\r
422 ignoredprops = MultibyteToWide(st.c_str());
\r
423 // remove all escape chars ('\\')
\r
424 std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
429 if (status == git_wc_status_normal)
\r
430 itemStates |= ITEMIS_NORMAL;
\r
431 if (status == git_wc_status_conflicted)
\r
432 itemStates |= ITEMIS_CONFLICTED;
\r
433 if (status == git_wc_status_added)
\r
434 itemStates |= ITEMIS_ADDED;
\r
435 if (status == git_wc_status_deleted)
\r
436 itemStates |= ITEMIS_DELETED;
\r
439 } // for (int i = 0; i < count; ++i)
\r
440 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
441 if (g_ShellCache.HasGitAdminDir(child.toString().c_str(), FALSE))
\r
442 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
443 GlobalUnlock(medium.hGlobal);
\r
445 // if the item is a versioned folder, check if there's a patch file
\r
446 // in the clipboard to be used in "Apply Patch"
\r
447 UINT cFormatDiff = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
450 if (IsClipboardFormatAvailable(cFormatDiff))
\r
451 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
453 if (IsClipboardFormatAvailable(CF_HDROP))
\r
454 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
457 ReleaseStgMedium ( &medium );
\r
458 if (medium.pUnkForRelease)
\r
460 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
461 relInterface->Release();
\r
466 // get folder background
\r
469 ItemIDList list(pIDFolder);
\r
470 folder_ = list.toString();
\r
471 git_wc_status_kind status = git_wc_status_none;
\r
472 if (IsClipboardFormatAvailable(CF_HDROP))
\r
473 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
474 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
476 CTGitPath askedpath;
\r
477 askedpath.SetFromWin(folder_.c_str());
\r
481 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
484 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
485 if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
486 itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
487 if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
489 if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
490 itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
492 if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
493 uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
494 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
495 itemStatesFolder |= ITEMIS_INGit;
\r
496 if (status == git_wc_status_normal)
\r
497 itemStatesFolder |= ITEMIS_NORMAL;
\r
498 if (status == git_wc_status_conflicted)
\r
499 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
500 if (status == git_wc_status_added)
\r
501 itemStatesFolder |= ITEMIS_ADDED;
\r
502 if (status == git_wc_status_deleted)
\r
503 itemStatesFolder |= ITEMIS_DELETED;
\r
507 // sometimes, git_client_status() returns with an error.
\r
508 // in that case, we have to check if the working copy is versioned
\r
509 // anyway to show the 'correct' context menu
\r
510 if (askedpath.HasAdminDir())
\r
511 status = git_wc_status_normal;
\r
516 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
521 status = fetchedstatus;
\r
523 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
525 itemStatesFolder |= ITEMIS_FOLDERINGit;
\r
527 if (status == git_wc_status_ignored)
\r
528 itemStatesFolder |= ITEMIS_IGNORED;
\r
529 itemStatesFolder |= ITEMIS_FOLDER;
\r
530 if (files_.size() == 0)
\r
531 itemStates |= ITEMIS_ONLYONE;
\r
532 if (m_State != FileStateDropHandler)
\r
533 itemStates |= itemStatesFolder;
\r
535 if (files_.size() == 2)
\r
536 itemStates |= ITEMIS_TWO;
\r
537 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
539 itemStates |= ITEMIS_ONLYONE;
\r
540 if (m_State != FileStateDropHandler)
\r
542 if (PathIsDirectory(files_.front().c_str()))
\r
544 folder_ = files_.front();
\r
545 git_wc_status_kind status = git_wc_status_none;
\r
546 if (folder_.compare(statuspath)!=0)
\r
548 CTGitPath askedpath;
\r
549 askedpath.SetFromWin(folder_.c_str());
\r
553 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
556 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
557 if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
558 itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
559 if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
561 if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
562 itemStates |= ITEMIS_NEEDSLOCK;
\r
564 if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
565 uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
570 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
575 status = fetchedstatus;
\r
577 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
578 itemStates |= ITEMIS_FOLDERINGit;
\r
579 if (status == git_wc_status_ignored)
\r
580 itemStates |= ITEMIS_IGNORED;
\r
581 itemStates |= ITEMIS_FOLDER;
\r
582 if (status == git_wc_status_added)
\r
583 itemStates |= ITEMIS_ADDED;
\r
584 if (status == git_wc_status_deleted)
\r
585 itemStates |= ITEMIS_DELETED;
\r
593 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
595 TCHAR menutextbuffer[255] = {0};
\r
596 TCHAR verbsbuffer[255] = {0};
\r
597 MAKESTRING(stringid);
\r
601 //menu entry for the top context menu, so append an "Git " before
\r
602 //the menu text to indicate where the entry comes from
\r
603 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
605 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
606 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
608 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
609 if (fullver >= 0x500)
\r
611 // on win2k, the context menu does not work properly if we use
\r
612 // icon bitmaps. At least the menu text is empty in the context menu
\r
613 // for folder backgrounds (seems like a win2k bug).
\r
614 HBITMAP bmp = IconToBitmap(icon);
\r
615 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
620 MENUITEMINFO menuiteminfo = {0};
\r
621 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
622 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
623 menuiteminfo.fType = MFT_STRING;
\r
624 menuiteminfo.dwTypeData = menutextbuffer;
\r
626 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
627 menuiteminfo.wID = id;
\r
628 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
633 //menu entry for the top context menu, so append an "Git " before
\r
634 //the menu text to indicate where the entry comes from
\r
635 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
637 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
638 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
639 stdstring verb = stdstring(menutextbuffer);
\r
640 if (verb.find('&') != -1)
\r
642 verb.erase(verb.find('&'),1);
\r
644 myVerbsMap[verb] = id - idCmdFirst;
\r
645 myVerbsMap[verb] = id;
\r
646 myVerbsIDMap[id - idCmdFirst] = verb;
\r
647 myVerbsIDMap[id] = verb;
\r
648 // We store the relative and absolute diameter
\r
649 // (drawitem callback uses absolute, others relative)
\r
650 myIDMap[id - idCmdFirst] = com;
\r
653 mySubMenuMap[pos] = com;
\r
656 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
658 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
659 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
660 return bitmap_it->second;
\r
662 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
668 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
669 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
671 rect.left = rect.top = 0;
\r
673 HWND desktop = ::GetDesktopWindow();
\r
674 if (desktop == NULL)
\r
676 DestroyIcon(hIcon);
\r
680 HDC screen_dev = ::GetDC(desktop);
\r
681 if (screen_dev == NULL)
\r
683 DestroyIcon(hIcon);
\r
687 // Create a compatible DC
\r
688 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
689 if (dst_hdc == NULL)
\r
691 DestroyIcon(hIcon);
\r
692 ::ReleaseDC(desktop, screen_dev);
\r
696 // Create a new bitmap of icon size
\r
697 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
700 DestroyIcon(hIcon);
\r
701 ::DeleteDC(dst_hdc);
\r
702 ::ReleaseDC(desktop, screen_dev);
\r
706 // Select it into the compatible DC
\r
707 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
708 if (old_dst_bmp == NULL)
\r
710 DestroyIcon(hIcon);
\r
714 // Fill the background of the compatible DC with the white color
\r
715 // that is taken by menu routines as transparent
\r
716 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
717 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
719 // Draw the icon into the compatible DC
\r
720 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
722 // Restore settings
\r
723 ::SelectObject(dst_hdc, old_dst_bmp);
\r
724 ::DeleteDC(dst_hdc);
\r
725 ::ReleaseDC(desktop, screen_dev);
\r
726 DestroyIcon(hIcon);
\r
728 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
732 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
735 tempfile = stdstring();
\r
736 //write all selected files and paths to a temporary file
\r
737 //for TortoiseProc.exe to read out again.
\r
739 DWORD pathlength = GetTempPath(0, NULL);
\r
740 TCHAR * path = new TCHAR[pathlength+1];
\r
741 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
742 GetTempPath (pathlength+1, path);
\r
743 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
744 tempfile = stdstring(tempFile);
\r
746 HANDLE file = ::CreateFile (tempFile,
\r
751 FILE_ATTRIBUTE_TEMPORARY,
\r
755 delete [] tempFile;
\r
756 if (file == INVALID_HANDLE_VALUE)
\r
759 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
761 if (!OpenClipboard(NULL))
\r
764 stdstring sClipboardText;
\r
765 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
766 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
769 TCHAR szFileName[MAX_PATH];
\r
770 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
771 for(UINT i = 0; i < cFiles; ++i)
\r
773 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
774 stdstring filename = szFileName;
\r
775 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
776 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
778 GlobalUnlock(hDrop);
\r
781 GlobalUnlock(hglb);
\r
784 ::CloseHandle(file);
\r
789 stdstring CShellExt::WriteFileListToTempFile()
\r
791 //write all selected files and paths to a temporary file
\r
792 //for TortoiseProc.exe to read out again.
\r
793 DWORD pathlength = GetTempPath(0, NULL);
\r
794 TCHAR * path = new TCHAR[pathlength+1];
\r
795 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
796 GetTempPath (pathlength+1, path);
\r
797 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
798 stdstring retFilePath = stdstring(tempFile);
\r
800 HANDLE file = ::CreateFile (tempFile,
\r
805 FILE_ATTRIBUTE_TEMPORARY,
\r
809 delete [] tempFile;
\r
810 if (file == INVALID_HANDLE_VALUE)
\r
811 return stdstring();
\r
814 if (files_.empty())
\r
816 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
817 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
820 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
822 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
823 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
825 ::CloseHandle(file);
\r
826 return retFilePath;
\r
829 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
831 PreserveChdir preserveChdir;
\r
834 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
835 return NOERROR; //we don't change the default action
\r
837 if ((files_.size() == 0)||(folder_.size() == 0))
\r
840 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
843 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
845 //the drop handler only has eight commands, but not all are visible at the same time:
\r
846 //if the source file(s) are under version control then those files can be moved
\r
847 //to the new location or they can be moved with a rename,
\r
848 //if they are unversioned then they can be added to the working copy
\r
849 //if they are versioned, they also can be exported to an unversioned location
\r
850 UINT idCmd = idCmdFirst;
\r
853 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
854 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
855 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
857 // Git move and rename here
\r
858 // 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
859 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
860 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
863 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
864 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
865 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
867 // Git copy and rename here, source and target from same repository
\r
868 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
869 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
870 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
873 // available if target is versioned and source is either unversioned or from another repository
\r
874 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
875 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
878 // available if source is versioned and a folder
\r
879 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
880 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
882 // Git export all here
\r
883 // available if source is versioned and a folder
\r
884 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
885 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
888 // available if source is a patchfile
\r
889 if (itemStates & ITEMIS_PATCHFILE)
\r
890 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
893 if (idCmd != idCmdFirst)
\r
894 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
896 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
899 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
902 UINT /*idCmdLast*/,
\r
905 ATLTRACE("Shell :: QueryContextMenu\n");
\r
906 PreserveChdir preserveChdir;
\r
908 //first check if our drop handler is called
\r
909 //and then (if true) provide the context menu for the
\r
911 if (m_State == FileStateDropHandler)
\r
913 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
916 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
917 return NOERROR; //we don't change the default action
\r
919 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
922 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
925 int csidlarray[] =
\r
929 CSIDL_COMMON_FAVORITES,
\r
930 CSIDL_COMMON_STARTMENU,
\r
931 CSIDL_COMPUTERSNEARME,
\r
939 CSIDL_INTERNET_CACHE,
\r
949 if (IsIllegalFolder(folder_, csidlarray))
\r
952 if (folder_.empty())
\r
954 // folder is empty, but maybe files are selected
\r
955 if (files_.size() == 0)
\r
956 return NOERROR; // nothing selected - we don't have a menu to show
\r
957 // check whether a selected entry is an UID - those are namespace extensions
\r
958 // which we can't handle
\r
959 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
961 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
966 //check if our menu is requested for a subversion admin directory
\r
967 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
970 if (uFlags & CMF_EXTENDEDVERBS)
\r
971 itemStates |= ITEMIS_EXTENDED;
\r
973 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
974 if ( bShortcut && (files_.size()==1))
\r
976 // Don't show the context menu for a link if the
\r
977 // destination is not part of a working copy.
\r
978 // It would only show the standard menu items
\r
979 // which are already shown for the lnk-file.
\r
980 CString path = files_.front().c_str();
\r
981 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
987 //check if we already added our menu entry for a folder.
\r
988 //we check that by iterating through all menu entries and check if
\r
989 //the dwItemData member points to our global ID string. That string is set
\r
990 //by our shell extension when the folder menu is inserted.
\r
991 TCHAR menubuf[MAX_PATH];
\r
992 int count = GetMenuItemCount(hMenu);
\r
993 for (int i=0; i<count; ++i)
\r
996 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
997 miif.cbSize = sizeof(MENUITEMINFO);
\r
998 miif.fMask = MIIM_DATA;
\r
999 miif.dwTypeData = menubuf;
\r
1000 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1001 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1002 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1007 UINT idCmd = idCmdFirst;
\r
1009 //create the sub menu
\r
1010 HMENU subMenu = CreateMenu();
\r
1011 int indexSubMenu = 0;
\r
1013 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1014 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1016 int menuIndex = 0;
\r
1017 bool bAddSeparator = false;
\r
1018 bool bMenuEntryAdded = false;
\r
1019 // insert separator at start
\r
1020 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1021 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1022 if (fullver <= 0x0500)
\r
1023 bShowIcons = false;
\r
1024 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1026 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1028 // we don't add a separator immediately. Because there might not be
\r
1029 // another 'normal' menu entry after we insert a separator.
\r
1030 // we simply set a flag here, indicating that before the next
\r
1031 // 'normal' menu entry, a separator should be added.
\r
1032 bAddSeparator = true;
\r
1036 // check the conditions whether to show the menu entry or not
\r
1037 bool bInsertMenu = false;
\r
1039 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1041 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1043 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1044 bInsertMenu = true;
\r
1046 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1047 bInsertMenu = true;
\r
1048 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1049 bInsertMenu = true;
\r
1051 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1053 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1055 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1056 bInsertMenu = true;
\r
1058 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1059 bInsertMenu = true;
\r
1060 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1061 bInsertMenu = true;
\r
1063 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1065 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1067 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1068 bInsertMenu = true;
\r
1070 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1071 bInsertMenu = true;
\r
1072 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1073 bInsertMenu = true;
\r
1075 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1077 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1079 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1080 bInsertMenu = true;
\r
1082 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1083 bInsertMenu = true;
\r
1084 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1085 bInsertMenu = true;
\r
1087 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1091 // insert a separator
\r
1092 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1094 bAddSeparator = false;
\r
1095 bMenuEntryAdded = false;
\r
1096 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1100 // handle special cases (sub menus)
\r
1101 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1103 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1104 bMenuEntryAdded = true;
\r
1108 // the 'get lock' command is special
\r
1109 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1110 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1112 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1115 // insert the menu entry
\r
1116 InsertGitMenu( bIsTop,
\r
1117 bIsTop ? hMenu : subMenu,
\r
1118 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1120 menuInfo[menuIndex].menuTextID,
\r
1121 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1123 menuInfo[menuIndex].command,
\r
1126 bMenuEntryAdded = true;
\r
1134 //add sub menu to main context menu
\r
1135 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1136 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1137 MAKESTRING(IDS_MENUSUBMENU);
\r
1138 MENUITEMINFO menuiteminfo;
\r
1139 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1140 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1141 menuiteminfo.fType = MFT_STRING;
\r
1142 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1144 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1145 if (folder_.size())
\r
1147 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1148 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1149 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1150 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1152 else if (!bShortcut && (files_.size()==1))
\r
1154 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1155 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1156 myIDMap[idCmd] = ShellSubMenuFile;
\r
1158 else if (bShortcut && (files_.size()==1))
\r
1160 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1161 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1162 myIDMap[idCmd] = ShellSubMenuLink;
\r
1164 else if (files_.size() > 1)
\r
1166 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1167 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1168 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1172 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1173 myIDMap[idCmd] = ShellSubMenu;
\r
1175 HBITMAP bmp = NULL;
\r
1176 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1178 bmp = IconToBitmap(uIcon);
\r
1179 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1183 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1185 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1187 menuiteminfo.hbmpChecked = bmp;
\r
1188 menuiteminfo.hbmpUnchecked = bmp;
\r
1189 menuiteminfo.hSubMenu = subMenu;
\r
1190 menuiteminfo.wID = idCmd++;
\r
1191 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1194 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1196 //return number of menu items added
\r
1197 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1201 // This is called when you invoke a command on the menu:
\r
1202 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1204 PreserveChdir preserveChdir;
\r
1205 HRESULT hr = E_INVALIDARG;
\r
1206 if (lpcmi == NULL)
\r
1209 std::string command;
\r
1210 std::string parent;
\r
1213 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1215 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1217 if (HIWORD(lpcmi->lpVerb))
\r
1219 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1220 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1221 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1222 idCmd = verb_it->second;
\r
1227 // See if we have a handler interface for this id
\r
1228 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1229 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1231 STARTUPINFO startup;
\r
1232 PROCESS_INFORMATION process;
\r
1233 memset(&startup, 0, sizeof(startup));
\r
1234 startup.cb = sizeof(startup);
\r
1235 memset(&process, 0, sizeof(process));
\r
1236 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1237 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1239 //TortoiseProc expects a command line of the form:
\r
1240 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1242 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1244 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1245 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1246 stdstring svnCmd = _T(" /command:");
\r
1247 stdstring tempfile;
\r
1248 switch (id_it->second)
\r
1251 case ShellMenuCheckout:
\r
1252 svnCmd += _T("checkout /path:\"");
\r
1253 svnCmd += folder_;
\r
1254 svnCmd += _T("\"");
\r
1256 case ShellMenuUpdate:
\r
1257 tempfile = WriteFileListToTempFile();
\r
1258 svnCmd += _T("update /pathfile:\"");
\r
1259 svnCmd += tempfile;
\r
1260 svnCmd += _T("\"");
\r
1261 svnCmd += _T(" /deletepathfile");
\r
1263 case ShellMenuUpdateExt:
\r
1264 tempfile = WriteFileListToTempFile();
\r
1265 svnCmd += _T("update /pathfile:\"");
\r
1266 svnCmd += tempfile;
\r
1267 svnCmd += _T("\"");
\r
1268 svnCmd += _T(" /deletepathfile");
\r
1269 svnCmd += _T(" /rev");
\r
1271 case ShellMenuCommit:
\r
1272 tempfile = WriteFileListToTempFile();
\r
1273 svnCmd += _T("commit /pathfile:\"");
\r
1274 svnCmd += tempfile;
\r
1275 svnCmd += _T("\"");
\r
1276 svnCmd += _T(" /deletepathfile");
\r
1278 case ShellMenuAdd:
\r
1279 case ShellMenuAddAsReplacement:
\r
1280 tempfile = WriteFileListToTempFile();
\r
1281 svnCmd += _T("add /pathfile:\"");
\r
1282 svnCmd += tempfile;
\r
1283 svnCmd += _T("\"");
\r
1284 svnCmd += _T(" /deletepathfile");
\r
1286 case ShellMenuIgnore:
\r
1287 tempfile = WriteFileListToTempFile();
\r
1288 svnCmd += _T("ignore /pathfile:\"");
\r
1289 svnCmd += tempfile;
\r
1290 svnCmd += _T("\"");
\r
1291 svnCmd += _T(" /deletepathfile");
\r
1293 case ShellMenuIgnoreCaseSensitive:
\r
1294 tempfile = WriteFileListToTempFile();
\r
1295 svnCmd += _T("ignore /pathfile:\"");
\r
1296 svnCmd += tempfile;
\r
1297 svnCmd += _T("\"");
\r
1298 svnCmd += _T(" /deletepathfile");
\r
1299 svnCmd += _T(" /onlymask");
\r
1301 case ShellMenuUnIgnore:
\r
1302 tempfile = WriteFileListToTempFile();
\r
1303 svnCmd += _T("unignore /pathfile:\"");
\r
1304 svnCmd += tempfile;
\r
1305 svnCmd += _T("\"");
\r
1306 svnCmd += _T(" /deletepathfile");
\r
1308 case ShellMenuUnIgnoreCaseSensitive:
\r
1309 tempfile = WriteFileListToTempFile();
\r
1310 svnCmd += _T("unignore /pathfile:\"");
\r
1311 svnCmd += tempfile;
\r
1312 svnCmd += _T("\"");
\r
1313 svnCmd += _T(" /deletepathfile");
\r
1314 svnCmd += _T(" /onlymask");
\r
1316 case ShellMenuRevert:
\r
1317 tempfile = WriteFileListToTempFile();
\r
1318 svnCmd += _T("revert /pathfile:\"");
\r
1319 svnCmd += tempfile;
\r
1320 svnCmd += _T("\"");
\r
1321 svnCmd += _T(" /deletepathfile");
\r
1323 case ShellMenuDelUnversioned:
\r
1324 svnCmd += _T("delunversioned /path:\"");
\r
1325 svnCmd += folder_;
\r
1326 svnCmd += _T("\"");
\r
1328 case ShellMenuCleanup:
\r
1329 tempfile = WriteFileListToTempFile();
\r
1330 svnCmd += _T("cleanup /pathfile:\"");
\r
1331 svnCmd += tempfile;
\r
1332 svnCmd += _T("\"");
\r
1333 svnCmd += _T(" /deletepathfile");
\r
1335 case ShellMenuResolve:
\r
1336 tempfile = WriteFileListToTempFile();
\r
1337 svnCmd += _T("resolve /pathfile:\"");
\r
1338 svnCmd += tempfile;
\r
1339 svnCmd += _T("\"");
\r
1340 svnCmd += _T(" /deletepathfile");
\r
1342 case ShellMenuSwitch:
\r
1343 svnCmd += _T("switch /path:\"");
\r
1344 if (files_.size() > 0)
\r
1345 svnCmd += files_.front();
\r
1347 svnCmd += folder_;
\r
1348 svnCmd += _T("\"");
\r
1350 case ShellMenuImport:
\r
1351 svnCmd += _T("import /path:\"");
\r
1352 svnCmd += folder_;
\r
1353 svnCmd += _T("\"");
\r
1355 case ShellMenuExport:
\r
1356 svnCmd += _T("export /path:\"");
\r
1357 svnCmd += folder_;
\r
1358 svnCmd += _T("\"");
\r
1360 case ShellMenuAbout:
\r
1361 svnCmd += _T("about");
\r
1363 case ShellMenuCreateRepos:
\r
1364 svnCmd += _T("repocreate /path:\"");
\r
1365 svnCmd += folder_;
\r
1366 svnCmd += _T("\"");
\r
1368 case ShellMenuMerge:
\r
1369 svnCmd += _T("merge /path:\"");
\r
1370 if (files_.size() > 0)
\r
1371 svnCmd += files_.front();
\r
1373 svnCmd += folder_;
\r
1374 svnCmd += _T("\"");
\r
1376 case ShellMenuMergeAll:
\r
1377 svnCmd += _T("mergeall /path:\"");
\r
1378 if (files_.size() > 0)
\r
1379 svnCmd += files_.front();
\r
1381 svnCmd += folder_;
\r
1382 svnCmd += _T("\"");
\r
1384 case ShellMenuCopy:
\r
1385 svnCmd += _T("copy /path:\"");
\r
1386 if (files_.size() > 0)
\r
1387 svnCmd += files_.front();
\r
1389 svnCmd += folder_;
\r
1390 svnCmd += _T("\"");
\r
1392 case ShellMenuSettings:
\r
1393 svnCmd += _T("settings");
\r
1395 case ShellMenuHelp:
\r
1396 svnCmd += _T("help");
\r
1398 case ShellMenuRename:
\r
1399 svnCmd += _T("rename /path:\"");
\r
1400 if (files_.size() > 0)
\r
1401 svnCmd += files_.front();
\r
1403 svnCmd += folder_;
\r
1404 svnCmd += _T("\"");
\r
1406 case ShellMenuRemove:
\r
1407 tempfile = WriteFileListToTempFile();
\r
1408 svnCmd += _T("remove /pathfile:\"");
\r
1409 svnCmd += tempfile;
\r
1410 svnCmd += _T("\"");
\r
1411 svnCmd += _T(" /deletepathfile");
\r
1413 case ShellMenuRemoveKeep:
\r
1414 tempfile = WriteFileListToTempFile();
\r
1415 svnCmd += _T("remove /pathfile:\"");
\r
1416 svnCmd += tempfile;
\r
1417 svnCmd += _T("\"");
\r
1418 svnCmd += _T(" /deletepathfile");
\r
1419 svnCmd += _T(" /keep");
\r
1421 case ShellMenuDiff:
\r
1422 svnCmd += _T("diff /path:\"");
\r
1423 if (files_.size() == 1)
\r
1424 svnCmd += files_.front();
\r
1425 else if (files_.size() == 2)
\r
1427 std::vector<stdstring>::iterator I = files_.begin();
\r
1430 svnCmd += _T("\" /path2:\"");
\r
1434 svnCmd += folder_;
\r
1435 svnCmd += _T("\"");
\r
1436 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1437 svnCmd += _T(" /alternative");
\r
1439 case ShellMenuPrevDiff:
\r
1440 svnCmd += _T("prevdiff /path:\"");
\r
1441 if (files_.size() == 1)
\r
1442 svnCmd += files_.front();
\r
1444 svnCmd += folder_;
\r
1445 svnCmd += _T("\"");
\r
1446 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1447 svnCmd += _T(" /alternative");
\r
1449 case ShellMenuUrlDiff:
\r
1450 svnCmd += _T("urldiff /path:\"");
\r
1451 if (files_.size() == 1)
\r
1452 svnCmd += files_.front();
\r
1454 svnCmd += folder_;
\r
1455 svnCmd += _T("\"");
\r
1457 case ShellMenuDropCopyAdd:
\r
1458 tempfile = WriteFileListToTempFile();
\r
1459 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1460 svnCmd += tempfile;
\r
1461 svnCmd += _T("\"");
\r
1462 svnCmd += _T(" /deletepathfile");
\r
1463 svnCmd += _T(" /droptarget:\"");
\r
1464 svnCmd += folder_;
\r
1465 svnCmd += _T("\"";)
\r
1467 case ShellMenuDropCopy:
\r
1468 tempfile = WriteFileListToTempFile();
\r
1469 svnCmd += _T("dropcopy /pathfile:\"");
\r
1470 svnCmd += tempfile;
\r
1471 svnCmd += _T("\"");
\r
1472 svnCmd += _T(" /deletepathfile");
\r
1473 svnCmd += _T(" /droptarget:\"");
\r
1474 svnCmd += folder_;
\r
1475 svnCmd += _T("\"";)
\r
1477 case ShellMenuDropCopyRename:
\r
1478 tempfile = WriteFileListToTempFile();
\r
1479 svnCmd += _T("dropcopy /pathfile:\"");
\r
1480 svnCmd += tempfile;
\r
1481 svnCmd += _T("\"");
\r
1482 svnCmd += _T(" /deletepathfile");
\r
1483 svnCmd += _T(" /droptarget:\"");
\r
1484 svnCmd += folder_;
\r
1485 svnCmd += _T("\" /rename";)
\r
1487 case ShellMenuDropMove:
\r
1488 tempfile = WriteFileListToTempFile();
\r
1489 svnCmd += _T("dropmove /pathfile:\"");
\r
1490 svnCmd += tempfile;
\r
1491 svnCmd += _T("\"");
\r
1492 svnCmd += _T(" /deletepathfile");
\r
1493 svnCmd += _T(" /droptarget:\"");
\r
1494 svnCmd += folder_;
\r
1495 svnCmd += _T("\"");
\r
1497 case ShellMenuDropMoveRename:
\r
1498 tempfile = WriteFileListToTempFile();
\r
1499 svnCmd += _T("dropmove /pathfile:\"");
\r
1500 svnCmd += tempfile;
\r
1501 svnCmd += _T("\"");
\r
1502 svnCmd += _T(" /deletepathfile");
\r
1503 svnCmd += _T(" /droptarget:\"");
\r
1504 svnCmd += folder_;
\r
1505 svnCmd += _T("\" /rename";)
\r
1507 case ShellMenuDropExport:
\r
1508 tempfile = WriteFileListToTempFile();
\r
1509 svnCmd += _T("dropexport /pathfile:\"");
\r
1510 svnCmd += tempfile;
\r
1511 svnCmd += _T("\"");
\r
1512 svnCmd += _T(" /deletepathfile");
\r
1513 svnCmd += _T(" /droptarget:\"");
\r
1514 svnCmd += folder_;
\r
1515 svnCmd += _T("\"");
\r
1517 case ShellMenuDropExportExtended:
\r
1518 tempfile = WriteFileListToTempFile();
\r
1519 svnCmd += _T("dropexport /pathfile:\"");
\r
1520 svnCmd += tempfile;
\r
1521 svnCmd += _T("\"");
\r
1522 svnCmd += _T(" /deletepathfile");
\r
1523 svnCmd += _T(" /droptarget:\"");
\r
1524 svnCmd += folder_;
\r
1525 svnCmd += _T("\"");
\r
1526 svnCmd += _T(" /extended");
\r
1528 case ShellMenuLog:
\r
1529 svnCmd += _T("log /path:\"");
\r
1530 if (files_.size() > 0)
\r
1531 svnCmd += files_.front();
\r
1533 svnCmd += folder_;
\r
1534 svnCmd += _T("\"");
\r
1536 case ShellMenuConflictEditor:
\r
1537 svnCmd += _T("conflicteditor /path:\"");
\r
1538 if (files_.size() > 0)
\r
1539 svnCmd += files_.front();
\r
1541 svnCmd += folder_;
\r
1542 svnCmd += _T("\"");
\r
1544 case ShellMenuRelocate:
\r
1545 svnCmd += _T("relocate /path:\"");
\r
1546 if (files_.size() > 0)
\r
1547 svnCmd += files_.front();
\r
1549 svnCmd += folder_;
\r
1550 svnCmd += _T("\"");
\r
1552 case ShellMenuShowChanged:
\r
1553 if (files_.size() > 1)
\r
1555 tempfile = WriteFileListToTempFile();
\r
1556 svnCmd += _T("repostatus /pathfile:\"");
\r
1557 svnCmd += tempfile;
\r
1558 svnCmd += _T("\"");
\r
1559 svnCmd += _T(" /deletepathfile");
\r
1563 svnCmd += _T("repostatus /path:\"");
\r
1564 if (files_.size() > 0)
\r
1565 svnCmd += files_.front();
\r
1567 svnCmd += folder_;
\r
1568 svnCmd += _T("\"");
\r
1571 case ShellMenuRepoBrowse:
\r
1572 svnCmd += _T("repobrowser /path:\"");
\r
1573 if (files_.size() > 0)
\r
1574 svnCmd += files_.front();
\r
1576 svnCmd += folder_;
\r
1577 svnCmd += _T("\"");
\r
1579 case ShellMenuBlame:
\r
1580 svnCmd += _T("blame /path:\"");
\r
1581 if (files_.size() > 0)
\r
1582 svnCmd += files_.front();
\r
1584 svnCmd += folder_;
\r
1585 svnCmd += _T("\"");
\r
1587 case ShellMenuCreatePatch:
\r
1588 tempfile = WriteFileListToTempFile();
\r
1589 svnCmd += _T("createpatch /pathfile:\"");
\r
1590 svnCmd += tempfile;
\r
1591 svnCmd += _T("\"");
\r
1592 svnCmd += _T(" /deletepathfile");
\r
1594 case ShellMenuApplyPatch:
\r
1595 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1597 // if there's a patch file in the clipboard, we save it
\r
1598 // to a temporary file and tell TortoiseMerge to use that one
\r
1599 UINT cFormat = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
1600 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1602 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1603 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1605 DWORD len = GetTempPath(0, NULL);
\r
1606 TCHAR * path = new TCHAR[len+1];
\r
1607 TCHAR * tempF = new TCHAR[len+100];
\r
1608 GetTempPath (len+1, path);
\r
1609 GetTempFileName (path, TEXT("svn"), 0, tempF);
\r
1610 std::wstring sTempFile = std::wstring(tempF);
\r
1615 size_t patchlen = strlen(lpstr);
\r
1616 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1619 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1620 if (size == patchlen)
\r
1622 itemStates |= ITEMIS_PATCHFILE;
\r
1624 files_.push_back(sTempFile);
\r
1628 GlobalUnlock(hglb);
\r
1629 CloseClipboard();
\r
1632 if (itemStates & ITEMIS_PATCHFILE)
\r
1634 svnCmd = _T(" /diff:\"");
\r
1635 if (files_.size() > 0)
\r
1637 svnCmd += files_.front();
\r
1638 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1640 svnCmd += _T("\" /patchpath:\"");
\r
1641 svnCmd += folder_;
\r
1645 svnCmd += folder_;
\r
1646 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1647 svnCmd += _T("\" /wc");
\r
1649 svnCmd += _T("\"");
\r
1653 svnCmd = _T(" /patchpath:\"");
\r
1654 if (files_.size() > 0)
\r
1655 svnCmd += files_.front();
\r
1657 svnCmd += folder_;
\r
1658 svnCmd += _T("\"");
\r
1661 myVerbsIDMap.clear();
\r
1662 myVerbsMap.clear();
\r
1663 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1666 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1667 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1668 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1671 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1672 (LPTSTR) &lpMsgBuf,
\r
1676 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1677 LocalFree( lpMsgBuf );
\r
1679 CloseHandle(process.hThread);
\r
1680 CloseHandle(process.hProcess);
\r
1683 case ShellMenuRevisionGraph:
\r
1684 svnCmd += _T("revisiongraph /path:\"");
\r
1685 if (files_.size() > 0)
\r
1686 svnCmd += files_.front();
\r
1688 svnCmd += folder_;
\r
1689 svnCmd += _T("\"");
\r
1691 case ShellMenuLock:
\r
1692 tempfile = WriteFileListToTempFile();
\r
1693 svnCmd += _T("lock /pathfile:\"");
\r
1694 svnCmd += tempfile;
\r
1695 svnCmd += _T("\"");
\r
1696 svnCmd += _T(" /deletepathfile");
\r
1698 case ShellMenuUnlock:
\r
1699 tempfile = WriteFileListToTempFile();
\r
1700 svnCmd += _T("unlock /pathfile:\"");
\r
1701 svnCmd += tempfile;
\r
1702 svnCmd += _T("\"");
\r
1703 svnCmd += _T(" /deletepathfile");
\r
1705 case ShellMenuUnlockForce:
\r
1706 tempfile = WriteFileListToTempFile();
\r
1707 svnCmd += _T("unlock /pathfile:\"");
\r
1708 svnCmd += tempfile;
\r
1709 svnCmd += _T("\"");
\r
1710 svnCmd += _T(" /deletepathfile");
\r
1711 svnCmd += _T(" /force");
\r
1713 case ShellMenuProperties:
\r
1714 tempfile = WriteFileListToTempFile();
\r
1715 svnCmd += _T("properties /pathfile:\"");
\r
1716 svnCmd += tempfile;
\r
1717 svnCmd += _T("\"");
\r
1718 svnCmd += _T(" /deletepathfile");
\r
1720 case ShellMenuClipPaste:
\r
1721 if (WriteClipboardPathsToTempFile(tempfile))
\r
1723 bool bCopy = true;
\r
1724 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1725 if (cPrefDropFormat)
\r
1727 if (OpenClipboard(lpcmi->hwnd))
\r
1729 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1732 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1733 if (*effect == DROPEFFECT_MOVE)
\r
1735 GlobalUnlock(hglb);
\r
1742 svnCmd += _T("pastecopy /pathfile:\"");
\r
1744 svnCmd += _T("pastemove /pathfile:\"");
\r
1745 svnCmd += tempfile;
\r
1746 svnCmd += _T("\"");
\r
1747 svnCmd += _T(" /deletepathfile");
\r
1748 svnCmd += _T(" /droptarget:\"");
\r
1749 svnCmd += folder_;
\r
1750 svnCmd += _T("\"");
\r
1752 else return NOERROR;
\r
1757 } // switch (id_it->second)
\r
1758 svnCmd += _T(" /hwnd:");
\r
1760 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1763 myVerbsIDMap.clear();
\r
1764 myVerbsMap.clear();
\r
1765 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1768 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1769 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1770 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1773 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1774 (LPTSTR) &lpMsgBuf,
\r
1778 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1779 LocalFree( lpMsgBuf );
\r
1781 CloseHandle(process.hThread);
\r
1782 CloseHandle(process.hProcess);
\r
1784 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1785 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1790 // This is for the status bar and things like that:
\r
1791 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1793 UINT FAR * /*reserved*/,
\r
1797 PreserveChdir preserveChdir;
\r
1798 //do we know the id?
\r
1799 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1800 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1802 return E_INVALIDARG; //no, we don't
\r
1806 HRESULT hr = E_INVALIDARG;
\r
1808 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1809 int menuIndex = 0;
\r
1810 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1812 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1814 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1820 const TCHAR * desc = stringtablebuffer;
\r
1823 case GCS_HELPTEXTA:
\r
1825 std::string help = WideToMultibyte(desc);
\r
1826 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1830 case GCS_HELPTEXTW:
\r
1832 wide_string help = desc;
\r
1833 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1839 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1840 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1842 std::string help = WideToMultibyte(verb_id_it->second);
\r
1843 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1850 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1851 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1853 wide_string help = verb_id_it->second;
\r
1854 ATLTRACE("verb : %ws\n", help.c_str());
\r
1855 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1864 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1867 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
1870 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
1872 PreserveChdir preserveChdir;
\r
1875 if (pResult == NULL)
\r
1882 case WM_MEASUREITEM:
\r
1884 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
1887 lpmis->itemWidth += 2;
\r
1888 if (lpmis->itemHeight < 16)
\r
1889 lpmis->itemHeight = 16;
\r
1896 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
1897 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
1898 return S_OK; //not for a menu
\r
1899 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
1900 if (resource == NULL)
\r
1902 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
1903 if (hIcon == NULL)
\r
1905 DrawIconEx(lpdis->hDC,
\r
1906 lpdis->rcItem.left - 16,
\r
1907 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
1909 0, NULL, DI_NORMAL);
\r
1910 DestroyIcon(hIcon);
\r
1918 if (HIWORD(wParam) != MF_POPUP)
\r
1920 int nChar = LOWORD(wParam);
\r
1921 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
1922 nChar = tolower(nChar);
\r
1923 // we have the char the user pressed, now search that char in all our
\r
1925 std::vector<int> accmenus;
\r
1926 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
1928 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
1929 if (resource == NULL)
\r
1931 szItem = stringtablebuffer;
\r
1932 TCHAR * amp = _tcschr(szItem, '&');
\r
1936 int ampChar = LOWORD(*amp);
\r
1937 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
1938 ampChar = tolower(ampChar);
\r
1939 if (ampChar == nChar)
\r
1941 // yep, we found a menu which has the pressed key
\r
1942 // as an accelerator. Add that menu to the list to
\r
1944 accmenus.push_back(It->first);
\r
1947 if (accmenus.size() == 0)
\r
1949 // no menu with that accelerator key.
\r
1950 *pResult = MAKELONG(0, MNC_IGNORE);
\r
1953 if (accmenus.size() == 1)
\r
1955 // Only one menu with that accelerator key. We're lucky!
\r
1956 // So just execute that menu entry.
\r
1957 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
1960 if (accmenus.size() > 1)
\r
1962 // we have more than one menu item with this accelerator key!
\r
1964 mif.cbSize = sizeof(MENUITEMINFO);
\r
1965 mif.fMask = MIIM_STATE;
\r
1966 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
1968 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
1969 if (mif.fState == MFS_HILITE)
\r
1971 // this is the selected item, so select the next one
\r
1973 if (it == accmenus.end())
\r
1974 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
1976 *pResult = MAKELONG(*it, MNC_SELECT);
\r
1980 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
1991 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
1993 TCHAR textbuf[255];
\r
1994 LPCTSTR resource = NULL;
\r
1995 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
1998 int menuIndex = 0;
\r
1999 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2001 if (menuInfo[menuIndex].command == id)
\r
2003 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2004 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2007 case ShellMenuLock:
\r
2008 // menu lock is special because it can be set to the top
\r
2009 // with a separate option in the registry
\r
2010 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2011 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2013 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2014 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2015 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2018 // the sub menu entries are special because they're *always* on the top level menu
\r
2019 case ShellSubMenuMultiple:
\r
2020 case ShellSubMenuLink:
\r
2021 case ShellSubMenuFolder:
\r
2022 case ShellSubMenuFile:
\r
2023 case ShellSubMenu:
\r
2027 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2028 if (layout & (menuInfo[menuIndex].menuID))
\r
2030 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2031 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2032 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2043 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2046 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2047 LPITEMIDLIST pidl = NULL;
\r
2048 while (cslidarray[i])
\r
2052 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2054 if (!SHGetPathFromIDList(pidl, buf))
\r
2056 // not a file system path, definitely illegal for our use
\r
2057 CoTaskMemFree(pidl);
\r
2060 CoTaskMemFree(pidl);
\r
2061 if (_tcslen(buf)==0)
\r
2063 if (_tcscmp(buf, folder.c_str())==0)
\r
2069 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2071 HMENU ignoresubmenu = NULL;
\r
2072 int indexignoresub = 0;
\r
2073 bool bShowIgnoreMenu = false;
\r
2074 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2075 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2076 if (files_.size() == 0)
\r
2078 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2080 std::vector<stdstring>::iterator I = files_.begin();
\r
2081 if (_tcsrchr(I->c_str(), '\\'))
\r
2082 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2084 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2085 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2087 // check if the item name is ignored or the mask
\r
2089 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2091 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2092 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2100 ignoresubmenu = CreateMenu();
\r
2101 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2102 stdstring verb = stdstring(ignorepath);
\r
2103 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2104 myVerbsMap[verb] = idCmd;
\r
2105 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2106 myVerbsIDMap[idCmd] = verb;
\r
2107 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2108 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2109 bShowIgnoreMenu = true;
\r
2111 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2112 if (_tcsrchr(ignorepath, '.'))
\r
2114 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2115 p = ignoredprops.find(maskbuf);
\r
2117 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2119 if (ignoresubmenu==NULL)
\r
2120 ignoresubmenu = CreateMenu();
\r
2122 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2123 stdstring verb = stdstring(maskbuf);
\r
2124 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2125 myVerbsMap[verb] = idCmd;
\r
2126 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2127 myVerbsIDMap[idCmd] = verb;
\r
2128 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2129 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2130 bShowIgnoreMenu = true;
\r
2134 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2136 bShowIgnoreMenu = true;
\r
2137 ignoresubmenu = CreateMenu();
\r
2138 if (itemStates & ITEMIS_ONLYONE)
\r
2140 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2141 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2142 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2144 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2145 if (_tcsrchr(ignorepath, '.'))
\r
2147 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2148 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2149 stdstring verb = stdstring(maskbuf);
\r
2150 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2151 myVerbsMap[verb] = idCmd;
\r
2152 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2153 myVerbsIDMap[idCmd] = verb;
\r
2154 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2155 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2160 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2161 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2162 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2163 stdstring verb = stdstring(ignorepath);
\r
2164 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2165 myVerbsMap[verb] = idCmd;
\r
2166 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2167 myVerbsIDMap[idCmd] = verb;
\r
2168 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2169 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2171 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2172 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2173 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2174 verb = stdstring(ignorepath);
\r
2175 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2176 myVerbsMap[verb] = idCmd;
\r
2177 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2178 myVerbsIDMap[idCmd] = verb;
\r
2179 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2180 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2184 if (bShowIgnoreMenu)
\r
2186 MENUITEMINFO menuiteminfo;
\r
2187 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2188 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2189 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2190 menuiteminfo.fType = MFT_STRING;
\r
2191 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2193 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2194 menuiteminfo.hbmpChecked = bmp;
\r
2195 menuiteminfo.hbmpUnchecked = bmp;
\r
2196 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2197 menuiteminfo.wID = idCmd;
\r
2198 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2199 if (itemStates & ITEMIS_IGNORED)
\r
2200 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2202 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2203 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2204 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2206 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2207 if (itemStates & ITEMIS_IGNORED)
\r
2209 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2210 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2214 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2215 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2220 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2222 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2223 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2224 return bitmap_it->second;
\r
2226 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2230 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2234 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2235 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2238 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2239 HBITMAP hBmp = NULL;
\r
2241 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2244 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2246 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2249 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2250 BP_PAINTPARAMS paintParams = {0};
\r
2251 paintParams.cbSize = sizeof(paintParams);
\r
2252 paintParams.dwFlags = BPPF_ERASE;
\r
2253 paintParams.pBlendFunction = &bfAlpha;
\r
2256 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2259 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2261 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2262 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2265 // This will write the buffer contents to the destination bitmap
\r
2266 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2269 SelectObject(hdcDest, hbmpOld);
\r
2273 DeleteDC(hdcDest);
\r
2276 DestroyIcon(hIcon);
\r
2279 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2283 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2288 ZeroMemory(&bmi, sizeof(bmi));
\r
2289 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2290 bmi.bmiHeader.biPlanes = 1;
\r
2291 bmi.bmiHeader.biCompression = BI_RGB;
\r
2293 bmi.bmiHeader.biWidth = psize->cx;
\r
2294 bmi.bmiHeader.biHeight = psize->cy;
\r
2295 bmi.bmiHeader.biBitCount = 32;
\r
2297 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2300 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2301 if (hdc != hdcUsed)
\r
2303 ReleaseDC(NULL, hdcUsed);
\r
2306 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2309 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2311 RGBQUAD *prgbQuad;
\r
2313 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2314 if (SUCCEEDED(hr))
\r
2316 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2317 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2320 if (GetIconInfo(hicon, &info))
\r
2324 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2327 DeleteObject(info.hbmColor);
\r
2328 DeleteObject(info.hbmMask);
\r
2336 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2338 ULONG cxDelta = cxRow - sizImage.cx;
\r
2339 for (ULONG y = sizImage.cy; y; --y)
\r
2341 for (ULONG x = sizImage.cx; x; --x)
\r
2343 if (*pargb++ & 0xFF000000)
\r
2355 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2358 ZeroMemory(&bmi, sizeof(bmi));
\r
2359 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2360 bmi.bmiHeader.biPlanes = 1;
\r
2361 bmi.bmiHeader.biCompression = BI_RGB;
\r
2363 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2364 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2365 bmi.bmiHeader.biBitCount = 32;
\r
2367 HRESULT hr = E_OUTOFMEMORY;
\r
2368 HANDLE hHeap = GetProcessHeap();
\r
2369 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2372 hr = E_UNEXPECTED;
\r
2373 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2375 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2376 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2378 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2380 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2384 // transparent pixel
\r
2390 *pargb++ |= 0xFF000000;
\r
2400 HeapFree(hHeap, 0, pvBits);
\r