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, IDS_MENUPULL,
\r
39 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
41 { ShellMenuFetch, MENUFETCH, IDI_PULL, IDS_MENUFETCH, IDS_MENUFETCH,
\r
42 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
44 { ShellMenuPush, MENUPUSH, IDI_PUSH, IDS_MENUPUSH, IDS_MENUPULL,
\r
45 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
47 // { ShellMenuCheckout, MENUCHECKOUT, IDI_CHECKOUT, IDS_MENUCHECKOUT, IDS_MENUDESCCHECKOUT,
\r
48 // ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
50 // { ShellMenuUpdate, MENUUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
\r
51 // ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
53 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
54 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
56 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
58 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
59 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
61 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
62 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
64 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
65 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
67 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
68 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
70 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
71 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
73 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
74 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
76 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
77 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
79 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
81 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
82 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
84 // { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
85 // ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
87 // { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
88 // ITEMIS_INSVN, ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
90 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
91 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
93 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
94 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
96 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
97 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
99 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
100 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
102 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
103 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
105 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
106 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
108 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
109 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
111 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
112 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
114 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
115 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
117 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
118 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
120 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
122 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
123 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
125 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
126 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
128 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
129 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
130 { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
131 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
133 { ShellMenuBranch, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
134 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
135 { ShellMenuTag, MENUTAG, IDI_TAG, IDS_MENUTAG, IDS_MENUDESCCOPY,
\r
136 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
138 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
139 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
141 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
142 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
144 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
146 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
147 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
149 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
150 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
152 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
153 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
155 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
156 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
158 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
159 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
161 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
162 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
164 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
165 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
167 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
169 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
170 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
172 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
173 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
175 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
176 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
179 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
180 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
182 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
183 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },
\r
185 { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
186 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
188 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
189 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
190 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
192 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
194 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
195 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
196 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
197 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
198 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
199 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
201 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
202 // but they still need to be in here, because we use the icon and string information anyway.
\r
203 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
204 0, 0, 0, 0, 0, 0, 0, 0 },
\r
205 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
206 0, 0, 0, 0, 0, 0, 0, 0 },
\r
207 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
208 0, 0, 0, 0, 0, 0, 0, 0 },
\r
209 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
210 0, 0, 0, 0, 0, 0, 0, 0 },
\r
211 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
212 0, 0, 0, 0, 0, 0, 0, 0 },
\r
213 // mark the last entry to tell the loop where to stop iterating over this array
\r
214 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
215 0, 0, 0, 0, 0, 0, 0, 0 },
\r
219 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
220 LPDATAOBJECT pDataObj,
\r
221 HKEY /* hRegKey */)
\r
224 ATLTRACE("Shell :: Initialize\n");
\r
225 PreserveChdir preserveChdir;
\r
228 uuidSource.erase();
\r
229 uuidTarget.erase();
\r
231 itemStatesFolder = 0;
\r
232 stdstring statuspath;
\r
233 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
234 // get selected files/folders
\r
238 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
239 (DVTARGETDEVICE FAR *)NULL,
\r
243 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
245 if (SUCCEEDED(hres) && medium.hGlobal)
\r
247 if (m_State == FileStateDropHandler)
\r
250 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
251 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
252 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
254 ReleaseStgMedium ( &medium );
\r
255 return E_INVALIDARG;
\r
259 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
260 if ( NULL == drop )
\r
262 ReleaseStgMedium ( &stg );
\r
263 ReleaseStgMedium ( &medium );
\r
264 return E_INVALIDARG;
\r
267 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
269 itemStates |= ITEMIS_ONLYONE;
\r
270 for (int i = 0; i < count; i++)
\r
272 // find the path length in chars
\r
273 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
276 TCHAR * szFileName = new TCHAR[len+1];
\r
277 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
279 delete [] szFileName;
\r
282 stdstring str = stdstring(szFileName);
\r
283 delete [] szFileName;
\r
284 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
286 if (itemStates & ITEMIS_ONLYONE)
\r
289 strpath.SetFromWin(str.c_str());
\r
290 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
291 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
293 files_.push_back(str);
\r
296 //get the Subversion status of the item
\r
297 git_wc_status_kind status = git_wc_status_none;
\r
298 CTGitPath askedpath;
\r
299 askedpath.SetFromWin(str.c_str());
\r
303 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
307 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
308 fetchedstatus = status;
\r
309 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
310 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
311 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
313 // itemStates |= ITEMIS_FOLDER;
\r
314 // if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
315 // itemStates |= ITEMIS_FOLDERINGit;
\r
317 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
319 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
320 // itemStates |= ITEMIS_NEEDSLOCK;
\r
322 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
323 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
327 // sometimes, git_client_status() returns with an error.
\r
328 // in that case, we have to check if the working copy is versioned
\r
329 // anyway to show the 'correct' context menu
\r
330 if (askedpath.HasAdminDir())
\r
331 status = git_wc_status_normal;
\r
336 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
338 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
339 if (askedpath.HasAdminDir())
\r
340 itemStates |= ITEMIS_INSVN;
\r
341 if (status == git_wc_status_ignored)
\r
342 itemStates |= ITEMIS_IGNORED;
\r
343 if (status == git_wc_status_normal)
\r
344 itemStates |= ITEMIS_NORMAL;
\r
345 if (status == git_wc_status_conflicted)
\r
346 itemStates |= ITEMIS_CONFLICTED;
\r
347 if (status == git_wc_status_added)
\r
348 itemStates |= ITEMIS_ADDED;
\r
349 if (status == git_wc_status_deleted)
\r
350 itemStates |= ITEMIS_DELETED;
\r
353 } // for (int i = 0; i < count; i++)
\r
354 GlobalUnlock ( drop );
\r
355 ReleaseStgMedium ( &stg );
\r
357 } // if (m_State == FileStateDropHandler)
\r
361 //Enumerate PIDLs which the user has selected
\r
362 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
363 ItemIDList parent( GetPIDLFolder (cida));
\r
365 int count = cida->cidl;
\r
366 BOOL statfetched = FALSE;
\r
367 for (int i = 0; i < count; ++i)
\r
369 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
370 stdstring str = child.toString();
\r
371 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
373 //check if our menu is requested for a subversion admin directory
\r
374 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
377 files_.push_back(str);
\r
379 strpath.SetFromWin(str.c_str());
\r
380 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
381 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
384 //get the Subversion status of the item
\r
385 git_wc_status_kind status = git_wc_status_none;
\r
386 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
388 if (strpath.HasAdminDir())
\r
389 status = git_wc_status_normal;
\r
396 if (strpath.HasAdminDir())
\r
397 stat.GetStatus(strpath, false, true, true);
\r
401 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
402 fetchedstatus = status;
\r
403 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
404 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
405 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
407 // itemStates |= ITEMIS_FOLDER;
\r
408 // if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
409 // itemStates |= ITEMIS_FOLDERINGit;
\r
411 //if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
412 // itemStates |= ITEMIS_CONFLICTED;
\r
413 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
415 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
416 // itemStates |= ITEMIS_NEEDSLOCK;
\r
418 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
419 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
423 // sometimes, git_client_status() returns with an error.
\r
424 // in that case, we have to check if the working copy is versioned
\r
425 // anyway to show the 'correct' context menu
\r
426 if (strpath.HasAdminDir())
\r
428 status = git_wc_status_normal;
\r
429 fetchedstatus = status;
\r
432 statfetched = TRUE;
\r
436 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
439 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
440 if (strpath.HasAdminDir())
\r
441 itemStates |= ITEMIS_INSVN;
\r
442 if (status == git_wc_status_ignored)
\r
444 itemStates |= ITEMIS_IGNORED;
\r
445 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
446 // offer a 'remove from ignored list' entry
\r
447 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
448 // ignoredprops.empty();
\r
449 // for (int p=0; p<props.GetCount(); ++p)
\r
451 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
453 // std::string st = props.GetItemValue(p);
\r
454 // ignoredprops = MultibyteToWide(st.c_str());
\r
455 // // remove all escape chars ('\\')
\r
456 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
461 if (status == git_wc_status_normal)
\r
462 itemStates |= ITEMIS_NORMAL;
\r
463 if (status == git_wc_status_conflicted)
\r
464 itemStates |= ITEMIS_CONFLICTED;
\r
465 if (status == git_wc_status_added)
\r
466 itemStates |= ITEMIS_ADDED;
\r
467 if (status == git_wc_status_deleted)
\r
468 itemStates |= ITEMIS_DELETED;
\r
471 } // for (int i = 0; i < count; ++i)
\r
472 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
473 // ? was this disabled because the /wc option does not work safely with Git? or because the code below didn't compile before?
\r
474 // if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
475 // itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
476 GlobalUnlock(medium.hGlobal);
\r
478 // if the item is a versioned folder, check if there's a patch file
\r
479 // in the clipboard to be used in "Apply Patch"
\r
480 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
483 if (IsClipboardFormatAvailable(cFormatDiff))
\r
484 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
486 if (IsClipboardFormatAvailable(CF_HDROP))
\r
487 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
491 ReleaseStgMedium ( &medium );
\r
492 if (medium.pUnkForRelease)
\r
494 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
495 relInterface->Release();
\r
500 // get folder background
\r
504 ItemIDList list(pIDFolder);
\r
505 folder_ = list.toString();
\r
506 git_wc_status_kind status = git_wc_status_none;
\r
507 if (IsClipboardFormatAvailable(CF_HDROP))
\r
508 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
510 CTGitPath askedpath;
\r
511 askedpath.SetFromWin(folder_.c_str());
\r
513 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
519 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
522 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
523 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
524 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
525 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
527 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
528 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
530 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
531 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
536 // sometimes, git_client_status() returns with an error.
\r
537 // in that case, we have to check if the working copy is versioned
\r
538 // anyway to show the 'correct' context menu
\r
539 if (askedpath.HasAdminDir())
\r
540 status = git_wc_status_normal;
\r
543 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
544 if (askedpath.HasAdminDir())
\r
545 itemStatesFolder |= ITEMIS_INSVN;
\r
546 if (status == git_wc_status_normal)
\r
547 itemStatesFolder |= ITEMIS_NORMAL;
\r
548 if (status == git_wc_status_conflicted)
\r
549 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
550 if (status == git_wc_status_added)
\r
551 itemStatesFolder |= ITEMIS_ADDED;
\r
552 if (status == git_wc_status_deleted)
\r
553 itemStatesFolder |= ITEMIS_DELETED;
\r
558 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
563 status = fetchedstatus;
\r
565 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
566 if (askedpath.HasAdminDir())
\r
568 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
570 if (status == git_wc_status_ignored)
\r
571 itemStatesFolder |= ITEMIS_IGNORED;
\r
572 itemStatesFolder |= ITEMIS_FOLDER;
\r
573 if (files_.size() == 0)
\r
574 itemStates |= ITEMIS_ONLYONE;
\r
575 if (m_State != FileStateDropHandler)
\r
576 itemStates |= itemStatesFolder;
\r
579 if (files_.size() == 2)
\r
580 itemStates |= ITEMIS_TWO;
\r
581 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
584 itemStates |= ITEMIS_ONLYONE;
\r
585 if (m_State != FileStateDropHandler)
\r
587 if (PathIsDirectory(files_.front().c_str()))
\r
589 folder_ = files_.front();
\r
590 git_wc_status_kind status = git_wc_status_none;
\r
591 CTGitPath askedpath;
\r
592 askedpath.SetFromWin(folder_.c_str());
\r
594 if (folder_.compare(statuspath)!=0)
\r
599 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
602 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
603 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
604 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
605 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
607 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
608 // itemStates |= ITEMIS_NEEDSLOCK;
\r
610 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
611 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
616 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
621 status = fetchedstatus;
\r
623 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
624 if (askedpath.HasAdminDir())
\r
625 itemStates |= ITEMIS_FOLDERINSVN;
\r
626 if (status == git_wc_status_ignored)
\r
627 itemStates |= ITEMIS_IGNORED;
\r
628 itemStates |= ITEMIS_FOLDER;
\r
629 if (status == git_wc_status_added)
\r
630 itemStates |= ITEMIS_ADDED;
\r
631 if (status == git_wc_status_deleted)
\r
632 itemStates |= ITEMIS_DELETED;
\r
641 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
643 TCHAR menutextbuffer[255] = {0};
\r
644 TCHAR verbsbuffer[255] = {0};
\r
645 MAKESTRING(stringid);
\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 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
654 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
656 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
657 if (fullver >= 0x500)
\r
659 // on win2k, the context menu does not work properly if we use
\r
660 // icon bitmaps. At least the menu text is empty in the context menu
\r
661 // for folder backgrounds (seems like a win2k bug).
\r
662 HBITMAP bmp = IconToBitmap(icon);
\r
663 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
668 MENUITEMINFO menuiteminfo = {0};
\r
669 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
670 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
671 menuiteminfo.fType = MFT_STRING;
\r
672 menuiteminfo.dwTypeData = menutextbuffer;
\r
674 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
675 menuiteminfo.wID = id;
\r
676 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
681 //menu entry for the top context menu, so append an "Git " before
\r
682 //the menu text to indicate where the entry comes from
\r
683 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
685 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
686 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
687 stdstring verb = stdstring(menutextbuffer);
\r
688 if (verb.find('&') != -1)
\r
690 verb.erase(verb.find('&'),1);
\r
692 myVerbsMap[verb] = id - idCmdFirst;
\r
693 myVerbsMap[verb] = id;
\r
694 myVerbsIDMap[id - idCmdFirst] = verb;
\r
695 myVerbsIDMap[id] = verb;
\r
696 // We store the relative and absolute diameter
\r
697 // (drawitem callback uses absolute, others relative)
\r
698 myIDMap[id - idCmdFirst] = com;
\r
701 mySubMenuMap[pos] = com;
\r
704 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
706 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
707 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
708 return bitmap_it->second;
\r
710 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
716 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
717 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
719 rect.left = rect.top = 0;
\r
721 HWND desktop = ::GetDesktopWindow();
\r
722 if (desktop == NULL)
\r
724 DestroyIcon(hIcon);
\r
728 HDC screen_dev = ::GetDC(desktop);
\r
729 if (screen_dev == NULL)
\r
731 DestroyIcon(hIcon);
\r
735 // Create a compatible DC
\r
736 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
737 if (dst_hdc == NULL)
\r
739 DestroyIcon(hIcon);
\r
740 ::ReleaseDC(desktop, screen_dev);
\r
744 // Create a new bitmap of icon size
\r
745 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
748 DestroyIcon(hIcon);
\r
749 ::DeleteDC(dst_hdc);
\r
750 ::ReleaseDC(desktop, screen_dev);
\r
754 // Select it into the compatible DC
\r
755 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
756 if (old_dst_bmp == NULL)
\r
758 DestroyIcon(hIcon);
\r
762 // Fill the background of the compatible DC with the white color
\r
763 // that is taken by menu routines as transparent
\r
764 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
765 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
767 // Draw the icon into the compatible DC
\r
768 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
770 // Restore settings
\r
771 ::SelectObject(dst_hdc, old_dst_bmp);
\r
772 ::DeleteDC(dst_hdc);
\r
773 ::ReleaseDC(desktop, screen_dev);
\r
774 DestroyIcon(hIcon);
\r
776 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
780 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
783 tempfile = stdstring();
\r
784 //write all selected files and paths to a temporary file
\r
785 //for TortoiseProc.exe to read out again.
\r
787 DWORD pathlength = GetTempPath(0, NULL);
\r
788 TCHAR * path = new TCHAR[pathlength+1];
\r
789 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
790 GetTempPath (pathlength+1, path);
\r
791 GetTempFileName (path, _T("git"), 0, tempFile);
\r
792 tempfile = stdstring(tempFile);
\r
794 HANDLE file = ::CreateFile (tempFile,
\r
799 FILE_ATTRIBUTE_TEMPORARY,
\r
803 delete [] tempFile;
\r
804 if (file == INVALID_HANDLE_VALUE)
\r
807 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
809 if (!OpenClipboard(NULL))
\r
812 stdstring sClipboardText;
\r
813 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
814 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
817 TCHAR szFileName[MAX_PATH];
\r
818 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
819 for(UINT i = 0; i < cFiles; ++i)
\r
821 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
822 stdstring filename = szFileName;
\r
823 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
824 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
826 GlobalUnlock(hDrop);
\r
829 GlobalUnlock(hglb);
\r
832 ::CloseHandle(file);
\r
837 stdstring CShellExt::WriteFileListToTempFile()
\r
839 //write all selected files and paths to a temporary file
\r
840 //for TortoiseProc.exe to read out again.
\r
841 DWORD pathlength = GetTempPath(0, NULL);
\r
842 TCHAR * path = new TCHAR[pathlength+1];
\r
843 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
844 GetTempPath (pathlength+1, path);
\r
845 GetTempFileName (path, _T("git"), 0, tempFile);
\r
846 stdstring retFilePath = stdstring(tempFile);
\r
848 HANDLE file = ::CreateFile (tempFile,
\r
853 FILE_ATTRIBUTE_TEMPORARY,
\r
857 delete [] tempFile;
\r
858 if (file == INVALID_HANDLE_VALUE)
\r
859 return stdstring();
\r
862 if (files_.empty())
\r
864 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
865 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
868 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
870 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
871 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
873 ::CloseHandle(file);
\r
874 return retFilePath;
\r
877 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
879 PreserveChdir preserveChdir;
\r
882 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
883 return NOERROR; //we don't change the default action
\r
885 if ((files_.size() == 0)||(folder_.size() == 0))
\r
888 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
891 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
893 //the drop handler only has eight commands, but not all are visible at the same time:
\r
894 //if the source file(s) are under version control then those files can be moved
\r
895 //to the new location or they can be moved with a rename,
\r
896 //if they are unversioned then they can be added to the working copy
\r
897 //if they are versioned, they also can be exported to an unversioned location
\r
898 UINT idCmd = idCmdFirst;
\r
901 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
902 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
903 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
905 // Git move and rename here
\r
906 // 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
907 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
908 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
911 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
912 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
913 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
915 // Git copy and rename here, source and target from same repository
\r
916 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
917 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
918 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
921 // available if target is versioned and source is either unversioned or from another repository
\r
922 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
923 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
926 // available if source is versioned and a folder
\r
927 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
928 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
930 // Git export all here
\r
931 // available if source is versioned and a folder
\r
932 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
933 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
936 // available if source is a patchfile
\r
937 if (itemStates & ITEMIS_PATCHFILE)
\r
938 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
941 if (idCmd != idCmdFirst)
\r
942 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
944 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
947 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
950 UINT /*idCmdLast*/,
\r
953 ATLTRACE("Shell :: QueryContextMenu\n");
\r
954 PreserveChdir preserveChdir;
\r
956 //first check if our drop handler is called
\r
957 //and then (if true) provide the context menu for the
\r
959 if (m_State == FileStateDropHandler)
\r
961 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
964 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
965 return NOERROR; //we don't change the default action
\r
967 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
970 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
973 int csidlarray[] =
\r
977 CSIDL_COMMON_FAVORITES,
\r
978 CSIDL_COMMON_STARTMENU,
\r
979 CSIDL_COMPUTERSNEARME,
\r
987 CSIDL_INTERNET_CACHE,
\r
997 if (IsIllegalFolder(folder_, csidlarray))
\r
1000 if (folder_.empty())
\r
1002 // folder is empty, but maybe files are selected
\r
1003 if (files_.size() == 0)
\r
1004 return NOERROR; // nothing selected - we don't have a menu to show
\r
1005 // check whether a selected entry is an UID - those are namespace extensions
\r
1006 // which we can't handle
\r
1007 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1009 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1014 //check if our menu is requested for a subversion admin directory
\r
1015 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1018 if (uFlags & CMF_EXTENDEDVERBS)
\r
1019 itemStates |= ITEMIS_EXTENDED;
\r
1021 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1022 if ( bShortcut && (files_.size()==1))
\r
1024 // Don't show the context menu for a link if the
\r
1025 // destination is not part of a working copy.
\r
1026 // It would only show the standard menu items
\r
1027 // which are already shown for the lnk-file.
\r
1028 CString path = files_.front().c_str();
\r
1029 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1035 //check if we already added our menu entry for a folder.
\r
1036 //we check that by iterating through all menu entries and check if
\r
1037 //the dwItemData member points to our global ID string. That string is set
\r
1038 //by our shell extension when the folder menu is inserted.
\r
1039 TCHAR menubuf[MAX_PATH];
\r
1040 int count = GetMenuItemCount(hMenu);
\r
1041 for (int i=0; i<count; ++i)
\r
1043 MENUITEMINFO miif;
\r
1044 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1045 miif.cbSize = sizeof(MENUITEMINFO);
\r
1046 miif.fMask = MIIM_DATA;
\r
1047 miif.dwTypeData = menubuf;
\r
1048 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1049 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1050 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1055 UINT idCmd = idCmdFirst;
\r
1057 //create the sub menu
\r
1058 HMENU subMenu = CreateMenu();
\r
1059 int indexSubMenu = 0;
\r
1061 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1062 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1064 int menuIndex = 0;
\r
1065 bool bAddSeparator = false;
\r
1066 bool bMenuEntryAdded = false;
\r
1067 // insert separator at start
\r
1068 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1069 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1070 if (fullver <= 0x0500)
\r
1071 bShowIcons = false;
\r
1072 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1074 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1076 // we don't add a separator immediately. Because there might not be
\r
1077 // another 'normal' menu entry after we insert a separator.
\r
1078 // we simply set a flag here, indicating that before the next
\r
1079 // 'normal' menu entry, a separator should be added.
\r
1080 bAddSeparator = true;
\r
1084 // check the conditions whether to show the menu entry or not
\r
1085 bool bInsertMenu = false;
\r
1087 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1089 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1091 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1092 bInsertMenu = true;
\r
1094 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1095 bInsertMenu = true;
\r
1096 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1097 bInsertMenu = true;
\r
1099 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1101 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1103 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1104 bInsertMenu = true;
\r
1106 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1107 bInsertMenu = true;
\r
1108 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1109 bInsertMenu = true;
\r
1111 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1113 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1115 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1116 bInsertMenu = true;
\r
1118 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1119 bInsertMenu = true;
\r
1120 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1121 bInsertMenu = true;
\r
1123 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1125 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1127 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1128 bInsertMenu = true;
\r
1130 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1131 bInsertMenu = true;
\r
1132 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1133 bInsertMenu = true;
\r
1135 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1139 // insert a separator
\r
1140 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1142 bAddSeparator = false;
\r
1143 bMenuEntryAdded = false;
\r
1144 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1148 // handle special cases (sub menus)
\r
1149 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1151 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1152 bMenuEntryAdded = true;
\r
1156 // the 'get lock' command is special
\r
1157 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1158 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1160 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1163 // insert the menu entry
\r
1164 InsertGitMenu( bIsTop,
\r
1165 bIsTop ? hMenu : subMenu,
\r
1166 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1168 menuInfo[menuIndex].menuTextID,
\r
1169 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1171 menuInfo[menuIndex].command,
\r
1174 bMenuEntryAdded = true;
\r
1182 //add sub menu to main context menu
\r
1183 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1184 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1185 MAKESTRING(IDS_MENUSUBMENU);
\r
1186 MENUITEMINFO menuiteminfo;
\r
1187 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1188 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1189 menuiteminfo.fType = MFT_STRING;
\r
1190 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1192 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1193 if (folder_.size())
\r
1195 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1196 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1197 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1198 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1200 else if (!bShortcut && (files_.size()==1))
\r
1202 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1203 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1204 myIDMap[idCmd] = ShellSubMenuFile;
\r
1206 else if (bShortcut && (files_.size()==1))
\r
1208 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1209 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1210 myIDMap[idCmd] = ShellSubMenuLink;
\r
1212 else if (files_.size() > 1)
\r
1214 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1215 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1216 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1220 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1221 myIDMap[idCmd] = ShellSubMenu;
\r
1223 HBITMAP bmp = NULL;
\r
1224 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1226 bmp = IconToBitmap(uIcon);
\r
1227 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1231 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1233 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1235 menuiteminfo.hbmpChecked = bmp;
\r
1236 menuiteminfo.hbmpUnchecked = bmp;
\r
1237 menuiteminfo.hSubMenu = subMenu;
\r
1238 menuiteminfo.wID = idCmd++;
\r
1239 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1242 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1244 //return number of menu items added
\r
1245 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1249 // This is called when you invoke a command on the menu:
\r
1250 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1252 PreserveChdir preserveChdir;
\r
1253 HRESULT hr = E_INVALIDARG;
\r
1254 if (lpcmi == NULL)
\r
1257 std::string command;
\r
1258 std::string parent;
\r
1261 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1263 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1265 if (HIWORD(lpcmi->lpVerb))
\r
1267 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1268 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1269 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1270 idCmd = verb_it->second;
\r
1275 // See if we have a handler interface for this id
\r
1276 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1277 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1279 STARTUPINFO startup;
\r
1280 PROCESS_INFORMATION process;
\r
1281 memset(&startup, 0, sizeof(startup));
\r
1282 startup.cb = sizeof(startup);
\r
1283 memset(&process, 0, sizeof(process));
\r
1284 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1285 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1287 //TortoiseProc expects a command line of the form:
\r
1288 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1290 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1292 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1293 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1294 stdstring svnCmd = _T(" /command:");
\r
1295 stdstring tempfile;
\r
1296 switch (id_it->second)
\r
1299 case ShellMenuCheckout:
\r
1300 svnCmd += _T("checkout /path:\"");
\r
1301 svnCmd += folder_;
\r
1302 svnCmd += _T("\"");
\r
1304 case ShellMenuUpdate:
\r
1305 tempfile = WriteFileListToTempFile();
\r
1306 svnCmd += _T("update /pathfile:\"");
\r
1307 svnCmd += tempfile;
\r
1308 svnCmd += _T("\"");
\r
1309 svnCmd += _T(" /deletepathfile");
\r
1311 case ShellMenuUpdateExt:
\r
1312 tempfile = WriteFileListToTempFile();
\r
1313 svnCmd += _T("update /pathfile:\"");
\r
1314 svnCmd += tempfile;
\r
1315 svnCmd += _T("\"");
\r
1316 svnCmd += _T(" /deletepathfile");
\r
1317 svnCmd += _T(" /rev");
\r
1319 case ShellMenuCommit:
\r
1320 tempfile = WriteFileListToTempFile();
\r
1321 svnCmd += _T("commit /pathfile:\"");
\r
1322 svnCmd += tempfile;
\r
1323 svnCmd += _T("\"");
\r
1324 svnCmd += _T(" /deletepathfile");
\r
1326 case ShellMenuAdd:
\r
1327 case ShellMenuAddAsReplacement:
\r
1328 tempfile = WriteFileListToTempFile();
\r
1329 svnCmd += _T("add /pathfile:\"");
\r
1330 svnCmd += tempfile;
\r
1331 svnCmd += _T("\"");
\r
1332 svnCmd += _T(" /deletepathfile");
\r
1334 case ShellMenuIgnore:
\r
1335 tempfile = WriteFileListToTempFile();
\r
1336 svnCmd += _T("ignore /pathfile:\"");
\r
1337 svnCmd += tempfile;
\r
1338 svnCmd += _T("\"");
\r
1339 svnCmd += _T(" /deletepathfile");
\r
1341 case ShellMenuIgnoreCaseSensitive:
\r
1342 tempfile = WriteFileListToTempFile();
\r
1343 svnCmd += _T("ignore /pathfile:\"");
\r
1344 svnCmd += tempfile;
\r
1345 svnCmd += _T("\"");
\r
1346 svnCmd += _T(" /deletepathfile");
\r
1347 svnCmd += _T(" /onlymask");
\r
1349 case ShellMenuUnIgnore:
\r
1350 tempfile = WriteFileListToTempFile();
\r
1351 svnCmd += _T("unignore /pathfile:\"");
\r
1352 svnCmd += tempfile;
\r
1353 svnCmd += _T("\"");
\r
1354 svnCmd += _T(" /deletepathfile");
\r
1356 case ShellMenuUnIgnoreCaseSensitive:
\r
1357 tempfile = WriteFileListToTempFile();
\r
1358 svnCmd += _T("unignore /pathfile:\"");
\r
1359 svnCmd += tempfile;
\r
1360 svnCmd += _T("\"");
\r
1361 svnCmd += _T(" /deletepathfile");
\r
1362 svnCmd += _T(" /onlymask");
\r
1364 case ShellMenuRevert:
\r
1365 tempfile = WriteFileListToTempFile();
\r
1366 svnCmd += _T("revert /pathfile:\"");
\r
1367 svnCmd += tempfile;
\r
1368 svnCmd += _T("\"");
\r
1369 svnCmd += _T(" /deletepathfile");
\r
1371 case ShellMenuDelUnversioned:
\r
1372 svnCmd += _T("delunversioned /path:\"");
\r
1373 svnCmd += folder_;
\r
1374 svnCmd += _T("\"");
\r
1376 case ShellMenuCleanup:
\r
1377 tempfile = WriteFileListToTempFile();
\r
1378 svnCmd += _T("cleanup /pathfile:\"");
\r
1379 svnCmd += tempfile;
\r
1380 svnCmd += _T("\"");
\r
1381 svnCmd += _T(" /deletepathfile");
\r
1383 case ShellMenuResolve:
\r
1384 tempfile = WriteFileListToTempFile();
\r
1385 svnCmd += _T("resolve /pathfile:\"");
\r
1386 svnCmd += tempfile;
\r
1387 svnCmd += _T("\"");
\r
1388 svnCmd += _T(" /deletepathfile");
\r
1390 case ShellMenuSwitch:
\r
1391 svnCmd += _T("switch /path:\"");
\r
1392 if (files_.size() > 0)
\r
1393 svnCmd += files_.front();
\r
1395 svnCmd += folder_;
\r
1396 svnCmd += _T("\"");
\r
1398 case ShellMenuImport:
\r
1399 svnCmd += _T("import /path:\"");
\r
1400 svnCmd += folder_;
\r
1401 svnCmd += _T("\"");
\r
1403 case ShellMenuExport:
\r
1404 svnCmd += _T("export /path:\"");
\r
1405 svnCmd += folder_;
\r
1406 svnCmd += _T("\"");
\r
1408 case ShellMenuAbout:
\r
1409 svnCmd += _T("about");
\r
1411 case ShellMenuCreateRepos:
\r
1412 svnCmd += _T("repocreate /path:\"");
\r
1413 svnCmd += folder_;
\r
1414 svnCmd += _T("\"");
\r
1416 case ShellMenuMerge:
\r
1417 svnCmd += _T("merge /path:\"");
\r
1418 if (files_.size() > 0)
\r
1419 svnCmd += files_.front();
\r
1421 svnCmd += folder_;
\r
1422 svnCmd += _T("\"");
\r
1424 case ShellMenuMergeAll:
\r
1425 svnCmd += _T("mergeall /path:\"");
\r
1426 if (files_.size() > 0)
\r
1427 svnCmd += files_.front();
\r
1429 svnCmd += folder_;
\r
1430 svnCmd += _T("\"");
\r
1432 case ShellMenuCopy:
\r
1433 svnCmd += _T("copy /path:\"");
\r
1434 if (files_.size() > 0)
\r
1435 svnCmd += files_.front();
\r
1437 svnCmd += folder_;
\r
1438 svnCmd += _T("\"");
\r
1440 case ShellMenuSettings:
\r
1441 svnCmd += _T("settings");
\r
1443 case ShellMenuHelp:
\r
1444 svnCmd += _T("help");
\r
1446 case ShellMenuRename:
\r
1447 svnCmd += _T("rename /path:\"");
\r
1448 if (files_.size() > 0)
\r
1449 svnCmd += files_.front();
\r
1451 svnCmd += folder_;
\r
1452 svnCmd += _T("\"");
\r
1454 case ShellMenuRemove:
\r
1455 tempfile = WriteFileListToTempFile();
\r
1456 svnCmd += _T("remove /pathfile:\"");
\r
1457 svnCmd += tempfile;
\r
1458 svnCmd += _T("\"");
\r
1459 svnCmd += _T(" /deletepathfile");
\r
1461 case ShellMenuRemoveKeep:
\r
1462 tempfile = WriteFileListToTempFile();
\r
1463 svnCmd += _T("remove /pathfile:\"");
\r
1464 svnCmd += tempfile;
\r
1465 svnCmd += _T("\"");
\r
1466 svnCmd += _T(" /deletepathfile");
\r
1467 svnCmd += _T(" /keep");
\r
1469 case ShellMenuDiff:
\r
1470 svnCmd += _T("diff /path:\"");
\r
1471 if (files_.size() == 1)
\r
1472 svnCmd += files_.front();
\r
1473 else if (files_.size() == 2)
\r
1475 std::vector<stdstring>::iterator I = files_.begin();
\r
1478 svnCmd += _T("\" /path2:\"");
\r
1482 svnCmd += folder_;
\r
1483 svnCmd += _T("\"");
\r
1484 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1485 svnCmd += _T(" /alternative");
\r
1487 case ShellMenuPrevDiff:
\r
1488 svnCmd += _T("prevdiff /path:\"");
\r
1489 if (files_.size() == 1)
\r
1490 svnCmd += files_.front();
\r
1492 svnCmd += folder_;
\r
1493 svnCmd += _T("\"");
\r
1494 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1495 svnCmd += _T(" /alternative");
\r
1497 case ShellMenuUrlDiff:
\r
1498 svnCmd += _T("urldiff /path:\"");
\r
1499 if (files_.size() == 1)
\r
1500 svnCmd += files_.front();
\r
1502 svnCmd += folder_;
\r
1503 svnCmd += _T("\"");
\r
1505 case ShellMenuDropCopyAdd:
\r
1506 tempfile = WriteFileListToTempFile();
\r
1507 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1508 svnCmd += tempfile;
\r
1509 svnCmd += _T("\"");
\r
1510 svnCmd += _T(" /deletepathfile");
\r
1511 svnCmd += _T(" /droptarget:\"");
\r
1512 svnCmd += folder_;
\r
1513 svnCmd += _T("\"";)
\r
1515 case ShellMenuDropCopy:
\r
1516 tempfile = WriteFileListToTempFile();
\r
1517 svnCmd += _T("dropcopy /pathfile:\"");
\r
1518 svnCmd += tempfile;
\r
1519 svnCmd += _T("\"");
\r
1520 svnCmd += _T(" /deletepathfile");
\r
1521 svnCmd += _T(" /droptarget:\"");
\r
1522 svnCmd += folder_;
\r
1523 svnCmd += _T("\"";)
\r
1525 case ShellMenuDropCopyRename:
\r
1526 tempfile = WriteFileListToTempFile();
\r
1527 svnCmd += _T("dropcopy /pathfile:\"");
\r
1528 svnCmd += tempfile;
\r
1529 svnCmd += _T("\"");
\r
1530 svnCmd += _T(" /deletepathfile");
\r
1531 svnCmd += _T(" /droptarget:\"");
\r
1532 svnCmd += folder_;
\r
1533 svnCmd += _T("\" /rename";)
\r
1535 case ShellMenuDropMove:
\r
1536 tempfile = WriteFileListToTempFile();
\r
1537 svnCmd += _T("dropmove /pathfile:\"");
\r
1538 svnCmd += tempfile;
\r
1539 svnCmd += _T("\"");
\r
1540 svnCmd += _T(" /deletepathfile");
\r
1541 svnCmd += _T(" /droptarget:\"");
\r
1542 svnCmd += folder_;
\r
1543 svnCmd += _T("\"");
\r
1545 case ShellMenuDropMoveRename:
\r
1546 tempfile = WriteFileListToTempFile();
\r
1547 svnCmd += _T("dropmove /pathfile:\"");
\r
1548 svnCmd += tempfile;
\r
1549 svnCmd += _T("\"");
\r
1550 svnCmd += _T(" /deletepathfile");
\r
1551 svnCmd += _T(" /droptarget:\"");
\r
1552 svnCmd += folder_;
\r
1553 svnCmd += _T("\" /rename";)
\r
1555 case ShellMenuDropExport:
\r
1556 tempfile = WriteFileListToTempFile();
\r
1557 svnCmd += _T("dropexport /pathfile:\"");
\r
1558 svnCmd += tempfile;
\r
1559 svnCmd += _T("\"");
\r
1560 svnCmd += _T(" /deletepathfile");
\r
1561 svnCmd += _T(" /droptarget:\"");
\r
1562 svnCmd += folder_;
\r
1563 svnCmd += _T("\"");
\r
1565 case ShellMenuDropExportExtended:
\r
1566 tempfile = WriteFileListToTempFile();
\r
1567 svnCmd += _T("dropexport /pathfile:\"");
\r
1568 svnCmd += tempfile;
\r
1569 svnCmd += _T("\"");
\r
1570 svnCmd += _T(" /deletepathfile");
\r
1571 svnCmd += _T(" /droptarget:\"");
\r
1572 svnCmd += folder_;
\r
1573 svnCmd += _T("\"");
\r
1574 svnCmd += _T(" /extended");
\r
1576 case ShellMenuLog:
\r
1577 svnCmd += _T("log /path:\"");
\r
1578 if (files_.size() > 0)
\r
1579 svnCmd += files_.front();
\r
1581 svnCmd += folder_;
\r
1582 svnCmd += _T("\"");
\r
1584 case ShellMenuConflictEditor:
\r
1585 svnCmd += _T("conflicteditor /path:\"");
\r
1586 if (files_.size() > 0)
\r
1587 svnCmd += files_.front();
\r
1589 svnCmd += folder_;
\r
1590 svnCmd += _T("\"");
\r
1592 case ShellMenuRelocate:
\r
1593 svnCmd += _T("relocate /path:\"");
\r
1594 if (files_.size() > 0)
\r
1595 svnCmd += files_.front();
\r
1597 svnCmd += folder_;
\r
1598 svnCmd += _T("\"");
\r
1600 case ShellMenuShowChanged:
\r
1601 if (files_.size() > 1)
\r
1603 tempfile = WriteFileListToTempFile();
\r
1604 svnCmd += _T("repostatus /pathfile:\"");
\r
1605 svnCmd += tempfile;
\r
1606 svnCmd += _T("\"");
\r
1607 svnCmd += _T(" /deletepathfile");
\r
1611 svnCmd += _T("repostatus /path:\"");
\r
1612 if (files_.size() > 0)
\r
1613 svnCmd += files_.front();
\r
1615 svnCmd += folder_;
\r
1616 svnCmd += _T("\"");
\r
1619 case ShellMenuRepoBrowse:
\r
1620 svnCmd += _T("repobrowser /path:\"");
\r
1621 if (files_.size() > 0)
\r
1622 svnCmd += files_.front();
\r
1624 svnCmd += folder_;
\r
1625 svnCmd += _T("\"");
\r
1627 case ShellMenuBlame:
\r
1628 svnCmd += _T("blame /path:\"");
\r
1629 if (files_.size() > 0)
\r
1630 svnCmd += files_.front();
\r
1632 svnCmd += folder_;
\r
1633 svnCmd += _T("\"");
\r
1635 case ShellMenuCreatePatch:
\r
1636 tempfile = WriteFileListToTempFile();
\r
1637 svnCmd += _T("createpatch /pathfile:\"");
\r
1638 svnCmd += tempfile;
\r
1639 svnCmd += _T("\"");
\r
1640 svnCmd += _T(" /deletepathfile");
\r
1642 case ShellMenuApplyPatch:
\r
1643 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1645 // if there's a patch file in the clipboard, we save it
\r
1646 // to a temporary file and tell TortoiseMerge to use that one
\r
1647 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1648 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1650 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1651 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1653 DWORD len = GetTempPath(0, NULL);
\r
1654 TCHAR * path = new TCHAR[len+1];
\r
1655 TCHAR * tempF = new TCHAR[len+100];
\r
1656 GetTempPath (len+1, path);
\r
1657 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1658 std::wstring sTempFile = std::wstring(tempF);
\r
1663 size_t patchlen = strlen(lpstr);
\r
1664 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1667 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1668 if (size == patchlen)
\r
1670 itemStates |= ITEMIS_PATCHFILE;
\r
1672 files_.push_back(sTempFile);
\r
1676 GlobalUnlock(hglb);
\r
1677 CloseClipboard();
\r
1680 if (itemStates & ITEMIS_PATCHFILE)
\r
1682 svnCmd = _T(" /diff:\"");
\r
1683 if (files_.size() > 0)
\r
1685 svnCmd += files_.front();
\r
1686 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1688 svnCmd += _T("\" /patchpath:\"");
\r
1689 svnCmd += folder_;
\r
1693 svnCmd += folder_;
\r
1694 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1695 svnCmd += _T("\" /wc");
\r
1697 svnCmd += _T("\"");
\r
1701 svnCmd = _T(" /patchpath:\"");
\r
1702 if (files_.size() > 0)
\r
1703 svnCmd += files_.front();
\r
1705 svnCmd += folder_;
\r
1706 svnCmd += _T("\"");
\r
1709 myVerbsIDMap.clear();
\r
1710 myVerbsMap.clear();
\r
1711 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1714 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1715 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1716 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1719 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1720 (LPTSTR) &lpMsgBuf,
\r
1724 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1725 LocalFree( lpMsgBuf );
\r
1727 CloseHandle(process.hThread);
\r
1728 CloseHandle(process.hProcess);
\r
1731 case ShellMenuRevisionGraph:
\r
1732 svnCmd += _T("revisiongraph /path:\"");
\r
1733 if (files_.size() > 0)
\r
1734 svnCmd += files_.front();
\r
1736 svnCmd += folder_;
\r
1737 svnCmd += _T("\"");
\r
1739 case ShellMenuLock:
\r
1740 tempfile = WriteFileListToTempFile();
\r
1741 svnCmd += _T("lock /pathfile:\"");
\r
1742 svnCmd += tempfile;
\r
1743 svnCmd += _T("\"");
\r
1744 svnCmd += _T(" /deletepathfile");
\r
1746 case ShellMenuUnlock:
\r
1747 tempfile = WriteFileListToTempFile();
\r
1748 svnCmd += _T("unlock /pathfile:\"");
\r
1749 svnCmd += tempfile;
\r
1750 svnCmd += _T("\"");
\r
1751 svnCmd += _T(" /deletepathfile");
\r
1753 case ShellMenuUnlockForce:
\r
1754 tempfile = WriteFileListToTempFile();
\r
1755 svnCmd += _T("unlock /pathfile:\"");
\r
1756 svnCmd += tempfile;
\r
1757 svnCmd += _T("\"");
\r
1758 svnCmd += _T(" /deletepathfile");
\r
1759 svnCmd += _T(" /force");
\r
1761 case ShellMenuProperties:
\r
1762 tempfile = WriteFileListToTempFile();
\r
1763 svnCmd += _T("properties /pathfile:\"");
\r
1764 svnCmd += tempfile;
\r
1765 svnCmd += _T("\"");
\r
1766 svnCmd += _T(" /deletepathfile");
\r
1768 case ShellMenuClipPaste:
\r
1769 if (WriteClipboardPathsToTempFile(tempfile))
\r
1771 bool bCopy = true;
\r
1772 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1773 if (cPrefDropFormat)
\r
1775 if (OpenClipboard(lpcmi->hwnd))
\r
1777 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1780 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1781 if (*effect == DROPEFFECT_MOVE)
\r
1783 GlobalUnlock(hglb);
\r
1790 svnCmd += _T("pastecopy /pathfile:\"");
\r
1792 svnCmd += _T("pastemove /pathfile:\"");
\r
1793 svnCmd += tempfile;
\r
1794 svnCmd += _T("\"");
\r
1795 svnCmd += _T(" /deletepathfile");
\r
1796 svnCmd += _T(" /droptarget:\"");
\r
1797 svnCmd += folder_;
\r
1798 svnCmd += _T("\"");
\r
1800 else return NOERROR;
\r
1802 case ShellMenuClone:
\r
1803 svnCmd += _T("clone /path:\"");
\r
1804 svnCmd += folder_;
\r
1805 svnCmd += _T("\"");
\r
1807 case ShellMenuPull:
\r
1808 svnCmd += _T("pull /path:\"");
\r
1809 if (files_.size() > 0)
\r
1810 svnCmd += files_.front();
\r
1812 svnCmd += folder_;
\r
1813 svnCmd += _T("\"");
\r
1815 case ShellMenuPush:
\r
1816 svnCmd += _T("push /path:\"");
\r
1817 if (files_.size() > 0)
\r
1818 svnCmd += files_.front();
\r
1820 svnCmd += folder_;
\r
1821 svnCmd += _T("\"");
\r
1823 case ShellMenuBranch:
\r
1824 svnCmd += _T("branch /path:\"");
\r
1825 if (files_.size() > 0)
\r
1826 svnCmd += files_.front();
\r
1828 svnCmd += folder_;
\r
1829 svnCmd += _T("\"");
\r
1832 case ShellMenuTag:
\r
1833 svnCmd += _T("tag /path:\"");
\r
1834 if (files_.size() > 0)
\r
1835 svnCmd += files_.front();
\r
1837 svnCmd += folder_;
\r
1838 svnCmd += _T("\"");
\r
1841 case ShellMenuFormatPatch:
\r
1842 svnCmd += _T("formatpatch /path:\"");
\r
1843 if (files_.size() > 0)
\r
1844 svnCmd += files_.front();
\r
1846 svnCmd += folder_;
\r
1847 svnCmd += _T("\"");
\r
1850 case ShellMenuImportPatch:
\r
1851 svnCmd += _T("importpatch /path:\"");
\r
1852 if (files_.size() > 0)
\r
1853 svnCmd += files_.front();
\r
1855 svnCmd += folder_;
\r
1856 svnCmd += _T("\"");
\r
1859 case ShellMenuCherryPick:
\r
1860 svnCmd += _T("cherrypick /path:\"");
\r
1861 if (files_.size() > 0)
\r
1862 svnCmd += files_.front();
\r
1864 svnCmd += folder_;
\r
1865 svnCmd += _T("\"");
\r
1867 case ShellMenuFetch:
\r
1868 svnCmd += _T("fetch /path:\"");
\r
1869 if (files_.size() > 0)
\r
1870 svnCmd += files_.front();
\r
1872 svnCmd += folder_;
\r
1873 svnCmd += _T("\"");
\r
1879 } // switch (id_it->second)
\r
1880 svnCmd += _T(" /hwnd:");
\r
1882 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1885 myVerbsIDMap.clear();
\r
1886 myVerbsMap.clear();
\r
1887 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1890 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1891 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1892 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1895 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1896 (LPTSTR) &lpMsgBuf,
\r
1900 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1901 LocalFree( lpMsgBuf );
\r
1903 CloseHandle(process.hThread);
\r
1904 CloseHandle(process.hProcess);
\r
1906 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1907 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1912 // This is for the status bar and things like that:
\r
1913 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1915 UINT FAR * /*reserved*/,
\r
1919 PreserveChdir preserveChdir;
\r
1920 //do we know the id?
\r
1921 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1922 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1924 return E_INVALIDARG; //no, we don't
\r
1928 HRESULT hr = E_INVALIDARG;
\r
1930 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1931 int menuIndex = 0;
\r
1932 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1934 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1936 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1942 const TCHAR * desc = stringtablebuffer;
\r
1945 case GCS_HELPTEXTA:
\r
1947 std::string help = WideToMultibyte(desc);
\r
1948 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1952 case GCS_HELPTEXTW:
\r
1954 wide_string help = desc;
\r
1955 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1961 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1962 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1964 std::string help = WideToMultibyte(verb_id_it->second);
\r
1965 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1972 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1973 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1975 wide_string help = verb_id_it->second;
\r
1976 ATLTRACE("verb : %ws\n", help.c_str());
\r
1977 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1986 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1989 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
1992 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
1994 PreserveChdir preserveChdir;
\r
1997 if (pResult == NULL)
\r
2004 case WM_MEASUREITEM:
\r
2006 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2009 lpmis->itemWidth += 2;
\r
2010 if (lpmis->itemHeight < 16)
\r
2011 lpmis->itemHeight = 16;
\r
2018 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2019 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2020 return S_OK; //not for a menu
\r
2021 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2022 if (resource == NULL)
\r
2024 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2025 if (hIcon == NULL)
\r
2027 DrawIconEx(lpdis->hDC,
\r
2028 lpdis->rcItem.left - 16,
\r
2029 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2031 0, NULL, DI_NORMAL);
\r
2032 DestroyIcon(hIcon);
\r
2040 if (HIWORD(wParam) != MF_POPUP)
\r
2042 int nChar = LOWORD(wParam);
\r
2043 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2044 nChar = tolower(nChar);
\r
2045 // we have the char the user pressed, now search that char in all our
\r
2047 std::vector<int> accmenus;
\r
2048 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2050 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2051 if (resource == NULL)
\r
2053 szItem = stringtablebuffer;
\r
2054 TCHAR * amp = _tcschr(szItem, '&');
\r
2058 int ampChar = LOWORD(*amp);
\r
2059 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2060 ampChar = tolower(ampChar);
\r
2061 if (ampChar == nChar)
\r
2063 // yep, we found a menu which has the pressed key
\r
2064 // as an accelerator. Add that menu to the list to
\r
2066 accmenus.push_back(It->first);
\r
2069 if (accmenus.size() == 0)
\r
2071 // no menu with that accelerator key.
\r
2072 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2075 if (accmenus.size() == 1)
\r
2077 // Only one menu with that accelerator key. We're lucky!
\r
2078 // So just execute that menu entry.
\r
2079 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2082 if (accmenus.size() > 1)
\r
2084 // we have more than one menu item with this accelerator key!
\r
2086 mif.cbSize = sizeof(MENUITEMINFO);
\r
2087 mif.fMask = MIIM_STATE;
\r
2088 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2090 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2091 if (mif.fState == MFS_HILITE)
\r
2093 // this is the selected item, so select the next one
\r
2095 if (it == accmenus.end())
\r
2096 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2098 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2102 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2113 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2115 TCHAR textbuf[255];
\r
2116 LPCTSTR resource = NULL;
\r
2117 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2120 int menuIndex = 0;
\r
2121 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2123 if (menuInfo[menuIndex].command == id)
\r
2125 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2126 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2129 case ShellMenuLock:
\r
2130 // menu lock is special because it can be set to the top
\r
2131 // with a separate option in the registry
\r
2132 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2133 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2135 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2136 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2137 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2140 // the sub menu entries are special because they're *always* on the top level menu
\r
2141 case ShellSubMenuMultiple:
\r
2142 case ShellSubMenuLink:
\r
2143 case ShellSubMenuFolder:
\r
2144 case ShellSubMenuFile:
\r
2145 case ShellSubMenu:
\r
2149 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2150 if (layout & (menuInfo[menuIndex].menuID))
\r
2152 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2153 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2154 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2165 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2168 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2169 LPITEMIDLIST pidl = NULL;
\r
2170 while (cslidarray[i])
\r
2174 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2176 if (!SHGetPathFromIDList(pidl, buf))
\r
2178 // not a file system path, definitely illegal for our use
\r
2179 CoTaskMemFree(pidl);
\r
2182 CoTaskMemFree(pidl);
\r
2183 if (_tcslen(buf)==0)
\r
2185 if (_tcscmp(buf, folder.c_str())==0)
\r
2191 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2193 HMENU ignoresubmenu = NULL;
\r
2194 int indexignoresub = 0;
\r
2195 bool bShowIgnoreMenu = false;
\r
2196 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2197 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2198 if (files_.size() == 0)
\r
2200 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2202 std::vector<stdstring>::iterator I = files_.begin();
\r
2203 if (_tcsrchr(I->c_str(), '\\'))
\r
2204 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2206 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2207 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2209 // check if the item name is ignored or the mask
\r
2211 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2213 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2214 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2222 ignoresubmenu = CreateMenu();
\r
2223 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2224 stdstring verb = stdstring(ignorepath);
\r
2225 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2226 myVerbsMap[verb] = idCmd;
\r
2227 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2228 myVerbsIDMap[idCmd] = verb;
\r
2229 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2230 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2231 bShowIgnoreMenu = true;
\r
2233 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2234 if (_tcsrchr(ignorepath, '.'))
\r
2236 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2237 p = ignoredprops.find(maskbuf);
\r
2239 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2241 if (ignoresubmenu==NULL)
\r
2242 ignoresubmenu = CreateMenu();
\r
2244 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2245 stdstring verb = stdstring(maskbuf);
\r
2246 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2247 myVerbsMap[verb] = idCmd;
\r
2248 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2249 myVerbsIDMap[idCmd] = verb;
\r
2250 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2251 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2252 bShowIgnoreMenu = true;
\r
2256 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2258 bShowIgnoreMenu = true;
\r
2259 ignoresubmenu = CreateMenu();
\r
2260 if (itemStates & ITEMIS_ONLYONE)
\r
2262 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2263 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2264 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2266 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2267 if (_tcsrchr(ignorepath, '.'))
\r
2269 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2270 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2271 stdstring verb = stdstring(maskbuf);
\r
2272 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2273 myVerbsMap[verb] = idCmd;
\r
2274 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2275 myVerbsIDMap[idCmd] = verb;
\r
2276 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2277 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2282 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2283 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2284 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2285 stdstring verb = stdstring(ignorepath);
\r
2286 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2287 myVerbsMap[verb] = idCmd;
\r
2288 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2289 myVerbsIDMap[idCmd] = verb;
\r
2290 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2291 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2293 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2294 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2295 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2296 verb = stdstring(ignorepath);
\r
2297 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2298 myVerbsMap[verb] = idCmd;
\r
2299 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2300 myVerbsIDMap[idCmd] = verb;
\r
2301 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2302 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2306 if (bShowIgnoreMenu)
\r
2308 MENUITEMINFO menuiteminfo;
\r
2309 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2310 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2311 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2312 menuiteminfo.fType = MFT_STRING;
\r
2313 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2315 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2316 menuiteminfo.hbmpChecked = bmp;
\r
2317 menuiteminfo.hbmpUnchecked = bmp;
\r
2318 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2319 menuiteminfo.wID = idCmd;
\r
2320 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2321 if (itemStates & ITEMIS_IGNORED)
\r
2322 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2324 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2325 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2326 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2328 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2329 if (itemStates & ITEMIS_IGNORED)
\r
2331 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2332 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2336 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2337 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2342 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2344 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2345 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2346 return bitmap_it->second;
\r
2348 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2352 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2356 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2357 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2360 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2361 HBITMAP hBmp = NULL;
\r
2363 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2366 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2368 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2371 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2372 BP_PAINTPARAMS paintParams = {0};
\r
2373 paintParams.cbSize = sizeof(paintParams);
\r
2374 paintParams.dwFlags = BPPF_ERASE;
\r
2375 paintParams.pBlendFunction = &bfAlpha;
\r
2378 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2381 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2383 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2384 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2387 // This will write the buffer contents to the destination bitmap
\r
2388 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2391 SelectObject(hdcDest, hbmpOld);
\r
2395 DeleteDC(hdcDest);
\r
2398 DestroyIcon(hIcon);
\r
2401 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2405 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2410 ZeroMemory(&bmi, sizeof(bmi));
\r
2411 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2412 bmi.bmiHeader.biPlanes = 1;
\r
2413 bmi.bmiHeader.biCompression = BI_RGB;
\r
2415 bmi.bmiHeader.biWidth = psize->cx;
\r
2416 bmi.bmiHeader.biHeight = psize->cy;
\r
2417 bmi.bmiHeader.biBitCount = 32;
\r
2419 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2422 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2423 if (hdc != hdcUsed)
\r
2425 ReleaseDC(NULL, hdcUsed);
\r
2428 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2431 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2433 RGBQUAD *prgbQuad;
\r
2435 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2436 if (SUCCEEDED(hr))
\r
2438 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2439 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2442 if (GetIconInfo(hicon, &info))
\r
2446 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2449 DeleteObject(info.hbmColor);
\r
2450 DeleteObject(info.hbmMask);
\r
2458 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2460 ULONG cxDelta = cxRow - sizImage.cx;
\r
2461 for (ULONG y = sizImage.cy; y; --y)
\r
2463 for (ULONG x = sizImage.cx; x; --x)
\r
2465 if (*pargb++ & 0xFF000000)
\r
2477 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2480 ZeroMemory(&bmi, sizeof(bmi));
\r
2481 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2482 bmi.bmiHeader.biPlanes = 1;
\r
2483 bmi.bmiHeader.biCompression = BI_RGB;
\r
2485 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2486 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2487 bmi.bmiHeader.biBitCount = 32;
\r
2489 HRESULT hr = E_OUTOFMEMORY;
\r
2490 HANDLE hHeap = GetProcessHeap();
\r
2491 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2494 hr = E_UNEXPECTED;
\r
2495 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2497 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2498 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2500 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2502 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2506 // transparent pixel
\r
2512 *pargb++ |= 0xFF000000;
\r
2522 HeapFree(hHeap, 0, pvBits);
\r