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
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 ( askedpath.IsDirectory() )//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_FOLDERINSVN;
\r
317 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
319 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
320 // itemStates |= ITEMIS_NEEDSLOCK;
\r
322 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
323 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
327 // sometimes, git_client_status() returns with an error.
\r
328 // in that case, we have to check if the working copy is versioned
\r
329 // anyway to show the 'correct' context menu
\r
330 if (askedpath.HasAdminDir())
\r
331 status = git_wc_status_normal;
\r
336 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
339 if ( askedpath.IsDirectory() )
\r
341 if (askedpath.HasAdminDir())
\r
342 itemStates |= ITEMIS_INSVN;
\r
344 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
345 //if (askedpath.HasAdminDir())
\r
346 itemStates |= ITEMIS_INSVN;
\r
347 if (status == git_wc_status_ignored)
\r
348 itemStates |= ITEMIS_IGNORED;
\r
349 if (status == git_wc_status_normal)
\r
350 itemStates |= ITEMIS_NORMAL;
\r
351 if (status == git_wc_status_conflicted)
\r
352 itemStates |= ITEMIS_CONFLICTED;
\r
353 if (status == git_wc_status_added)
\r
354 itemStates |= ITEMIS_ADDED;
\r
355 if (status == git_wc_status_deleted)
\r
356 itemStates |= ITEMIS_DELETED;
\r
359 } // for (int i = 0; i < count; i++)
\r
360 GlobalUnlock ( drop );
\r
361 ReleaseStgMedium ( &stg );
\r
363 } // if (m_State == FileStateDropHandler)
\r
367 //Enumerate PIDLs which the user has selected
\r
368 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
369 ItemIDList parent( GetPIDLFolder (cida));
\r
371 int count = cida->cidl;
\r
372 BOOL statfetched = FALSE;
\r
373 for (int i = 0; i < count; ++i)
\r
375 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
376 stdstring str = child.toString();
\r
377 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
379 //check if our menu is requested for a subversion admin directory
\r
380 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
383 files_.push_back(str);
\r
385 strpath.SetFromWin(str.c_str());
\r
386 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
387 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
390 //get the Subversion status of the item
\r
391 git_wc_status_kind status = git_wc_status_none;
\r
392 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
394 if (strpath.HasAdminDir())
\r
395 status = git_wc_status_normal;
\r
402 if (strpath.HasAdminDir())
\r
403 stat.GetStatus(strpath, false, true, true);
\r
407 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
408 fetchedstatus = status;
\r
409 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
410 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
411 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
413 itemStates |= ITEMIS_FOLDER;
\r
414 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
415 itemStates |= ITEMIS_FOLDERINSVN;
\r
417 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
\r
418 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
419 itemStates |= ITEMIS_CONFLICTED;
\r
420 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
422 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
423 // itemStates |= ITEMIS_NEEDSLOCK;
\r
425 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
426 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
430 // sometimes, git_client_status() returns with an error.
\r
431 // in that case, we have to check if the working copy is versioned
\r
432 // anyway to show the 'correct' context menu
\r
433 if (strpath.HasAdminDir())
\r
435 status = git_wc_status_normal;
\r
436 fetchedstatus = status;
\r
439 statfetched = TRUE;
\r
443 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
447 if ( strpath.IsDirectory() )
\r
449 if (strpath.HasAdminDir())
\r
450 itemStates |= ITEMIS_INSVN;
\r
452 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
453 //if (strpath.HasAdminDir())
\r
454 itemStates |= ITEMIS_INSVN;
\r
455 if (status == git_wc_status_ignored)
\r
457 itemStates |= ITEMIS_IGNORED;
\r
458 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
459 // offer a 'remove from ignored list' entry
\r
460 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
461 // ignoredprops.empty();
\r
462 // for (int p=0; p<props.GetCount(); ++p)
\r
464 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
466 // std::string st = props.GetItemValue(p);
\r
467 // ignoredprops = MultibyteToWide(st.c_str());
\r
468 // // remove all escape chars ('\\')
\r
469 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
474 if (status == git_wc_status_normal)
\r
475 itemStates |= ITEMIS_NORMAL;
\r
476 if (status == git_wc_status_conflicted)
\r
477 itemStates |= ITEMIS_CONFLICTED;
\r
478 if (status == git_wc_status_added)
\r
479 itemStates |= ITEMIS_ADDED;
\r
480 if (status == git_wc_status_deleted)
\r
481 itemStates |= ITEMIS_DELETED;
\r
484 } // for (int i = 0; i < count; ++i)
\r
485 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
486 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
487 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
488 GlobalUnlock(medium.hGlobal);
\r
490 // if the item is a versioned folder, check if there's a patch file
\r
491 // in the clipboard to be used in "Apply Patch"
\r
492 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
495 if (IsClipboardFormatAvailable(cFormatDiff))
\r
496 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
498 if (IsClipboardFormatAvailable(CF_HDROP))
\r
499 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
503 ReleaseStgMedium ( &medium );
\r
504 if (medium.pUnkForRelease)
\r
506 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
507 relInterface->Release();
\r
512 // get folder background
\r
516 ItemIDList list(pIDFolder);
\r
517 folder_ = list.toString();
\r
518 git_wc_status_kind status = git_wc_status_none;
\r
519 if (IsClipboardFormatAvailable(CF_HDROP))
\r
520 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
522 CTGitPath askedpath;
\r
523 askedpath.SetFromWin(folder_.c_str());
\r
525 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
531 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
534 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
535 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
536 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
537 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
539 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
540 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
542 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
543 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
548 // sometimes, git_client_status() returns with an error.
\r
549 // in that case, we have to check if the working copy is versioned
\r
550 // anyway to show the 'correct' context menu
\r
551 if (askedpath.HasAdminDir())
\r
552 status = git_wc_status_normal;
\r
555 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
556 if (askedpath.HasAdminDir())
\r
557 itemStatesFolder |= ITEMIS_INSVN;
\r
558 if (status == git_wc_status_normal)
\r
559 itemStatesFolder |= ITEMIS_NORMAL;
\r
560 if (status == git_wc_status_conflicted)
\r
561 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
562 if (status == git_wc_status_added)
\r
563 itemStatesFolder |= ITEMIS_ADDED;
\r
564 if (status == git_wc_status_deleted)
\r
565 itemStatesFolder |= ITEMIS_DELETED;
\r
570 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
575 status = fetchedstatus;
\r
577 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
578 if (askedpath.HasAdminDir())
\r
580 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
582 if (status == git_wc_status_ignored)
\r
583 itemStatesFolder |= ITEMIS_IGNORED;
\r
584 itemStatesFolder |= ITEMIS_FOLDER;
\r
585 if (files_.size() == 0)
\r
586 itemStates |= ITEMIS_ONLYONE;
\r
587 if (m_State != FileStateDropHandler)
\r
588 itemStates |= itemStatesFolder;
\r
591 if (files_.size() == 2)
\r
592 itemStates |= ITEMIS_TWO;
\r
593 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
596 itemStates |= ITEMIS_ONLYONE;
\r
597 if (m_State != FileStateDropHandler)
\r
599 if (PathIsDirectory(files_.front().c_str()))
\r
601 folder_ = files_.front();
\r
602 git_wc_status_kind status = git_wc_status_none;
\r
603 CTGitPath askedpath;
\r
604 askedpath.SetFromWin(folder_.c_str());
\r
606 if (folder_.compare(statuspath)!=0)
\r
611 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
614 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
615 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
616 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
617 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
619 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
620 // itemStates |= ITEMIS_NEEDSLOCK;
\r
622 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
623 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
628 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
633 status = fetchedstatus;
\r
635 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
636 if (askedpath.HasAdminDir())
\r
637 itemStates |= ITEMIS_FOLDERINSVN;
\r
638 if (status == git_wc_status_ignored)
\r
639 itemStates |= ITEMIS_IGNORED;
\r
640 itemStates |= ITEMIS_FOLDER;
\r
641 if (status == git_wc_status_added)
\r
642 itemStates |= ITEMIS_ADDED;
\r
643 if (status == git_wc_status_deleted)
\r
644 itemStates |= ITEMIS_DELETED;
\r
653 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
655 TCHAR menutextbuffer[255] = {0};
\r
656 TCHAR verbsbuffer[255] = {0};
\r
657 MAKESTRING(stringid);
\r
661 //menu entry for the top context menu, so append an "Git " before
\r
662 //the menu text to indicate where the entry comes from
\r
663 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
665 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
666 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
668 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
669 if (fullver >= 0x500)
\r
671 // on win2k, the context menu does not work properly if we use
\r
672 // icon bitmaps. At least the menu text is empty in the context menu
\r
673 // for folder backgrounds (seems like a win2k bug).
\r
674 HBITMAP bmp = IconToBitmap(icon);
\r
675 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
680 MENUITEMINFO menuiteminfo = {0};
\r
681 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
682 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;
\r
683 menuiteminfo.fType = MFT_STRING;
\r
684 menuiteminfo.dwTypeData = menutextbuffer;
\r
686 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
687 menuiteminfo.wID = id;
\r
688 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
693 //menu entry for the top context menu, so append an "Git " before
\r
694 //the menu text to indicate where the entry comes from
\r
695 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
697 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
698 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
699 stdstring verb = stdstring(menutextbuffer);
\r
700 if (verb.find('&') != -1)
\r
702 verb.erase(verb.find('&'),1);
\r
704 myVerbsMap[verb] = id - idCmdFirst;
\r
705 myVerbsMap[verb] = id;
\r
706 myVerbsIDMap[id - idCmdFirst] = verb;
\r
707 myVerbsIDMap[id] = verb;
\r
708 // We store the relative and absolute diameter
\r
709 // (drawitem callback uses absolute, others relative)
\r
710 myIDMap[id - idCmdFirst] = com;
\r
713 mySubMenuMap[pos] = com;
\r
716 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
718 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
719 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
720 return bitmap_it->second;
\r
722 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
728 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
729 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
731 rect.left = rect.top = 0;
\r
733 HWND desktop = ::GetDesktopWindow();
\r
734 if (desktop == NULL)
\r
736 DestroyIcon(hIcon);
\r
740 HDC screen_dev = ::GetDC(desktop);
\r
741 if (screen_dev == NULL)
\r
743 DestroyIcon(hIcon);
\r
747 // Create a compatible DC
\r
748 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
749 if (dst_hdc == NULL)
\r
751 DestroyIcon(hIcon);
\r
752 ::ReleaseDC(desktop, screen_dev);
\r
756 // Create a new bitmap of icon size
\r
757 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
760 DestroyIcon(hIcon);
\r
761 ::DeleteDC(dst_hdc);
\r
762 ::ReleaseDC(desktop, screen_dev);
\r
766 // Select it into the compatible DC
\r
767 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
768 if (old_dst_bmp == NULL)
\r
770 DestroyIcon(hIcon);
\r
774 // Fill the background of the compatible DC with the white color
\r
775 // that is taken by menu routines as transparent
\r
776 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
777 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
779 // Draw the icon into the compatible DC
\r
780 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
782 // Restore settings
\r
783 ::SelectObject(dst_hdc, old_dst_bmp);
\r
784 ::DeleteDC(dst_hdc);
\r
785 ::ReleaseDC(desktop, screen_dev);
\r
786 DestroyIcon(hIcon);
\r
788 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
792 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
795 tempfile = stdstring();
\r
796 //write all selected files and paths to a temporary file
\r
797 //for TortoiseProc.exe to read out again.
\r
799 DWORD pathlength = GetTempPath(0, NULL);
\r
800 TCHAR * path = new TCHAR[pathlength+1];
\r
801 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
802 GetTempPath (pathlength+1, path);
\r
803 GetTempFileName (path, _T("git"), 0, tempFile);
\r
804 tempfile = stdstring(tempFile);
\r
806 HANDLE file = ::CreateFile (tempFile,
\r
811 FILE_ATTRIBUTE_TEMPORARY,
\r
815 delete [] tempFile;
\r
816 if (file == INVALID_HANDLE_VALUE)
\r
819 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
821 if (!OpenClipboard(NULL))
\r
824 stdstring sClipboardText;
\r
825 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
826 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
829 TCHAR szFileName[MAX_PATH];
\r
830 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
831 for(UINT i = 0; i < cFiles; ++i)
\r
833 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
834 stdstring filename = szFileName;
\r
835 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
836 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
838 GlobalUnlock(hDrop);
\r
841 GlobalUnlock(hglb);
\r
844 ::CloseHandle(file);
\r
849 stdstring CShellExt::WriteFileListToTempFile()
\r
851 //write all selected files and paths to a temporary file
\r
852 //for TortoiseProc.exe to read out again.
\r
853 DWORD pathlength = GetTempPath(0, NULL);
\r
854 TCHAR * path = new TCHAR[pathlength+1];
\r
855 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
856 GetTempPath (pathlength+1, path);
\r
857 GetTempFileName (path, _T("git"), 0, tempFile);
\r
858 stdstring retFilePath = stdstring(tempFile);
\r
860 HANDLE file = ::CreateFile (tempFile,
\r
865 FILE_ATTRIBUTE_TEMPORARY,
\r
869 delete [] tempFile;
\r
870 if (file == INVALID_HANDLE_VALUE)
\r
871 return stdstring();
\r
874 if (files_.empty())
\r
876 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
877 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
880 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
882 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
883 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
885 ::CloseHandle(file);
\r
886 return retFilePath;
\r
889 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
891 PreserveChdir preserveChdir;
\r
894 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
895 return NOERROR; //we don't change the default action
\r
897 if ((files_.size() == 0)||(folder_.size() == 0))
\r
900 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
903 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
905 //the drop handler only has eight commands, but not all are visible at the same time:
\r
906 //if the source file(s) are under version control then those files can be moved
\r
907 //to the new location or they can be moved with a rename,
\r
908 //if they are unversioned then they can be added to the working copy
\r
909 //if they are versioned, they also can be exported to an unversioned location
\r
910 UINT idCmd = idCmdFirst;
\r
913 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
914 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
915 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
917 // Git move and rename here
\r
918 // 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
919 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
920 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
923 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
924 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
925 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
927 // Git copy and rename here, source and target from same repository
\r
928 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
929 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
930 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
933 // available if target is versioned and source is either unversioned or from another repository
\r
934 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
935 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
938 // available if source is versioned and a folder
\r
939 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
940 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
942 // Git export all here
\r
943 // available if source is versioned and a folder
\r
944 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
945 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
948 // available if source is a patchfile
\r
949 if (itemStates & ITEMIS_PATCHFILE)
\r
950 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
953 if (idCmd != idCmdFirst)
\r
954 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
956 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
959 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
962 UINT /*idCmdLast*/,
\r
965 ATLTRACE("Shell :: QueryContextMenu\n");
\r
966 PreserveChdir preserveChdir;
\r
968 //first check if our drop handler is called
\r
969 //and then (if true) provide the context menu for the
\r
971 if (m_State == FileStateDropHandler)
\r
973 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
976 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
977 return NOERROR; //we don't change the default action
\r
979 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
982 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
985 int csidlarray[] =
\r
989 CSIDL_COMMON_FAVORITES,
\r
990 CSIDL_COMMON_STARTMENU,
\r
991 CSIDL_COMPUTERSNEARME,
\r
999 CSIDL_INTERNET_CACHE,
\r
1009 if (IsIllegalFolder(folder_, csidlarray))
\r
1012 if (folder_.empty())
\r
1014 // folder is empty, but maybe files are selected
\r
1015 if (files_.size() == 0)
\r
1016 return NOERROR; // nothing selected - we don't have a menu to show
\r
1017 // check whether a selected entry is an UID - those are namespace extensions
\r
1018 // which we can't handle
\r
1019 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1021 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1026 //check if our menu is requested for a subversion admin directory
\r
1027 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1030 if (uFlags & CMF_EXTENDEDVERBS)
\r
1031 itemStates |= ITEMIS_EXTENDED;
\r
1033 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1034 if ( bShortcut && (files_.size()==1))
\r
1036 // Don't show the context menu for a link if the
\r
1037 // destination is not part of a working copy.
\r
1038 // It would only show the standard menu items
\r
1039 // which are already shown for the lnk-file.
\r
1040 CString path = files_.front().c_str();
\r
1041 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1047 //check if we already added our menu entry for a folder.
\r
1048 //we check that by iterating through all menu entries and check if
\r
1049 //the dwItemData member points to our global ID string. That string is set
\r
1050 //by our shell extension when the folder menu is inserted.
\r
1051 TCHAR menubuf[MAX_PATH];
\r
1052 int count = GetMenuItemCount(hMenu);
\r
1053 for (int i=0; i<count; ++i)
\r
1055 MENUITEMINFO miif;
\r
1056 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1057 miif.cbSize = sizeof(MENUITEMINFO);
\r
1058 miif.fMask = MIIM_DATA;
\r
1059 miif.dwTypeData = menubuf;
\r
1060 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1061 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1062 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1067 UINT idCmd = idCmdFirst;
\r
1069 //create the sub menu
\r
1070 HMENU subMenu = CreateMenu();
\r
1071 int indexSubMenu = 0;
\r
1073 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1074 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1076 int menuIndex = 0;
\r
1077 bool bAddSeparator = false;
\r
1078 bool bMenuEntryAdded = false;
\r
1079 bool bMenuEmpty = true;
\r
1080 // insert separator at start
\r
1081 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1082 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1083 // ?? TortoiseSVN had this as (fullver <= 0x0500) this disabled icons in win2k, but icons work fine in win2k
\r
1084 if (fullver < 0x0500)
\r
1085 bShowIcons = false;
\r
1086 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1088 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1090 // we don't add a separator immediately. Because there might not be
\r
1091 // another 'normal' menu entry after we insert a separator.
\r
1092 // we simply set a flag here, indicating that before the next
\r
1093 // 'normal' menu entry, a separator should be added.
\r
1095 bAddSeparator = true;
\r
1099 // check the conditions whether to show the menu entry or not
\r
1100 bool bInsertMenu = false;
\r
1102 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1104 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1106 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1107 bInsertMenu = true;
\r
1109 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1110 bInsertMenu = true;
\r
1111 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1112 bInsertMenu = true;
\r
1114 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1116 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1118 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1119 bInsertMenu = true;
\r
1121 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1122 bInsertMenu = true;
\r
1123 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1124 bInsertMenu = true;
\r
1126 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1128 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1130 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1131 bInsertMenu = true;
\r
1133 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1134 bInsertMenu = true;
\r
1135 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1136 bInsertMenu = true;
\r
1138 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1140 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1142 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1143 bInsertMenu = true;
\r
1145 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1146 bInsertMenu = true;
\r
1147 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1148 bInsertMenu = true;
\r
1150 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1154 // insert a separator
\r
1155 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1157 bAddSeparator = false;
\r
1158 bMenuEntryAdded = false;
\r
1159 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1163 // handle special cases (sub menus)
\r
1164 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1166 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);
\r
1167 bMenuEntryAdded = true;
\r
1168 bMenuEmpty = false;
\r
1172 // the 'get lock' command is special
\r
1173 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1174 if (menuInfo[menuIndex].command == ShellMenuLock)
\r
1176 if ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())
\r
1179 // insert the menu entry
\r
1180 InsertGitMenu( bIsTop,
\r
1181 bIsTop ? hMenu : subMenu,
\r
1182 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1184 menuInfo[menuIndex].menuTextID,
\r
1185 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1187 menuInfo[menuIndex].command,
\r
1191 bMenuEntryAdded = true;
\r
1192 bMenuEmpty = false;
\r
1201 //add sub menu to main context menu
\r
1202 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1203 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1204 MAKESTRING(IDS_MENUSUBMENU);
\r
1205 MENUITEMINFO menuiteminfo;
\r
1206 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1207 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1208 menuiteminfo.fType = MFT_STRING;
\r
1209 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1211 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1212 if (folder_.size())
\r
1214 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1215 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1216 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1217 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1219 else if (!bShortcut && (files_.size()==1))
\r
1221 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1222 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1223 myIDMap[idCmd] = ShellSubMenuFile;
\r
1225 else if (bShortcut && (files_.size()==1))
\r
1227 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1228 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1229 myIDMap[idCmd] = ShellSubMenuLink;
\r
1231 else if (files_.size() > 1)
\r
1233 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1234 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1235 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1239 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1240 myIDMap[idCmd] = ShellSubMenu;
\r
1242 HBITMAP bmp = NULL;
\r
1243 if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))
\r
1245 bmp = IconToBitmap(uIcon);
\r
1246 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
\r
1250 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
1252 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1254 menuiteminfo.hbmpChecked = bmp;
\r
1255 menuiteminfo.hbmpUnchecked = bmp;
\r
1256 menuiteminfo.hSubMenu = subMenu;
\r
1257 menuiteminfo.wID = idCmd++;
\r
1258 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1261 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1263 //return number of menu items added
\r
1264 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1268 // This is called when you invoke a command on the menu:
\r
1269 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1271 PreserveChdir preserveChdir;
\r
1272 HRESULT hr = E_INVALIDARG;
\r
1273 if (lpcmi == NULL)
\r
1276 std::string command;
\r
1277 std::string parent;
\r
1280 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1282 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1284 if (HIWORD(lpcmi->lpVerb))
\r
1286 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1287 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1288 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1289 idCmd = verb_it->second;
\r
1294 // See if we have a handler interface for this id
\r
1295 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1296 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1298 STARTUPINFO startup;
\r
1299 PROCESS_INFORMATION process;
\r
1300 memset(&startup, 0, sizeof(startup));
\r
1301 startup.cb = sizeof(startup);
\r
1302 memset(&process, 0, sizeof(process));
\r
1303 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1304 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1306 //TortoiseProc expects a command line of the form:
\r
1307 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1309 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1311 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1312 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1313 stdstring svnCmd = _T(" /command:");
\r
1314 stdstring tempfile;
\r
1315 switch (id_it->second)
\r
1318 case ShellMenuCheckout:
\r
1319 svnCmd += _T("checkout /path:\"");
\r
1320 svnCmd += folder_;
\r
1321 svnCmd += _T("\"");
\r
1323 case ShellMenuUpdate:
\r
1324 tempfile = WriteFileListToTempFile();
\r
1325 svnCmd += _T("update /pathfile:\"");
\r
1326 svnCmd += tempfile;
\r
1327 svnCmd += _T("\"");
\r
1328 svnCmd += _T(" /deletepathfile");
\r
1330 case ShellMenuUpdateExt:
\r
1331 tempfile = WriteFileListToTempFile();
\r
1332 svnCmd += _T("update /pathfile:\"");
\r
1333 svnCmd += tempfile;
\r
1334 svnCmd += _T("\"");
\r
1335 svnCmd += _T(" /deletepathfile");
\r
1336 svnCmd += _T(" /rev");
\r
1338 case ShellMenuCommit:
\r
1339 tempfile = WriteFileListToTempFile();
\r
1340 svnCmd += _T("commit /pathfile:\"");
\r
1341 svnCmd += tempfile;
\r
1342 svnCmd += _T("\"");
\r
1343 svnCmd += _T(" /deletepathfile");
\r
1345 case ShellMenuAdd:
\r
1346 case ShellMenuAddAsReplacement:
\r
1347 tempfile = WriteFileListToTempFile();
\r
1348 svnCmd += _T("add /pathfile:\"");
\r
1349 svnCmd += tempfile;
\r
1350 svnCmd += _T("\"");
\r
1351 svnCmd += _T(" /deletepathfile");
\r
1353 case ShellMenuIgnore:
\r
1354 tempfile = WriteFileListToTempFile();
\r
1355 svnCmd += _T("ignore /pathfile:\"");
\r
1356 svnCmd += tempfile;
\r
1357 svnCmd += _T("\"");
\r
1358 svnCmd += _T(" /deletepathfile");
\r
1360 case ShellMenuIgnoreCaseSensitive:
\r
1361 tempfile = WriteFileListToTempFile();
\r
1362 svnCmd += _T("ignore /pathfile:\"");
\r
1363 svnCmd += tempfile;
\r
1364 svnCmd += _T("\"");
\r
1365 svnCmd += _T(" /deletepathfile");
\r
1366 svnCmd += _T(" /onlymask");
\r
1368 case ShellMenuUnIgnore:
\r
1369 tempfile = WriteFileListToTempFile();
\r
1370 svnCmd += _T("unignore /pathfile:\"");
\r
1371 svnCmd += tempfile;
\r
1372 svnCmd += _T("\"");
\r
1373 svnCmd += _T(" /deletepathfile");
\r
1375 case ShellMenuUnIgnoreCaseSensitive:
\r
1376 tempfile = WriteFileListToTempFile();
\r
1377 svnCmd += _T("unignore /pathfile:\"");
\r
1378 svnCmd += tempfile;
\r
1379 svnCmd += _T("\"");
\r
1380 svnCmd += _T(" /deletepathfile");
\r
1381 svnCmd += _T(" /onlymask");
\r
1383 case ShellMenuRevert:
\r
1384 tempfile = WriteFileListToTempFile();
\r
1385 svnCmd += _T("revert /pathfile:\"");
\r
1386 svnCmd += tempfile;
\r
1387 svnCmd += _T("\"");
\r
1388 svnCmd += _T(" /deletepathfile");
\r
1390 case ShellMenuDelUnversioned:
\r
1391 svnCmd += _T("delunversioned /path:\"");
\r
1392 svnCmd += folder_;
\r
1393 svnCmd += _T("\"");
\r
1395 case ShellMenuCleanup:
\r
1396 tempfile = WriteFileListToTempFile();
\r
1397 svnCmd += _T("cleanup /pathfile:\"");
\r
1398 svnCmd += tempfile;
\r
1399 svnCmd += _T("\"");
\r
1400 svnCmd += _T(" /deletepathfile");
\r
1402 case ShellMenuResolve:
\r
1403 tempfile = WriteFileListToTempFile();
\r
1404 svnCmd += _T("resolve /pathfile:\"");
\r
1405 svnCmd += tempfile;
\r
1406 svnCmd += _T("\"");
\r
1407 svnCmd += _T(" /deletepathfile");
\r
1409 case ShellMenuSwitch:
\r
1410 svnCmd += _T("switch /path:\"");
\r
1411 if (files_.size() > 0)
\r
1412 svnCmd += files_.front();
\r
1414 svnCmd += folder_;
\r
1415 svnCmd += _T("\"");
\r
1417 case ShellMenuImport:
\r
1418 svnCmd += _T("import /path:\"");
\r
1419 svnCmd += folder_;
\r
1420 svnCmd += _T("\"");
\r
1422 case ShellMenuExport:
\r
1423 svnCmd += _T("export /path:\"");
\r
1424 svnCmd += folder_;
\r
1425 svnCmd += _T("\"");
\r
1427 case ShellMenuAbout:
\r
1428 svnCmd += _T("about");
\r
1430 case ShellMenuCreateRepos:
\r
1431 svnCmd += _T("repocreate /path:\"");
\r
1432 svnCmd += folder_;
\r
1433 svnCmd += _T("\"");
\r
1435 case ShellMenuMerge:
\r
1436 svnCmd += _T("merge /path:\"");
\r
1437 if (files_.size() > 0)
\r
1438 svnCmd += files_.front();
\r
1440 svnCmd += folder_;
\r
1441 svnCmd += _T("\"");
\r
1443 case ShellMenuMergeAll:
\r
1444 svnCmd += _T("mergeall /path:\"");
\r
1445 if (files_.size() > 0)
\r
1446 svnCmd += files_.front();
\r
1448 svnCmd += folder_;
\r
1449 svnCmd += _T("\"");
\r
1451 case ShellMenuCopy:
\r
1452 svnCmd += _T("copy /path:\"");
\r
1453 if (files_.size() > 0)
\r
1454 svnCmd += files_.front();
\r
1456 svnCmd += folder_;
\r
1457 svnCmd += _T("\"");
\r
1459 case ShellMenuSettings:
\r
1460 svnCmd += _T("settings");
\r
1462 case ShellMenuHelp:
\r
1463 svnCmd += _T("help");
\r
1465 case ShellMenuRename:
\r
1466 svnCmd += _T("rename /path:\"");
\r
1467 if (files_.size() > 0)
\r
1468 svnCmd += files_.front();
\r
1470 svnCmd += folder_;
\r
1471 svnCmd += _T("\"");
\r
1473 case ShellMenuRemove:
\r
1474 tempfile = WriteFileListToTempFile();
\r
1475 svnCmd += _T("remove /pathfile:\"");
\r
1476 svnCmd += tempfile;
\r
1477 svnCmd += _T("\"");
\r
1478 svnCmd += _T(" /deletepathfile");
\r
1480 case ShellMenuRemoveKeep:
\r
1481 tempfile = WriteFileListToTempFile();
\r
1482 svnCmd += _T("remove /pathfile:\"");
\r
1483 svnCmd += tempfile;
\r
1484 svnCmd += _T("\"");
\r
1485 svnCmd += _T(" /deletepathfile");
\r
1486 svnCmd += _T(" /keep");
\r
1488 case ShellMenuDiff:
\r
1489 svnCmd += _T("diff /path:\"");
\r
1490 if (files_.size() == 1)
\r
1491 svnCmd += files_.front();
\r
1492 else if (files_.size() == 2)
\r
1494 std::vector<stdstring>::iterator I = files_.begin();
\r
1497 svnCmd += _T("\" /path2:\"");
\r
1501 svnCmd += folder_;
\r
1502 svnCmd += _T("\"");
\r
1503 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1504 svnCmd += _T(" /alternative");
\r
1506 case ShellMenuPrevDiff:
\r
1507 svnCmd += _T("prevdiff /path:\"");
\r
1508 if (files_.size() == 1)
\r
1509 svnCmd += files_.front();
\r
1511 svnCmd += folder_;
\r
1512 svnCmd += _T("\"");
\r
1513 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1514 svnCmd += _T(" /alternative");
\r
1516 case ShellMenuUrlDiff:
\r
1517 svnCmd += _T("urldiff /path:\"");
\r
1518 if (files_.size() == 1)
\r
1519 svnCmd += files_.front();
\r
1521 svnCmd += folder_;
\r
1522 svnCmd += _T("\"");
\r
1524 case ShellMenuDropCopyAdd:
\r
1525 tempfile = WriteFileListToTempFile();
\r
1526 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1527 svnCmd += tempfile;
\r
1528 svnCmd += _T("\"");
\r
1529 svnCmd += _T(" /deletepathfile");
\r
1530 svnCmd += _T(" /droptarget:\"");
\r
1531 svnCmd += folder_;
\r
1532 svnCmd += _T("\"";)
\r
1534 case ShellMenuDropCopy:
\r
1535 tempfile = WriteFileListToTempFile();
\r
1536 svnCmd += _T("dropcopy /pathfile:\"");
\r
1537 svnCmd += tempfile;
\r
1538 svnCmd += _T("\"");
\r
1539 svnCmd += _T(" /deletepathfile");
\r
1540 svnCmd += _T(" /droptarget:\"");
\r
1541 svnCmd += folder_;
\r
1542 svnCmd += _T("\"";)
\r
1544 case ShellMenuDropCopyRename:
\r
1545 tempfile = WriteFileListToTempFile();
\r
1546 svnCmd += _T("dropcopy /pathfile:\"");
\r
1547 svnCmd += tempfile;
\r
1548 svnCmd += _T("\"");
\r
1549 svnCmd += _T(" /deletepathfile");
\r
1550 svnCmd += _T(" /droptarget:\"");
\r
1551 svnCmd += folder_;
\r
1552 svnCmd += _T("\" /rename";)
\r
1554 case ShellMenuDropMove:
\r
1555 tempfile = WriteFileListToTempFile();
\r
1556 svnCmd += _T("dropmove /pathfile:\"");
\r
1557 svnCmd += tempfile;
\r
1558 svnCmd += _T("\"");
\r
1559 svnCmd += _T(" /deletepathfile");
\r
1560 svnCmd += _T(" /droptarget:\"");
\r
1561 svnCmd += folder_;
\r
1562 svnCmd += _T("\"");
\r
1564 case ShellMenuDropMoveRename:
\r
1565 tempfile = WriteFileListToTempFile();
\r
1566 svnCmd += _T("dropmove /pathfile:\"");
\r
1567 svnCmd += tempfile;
\r
1568 svnCmd += _T("\"");
\r
1569 svnCmd += _T(" /deletepathfile");
\r
1570 svnCmd += _T(" /droptarget:\"");
\r
1571 svnCmd += folder_;
\r
1572 svnCmd += _T("\" /rename";)
\r
1574 case ShellMenuDropExport:
\r
1575 tempfile = WriteFileListToTempFile();
\r
1576 svnCmd += _T("dropexport /pathfile:\"");
\r
1577 svnCmd += tempfile;
\r
1578 svnCmd += _T("\"");
\r
1579 svnCmd += _T(" /deletepathfile");
\r
1580 svnCmd += _T(" /droptarget:\"");
\r
1581 svnCmd += folder_;
\r
1582 svnCmd += _T("\"");
\r
1584 case ShellMenuDropExportExtended:
\r
1585 tempfile = WriteFileListToTempFile();
\r
1586 svnCmd += _T("dropexport /pathfile:\"");
\r
1587 svnCmd += tempfile;
\r
1588 svnCmd += _T("\"");
\r
1589 svnCmd += _T(" /deletepathfile");
\r
1590 svnCmd += _T(" /droptarget:\"");
\r
1591 svnCmd += folder_;
\r
1592 svnCmd += _T("\"");
\r
1593 svnCmd += _T(" /extended");
\r
1595 case ShellMenuLog:
\r
1596 svnCmd += _T("log /path:\"");
\r
1597 if (files_.size() > 0)
\r
1598 svnCmd += files_.front();
\r
1600 svnCmd += folder_;
\r
1601 svnCmd += _T("\"");
\r
1603 case ShellMenuConflictEditor:
\r
1604 svnCmd += _T("conflicteditor /path:\"");
\r
1605 if (files_.size() > 0)
\r
1606 svnCmd += files_.front();
\r
1608 svnCmd += folder_;
\r
1609 svnCmd += _T("\"");
\r
1611 case ShellMenuRelocate:
\r
1612 svnCmd += _T("relocate /path:\"");
\r
1613 if (files_.size() > 0)
\r
1614 svnCmd += files_.front();
\r
1616 svnCmd += folder_;
\r
1617 svnCmd += _T("\"");
\r
1619 case ShellMenuShowChanged:
\r
1620 if (files_.size() > 1)
\r
1622 tempfile = WriteFileListToTempFile();
\r
1623 svnCmd += _T("repostatus /pathfile:\"");
\r
1624 svnCmd += tempfile;
\r
1625 svnCmd += _T("\"");
\r
1626 svnCmd += _T(" /deletepathfile");
\r
1630 svnCmd += _T("repostatus /path:\"");
\r
1631 if (files_.size() > 0)
\r
1632 svnCmd += files_.front();
\r
1634 svnCmd += folder_;
\r
1635 svnCmd += _T("\"");
\r
1638 case ShellMenuRepoBrowse:
\r
1639 svnCmd += _T("repobrowser /path:\"");
\r
1640 if (files_.size() > 0)
\r
1641 svnCmd += files_.front();
\r
1643 svnCmd += folder_;
\r
1644 svnCmd += _T("\"");
\r
1646 case ShellMenuBlame:
\r
1647 svnCmd += _T("blame /path:\"");
\r
1648 if (files_.size() > 0)
\r
1649 svnCmd += files_.front();
\r
1651 svnCmd += folder_;
\r
1652 svnCmd += _T("\"");
\r
1654 case ShellMenuCreatePatch:
\r
1655 tempfile = WriteFileListToTempFile();
\r
1656 svnCmd += _T("createpatch /pathfile:\"");
\r
1657 svnCmd += tempfile;
\r
1658 svnCmd += _T("\"");
\r
1659 svnCmd += _T(" /deletepathfile");
\r
1661 case ShellMenuApplyPatch:
\r
1662 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1664 // if there's a patch file in the clipboard, we save it
\r
1665 // to a temporary file and tell TortoiseMerge to use that one
\r
1666 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1667 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1669 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1670 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1672 DWORD len = GetTempPath(0, NULL);
\r
1673 TCHAR * path = new TCHAR[len+1];
\r
1674 TCHAR * tempF = new TCHAR[len+100];
\r
1675 GetTempPath (len+1, path);
\r
1676 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1677 std::wstring sTempFile = std::wstring(tempF);
\r
1682 size_t patchlen = strlen(lpstr);
\r
1683 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1686 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1687 if (size == patchlen)
\r
1689 itemStates |= ITEMIS_PATCHFILE;
\r
1691 files_.push_back(sTempFile);
\r
1695 GlobalUnlock(hglb);
\r
1696 CloseClipboard();
\r
1699 if (itemStates & ITEMIS_PATCHFILE)
\r
1701 svnCmd = _T(" /diff:\"");
\r
1702 if (files_.size() > 0)
\r
1704 svnCmd += files_.front();
\r
1705 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1707 svnCmd += _T("\" /patchpath:\"");
\r
1708 svnCmd += folder_;
\r
1712 svnCmd += folder_;
\r
1713 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1714 svnCmd += _T("\" /wc");
\r
1716 svnCmd += _T("\"");
\r
1720 svnCmd = _T(" /patchpath:\"");
\r
1721 if (files_.size() > 0)
\r
1722 svnCmd += files_.front();
\r
1724 svnCmd += folder_;
\r
1725 svnCmd += _T("\"");
\r
1728 myVerbsIDMap.clear();
\r
1729 myVerbsMap.clear();
\r
1730 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1733 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1734 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1735 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1738 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1739 (LPTSTR) &lpMsgBuf,
\r
1743 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1744 LocalFree( lpMsgBuf );
\r
1746 CloseHandle(process.hThread);
\r
1747 CloseHandle(process.hProcess);
\r
1750 case ShellMenuRevisionGraph:
\r
1751 svnCmd += _T("revisiongraph /path:\"");
\r
1752 if (files_.size() > 0)
\r
1753 svnCmd += files_.front();
\r
1755 svnCmd += folder_;
\r
1756 svnCmd += _T("\"");
\r
1758 case ShellMenuLock:
\r
1759 tempfile = WriteFileListToTempFile();
\r
1760 svnCmd += _T("lock /pathfile:\"");
\r
1761 svnCmd += tempfile;
\r
1762 svnCmd += _T("\"");
\r
1763 svnCmd += _T(" /deletepathfile");
\r
1765 case ShellMenuUnlock:
\r
1766 tempfile = WriteFileListToTempFile();
\r
1767 svnCmd += _T("unlock /pathfile:\"");
\r
1768 svnCmd += tempfile;
\r
1769 svnCmd += _T("\"");
\r
1770 svnCmd += _T(" /deletepathfile");
\r
1772 case ShellMenuUnlockForce:
\r
1773 tempfile = WriteFileListToTempFile();
\r
1774 svnCmd += _T("unlock /pathfile:\"");
\r
1775 svnCmd += tempfile;
\r
1776 svnCmd += _T("\"");
\r
1777 svnCmd += _T(" /deletepathfile");
\r
1778 svnCmd += _T(" /force");
\r
1780 case ShellMenuProperties:
\r
1781 tempfile = WriteFileListToTempFile();
\r
1782 svnCmd += _T("properties /pathfile:\"");
\r
1783 svnCmd += tempfile;
\r
1784 svnCmd += _T("\"");
\r
1785 svnCmd += _T(" /deletepathfile");
\r
1787 case ShellMenuClipPaste:
\r
1788 if (WriteClipboardPathsToTempFile(tempfile))
\r
1790 bool bCopy = true;
\r
1791 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
1792 if (cPrefDropFormat)
\r
1794 if (OpenClipboard(lpcmi->hwnd))
\r
1796 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
1799 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
1800 if (*effect == DROPEFFECT_MOVE)
\r
1802 GlobalUnlock(hglb);
\r
1809 svnCmd += _T("pastecopy /pathfile:\"");
\r
1811 svnCmd += _T("pastemove /pathfile:\"");
\r
1812 svnCmd += tempfile;
\r
1813 svnCmd += _T("\"");
\r
1814 svnCmd += _T(" /deletepathfile");
\r
1815 svnCmd += _T(" /droptarget:\"");
\r
1816 svnCmd += folder_;
\r
1817 svnCmd += _T("\"");
\r
1819 else return NOERROR;
\r
1821 case ShellMenuClone:
\r
1822 svnCmd += _T("clone /path:\"");
\r
1823 svnCmd += folder_;
\r
1824 svnCmd += _T("\"");
\r
1826 case ShellMenuPull:
\r
1827 svnCmd += _T("pull /path:\"");
\r
1828 if (files_.size() > 0)
\r
1829 svnCmd += files_.front();
\r
1831 svnCmd += folder_;
\r
1832 svnCmd += _T("\"");
\r
1834 case ShellMenuPush:
\r
1835 svnCmd += _T("push /path:\"");
\r
1836 if (files_.size() > 0)
\r
1837 svnCmd += files_.front();
\r
1839 svnCmd += folder_;
\r
1840 svnCmd += _T("\"");
\r
1842 case ShellMenuBranch:
\r
1843 svnCmd += _T("branch /path:\"");
\r
1844 if (files_.size() > 0)
\r
1845 svnCmd += files_.front();
\r
1847 svnCmd += folder_;
\r
1848 svnCmd += _T("\"");
\r
1851 case ShellMenuTag:
\r
1852 svnCmd += _T("tag /path:\"");
\r
1853 if (files_.size() > 0)
\r
1854 svnCmd += files_.front();
\r
1856 svnCmd += folder_;
\r
1857 svnCmd += _T("\"");
\r
1860 case ShellMenuFormatPatch:
\r
1861 svnCmd += _T("formatpatch /path:\"");
\r
1862 if (files_.size() > 0)
\r
1863 svnCmd += files_.front();
\r
1865 svnCmd += folder_;
\r
1866 svnCmd += _T("\"");
\r
1869 case ShellMenuImportPatch:
\r
1870 svnCmd += _T("importpatch /path:\"");
\r
1871 if (files_.size() > 0)
\r
1872 svnCmd += files_.front();
\r
1874 svnCmd += folder_;
\r
1875 svnCmd += _T("\"");
\r
1878 case ShellMenuCherryPick:
\r
1879 svnCmd += _T("cherrypick /path:\"");
\r
1880 if (files_.size() > 0)
\r
1881 svnCmd += files_.front();
\r
1883 svnCmd += folder_;
\r
1884 svnCmd += _T("\"");
\r
1886 case ShellMenuFetch:
\r
1887 svnCmd += _T("fetch /path:\"");
\r
1888 if (files_.size() > 0)
\r
1889 svnCmd += files_.front();
\r
1891 svnCmd += folder_;
\r
1892 svnCmd += _T("\"");
\r
1898 } // switch (id_it->second)
\r
1899 svnCmd += _T(" /hwnd:");
\r
1901 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
1904 myVerbsIDMap.clear();
\r
1905 myVerbsMap.clear();
\r
1906 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1909 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1910 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1911 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1914 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1915 (LPTSTR) &lpMsgBuf,
\r
1919 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1920 LocalFree( lpMsgBuf );
\r
1922 CloseHandle(process.hThread);
\r
1923 CloseHandle(process.hProcess);
\r
1925 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1926 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
1931 // This is for the status bar and things like that:
\r
1932 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
1934 UINT FAR * /*reserved*/,
\r
1938 PreserveChdir preserveChdir;
\r
1939 //do we know the id?
\r
1940 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1941 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
1943 return E_INVALIDARG; //no, we don't
\r
1947 HRESULT hr = E_INVALIDARG;
\r
1949 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
1950 int menuIndex = 0;
\r
1951 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1953 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
1955 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
1961 const TCHAR * desc = stringtablebuffer;
\r
1964 case GCS_HELPTEXTA:
\r
1966 std::string help = WideToMultibyte(desc);
\r
1967 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1971 case GCS_HELPTEXTW:
\r
1973 wide_string help = desc;
\r
1974 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
1980 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1981 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1983 std::string help = WideToMultibyte(verb_id_it->second);
\r
1984 lstrcpynA(pszName, help.c_str(), cchMax);
\r
1991 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
1992 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
1994 wide_string help = verb_id_it->second;
\r
1995 ATLTRACE("verb : %ws\n", help.c_str());
\r
1996 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2005 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2008 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2011 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2013 PreserveChdir preserveChdir;
\r
2016 if (pResult == NULL)
\r
2023 case WM_MEASUREITEM:
\r
2025 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2028 lpmis->itemWidth += 2;
\r
2029 if (lpmis->itemHeight < 16)
\r
2030 lpmis->itemHeight = 16;
\r
2037 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2038 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2039 return S_OK; //not for a menu
\r
2040 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2041 if (resource == NULL)
\r
2043 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2044 if (hIcon == NULL)
\r
2046 DrawIconEx(lpdis->hDC,
\r
2047 lpdis->rcItem.left - 16,
\r
2048 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2050 0, NULL, DI_NORMAL);
\r
2051 DestroyIcon(hIcon);
\r
2059 if (HIWORD(wParam) != MF_POPUP)
\r
2061 int nChar = LOWORD(wParam);
\r
2062 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2063 nChar = tolower(nChar);
\r
2064 // we have the char the user pressed, now search that char in all our
\r
2066 std::vector<int> accmenus;
\r
2067 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2069 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2070 if (resource == NULL)
\r
2072 szItem = stringtablebuffer;
\r
2073 TCHAR * amp = _tcschr(szItem, '&');
\r
2077 int ampChar = LOWORD(*amp);
\r
2078 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2079 ampChar = tolower(ampChar);
\r
2080 if (ampChar == nChar)
\r
2082 // yep, we found a menu which has the pressed key
\r
2083 // as an accelerator. Add that menu to the list to
\r
2085 accmenus.push_back(It->first);
\r
2088 if (accmenus.size() == 0)
\r
2090 // no menu with that accelerator key.
\r
2091 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2094 if (accmenus.size() == 1)
\r
2096 // Only one menu with that accelerator key. We're lucky!
\r
2097 // So just execute that menu entry.
\r
2098 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2101 if (accmenus.size() > 1)
\r
2103 // we have more than one menu item with this accelerator key!
\r
2105 mif.cbSize = sizeof(MENUITEMINFO);
\r
2106 mif.fMask = MIIM_STATE;
\r
2107 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2109 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2110 if (mif.fState == MFS_HILITE)
\r
2112 // this is the selected item, so select the next one
\r
2114 if (it == accmenus.end())
\r
2115 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2117 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2121 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2132 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2134 TCHAR textbuf[255];
\r
2135 LPCTSTR resource = NULL;
\r
2136 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2139 int menuIndex = 0;
\r
2140 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2142 if (menuInfo[menuIndex].command == id)
\r
2144 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2145 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2148 case ShellMenuLock:
\r
2149 // menu lock is special because it can be set to the top
\r
2150 // with a separate option in the registry
\r
2151 space = ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop())) ? 0 : 6;
\r
2152 if ((layout & MENULOCK) || ((itemStates & ITEMIS_NEEDSLOCK) && g_ShellCache.IsGetLockTop()))
\r
2154 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2155 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2156 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2159 // the sub menu entries are special because they're *always* on the top level menu
\r
2160 case ShellSubMenuMultiple:
\r
2161 case ShellSubMenuLink:
\r
2162 case ShellSubMenuFolder:
\r
2163 case ShellSubMenuFile:
\r
2164 case ShellSubMenu:
\r
2168 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2169 if (layout & (menuInfo[menuIndex].menuID))
\r
2171 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2172 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2173 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2184 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2187 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2188 LPITEMIDLIST pidl = NULL;
\r
2189 while (cslidarray[i])
\r
2193 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2195 if (!SHGetPathFromIDList(pidl, buf))
\r
2197 // not a file system path, definitely illegal for our use
\r
2198 CoTaskMemFree(pidl);
\r
2201 CoTaskMemFree(pidl);
\r
2202 if (_tcslen(buf)==0)
\r
2204 if (_tcscmp(buf, folder.c_str())==0)
\r
2210 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)
\r
2212 HMENU ignoresubmenu = NULL;
\r
2213 int indexignoresub = 0;
\r
2214 bool bShowIgnoreMenu = false;
\r
2215 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2216 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2217 if (files_.size() == 0)
\r
2219 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2221 std::vector<stdstring>::iterator I = files_.begin();
\r
2222 if (_tcsrchr(I->c_str(), '\\'))
\r
2223 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2225 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2226 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2228 // check if the item name is ignored or the mask
\r
2230 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2232 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2233 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2241 ignoresubmenu = CreateMenu();
\r
2242 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2243 stdstring verb = stdstring(ignorepath);
\r
2244 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2245 myVerbsMap[verb] = idCmd;
\r
2246 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2247 myVerbsIDMap[idCmd] = verb;
\r
2248 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2249 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2250 bShowIgnoreMenu = true;
\r
2252 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2253 if (_tcsrchr(ignorepath, '.'))
\r
2255 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2256 p = ignoredprops.find(maskbuf);
\r
2258 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2260 if (ignoresubmenu==NULL)
\r
2261 ignoresubmenu = CreateMenu();
\r
2263 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2264 stdstring verb = stdstring(maskbuf);
\r
2265 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2266 myVerbsMap[verb] = idCmd;
\r
2267 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2268 myVerbsIDMap[idCmd] = verb;
\r
2269 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2270 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2271 bShowIgnoreMenu = true;
\r
2275 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2277 bShowIgnoreMenu = true;
\r
2278 ignoresubmenu = CreateMenu();
\r
2279 if (itemStates & ITEMIS_ONLYONE)
\r
2281 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2282 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2283 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2285 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2286 if (_tcsrchr(ignorepath, '.'))
\r
2288 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2289 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2290 stdstring verb = stdstring(maskbuf);
\r
2291 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2292 myVerbsMap[verb] = idCmd;
\r
2293 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2294 myVerbsIDMap[idCmd] = verb;
\r
2295 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2296 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2301 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2302 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2303 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2304 stdstring verb = stdstring(ignorepath);
\r
2305 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2306 myVerbsMap[verb] = idCmd;
\r
2307 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2308 myVerbsIDMap[idCmd] = verb;
\r
2309 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2310 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2312 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2313 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2314 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2315 verb = stdstring(ignorepath);
\r
2316 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2317 myVerbsMap[verb] = idCmd;
\r
2318 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2319 myVerbsIDMap[idCmd] = verb;
\r
2320 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2321 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2325 if (bShowIgnoreMenu)
\r
2327 MENUITEMINFO menuiteminfo;
\r
2328 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2329 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2330 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
\r
2331 menuiteminfo.fType = MFT_STRING;
\r
2332 HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);
\r
2334 menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;
\r
2335 menuiteminfo.hbmpChecked = bmp;
\r
2336 menuiteminfo.hbmpUnchecked = bmp;
\r
2337 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2338 menuiteminfo.wID = idCmd;
\r
2339 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2340 if (itemStates & ITEMIS_IGNORED)
\r
2341 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2343 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2344 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2345 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2347 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2348 if (itemStates & ITEMIS_IGNORED)
\r
2350 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2351 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2355 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2356 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2361 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2363 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2364 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2365 return bitmap_it->second;
\r
2367 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2371 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2375 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2376 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2379 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2380 HBITMAP hBmp = NULL;
\r
2382 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2385 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2387 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2390 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2391 BP_PAINTPARAMS paintParams = {0};
\r
2392 paintParams.cbSize = sizeof(paintParams);
\r
2393 paintParams.dwFlags = BPPF_ERASE;
\r
2394 paintParams.pBlendFunction = &bfAlpha;
\r
2397 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2400 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2402 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2403 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2406 // This will write the buffer contents to the destination bitmap
\r
2407 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2410 SelectObject(hdcDest, hbmpOld);
\r
2414 DeleteDC(hdcDest);
\r
2417 DestroyIcon(hIcon);
\r
2420 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2424 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2429 ZeroMemory(&bmi, sizeof(bmi));
\r
2430 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2431 bmi.bmiHeader.biPlanes = 1;
\r
2432 bmi.bmiHeader.biCompression = BI_RGB;
\r
2434 bmi.bmiHeader.biWidth = psize->cx;
\r
2435 bmi.bmiHeader.biHeight = psize->cy;
\r
2436 bmi.bmiHeader.biBitCount = 32;
\r
2438 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2441 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2442 if (hdc != hdcUsed)
\r
2444 ReleaseDC(NULL, hdcUsed);
\r
2447 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2450 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2452 RGBQUAD *prgbQuad;
\r
2454 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2455 if (SUCCEEDED(hr))
\r
2457 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2458 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2461 if (GetIconInfo(hicon, &info))
\r
2465 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2468 DeleteObject(info.hbmColor);
\r
2469 DeleteObject(info.hbmMask);
\r
2477 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2479 ULONG cxDelta = cxRow - sizImage.cx;
\r
2480 for (ULONG y = sizImage.cy; y; --y)
\r
2482 for (ULONG x = sizImage.cx; x; --x)
\r
2484 if (*pargb++ & 0xFF000000)
\r
2496 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2499 ZeroMemory(&bmi, sizeof(bmi));
\r
2500 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2501 bmi.bmiHeader.biPlanes = 1;
\r
2502 bmi.bmiHeader.biCompression = BI_RGB;
\r
2504 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2505 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2506 bmi.bmiHeader.biBitCount = 32;
\r
2508 HRESULT hr = E_OUTOFMEMORY;
\r
2509 HANDLE hHeap = GetProcessHeap();
\r
2510 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2513 hr = E_UNEXPECTED;
\r
2514 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2516 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2517 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2519 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2521 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2525 // transparent pixel
\r
2531 *pargb++ |= 0xFF000000;
\r
2541 HeapFree(hHeap, 0, pvBits);
\r