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, MENUSUBUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
\r
51 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
54 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
55 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
57 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
59 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
60 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
62 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
63 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
65 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
66 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
68 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
69 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
71 { ShellMenuRefLog, MENUREFLOG, IDI_LOG, IDS_MENUREFLOG, IDS_MENUDESCREFLOG,
\r
72 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0 },
\r
74 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
75 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
77 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
78 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
80 { ShellMenuRebase, MENUREBASE, IDI_REBASE, IDS_MENUREBASE, IDS_MENUREBASE,
\r
81 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
83 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
84 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
86 { ShellMenuStashSave, MENUSTASHSAVE, IDI_COMMIT, IDS_MENUSTASHSAVE, IDS_MENUSTASHSAVE,
\r
87 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
88 { ShellMenuStashApply, MENUSTASHAPPLY, IDI_RELOCATE, IDS_MENUSTASHAPPLY, IDS_MENUSTASHAPPLY,
\r
89 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
90 { ShellMenuStashList, MENUSTASHAPPLY, IDI_LOG, IDS_MENUSTASHLIST, IDS_MENUSTASHLIST,
\r
91 ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
94 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
96 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
97 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
99 { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
100 ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
103 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
104 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
106 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
107 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
109 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
110 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
112 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
113 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
115 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
116 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
118 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
119 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
121 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
122 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
124 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
125 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
127 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
128 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
130 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
131 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
133 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
135 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
136 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
138 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
139 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
141 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
142 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
143 // { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
144 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
146 { ShellMenuBranch, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
147 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
148 { ShellMenuTag, MENUTAG, IDI_TAG, IDS_MENUTAG, IDS_MENUDESCCOPY,
\r
149 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
151 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
152 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
154 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
155 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
157 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
159 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
160 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
162 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
163 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
165 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
166 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
168 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
169 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
171 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
172 ITEMIS_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
173 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
\r
174 // why was this changed, is this related to GitStatus?
\r
176 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
177 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
179 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
180 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
182 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
184 { ShellMenuSubAdd, MENUSUBADD, IDI_ADD, IDS_MENUSUBADD, IDS_MENUSUBADD,
\r
185 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
187 { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
188 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE, 0, 0, 0, 0, 0, 0, 0 },
\r
190 { ShellMenuSubSync, MENUSUBSYNC, IDI_MENUSYNC, IDS_MENUSUBSYNC, IDS_MENUSUBSYNC,
\r
191 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0, 0, 0 },
\r
195 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
197 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
198 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
200 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
201 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
203 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
204 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, ITEMIS_PATCHFILE, 0, 0, 0 },
\r
207 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
208 ITEMIS_INSVN|ITEMIS_EXTENDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
210 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
211 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0 },
\r
213 { ShellMenuSendMail, MENUSENDMAIL, IDI_MENUSENDMAIL, IDS_MENUSENDMAIL, IDS_MENUDESSENDMAIL,
\r
214 ITEMIS_PATCHFILE, 0, 0, 0, 0, 0, 0, 0 },
\r
216 // { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
217 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
219 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
220 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
221 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
223 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
225 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
226 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
227 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
228 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
229 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
230 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
232 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
233 // but they still need to be in here, because we use the icon and string information anyway.
\r
234 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
235 0, 0, 0, 0, 0, 0, 0, 0 },
\r
236 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
237 0, 0, 0, 0, 0, 0, 0, 0 },
\r
238 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
239 0, 0, 0, 0, 0, 0, 0, 0 },
\r
240 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
241 0, 0, 0, 0, 0, 0, 0, 0 },
\r
242 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
243 0, 0, 0, 0, 0, 0, 0, 0 },
\r
244 // mark the last entry to tell the loop where to stop iterating over this array
\r
245 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
246 0, 0, 0, 0, 0, 0, 0, 0 },
\r
250 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
251 LPDATAOBJECT pDataObj,
\r
252 HKEY /* hRegKey */)
\r
255 ATLTRACE("Shell :: Initialize\n");
\r
256 PreserveChdir preserveChdir;
\r
259 uuidSource.erase();
\r
260 uuidTarget.erase();
\r
262 itemStatesFolder = 0;
\r
263 stdstring statuspath;
\r
264 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
265 // get selected files/folders
\r
269 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
270 (DVTARGETDEVICE FAR *)NULL,
\r
274 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
276 if (SUCCEEDED(hres) && medium.hGlobal)
\r
278 if (m_State == FileStateDropHandler)
\r
281 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
282 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
283 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
285 ReleaseStgMedium ( &medium );
\r
286 return E_INVALIDARG;
\r
290 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
291 if ( NULL == drop )
\r
293 ReleaseStgMedium ( &stg );
\r
294 ReleaseStgMedium ( &medium );
\r
295 return E_INVALIDARG;
\r
298 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
300 itemStates |= ITEMIS_ONLYONE;
\r
301 for (int i = 0; i < count; i++)
\r
303 // find the path length in chars
\r
304 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
307 TCHAR * szFileName = new TCHAR[len+1];
\r
308 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
310 delete [] szFileName;
\r
313 stdstring str = stdstring(szFileName);
\r
314 delete [] szFileName;
\r
315 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
317 if (itemStates & ITEMIS_ONLYONE)
\r
320 strpath.SetFromWin(str.c_str());
\r
321 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
322 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
324 files_.push_back(str);
\r
327 //get the Subversion status of the item
\r
328 git_wc_status_kind status = git_wc_status_none;
\r
329 CTGitPath askedpath;
\r
330 askedpath.SetFromWin(str.c_str());
\r
334 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
338 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
339 fetchedstatus = status;
\r
340 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
341 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
342 if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
344 itemStates |= ITEMIS_FOLDER;
\r
345 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
346 itemStates |= ITEMIS_FOLDERINSVN;
\r
348 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
350 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
351 // itemStates |= ITEMIS_NEEDSLOCK;
\r
353 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
354 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
358 // sometimes, git_client_status() returns with an error.
\r
359 // in that case, we have to check if the working copy is versioned
\r
360 // anyway to show the 'correct' context menu
\r
361 if (askedpath.HasAdminDir())
\r
362 status = git_wc_status_normal;
\r
367 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
370 // TODO: should we really assume any sub-directory to be versioned
\r
371 // or only if it contains versioned files
\r
372 if ( askedpath.IsDirectory() )
\r
374 if (askedpath.HasAdminDir())
\r
375 itemStates |= ITEMIS_INSVN;
\r
376 if (askedpath.HasSubmodules())
\r
378 itemStates |= ITEMIS_SUBMODULE;
\r
381 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
382 itemStates |= ITEMIS_INSVN;
\r
383 if (status == git_wc_status_ignored)
\r
384 itemStates |= ITEMIS_IGNORED;
\r
385 if (status == git_wc_status_normal)
\r
386 itemStates |= ITEMIS_NORMAL;
\r
387 if (status == git_wc_status_conflicted)
\r
388 itemStates |= ITEMIS_CONFLICTED;
\r
389 if (status == git_wc_status_added)
\r
390 itemStates |= ITEMIS_ADDED;
\r
391 if (status == git_wc_status_deleted)
\r
392 itemStates |= ITEMIS_DELETED;
\r
395 } // for (int i = 0; i < count; i++)
\r
396 GlobalUnlock ( drop );
\r
397 ReleaseStgMedium ( &stg );
\r
399 } // if (m_State == FileStateDropHandler)
\r
403 //Enumerate PIDLs which the user has selected
\r
404 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
405 ItemIDList parent( GetPIDLFolder (cida));
\r
407 int count = cida->cidl;
\r
408 BOOL statfetched = FALSE;
\r
409 for (int i = 0; i < count; ++i)
\r
411 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
412 stdstring str = child.toString();
\r
413 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
415 //check if our menu is requested for a subversion admin directory
\r
416 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
419 files_.push_back(str);
\r
421 strpath.SetFromWin(str.c_str());
\r
422 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
423 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
426 //get the Subversion status of the item
\r
427 git_wc_status_kind status = git_wc_status_none;
\r
428 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
430 if (strpath.HasAdminDir())
\r
431 status = git_wc_status_normal;
\r
438 if (strpath.HasAdminDir())
\r
439 stat.GetStatus(strpath, false, true, true);
\r
443 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
444 fetchedstatus = status;
\r
445 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
446 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
447 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
449 itemStates |= ITEMIS_FOLDER;
\r
450 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
451 itemStates |= ITEMIS_FOLDERINSVN;
\r
453 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
\r
454 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
455 itemStates |= ITEMIS_CONFLICTED;
\r
456 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
458 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
459 // itemStates |= ITEMIS_NEEDSLOCK;
\r
461 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
462 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
466 // sometimes, git_client_status() returns with an error.
\r
467 // in that case, we have to check if the working copy is versioned
\r
468 // anyway to show the 'correct' context menu
\r
469 if (strpath.HasAdminDir())
\r
471 status = git_wc_status_normal;
\r
472 fetchedstatus = status;
\r
475 statfetched = TRUE;
\r
479 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
483 // TODO: should we really assume any sub-directory to be versioned
\r
484 // or only if it contains versioned files
\r
485 if ( strpath.IsDirectory() )
\r
487 if (strpath.HasAdminDir())
\r
488 itemStates |= ITEMIS_INSVN;
\r
489 if (strpath.HasSubmodules())
\r
491 itemStates |= ITEMIS_SUBMODULE;
\r
494 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
495 itemStates |= ITEMIS_INSVN;
\r
496 if (status == git_wc_status_ignored)
\r
498 itemStates |= ITEMIS_IGNORED;
\r
499 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
500 // offer a 'remove from ignored list' entry
\r
501 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
502 // ignoredprops.empty();
\r
503 // for (int p=0; p<props.GetCount(); ++p)
\r
505 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
507 // std::string st = props.GetItemValue(p);
\r
508 // ignoredprops = MultibyteToWide(st.c_str());
\r
509 // // remove all escape chars ('\\')
\r
510 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
515 if (status == git_wc_status_normal)
\r
516 itemStates |= ITEMIS_NORMAL;
\r
517 if (status == git_wc_status_conflicted)
\r
518 itemStates |= ITEMIS_CONFLICTED;
\r
519 if (status == git_wc_status_added)
\r
520 itemStates |= ITEMIS_ADDED;
\r
521 if (status == git_wc_status_deleted)
\r
522 itemStates |= ITEMIS_DELETED;
\r
525 } // for (int i = 0; i < count; ++i)
\r
526 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
527 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
528 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
529 GlobalUnlock(medium.hGlobal);
\r
531 // if the item is a versioned folder, check if there's a patch file
\r
532 // in the clipboard to be used in "Apply Patch"
\r
533 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
536 if (IsClipboardFormatAvailable(cFormatDiff))
\r
537 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
539 if (IsClipboardFormatAvailable(CF_HDROP))
\r
540 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
544 ReleaseStgMedium ( &medium );
\r
545 if (medium.pUnkForRelease)
\r
547 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
548 relInterface->Release();
\r
553 // get folder background
\r
557 ItemIDList list(pIDFolder);
\r
558 folder_ = list.toString();
\r
559 git_wc_status_kind status = git_wc_status_none;
\r
560 if (IsClipboardFormatAvailable(CF_HDROP))
\r
561 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
563 CTGitPath askedpath;
\r
564 askedpath.SetFromWin(folder_.c_str());
\r
566 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
572 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
575 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
576 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
577 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
578 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
580 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
581 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
583 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
584 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
589 // sometimes, git_client_status() returns with an error.
\r
590 // in that case, we have to check if the working copy is versioned
\r
591 // anyway to show the 'correct' context menu
\r
592 if (askedpath.HasAdminDir())
\r
593 status = git_wc_status_normal;
\r
596 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
597 if (askedpath.HasAdminDir())
\r
598 itemStatesFolder |= ITEMIS_INSVN;
\r
599 if (status == git_wc_status_normal)
\r
600 itemStatesFolder |= ITEMIS_NORMAL;
\r
601 if (status == git_wc_status_conflicted)
\r
602 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
603 if (status == git_wc_status_added)
\r
604 itemStatesFolder |= ITEMIS_ADDED;
\r
605 if (status == git_wc_status_deleted)
\r
606 itemStatesFolder |= ITEMIS_DELETED;
\r
611 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
616 status = fetchedstatus;
\r
618 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
619 if (askedpath.HasAdminDir())
\r
621 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
623 if (askedpath.HasSubmodules())
\r
625 itemStatesFolder |= ITEMIS_SUBMODULE;
\r
627 if (status == git_wc_status_ignored)
\r
628 itemStatesFolder |= ITEMIS_IGNORED;
\r
629 itemStatesFolder |= ITEMIS_FOLDER;
\r
630 if (files_.size() == 0)
\r
631 itemStates |= ITEMIS_ONLYONE;
\r
632 if (m_State != FileStateDropHandler)
\r
633 itemStates |= itemStatesFolder;
\r
637 if (files_.size() == 2)
\r
638 itemStates |= ITEMIS_TWO;
\r
639 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
642 itemStates |= ITEMIS_ONLYONE;
\r
643 if (m_State != FileStateDropHandler)
\r
645 if (PathIsDirectory(files_.front().c_str()))
\r
647 folder_ = files_.front();
\r
648 git_wc_status_kind status = git_wc_status_none;
\r
649 CTGitPath askedpath;
\r
650 askedpath.SetFromWin(folder_.c_str());
\r
652 if (folder_.compare(statuspath)!=0)
\r
657 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
660 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
661 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
662 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
663 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
665 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
666 // itemStates |= ITEMIS_NEEDSLOCK;
\r
668 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
669 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
674 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
679 status = fetchedstatus;
\r
681 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
682 if (askedpath.HasAdminDir())
\r
683 itemStates |= ITEMIS_FOLDERINSVN;
\r
684 if (status == git_wc_status_ignored)
\r
685 itemStates |= ITEMIS_IGNORED;
\r
686 itemStates |= ITEMIS_FOLDER;
\r
687 if (status == git_wc_status_added)
\r
688 itemStates |= ITEMIS_ADDED;
\r
689 if (status == git_wc_status_deleted)
\r
690 itemStates |= ITEMIS_DELETED;
\r
699 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
701 TCHAR menutextbuffer[512] = {0};
\r
702 TCHAR verbsbuffer[255] = {0};
\r
703 MAKESTRING(stringid);
\r
707 //menu entry for the top context menu, so append an "Git " before
\r
708 //the menu text to indicate where the entry comes from
\r
709 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
711 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
713 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
\r
714 // so we have an easy and fast way to check the current branch
\r
715 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
\r
716 if (com == ShellMenuCommit)
\r
719 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
720 CString sProjectRoot;
\r
721 CString sBranchName;
\r
723 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
725 if (sBranchName.GetLength() == 40)
\r
727 // if SHA1 only show 4 first bytes
\r
728 BOOL bIsSha1 = TRUE;
\r
729 for (int i=0; i<40; i++)
\r
730 if ( !iswxdigit(sBranchName[i]) )
\r
736 sBranchName = sBranchName.Left(8) + _T("....");
\r
740 if (sBranchName.GetLength() > 64)
\r
741 sBranchName = sBranchName.Left(64) + _T("...");
\r
743 // scan to before "..."
\r
744 LPTSTR s = menutextbuffer + _tcslen(menutextbuffer)-1;
\r
745 if (s > menutextbuffer)
\r
747 while (s > menutextbuffer)
\r
759 s = menutextbuffer;
\r
762 // append branch name and end with ...
\r
763 _tcscpy(s, _T(" -> \"") + sBranchName + _T("\"..."));
\r
767 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
769 // on win2k, the context menu does not work properly if we use
\r
770 // icon bitmaps. At least the menu text is empty in the context menu
\r
771 // for folder backgrounds (seems like a win2k bug).
\r
772 // the workaround is to use the check/unchecked bitmaps, which are drawn
\r
773 // with AND raster op, but it's better than nothing at all
\r
774 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
777 HBITMAP bmp = IconToBitmap(icon);
\r
778 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
783 MENUITEMINFO menuiteminfo;
\r
784 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
785 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
786 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
\r
787 menuiteminfo.fType = MFT_STRING;
\r
788 menuiteminfo.dwTypeData = menutextbuffer;
\r
791 menuiteminfo.fMask |= MIIM_BITMAP;
\r
792 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
794 menuiteminfo.wID = id;
\r
795 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
800 //menu entry for the top context menu, so append an "Git " before
\r
801 //the menu text to indicate where the entry comes from
\r
802 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
804 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
805 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
806 stdstring verb = stdstring(menutextbuffer);
\r
807 if (verb.find('&') != -1)
\r
809 verb.erase(verb.find('&'),1);
\r
811 myVerbsMap[verb] = id - idCmdFirst;
\r
812 myVerbsMap[verb] = id;
\r
813 myVerbsIDMap[id - idCmdFirst] = verb;
\r
814 myVerbsIDMap[id] = verb;
\r
815 // We store the relative and absolute diameter
\r
816 // (drawitem callback uses absolute, others relative)
\r
817 myIDMap[id - idCmdFirst] = com;
\r
820 mySubMenuMap[pos] = com;
\r
823 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
825 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
826 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
827 return bitmap_it->second;
\r
829 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
835 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
836 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
838 rect.left = rect.top = 0;
\r
840 HWND desktop = ::GetDesktopWindow();
\r
841 if (desktop == NULL)
\r
843 DestroyIcon(hIcon);
\r
847 HDC screen_dev = ::GetDC(desktop);
\r
848 if (screen_dev == NULL)
\r
850 DestroyIcon(hIcon);
\r
854 // Create a compatible DC
\r
855 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
856 if (dst_hdc == NULL)
\r
858 DestroyIcon(hIcon);
\r
859 ::ReleaseDC(desktop, screen_dev);
\r
863 // Create a new bitmap of icon size
\r
864 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
867 DestroyIcon(hIcon);
\r
868 ::DeleteDC(dst_hdc);
\r
869 ::ReleaseDC(desktop, screen_dev);
\r
873 // Select it into the compatible DC
\r
874 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
875 if (old_dst_bmp == NULL)
\r
877 DestroyIcon(hIcon);
\r
881 // Fill the background of the compatible DC with the white color
\r
882 // that is taken by menu routines as transparent
\r
883 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
884 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
886 // Draw the icon into the compatible DC
\r
887 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
889 // Restore settings
\r
890 ::SelectObject(dst_hdc, old_dst_bmp);
\r
891 ::DeleteDC(dst_hdc);
\r
892 ::ReleaseDC(desktop, screen_dev);
\r
893 DestroyIcon(hIcon);
\r
895 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
899 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
902 tempfile = stdstring();
\r
903 //write all selected files and paths to a temporary file
\r
904 //for TortoiseProc.exe to read out again.
\r
906 DWORD pathlength = GetTempPath(0, NULL);
\r
907 TCHAR * path = new TCHAR[pathlength+1];
\r
908 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
909 GetTempPath (pathlength+1, path);
\r
910 GetTempFileName (path, _T("git"), 0, tempFile);
\r
911 tempfile = stdstring(tempFile);
\r
913 HANDLE file = ::CreateFile (tempFile,
\r
918 FILE_ATTRIBUTE_TEMPORARY,
\r
922 delete [] tempFile;
\r
923 if (file == INVALID_HANDLE_VALUE)
\r
926 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
928 if (!OpenClipboard(NULL))
\r
931 stdstring sClipboardText;
\r
932 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
933 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
936 TCHAR szFileName[MAX_PATH];
\r
937 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
938 for(UINT i = 0; i < cFiles; ++i)
\r
940 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
941 stdstring filename = szFileName;
\r
942 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
943 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
945 GlobalUnlock(hDrop);
\r
948 GlobalUnlock(hglb);
\r
951 ::CloseHandle(file);
\r
956 stdstring CShellExt::WriteFileListToTempFile()
\r
958 //write all selected files and paths to a temporary file
\r
959 //for TortoiseProc.exe to read out again.
\r
960 DWORD pathlength = GetTempPath(0, NULL);
\r
961 TCHAR * path = new TCHAR[pathlength+1];
\r
962 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
963 GetTempPath (pathlength+1, path);
\r
964 GetTempFileName (path, _T("git"), 0, tempFile);
\r
965 stdstring retFilePath = stdstring(tempFile);
\r
967 HANDLE file = ::CreateFile (tempFile,
\r
972 FILE_ATTRIBUTE_TEMPORARY,
\r
976 delete [] tempFile;
\r
977 if (file == INVALID_HANDLE_VALUE)
\r
978 return stdstring();
\r
981 if (files_.empty())
\r
983 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
984 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
987 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
989 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
990 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
992 ::CloseHandle(file);
\r
993 return retFilePath;
\r
996 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
998 PreserveChdir preserveChdir;
\r
1001 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1002 return NOERROR; //we don't change the default action
\r
1004 if ((files_.size() == 0)||(folder_.size() == 0))
\r
1007 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1010 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
1012 //the drop handler only has eight commands, but not all are visible at the same time:
\r
1013 //if the source file(s) are under version control then those files can be moved
\r
1014 //to the new location or they can be moved with a rename,
\r
1015 //if they are unversioned then they can be added to the working copy
\r
1016 //if they are versioned, they also can be exported to an unversioned location
\r
1017 UINT idCmd = idCmdFirst;
\r
1020 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1021 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
1022 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
1024 // Git move and rename here
\r
1025 // 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
1026 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1027 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
1030 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1031 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
1032 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
1034 // Git copy and rename here, source and target from same repository
\r
1035 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
1036 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1037 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
1040 // available if target is versioned and source is either unversioned or from another repository
\r
1041 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
1042 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
1044 // Git export here
\r
1045 // available if source is versioned and a folder
\r
1046 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1047 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
1049 // Git export all here
\r
1050 // available if source is versioned and a folder
\r
1051 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1052 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
1055 // available if source is a patchfile
\r
1056 if (itemStates & ITEMIS_PATCHFILE)
\r
1057 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
1060 if (idCmd != idCmdFirst)
\r
1061 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1063 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1066 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
1069 UINT /*idCmdLast*/,
\r
1072 ATLTRACE("Shell :: QueryContextMenu\n");
\r
1073 PreserveChdir preserveChdir;
\r
1075 //first check if our drop handler is called
\r
1076 //and then (if true) provide the context menu for the
\r
1078 if (m_State == FileStateDropHandler)
\r
1080 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
1083 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1084 return NOERROR; //we don't change the default action
\r
1086 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
1089 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1092 int csidlarray[] =
\r
1095 CSIDL_CDBURN_AREA,
\r
1096 CSIDL_COMMON_FAVORITES,
\r
1097 CSIDL_COMMON_STARTMENU,
\r
1098 CSIDL_COMPUTERSNEARME,
\r
1099 CSIDL_CONNECTIONS,
\r
1106 CSIDL_INTERNET_CACHE,
\r
1116 if (IsIllegalFolder(folder_, csidlarray))
\r
1119 if (folder_.empty())
\r
1121 // folder is empty, but maybe files are selected
\r
1122 if (files_.size() == 0)
\r
1123 return NOERROR; // nothing selected - we don't have a menu to show
\r
1124 // check whether a selected entry is an UID - those are namespace extensions
\r
1125 // which we can't handle
\r
1126 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1128 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1133 //check if our menu is requested for a subversion admin directory
\r
1134 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1137 if (uFlags & CMF_EXTENDEDVERBS)
\r
1138 itemStates |= ITEMIS_EXTENDED;
\r
1140 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1141 if ( bShortcut && (files_.size()==1))
\r
1143 // Don't show the context menu for a link if the
\r
1144 // destination is not part of a working copy.
\r
1145 // It would only show the standard menu items
\r
1146 // which are already shown for the lnk-file.
\r
1147 CString path = files_.front().c_str();
\r
1148 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1154 //check if we already added our menu entry for a folder.
\r
1155 //we check that by iterating through all menu entries and check if
\r
1156 //the dwItemData member points to our global ID string. That string is set
\r
1157 //by our shell extension when the folder menu is inserted.
\r
1158 TCHAR menubuf[MAX_PATH];
\r
1159 int count = GetMenuItemCount(hMenu);
\r
1160 for (int i=0; i<count; ++i)
\r
1162 MENUITEMINFO miif;
\r
1163 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1164 miif.cbSize = sizeof(MENUITEMINFO);
\r
1165 miif.fMask = MIIM_DATA;
\r
1166 miif.dwTypeData = menubuf;
\r
1167 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1168 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1169 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1174 UINT idCmd = idCmdFirst;
\r
1176 //create the sub menu
\r
1177 HMENU subMenu = CreateMenu();
\r
1178 int indexSubMenu = 0;
\r
1180 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1181 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1183 int menuIndex = 0;
\r
1184 bool bAddSeparator = false;
\r
1185 bool bMenuEntryAdded = false;
\r
1186 bool bMenuEmpty = true;
\r
1187 // insert separator at start
\r
1188 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1189 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1190 // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up
\r
1191 /*if (fullver <= 0x500)
\r
1192 bShowIcons = false;*/
\r
1195 if (itemStates & (ITEMIS_INSVN|ITEMIS_FOLDERINSVN))
\r
1197 // show current branch name (as a "read-only" menu entry)
\r
1199 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
1200 CString sProjectRoot;
\r
1201 CString sBranchName;
\r
1203 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
1205 if (sBranchName.GetLength() == 40)
\r
1207 // if SHA1 only show 4 first bytes
\r
1208 BOOL bIsSha1 = TRUE;
\r
1209 for (int i=0; i<40; i++)
\r
1210 if ( !iswxdigit(sBranchName[i]) )
\r
1216 sBranchName = sBranchName.Left(8) + _T("....");
\r
1219 sBranchName = _T('"') + sBranchName + _T('"');
\r
1221 const int icon = IDI_COPY;
\r
1222 const int pos = indexMenu++;
\r
1223 const int id = idCmd++;
\r
1225 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1227 InsertMenu(hMenu, pos, MF_DISABLED|MF_GRAYED|MF_BYPOSITION|MF_STRING, id, sBranchName);
\r
1228 HBITMAP bmp = IconToBitmap(icon);
\r
1229 SetMenuItemBitmaps(hMenu, pos, MF_BYPOSITION, bmp, bmp);
\r
1233 MENUITEMINFO menuiteminfo;
\r
1234 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1235 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1236 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
\r
1237 menuiteminfo.fState = MFS_DISABLED;
\r
1238 menuiteminfo.fType = MFT_STRING;
\r
1239 menuiteminfo.dwTypeData = (LPWSTR)sBranchName.GetString();
\r
1242 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1243 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
1245 if (menuiteminfo.hbmpItem == HBMMENU_CALLBACK)
\r
1247 // WM_DRAWITEM uses myIDMap to get icon, we use the same icon as create branch
\r
1248 myIDMap[id - idCmdFirst] = ShellMenuBranch;
\r
1249 myIDMap[id] = ShellMenuBranch;
\r
1252 menuiteminfo.wID = id;
\r
1253 InsertMenuItem(hMenu, pos, TRUE, &menuiteminfo);
\r
1259 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1261 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1263 // we don't add a separator immediately. Because there might not be
\r
1264 // another 'normal' menu entry after we insert a separator.
\r
1265 // we simply set a flag here, indicating that before the next
\r
1266 // 'normal' menu entry, a separator should be added.
\r
1268 bAddSeparator = true;
\r
1272 // check the conditions whether to show the menu entry or not
\r
1273 bool bInsertMenu = false;
\r
1275 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1277 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1279 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1280 bInsertMenu = true;
\r
1282 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1283 bInsertMenu = true;
\r
1284 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1285 bInsertMenu = true;
\r
1287 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1289 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1291 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1292 bInsertMenu = true;
\r
1294 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1295 bInsertMenu = true;
\r
1296 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1297 bInsertMenu = true;
\r
1299 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1301 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1303 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1304 bInsertMenu = true;
\r
1306 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1307 bInsertMenu = true;
\r
1308 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1309 bInsertMenu = true;
\r
1311 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1313 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1315 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1316 bInsertMenu = true;
\r
1318 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1319 bInsertMenu = true;
\r
1320 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1321 bInsertMenu = true;
\r
1323 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1327 // insert a separator
\r
1328 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1330 bAddSeparator = false;
\r
1331 bMenuEntryAdded = false;
\r
1332 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1336 // handle special cases (sub menus)
\r
1337 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1339 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons, uFlags);
\r
1340 bMenuEntryAdded = true;
\r
1341 bMenuEmpty = false;
\r
1345 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1347 // insert the menu entry
\r
1348 InsertGitMenu( bIsTop,
\r
1349 bIsTop ? hMenu : subMenu,
\r
1350 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1352 menuInfo[menuIndex].menuTextID,
\r
1353 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1355 menuInfo[menuIndex].command,
\r
1359 bMenuEntryAdded = true;
\r
1360 bMenuEmpty = false;
\r
1369 //add sub menu to main context menu
\r
1370 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1371 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1372 MAKESTRING(IDS_MENUSUBMENU);
\r
1373 MENUITEMINFO menuiteminfo;
\r
1374 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1375 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1376 menuiteminfo.fType = MFT_STRING;
\r
1377 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1379 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1380 if (folder_.size())
\r
1382 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1383 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1384 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1385 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1387 else if (!bShortcut && (files_.size()==1))
\r
1389 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1390 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1391 myIDMap[idCmd] = ShellSubMenuFile;
\r
1393 else if (bShortcut && (files_.size()==1))
\r
1395 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1396 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1397 myIDMap[idCmd] = ShellSubMenuLink;
\r
1399 else if (files_.size() > 1)
\r
1401 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1402 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1403 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1407 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1408 myIDMap[idCmd] = ShellSubMenu;
\r
1410 HBITMAP bmp = NULL;
\r
1411 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1413 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
1416 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
1417 bmp = IconToBitmap(uIcon);
\r
1418 menuiteminfo.hbmpChecked = bmp;
\r
1419 menuiteminfo.hbmpUnchecked = bmp;
\r
1424 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
1427 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1428 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1431 menuiteminfo.hSubMenu = subMenu;
\r
1432 menuiteminfo.wID = idCmd++;
\r
1433 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1436 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1438 //return number of menu items added
\r
1439 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1443 // This is called when you invoke a command on the menu:
\r
1444 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1446 PreserveChdir preserveChdir;
\r
1447 HRESULT hr = E_INVALIDARG;
\r
1448 if (lpcmi == NULL)
\r
1451 std::string command;
\r
1452 std::string parent;
\r
1455 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1457 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1459 if (HIWORD(lpcmi->lpVerb))
\r
1461 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1462 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1463 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1464 idCmd = verb_it->second;
\r
1469 // See if we have a handler interface for this id
\r
1470 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1471 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1473 STARTUPINFO startup;
\r
1474 PROCESS_INFORMATION process;
\r
1475 memset(&startup, 0, sizeof(startup));
\r
1476 startup.cb = sizeof(startup);
\r
1477 memset(&process, 0, sizeof(process));
\r
1478 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1479 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1481 //TortoiseProc expects a command line of the form:
\r
1482 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1484 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1486 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1487 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1488 stdstring svnCmd = _T(" /command:");
\r
1489 stdstring tempfile;
\r
1490 switch (id_it->second)
\r
1493 case ShellMenuCheckout:
\r
1494 svnCmd += _T("checkout /path:\"");
\r
1495 svnCmd += folder_;
\r
1496 svnCmd += _T("\"");
\r
1498 case ShellMenuUpdate:
\r
1499 tempfile = WriteFileListToTempFile();
\r
1500 svnCmd += _T("update /pathfile:\"");
\r
1501 svnCmd += tempfile;
\r
1502 svnCmd += _T("\"");
\r
1503 svnCmd += _T(" /deletepathfile");
\r
1505 case ShellMenuSubSync:
\r
1506 tempfile = WriteFileListToTempFile();
\r
1507 svnCmd += _T("subsync /pathfile:\"");
\r
1508 svnCmd += tempfile;
\r
1509 svnCmd += _T("\"");
\r
1510 svnCmd += _T(" /deletepathfile");
\r
1511 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1513 svnCmd += _T(" /bkpath:");
\r
1514 svnCmd += folder_;
\r
1517 case ShellMenuUpdateExt:
\r
1518 tempfile = WriteFileListToTempFile();
\r
1519 svnCmd += _T("subupdate /pathfile:\"");
\r
1520 svnCmd += tempfile;
\r
1521 svnCmd += _T("\"");
\r
1522 svnCmd += _T(" /deletepathfile");
\r
1523 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1525 svnCmd += _T(" /bkpath:");
\r
1526 svnCmd += folder_;
\r
1529 case ShellMenuCommit:
\r
1530 tempfile = WriteFileListToTempFile();
\r
1531 svnCmd += _T("commit /pathfile:\"");
\r
1532 svnCmd += tempfile;
\r
1533 svnCmd += _T("\"");
\r
1534 svnCmd += _T(" /deletepathfile");
\r
1536 case ShellMenuAdd:
\r
1537 case ShellMenuAddAsReplacement:
\r
1538 tempfile = WriteFileListToTempFile();
\r
1539 svnCmd += _T("add /pathfile:\"");
\r
1540 svnCmd += tempfile;
\r
1541 svnCmd += _T("\"");
\r
1542 svnCmd += _T(" /deletepathfile");
\r
1544 case ShellMenuIgnore:
\r
1545 tempfile = WriteFileListToTempFile();
\r
1546 svnCmd += _T("ignore /pathfile:\"");
\r
1547 svnCmd += tempfile;
\r
1548 svnCmd += _T("\"");
\r
1549 svnCmd += _T(" /deletepathfile");
\r
1551 case ShellMenuIgnoreCaseSensitive:
\r
1552 tempfile = WriteFileListToTempFile();
\r
1553 svnCmd += _T("ignore /pathfile:\"");
\r
1554 svnCmd += tempfile;
\r
1555 svnCmd += _T("\"");
\r
1556 svnCmd += _T(" /deletepathfile");
\r
1557 svnCmd += _T(" /onlymask");
\r
1559 case ShellMenuUnIgnore:
\r
1560 tempfile = WriteFileListToTempFile();
\r
1561 svnCmd += _T("unignore /pathfile:\"");
\r
1562 svnCmd += tempfile;
\r
1563 svnCmd += _T("\"");
\r
1564 svnCmd += _T(" /deletepathfile");
\r
1566 case ShellMenuUnIgnoreCaseSensitive:
\r
1567 tempfile = WriteFileListToTempFile();
\r
1568 svnCmd += _T("unignore /pathfile:\"");
\r
1569 svnCmd += tempfile;
\r
1570 svnCmd += _T("\"");
\r
1571 svnCmd += _T(" /deletepathfile");
\r
1572 svnCmd += _T(" /onlymask");
\r
1574 case ShellMenuRevert:
\r
1575 tempfile = WriteFileListToTempFile();
\r
1576 svnCmd += _T("revert /pathfile:\"");
\r
1577 svnCmd += tempfile;
\r
1578 svnCmd += _T("\"");
\r
1579 svnCmd += _T(" /deletepathfile");
\r
1581 case ShellMenuDelUnversioned:
\r
1582 svnCmd += _T("delunversioned /path:\"");
\r
1583 svnCmd += folder_;
\r
1584 svnCmd += _T("\"");
\r
1586 case ShellMenuCleanup:
\r
1587 tempfile = WriteFileListToTempFile();
\r
1588 svnCmd += _T("cleanup /pathfile:\"");
\r
1589 svnCmd += tempfile;
\r
1590 svnCmd += _T("\"");
\r
1591 svnCmd += _T(" /deletepathfile");
\r
1593 case ShellMenuSendMail:
\r
1594 tempfile = WriteFileListToTempFile();
\r
1595 svnCmd += _T("sendmail /pathfile:\"");
\r
1596 svnCmd += tempfile;
\r
1597 svnCmd += _T("\"");
\r
1598 svnCmd += _T(" /deletepathfile");
\r
1600 case ShellMenuResolve:
\r
1601 tempfile = WriteFileListToTempFile();
\r
1602 svnCmd += _T("resolve /pathfile:\"");
\r
1603 svnCmd += tempfile;
\r
1604 svnCmd += _T("\"");
\r
1605 svnCmd += _T(" /deletepathfile");
\r
1607 case ShellMenuSwitch:
\r
1608 svnCmd += _T("switch /path:\"");
\r
1609 if (files_.size() > 0)
\r
1610 svnCmd += files_.front();
\r
1612 svnCmd += folder_;
\r
1613 svnCmd += _T("\"");
\r
1615 case ShellMenuImport:
\r
1616 svnCmd += _T("import /path:\"");
\r
1617 svnCmd += folder_;
\r
1618 svnCmd += _T("\"");
\r
1620 case ShellMenuExport:
\r
1621 svnCmd += _T("export /path:\"");
\r
1622 svnCmd += folder_;
\r
1623 svnCmd += _T("\"");
\r
1625 case ShellMenuAbout:
\r
1626 svnCmd += _T("about");
\r
1628 case ShellMenuCreateRepos:
\r
1629 svnCmd += _T("repocreate /path:\"");
\r
1630 svnCmd += folder_;
\r
1631 svnCmd += _T("\"");
\r
1633 case ShellMenuMerge:
\r
1634 svnCmd += _T("merge /path:\"");
\r
1635 if (files_.size() > 0)
\r
1636 svnCmd += files_.front();
\r
1638 svnCmd += folder_;
\r
1639 svnCmd += _T("\"");
\r
1641 case ShellMenuMergeAll:
\r
1642 svnCmd += _T("mergeall /path:\"");
\r
1643 if (files_.size() > 0)
\r
1644 svnCmd += files_.front();
\r
1646 svnCmd += folder_;
\r
1647 svnCmd += _T("\"");
\r
1649 case ShellMenuCopy:
\r
1650 svnCmd += _T("copy /path:\"");
\r
1651 if (files_.size() > 0)
\r
1652 svnCmd += files_.front();
\r
1654 svnCmd += folder_;
\r
1655 svnCmd += _T("\"");
\r
1657 case ShellMenuSettings:
\r
1658 svnCmd += _T("settings");
\r
1660 case ShellMenuHelp:
\r
1661 svnCmd += _T("help");
\r
1663 case ShellMenuRename:
\r
1664 svnCmd += _T("rename /path:\"");
\r
1665 if (files_.size() > 0)
\r
1666 svnCmd += files_.front();
\r
1668 svnCmd += folder_;
\r
1669 svnCmd += _T("\"");
\r
1671 case ShellMenuRemove:
\r
1672 tempfile = WriteFileListToTempFile();
\r
1673 svnCmd += _T("remove /pathfile:\"");
\r
1674 svnCmd += tempfile;
\r
1675 svnCmd += _T("\"");
\r
1676 svnCmd += _T(" /deletepathfile");
\r
1678 case ShellMenuRemoveKeep:
\r
1679 tempfile = WriteFileListToTempFile();
\r
1680 svnCmd += _T("remove /pathfile:\"");
\r
1681 svnCmd += tempfile;
\r
1682 svnCmd += _T("\"");
\r
1683 svnCmd += _T(" /deletepathfile");
\r
1684 svnCmd += _T(" /keep");
\r
1686 case ShellMenuDiff:
\r
1687 svnCmd += _T("diff /path:\"");
\r
1688 if (files_.size() == 1)
\r
1689 svnCmd += files_.front();
\r
1690 else if (files_.size() == 2)
\r
1692 std::vector<stdstring>::iterator I = files_.begin();
\r
1695 svnCmd += _T("\" /path2:\"");
\r
1699 svnCmd += folder_;
\r
1700 svnCmd += _T("\"");
\r
1701 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1702 svnCmd += _T(" /alternative");
\r
1704 case ShellMenuPrevDiff:
\r
1705 svnCmd += _T("prevdiff /path:\"");
\r
1706 if (files_.size() == 1)
\r
1707 svnCmd += files_.front();
\r
1709 svnCmd += folder_;
\r
1710 svnCmd += _T("\"");
\r
1711 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1712 svnCmd += _T(" /alternative");
\r
1714 case ShellMenuUrlDiff:
\r
1715 svnCmd += _T("urldiff /path:\"");
\r
1716 if (files_.size() == 1)
\r
1717 svnCmd += files_.front();
\r
1719 svnCmd += folder_;
\r
1720 svnCmd += _T("\"");
\r
1722 case ShellMenuDropCopyAdd:
\r
1723 tempfile = WriteFileListToTempFile();
\r
1724 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1725 svnCmd += tempfile;
\r
1726 svnCmd += _T("\"");
\r
1727 svnCmd += _T(" /deletepathfile");
\r
1728 svnCmd += _T(" /droptarget:\"");
\r
1729 svnCmd += folder_;
\r
1730 svnCmd += _T("\"";)
\r
1732 case ShellMenuDropCopy:
\r
1733 tempfile = WriteFileListToTempFile();
\r
1734 svnCmd += _T("dropcopy /pathfile:\"");
\r
1735 svnCmd += tempfile;
\r
1736 svnCmd += _T("\"");
\r
1737 svnCmd += _T(" /deletepathfile");
\r
1738 svnCmd += _T(" /droptarget:\"");
\r
1739 svnCmd += folder_;
\r
1740 svnCmd += _T("\"";)
\r
1742 case ShellMenuDropCopyRename:
\r
1743 tempfile = WriteFileListToTempFile();
\r
1744 svnCmd += _T("dropcopy /pathfile:\"");
\r
1745 svnCmd += tempfile;
\r
1746 svnCmd += _T("\"");
\r
1747 svnCmd += _T(" /deletepathfile");
\r
1748 svnCmd += _T(" /droptarget:\"");
\r
1749 svnCmd += folder_;
\r
1750 svnCmd += _T("\" /rename";)
\r
1752 case ShellMenuDropMove:
\r
1753 tempfile = WriteFileListToTempFile();
\r
1754 svnCmd += _T("dropmove /pathfile:\"");
\r
1755 svnCmd += tempfile;
\r
1756 svnCmd += _T("\"");
\r
1757 svnCmd += _T(" /deletepathfile");
\r
1758 svnCmd += _T(" /droptarget:\"");
\r
1759 svnCmd += folder_;
\r
1760 svnCmd += _T("\"");
\r
1762 case ShellMenuDropMoveRename:
\r
1763 tempfile = WriteFileListToTempFile();
\r
1764 svnCmd += _T("dropmove /pathfile:\"");
\r
1765 svnCmd += tempfile;
\r
1766 svnCmd += _T("\"");
\r
1767 svnCmd += _T(" /deletepathfile");
\r
1768 svnCmd += _T(" /droptarget:\"");
\r
1769 svnCmd += folder_;
\r
1770 svnCmd += _T("\" /rename";)
\r
1772 case ShellMenuDropExport:
\r
1773 tempfile = WriteFileListToTempFile();
\r
1774 svnCmd += _T("dropexport /pathfile:\"");
\r
1775 svnCmd += tempfile;
\r
1776 svnCmd += _T("\"");
\r
1777 svnCmd += _T(" /deletepathfile");
\r
1778 svnCmd += _T(" /droptarget:\"");
\r
1779 svnCmd += folder_;
\r
1780 svnCmd += _T("\"");
\r
1782 case ShellMenuDropExportExtended:
\r
1783 tempfile = WriteFileListToTempFile();
\r
1784 svnCmd += _T("dropexport /pathfile:\"");
\r
1785 svnCmd += tempfile;
\r
1786 svnCmd += _T("\"");
\r
1787 svnCmd += _T(" /deletepathfile");
\r
1788 svnCmd += _T(" /droptarget:\"");
\r
1789 svnCmd += folder_;
\r
1790 svnCmd += _T("\"");
\r
1791 svnCmd += _T(" /extended");
\r
1793 case ShellMenuLog:
\r
1794 svnCmd += _T("log /path:\"");
\r
1795 if (files_.size() > 0)
\r
1796 svnCmd += files_.front();
\r
1798 svnCmd += folder_;
\r
1799 svnCmd += _T("\"");
\r
1801 case ShellMenuConflictEditor:
\r
1802 svnCmd += _T("conflicteditor /path:\"");
\r
1803 if (files_.size() > 0)
\r
1804 svnCmd += files_.front();
\r
1806 svnCmd += folder_;
\r
1807 svnCmd += _T("\"");
\r
1809 case ShellMenuRelocate:
\r
1810 svnCmd += _T("relocate /path:\"");
\r
1811 if (files_.size() > 0)
\r
1812 svnCmd += files_.front();
\r
1814 svnCmd += folder_;
\r
1815 svnCmd += _T("\"");
\r
1817 case ShellMenuRebase:
\r
1818 svnCmd += _T("rebase /path:\"");
\r
1819 if (files_.size() > 0)
\r
1820 svnCmd += files_.front();
\r
1822 svnCmd += folder_;
\r
1823 svnCmd += _T("\"");
\r
1825 case ShellMenuShowChanged:
\r
1826 if (files_.size() > 1)
\r
1828 tempfile = WriteFileListToTempFile();
\r
1829 svnCmd += _T("repostatus /pathfile:\"");
\r
1830 svnCmd += tempfile;
\r
1831 svnCmd += _T("\"");
\r
1832 svnCmd += _T(" /deletepathfile");
\r
1836 svnCmd += _T("repostatus /path:\"");
\r
1837 if (files_.size() > 0)
\r
1838 svnCmd += files_.front();
\r
1840 svnCmd += folder_;
\r
1841 svnCmd += _T("\"");
\r
1844 case ShellMenuRefLog:
\r
1845 svnCmd += _T("reflog /path:\"");
\r
1846 if (files_.size() > 0)
\r
1847 svnCmd += files_.front();
\r
1849 svnCmd += folder_;
\r
1850 svnCmd += _T("\"");
\r
1853 case ShellMenuStashSave:
\r
1854 svnCmd += _T("stashsave /path:\"");
\r
1855 if (files_.size() > 0)
\r
1856 svnCmd += files_.front();
\r
1858 svnCmd += folder_;
\r
1859 svnCmd += _T("\"");
\r
1862 case ShellMenuStashApply:
\r
1863 svnCmd += _T("stashapply /path:\"");
\r
1864 if (files_.size() > 0)
\r
1865 svnCmd += files_.front();
\r
1867 svnCmd += folder_;
\r
1868 svnCmd += _T("\"");
\r
1871 case ShellMenuStashList:
\r
1872 svnCmd += _T("reflog /path:\"");
\r
1873 if (files_.size() > 0)
\r
1874 svnCmd += files_.front();
\r
1876 svnCmd += folder_;
\r
1877 svnCmd += _T("\" /ref:refs/stash");
\r
1880 case ShellMenuSubAdd:
\r
1881 svnCmd += _T("subadd /path:\"");
\r
1882 if (files_.size() > 0)
\r
1883 svnCmd += files_.front();
\r
1885 svnCmd += folder_;
\r
1886 svnCmd += _T("\"");
\r
1889 case ShellMenuBlame:
\r
1890 svnCmd += _T("blame /path:\"");
\r
1891 if (files_.size() > 0)
\r
1892 svnCmd += files_.front();
\r
1894 svnCmd += folder_;
\r
1895 svnCmd += _T("\"");
\r
1897 case ShellMenuCreatePatch:
\r
1898 tempfile = WriteFileListToTempFile();
\r
1899 svnCmd += _T("createpatch /pathfile:\"");
\r
1900 svnCmd += tempfile;
\r
1901 svnCmd += _T("\"");
\r
1902 svnCmd += _T(" /deletepathfile");
\r
1904 case ShellMenuApplyPatch:
\r
1905 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1907 // if there's a patch file in the clipboard, we save it
\r
1908 // to a temporary file and tell TortoiseMerge to use that one
\r
1909 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1910 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1912 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1913 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1915 DWORD len = GetTempPath(0, NULL);
\r
1916 TCHAR * path = new TCHAR[len+1];
\r
1917 TCHAR * tempF = new TCHAR[len+100];
\r
1918 GetTempPath (len+1, path);
\r
1919 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1920 std::wstring sTempFile = std::wstring(tempF);
\r
1925 size_t patchlen = strlen(lpstr);
\r
1926 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1929 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1930 if (size == patchlen)
\r
1932 itemStates |= ITEMIS_PATCHFILE;
\r
1934 files_.push_back(sTempFile);
\r
1938 GlobalUnlock(hglb);
\r
1939 CloseClipboard();
\r
1942 if (itemStates & ITEMIS_PATCHFILE)
\r
1944 svnCmd = _T(" /diff:\"");
\r
1945 if (files_.size() > 0)
\r
1947 svnCmd += files_.front();
\r
1948 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1950 svnCmd += _T("\" /patchpath:\"");
\r
1951 svnCmd += folder_;
\r
1955 svnCmd += folder_;
\r
1956 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1957 svnCmd += _T("\" /wc");
\r
1959 svnCmd += _T("\"");
\r
1963 svnCmd = _T(" /patchpath:\"");
\r
1964 if (files_.size() > 0)
\r
1965 svnCmd += files_.front();
\r
1967 svnCmd += folder_;
\r
1968 svnCmd += _T("\"");
\r
1971 myVerbsIDMap.clear();
\r
1972 myVerbsMap.clear();
\r
1973 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1976 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1977 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1978 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1981 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1982 (LPTSTR) &lpMsgBuf,
\r
1986 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
1987 LocalFree( lpMsgBuf );
\r
1989 CloseHandle(process.hThread);
\r
1990 CloseHandle(process.hProcess);
\r
1993 case ShellMenuRevisionGraph:
\r
1994 svnCmd += _T("revisiongraph /path:\"");
\r
1995 if (files_.size() > 0)
\r
1996 svnCmd += files_.front();
\r
1998 svnCmd += folder_;
\r
1999 svnCmd += _T("\"");
\r
2001 case ShellMenuProperties:
\r
2002 tempfile = WriteFileListToTempFile();
\r
2003 svnCmd += _T("properties /pathfile:\"");
\r
2004 svnCmd += tempfile;
\r
2005 svnCmd += _T("\"");
\r
2006 svnCmd += _T(" /deletepathfile");
\r
2008 case ShellMenuClipPaste:
\r
2009 if (WriteClipboardPathsToTempFile(tempfile))
\r
2011 bool bCopy = true;
\r
2012 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
2013 if (cPrefDropFormat)
\r
2015 if (OpenClipboard(lpcmi->hwnd))
\r
2017 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
2020 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
2021 if (*effect == DROPEFFECT_MOVE)
\r
2023 GlobalUnlock(hglb);
\r
2030 svnCmd += _T("pastecopy /pathfile:\"");
\r
2032 svnCmd += _T("pastemove /pathfile:\"");
\r
2033 svnCmd += tempfile;
\r
2034 svnCmd += _T("\"");
\r
2035 svnCmd += _T(" /deletepathfile");
\r
2036 svnCmd += _T(" /droptarget:\"");
\r
2037 svnCmd += folder_;
\r
2038 svnCmd += _T("\"");
\r
2040 else return NOERROR;
\r
2042 case ShellMenuClone:
\r
2043 svnCmd += _T("clone /path:\"");
\r
2044 svnCmd += folder_;
\r
2045 svnCmd += _T("\"");
\r
2047 case ShellMenuPull:
\r
2048 svnCmd += _T("pull /path:\"");
\r
2049 if (files_.size() > 0)
\r
2050 svnCmd += files_.front();
\r
2052 svnCmd += folder_;
\r
2053 svnCmd += _T("\"");
\r
2055 case ShellMenuPush:
\r
2056 svnCmd += _T("push /path:\"");
\r
2057 if (files_.size() > 0)
\r
2058 svnCmd += files_.front();
\r
2060 svnCmd += folder_;
\r
2061 svnCmd += _T("\"");
\r
2063 case ShellMenuBranch:
\r
2064 svnCmd += _T("branch /path:\"");
\r
2065 if (files_.size() > 0)
\r
2066 svnCmd += files_.front();
\r
2068 svnCmd += folder_;
\r
2069 svnCmd += _T("\"");
\r
2072 case ShellMenuTag:
\r
2073 svnCmd += _T("tag /path:\"");
\r
2074 if (files_.size() > 0)
\r
2075 svnCmd += files_.front();
\r
2077 svnCmd += folder_;
\r
2078 svnCmd += _T("\"");
\r
2081 case ShellMenuFormatPatch:
\r
2082 svnCmd += _T("formatpatch /path:\"");
\r
2083 if (files_.size() > 0)
\r
2084 svnCmd += files_.front();
\r
2086 svnCmd += folder_;
\r
2087 svnCmd += _T("\"");
\r
2090 case ShellMenuImportPatch:
\r
2091 tempfile = WriteFileListToTempFile();
\r
2092 svnCmd += _T("importpatch /pathfile:\"");
\r
2093 svnCmd += tempfile;
\r
2094 svnCmd += _T("\"");
\r
2095 svnCmd += _T(" /deletepathfile");
\r
2098 case ShellMenuCherryPick:
\r
2099 svnCmd += _T("cherrypick /path:\"");
\r
2100 if (files_.size() > 0)
\r
2101 svnCmd += files_.front();
\r
2103 svnCmd += folder_;
\r
2104 svnCmd += _T("\"");
\r
2106 case ShellMenuFetch:
\r
2107 svnCmd += _T("fetch /path:\"");
\r
2108 if (files_.size() > 0)
\r
2109 svnCmd += files_.front();
\r
2111 svnCmd += folder_;
\r
2112 svnCmd += _T("\"");
\r
2118 } // switch (id_it->second)
\r
2119 svnCmd += _T(" /hwnd:");
\r
2121 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
2124 myVerbsIDMap.clear();
\r
2125 myVerbsMap.clear();
\r
2126 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2129 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2130 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2131 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2134 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2135 (LPTSTR) &lpMsgBuf,
\r
2139 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2140 LocalFree( lpMsgBuf );
\r
2142 CloseHandle(process.hThread);
\r
2143 CloseHandle(process.hProcess);
\r
2145 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
2146 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
2151 // This is for the status bar and things like that:
\r
2152 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
2154 UINT FAR * /*reserved*/,
\r
2158 PreserveChdir preserveChdir;
\r
2159 //do we know the id?
\r
2160 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
2161 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
2163 return E_INVALIDARG; //no, we don't
\r
2167 HRESULT hr = E_INVALIDARG;
\r
2169 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
2170 int menuIndex = 0;
\r
2171 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2173 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
2175 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
2181 const TCHAR * desc = stringtablebuffer;
\r
2184 case GCS_HELPTEXTA:
\r
2186 std::string help = WideToMultibyte(desc);
\r
2187 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2191 case GCS_HELPTEXTW:
\r
2193 wide_string help = desc;
\r
2194 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2200 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2201 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2203 std::string help = WideToMultibyte(verb_id_it->second);
\r
2204 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2211 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2212 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2214 wide_string help = verb_id_it->second;
\r
2215 ATLTRACE("verb : %ws\n", help.c_str());
\r
2216 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2225 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2228 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2231 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2233 PreserveChdir preserveChdir;
\r
2236 if (pResult == NULL)
\r
2243 case WM_MEASUREITEM:
\r
2245 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2246 if (lpmis==NULL||lpmis->CtlType!=ODT_MENU)
\r
2248 lpmis->itemWidth += 2;
\r
2249 if (lpmis->itemHeight < 16)
\r
2250 lpmis->itemHeight = 16;
\r
2257 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2258 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2259 return S_OK; //not for a menu
\r
2260 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2261 if (resource == NULL)
\r
2263 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2264 if (hIcon == NULL)
\r
2266 DrawIconEx(lpdis->hDC,
\r
2267 lpdis->rcItem.left - 16,
\r
2268 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2270 0, NULL, DI_NORMAL);
\r
2271 DestroyIcon(hIcon);
\r
2279 if (HIWORD(wParam) != MF_POPUP)
\r
2281 int nChar = LOWORD(wParam);
\r
2282 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2283 nChar = tolower(nChar);
\r
2284 // we have the char the user pressed, now search that char in all our
\r
2286 std::vector<int> accmenus;
\r
2287 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2289 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2290 if (resource == NULL)
\r
2292 szItem = stringtablebuffer;
\r
2293 TCHAR * amp = _tcschr(szItem, '&');
\r
2297 int ampChar = LOWORD(*amp);
\r
2298 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2299 ampChar = tolower(ampChar);
\r
2300 if (ampChar == nChar)
\r
2302 // yep, we found a menu which has the pressed key
\r
2303 // as an accelerator. Add that menu to the list to
\r
2305 accmenus.push_back(It->first);
\r
2308 if (accmenus.size() == 0)
\r
2310 // no menu with that accelerator key.
\r
2311 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2314 if (accmenus.size() == 1)
\r
2316 // Only one menu with that accelerator key. We're lucky!
\r
2317 // So just execute that menu entry.
\r
2318 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2321 if (accmenus.size() > 1)
\r
2323 // we have more than one menu item with this accelerator key!
\r
2325 mif.cbSize = sizeof(MENUITEMINFO);
\r
2326 mif.fMask = MIIM_STATE;
\r
2327 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2329 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2330 if (mif.fState == MFS_HILITE)
\r
2332 // this is the selected item, so select the next one
\r
2334 if (it == accmenus.end())
\r
2335 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2337 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2341 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2352 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2354 TCHAR textbuf[255];
\r
2355 LPCTSTR resource = NULL;
\r
2356 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2359 int menuIndex = 0;
\r
2360 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2362 if (menuInfo[menuIndex].command == id)
\r
2364 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2365 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2368 case ShellSubMenuMultiple:
\r
2369 case ShellSubMenuLink:
\r
2370 case ShellSubMenuFolder:
\r
2371 case ShellSubMenuFile:
\r
2372 case ShellSubMenu:
\r
2376 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2377 if (layout & (menuInfo[menuIndex].menuID))
\r
2379 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2380 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2381 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2392 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2395 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2396 LPITEMIDLIST pidl = NULL;
\r
2397 while (cslidarray[i])
\r
2401 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2403 if (!SHGetPathFromIDList(pidl, buf))
\r
2405 // not a file system path, definitely illegal for our use
\r
2406 CoTaskMemFree(pidl);
\r
2409 CoTaskMemFree(pidl);
\r
2410 if (_tcslen(buf)==0)
\r
2412 if (_tcscmp(buf, folder.c_str())==0)
\r
2418 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags)
\r
2420 HMENU ignoresubmenu = NULL;
\r
2421 int indexignoresub = 0;
\r
2422 bool bShowIgnoreMenu = false;
\r
2423 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2424 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2425 if (files_.size() == 0)
\r
2427 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2429 std::vector<stdstring>::iterator I = files_.begin();
\r
2430 if (_tcsrchr(I->c_str(), '\\'))
\r
2431 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2433 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2434 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2436 // check if the item name is ignored or the mask
\r
2438 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2440 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2441 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2449 ignoresubmenu = CreateMenu();
\r
2450 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2451 stdstring verb = stdstring(ignorepath);
\r
2452 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2453 myVerbsMap[verb] = idCmd;
\r
2454 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2455 myVerbsIDMap[idCmd] = verb;
\r
2456 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2457 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2458 bShowIgnoreMenu = true;
\r
2460 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2461 if (_tcsrchr(ignorepath, '.'))
\r
2463 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2464 p = ignoredprops.find(maskbuf);
\r
2466 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2468 if (ignoresubmenu==NULL)
\r
2469 ignoresubmenu = CreateMenu();
\r
2471 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2472 stdstring verb = stdstring(maskbuf);
\r
2473 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2474 myVerbsMap[verb] = idCmd;
\r
2475 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2476 myVerbsIDMap[idCmd] = verb;
\r
2477 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2478 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2479 bShowIgnoreMenu = true;
\r
2483 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2485 bShowIgnoreMenu = true;
\r
2486 ignoresubmenu = CreateMenu();
\r
2487 if (itemStates & ITEMIS_ONLYONE)
\r
2489 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2490 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2491 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2493 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2494 if (_tcsrchr(ignorepath, '.'))
\r
2496 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2497 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2498 stdstring verb = stdstring(maskbuf);
\r
2499 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2500 myVerbsMap[verb] = idCmd;
\r
2501 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2502 myVerbsIDMap[idCmd] = verb;
\r
2503 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2504 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2509 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2510 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2511 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2512 stdstring verb = stdstring(ignorepath);
\r
2513 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2514 myVerbsMap[verb] = idCmd;
\r
2515 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2516 myVerbsIDMap[idCmd] = verb;
\r
2517 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2518 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2520 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2521 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2522 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2523 verb = stdstring(ignorepath);
\r
2524 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2525 myVerbsMap[verb] = idCmd;
\r
2526 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2527 myVerbsIDMap[idCmd] = verb;
\r
2528 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2529 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2533 if (bShowIgnoreMenu)
\r
2535 MENUITEMINFO menuiteminfo;
\r
2536 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2537 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2538 if (fullver < 0x500 || (fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
2540 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
2543 HBITMAP bmp = IconToBitmap(icon);
\r
2544 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
2545 menuiteminfo.hbmpChecked = bmp;
\r
2546 menuiteminfo.hbmpUnchecked = bmp;
\r
2551 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
2554 menuiteminfo.fMask |= MIIM_BITMAP;
\r
2555 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
2558 menuiteminfo.fType = MFT_STRING;
\r
2559 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2560 menuiteminfo.wID = idCmd;
\r
2561 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2562 if (itemStates & ITEMIS_IGNORED)
\r
2563 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2565 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2566 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2567 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2569 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2570 if (itemStates & ITEMIS_IGNORED)
\r
2572 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2573 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2577 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2578 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2583 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2585 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2586 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2587 return bitmap_it->second;
\r
2589 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2593 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2597 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2598 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2601 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2602 HBITMAP hBmp = NULL;
\r
2604 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2607 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2609 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2612 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2613 BP_PAINTPARAMS paintParams = {0};
\r
2614 paintParams.cbSize = sizeof(paintParams);
\r
2615 paintParams.dwFlags = BPPF_ERASE;
\r
2616 paintParams.pBlendFunction = &bfAlpha;
\r
2619 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2622 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2624 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2625 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2628 // This will write the buffer contents to the destination bitmap
\r
2629 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2632 SelectObject(hdcDest, hbmpOld);
\r
2636 DeleteDC(hdcDest);
\r
2639 DestroyIcon(hIcon);
\r
2642 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2646 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2651 ZeroMemory(&bmi, sizeof(bmi));
\r
2652 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2653 bmi.bmiHeader.biPlanes = 1;
\r
2654 bmi.bmiHeader.biCompression = BI_RGB;
\r
2656 bmi.bmiHeader.biWidth = psize->cx;
\r
2657 bmi.bmiHeader.biHeight = psize->cy;
\r
2658 bmi.bmiHeader.biBitCount = 32;
\r
2660 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2663 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2664 if (hdc != hdcUsed)
\r
2666 ReleaseDC(NULL, hdcUsed);
\r
2669 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2672 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2674 RGBQUAD *prgbQuad;
\r
2676 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2677 if (SUCCEEDED(hr))
\r
2679 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2680 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2683 if (GetIconInfo(hicon, &info))
\r
2687 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2690 DeleteObject(info.hbmColor);
\r
2691 DeleteObject(info.hbmMask);
\r
2699 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2701 ULONG cxDelta = cxRow - sizImage.cx;
\r
2702 for (ULONG y = sizImage.cy; y; --y)
\r
2704 for (ULONG x = sizImage.cx; x; --x)
\r
2706 if (*pargb++ & 0xFF000000)
\r
2718 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2721 ZeroMemory(&bmi, sizeof(bmi));
\r
2722 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2723 bmi.bmiHeader.biPlanes = 1;
\r
2724 bmi.bmiHeader.biCompression = BI_RGB;
\r
2726 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2727 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2728 bmi.bmiHeader.biBitCount = 32;
\r
2730 HRESULT hr = E_OUTOFMEMORY;
\r
2731 HANDLE hHeap = GetProcessHeap();
\r
2732 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2735 hr = E_UNEXPECTED;
\r
2736 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2738 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2739 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2741 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2743 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2747 // transparent pixel
\r
2753 *pargb++ |= 0xFF000000;
\r
2763 HeapFree(hHeap, 0, pvBits);
\r