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_MENUPUSH,
\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
53 { ShellSeparator, ITEMIS_GITSVN, 0, 0, 0, 0, 0, 0, 0},
\r
55 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
56 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
58 { ShellMenuGitSVNDCommit, MENUSVNDCOMMIT, IDI_COMMIT, IDS_MENUSVNDCOMMIT, IDS_MENUSVNDCOMMIT_DESC,
\r
59 ITEMIS_INSVN|ITEMIS_GITSVN, 0, ITEMIS_FOLDERINSVN|ITEMIS_GITSVN, 0, 0, 0, 0, 0 },
\r
61 { ShellMenuGitSVNRebase, MENUSVNREBASE, IDI_REBASE, IDS_MENUSVNREBASE, IDS_MENUSVNREBASE_DESC,
\r
62 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_GITSVN, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_GITSVN, 0, 0, 0, 0, 0},
\r
64 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
66 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
67 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
69 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
70 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
72 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
73 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
75 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
76 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
78 { ShellMenuRefLog, MENUREFLOG, IDI_LOG, IDS_MENUREFLOG, IDS_MENUDESCREFLOG,
\r
79 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
81 { ShellMenuRefBrowse, MENUREFBROWSE, IDI_REPOBROWSE, IDS_MENUREFBROWSE, IDS_MENUDESCREFBROWSE,
\r
82 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
85 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
86 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
88 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
89 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
91 { ShellMenuRebase, MENUREBASE, IDI_REBASE, IDS_MENUREBASE, IDS_MENUREBASE,
\r
92 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
94 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
95 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
97 { ShellMenuStashSave, MENUSTASHSAVE, IDI_COMMIT, IDS_MENUSTASHSAVE, IDS_MENUSTASHSAVE,
\r
98 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
99 { ShellMenuStashApply, MENUSTASHAPPLY, IDI_RELOCATE, IDS_MENUSTASHAPPLY, IDS_MENUSTASHAPPLY,
\r
100 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
101 { ShellMenuStashList, MENUSTASHAPPLY, IDI_LOG, IDS_MENUSTASHLIST, IDS_MENUSTASHLIST,
\r
102 ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
105 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
107 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
108 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
110 { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
111 ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
114 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
115 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
117 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
118 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
120 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
121 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
123 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
124 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
126 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
127 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
129 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
130 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
132 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
133 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
135 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
136 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
138 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
139 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
141 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
142 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
144 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
146 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
147 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
149 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
150 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
152 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
153 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
154 // { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
155 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
157 { ShellMenuBranch, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
158 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
159 { ShellMenuTag, MENUTAG, IDI_TAG, IDS_MENUTAG, IDS_MENUDESCCOPY,
\r
160 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
162 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
163 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
165 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
166 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
168 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
170 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
171 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
173 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
174 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
176 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
177 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
179 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
180 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
182 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
183 ITEMIS_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
184 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
\r
185 // why was this changed, is this related to GitStatus?
\r
187 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
188 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
190 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
191 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
193 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
195 { ShellMenuSubAdd, MENUSUBADD, IDI_ADD, IDS_MENUSUBADD, IDS_MENUSUBADD,
\r
196 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
198 { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
199 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE, 0, 0, 0, 0, 0, 0, 0 },
\r
201 { ShellMenuSubSync, MENUSUBSYNC, IDI_MENUSYNC, IDS_MENUSUBSYNC, IDS_MENUSUBSYNC,
\r
202 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0, 0, 0 },
\r
206 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
208 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
209 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
211 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
212 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
214 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
215 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, ITEMIS_PATCHFILE, 0, 0, 0 },
\r
218 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
219 ITEMIS_INSVN|ITEMIS_EXTENDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
221 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
222 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0 },
\r
224 { ShellMenuSendMail, MENUSENDMAIL, IDI_MENUSENDMAIL, IDS_MENUSENDMAIL, IDS_MENUDESSENDMAIL,
\r
225 ITEMIS_PATCHFILE, 0, 0, 0, 0, 0, 0, 0 },
\r
227 // { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
228 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
230 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
231 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
232 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
234 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
236 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
237 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
238 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
239 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
240 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
241 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
243 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
244 // but they still need to be in here, because we use the icon and string information anyway.
\r
245 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
246 0, 0, 0, 0, 0, 0, 0, 0 },
\r
247 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
248 0, 0, 0, 0, 0, 0, 0, 0 },
\r
249 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
250 0, 0, 0, 0, 0, 0, 0, 0 },
\r
251 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
252 0, 0, 0, 0, 0, 0, 0, 0 },
\r
253 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
254 0, 0, 0, 0, 0, 0, 0, 0 },
\r
255 // mark the last entry to tell the loop where to stop iterating over this array
\r
256 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
257 0, 0, 0, 0, 0, 0, 0, 0 },
\r
261 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
262 LPDATAOBJECT pDataObj,
\r
263 HKEY /* hRegKey */)
\r
266 ATLTRACE("Shell :: Initialize\n");
\r
267 PreserveChdir preserveChdir;
\r
270 uuidSource.erase();
\r
271 uuidTarget.erase();
\r
273 itemStatesFolder = 0;
\r
274 stdstring statuspath;
\r
275 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
276 // get selected files/folders
\r
280 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
281 (DVTARGETDEVICE FAR *)NULL,
\r
285 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
287 if (SUCCEEDED(hres) && medium.hGlobal)
\r
289 if (m_State == FileStateDropHandler)
\r
292 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
293 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
294 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
296 ReleaseStgMedium ( &medium );
\r
297 return E_INVALIDARG;
\r
301 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
302 if ( NULL == drop )
\r
304 ReleaseStgMedium ( &stg );
\r
305 ReleaseStgMedium ( &medium );
\r
306 return E_INVALIDARG;
\r
309 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
311 itemStates |= ITEMIS_ONLYONE;
\r
312 for (int i = 0; i < count; i++)
\r
314 // find the path length in chars
\r
315 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
318 TCHAR * szFileName = new TCHAR[len+1];
\r
319 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
321 delete [] szFileName;
\r
324 stdstring str = stdstring(szFileName);
\r
325 delete [] szFileName;
\r
326 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
328 if (itemStates & ITEMIS_ONLYONE)
\r
331 strpath.SetFromWin(str.c_str());
\r
332 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
333 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
335 files_.push_back(str);
\r
338 //get the Subversion status of the item
\r
339 git_wc_status_kind status = git_wc_status_none;
\r
340 CTGitPath askedpath;
\r
341 askedpath.SetFromWin(str.c_str());
\r
345 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
349 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
350 fetchedstatus = status;
\r
351 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
352 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
353 if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
355 itemStates |= ITEMIS_FOLDER;
\r
356 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
357 itemStates |= ITEMIS_FOLDERINSVN;
\r
359 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
361 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
362 // itemStates |= ITEMIS_NEEDSLOCK;
\r
364 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
365 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
369 // sometimes, git_client_status() returns with an error.
\r
370 // in that case, we have to check if the working copy is versioned
\r
371 // anyway to show the 'correct' context menu
\r
372 if (askedpath.HasAdminDir())
\r
373 status = git_wc_status_normal;
\r
378 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
381 // TODO: should we really assume any sub-directory to be versioned
\r
382 // or only if it contains versioned files
\r
383 if ( askedpath.IsDirectory() )
\r
385 if (askedpath.HasAdminDir())
\r
386 itemStates |= ITEMIS_INSVN;
\r
387 if (askedpath.HasSubmodules())
\r
389 itemStates |= ITEMIS_SUBMODULE;
\r
392 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
393 itemStates |= ITEMIS_INSVN;
\r
394 if (status == git_wc_status_ignored)
\r
395 itemStates |= ITEMIS_IGNORED;
\r
396 if (status == git_wc_status_normal)
\r
397 itemStates |= ITEMIS_NORMAL;
\r
398 if (status == git_wc_status_conflicted)
\r
399 itemStates |= ITEMIS_CONFLICTED;
\r
400 if (status == git_wc_status_added)
\r
401 itemStates |= ITEMIS_ADDED;
\r
402 if (status == git_wc_status_deleted)
\r
403 itemStates |= ITEMIS_DELETED;
\r
406 } // for (int i = 0; i < count; i++)
\r
407 GlobalUnlock ( drop );
\r
408 ReleaseStgMedium ( &stg );
\r
410 } // if (m_State == FileStateDropHandler)
\r
414 //Enumerate PIDLs which the user has selected
\r
415 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
416 ItemIDList parent( GetPIDLFolder (cida));
\r
418 int count = cida->cidl;
\r
419 BOOL statfetched = FALSE;
\r
420 for (int i = 0; i < count; ++i)
\r
422 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
423 stdstring str = child.toString();
\r
424 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
426 //check if our menu is requested for a subversion admin directory
\r
427 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
430 files_.push_back(str);
\r
432 strpath.SetFromWin(str.c_str());
\r
433 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
434 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
437 //get the Subversion status of the item
\r
438 git_wc_status_kind status = git_wc_status_none;
\r
439 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
441 if (strpath.HasAdminDir())
\r
442 status = git_wc_status_normal;
\r
449 if (strpath.HasAdminDir())
\r
450 stat.GetStatus(strpath, false, true, true);
\r
454 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
455 fetchedstatus = status;
\r
456 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
457 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
458 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
460 itemStates |= ITEMIS_FOLDER;
\r
461 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
462 itemStates |= ITEMIS_FOLDERINSVN;
\r
464 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
\r
465 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
466 itemStates |= ITEMIS_CONFLICTED;
\r
467 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
469 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
470 // itemStates |= ITEMIS_NEEDSLOCK;
\r
472 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
473 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
477 // sometimes, git_client_status() returns with an error.
\r
478 // in that case, we have to check if the working copy is versioned
\r
479 // anyway to show the 'correct' context menu
\r
480 if (strpath.HasAdminDir())
\r
482 status = git_wc_status_normal;
\r
483 fetchedstatus = status;
\r
486 statfetched = TRUE;
\r
490 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
494 // TODO: should we really assume any sub-directory to be versioned
\r
495 // or only if it contains versioned files
\r
496 if ( strpath.IsDirectory() )
\r
498 if (strpath.HasAdminDir())
\r
499 itemStates |= ITEMIS_INSVN;
\r
500 if (strpath.HasSubmodules())
\r
502 itemStates |= ITEMIS_SUBMODULE;
\r
505 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
506 itemStates |= ITEMIS_INSVN;
\r
507 if (status == git_wc_status_ignored)
\r
509 itemStates |= ITEMIS_IGNORED;
\r
510 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
511 // offer a 'remove from ignored list' entry
\r
512 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
513 // ignoredprops.empty();
\r
514 // for (int p=0; p<props.GetCount(); ++p)
\r
516 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
518 // std::string st = props.GetItemValue(p);
\r
519 // ignoredprops = MultibyteToWide(st.c_str());
\r
520 // // remove all escape chars ('\\')
\r
521 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
526 if (status == git_wc_status_normal)
\r
527 itemStates |= ITEMIS_NORMAL;
\r
528 if (status == git_wc_status_conflicted)
\r
529 itemStates |= ITEMIS_CONFLICTED;
\r
530 if (status == git_wc_status_added)
\r
531 itemStates |= ITEMIS_ADDED;
\r
532 if (status == git_wc_status_deleted)
\r
533 itemStates |= ITEMIS_DELETED;
\r
536 } // for (int i = 0; i < count; ++i)
\r
537 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
538 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
539 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
540 GlobalUnlock(medium.hGlobal);
\r
542 // if the item is a versioned folder, check if there's a patch file
\r
543 // in the clipboard to be used in "Apply Patch"
\r
544 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
547 if (IsClipboardFormatAvailable(cFormatDiff))
\r
548 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
550 if (IsClipboardFormatAvailable(CF_HDROP))
\r
551 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
555 ReleaseStgMedium ( &medium );
\r
556 if (medium.pUnkForRelease)
\r
558 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
559 relInterface->Release();
\r
564 // get folder background
\r
568 ItemIDList list(pIDFolder);
\r
569 folder_ = list.toString();
\r
570 git_wc_status_kind status = git_wc_status_none;
\r
571 if (IsClipboardFormatAvailable(CF_HDROP))
\r
572 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
574 CTGitPath askedpath;
\r
575 askedpath.SetFromWin(folder_.c_str());
\r
577 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
583 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
586 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
587 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
588 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
589 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
591 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
592 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
594 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
595 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
600 // sometimes, git_client_status() returns with an error.
\r
601 // in that case, we have to check if the working copy is versioned
\r
602 // anyway to show the 'correct' context menu
\r
603 if (askedpath.HasAdminDir())
\r
604 status = git_wc_status_normal;
\r
607 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
608 if (askedpath.HasAdminDir())
\r
609 itemStatesFolder |= ITEMIS_INSVN;
\r
610 if (status == git_wc_status_normal)
\r
611 itemStatesFolder |= ITEMIS_NORMAL;
\r
612 if (status == git_wc_status_conflicted)
\r
613 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
614 if (status == git_wc_status_added)
\r
615 itemStatesFolder |= ITEMIS_ADDED;
\r
616 if (status == git_wc_status_deleted)
\r
617 itemStatesFolder |= ITEMIS_DELETED;
\r
622 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
627 status = fetchedstatus;
\r
629 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
630 if (askedpath.HasAdminDir())
\r
632 itemStatesFolder |= ITEMIS_FOLDERINSVN;
\r
634 if (askedpath.HasSubmodules())
\r
636 itemStatesFolder |= ITEMIS_SUBMODULE;
\r
638 if (askedpath.HasGitSVNDir())
\r
640 itemStatesFolder |= ITEMIS_GITSVN;
\r
642 if (status == git_wc_status_ignored)
\r
643 itemStatesFolder |= ITEMIS_IGNORED;
\r
644 itemStatesFolder |= ITEMIS_FOLDER;
\r
645 if (files_.size() == 0)
\r
646 itemStates |= ITEMIS_ONLYONE;
\r
647 if (m_State != FileStateDropHandler)
\r
648 itemStates |= itemStatesFolder;
\r
652 if (files_.size() == 2)
\r
653 itemStates |= ITEMIS_TWO;
\r
654 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
657 itemStates |= ITEMIS_ONLYONE;
\r
658 if (m_State != FileStateDropHandler)
\r
660 if (PathIsDirectory(files_.front().c_str()))
\r
662 folder_ = files_.front();
\r
663 git_wc_status_kind status = git_wc_status_none;
\r
664 CTGitPath askedpath;
\r
665 askedpath.SetFromWin(folder_.c_str());
\r
667 if (folder_.compare(statuspath)!=0)
\r
672 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
675 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
676 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
677 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
678 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
680 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
681 // itemStates |= ITEMIS_NEEDSLOCK;
\r
683 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
684 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
689 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
694 status = fetchedstatus;
\r
696 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
697 if (askedpath.HasAdminDir())
\r
698 itemStates |= ITEMIS_FOLDERINSVN;
\r
699 if (status == git_wc_status_ignored)
\r
700 itemStates |= ITEMIS_IGNORED;
\r
701 itemStates |= ITEMIS_FOLDER;
\r
702 if (status == git_wc_status_added)
\r
703 itemStates |= ITEMIS_ADDED;
\r
704 if (status == git_wc_status_deleted)
\r
705 itemStates |= ITEMIS_DELETED;
\r
714 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
716 TCHAR menutextbuffer[512] = {0};
\r
717 TCHAR verbsbuffer[255] = {0};
\r
718 MAKESTRING(stringid);
\r
722 //menu entry for the top context menu, so append an "Git " before
\r
723 //the menu text to indicate where the entry comes from
\r
724 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
726 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
728 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
\r
729 // so we have an easy and fast way to check the current branch
\r
730 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
\r
731 if (com == ShellMenuCommit)
\r
734 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
735 CString sProjectRoot;
\r
736 CString sBranchName;
\r
738 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
740 if (sBranchName.GetLength() == 40)
\r
742 // if SHA1 only show 4 first bytes
\r
743 BOOL bIsSha1 = TRUE;
\r
744 for (int i=0; i<40; i++)
\r
745 if ( !iswxdigit(sBranchName[i]) )
\r
751 sBranchName = sBranchName.Left(8) + _T("....");
\r
755 if (sBranchName.GetLength() > 64)
\r
756 sBranchName = sBranchName.Left(64) + _T("...");
\r
758 // scan to before "..."
\r
759 LPTSTR s = menutextbuffer + _tcslen(menutextbuffer)-1;
\r
760 if (s > menutextbuffer)
\r
762 while (s > menutextbuffer)
\r
774 s = menutextbuffer;
\r
777 // append branch name and end with ...
\r
778 _tcscpy(s, _T(" -> \"") + sBranchName + _T("\"..."));
\r
782 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
784 // on win2k, the context menu does not work properly if we use
\r
785 // icon bitmaps. At least the menu text is empty in the context menu
\r
786 // for folder backgrounds (seems like a win2k bug).
\r
787 // the workaround is to use the check/unchecked bitmaps, which are drawn
\r
788 // with AND raster op, but it's better than nothing at all
\r
789 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
792 HBITMAP bmp = IconToBitmap(icon);
\r
793 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
798 MENUITEMINFO menuiteminfo;
\r
799 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
800 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
801 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
\r
802 menuiteminfo.fType = MFT_STRING;
\r
803 menuiteminfo.dwTypeData = menutextbuffer;
\r
806 menuiteminfo.fMask |= MIIM_BITMAP;
\r
807 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
809 menuiteminfo.wID = id;
\r
810 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
815 //menu entry for the top context menu, so append an "Git " before
\r
816 //the menu text to indicate where the entry comes from
\r
817 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
819 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
820 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
821 stdstring verb = stdstring(menutextbuffer);
\r
822 if (verb.find('&') != -1)
\r
824 verb.erase(verb.find('&'),1);
\r
826 myVerbsMap[verb] = id - idCmdFirst;
\r
827 myVerbsMap[verb] = id;
\r
828 myVerbsIDMap[id - idCmdFirst] = verb;
\r
829 myVerbsIDMap[id] = verb;
\r
830 // We store the relative and absolute diameter
\r
831 // (drawitem callback uses absolute, others relative)
\r
832 myIDMap[id - idCmdFirst] = com;
\r
835 mySubMenuMap[pos] = com;
\r
838 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
840 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
841 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
842 return bitmap_it->second;
\r
844 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
850 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
851 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
853 rect.left = rect.top = 0;
\r
855 HWND desktop = ::GetDesktopWindow();
\r
856 if (desktop == NULL)
\r
858 DestroyIcon(hIcon);
\r
862 HDC screen_dev = ::GetDC(desktop);
\r
863 if (screen_dev == NULL)
\r
865 DestroyIcon(hIcon);
\r
869 // Create a compatible DC
\r
870 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
871 if (dst_hdc == NULL)
\r
873 DestroyIcon(hIcon);
\r
874 ::ReleaseDC(desktop, screen_dev);
\r
878 // Create a new bitmap of icon size
\r
879 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
882 DestroyIcon(hIcon);
\r
883 ::DeleteDC(dst_hdc);
\r
884 ::ReleaseDC(desktop, screen_dev);
\r
888 // Select it into the compatible DC
\r
889 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
890 if (old_dst_bmp == NULL)
\r
892 DestroyIcon(hIcon);
\r
896 // Fill the background of the compatible DC with the white color
\r
897 // that is taken by menu routines as transparent
\r
898 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
899 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
901 // Draw the icon into the compatible DC
\r
902 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
904 // Restore settings
\r
905 ::SelectObject(dst_hdc, old_dst_bmp);
\r
906 ::DeleteDC(dst_hdc);
\r
907 ::ReleaseDC(desktop, screen_dev);
\r
908 DestroyIcon(hIcon);
\r
910 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
914 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
917 tempfile = stdstring();
\r
918 //write all selected files and paths to a temporary file
\r
919 //for TortoiseProc.exe to read out again.
\r
921 DWORD pathlength = GetTempPath(0, NULL);
\r
922 TCHAR * path = new TCHAR[pathlength+1];
\r
923 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
924 GetTempPath (pathlength+1, path);
\r
925 GetTempFileName (path, _T("git"), 0, tempFile);
\r
926 tempfile = stdstring(tempFile);
\r
928 HANDLE file = ::CreateFile (tempFile,
\r
933 FILE_ATTRIBUTE_TEMPORARY,
\r
937 delete [] tempFile;
\r
938 if (file == INVALID_HANDLE_VALUE)
\r
941 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
943 if (!OpenClipboard(NULL))
\r
946 stdstring sClipboardText;
\r
947 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
948 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
951 TCHAR szFileName[MAX_PATH];
\r
952 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
953 for(UINT i = 0; i < cFiles; ++i)
\r
955 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
956 stdstring filename = szFileName;
\r
957 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
958 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
960 GlobalUnlock(hDrop);
\r
963 GlobalUnlock(hglb);
\r
966 ::CloseHandle(file);
\r
971 stdstring CShellExt::WriteFileListToTempFile()
\r
973 //write all selected files and paths to a temporary file
\r
974 //for TortoiseProc.exe to read out again.
\r
975 DWORD pathlength = GetTempPath(0, NULL);
\r
976 TCHAR * path = new TCHAR[pathlength+1];
\r
977 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
978 GetTempPath (pathlength+1, path);
\r
979 GetTempFileName (path, _T("git"), 0, tempFile);
\r
980 stdstring retFilePath = stdstring(tempFile);
\r
982 HANDLE file = ::CreateFile (tempFile,
\r
987 FILE_ATTRIBUTE_TEMPORARY,
\r
991 delete [] tempFile;
\r
992 if (file == INVALID_HANDLE_VALUE)
\r
993 return stdstring();
\r
996 if (files_.empty())
\r
998 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
999 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
1002 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
1004 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
1005 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
1007 ::CloseHandle(file);
\r
1008 return retFilePath;
\r
1011 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
1013 PreserveChdir preserveChdir;
\r
1016 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1017 return NOERROR; //we don't change the default action
\r
1019 if ((files_.size() == 0)||(folder_.size() == 0))
\r
1022 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1025 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
1027 //the drop handler only has eight commands, but not all are visible at the same time:
\r
1028 //if the source file(s) are under version control then those files can be moved
\r
1029 //to the new location or they can be moved with a rename,
\r
1030 //if they are unversioned then they can be added to the working copy
\r
1031 //if they are versioned, they also can be exported to an unversioned location
\r
1032 UINT idCmd = idCmdFirst;
\r
1035 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1036 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
1037 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
1039 // Git move and rename here
\r
1040 // 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
1041 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1042 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
1045 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1046 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
1047 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
1049 // Git copy and rename here, source and target from same repository
\r
1050 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
1051 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1052 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
1055 // available if target is versioned and source is either unversioned or from another repository
\r
1056 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
1057 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
1059 // Git export here
\r
1060 // available if source is versioned and a folder
\r
1061 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1062 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
1064 // Git export all here
\r
1065 // available if source is versioned and a folder
\r
1066 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1067 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
1070 // available if source is a patchfile
\r
1071 if (itemStates & ITEMIS_PATCHFILE)
\r
1072 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
1075 if (idCmd != idCmdFirst)
\r
1076 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1078 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1081 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
1084 UINT /*idCmdLast*/,
\r
1087 ATLTRACE("Shell :: QueryContextMenu\n");
\r
1088 PreserveChdir preserveChdir;
\r
1090 //first check if our drop handler is called
\r
1091 //and then (if true) provide the context menu for the
\r
1093 if (m_State == FileStateDropHandler)
\r
1095 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
1098 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1099 return NOERROR; //we don't change the default action
\r
1101 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
1104 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1107 int csidlarray[] =
\r
1110 CSIDL_CDBURN_AREA,
\r
1111 CSIDL_COMMON_FAVORITES,
\r
1112 CSIDL_COMMON_STARTMENU,
\r
1113 CSIDL_COMPUTERSNEARME,
\r
1114 CSIDL_CONNECTIONS,
\r
1121 CSIDL_INTERNET_CACHE,
\r
1131 if (IsIllegalFolder(folder_, csidlarray))
\r
1134 if (folder_.empty())
\r
1136 // folder is empty, but maybe files are selected
\r
1137 if (files_.size() == 0)
\r
1138 return NOERROR; // nothing selected - we don't have a menu to show
\r
1139 // check whether a selected entry is an UID - those are namespace extensions
\r
1140 // which we can't handle
\r
1141 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1143 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1148 //check if our menu is requested for a subversion admin directory
\r
1149 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1152 if (uFlags & CMF_EXTENDEDVERBS)
\r
1153 itemStates |= ITEMIS_EXTENDED;
\r
1155 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1156 if ( bShortcut && (files_.size()==1))
\r
1158 // Don't show the context menu for a link if the
\r
1159 // destination is not part of a working copy.
\r
1160 // It would only show the standard menu items
\r
1161 // which are already shown for the lnk-file.
\r
1162 CString path = files_.front().c_str();
\r
1163 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1169 //check if we already added our menu entry for a folder.
\r
1170 //we check that by iterating through all menu entries and check if
\r
1171 //the dwItemData member points to our global ID string. That string is set
\r
1172 //by our shell extension when the folder menu is inserted.
\r
1173 TCHAR menubuf[MAX_PATH];
\r
1174 int count = GetMenuItemCount(hMenu);
\r
1175 for (int i=0; i<count; ++i)
\r
1177 MENUITEMINFO miif;
\r
1178 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1179 miif.cbSize = sizeof(MENUITEMINFO);
\r
1180 miif.fMask = MIIM_DATA;
\r
1181 miif.dwTypeData = menubuf;
\r
1182 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1183 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1184 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1189 UINT idCmd = idCmdFirst;
\r
1191 //create the sub menu
\r
1192 HMENU subMenu = CreateMenu();
\r
1193 int indexSubMenu = 0;
\r
1195 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1196 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1198 int menuIndex = 0;
\r
1199 bool bAddSeparator = false;
\r
1200 bool bMenuEntryAdded = false;
\r
1201 bool bMenuEmpty = true;
\r
1202 // insert separator at start
\r
1203 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1204 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1205 // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up
\r
1206 /*if (fullver <= 0x500)
\r
1207 bShowIcons = false;*/
\r
1210 if (itemStates & (ITEMIS_INSVN|ITEMIS_FOLDERINSVN))
\r
1212 // show current branch name (as a "read-only" menu entry)
\r
1214 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
1215 CString sProjectRoot;
\r
1216 CString sBranchName;
\r
1218 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
1220 if (sBranchName.GetLength() == 40)
\r
1222 // if SHA1 only show 4 first bytes
\r
1223 BOOL bIsSha1 = TRUE;
\r
1224 for (int i=0; i<40; i++)
\r
1225 if ( !iswxdigit(sBranchName[i]) )
\r
1231 sBranchName = sBranchName.Left(8) + _T("....");
\r
1234 sBranchName = _T('"') + sBranchName + _T('"');
\r
1236 const int icon = IDI_COPY;
\r
1237 const int pos = indexMenu++;
\r
1238 const int id = idCmd++;
\r
1240 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1242 InsertMenu(hMenu, pos, MF_DISABLED|MF_GRAYED|MF_BYPOSITION|MF_STRING, id, sBranchName);
\r
1243 HBITMAP bmp = IconToBitmap(icon);
\r
1244 SetMenuItemBitmaps(hMenu, pos, MF_BYPOSITION, bmp, bmp);
\r
1248 MENUITEMINFO menuiteminfo;
\r
1249 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1250 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1251 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
\r
1252 menuiteminfo.fState = MFS_DISABLED;
\r
1253 menuiteminfo.fType = MFT_STRING;
\r
1254 menuiteminfo.dwTypeData = (LPWSTR)sBranchName.GetString();
\r
1257 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1258 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
1260 if (menuiteminfo.hbmpItem == HBMMENU_CALLBACK)
\r
1262 // WM_DRAWITEM uses myIDMap to get icon, we use the same icon as create branch
\r
1263 myIDMap[id - idCmdFirst] = ShellMenuBranch;
\r
1264 myIDMap[id] = ShellMenuBranch;
\r
1267 menuiteminfo.wID = id;
\r
1268 InsertMenuItem(hMenu, pos, TRUE, &menuiteminfo);
\r
1274 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1276 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1278 // we don't add a separator immediately. Because there might not be
\r
1279 // another 'normal' menu entry after we insert a separator.
\r
1280 // we simply set a flag here, indicating that before the next
\r
1281 // 'normal' menu entry, a separator should be added.
\r
1283 bAddSeparator = true;
\r
1287 // check the conditions whether to show the menu entry or not
\r
1288 bool bInsertMenu = false;
\r
1290 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1292 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1294 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1295 bInsertMenu = true;
\r
1297 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1298 bInsertMenu = true;
\r
1299 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1300 bInsertMenu = true;
\r
1302 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1304 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1306 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1307 bInsertMenu = true;
\r
1309 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1310 bInsertMenu = true;
\r
1311 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1312 bInsertMenu = true;
\r
1314 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1316 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1318 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1319 bInsertMenu = true;
\r
1321 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1322 bInsertMenu = true;
\r
1323 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1324 bInsertMenu = true;
\r
1326 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1328 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1330 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1331 bInsertMenu = true;
\r
1333 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1334 bInsertMenu = true;
\r
1335 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1336 bInsertMenu = true;
\r
1338 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1342 // insert a separator
\r
1343 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1345 bAddSeparator = false;
\r
1346 bMenuEntryAdded = false;
\r
1347 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1351 // handle special cases (sub menus)
\r
1352 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1354 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons, uFlags);
\r
1355 bMenuEntryAdded = true;
\r
1356 bMenuEmpty = false;
\r
1360 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1362 // insert the menu entry
\r
1363 InsertGitMenu( bIsTop,
\r
1364 bIsTop ? hMenu : subMenu,
\r
1365 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1367 menuInfo[menuIndex].menuTextID,
\r
1368 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1370 menuInfo[menuIndex].command,
\r
1374 bMenuEntryAdded = true;
\r
1375 bMenuEmpty = false;
\r
1384 //add sub menu to main context menu
\r
1385 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1386 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1387 MAKESTRING(IDS_MENUSUBMENU);
\r
1388 MENUITEMINFO menuiteminfo;
\r
1389 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1390 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1391 menuiteminfo.fType = MFT_STRING;
\r
1392 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1394 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1395 if (folder_.size())
\r
1397 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1398 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1399 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1400 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1402 else if (!bShortcut && (files_.size()==1))
\r
1404 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1405 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1406 myIDMap[idCmd] = ShellSubMenuFile;
\r
1408 else if (bShortcut && (files_.size()==1))
\r
1410 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1411 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1412 myIDMap[idCmd] = ShellSubMenuLink;
\r
1414 else if (files_.size() > 1)
\r
1416 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1417 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1418 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1422 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1423 myIDMap[idCmd] = ShellSubMenu;
\r
1425 HBITMAP bmp = NULL;
\r
1426 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1428 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
1431 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
1432 bmp = IconToBitmap(uIcon);
\r
1433 menuiteminfo.hbmpChecked = bmp;
\r
1434 menuiteminfo.hbmpUnchecked = bmp;
\r
1439 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
1442 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1443 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1446 menuiteminfo.hSubMenu = subMenu;
\r
1447 menuiteminfo.wID = idCmd++;
\r
1448 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1451 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1453 //return number of menu items added
\r
1454 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1458 // This is called when you invoke a command on the menu:
\r
1459 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1461 PreserveChdir preserveChdir;
\r
1462 HRESULT hr = E_INVALIDARG;
\r
1463 if (lpcmi == NULL)
\r
1466 std::string command;
\r
1467 std::string parent;
\r
1470 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1472 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1474 if (HIWORD(lpcmi->lpVerb))
\r
1476 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1477 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1478 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1479 idCmd = verb_it->second;
\r
1484 // See if we have a handler interface for this id
\r
1485 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1486 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1488 STARTUPINFO startup;
\r
1489 PROCESS_INFORMATION process;
\r
1490 memset(&startup, 0, sizeof(startup));
\r
1491 startup.cb = sizeof(startup);
\r
1492 memset(&process, 0, sizeof(process));
\r
1493 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1494 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1496 //TortoiseProc expects a command line of the form:
\r
1497 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1499 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1501 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1502 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1503 stdstring svnCmd = _T(" /command:");
\r
1504 stdstring tempfile;
\r
1505 switch (id_it->second)
\r
1508 case ShellMenuCheckout:
\r
1509 svnCmd += _T("checkout /path:\"");
\r
1510 svnCmd += folder_;
\r
1511 svnCmd += _T("\"");
\r
1513 case ShellMenuUpdate:
\r
1514 tempfile = WriteFileListToTempFile();
\r
1515 svnCmd += _T("update /pathfile:\"");
\r
1516 svnCmd += tempfile;
\r
1517 svnCmd += _T("\"");
\r
1518 svnCmd += _T(" /deletepathfile");
\r
1520 case ShellMenuSubSync:
\r
1521 tempfile = WriteFileListToTempFile();
\r
1522 svnCmd += _T("subsync /pathfile:\"");
\r
1523 svnCmd += tempfile;
\r
1524 svnCmd += _T("\"");
\r
1525 svnCmd += _T(" /deletepathfile");
\r
1526 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1528 svnCmd += _T(" /bkpath:");
\r
1529 svnCmd += folder_;
\r
1532 case ShellMenuUpdateExt:
\r
1533 tempfile = WriteFileListToTempFile();
\r
1534 svnCmd += _T("subupdate /pathfile:\"");
\r
1535 svnCmd += tempfile;
\r
1536 svnCmd += _T("\"");
\r
1537 svnCmd += _T(" /deletepathfile");
\r
1538 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1540 svnCmd += _T(" /bkpath:");
\r
1541 svnCmd += folder_;
\r
1544 case ShellMenuCommit:
\r
1545 tempfile = WriteFileListToTempFile();
\r
1546 svnCmd += _T("commit /pathfile:\"");
\r
1547 svnCmd += tempfile;
\r
1548 svnCmd += _T("\"");
\r
1549 svnCmd += _T(" /deletepathfile");
\r
1551 case ShellMenuAdd:
\r
1552 case ShellMenuAddAsReplacement:
\r
1553 tempfile = WriteFileListToTempFile();
\r
1554 svnCmd += _T("add /pathfile:\"");
\r
1555 svnCmd += tempfile;
\r
1556 svnCmd += _T("\"");
\r
1557 svnCmd += _T(" /deletepathfile");
\r
1559 case ShellMenuIgnore:
\r
1560 tempfile = WriteFileListToTempFile();
\r
1561 svnCmd += _T("ignore /pathfile:\"");
\r
1562 svnCmd += tempfile;
\r
1563 svnCmd += _T("\"");
\r
1564 svnCmd += _T(" /deletepathfile");
\r
1566 case ShellMenuIgnoreCaseSensitive:
\r
1567 tempfile = WriteFileListToTempFile();
\r
1568 svnCmd += _T("ignore /pathfile:\"");
\r
1569 svnCmd += tempfile;
\r
1570 svnCmd += _T("\"");
\r
1571 svnCmd += _T(" /deletepathfile");
\r
1572 svnCmd += _T(" /onlymask");
\r
1574 case ShellMenuUnIgnore:
\r
1575 tempfile = WriteFileListToTempFile();
\r
1576 svnCmd += _T("unignore /pathfile:\"");
\r
1577 svnCmd += tempfile;
\r
1578 svnCmd += _T("\"");
\r
1579 svnCmd += _T(" /deletepathfile");
\r
1581 case ShellMenuUnIgnoreCaseSensitive:
\r
1582 tempfile = WriteFileListToTempFile();
\r
1583 svnCmd += _T("unignore /pathfile:\"");
\r
1584 svnCmd += tempfile;
\r
1585 svnCmd += _T("\"");
\r
1586 svnCmd += _T(" /deletepathfile");
\r
1587 svnCmd += _T(" /onlymask");
\r
1589 case ShellMenuRevert:
\r
1590 tempfile = WriteFileListToTempFile();
\r
1591 svnCmd += _T("revert /pathfile:\"");
\r
1592 svnCmd += tempfile;
\r
1593 svnCmd += _T("\"");
\r
1594 svnCmd += _T(" /deletepathfile");
\r
1596 case ShellMenuDelUnversioned:
\r
1597 svnCmd += _T("delunversioned /path:\"");
\r
1598 svnCmd += folder_;
\r
1599 svnCmd += _T("\"");
\r
1601 case ShellMenuCleanup:
\r
1602 tempfile = WriteFileListToTempFile();
\r
1603 svnCmd += _T("cleanup /pathfile:\"");
\r
1604 svnCmd += tempfile;
\r
1605 svnCmd += _T("\"");
\r
1606 svnCmd += _T(" /deletepathfile");
\r
1608 case ShellMenuSendMail:
\r
1609 tempfile = WriteFileListToTempFile();
\r
1610 svnCmd += _T("sendmail /pathfile:\"");
\r
1611 svnCmd += tempfile;
\r
1612 svnCmd += _T("\"");
\r
1613 svnCmd += _T(" /deletepathfile");
\r
1615 case ShellMenuResolve:
\r
1616 tempfile = WriteFileListToTempFile();
\r
1617 svnCmd += _T("resolve /pathfile:\"");
\r
1618 svnCmd += tempfile;
\r
1619 svnCmd += _T("\"");
\r
1620 svnCmd += _T(" /deletepathfile");
\r
1622 case ShellMenuSwitch:
\r
1623 svnCmd += _T("switch /path:\"");
\r
1624 if (files_.size() > 0)
\r
1625 svnCmd += files_.front();
\r
1627 svnCmd += folder_;
\r
1628 svnCmd += _T("\"");
\r
1630 case ShellMenuImport:
\r
1631 svnCmd += _T("import /path:\"");
\r
1632 svnCmd += folder_;
\r
1633 svnCmd += _T("\"");
\r
1635 case ShellMenuExport:
\r
1636 svnCmd += _T("export /path:\"");
\r
1637 svnCmd += folder_;
\r
1638 svnCmd += _T("\"");
\r
1640 case ShellMenuAbout:
\r
1641 svnCmd += _T("about");
\r
1643 case ShellMenuCreateRepos:
\r
1644 svnCmd += _T("repocreate /path:\"");
\r
1645 svnCmd += folder_;
\r
1646 svnCmd += _T("\"");
\r
1648 case ShellMenuMerge:
\r
1649 svnCmd += _T("merge /path:\"");
\r
1650 if (files_.size() > 0)
\r
1651 svnCmd += files_.front();
\r
1653 svnCmd += folder_;
\r
1654 svnCmd += _T("\"");
\r
1656 case ShellMenuMergeAll:
\r
1657 svnCmd += _T("mergeall /path:\"");
\r
1658 if (files_.size() > 0)
\r
1659 svnCmd += files_.front();
\r
1661 svnCmd += folder_;
\r
1662 svnCmd += _T("\"");
\r
1664 case ShellMenuCopy:
\r
1665 svnCmd += _T("copy /path:\"");
\r
1666 if (files_.size() > 0)
\r
1667 svnCmd += files_.front();
\r
1669 svnCmd += folder_;
\r
1670 svnCmd += _T("\"");
\r
1672 case ShellMenuSettings:
\r
1673 svnCmd += _T("settings /path:\"");
\r
1674 if (files_.size() > 0)
\r
1675 svnCmd += files_.front();
\r
1677 svnCmd += folder_;
\r
1678 svnCmd += _T("\"");
\r
1680 case ShellMenuHelp:
\r
1681 svnCmd += _T("help");
\r
1683 case ShellMenuRename:
\r
1684 svnCmd += _T("rename /path:\"");
\r
1685 if (files_.size() > 0)
\r
1686 svnCmd += files_.front();
\r
1688 svnCmd += folder_;
\r
1689 svnCmd += _T("\"");
\r
1691 case ShellMenuRemove:
\r
1692 tempfile = WriteFileListToTempFile();
\r
1693 svnCmd += _T("remove /pathfile:\"");
\r
1694 svnCmd += tempfile;
\r
1695 svnCmd += _T("\"");
\r
1696 svnCmd += _T(" /deletepathfile");
\r
1698 case ShellMenuRemoveKeep:
\r
1699 tempfile = WriteFileListToTempFile();
\r
1700 svnCmd += _T("remove /pathfile:\"");
\r
1701 svnCmd += tempfile;
\r
1702 svnCmd += _T("\"");
\r
1703 svnCmd += _T(" /deletepathfile");
\r
1704 svnCmd += _T(" /keep");
\r
1706 case ShellMenuDiff:
\r
1707 svnCmd += _T("diff /path:\"");
\r
1708 if (files_.size() == 1)
\r
1709 svnCmd += files_.front();
\r
1710 else if (files_.size() == 2)
\r
1712 std::vector<stdstring>::iterator I = files_.begin();
\r
1715 svnCmd += _T("\" /path2:\"");
\r
1719 svnCmd += folder_;
\r
1720 svnCmd += _T("\"");
\r
1721 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1722 svnCmd += _T(" /alternative");
\r
1724 case ShellMenuPrevDiff:
\r
1725 svnCmd += _T("prevdiff /path:\"");
\r
1726 if (files_.size() == 1)
\r
1727 svnCmd += files_.front();
\r
1729 svnCmd += folder_;
\r
1730 svnCmd += _T("\"");
\r
1731 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1732 svnCmd += _T(" /alternative");
\r
1734 case ShellMenuUrlDiff:
\r
1735 svnCmd += _T("urldiff /path:\"");
\r
1736 if (files_.size() == 1)
\r
1737 svnCmd += files_.front();
\r
1739 svnCmd += folder_;
\r
1740 svnCmd += _T("\"");
\r
1742 case ShellMenuDropCopyAdd:
\r
1743 tempfile = WriteFileListToTempFile();
\r
1744 svnCmd += _T("dropcopyadd /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("\"";)
\r
1752 case ShellMenuDropCopy:
\r
1753 tempfile = WriteFileListToTempFile();
\r
1754 svnCmd += _T("dropcopy /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 ShellMenuDropCopyRename:
\r
1763 tempfile = WriteFileListToTempFile();
\r
1764 svnCmd += _T("dropcopy /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 ShellMenuDropMove:
\r
1773 tempfile = WriteFileListToTempFile();
\r
1774 svnCmd += _T("dropmove /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 ShellMenuDropMoveRename:
\r
1783 tempfile = WriteFileListToTempFile();
\r
1784 svnCmd += _T("dropmove /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("\" /rename";)
\r
1792 case ShellMenuDropExport:
\r
1793 tempfile = WriteFileListToTempFile();
\r
1794 svnCmd += _T("dropexport /pathfile:\"");
\r
1795 svnCmd += tempfile;
\r
1796 svnCmd += _T("\"");
\r
1797 svnCmd += _T(" /deletepathfile");
\r
1798 svnCmd += _T(" /droptarget:\"");
\r
1799 svnCmd += folder_;
\r
1800 svnCmd += _T("\"");
\r
1802 case ShellMenuDropExportExtended:
\r
1803 tempfile = WriteFileListToTempFile();
\r
1804 svnCmd += _T("dropexport /pathfile:\"");
\r
1805 svnCmd += tempfile;
\r
1806 svnCmd += _T("\"");
\r
1807 svnCmd += _T(" /deletepathfile");
\r
1808 svnCmd += _T(" /droptarget:\"");
\r
1809 svnCmd += folder_;
\r
1810 svnCmd += _T("\"");
\r
1811 svnCmd += _T(" /extended");
\r
1813 case ShellMenuLog:
\r
1814 svnCmd += _T("log /path:\"");
\r
1815 if (files_.size() > 0)
\r
1816 svnCmd += files_.front();
\r
1818 svnCmd += folder_;
\r
1819 svnCmd += _T("\"");
\r
1821 case ShellMenuConflictEditor:
\r
1822 svnCmd += _T("conflicteditor /path:\"");
\r
1823 if (files_.size() > 0)
\r
1824 svnCmd += files_.front();
\r
1826 svnCmd += folder_;
\r
1827 svnCmd += _T("\"");
\r
1829 case ShellMenuRelocate:
\r
1830 svnCmd += _T("relocate /path:\"");
\r
1831 if (files_.size() > 0)
\r
1832 svnCmd += files_.front();
\r
1834 svnCmd += folder_;
\r
1835 svnCmd += _T("\"");
\r
1837 case ShellMenuGitSVNRebase:
\r
1838 svnCmd += _T("svnrebase /path:\"");
\r
1839 if (files_.size() > 0)
\r
1840 svnCmd += files_.front();
\r
1842 svnCmd += folder_;
\r
1843 svnCmd += _T("\"");
\r
1845 case ShellMenuGitSVNDCommit:
\r
1846 svnCmd += _T("svndcommit /path:\"");
\r
1847 if (files_.size() > 0)
\r
1848 svnCmd += files_.front();
\r
1850 svnCmd += folder_;
\r
1851 svnCmd += _T("\"");
\r
1853 case ShellMenuRebase:
\r
1854 svnCmd += _T("rebase /path:\"");
\r
1855 if (files_.size() > 0)
\r
1856 svnCmd += files_.front();
\r
1858 svnCmd += folder_;
\r
1859 svnCmd += _T("\"");
\r
1861 case ShellMenuShowChanged:
\r
1862 if (files_.size() > 1)
\r
1864 tempfile = WriteFileListToTempFile();
\r
1865 svnCmd += _T("repostatus /pathfile:\"");
\r
1866 svnCmd += tempfile;
\r
1867 svnCmd += _T("\"");
\r
1868 svnCmd += _T(" /deletepathfile");
\r
1872 svnCmd += _T("repostatus /path:\"");
\r
1873 if (files_.size() > 0)
\r
1874 svnCmd += files_.front();
\r
1876 svnCmd += folder_;
\r
1877 svnCmd += _T("\"");
\r
1880 case ShellMenuRefBrowse:
\r
1881 svnCmd += _T("refbrowse /path:\"");
\r
1882 if (files_.size() > 0)
\r
1883 svnCmd += files_.front();
\r
1885 svnCmd += folder_;
\r
1886 svnCmd += _T("\"");
\r
1888 case ShellMenuRefLog:
\r
1889 svnCmd += _T("reflog /path:\"");
\r
1890 if (files_.size() > 0)
\r
1891 svnCmd += files_.front();
\r
1893 svnCmd += folder_;
\r
1894 svnCmd += _T("\"");
\r
1897 case ShellMenuStashSave:
\r
1898 svnCmd += _T("stashsave /path:\"");
\r
1899 if (files_.size() > 0)
\r
1900 svnCmd += files_.front();
\r
1902 svnCmd += folder_;
\r
1903 svnCmd += _T("\"");
\r
1906 case ShellMenuStashApply:
\r
1907 svnCmd += _T("stashapply /path:\"");
\r
1908 if (files_.size() > 0)
\r
1909 svnCmd += files_.front();
\r
1911 svnCmd += folder_;
\r
1912 svnCmd += _T("\"");
\r
1915 case ShellMenuStashList:
\r
1916 svnCmd += _T("reflog /path:\"");
\r
1917 if (files_.size() > 0)
\r
1918 svnCmd += files_.front();
\r
1920 svnCmd += folder_;
\r
1921 svnCmd += _T("\" /ref:refs/stash");
\r
1924 case ShellMenuSubAdd:
\r
1925 svnCmd += _T("subadd /path:\"");
\r
1926 if (files_.size() > 0)
\r
1927 svnCmd += files_.front();
\r
1929 svnCmd += folder_;
\r
1930 svnCmd += _T("\"");
\r
1933 case ShellMenuBlame:
\r
1934 svnCmd += _T("blame /path:\"");
\r
1935 if (files_.size() > 0)
\r
1936 svnCmd += files_.front();
\r
1938 svnCmd += folder_;
\r
1939 svnCmd += _T("\"");
\r
1941 case ShellMenuCreatePatch:
\r
1942 tempfile = WriteFileListToTempFile();
\r
1943 svnCmd += _T("createpatch /pathfile:\"");
\r
1944 svnCmd += tempfile;
\r
1945 svnCmd += _T("\"");
\r
1946 svnCmd += _T(" /deletepathfile");
\r
1948 case ShellMenuApplyPatch:
\r
1949 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1951 // if there's a patch file in the clipboard, we save it
\r
1952 // to a temporary file and tell TortoiseMerge to use that one
\r
1953 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1954 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1956 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1957 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1959 DWORD len = GetTempPath(0, NULL);
\r
1960 TCHAR * path = new TCHAR[len+1];
\r
1961 TCHAR * tempF = new TCHAR[len+100];
\r
1962 GetTempPath (len+1, path);
\r
1963 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1964 std::wstring sTempFile = std::wstring(tempF);
\r
1969 size_t patchlen = strlen(lpstr);
\r
1970 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1973 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1974 if (size == patchlen)
\r
1976 itemStates |= ITEMIS_PATCHFILE;
\r
1978 files_.push_back(sTempFile);
\r
1982 GlobalUnlock(hglb);
\r
1983 CloseClipboard();
\r
1986 if (itemStates & ITEMIS_PATCHFILE)
\r
1988 svnCmd = _T(" /diff:\"");
\r
1989 if (files_.size() > 0)
\r
1991 svnCmd += files_.front();
\r
1992 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1994 svnCmd += _T("\" /patchpath:\"");
\r
1995 svnCmd += folder_;
\r
1999 svnCmd += folder_;
\r
2000 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
2001 svnCmd += _T("\" /wc");
\r
2003 svnCmd += _T("\"");
\r
2007 svnCmd = _T(" /patchpath:\"");
\r
2008 if (files_.size() > 0)
\r
2009 svnCmd += files_.front();
\r
2011 svnCmd += folder_;
\r
2012 svnCmd += _T("\"");
\r
2015 myVerbsIDMap.clear();
\r
2016 myVerbsMap.clear();
\r
2017 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2020 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2021 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2022 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2025 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2026 (LPTSTR) &lpMsgBuf,
\r
2030 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2031 LocalFree( lpMsgBuf );
\r
2033 CloseHandle(process.hThread);
\r
2034 CloseHandle(process.hProcess);
\r
2037 case ShellMenuRevisionGraph:
\r
2038 svnCmd += _T("revisiongraph /path:\"");
\r
2039 if (files_.size() > 0)
\r
2040 svnCmd += files_.front();
\r
2042 svnCmd += folder_;
\r
2043 svnCmd += _T("\"");
\r
2045 case ShellMenuProperties:
\r
2046 tempfile = WriteFileListToTempFile();
\r
2047 svnCmd += _T("properties /pathfile:\"");
\r
2048 svnCmd += tempfile;
\r
2049 svnCmd += _T("\"");
\r
2050 svnCmd += _T(" /deletepathfile");
\r
2052 case ShellMenuClipPaste:
\r
2053 if (WriteClipboardPathsToTempFile(tempfile))
\r
2055 bool bCopy = true;
\r
2056 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
2057 if (cPrefDropFormat)
\r
2059 if (OpenClipboard(lpcmi->hwnd))
\r
2061 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
2064 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
2065 if (*effect == DROPEFFECT_MOVE)
\r
2067 GlobalUnlock(hglb);
\r
2074 svnCmd += _T("pastecopy /pathfile:\"");
\r
2076 svnCmd += _T("pastemove /pathfile:\"");
\r
2077 svnCmd += tempfile;
\r
2078 svnCmd += _T("\"");
\r
2079 svnCmd += _T(" /deletepathfile");
\r
2080 svnCmd += _T(" /droptarget:\"");
\r
2081 svnCmd += folder_;
\r
2082 svnCmd += _T("\"");
\r
2084 else return NOERROR;
\r
2086 case ShellMenuClone:
\r
2087 svnCmd += _T("clone /path:\"");
\r
2088 svnCmd += folder_;
\r
2089 svnCmd += _T("\"");
\r
2091 case ShellMenuPull:
\r
2092 svnCmd += _T("pull /path:\"");
\r
2093 if (files_.size() > 0)
\r
2094 svnCmd += files_.front();
\r
2096 svnCmd += folder_;
\r
2097 svnCmd += _T("\"");
\r
2099 case ShellMenuPush:
\r
2100 svnCmd += _T("push /path:\"");
\r
2101 if (files_.size() > 0)
\r
2102 svnCmd += files_.front();
\r
2104 svnCmd += folder_;
\r
2105 svnCmd += _T("\"");
\r
2107 case ShellMenuBranch:
\r
2108 svnCmd += _T("branch /path:\"");
\r
2109 if (files_.size() > 0)
\r
2110 svnCmd += files_.front();
\r
2112 svnCmd += folder_;
\r
2113 svnCmd += _T("\"");
\r
2116 case ShellMenuTag:
\r
2117 svnCmd += _T("tag /path:\"");
\r
2118 if (files_.size() > 0)
\r
2119 svnCmd += files_.front();
\r
2121 svnCmd += folder_;
\r
2122 svnCmd += _T("\"");
\r
2125 case ShellMenuFormatPatch:
\r
2126 svnCmd += _T("formatpatch /path:\"");
\r
2127 if (files_.size() > 0)
\r
2128 svnCmd += files_.front();
\r
2130 svnCmd += folder_;
\r
2131 svnCmd += _T("\"");
\r
2134 case ShellMenuImportPatch:
\r
2135 tempfile = WriteFileListToTempFile();
\r
2136 svnCmd += _T("importpatch /pathfile:\"");
\r
2137 svnCmd += tempfile;
\r
2138 svnCmd += _T("\"");
\r
2139 svnCmd += _T(" /deletepathfile");
\r
2142 case ShellMenuCherryPick:
\r
2143 svnCmd += _T("cherrypick /path:\"");
\r
2144 if (files_.size() > 0)
\r
2145 svnCmd += files_.front();
\r
2147 svnCmd += folder_;
\r
2148 svnCmd += _T("\"");
\r
2150 case ShellMenuFetch:
\r
2151 svnCmd += _T("fetch /path:\"");
\r
2152 if (files_.size() > 0)
\r
2153 svnCmd += files_.front();
\r
2155 svnCmd += folder_;
\r
2156 svnCmd += _T("\"");
\r
2162 } // switch (id_it->second)
\r
2163 svnCmd += _T(" /hwnd:");
\r
2165 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
2168 myVerbsIDMap.clear();
\r
2169 myVerbsMap.clear();
\r
2170 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2173 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2174 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2175 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2178 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2179 (LPTSTR) &lpMsgBuf,
\r
2183 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2184 LocalFree( lpMsgBuf );
\r
2186 CloseHandle(process.hThread);
\r
2187 CloseHandle(process.hProcess);
\r
2189 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
2190 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
2195 // This is for the status bar and things like that:
\r
2196 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
2198 UINT FAR * /*reserved*/,
\r
2202 PreserveChdir preserveChdir;
\r
2203 //do we know the id?
\r
2204 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
2205 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
2207 return E_INVALIDARG; //no, we don't
\r
2211 HRESULT hr = E_INVALIDARG;
\r
2213 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
2214 int menuIndex = 0;
\r
2215 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2217 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
2219 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
2225 const TCHAR * desc = stringtablebuffer;
\r
2228 case GCS_HELPTEXTA:
\r
2230 std::string help = WideToMultibyte(desc);
\r
2231 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2235 case GCS_HELPTEXTW:
\r
2237 wide_string help = desc;
\r
2238 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2244 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2245 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2247 std::string help = WideToMultibyte(verb_id_it->second);
\r
2248 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2255 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2256 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2258 wide_string help = verb_id_it->second;
\r
2259 ATLTRACE("verb : %ws\n", help.c_str());
\r
2260 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2269 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2272 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2275 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2277 PreserveChdir preserveChdir;
\r
2280 if (pResult == NULL)
\r
2287 case WM_MEASUREITEM:
\r
2289 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2290 if (lpmis==NULL||lpmis->CtlType!=ODT_MENU)
\r
2292 lpmis->itemWidth += 2;
\r
2293 if (lpmis->itemHeight < 16)
\r
2294 lpmis->itemHeight = 16;
\r
2301 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2302 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2303 return S_OK; //not for a menu
\r
2304 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2305 if (resource == NULL)
\r
2307 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2308 if (hIcon == NULL)
\r
2310 DrawIconEx(lpdis->hDC,
\r
2311 lpdis->rcItem.left - 16,
\r
2312 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2314 0, NULL, DI_NORMAL);
\r
2315 DestroyIcon(hIcon);
\r
2323 if (HIWORD(wParam) != MF_POPUP)
\r
2325 int nChar = LOWORD(wParam);
\r
2326 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2327 nChar = tolower(nChar);
\r
2328 // we have the char the user pressed, now search that char in all our
\r
2330 std::vector<int> accmenus;
\r
2331 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2333 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2334 if (resource == NULL)
\r
2336 szItem = stringtablebuffer;
\r
2337 TCHAR * amp = _tcschr(szItem, '&');
\r
2341 int ampChar = LOWORD(*amp);
\r
2342 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2343 ampChar = tolower(ampChar);
\r
2344 if (ampChar == nChar)
\r
2346 // yep, we found a menu which has the pressed key
\r
2347 // as an accelerator. Add that menu to the list to
\r
2349 accmenus.push_back(It->first);
\r
2352 if (accmenus.size() == 0)
\r
2354 // no menu with that accelerator key.
\r
2355 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2358 if (accmenus.size() == 1)
\r
2360 // Only one menu with that accelerator key. We're lucky!
\r
2361 // So just execute that menu entry.
\r
2362 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2365 if (accmenus.size() > 1)
\r
2367 // we have more than one menu item with this accelerator key!
\r
2369 mif.cbSize = sizeof(MENUITEMINFO);
\r
2370 mif.fMask = MIIM_STATE;
\r
2371 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2373 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2374 if (mif.fState == MFS_HILITE)
\r
2376 // this is the selected item, so select the next one
\r
2378 if (it == accmenus.end())
\r
2379 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2381 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2385 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2396 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2398 TCHAR textbuf[255];
\r
2399 LPCTSTR resource = NULL;
\r
2400 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2403 int menuIndex = 0;
\r
2404 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2406 if (menuInfo[menuIndex].command == id)
\r
2408 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2409 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2412 case ShellSubMenuMultiple:
\r
2413 case ShellSubMenuLink:
\r
2414 case ShellSubMenuFolder:
\r
2415 case ShellSubMenuFile:
\r
2416 case ShellSubMenu:
\r
2420 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2421 if (layout & (menuInfo[menuIndex].menuID))
\r
2423 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2424 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2425 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2436 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2439 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2440 LPITEMIDLIST pidl = NULL;
\r
2441 while (cslidarray[i])
\r
2445 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2447 if (!SHGetPathFromIDList(pidl, buf))
\r
2449 // not a file system path, definitely illegal for our use
\r
2450 CoTaskMemFree(pidl);
\r
2453 CoTaskMemFree(pidl);
\r
2454 if (_tcslen(buf)==0)
\r
2456 if (_tcscmp(buf, folder.c_str())==0)
\r
2462 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags)
\r
2464 HMENU ignoresubmenu = NULL;
\r
2465 int indexignoresub = 0;
\r
2466 bool bShowIgnoreMenu = false;
\r
2467 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2468 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2469 if (files_.size() == 0)
\r
2471 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2473 std::vector<stdstring>::iterator I = files_.begin();
\r
2474 if (_tcsrchr(I->c_str(), '\\'))
\r
2475 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2477 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2478 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2480 // check if the item name is ignored or the mask
\r
2482 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2484 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2485 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2493 ignoresubmenu = CreateMenu();
\r
2494 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2495 stdstring verb = stdstring(ignorepath);
\r
2496 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2497 myVerbsMap[verb] = idCmd;
\r
2498 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2499 myVerbsIDMap[idCmd] = verb;
\r
2500 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2501 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2502 bShowIgnoreMenu = true;
\r
2504 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2505 if (_tcsrchr(ignorepath, '.'))
\r
2507 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2508 p = ignoredprops.find(maskbuf);
\r
2510 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2512 if (ignoresubmenu==NULL)
\r
2513 ignoresubmenu = CreateMenu();
\r
2515 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2516 stdstring verb = stdstring(maskbuf);
\r
2517 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2518 myVerbsMap[verb] = idCmd;
\r
2519 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2520 myVerbsIDMap[idCmd] = verb;
\r
2521 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2522 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2523 bShowIgnoreMenu = true;
\r
2527 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2529 bShowIgnoreMenu = true;
\r
2530 ignoresubmenu = CreateMenu();
\r
2531 if (itemStates & ITEMIS_ONLYONE)
\r
2533 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2534 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2535 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2537 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2538 if (_tcsrchr(ignorepath, '.'))
\r
2540 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2541 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2542 stdstring verb = stdstring(maskbuf);
\r
2543 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2544 myVerbsMap[verb] = idCmd;
\r
2545 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2546 myVerbsIDMap[idCmd] = verb;
\r
2547 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2548 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2553 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2554 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2555 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2556 stdstring verb = stdstring(ignorepath);
\r
2557 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2558 myVerbsMap[verb] = idCmd;
\r
2559 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2560 myVerbsIDMap[idCmd] = verb;
\r
2561 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2562 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2564 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2565 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2566 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2567 verb = stdstring(ignorepath);
\r
2568 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2569 myVerbsMap[verb] = idCmd;
\r
2570 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2571 myVerbsIDMap[idCmd] = verb;
\r
2572 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2573 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2577 if (bShowIgnoreMenu)
\r
2579 MENUITEMINFO menuiteminfo;
\r
2580 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2581 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2582 if (fullver < 0x500 || (fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
2584 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
2587 HBITMAP bmp = IconToBitmap(icon);
\r
2588 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
2589 menuiteminfo.hbmpChecked = bmp;
\r
2590 menuiteminfo.hbmpUnchecked = bmp;
\r
2595 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
2598 menuiteminfo.fMask |= MIIM_BITMAP;
\r
2599 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
2602 menuiteminfo.fType = MFT_STRING;
\r
2603 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2604 menuiteminfo.wID = idCmd;
\r
2605 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2606 if (itemStates & ITEMIS_IGNORED)
\r
2607 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2609 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2610 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2611 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2613 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2614 if (itemStates & ITEMIS_IGNORED)
\r
2616 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2617 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2621 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2622 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2627 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2629 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2630 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2631 return bitmap_it->second;
\r
2633 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2637 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2641 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2642 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2645 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2646 HBITMAP hBmp = NULL;
\r
2648 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2651 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2653 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2656 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2657 BP_PAINTPARAMS paintParams = {0};
\r
2658 paintParams.cbSize = sizeof(paintParams);
\r
2659 paintParams.dwFlags = BPPF_ERASE;
\r
2660 paintParams.pBlendFunction = &bfAlpha;
\r
2663 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2666 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2668 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2669 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2672 // This will write the buffer contents to the destination bitmap
\r
2673 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2676 SelectObject(hdcDest, hbmpOld);
\r
2680 DeleteDC(hdcDest);
\r
2683 DestroyIcon(hIcon);
\r
2686 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2690 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2695 ZeroMemory(&bmi, sizeof(bmi));
\r
2696 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2697 bmi.bmiHeader.biPlanes = 1;
\r
2698 bmi.bmiHeader.biCompression = BI_RGB;
\r
2700 bmi.bmiHeader.biWidth = psize->cx;
\r
2701 bmi.bmiHeader.biHeight = psize->cy;
\r
2702 bmi.bmiHeader.biBitCount = 32;
\r
2704 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2707 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2708 if (hdc != hdcUsed)
\r
2710 ReleaseDC(NULL, hdcUsed);
\r
2713 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2716 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2718 RGBQUAD *prgbQuad;
\r
2720 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2721 if (SUCCEEDED(hr))
\r
2723 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2724 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2727 if (GetIconInfo(hicon, &info))
\r
2731 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2734 DeleteObject(info.hbmColor);
\r
2735 DeleteObject(info.hbmMask);
\r
2743 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2745 ULONG cxDelta = cxRow - sizImage.cx;
\r
2746 for (ULONG y = sizImage.cy; y; --y)
\r
2748 for (ULONG x = sizImage.cx; x; --x)
\r
2750 if (*pargb++ & 0xFF000000)
\r
2762 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2765 ZeroMemory(&bmi, sizeof(bmi));
\r
2766 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2767 bmi.bmiHeader.biPlanes = 1;
\r
2768 bmi.bmiHeader.biCompression = BI_RGB;
\r
2770 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2771 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2772 bmi.bmiHeader.biBitCount = 32;
\r
2774 HRESULT hr = E_OUTOFMEMORY;
\r
2775 HANDLE hHeap = GetProcessHeap();
\r
2776 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2779 hr = E_UNEXPECTED;
\r
2780 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2782 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2783 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2785 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2787 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2791 // transparent pixel
\r
2797 *pargb++ |= 0xFF000000;
\r
2807 HeapFree(hHeap, 0, pvBits);
\r