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::GetAllStatus()\n"));
\r
338 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
339 itemStates |= ITEMIS_INSVN;
\r
340 if (status == git_wc_status_ignored)
\r
341 itemStates |= ITEMIS_IGNORED;
\r
342 if (status == git_wc_status_normal)
\r
343 itemStates |= ITEMIS_NORMAL;
\r
344 if (status == git_wc_status_conflicted)
\r
345 itemStates |= ITEMIS_CONFLICTED;
\r
346 if (status == git_wc_status_added)
\r
347 itemStates |= ITEMIS_ADDED;
\r
348 if (status == git_wc_status_deleted)
\r
349 itemStates |= ITEMIS_DELETED;
\r
352 } // for (int i = 0; i < count; i++)
\r
353 GlobalUnlock ( drop );
\r
354 ReleaseStgMedium ( &stg );
\r
356 } // if (m_State == FileStateDropHandler)
\r
360 //Enumerate PIDLs which the user has selected
\r
361 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
362 ItemIDList parent( GetPIDLFolder (cida));
\r
364 int count = cida->cidl;
\r
365 BOOL statfetched = FALSE;
\r
366 for (int i = 0; i < count; ++i)
\r
368 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
369 stdstring str = child.toString();
\r
370 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
372 //check if our menu is requested for a subversion admin directory
\r
373 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
376 files_.push_back(str);
\r
378 strpath.SetFromWin(str.c_str());
\r
379 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
380 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
383 //get the Subversion status of the item
\r
384 git_wc_status_kind status = git_wc_status_none;
\r
385 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
387 if (strpath.HasAdminDir())
\r
388 status = git_wc_status_normal;
\r
395 if (strpath.HasAdminDir())
\r
396 stat.GetStatus(strpath, false, true, true);
\r
400 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
401 fetchedstatus = status;
\r
402 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
403 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
404 //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
406 // itemStates |= ITEMIS_FOLDER;
\r
407 // if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
408 // itemStates |= ITEMIS_FOLDERINGit;
\r
410 //if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
411 // itemStates |= ITEMIS_CONFLICTED;
\r
412 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
414 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
415 // itemStates |= ITEMIS_NEEDSLOCK;
\r
417 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
418 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
422 // sometimes, git_client_status() returns with an error.
\r
423 // in that case, we have to check if the working copy is versioned
\r
424 // anyway to show the 'correct' context menu
\r
425 if (strpath.HasAdminDir())
\r
427 status = git_wc_status_normal;
\r
428 fetchedstatus = status;
\r
431 statfetched = TRUE;
\r
435 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
438 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
439 itemStates |= ITEMIS_INSVN;
\r
440 if (status == git_wc_status_ignored)
\r
442 itemStates |= ITEMIS_IGNORED;
\r
443 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
444 // offer a 'remove from ignored list' entry
\r
445 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
446 // ignoredprops.empty();
\r
447 // for (int p=0; p<props.GetCount(); ++p)
\r
449 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
451 // std::string st = props.GetItemValue(p);
\r
452 // ignoredprops = MultibyteToWide(st.c_str());
\r
453 // // remove all escape chars ('\\')
\r
454 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
459 if (status == git_wc_status_normal)
\r
460 itemStates |= ITEMIS_NORMAL;
\r
461 if (status == git_wc_status_conflicted)
\r
462 itemStates |= ITEMIS_CONFLICTED;
\r
463 if (status == git_wc_status_added)
\r
464 itemStates |= ITEMIS_ADDED;
\r
465 if (status == git_wc_status_deleted)
\r
466 itemStates |= ITEMIS_DELETED;
\r
469 } // for (int i = 0; i < count; ++i)
\r
470 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
471 // if (g_ShellCache.HasGitAdminDir(child.toString().c_str(), FALSE))
\r
472 // itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
473 GlobalUnlock(medium.hGlobal);
\r
475 // if the item is a versioned folder, check if there's a patch file
\r
476 // in the clipboard to be used in "Apply Patch"
\r
477 UINT cFormatDiff = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
480 if (IsClipboardFormatAvailable(cFormatDiff))
\r
481 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
483 if (IsClipboardFormatAvailable(CF_HDROP))
\r
484 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
488 ReleaseStgMedium ( &medium );
\r
489 if (medium.pUnkForRelease)
\r
491 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
492 relInterface->Release();
\r
497 // get folder background
\r
501 ItemIDList list(pIDFolder);
\r
502 folder_ = list.toString();
\r
503 git_wc_status_kind status = git_wc_status_none;
\r
504 if (IsClipboardFormatAvailable(CF_HDROP))
\r
505 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
506 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
508 CTGitPath askedpath;
\r
509 askedpath.SetFromWin(folder_.c_str());
\r
513 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
516 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
517 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
518 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
519 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
521 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
522 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
524 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
525 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
526 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
527 itemStatesFolder |= ITEMIS_INSVN;
\r
528 if (status == git_wc_status_normal)
\r
529 itemStatesFolder |= ITEMIS_NORMAL;
\r
530 if (status == git_wc_status_conflicted)
\r
531 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
532 if (status == git_wc_status_added)
\r
533 itemStatesFolder |= ITEMIS_ADDED;
\r
534 if (status == git_wc_status_deleted)
\r
535 itemStatesFolder |= ITEMIS_DELETED;
\r
539 // sometimes, git_client_status() returns with an error.
\r
540 // in that case, we have to check if the working copy is versioned
\r
541 // anyway to show the 'correct' context menu
\r
542 if (askedpath.HasAdminDir())
\r
543 status = git_wc_status_normal;
\r
548 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
553 status = fetchedstatus;
\r
555 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
557 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
559 if (status == git_wc_status_ignored)
\r
560 itemStatesFolder |= ITEMIS_IGNORED;
\r
561 itemStatesFolder |= ITEMIS_FOLDER;
\r
562 if (files_.size() == 0)
\r
563 itemStates |= ITEMIS_ONLYONE;
\r
564 if (m_State != FileStateDropHandler)
\r
565 itemStates |= itemStatesFolder;
\r
568 if (files_.size() == 2)
\r
569 itemStates |= ITEMIS_TWO;
\r
570 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
573 itemStates |= ITEMIS_ONLYONE;
\r
574 if (m_State != FileStateDropHandler)
\r
576 if (PathIsDirectory(files_.front().c_str()))
\r
578 folder_ = files_.front();
\r
579 git_wc_status_kind status = git_wc_status_none;
\r
580 if (folder_.compare(statuspath)!=0)
\r
582 CTGitPath askedpath;
\r
583 askedpath.SetFromWin(folder_.c_str());
\r
587 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
590 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
591 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
592 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
593 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
595 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
596 // itemStates |= ITEMIS_NEEDSLOCK;
\r
598 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
599 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
604 ATLTRACE2(_T("Exception in GitStatus::GetAllStatus()\n"));
\r
609 status = fetchedstatus;
\r
611 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
612 itemStates |= ITEMIS_FOLDERINSVN;
\r
613 if (status == git_wc_status_ignored)
\r
614 itemStates |= ITEMIS_IGNORED;
\r
615 itemStates |= ITEMIS_FOLDER;
\r
616 if (status == git_wc_status_added)
\r
617 itemStates |= ITEMIS_ADDED;
\r
618 if (status == git_wc_status_deleted)
\r
619 itemStates |= ITEMIS_DELETED;
\r
628 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
630 TCHAR menutextbuffer[255] = {0};
\r
631 TCHAR verbsbuffer[255] = {0};
\r
632 MAKESTRING(stringid);
\r
636 //menu entry for the top context menu, so append an "Git " before
\r
637 //the menu text to indicate where the entry comes from
\r
638 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
640 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
641 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
643 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
644 if (fullver >= 0x500)
\r
646 // on win2k, the context menu does not work properly if we use
\r
647 // icon bitmaps. At least the menu text is empty in the context menu
\r
648 // for folder backgrounds (seems like a win2k bug).
\r
649 HBITMAP bmp = IconToBitmap(icon);
\r
650 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
655 MENUITEMINFO menuiteminfo = {0};
\r
656 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
657 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
658 menuiteminfo.fType = MFT_STRING;
\r
659 menuiteminfo.dwTypeData = menutextbuffer;
\r
661 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
662 menuiteminfo.wID = id;
\r
663 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
668 //menu entry for the top context menu, so append an "Git " before
\r
669 //the menu text to indicate where the entry comes from
\r
670 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
672 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
673 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
674 stdstring verb = stdstring(menutextbuffer);
\r
675 if (verb.find('&') != -1)
\r
677 verb.erase(verb.find('&'),1);
\r
679 myVerbsMap[verb] = id - idCmdFirst;
\r
680 myVerbsMap[verb] = id;
\r
681 myVerbsIDMap[id - idCmdFirst] = verb;
\r
682 myVerbsIDMap[id] = verb;
\r
683 // We store the relative and absolute diameter
\r
684 // (drawitem callback uses absolute, others relative)
\r
685 myIDMap[id - idCmdFirst] = com;
\r
688 mySubMenuMap[pos] = com;
\r
691 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
693 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
694 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
695 return bitmap_it->second;
\r
697 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
703 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
704 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
706 rect.left = rect.top = 0;
\r
708 HWND desktop = ::GetDesktopWindow();
\r
709 if (desktop == NULL)
\r
711 DestroyIcon(hIcon);
\r
715 HDC screen_dev = ::GetDC(desktop);
\r
716 if (screen_dev == NULL)
\r
718 DestroyIcon(hIcon);
\r
722 // Create a compatible DC
\r
723 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
724 if (dst_hdc == NULL)
\r
726 DestroyIcon(hIcon);
\r
727 ::ReleaseDC(desktop, screen_dev);
\r
731 // Create a new bitmap of icon size
\r
732 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
735 DestroyIcon(hIcon);
\r
736 ::DeleteDC(dst_hdc);
\r
737 ::ReleaseDC(desktop, screen_dev);
\r
741 // Select it into the compatible DC
\r
742 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
743 if (old_dst_bmp == NULL)
\r
745 DestroyIcon(hIcon);
\r
749 // Fill the background of the compatible DC with the white color
\r
750 // that is taken by menu routines as transparent
\r
751 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
752 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
754 // Draw the icon into the compatible DC
\r
755 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
757 // Restore settings
\r
758 ::SelectObject(dst_hdc, old_dst_bmp);
\r
759 ::DeleteDC(dst_hdc);
\r
760 ::ReleaseDC(desktop, screen_dev);
\r
761 DestroyIcon(hIcon);
\r
763 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
767 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
770 tempfile = stdstring();
\r
771 //write all selected files and paths to a temporary file
\r
772 //for TortoiseProc.exe to read out again.
\r
774 DWORD pathlength = GetTempPath(0, NULL);
\r
775 TCHAR * path = new TCHAR[pathlength+1];
\r
776 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
777 GetTempPath (pathlength+1, path);
\r
778 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
779 tempfile = stdstring(tempFile);
\r
781 HANDLE file = ::CreateFile (tempFile,
\r
786 FILE_ATTRIBUTE_TEMPORARY,
\r
790 delete [] tempFile;
\r
791 if (file == INVALID_HANDLE_VALUE)
\r
794 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
796 if (!OpenClipboard(NULL))
\r
799 stdstring sClipboardText;
\r
800 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
801 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
804 TCHAR szFileName[MAX_PATH];
\r
805 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
806 for(UINT i = 0; i < cFiles; ++i)
\r
808 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
809 stdstring filename = szFileName;
\r
810 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
811 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
813 GlobalUnlock(hDrop);
\r
816 GlobalUnlock(hglb);
\r
819 ::CloseHandle(file);
\r
824 stdstring CShellExt::WriteFileListToTempFile()
\r
826 //write all selected files and paths to a temporary file
\r
827 //for TortoiseProc.exe to read out again.
\r
828 DWORD pathlength = GetTempPath(0, NULL);
\r
829 TCHAR * path = new TCHAR[pathlength+1];
\r
830 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
831 GetTempPath (pathlength+1, path);
\r
832 GetTempFileName (path, _T("svn"), 0, tempFile);
\r
833 stdstring retFilePath = stdstring(tempFile);
\r
835 HANDLE file = ::CreateFile (tempFile,
\r
840 FILE_ATTRIBUTE_TEMPORARY,
\r
844 delete [] tempFile;
\r
845 if (file == INVALID_HANDLE_VALUE)
\r
846 return stdstring();
\r
849 if (files_.empty())
\r
851 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
852 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
855 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
857 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
858 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
860 ::CloseHandle(file);
\r
861 return retFilePath;
\r
864 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
866 PreserveChdir preserveChdir;
\r
869 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
870 return NOERROR; //we don't change the default action
\r
872 if ((files_.size() == 0)||(folder_.size() == 0))
\r
875 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
878 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
880 //the drop handler only has eight commands, but not all are visible at the same time:
\r
881 //if the source file(s) are under version control then those files can be moved
\r
882 //to the new location or they can be moved with a rename,
\r
883 //if they are unversioned then they can be added to the working copy
\r
884 //if they are versioned, they also can be exported to an unversioned location
\r
885 UINT idCmd = idCmdFirst;
\r
888 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
889 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
890 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
892 // Git move and rename here
\r
893 // 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
894 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
895 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
898 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
899 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
900 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
902 // Git copy and rename here, source and target from same repository
\r
903 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
904 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
905 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
908 // available if target is versioned and source is either unversioned or from another repository
\r
909 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
910 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
913 // available if source is versioned and a folder
\r
914 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
915 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
917 // Git export all here
\r
918 // available if source is versioned and a folder
\r
919 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
920 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
923 // available if source is a patchfile
\r
924 if (itemStates & ITEMIS_PATCHFILE)
\r
925 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
928 if (idCmd != idCmdFirst)
\r
929 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
931 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
934 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
937 UINT /*idCmdLast*/,
\r
940 ATLTRACE("Shell :: QueryContextMenu\n");
\r
941 PreserveChdir preserveChdir;
\r
943 //first check if our drop handler is called
\r
944 //and then (if true) provide the context menu for the
\r
946 if (m_State == FileStateDropHandler)
\r
948 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
951 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
952 return NOERROR; //we don't change the default action
\r
954 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
957 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
960 int csidlarray[] =
\r
964 CSIDL_COMMON_FAVORITES,
\r
965 CSIDL_COMMON_STARTMENU,
\r
966 CSIDL_COMPUTERSNEARME,
\r
974 CSIDL_INTERNET_CACHE,
\r
984 if (IsIllegalFolder(folder_, csidlarray))
\r
987 if (folder_.empty())
\r
989 // folder is empty, but maybe files are selected
\r
990 if (files_.size() == 0)
\r
991 return NOERROR; // nothing selected - we don't have a menu to show
\r
992 // check whether a selected entry is an UID - those are namespace extensions
\r
993 // which we can't handle
\r
994 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
996 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1001 //check if our menu is requested for a subversion admin directory
\r
1002 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1005 if (uFlags & CMF_EXTENDEDVERBS)
\r
1006 itemStates |= ITEMIS_EXTENDED;
\r
1008 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1009 if ( bShortcut && (files_.size()==1))
\r
1011 // Don't show the context menu for a link if the
\r
1012 // destination is not part of a working copy.
\r
1013 // It would only show the standard menu items
\r
1014 // which are already shown for the lnk-file.
\r
1015 CString path = files_.front().c_str();
\r
1016 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1022 //check if we already added our menu entry for a folder.
\r
1023 //we check that by iterating through all menu entries and check if
\r
1024 //the dwItemData member points to our global ID string. That string is set
\r
1025 //by our shell extension when the folder menu is inserted.
\r
1026 TCHAR menubuf[MAX_PATH];
\r
1027 int count = GetMenuItemCount(hMenu);
\r
1028 for (int i=0; i<count; ++i)
\r
1030 MENUITEMINFO miif;
\r
1031 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1032 miif.cbSize = sizeof(MENUITEMINFO);
\r
1033 miif.fMask = MIIM_DATA;
\r
1034 miif.dwTypeData = menubuf;
\r
1035 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1036 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1037 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1042 UINT idCmd = idCmdFirst;
\r
1044 //create the sub menu
\r
1045 HMENU subMenu = CreateMenu();
\r
1046 int indexSubMenu = 0;
\r
1048 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1049 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1051 int menuIndex = 0;
\r
1052 bool bAddSeparator = false;
\r
1053 bool bMenuEntryAdded = false;
\r
1054 // insert separator at start
\r
1055 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1056 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1057 if (fullver <= 0x0500)
\r
1058 bShowIcons = false;
\r
1059 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1061 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1063 // we don't add a separator immediately. Because there might not be
\r
1064 // another 'normal' menu entry after we insert a separator.
\r
1065 // we simply set a flag here, indicating that before the next
\r
1066 // 'normal' menu entry, a separator should be added.
\r
1067 bAddSeparator = true;
\r
1071 // check the conditions whether to show the menu entry or not
\r
1072 bool bInsertMenu = false;
\r
1074 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1076 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1078 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1079 bInsertMenu = true;
\r
1081 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1082 bInsertMenu = true;
\r
1083 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1084 bInsertMenu = true;
\r
1086 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1088 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1090 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1091 bInsertMenu = true;
\r
1093 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1094 bInsertMenu = true;
\r
1095 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1096 bInsertMenu = true;
\r
1098 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1100 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1102 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1103 bInsertMenu = true;
\r
1105 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1106 bInsertMenu = true;
\r
1107 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1108 bInsertMenu = true;
\r
1110 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1112 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1114 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1115 bInsertMenu = true;
\r
1117 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1118 bInsertMenu = true;
\r
1119 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1120 bInsertMenu = true;
\r
1122 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1126 // insert a separator
\r
1127 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1129 bAddSeparator = false;
\r
1130 bMenuEntryAdded = false;
\r
1131 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1135 // handle special cases (sub menus)
\r
1136 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1138 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1139 bMenuEntryAdded = true;
\r
1143 // the 'get lock' command is special
\r
1144 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1145 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1147 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1150 // insert the menu entry
\r
1151 InsertGitMenu( bIsTop,
\r
1152 bIsTop ? hMenu : subMenu,
\r
1153 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1155 menuInfo[menuIndex].menuTextID,
\r
1156 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1158 menuInfo[menuIndex].command,
\r
1161 bMenuEntryAdded = true;
\r
1169 //add sub menu to main context menu
\r
1170 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1171 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1172 MAKESTRING(IDS_MENUSUBMENU);
\r
1173 MENUITEMINFO menuiteminfo;
\r
1174 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1175 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1176 menuiteminfo.fType = MFT_STRING;
\r
1177 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1179 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1180 if (folder_.size())
\r
1182 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1183 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1184 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1185 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1187 else if (!bShortcut && (files_.size()==1))
\r
1189 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1190 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1191 myIDMap[idCmd] = ShellSubMenuFile;
\r
1193 else if (bShortcut && (files_.size()==1))
\r
1195 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1196 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1197 myIDMap[idCmd] = ShellSubMenuLink;
\r
1199 else if (files_.size() > 1)
\r
1201 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1202 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1203 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1207 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1208 myIDMap[idCmd] = ShellSubMenu;
\r
1210 HBITMAP bmp = NULL;
\r
1211 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1213 bmp = IconToBitmap(uIcon);
\r
1214 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1218 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1220 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1222 menuiteminfo.hbmpChecked = bmp;
\r
1223 menuiteminfo.hbmpUnchecked = bmp;
\r
1224 menuiteminfo.hSubMenu = subMenu;
\r
1225 menuiteminfo.wID = idCmd++;
\r
1226 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1229 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1231 //return number of menu items added
\r
1232 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1236 // This is called when you invoke a command on the menu:
\r
1237 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1239 PreserveChdir preserveChdir;
\r
1240 HRESULT hr = E_INVALIDARG;
\r
1241 if (lpcmi == NULL)
\r
1244 std::string command;
\r
1245 std::string parent;
\r
1248 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1250 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1252 if (HIWORD(lpcmi->lpVerb))
\r
1254 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1255 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1256 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1257 idCmd = verb_it->second;
\r
1262 // See if we have a handler interface for this id
\r
1263 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1264 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1266 STARTUPINFO startup;
\r
1267 PROCESS_INFORMATION process;
\r
1268 memset(&startup, 0, sizeof(startup));
\r
1269 startup.cb = sizeof(startup);
\r
1270 memset(&process, 0, sizeof(process));
\r
1271 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1272 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1274 //TortoiseProc expects a command line of the form:
\r
1275 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1277 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1279 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1280 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1281 stdstring svnCmd = _T(" /command:");
\r
1282 stdstring tempfile;
\r
1283 switch (id_it->second)
\r
1286 case ShellMenuCheckout:
\r
1287 svnCmd += _T("checkout /path:\"");
\r
1288 svnCmd += folder_;
\r
1289 svnCmd += _T("\"");
\r
1291 case ShellMenuUpdate:
\r
1292 tempfile = WriteFileListToTempFile();
\r
1293 svnCmd += _T("update /pathfile:\"");
\r
1294 svnCmd += tempfile;
\r
1295 svnCmd += _T("\"");
\r
1296 svnCmd += _T(" /deletepathfile");
\r
1298 case ShellMenuUpdateExt:
\r
1299 tempfile = WriteFileListToTempFile();
\r
1300 svnCmd += _T("update /pathfile:\"");
\r
1301 svnCmd += tempfile;
\r
1302 svnCmd += _T("\"");
\r
1303 svnCmd += _T(" /deletepathfile");
\r
1304 svnCmd += _T(" /rev");
\r
1306 case ShellMenuCommit:
\r
1307 tempfile = WriteFileListToTempFile();
\r
1308 svnCmd += _T("commit /pathfile:\"");
\r
1309 svnCmd += tempfile;
\r
1310 svnCmd += _T("\"");
\r
1311 svnCmd += _T(" /deletepathfile");
\r
1313 case ShellMenuAdd:
\r
1314 case ShellMenuAddAsReplacement:
\r
1315 tempfile = WriteFileListToTempFile();
\r
1316 svnCmd += _T("add /pathfile:\"");
\r
1317 svnCmd += tempfile;
\r
1318 svnCmd += _T("\"");
\r
1319 svnCmd += _T(" /deletepathfile");
\r
1321 case ShellMenuIgnore:
\r
1322 tempfile = WriteFileListToTempFile();
\r
1323 svnCmd += _T("ignore /pathfile:\"");
\r
1324 svnCmd += tempfile;
\r
1325 svnCmd += _T("\"");
\r
1326 svnCmd += _T(" /deletepathfile");
\r
1328 case ShellMenuIgnoreCaseSensitive:
\r
1329 tempfile = WriteFileListToTempFile();
\r
1330 svnCmd += _T("ignore /pathfile:\"");
\r
1331 svnCmd += tempfile;
\r
1332 svnCmd += _T("\"");
\r
1333 svnCmd += _T(" /deletepathfile");
\r
1334 svnCmd += _T(" /onlymask");
\r
1336 case ShellMenuUnIgnore:
\r
1337 tempfile = WriteFileListToTempFile();
\r
1338 svnCmd += _T("unignore /pathfile:\"");
\r
1339 svnCmd += tempfile;
\r
1340 svnCmd += _T("\"");
\r
1341 svnCmd += _T(" /deletepathfile");
\r
1343 case ShellMenuUnIgnoreCaseSensitive:
\r
1344 tempfile = WriteFileListToTempFile();
\r
1345 svnCmd += _T("unignore /pathfile:\"");
\r
1346 svnCmd += tempfile;
\r
1347 svnCmd += _T("\"");
\r
1348 svnCmd += _T(" /deletepathfile");
\r
1349 svnCmd += _T(" /onlymask");
\r
1351 case ShellMenuRevert:
\r
1352 tempfile = WriteFileListToTempFile();
\r
1353 svnCmd += _T("revert /pathfile:\"");
\r
1354 svnCmd += tempfile;
\r
1355 svnCmd += _T("\"");
\r
1356 svnCmd += _T(" /deletepathfile");
\r
1358 case ShellMenuDelUnversioned:
\r
1359 svnCmd += _T("delunversioned /path:\"");
\r
1360 svnCmd += folder_;
\r
1361 svnCmd += _T("\"");
\r
1363 case ShellMenuCleanup:
\r
1364 tempfile = WriteFileListToTempFile();
\r
1365 svnCmd += _T("cleanup /pathfile:\"");
\r
1366 svnCmd += tempfile;
\r
1367 svnCmd += _T("\"");
\r
1368 svnCmd += _T(" /deletepathfile");
\r
1370 case ShellMenuResolve:
\r
1371 tempfile = WriteFileListToTempFile();
\r
1372 svnCmd += _T("resolve /pathfile:\"");
\r
1373 svnCmd += tempfile;
\r
1374 svnCmd += _T("\"");
\r
1375 svnCmd += _T(" /deletepathfile");
\r
1377 case ShellMenuSwitch:
\r
1378 svnCmd += _T("switch /path:\"");
\r
1379 if (files_.size() > 0)
\r
1380 svnCmd += files_.front();
\r
1382 svnCmd += folder_;
\r
1383 svnCmd += _T("\"");
\r
1385 case ShellMenuImport:
\r
1386 svnCmd += _T("import /path:\"");
\r
1387 svnCmd += folder_;
\r
1388 svnCmd += _T("\"");
\r
1390 case ShellMenuExport:
\r
1391 svnCmd += _T("export /path:\"");
\r
1392 svnCmd += folder_;
\r
1393 svnCmd += _T("\"");
\r
1395 case ShellMenuAbout:
\r
1396 svnCmd += _T("about");
\r
1398 case ShellMenuCreateRepos:
\r
1399 svnCmd += _T("repocreate /path:\"");
\r
1400 svnCmd += folder_;
\r
1401 svnCmd += _T("\"");
\r
1403 case ShellMenuMerge:
\r
1404 svnCmd += _T("merge /path:\"");
\r
1405 if (files_.size() > 0)
\r
1406 svnCmd += files_.front();
\r
1408 svnCmd += folder_;
\r
1409 svnCmd += _T("\"");
\r
1411 case ShellMenuMergeAll:
\r
1412 svnCmd += _T("mergeall /path:\"");
\r
1413 if (files_.size() > 0)
\r
1414 svnCmd += files_.front();
\r
1416 svnCmd += folder_;
\r
1417 svnCmd += _T("\"");
\r
1419 case ShellMenuCopy:
\r
1420 svnCmd += _T("copy /path:\"");
\r
1421 if (files_.size() > 0)
\r
1422 svnCmd += files_.front();
\r
1424 svnCmd += folder_;
\r
1425 svnCmd += _T("\"");
\r
1427 case ShellMenuSettings:
\r
1428 svnCmd += _T("settings");
\r
1430 case ShellMenuHelp:
\r
1431 svnCmd += _T("help");
\r
1433 case ShellMenuRename:
\r
1434 svnCmd += _T("rename /path:\"");
\r
1435 if (files_.size() > 0)
\r
1436 svnCmd += files_.front();
\r
1438 svnCmd += folder_;
\r
1439 svnCmd += _T("\"");
\r
1441 case ShellMenuRemove:
\r
1442 tempfile = WriteFileListToTempFile();
\r
1443 svnCmd += _T("remove /pathfile:\"");
\r
1444 svnCmd += tempfile;
\r
1445 svnCmd += _T("\"");
\r
1446 svnCmd += _T(" /deletepathfile");
\r
1448 case ShellMenuRemoveKeep:
\r
1449 tempfile = WriteFileListToTempFile();
\r
1450 svnCmd += _T("remove /pathfile:\"");
\r
1451 svnCmd += tempfile;
\r
1452 svnCmd += _T("\"");
\r
1453 svnCmd += _T(" /deletepathfile");
\r
1454 svnCmd += _T(" /keep");
\r
1456 case ShellMenuDiff:
\r
1457 svnCmd += _T("diff /path:\"");
\r
1458 if (files_.size() == 1)
\r
1459 svnCmd += files_.front();
\r
1460 else if (files_.size() == 2)
\r
1462 std::vector<stdstring>::iterator I = files_.begin();
\r
1465 svnCmd += _T("\" /path2:\"");
\r
1469 svnCmd += folder_;
\r
1470 svnCmd += _T("\"");
\r
1471 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1472 svnCmd += _T(" /alternative");
\r
1474 case ShellMenuPrevDiff:
\r
1475 svnCmd += _T("prevdiff /path:\"");
\r
1476 if (files_.size() == 1)
\r
1477 svnCmd += files_.front();
\r
1479 svnCmd += folder_;
\r
1480 svnCmd += _T("\"");
\r
1481 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1482 svnCmd += _T(" /alternative");
\r
1484 case ShellMenuUrlDiff:
\r
1485 svnCmd += _T("urldiff /path:\"");
\r
1486 if (files_.size() == 1)
\r
1487 svnCmd += files_.front();
\r
1489 svnCmd += folder_;
\r
1490 svnCmd += _T("\"");
\r
1492 case ShellMenuDropCopyAdd:
\r
1493 tempfile = WriteFileListToTempFile();
\r
1494 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1495 svnCmd += tempfile;
\r
1496 svnCmd += _T("\"");
\r
1497 svnCmd += _T(" /deletepathfile");
\r
1498 svnCmd += _T(" /droptarget:\"");
\r
1499 svnCmd += folder_;
\r
1500 svnCmd += _T("\"";)
\r
1502 case ShellMenuDropCopy:
\r
1503 tempfile = WriteFileListToTempFile();
\r
1504 svnCmd += _T("dropcopy /pathfile:\"");
\r
1505 svnCmd += tempfile;
\r
1506 svnCmd += _T("\"");
\r
1507 svnCmd += _T(" /deletepathfile");
\r
1508 svnCmd += _T(" /droptarget:\"");
\r
1509 svnCmd += folder_;
\r
1510 svnCmd += _T("\"";)
\r
1512 case ShellMenuDropCopyRename:
\r
1513 tempfile = WriteFileListToTempFile();
\r
1514 svnCmd += _T("dropcopy /pathfile:\"");
\r
1515 svnCmd += tempfile;
\r
1516 svnCmd += _T("\"");
\r
1517 svnCmd += _T(" /deletepathfile");
\r
1518 svnCmd += _T(" /droptarget:\"");
\r
1519 svnCmd += folder_;
\r
1520 svnCmd += _T("\" /rename";)
\r
1522 case ShellMenuDropMove:
\r
1523 tempfile = WriteFileListToTempFile();
\r
1524 svnCmd += _T("dropmove /pathfile:\"");
\r
1525 svnCmd += tempfile;
\r
1526 svnCmd += _T("\"");
\r
1527 svnCmd += _T(" /deletepathfile");
\r
1528 svnCmd += _T(" /droptarget:\"");
\r
1529 svnCmd += folder_;
\r
1530 svnCmd += _T("\"");
\r
1532 case ShellMenuDropMoveRename:
\r
1533 tempfile = WriteFileListToTempFile();
\r
1534 svnCmd += _T("dropmove /pathfile:\"");
\r
1535 svnCmd += tempfile;
\r
1536 svnCmd += _T("\"");
\r
1537 svnCmd += _T(" /deletepathfile");
\r
1538 svnCmd += _T(" /droptarget:\"");
\r
1539 svnCmd += folder_;
\r
1540 svnCmd += _T("\" /rename";)
\r
1542 case ShellMenuDropExport:
\r
1543 tempfile = WriteFileListToTempFile();
\r
1544 svnCmd += _T("dropexport /pathfile:\"");
\r
1545 svnCmd += tempfile;
\r
1546 svnCmd += _T("\"");
\r
1547 svnCmd += _T(" /deletepathfile");
\r
1548 svnCmd += _T(" /droptarget:\"");
\r
1549 svnCmd += folder_;
\r
1550 svnCmd += _T("\"");
\r
1552 case ShellMenuDropExportExtended:
\r
1553 tempfile = WriteFileListToTempFile();
\r
1554 svnCmd += _T("dropexport /pathfile:\"");
\r
1555 svnCmd += tempfile;
\r
1556 svnCmd += _T("\"");
\r
1557 svnCmd += _T(" /deletepathfile");
\r
1558 svnCmd += _T(" /droptarget:\"");
\r
1559 svnCmd += folder_;
\r
1560 svnCmd += _T("\"");
\r
1561 svnCmd += _T(" /extended");
\r
1563 case ShellMenuLog:
\r
1564 svnCmd += _T("log /path:\"");
\r
1565 if (files_.size() > 0)
\r
1566 svnCmd += files_.front();
\r
1568 svnCmd += folder_;
\r
1569 svnCmd += _T("\"");
\r
1571 case ShellMenuConflictEditor:
\r
1572 svnCmd += _T("conflicteditor /path:\"");
\r
1573 if (files_.size() > 0)
\r
1574 svnCmd += files_.front();
\r
1576 svnCmd += folder_;
\r
1577 svnCmd += _T("\"");
\r
1579 case ShellMenuRelocate:
\r
1580 svnCmd += _T("relocate /path:\"");
\r
1581 if (files_.size() > 0)
\r
1582 svnCmd += files_.front();
\r
1584 svnCmd += folder_;
\r
1585 svnCmd += _T("\"");
\r
1587 case ShellMenuShowChanged:
\r
1588 if (files_.size() > 1)
\r
1590 tempfile = WriteFileListToTempFile();
\r
1591 svnCmd += _T("repostatus /pathfile:\"");
\r
1592 svnCmd += tempfile;
\r
1593 svnCmd += _T("\"");
\r
1594 svnCmd += _T(" /deletepathfile");
\r
1598 svnCmd += _T("repostatus /path:\"");
\r
1599 if (files_.size() > 0)
\r
1600 svnCmd += files_.front();
\r
1602 svnCmd += folder_;
\r
1603 svnCmd += _T("\"");
\r
1606 case ShellMenuRepoBrowse:
\r
1607 svnCmd += _T("repobrowser /path:\"");
\r
1608 if (files_.size() > 0)
\r
1609 svnCmd += files_.front();
\r
1611 svnCmd += folder_;
\r
1612 svnCmd += _T("\"");
\r
1614 case ShellMenuBlame:
\r
1615 svnCmd += _T("blame /path:\"");
\r
1616 if (files_.size() > 0)
\r
1617 svnCmd += files_.front();
\r
1619 svnCmd += folder_;
\r
1620 svnCmd += _T("\"");
\r
1622 case ShellMenuCreatePatch:
\r
1623 tempfile = WriteFileListToTempFile();
\r
1624 svnCmd += _T("createpatch /pathfile:\"");
\r
1625 svnCmd += tempfile;
\r
1626 svnCmd += _T("\"");
\r
1627 svnCmd += _T(" /deletepathfile");
\r
1629 case ShellMenuApplyPatch:
\r
1630 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1632 // if there's a patch file in the clipboard, we save it
\r
1633 // to a temporary file and tell TortoiseMerge to use that one
\r
1634 UINT cFormat = RegisterClipboardFormat(_T("Tgit_UNIFIEDDIFF"));
\r
1635 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1637 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1638 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1640 DWORD len = GetTempPath(0, NULL);
\r
1641 TCHAR * path = new TCHAR[len+1];
\r
1642 TCHAR * tempF = new TCHAR[len+100];
\r
1643 GetTempPath (len+1, path);
\r
1644 GetTempFileName (path, TEXT("svn"), 0, tempF);
\r
1645 std::wstring sTempFile = std::wstring(tempF);
\r
1650 size_t patchlen = strlen(lpstr);
\r
1651 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1654 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1655 if (size == patchlen)
\r
1657 itemStates |= ITEMIS_PATCHFILE;
\r
1659 files_.push_back(sTempFile);
\r
1663 GlobalUnlock(hglb);
\r
1664 CloseClipboard();
\r
1667 if (itemStates & ITEMIS_PATCHFILE)
\r
1669 svnCmd = _T(" /diff:\"");
\r
1670 if (files_.size() > 0)
\r
1672 svnCmd += files_.front();
\r
1673 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1675 svnCmd += _T("\" /patchpath:\"");
\r
1676 svnCmd += folder_;
\r
1680 svnCmd += folder_;
\r
1681 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1682 svnCmd += _T("\" /wc");
\r
1684 svnCmd += _T("\"");
\r
1688 svnCmd = _T(" /patchpath:\"");
\r
1689 if (files_.size() > 0)
\r
1690 svnCmd += files_.front();
\r
1692 svnCmd += folder_;
\r
1693 svnCmd += _T("\"");
\r
1696 myVerbsIDMap.clear();
\r
1697 myVerbsMap.clear();
\r
1698 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1701 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1702 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1703 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1706 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1707 (LPTSTR) &lpMsgBuf,
\r
1711 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1712 LocalFree( lpMsgBuf );
\r
1714 CloseHandle(process.hThread);
\r
1715 CloseHandle(process.hProcess);
\r
1718 case ShellMenuRevisionGraph:
\r
1719 svnCmd += _T("revisiongraph /path:\"");
\r
1720 if (files_.size() > 0)
\r
1721 svnCmd += files_.front();
\r
1723 svnCmd += folder_;
\r
1724 svnCmd += _T("\"");
\r
1726 case ShellMenuLock:
\r
1727 tempfile = WriteFileListToTempFile();
\r
1728 svnCmd += _T("lock /pathfile:\"");
\r
1729 svnCmd += tempfile;
\r
1730 svnCmd += _T("\"");
\r
1731 svnCmd += _T(" /deletepathfile");
\r
1733 case ShellMenuUnlock:
\r
1734 tempfile = WriteFileListToTempFile();
\r
1735 svnCmd += _T("unlock /pathfile:\"");
\r
1736 svnCmd += tempfile;
\r
1737 svnCmd += _T("\"");
\r
1738 svnCmd += _T(" /deletepathfile");
\r
1740 case ShellMenuUnlockForce:
\r
1741 tempfile = WriteFileListToTempFile();
\r
1742 svnCmd += _T("unlock /pathfile:\"");
\r
1743 svnCmd += tempfile;
\r
1744 svnCmd += _T("\"");
\r
1745 svnCmd += _T(" /deletepathfile");
\r
1746 svnCmd += _T(" /force");
\r
1748 case ShellMenuProperties:
\r
1749 tempfile = WriteFileListToTempFile();
\r
1750 svnCmd += _T("properties /pathfile:\"");
\r
1751 svnCmd += tempfile;
\r
1752 svnCmd += _T("\"");
\r
1753 svnCmd += _T(" /deletepathfile");
\r
1755 case ShellMenuClipPaste:
\r
1756 if (WriteClipboardPathsToTempFile(tempfile))
\r
1758 bool bCopy = true;
\r
1759 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1760 if (cPrefDropFormat)
\r
1762 if (OpenClipboard(lpcmi->hwnd))
\r
1764 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1767 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1768 if (*effect == DROPEFFECT_MOVE)
\r
1770 GlobalUnlock(hglb);
\r
1777 svnCmd += _T("pastecopy /pathfile:\"");
\r
1779 svnCmd += _T("pastemove /pathfile:\"");
\r
1780 svnCmd += tempfile;
\r
1781 svnCmd += _T("\"");
\r
1782 svnCmd += _T(" /deletepathfile");
\r
1783 svnCmd += _T(" /droptarget:\"");
\r
1784 svnCmd += folder_;
\r
1785 svnCmd += _T("\"");
\r
1787 else return NOERROR;
\r
1789 case ShellMenuClone:
\r
1790 svnCmd += _T("clone /path:\"");
\r
1791 svnCmd += folder_;
\r
1792 svnCmd += _T("\"");
\r
1794 case ShellMenuPull:
\r
1795 svnCmd += _T("pull /path:\"");
\r
1796 if (files_.size() > 0)
\r
1797 svnCmd += files_.front();
\r
1799 svnCmd += folder_;
\r
1800 svnCmd += _T("\"");
\r
1802 case ShellMenuPush:
\r
1803 svnCmd += _T("push /path:\"");
\r
1804 if (files_.size() > 0)
\r
1805 svnCmd += files_.front();
\r
1807 svnCmd += folder_;
\r
1808 svnCmd += _T("\"");
\r
1810 case ShellMenuBranch:
\r
1811 svnCmd += _T("branch /path:\"");
\r
1812 if (files_.size() > 0)
\r
1813 svnCmd += files_.front();
\r
1815 svnCmd += folder_;
\r
1816 svnCmd += _T("\"");
\r
1819 case ShellMenuTag:
\r
1820 svnCmd += _T("tag /path:\"");
\r
1821 if (files_.size() > 0)
\r
1822 svnCmd += files_.front();
\r
1824 svnCmd += folder_;
\r
1825 svnCmd += _T("\"");
\r
1828 case ShellMenuFormatPatch:
\r
1829 svnCmd += _T("formatpatch /path:\"");
\r
1830 if (files_.size() > 0)
\r
1831 svnCmd += files_.front();
\r
1833 svnCmd += folder_;
\r
1834 svnCmd += _T("\"");
\r
1837 case ShellMenuImportPatch:
\r
1838 svnCmd += _T("importpatch /path:\"");
\r
1839 if (files_.size() > 0)
\r
1840 svnCmd += files_.front();
\r
1842 svnCmd += folder_;
\r
1843 svnCmd += _T("\"");
\r
1846 case ShellMenuCherryPick:
\r
1847 svnCmd += _T("cherrypick /path:\"");
\r
1848 if (files_.size() > 0)
\r
1849 svnCmd += files_.front();
\r
1851 svnCmd += folder_;
\r
1852 svnCmd += _T("\"");
\r
1854 case ShellMenuFetch:
\r
1855 svnCmd += _T("fetch /path:\"");
\r
1856 if (files_.size() > 0)
\r
1857 svnCmd += files_.front();
\r
1859 svnCmd += folder_;
\r
1860 svnCmd += _T("\"");
\r
1866 } // switch (id_it->second)
\r
1867 svnCmd += _T(" /hwnd:");
\r
1869 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1872 myVerbsIDMap.clear();
\r
1873 myVerbsMap.clear();
\r
1874 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1877 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1878 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1879 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1882 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1883 (LPTSTR) &lpMsgBuf,
\r
1887 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1888 LocalFree( lpMsgBuf );
\r
1890 CloseHandle(process.hThread);
\r
1891 CloseHandle(process.hProcess);
\r
1893 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1894 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1899 // This is for the status bar and things like that:
\r
1900 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1902 UINT FAR * /*reserved*/,
\r
1906 PreserveChdir preserveChdir;
\r
1907 //do we know the id?
\r
1908 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1909 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1911 return E_INVALIDARG; //no, we don't
\r
1915 HRESULT hr = E_INVALIDARG;
\r
1917 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1918 int menuIndex = 0;
\r
1919 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1921 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1923 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1929 const TCHAR * desc = stringtablebuffer;
\r
1932 case GCS_HELPTEXTA:
\r
1934 std::string help = WideToMultibyte(desc);
\r
1935 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1939 case GCS_HELPTEXTW:
\r
1941 wide_string help = desc;
\r
1942 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1948 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1949 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1951 std::string help = WideToMultibyte(verb_id_it->second);
\r
1952 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1959 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1960 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1962 wide_string help = verb_id_it->second;
\r
1963 ATLTRACE("verb : %ws\n", help.c_str());
\r
1964 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1973 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1976 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
1979 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
1981 PreserveChdir preserveChdir;
\r
1984 if (pResult == NULL)
\r
1991 case WM_MEASUREITEM:
\r
1993 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
1996 lpmis->itemWidth += 2;
\r
1997 if (lpmis->itemHeight < 16)
\r
1998 lpmis->itemHeight = 16;
\r
2005 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2006 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2007 return S_OK; //not for a menu
\r
2008 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2009 if (resource == NULL)
\r
2011 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2012 if (hIcon == NULL)
\r
2014 DrawIconEx(lpdis->hDC,
\r
2015 lpdis->rcItem.left - 16,
\r
2016 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2018 0, NULL, DI_NORMAL);
\r
2019 DestroyIcon(hIcon);
\r
2027 if (HIWORD(wParam) != MF_POPUP)
\r
2029 int nChar = LOWORD(wParam);
\r
2030 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2031 nChar = tolower(nChar);
\r
2032 // we have the char the user pressed, now search that char in all our
\r
2034 std::vector<int> accmenus;
\r
2035 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2037 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2038 if (resource == NULL)
\r
2040 szItem = stringtablebuffer;
\r
2041 TCHAR * amp = _tcschr(szItem, '&');
\r
2045 int ampChar = LOWORD(*amp);
\r
2046 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2047 ampChar = tolower(ampChar);
\r
2048 if (ampChar == nChar)
\r
2050 // yep, we found a menu which has the pressed key
\r
2051 // as an accelerator. Add that menu to the list to
\r
2053 accmenus.push_back(It->first);
\r
2056 if (accmenus.size() == 0)
\r
2058 // no menu with that accelerator key.
\r
2059 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2062 if (accmenus.size() == 1)
\r
2064 // Only one menu with that accelerator key. We're lucky!
\r
2065 // So just execute that menu entry.
\r
2066 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2069 if (accmenus.size() > 1)
\r
2071 // we have more than one menu item with this accelerator key!
\r
2073 mif.cbSize = sizeof(MENUITEMINFO);
\r
2074 mif.fMask = MIIM_STATE;
\r
2075 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2077 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2078 if (mif.fState == MFS_HILITE)
\r
2080 // this is the selected item, so select the next one
\r
2082 if (it == accmenus.end())
\r
2083 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2085 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2089 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2100 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2102 TCHAR textbuf[255];
\r
2103 LPCTSTR resource = NULL;
\r
2104 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2107 int menuIndex = 0;
\r
2108 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2110 if (menuInfo[menuIndex].command == id)
\r
2112 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2113 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2116 case ShellMenuLock:
\r
2117 // menu lock is special because it can be set to the top
\r
2118 // with a separate option in the registry
\r
2119 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2120 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2122 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2123 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2124 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2127 // the sub menu entries are special because they're *always* on the top level menu
\r
2128 case ShellSubMenuMultiple:
\r
2129 case ShellSubMenuLink:
\r
2130 case ShellSubMenuFolder:
\r
2131 case ShellSubMenuFile:
\r
2132 case ShellSubMenu:
\r
2136 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2137 if (layout & (menuInfo[menuIndex].menuID))
\r
2139 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2140 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2141 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2152 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2155 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2156 LPITEMIDLIST pidl = NULL;
\r
2157 while (cslidarray[i])
\r
2161 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2163 if (!SHGetPathFromIDList(pidl, buf))
\r
2165 // not a file system path, definitely illegal for our use
\r
2166 CoTaskMemFree(pidl);
\r
2169 CoTaskMemFree(pidl);
\r
2170 if (_tcslen(buf)==0)
\r
2172 if (_tcscmp(buf, folder.c_str())==0)
\r
2178 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2180 HMENU ignoresubmenu = NULL;
\r
2181 int indexignoresub = 0;
\r
2182 bool bShowIgnoreMenu = false;
\r
2183 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2184 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2185 if (files_.size() == 0)
\r
2187 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2189 std::vector<stdstring>::iterator I = files_.begin();
\r
2190 if (_tcsrchr(I->c_str(), '\\'))
\r
2191 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2193 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2194 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2196 // check if the item name is ignored or the mask
\r
2198 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2200 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2201 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2209 ignoresubmenu = CreateMenu();
\r
2210 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2211 stdstring verb = stdstring(ignorepath);
\r
2212 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2213 myVerbsMap[verb] = idCmd;
\r
2214 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2215 myVerbsIDMap[idCmd] = verb;
\r
2216 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2217 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2218 bShowIgnoreMenu = true;
\r
2220 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2221 if (_tcsrchr(ignorepath, '.'))
\r
2223 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2224 p = ignoredprops.find(maskbuf);
\r
2226 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2228 if (ignoresubmenu==NULL)
\r
2229 ignoresubmenu = CreateMenu();
\r
2231 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2232 stdstring verb = stdstring(maskbuf);
\r
2233 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2234 myVerbsMap[verb] = idCmd;
\r
2235 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2236 myVerbsIDMap[idCmd] = verb;
\r
2237 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2238 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2239 bShowIgnoreMenu = true;
\r
2243 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2245 bShowIgnoreMenu = true;
\r
2246 ignoresubmenu = CreateMenu();
\r
2247 if (itemStates & ITEMIS_ONLYONE)
\r
2249 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2250 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2251 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2253 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2254 if (_tcsrchr(ignorepath, '.'))
\r
2256 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2257 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2258 stdstring verb = stdstring(maskbuf);
\r
2259 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2260 myVerbsMap[verb] = idCmd;
\r
2261 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2262 myVerbsIDMap[idCmd] = verb;
\r
2263 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2264 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2269 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2270 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2271 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2272 stdstring verb = stdstring(ignorepath);
\r
2273 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2274 myVerbsMap[verb] = idCmd;
\r
2275 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2276 myVerbsIDMap[idCmd] = verb;
\r
2277 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2278 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2280 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2281 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2282 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2283 verb = stdstring(ignorepath);
\r
2284 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2285 myVerbsMap[verb] = idCmd;
\r
2286 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2287 myVerbsIDMap[idCmd] = verb;
\r
2288 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2289 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2293 if (bShowIgnoreMenu)
\r
2295 MENUITEMINFO menuiteminfo;
\r
2296 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2297 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2298 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2299 menuiteminfo.fType = MFT_STRING;
\r
2300 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2302 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2303 menuiteminfo.hbmpChecked = bmp;
\r
2304 menuiteminfo.hbmpUnchecked = bmp;
\r
2305 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2306 menuiteminfo.wID = idCmd;
\r
2307 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2308 if (itemStates & ITEMIS_IGNORED)
\r
2309 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2311 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2312 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2313 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2315 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2316 if (itemStates & ITEMIS_IGNORED)
\r
2318 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2319 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2323 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2324 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2329 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2331 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2332 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2333 return bitmap_it->second;
\r
2335 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2339 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2343 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2344 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2347 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2348 HBITMAP hBmp = NULL;
\r
2350 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2353 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2355 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2358 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2359 BP_PAINTPARAMS paintParams = {0};
\r
2360 paintParams.cbSize = sizeof(paintParams);
\r
2361 paintParams.dwFlags = BPPF_ERASE;
\r
2362 paintParams.pBlendFunction = &bfAlpha;
\r
2365 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2368 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2370 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2371 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2374 // This will write the buffer contents to the destination bitmap
\r
2375 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2378 SelectObject(hdcDest, hbmpOld);
\r
2382 DeleteDC(hdcDest);
\r
2385 DestroyIcon(hIcon);
\r
2388 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2392 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2397 ZeroMemory(&bmi, sizeof(bmi));
\r
2398 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2399 bmi.bmiHeader.biPlanes = 1;
\r
2400 bmi.bmiHeader.biCompression = BI_RGB;
\r
2402 bmi.bmiHeader.biWidth = psize->cx;
\r
2403 bmi.bmiHeader.biHeight = psize->cy;
\r
2404 bmi.bmiHeader.biBitCount = 32;
\r
2406 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2409 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2410 if (hdc != hdcUsed)
\r
2412 ReleaseDC(NULL, hdcUsed);
\r
2415 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2418 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2420 RGBQUAD *prgbQuad;
\r
2422 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2423 if (SUCCEEDED(hr))
\r
2425 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2426 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2429 if (GetIconInfo(hicon, &info))
\r
2433 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2436 DeleteObject(info.hbmColor);
\r
2437 DeleteObject(info.hbmMask);
\r
2445 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2447 ULONG cxDelta = cxRow - sizImage.cx;
\r
2448 for (ULONG y = sizImage.cy; y; --y)
\r
2450 for (ULONG x = sizImage.cx; x; --x)
\r
2452 if (*pargb++ & 0xFF000000)
\r
2464 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2467 ZeroMemory(&bmi, sizeof(bmi));
\r
2468 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2469 bmi.bmiHeader.biPlanes = 1;
\r
2470 bmi.bmiHeader.biCompression = BI_RGB;
\r
2472 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2473 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2474 bmi.bmiHeader.biBitCount = 32;
\r
2476 HRESULT hr = E_OUTOFMEMORY;
\r
2477 HANDLE hHeap = GetProcessHeap();
\r
2478 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2481 hr = E_UNEXPECTED;
\r
2482 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2484 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2485 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2487 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2489 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2493 // transparent pixel
\r
2499 *pargb++ |= 0xFF000000;
\r
2509 HeapFree(hHeap, 0, pvBits);
\r