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_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
160 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
\r
161 // why was this changed, is this related to GitStatus?
\r
163 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
164 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
166 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
167 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
169 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
171 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
172 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
174 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
175 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
177 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
178 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
181 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
182 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
184 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
185 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0 },
\r
187 { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
188 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
190 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
191 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
192 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
194 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
196 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
197 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
198 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
199 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
200 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
201 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
203 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
204 // but they still need to be in here, because we use the icon and string information anyway.
\r
205 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
206 0, 0, 0, 0, 0, 0, 0, 0 },
\r
207 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
208 0, 0, 0, 0, 0, 0, 0, 0 },
\r
209 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
210 0, 0, 0, 0, 0, 0, 0, 0 },
\r
211 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
212 0, 0, 0, 0, 0, 0, 0, 0 },
\r
213 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
214 0, 0, 0, 0, 0, 0, 0, 0 },
\r
215 // mark the last entry to tell the loop where to stop iterating over this array
\r
216 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
217 0, 0, 0, 0, 0, 0, 0, 0 },
\r
221 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
222 LPDATAOBJECT pDataObj,
\r
223 HKEY /* hRegKey */)
\r
226 ATLTRACE("Shell :: Initialize\n");
\r
227 PreserveChdir preserveChdir;
\r
230 uuidSource.erase();
\r
231 uuidTarget.erase();
\r
233 itemStatesFolder = 0;
\r
234 stdstring statuspath;
\r
235 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
236 // get selected files/folders
\r
240 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
241 (DVTARGETDEVICE FAR *)NULL,
\r
245 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
247 if (SUCCEEDED(hres) && medium.hGlobal)
\r
249 if (m_State == FileStateDropHandler)
\r
252 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
253 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
254 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
256 ReleaseStgMedium ( &medium );
\r
257 return E_INVALIDARG;
\r
261 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
262 if ( NULL == drop )
\r
264 ReleaseStgMedium ( &stg );
\r
265 ReleaseStgMedium ( &medium );
\r
266 return E_INVALIDARG;
\r
269 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
271 itemStates |= ITEMIS_ONLYONE;
\r
272 for (int i = 0; i < count; i++)
\r
274 // find the path length in chars
\r
275 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
278 TCHAR * szFileName = new TCHAR[len+1];
\r
279 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
281 delete [] szFileName;
\r
284 stdstring str = stdstring(szFileName);
\r
285 delete [] szFileName;
\r
286 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
288 if (itemStates & ITEMIS_ONLYONE)
\r
291 strpath.SetFromWin(str.c_str());
\r
292 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
293 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
295 files_.push_back(str);
\r
298 //get the Subversion status of the item
\r
299 git_wc_status_kind status = git_wc_status_none;
\r
300 CTGitPath askedpath;
\r
301 askedpath.SetFromWin(str.c_str());
\r
305 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
309 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
310 fetchedstatus = status;
\r
311 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
312 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
313 if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
315 itemStates |= ITEMIS_FOLDER;
\r
316 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
317 itemStates |= ITEMIS_FOLDERINSVN;
\r
319 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
321 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
322 // itemStates |= ITEMIS_NEEDSLOCK;
\r
324 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
325 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
329 // sometimes, git_client_status() returns with an error.
\r
330 // in that case, we have to check if the working copy is versioned
\r
331 // anyway to show the 'correct' context menu
\r
332 if (askedpath.HasAdminDir())
\r
333 status = git_wc_status_normal;
\r
338 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
341 // TODO: should we really assume any sub-directory to be versioned
\r
342 // or only if it contains versioned files
\r
343 if ( askedpath.IsDirectory() )
\r
345 if (askedpath.HasAdminDir())
\r
346 itemStates |= ITEMIS_INSVN;
\r
348 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
349 itemStates |= ITEMIS_INSVN;
\r
350 if (status == git_wc_status_ignored)
\r
351 itemStates |= ITEMIS_IGNORED;
\r
352 if (status == git_wc_status_normal)
\r
353 itemStates |= ITEMIS_NORMAL;
\r
354 if (status == git_wc_status_conflicted)
\r
355 itemStates |= ITEMIS_CONFLICTED;
\r
356 if (status == git_wc_status_added)
\r
357 itemStates |= ITEMIS_ADDED;
\r
358 if (status == git_wc_status_deleted)
\r
359 itemStates |= ITEMIS_DELETED;
\r
362 } // for (int i = 0; i < count; i++)
\r
363 GlobalUnlock ( drop );
\r
364 ReleaseStgMedium ( &stg );
\r
366 } // if (m_State == FileStateDropHandler)
\r
370 //Enumerate PIDLs which the user has selected
\r
371 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
372 ItemIDList parent( GetPIDLFolder (cida));
\r
374 int count = cida->cidl;
\r
375 BOOL statfetched = FALSE;
\r
376 for (int i = 0; i < count; ++i)
\r
378 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
379 stdstring str = child.toString();
\r
380 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
382 //check if our menu is requested for a subversion admin directory
\r
383 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
386 files_.push_back(str);
\r
388 strpath.SetFromWin(str.c_str());
\r
389 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
390 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
393 //get the Subversion status of the item
\r
394 git_wc_status_kind status = git_wc_status_none;
\r
395 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
397 if (strpath.HasAdminDir())
\r
398 status = git_wc_status_normal;
\r
405 if (strpath.HasAdminDir())
\r
406 stat.GetStatus(strpath, false, true, true);
\r
410 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
411 fetchedstatus = status;
\r
412 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
413 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
414 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
416 itemStates |= ITEMIS_FOLDER;
\r
417 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
418 itemStates |= ITEMIS_FOLDERINSVN;
\r
420 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
\r
421 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
422 itemStates |= ITEMIS_CONFLICTED;
\r
423 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
425 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
426 // itemStates |= ITEMIS_NEEDSLOCK;
\r
428 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
429 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
433 // sometimes, git_client_status() returns with an error.
\r
434 // in that case, we have to check if the working copy is versioned
\r
435 // anyway to show the 'correct' context menu
\r
436 if (strpath.HasAdminDir())
\r
438 status = git_wc_status_normal;
\r
439 fetchedstatus = status;
\r
442 statfetched = TRUE;
\r
446 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
450 // TODO: should we really assume any sub-directory to be versioned
\r
451 // or only if it contains versioned files
\r
452 if ( strpath.IsDirectory() )
\r
454 if (strpath.HasAdminDir())
\r
455 itemStates |= ITEMIS_INSVN;
\r
457 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
458 itemStates |= ITEMIS_INSVN;
\r
459 if (status == git_wc_status_ignored)
\r
461 itemStates |= ITEMIS_IGNORED;
\r
462 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
463 // offer a 'remove from ignored list' entry
\r
464 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
465 // ignoredprops.empty();
\r
466 // for (int p=0; p<props.GetCount(); ++p)
\r
468 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
470 // std::string st = props.GetItemValue(p);
\r
471 // ignoredprops = MultibyteToWide(st.c_str());
\r
472 // // remove all escape chars ('\\')
\r
473 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
478 if (status == git_wc_status_normal)
\r
479 itemStates |= ITEMIS_NORMAL;
\r
480 if (status == git_wc_status_conflicted)
\r
481 itemStates |= ITEMIS_CONFLICTED;
\r
482 if (status == git_wc_status_added)
\r
483 itemStates |= ITEMIS_ADDED;
\r
484 if (status == git_wc_status_deleted)
\r
485 itemStates |= ITEMIS_DELETED;
\r
488 } // for (int i = 0; i < count; ++i)
\r
489 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
490 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
491 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
492 GlobalUnlock(medium.hGlobal);
\r
494 // if the item is a versioned folder, check if there's a patch file
\r
495 // in the clipboard to be used in "Apply Patch"
\r
496 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
499 if (IsClipboardFormatAvailable(cFormatDiff))
\r
500 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
502 if (IsClipboardFormatAvailable(CF_HDROP))
\r
503 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
507 ReleaseStgMedium ( &medium );
\r
508 if (medium.pUnkForRelease)
\r
510 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
511 relInterface->Release();
\r
516 // get folder background
\r
520 ItemIDList list(pIDFolder);
\r
521 folder_ = list.toString();
\r
522 git_wc_status_kind status = git_wc_status_none;
\r
523 if (IsClipboardFormatAvailable(CF_HDROP))
\r
524 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
526 CTGitPath askedpath;
\r
527 askedpath.SetFromWin(folder_.c_str());
\r
529 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
535 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
538 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
539 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
540 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
541 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
543 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
544 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
546 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
547 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
552 // sometimes, git_client_status() returns with an error.
\r
553 // in that case, we have to check if the working copy is versioned
\r
554 // anyway to show the 'correct' context menu
\r
555 if (askedpath.HasAdminDir())
\r
556 status = git_wc_status_normal;
\r
559 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
560 if (askedpath.HasAdminDir())
\r
561 itemStatesFolder |= ITEMIS_INSVN;
\r
562 if (status == git_wc_status_normal)
\r
563 itemStatesFolder |= ITEMIS_NORMAL;
\r
564 if (status == git_wc_status_conflicted)
\r
565 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
566 if (status == git_wc_status_added)
\r
567 itemStatesFolder |= ITEMIS_ADDED;
\r
568 if (status == git_wc_status_deleted)
\r
569 itemStatesFolder |= ITEMIS_DELETED;
\r
574 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
579 status = fetchedstatus;
\r
581 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
582 if (askedpath.HasAdminDir())
\r
584 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
586 if (status == git_wc_status_ignored)
\r
587 itemStatesFolder |= ITEMIS_IGNORED;
\r
588 itemStatesFolder |= ITEMIS_FOLDER;
\r
589 if (files_.size() == 0)
\r
590 itemStates |= ITEMIS_ONLYONE;
\r
591 if (m_State != FileStateDropHandler)
\r
592 itemStates |= itemStatesFolder;
\r
595 if (files_.size() == 2)
\r
596 itemStates |= ITEMIS_TWO;
\r
597 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
600 itemStates |= ITEMIS_ONLYONE;
\r
601 if (m_State != FileStateDropHandler)
\r
603 if (PathIsDirectory(files_.front().c_str()))
\r
605 folder_ = files_.front();
\r
606 git_wc_status_kind status = git_wc_status_none;
\r
607 CTGitPath askedpath;
\r
608 askedpath.SetFromWin(folder_.c_str());
\r
610 if (folder_.compare(statuspath)!=0)
\r
615 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
618 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
619 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
620 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
621 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
623 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
624 // itemStates |= ITEMIS_NEEDSLOCK;
\r
626 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
627 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
632 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
637 status = fetchedstatus;
\r
639 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
640 if (askedpath.HasAdminDir())
\r
641 itemStates |= ITEMIS_FOLDERINSVN;
\r
642 if (status == git_wc_status_ignored)
\r
643 itemStates |= ITEMIS_IGNORED;
\r
644 itemStates |= ITEMIS_FOLDER;
\r
645 if (status == git_wc_status_added)
\r
646 itemStates |= ITEMIS_ADDED;
\r
647 if (status == git_wc_status_deleted)
\r
648 itemStates |= ITEMIS_DELETED;
\r
657 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
659 TCHAR menutextbuffer[255] = {0};
\r
660 TCHAR verbsbuffer[255] = {0};
\r
661 MAKESTRING(stringid);
\r
665 //menu entry for the top context menu, so append an "Git " before
\r
666 //the menu text to indicate where the entry comes from
\r
667 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
669 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
670 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
672 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
673 if (fullver >= 0x500)
\r
675 // on win2k, the context menu does not work properly if we use
\r
676 // icon bitmaps. At least the menu text is empty in the context menu
\r
677 // for folder backgrounds (seems like a win2k bug).
\r
678 HBITMAP bmp = IconToBitmap(icon);
\r
679 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
684 MENUITEMINFO menuiteminfo = {0};
\r
685 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
686 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
687 menuiteminfo.fType = MFT_STRING;
\r
688 menuiteminfo.dwTypeData = menutextbuffer;
\r
690 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
691 menuiteminfo.wID = id;
\r
692 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
697 //menu entry for the top context menu, so append an "Git " before
\r
698 //the menu text to indicate where the entry comes from
\r
699 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
701 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
702 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
703 stdstring verb = stdstring(menutextbuffer);
\r
704 if (verb.find('&') != -1)
\r
706 verb.erase(verb.find('&'),1);
\r
708 myVerbsMap[verb] = id - idCmdFirst;
\r
709 myVerbsMap[verb] = id;
\r
710 myVerbsIDMap[id - idCmdFirst] = verb;
\r
711 myVerbsIDMap[id] = verb;
\r
712 // We store the relative and absolute diameter
\r
713 // (drawitem callback uses absolute, others relative)
\r
714 myIDMap[id - idCmdFirst] = com;
\r
717 mySubMenuMap[pos] = com;
\r
720 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
722 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
723 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
724 return bitmap_it->second;
\r
726 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
732 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
733 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
735 rect.left = rect.top = 0;
\r
737 HWND desktop = ::GetDesktopWindow();
\r
738 if (desktop == NULL)
\r
740 DestroyIcon(hIcon);
\r
744 HDC screen_dev = ::GetDC(desktop);
\r
745 if (screen_dev == NULL)
\r
747 DestroyIcon(hIcon);
\r
751 // Create a compatible DC
\r
752 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
753 if (dst_hdc == NULL)
\r
755 DestroyIcon(hIcon);
\r
756 ::ReleaseDC(desktop, screen_dev);
\r
760 // Create a new bitmap of icon size
\r
761 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
764 DestroyIcon(hIcon);
\r
765 ::DeleteDC(dst_hdc);
\r
766 ::ReleaseDC(desktop, screen_dev);
\r
770 // Select it into the compatible DC
\r
771 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
772 if (old_dst_bmp == NULL)
\r
774 DestroyIcon(hIcon);
\r
778 // Fill the background of the compatible DC with the white color
\r
779 // that is taken by menu routines as transparent
\r
780 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
781 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
783 // Draw the icon into the compatible DC
\r
784 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
786 // Restore settings
\r
787 ::SelectObject(dst_hdc, old_dst_bmp);
\r
788 ::DeleteDC(dst_hdc);
\r
789 ::ReleaseDC(desktop, screen_dev);
\r
790 DestroyIcon(hIcon);
\r
792 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
796 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
799 tempfile = stdstring();
\r
800 //write all selected files and paths to a temporary file
\r
801 //for TortoiseProc.exe to read out again.
\r
803 DWORD pathlength = GetTempPath(0, NULL);
\r
804 TCHAR * path = new TCHAR[pathlength+1];
\r
805 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
806 GetTempPath (pathlength+1, path);
\r
807 GetTempFileName (path, _T("git"), 0, tempFile);
\r
808 tempfile = stdstring(tempFile);
\r
810 HANDLE file = ::CreateFile (tempFile,
\r
815 FILE_ATTRIBUTE_TEMPORARY,
\r
819 delete [] tempFile;
\r
820 if (file == INVALID_HANDLE_VALUE)
\r
823 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
825 if (!OpenClipboard(NULL))
\r
828 stdstring sClipboardText;
\r
829 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
830 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
833 TCHAR szFileName[MAX_PATH];
\r
834 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
835 for(UINT i = 0; i < cFiles; ++i)
\r
837 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
838 stdstring filename = szFileName;
\r
839 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
840 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
842 GlobalUnlock(hDrop);
\r
845 GlobalUnlock(hglb);
\r
848 ::CloseHandle(file);
\r
853 stdstring CShellExt::WriteFileListToTempFile()
\r
855 //write all selected files and paths to a temporary file
\r
856 //for TortoiseProc.exe to read out again.
\r
857 DWORD pathlength = GetTempPath(0, NULL);
\r
858 TCHAR * path = new TCHAR[pathlength+1];
\r
859 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
860 GetTempPath (pathlength+1, path);
\r
861 GetTempFileName (path, _T("git"), 0, tempFile);
\r
862 stdstring retFilePath = stdstring(tempFile);
\r
864 HANDLE file = ::CreateFile (tempFile,
\r
869 FILE_ATTRIBUTE_TEMPORARY,
\r
873 delete [] tempFile;
\r
874 if (file == INVALID_HANDLE_VALUE)
\r
875 return stdstring();
\r
878 if (files_.empty())
\r
880 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
881 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
884 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
886 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
887 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
889 ::CloseHandle(file);
\r
890 return retFilePath;
\r
893 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
895 PreserveChdir preserveChdir;
\r
898 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
899 return NOERROR; //we don't change the default action
\r
901 if ((files_.size() == 0)||(folder_.size() == 0))
\r
904 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
907 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
909 //the drop handler only has eight commands, but not all are visible at the same time:
\r
910 //if the source file(s) are under version control then those files can be moved
\r
911 //to the new location or they can be moved with a rename,
\r
912 //if they are unversioned then they can be added to the working copy
\r
913 //if they are versioned, they also can be exported to an unversioned location
\r
914 UINT idCmd = idCmdFirst;
\r
917 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
918 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
919 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
921 // Git move and rename here
\r
922 // 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
923 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
924 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
927 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
928 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
929 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
931 // Git copy and rename here, source and target from same repository
\r
932 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
933 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
934 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
937 // available if target is versioned and source is either unversioned or from another repository
\r
938 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
939 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
942 // available if source is versioned and a folder
\r
943 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
944 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
946 // Git export all here
\r
947 // available if source is versioned and a folder
\r
948 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
949 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
952 // available if source is a patchfile
\r
953 if (itemStates & ITEMIS_PATCHFILE)
\r
954 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
957 if (idCmd != idCmdFirst)
\r
958 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
960 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
963 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
966 UINT /*idCmdLast*/,
\r
969 ATLTRACE("Shell :: QueryContextMenu\n");
\r
970 PreserveChdir preserveChdir;
\r
972 //first check if our drop handler is called
\r
973 //and then (if true) provide the context menu for the
\r
975 if (m_State == FileStateDropHandler)
\r
977 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
980 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
981 return NOERROR; //we don't change the default action
\r
983 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
986 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
989 int csidlarray[] =
\r
993 CSIDL_COMMON_FAVORITES,
\r
994 CSIDL_COMMON_STARTMENU,
\r
995 CSIDL_COMPUTERSNEARME,
\r
1003 CSIDL_INTERNET_CACHE,
\r
1013 if (IsIllegalFolder(folder_, csidlarray))
\r
1016 if (folder_.empty())
\r
1018 // folder is empty, but maybe files are selected
\r
1019 if (files_.size() == 0)
\r
1020 return NOERROR; // nothing selected - we don't have a menu to show
\r
1021 // check whether a selected entry is an UID - those are namespace extensions
\r
1022 // which we can't handle
\r
1023 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1025 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1030 //check if our menu is requested for a subversion admin directory
\r
1031 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1034 if (uFlags & CMF_EXTENDEDVERBS)
\r
1035 itemStates |= ITEMIS_EXTENDED;
\r
1037 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1038 if ( bShortcut && (files_.size()==1))
\r
1040 // Don't show the context menu for a link if the
\r
1041 // destination is not part of a working copy.
\r
1042 // It would only show the standard menu items
\r
1043 // which are already shown for the lnk-file.
\r
1044 CString path = files_.front().c_str();
\r
1045 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1051 //check if we already added our menu entry for a folder.
\r
1052 //we check that by iterating through all menu entries and check if
\r
1053 //the dwItemData member points to our global ID string. That string is set
\r
1054 //by our shell extension when the folder menu is inserted.
\r
1055 TCHAR menubuf[MAX_PATH];
\r
1056 int count = GetMenuItemCount(hMenu);
\r
1057 for (int i=0; i<count; ++i)
\r
1059 MENUITEMINFO miif;
\r
1060 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1061 miif.cbSize = sizeof(MENUITEMINFO);
\r
1062 miif.fMask = MIIM_DATA;
\r
1063 miif.dwTypeData = menubuf;
\r
1064 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1065 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1066 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1071 UINT idCmd = idCmdFirst;
\r
1073 //create the sub menu
\r
1074 HMENU subMenu = CreateMenu();
\r
1075 int indexSubMenu = 0;
\r
1077 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1078 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1080 int menuIndex = 0;
\r
1081 bool bAddSeparator = false;
\r
1082 bool bMenuEntryAdded = false;
\r
1083 bool bMenuEmpty = true;
\r
1084 // insert separator at start
\r
1085 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1086 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1087 // ?? TortoiseSVN had this as (fullver <= 0x0500) this disabled icons in win2k, but icons work fine in win2k
\r
1088 if (fullver < 0x0500)
\r
1089 bShowIcons = false;
\r
1090 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1092 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1094 // we don't add a separator immediately. Because there might not be
\r
1095 // another 'normal' menu entry after we insert a separator.
\r
1096 // we simply set a flag here, indicating that before the next
\r
1097 // 'normal' menu entry, a separator should be added.
\r
1099 bAddSeparator = true;
\r
1103 // check the conditions whether to show the menu entry or not
\r
1104 bool bInsertMenu = false;
\r
1106 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1108 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1110 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1111 bInsertMenu = true;
\r
1113 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1114 bInsertMenu = true;
\r
1115 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1116 bInsertMenu = true;
\r
1118 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1120 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1122 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1123 bInsertMenu = true;
\r
1125 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1126 bInsertMenu = true;
\r
1127 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1128 bInsertMenu = true;
\r
1130 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1132 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1134 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1135 bInsertMenu = true;
\r
1137 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1138 bInsertMenu = true;
\r
1139 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1140 bInsertMenu = true;
\r
1142 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1144 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1146 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1147 bInsertMenu = true;
\r
1149 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1150 bInsertMenu = true;
\r
1151 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1152 bInsertMenu = true;
\r
1154 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1158 // insert a separator
\r
1159 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1161 bAddSeparator = false;
\r
1162 bMenuEntryAdded = false;
\r
1163 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1167 // handle special cases (sub menus)
\r
1168 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1170 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1171 bMenuEntryAdded = true;
\r
1172 bMenuEmpty = false;
\r
1176 // the 'get lock' command is special
\r
1177 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1178 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1180 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1183 // insert the menu entry
\r
1184 InsertGitMenu( bIsTop,
\r
1185 bIsTop ? hMenu : subMenu,
\r
1186 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1188 menuInfo[menuIndex].menuTextID,
\r
1189 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1191 menuInfo[menuIndex].command,
\r
1195 bMenuEntryAdded = true;
\r
1196 bMenuEmpty = false;
\r
1205 //add sub menu to main context menu
\r
1206 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1207 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1208 MAKESTRING(IDS_MENUSUBMENU);
\r
1209 MENUITEMINFO menuiteminfo;
\r
1210 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1211 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1212 menuiteminfo.fType = MFT_STRING;
\r
1213 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1215 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1216 if (folder_.size())
\r
1218 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1219 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1220 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1221 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1223 else if (!bShortcut && (files_.size()==1))
\r
1225 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1226 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1227 myIDMap[idCmd] = ShellSubMenuFile;
\r
1229 else if (bShortcut && (files_.size()==1))
\r
1231 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1232 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1233 myIDMap[idCmd] = ShellSubMenuLink;
\r
1235 else if (files_.size() > 1)
\r
1237 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1238 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1239 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1243 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1244 myIDMap[idCmd] = ShellSubMenu;
\r
1246 HBITMAP bmp = NULL;
\r
1247 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1249 bmp = IconToBitmap(uIcon);
\r
1250 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1254 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1256 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1258 menuiteminfo.hbmpChecked = bmp;
\r
1259 menuiteminfo.hbmpUnchecked = bmp;
\r
1260 menuiteminfo.hSubMenu = subMenu;
\r
1261 menuiteminfo.wID = idCmd++;
\r
1262 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1265 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1267 //return number of menu items added
\r
1268 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1272 // This is called when you invoke a command on the menu:
\r
1273 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1275 PreserveChdir preserveChdir;
\r
1276 HRESULT hr = E_INVALIDARG;
\r
1277 if (lpcmi == NULL)
\r
1280 std::string command;
\r
1281 std::string parent;
\r
1284 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1286 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1288 if (HIWORD(lpcmi->lpVerb))
\r
1290 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1291 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1292 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1293 idCmd = verb_it->second;
\r
1298 // See if we have a handler interface for this id
\r
1299 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1300 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1302 STARTUPINFO startup;
\r
1303 PROCESS_INFORMATION process;
\r
1304 memset(&startup, 0, sizeof(startup));
\r
1305 startup.cb = sizeof(startup);
\r
1306 memset(&process, 0, sizeof(process));
\r
1307 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1308 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1310 //TortoiseProc expects a command line of the form:
\r
1311 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1313 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1315 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1316 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1317 stdstring svnCmd = _T(" /command:");
\r
1318 stdstring tempfile;
\r
1319 switch (id_it->second)
\r
1322 case ShellMenuCheckout:
\r
1323 svnCmd += _T("checkout /path:\"");
\r
1324 svnCmd += folder_;
\r
1325 svnCmd += _T("\"");
\r
1327 case ShellMenuUpdate:
\r
1328 tempfile = WriteFileListToTempFile();
\r
1329 svnCmd += _T("update /pathfile:\"");
\r
1330 svnCmd += tempfile;
\r
1331 svnCmd += _T("\"");
\r
1332 svnCmd += _T(" /deletepathfile");
\r
1334 case ShellMenuUpdateExt:
\r
1335 tempfile = WriteFileListToTempFile();
\r
1336 svnCmd += _T("update /pathfile:\"");
\r
1337 svnCmd += tempfile;
\r
1338 svnCmd += _T("\"");
\r
1339 svnCmd += _T(" /deletepathfile");
\r
1340 svnCmd += _T(" /rev");
\r
1342 case ShellMenuCommit:
\r
1343 tempfile = WriteFileListToTempFile();
\r
1344 svnCmd += _T("commit /pathfile:\"");
\r
1345 svnCmd += tempfile;
\r
1346 svnCmd += _T("\"");
\r
1347 svnCmd += _T(" /deletepathfile");
\r
1349 case ShellMenuAdd:
\r
1350 case ShellMenuAddAsReplacement:
\r
1351 tempfile = WriteFileListToTempFile();
\r
1352 svnCmd += _T("add /pathfile:\"");
\r
1353 svnCmd += tempfile;
\r
1354 svnCmd += _T("\"");
\r
1355 svnCmd += _T(" /deletepathfile");
\r
1357 case ShellMenuIgnore:
\r
1358 tempfile = WriteFileListToTempFile();
\r
1359 svnCmd += _T("ignore /pathfile:\"");
\r
1360 svnCmd += tempfile;
\r
1361 svnCmd += _T("\"");
\r
1362 svnCmd += _T(" /deletepathfile");
\r
1364 case ShellMenuIgnoreCaseSensitive:
\r
1365 tempfile = WriteFileListToTempFile();
\r
1366 svnCmd += _T("ignore /pathfile:\"");
\r
1367 svnCmd += tempfile;
\r
1368 svnCmd += _T("\"");
\r
1369 svnCmd += _T(" /deletepathfile");
\r
1370 svnCmd += _T(" /onlymask");
\r
1372 case ShellMenuUnIgnore:
\r
1373 tempfile = WriteFileListToTempFile();
\r
1374 svnCmd += _T("unignore /pathfile:\"");
\r
1375 svnCmd += tempfile;
\r
1376 svnCmd += _T("\"");
\r
1377 svnCmd += _T(" /deletepathfile");
\r
1379 case ShellMenuUnIgnoreCaseSensitive:
\r
1380 tempfile = WriteFileListToTempFile();
\r
1381 svnCmd += _T("unignore /pathfile:\"");
\r
1382 svnCmd += tempfile;
\r
1383 svnCmd += _T("\"");
\r
1384 svnCmd += _T(" /deletepathfile");
\r
1385 svnCmd += _T(" /onlymask");
\r
1387 case ShellMenuRevert:
\r
1388 tempfile = WriteFileListToTempFile();
\r
1389 svnCmd += _T("revert /pathfile:\"");
\r
1390 svnCmd += tempfile;
\r
1391 svnCmd += _T("\"");
\r
1392 svnCmd += _T(" /deletepathfile");
\r
1394 case ShellMenuDelUnversioned:
\r
1395 svnCmd += _T("delunversioned /path:\"");
\r
1396 svnCmd += folder_;
\r
1397 svnCmd += _T("\"");
\r
1399 case ShellMenuCleanup:
\r
1400 tempfile = WriteFileListToTempFile();
\r
1401 svnCmd += _T("cleanup /pathfile:\"");
\r
1402 svnCmd += tempfile;
\r
1403 svnCmd += _T("\"");
\r
1404 svnCmd += _T(" /deletepathfile");
\r
1406 case ShellMenuResolve:
\r
1407 tempfile = WriteFileListToTempFile();
\r
1408 svnCmd += _T("resolve /pathfile:\"");
\r
1409 svnCmd += tempfile;
\r
1410 svnCmd += _T("\"");
\r
1411 svnCmd += _T(" /deletepathfile");
\r
1413 case ShellMenuSwitch:
\r
1414 svnCmd += _T("switch /path:\"");
\r
1415 if (files_.size() > 0)
\r
1416 svnCmd += files_.front();
\r
1418 svnCmd += folder_;
\r
1419 svnCmd += _T("\"");
\r
1421 case ShellMenuImport:
\r
1422 svnCmd += _T("import /path:\"");
\r
1423 svnCmd += folder_;
\r
1424 svnCmd += _T("\"");
\r
1426 case ShellMenuExport:
\r
1427 svnCmd += _T("export /path:\"");
\r
1428 svnCmd += folder_;
\r
1429 svnCmd += _T("\"");
\r
1431 case ShellMenuAbout:
\r
1432 svnCmd += _T("about");
\r
1434 case ShellMenuCreateRepos:
\r
1435 svnCmd += _T("repocreate /path:\"");
\r
1436 svnCmd += folder_;
\r
1437 svnCmd += _T("\"");
\r
1439 case ShellMenuMerge:
\r
1440 svnCmd += _T("merge /path:\"");
\r
1441 if (files_.size() > 0)
\r
1442 svnCmd += files_.front();
\r
1444 svnCmd += folder_;
\r
1445 svnCmd += _T("\"");
\r
1447 case ShellMenuMergeAll:
\r
1448 svnCmd += _T("mergeall /path:\"");
\r
1449 if (files_.size() > 0)
\r
1450 svnCmd += files_.front();
\r
1452 svnCmd += folder_;
\r
1453 svnCmd += _T("\"");
\r
1455 case ShellMenuCopy:
\r
1456 svnCmd += _T("copy /path:\"");
\r
1457 if (files_.size() > 0)
\r
1458 svnCmd += files_.front();
\r
1460 svnCmd += folder_;
\r
1461 svnCmd += _T("\"");
\r
1463 case ShellMenuSettings:
\r
1464 svnCmd += _T("settings");
\r
1466 case ShellMenuHelp:
\r
1467 svnCmd += _T("help");
\r
1469 case ShellMenuRename:
\r
1470 svnCmd += _T("rename /path:\"");
\r
1471 if (files_.size() > 0)
\r
1472 svnCmd += files_.front();
\r
1474 svnCmd += folder_;
\r
1475 svnCmd += _T("\"");
\r
1477 case ShellMenuRemove:
\r
1478 tempfile = WriteFileListToTempFile();
\r
1479 svnCmd += _T("remove /pathfile:\"");
\r
1480 svnCmd += tempfile;
\r
1481 svnCmd += _T("\"");
\r
1482 svnCmd += _T(" /deletepathfile");
\r
1484 case ShellMenuRemoveKeep:
\r
1485 tempfile = WriteFileListToTempFile();
\r
1486 svnCmd += _T("remove /pathfile:\"");
\r
1487 svnCmd += tempfile;
\r
1488 svnCmd += _T("\"");
\r
1489 svnCmd += _T(" /deletepathfile");
\r
1490 svnCmd += _T(" /keep");
\r
1492 case ShellMenuDiff:
\r
1493 svnCmd += _T("diff /path:\"");
\r
1494 if (files_.size() == 1)
\r
1495 svnCmd += files_.front();
\r
1496 else if (files_.size() == 2)
\r
1498 std::vector<stdstring>::iterator I = files_.begin();
\r
1501 svnCmd += _T("\" /path2:\"");
\r
1505 svnCmd += folder_;
\r
1506 svnCmd += _T("\"");
\r
1507 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1508 svnCmd += _T(" /alternative");
\r
1510 case ShellMenuPrevDiff:
\r
1511 svnCmd += _T("prevdiff /path:\"");
\r
1512 if (files_.size() == 1)
\r
1513 svnCmd += files_.front();
\r
1515 svnCmd += folder_;
\r
1516 svnCmd += _T("\"");
\r
1517 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1518 svnCmd += _T(" /alternative");
\r
1520 case ShellMenuUrlDiff:
\r
1521 svnCmd += _T("urldiff /path:\"");
\r
1522 if (files_.size() == 1)
\r
1523 svnCmd += files_.front();
\r
1525 svnCmd += folder_;
\r
1526 svnCmd += _T("\"");
\r
1528 case ShellMenuDropCopyAdd:
\r
1529 tempfile = WriteFileListToTempFile();
\r
1530 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1531 svnCmd += tempfile;
\r
1532 svnCmd += _T("\"");
\r
1533 svnCmd += _T(" /deletepathfile");
\r
1534 svnCmd += _T(" /droptarget:\"");
\r
1535 svnCmd += folder_;
\r
1536 svnCmd += _T("\"";)
\r
1538 case ShellMenuDropCopy:
\r
1539 tempfile = WriteFileListToTempFile();
\r
1540 svnCmd += _T("dropcopy /pathfile:\"");
\r
1541 svnCmd += tempfile;
\r
1542 svnCmd += _T("\"");
\r
1543 svnCmd += _T(" /deletepathfile");
\r
1544 svnCmd += _T(" /droptarget:\"");
\r
1545 svnCmd += folder_;
\r
1546 svnCmd += _T("\"";)
\r
1548 case ShellMenuDropCopyRename:
\r
1549 tempfile = WriteFileListToTempFile();
\r
1550 svnCmd += _T("dropcopy /pathfile:\"");
\r
1551 svnCmd += tempfile;
\r
1552 svnCmd += _T("\"");
\r
1553 svnCmd += _T(" /deletepathfile");
\r
1554 svnCmd += _T(" /droptarget:\"");
\r
1555 svnCmd += folder_;
\r
1556 svnCmd += _T("\" /rename";)
\r
1558 case ShellMenuDropMove:
\r
1559 tempfile = WriteFileListToTempFile();
\r
1560 svnCmd += _T("dropmove /pathfile:\"");
\r
1561 svnCmd += tempfile;
\r
1562 svnCmd += _T("\"");
\r
1563 svnCmd += _T(" /deletepathfile");
\r
1564 svnCmd += _T(" /droptarget:\"");
\r
1565 svnCmd += folder_;
\r
1566 svnCmd += _T("\"");
\r
1568 case ShellMenuDropMoveRename:
\r
1569 tempfile = WriteFileListToTempFile();
\r
1570 svnCmd += _T("dropmove /pathfile:\"");
\r
1571 svnCmd += tempfile;
\r
1572 svnCmd += _T("\"");
\r
1573 svnCmd += _T(" /deletepathfile");
\r
1574 svnCmd += _T(" /droptarget:\"");
\r
1575 svnCmd += folder_;
\r
1576 svnCmd += _T("\" /rename";)
\r
1578 case ShellMenuDropExport:
\r
1579 tempfile = WriteFileListToTempFile();
\r
1580 svnCmd += _T("dropexport /pathfile:\"");
\r
1581 svnCmd += tempfile;
\r
1582 svnCmd += _T("\"");
\r
1583 svnCmd += _T(" /deletepathfile");
\r
1584 svnCmd += _T(" /droptarget:\"");
\r
1585 svnCmd += folder_;
\r
1586 svnCmd += _T("\"");
\r
1588 case ShellMenuDropExportExtended:
\r
1589 tempfile = WriteFileListToTempFile();
\r
1590 svnCmd += _T("dropexport /pathfile:\"");
\r
1591 svnCmd += tempfile;
\r
1592 svnCmd += _T("\"");
\r
1593 svnCmd += _T(" /deletepathfile");
\r
1594 svnCmd += _T(" /droptarget:\"");
\r
1595 svnCmd += folder_;
\r
1596 svnCmd += _T("\"");
\r
1597 svnCmd += _T(" /extended");
\r
1599 case ShellMenuLog:
\r
1600 svnCmd += _T("log /path:\"");
\r
1601 if (files_.size() > 0)
\r
1602 svnCmd += files_.front();
\r
1604 svnCmd += folder_;
\r
1605 svnCmd += _T("\"");
\r
1607 case ShellMenuConflictEditor:
\r
1608 svnCmd += _T("conflicteditor /path:\"");
\r
1609 if (files_.size() > 0)
\r
1610 svnCmd += files_.front();
\r
1612 svnCmd += folder_;
\r
1613 svnCmd += _T("\"");
\r
1615 case ShellMenuRelocate:
\r
1616 svnCmd += _T("relocate /path:\"");
\r
1617 if (files_.size() > 0)
\r
1618 svnCmd += files_.front();
\r
1620 svnCmd += folder_;
\r
1621 svnCmd += _T("\"");
\r
1623 case ShellMenuShowChanged:
\r
1624 if (files_.size() > 1)
\r
1626 tempfile = WriteFileListToTempFile();
\r
1627 svnCmd += _T("repostatus /pathfile:\"");
\r
1628 svnCmd += tempfile;
\r
1629 svnCmd += _T("\"");
\r
1630 svnCmd += _T(" /deletepathfile");
\r
1634 svnCmd += _T("repostatus /path:\"");
\r
1635 if (files_.size() > 0)
\r
1636 svnCmd += files_.front();
\r
1638 svnCmd += folder_;
\r
1639 svnCmd += _T("\"");
\r
1642 case ShellMenuRepoBrowse:
\r
1643 svnCmd += _T("repobrowser /path:\"");
\r
1644 if (files_.size() > 0)
\r
1645 svnCmd += files_.front();
\r
1647 svnCmd += folder_;
\r
1648 svnCmd += _T("\"");
\r
1650 case ShellMenuBlame:
\r
1651 svnCmd += _T("blame /path:\"");
\r
1652 if (files_.size() > 0)
\r
1653 svnCmd += files_.front();
\r
1655 svnCmd += folder_;
\r
1656 svnCmd += _T("\"");
\r
1658 case ShellMenuCreatePatch:
\r
1659 tempfile = WriteFileListToTempFile();
\r
1660 svnCmd += _T("createpatch /pathfile:\"");
\r
1661 svnCmd += tempfile;
\r
1662 svnCmd += _T("\"");
\r
1663 svnCmd += _T(" /deletepathfile");
\r
1665 case ShellMenuApplyPatch:
\r
1666 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1668 // if there's a patch file in the clipboard, we save it
\r
1669 // to a temporary file and tell TortoiseMerge to use that one
\r
1670 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1671 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1673 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1674 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1676 DWORD len = GetTempPath(0, NULL);
\r
1677 TCHAR * path = new TCHAR[len+1];
\r
1678 TCHAR * tempF = new TCHAR[len+100];
\r
1679 GetTempPath (len+1, path);
\r
1680 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1681 std::wstring sTempFile = std::wstring(tempF);
\r
1686 size_t patchlen = strlen(lpstr);
\r
1687 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1690 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1691 if (size == patchlen)
\r
1693 itemStates |= ITEMIS_PATCHFILE;
\r
1695 files_.push_back(sTempFile);
\r
1699 GlobalUnlock(hglb);
\r
1700 CloseClipboard();
\r
1703 if (itemStates & ITEMIS_PATCHFILE)
\r
1705 svnCmd = _T(" /diff:\"");
\r
1706 if (files_.size() > 0)
\r
1708 svnCmd += files_.front();
\r
1709 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1711 svnCmd += _T("\" /patchpath:\"");
\r
1712 svnCmd += folder_;
\r
1716 svnCmd += folder_;
\r
1717 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1718 svnCmd += _T("\" /wc");
\r
1720 svnCmd += _T("\"");
\r
1724 svnCmd = _T(" /patchpath:\"");
\r
1725 if (files_.size() > 0)
\r
1726 svnCmd += files_.front();
\r
1728 svnCmd += folder_;
\r
1729 svnCmd += _T("\"");
\r
1732 myVerbsIDMap.clear();
\r
1733 myVerbsMap.clear();
\r
1734 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1737 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1738 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1739 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1742 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1743 (LPTSTR) &lpMsgBuf,
\r
1747 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1748 LocalFree( lpMsgBuf );
\r
1750 CloseHandle(process.hThread);
\r
1751 CloseHandle(process.hProcess);
\r
1754 case ShellMenuRevisionGraph:
\r
1755 svnCmd += _T("revisiongraph /path:\"");
\r
1756 if (files_.size() > 0)
\r
1757 svnCmd += files_.front();
\r
1759 svnCmd += folder_;
\r
1760 svnCmd += _T("\"");
\r
1762 case ShellMenuLock:
\r
1763 tempfile = WriteFileListToTempFile();
\r
1764 svnCmd += _T("lock /pathfile:\"");
\r
1765 svnCmd += tempfile;
\r
1766 svnCmd += _T("\"");
\r
1767 svnCmd += _T(" /deletepathfile");
\r
1769 case ShellMenuUnlock:
\r
1770 tempfile = WriteFileListToTempFile();
\r
1771 svnCmd += _T("unlock /pathfile:\"");
\r
1772 svnCmd += tempfile;
\r
1773 svnCmd += _T("\"");
\r
1774 svnCmd += _T(" /deletepathfile");
\r
1776 case ShellMenuUnlockForce:
\r
1777 tempfile = WriteFileListToTempFile();
\r
1778 svnCmd += _T("unlock /pathfile:\"");
\r
1779 svnCmd += tempfile;
\r
1780 svnCmd += _T("\"");
\r
1781 svnCmd += _T(" /deletepathfile");
\r
1782 svnCmd += _T(" /force");
\r
1784 case ShellMenuProperties:
\r
1785 tempfile = WriteFileListToTempFile();
\r
1786 svnCmd += _T("properties /pathfile:\"");
\r
1787 svnCmd += tempfile;
\r
1788 svnCmd += _T("\"");
\r
1789 svnCmd += _T(" /deletepathfile");
\r
1791 case ShellMenuClipPaste:
\r
1792 if (WriteClipboardPathsToTempFile(tempfile))
\r
1794 bool bCopy = true;
\r
1795 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1796 if (cPrefDropFormat)
\r
1798 if (OpenClipboard(lpcmi->hwnd))
\r
1800 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1803 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1804 if (*effect == DROPEFFECT_MOVE)
\r
1806 GlobalUnlock(hglb);
\r
1813 svnCmd += _T("pastecopy /pathfile:\"");
\r
1815 svnCmd += _T("pastemove /pathfile:\"");
\r
1816 svnCmd += tempfile;
\r
1817 svnCmd += _T("\"");
\r
1818 svnCmd += _T(" /deletepathfile");
\r
1819 svnCmd += _T(" /droptarget:\"");
\r
1820 svnCmd += folder_;
\r
1821 svnCmd += _T("\"");
\r
1823 else return NOERROR;
\r
1825 case ShellMenuClone:
\r
1826 svnCmd += _T("clone /path:\"");
\r
1827 svnCmd += folder_;
\r
1828 svnCmd += _T("\"");
\r
1830 case ShellMenuPull:
\r
1831 svnCmd += _T("pull /path:\"");
\r
1832 if (files_.size() > 0)
\r
1833 svnCmd += files_.front();
\r
1835 svnCmd += folder_;
\r
1836 svnCmd += _T("\"");
\r
1838 case ShellMenuPush:
\r
1839 svnCmd += _T("push /path:\"");
\r
1840 if (files_.size() > 0)
\r
1841 svnCmd += files_.front();
\r
1843 svnCmd += folder_;
\r
1844 svnCmd += _T("\"");
\r
1846 case ShellMenuBranch:
\r
1847 svnCmd += _T("branch /path:\"");
\r
1848 if (files_.size() > 0)
\r
1849 svnCmd += files_.front();
\r
1851 svnCmd += folder_;
\r
1852 svnCmd += _T("\"");
\r
1855 case ShellMenuTag:
\r
1856 svnCmd += _T("tag /path:\"");
\r
1857 if (files_.size() > 0)
\r
1858 svnCmd += files_.front();
\r
1860 svnCmd += folder_;
\r
1861 svnCmd += _T("\"");
\r
1864 case ShellMenuFormatPatch:
\r
1865 svnCmd += _T("formatpatch /path:\"");
\r
1866 if (files_.size() > 0)
\r
1867 svnCmd += files_.front();
\r
1869 svnCmd += folder_;
\r
1870 svnCmd += _T("\"");
\r
1873 case ShellMenuImportPatch:
\r
1874 svnCmd += _T("importpatch /path:\"");
\r
1875 if (files_.size() > 0)
\r
1876 svnCmd += files_.front();
\r
1878 svnCmd += folder_;
\r
1879 svnCmd += _T("\"");
\r
1882 case ShellMenuCherryPick:
\r
1883 svnCmd += _T("cherrypick /path:\"");
\r
1884 if (files_.size() > 0)
\r
1885 svnCmd += files_.front();
\r
1887 svnCmd += folder_;
\r
1888 svnCmd += _T("\"");
\r
1890 case ShellMenuFetch:
\r
1891 svnCmd += _T("fetch /path:\"");
\r
1892 if (files_.size() > 0)
\r
1893 svnCmd += files_.front();
\r
1895 svnCmd += folder_;
\r
1896 svnCmd += _T("\"");
\r
1902 } // switch (id_it->second)
\r
1903 svnCmd += _T(" /hwnd:");
\r
1905 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1908 myVerbsIDMap.clear();
\r
1909 myVerbsMap.clear();
\r
1910 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1913 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1914 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1915 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1918 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1919 (LPTSTR) &lpMsgBuf,
\r
1923 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1924 LocalFree( lpMsgBuf );
\r
1926 CloseHandle(process.hThread);
\r
1927 CloseHandle(process.hProcess);
\r
1929 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1930 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1935 // This is for the status bar and things like that:
\r
1936 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1938 UINT FAR * /*reserved*/,
\r
1942 PreserveChdir preserveChdir;
\r
1943 //do we know the id?
\r
1944 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1945 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1947 return E_INVALIDARG; //no, we don't
\r
1951 HRESULT hr = E_INVALIDARG;
\r
1953 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1954 int menuIndex = 0;
\r
1955 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1957 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1959 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1965 const TCHAR * desc = stringtablebuffer;
\r
1968 case GCS_HELPTEXTA:
\r
1970 std::string help = WideToMultibyte(desc);
\r
1971 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1975 case GCS_HELPTEXTW:
\r
1977 wide_string help = desc;
\r
1978 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1984 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1985 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1987 std::string help = WideToMultibyte(verb_id_it->second);
\r
1988 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1995 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1996 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1998 wide_string help = verb_id_it->second;
\r
1999 ATLTRACE("verb : %ws\n", help.c_str());
\r
2000 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2009 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2012 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2015 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2017 PreserveChdir preserveChdir;
\r
2020 if (pResult == NULL)
\r
2027 case WM_MEASUREITEM:
\r
2029 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2032 lpmis->itemWidth += 2;
\r
2033 if (lpmis->itemHeight < 16)
\r
2034 lpmis->itemHeight = 16;
\r
2041 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2042 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2043 return S_OK; //not for a menu
\r
2044 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2045 if (resource == NULL)
\r
2047 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2048 if (hIcon == NULL)
\r
2050 DrawIconEx(lpdis->hDC,
\r
2051 lpdis->rcItem.left - 16,
\r
2052 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2054 0, NULL, DI_NORMAL);
\r
2055 DestroyIcon(hIcon);
\r
2063 if (HIWORD(wParam) != MF_POPUP)
\r
2065 int nChar = LOWORD(wParam);
\r
2066 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2067 nChar = tolower(nChar);
\r
2068 // we have the char the user pressed, now search that char in all our
\r
2070 std::vector<int> accmenus;
\r
2071 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2073 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2074 if (resource == NULL)
\r
2076 szItem = stringtablebuffer;
\r
2077 TCHAR * amp = _tcschr(szItem, '&');
\r
2081 int ampChar = LOWORD(*amp);
\r
2082 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2083 ampChar = tolower(ampChar);
\r
2084 if (ampChar == nChar)
\r
2086 // yep, we found a menu which has the pressed key
\r
2087 // as an accelerator. Add that menu to the list to
\r
2089 accmenus.push_back(It->first);
\r
2092 if (accmenus.size() == 0)
\r
2094 // no menu with that accelerator key.
\r
2095 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2098 if (accmenus.size() == 1)
\r
2100 // Only one menu with that accelerator key. We're lucky!
\r
2101 // So just execute that menu entry.
\r
2102 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2105 if (accmenus.size() > 1)
\r
2107 // we have more than one menu item with this accelerator key!
\r
2109 mif.cbSize = sizeof(MENUITEMINFO);
\r
2110 mif.fMask = MIIM_STATE;
\r
2111 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2113 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2114 if (mif.fState == MFS_HILITE)
\r
2116 // this is the selected item, so select the next one
\r
2118 if (it == accmenus.end())
\r
2119 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2121 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2125 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2136 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2138 TCHAR textbuf[255];
\r
2139 LPCTSTR resource = NULL;
\r
2140 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2143 int menuIndex = 0;
\r
2144 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2146 if (menuInfo[menuIndex].command == id)
\r
2148 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2149 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2152 case ShellMenuLock:
\r
2153 // menu lock is special because it can be set to the top
\r
2154 // with a separate option in the registry
\r
2155 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2156 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2158 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2159 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2160 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2163 // the sub menu entries are special because they're *always* on the top level menu
\r
2164 case ShellSubMenuMultiple:
\r
2165 case ShellSubMenuLink:
\r
2166 case ShellSubMenuFolder:
\r
2167 case ShellSubMenuFile:
\r
2168 case ShellSubMenu:
\r
2172 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2173 if (layout & (menuInfo[menuIndex].menuID))
\r
2175 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2176 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2177 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2188 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2191 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2192 LPITEMIDLIST pidl = NULL;
\r
2193 while (cslidarray[i])
\r
2197 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2199 if (!SHGetPathFromIDList(pidl, buf))
\r
2201 // not a file system path, definitely illegal for our use
\r
2202 CoTaskMemFree(pidl);
\r
2205 CoTaskMemFree(pidl);
\r
2206 if (_tcslen(buf)==0)
\r
2208 if (_tcscmp(buf, folder.c_str())==0)
\r
2214 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2216 HMENU ignoresubmenu = NULL;
\r
2217 int indexignoresub = 0;
\r
2218 bool bShowIgnoreMenu = false;
\r
2219 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2220 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2221 if (files_.size() == 0)
\r
2223 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2225 std::vector<stdstring>::iterator I = files_.begin();
\r
2226 if (_tcsrchr(I->c_str(), '\\'))
\r
2227 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2229 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2230 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2232 // check if the item name is ignored or the mask
\r
2234 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2236 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2237 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2245 ignoresubmenu = CreateMenu();
\r
2246 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2247 stdstring verb = stdstring(ignorepath);
\r
2248 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2249 myVerbsMap[verb] = idCmd;
\r
2250 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2251 myVerbsIDMap[idCmd] = verb;
\r
2252 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2253 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2254 bShowIgnoreMenu = true;
\r
2256 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2257 if (_tcsrchr(ignorepath, '.'))
\r
2259 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2260 p = ignoredprops.find(maskbuf);
\r
2262 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2264 if (ignoresubmenu==NULL)
\r
2265 ignoresubmenu = CreateMenu();
\r
2267 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2268 stdstring verb = stdstring(maskbuf);
\r
2269 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2270 myVerbsMap[verb] = idCmd;
\r
2271 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2272 myVerbsIDMap[idCmd] = verb;
\r
2273 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2274 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2275 bShowIgnoreMenu = true;
\r
2279 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2281 bShowIgnoreMenu = true;
\r
2282 ignoresubmenu = CreateMenu();
\r
2283 if (itemStates & ITEMIS_ONLYONE)
\r
2285 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2286 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2287 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2289 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2290 if (_tcsrchr(ignorepath, '.'))
\r
2292 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2293 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2294 stdstring verb = stdstring(maskbuf);
\r
2295 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2296 myVerbsMap[verb] = idCmd;
\r
2297 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2298 myVerbsIDMap[idCmd] = verb;
\r
2299 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2300 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2305 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2306 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2307 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2308 stdstring verb = stdstring(ignorepath);
\r
2309 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2310 myVerbsMap[verb] = idCmd;
\r
2311 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2312 myVerbsIDMap[idCmd] = verb;
\r
2313 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2314 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2316 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2317 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2318 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2319 verb = stdstring(ignorepath);
\r
2320 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2321 myVerbsMap[verb] = idCmd;
\r
2322 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2323 myVerbsIDMap[idCmd] = verb;
\r
2324 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2325 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2329 if (bShowIgnoreMenu)
\r
2331 MENUITEMINFO menuiteminfo;
\r
2332 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2333 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2334 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2335 menuiteminfo.fType = MFT_STRING;
\r
2336 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2338 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2339 menuiteminfo.hbmpChecked = bmp;
\r
2340 menuiteminfo.hbmpUnchecked = bmp;
\r
2341 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2342 menuiteminfo.wID = idCmd;
\r
2343 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2344 if (itemStates & ITEMIS_IGNORED)
\r
2345 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2347 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2348 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2349 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2351 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2352 if (itemStates & ITEMIS_IGNORED)
\r
2354 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2355 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2359 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2360 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2365 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2367 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2368 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2369 return bitmap_it->second;
\r
2371 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2375 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2379 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2380 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2383 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2384 HBITMAP hBmp = NULL;
\r
2386 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2389 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2391 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2394 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2395 BP_PAINTPARAMS paintParams = {0};
\r
2396 paintParams.cbSize = sizeof(paintParams);
\r
2397 paintParams.dwFlags = BPPF_ERASE;
\r
2398 paintParams.pBlendFunction = &bfAlpha;
\r
2401 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2404 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2406 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2407 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2410 // This will write the buffer contents to the destination bitmap
\r
2411 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2414 SelectObject(hdcDest, hbmpOld);
\r
2418 DeleteDC(hdcDest);
\r
2421 DestroyIcon(hIcon);
\r
2424 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2428 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2433 ZeroMemory(&bmi, sizeof(bmi));
\r
2434 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2435 bmi.bmiHeader.biPlanes = 1;
\r
2436 bmi.bmiHeader.biCompression = BI_RGB;
\r
2438 bmi.bmiHeader.biWidth = psize->cx;
\r
2439 bmi.bmiHeader.biHeight = psize->cy;
\r
2440 bmi.bmiHeader.biBitCount = 32;
\r
2442 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2445 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2446 if (hdc != hdcUsed)
\r
2448 ReleaseDC(NULL, hdcUsed);
\r
2451 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2454 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2456 RGBQUAD *prgbQuad;
\r
2458 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2459 if (SUCCEEDED(hr))
\r
2461 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2462 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2465 if (GetIconInfo(hicon, &info))
\r
2469 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2472 DeleteObject(info.hbmColor);
\r
2473 DeleteObject(info.hbmMask);
\r
2481 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2483 ULONG cxDelta = cxRow - sizImage.cx;
\r
2484 for (ULONG y = sizImage.cy; y; --y)
\r
2486 for (ULONG x = sizImage.cx; x; --x)
\r
2488 if (*pargb++ & 0xFF000000)
\r
2500 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2503 ZeroMemory(&bmi, sizeof(bmi));
\r
2504 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2505 bmi.bmiHeader.biPlanes = 1;
\r
2506 bmi.bmiHeader.biCompression = BI_RGB;
\r
2508 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2509 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2510 bmi.bmiHeader.biBitCount = 32;
\r
2512 HRESULT hr = E_OUTOFMEMORY;
\r
2513 HANDLE hHeap = GetProcessHeap();
\r
2514 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2517 hr = E_UNEXPECTED;
\r
2518 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2520 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2521 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2523 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2525 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2529 // transparent pixel
\r
2535 *pargb++ |= 0xFF000000;
\r
2545 HeapFree(hHeap, 0, pvBits);
\r