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 { ShellMenuSync, MENUSYNC, IDI_RELOCATE, IDS_MENUSYNC, IDS_MENUDESCSYNC,
\r
48 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
51 // { ShellMenuCheckout, MENUCHECKOUT, IDI_CHECKOUT, IDS_MENUCHECKOUT, IDS_MENUDESCCHECKOUT,
\r
52 // ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
54 // { ShellMenuUpdate, MENUSUBUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
\r
55 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
57 { ShellSeparator, ITEMIS_GITSVN, 0, 0, 0, 0, 0, 0, 0},
\r
59 { ShellMenuCommit, MENUCOMMIT, IDI_COMMIT, IDS_MENUCOMMIT, IDS_MENUDESCCOMMIT,
\r
60 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
62 { ShellMenuGitSVNDCommit, MENUSVNDCOMMIT, IDI_COMMIT, IDS_MENUSVNDCOMMIT, IDS_MENUSVNDCOMMIT_DESC,
\r
63 ITEMIS_INSVN|ITEMIS_GITSVN, 0, ITEMIS_FOLDERINSVN|ITEMIS_GITSVN, 0, 0, 0, 0, 0 },
\r
65 { ShellMenuGitSVNRebase, MENUSVNREBASE, IDI_REBASE, IDS_MENUSVNREBASE, IDS_MENUSVNREBASE_DESC,
\r
66 ITEMIS_INSVN|ITEMIS_GITSVN, 0, ITEMIS_FOLDERINSVN|ITEMIS_GITSVN, 0, 0, 0, 0, 0},
\r
68 { ShellMenuGitSVNIgnore, MENUSVNIGNORE, IDI_IGNORE, IDS_MENUSVNIGNORE, IDS_MENUSVNIGNORE_DESC,
\r
69 ITEMIS_INSVN|ITEMIS_GITSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_GITSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0},
\r
71 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
73 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
74 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
76 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
77 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
79 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
80 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
82 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
83 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
85 { ShellMenuRefLog, MENUREFLOG, IDI_LOG, IDS_MENUREFLOG, IDS_MENUDESCREFLOG,
\r
86 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
88 { ShellMenuRefBrowse, MENUREFBROWSE, IDI_REPOBROWSE, IDS_MENUREFBROWSE, IDS_MENUDESCREFBROWSE,
\r
89 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
92 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
93 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
95 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
96 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
98 { ShellMenuRebase, MENUREBASE, IDI_REBASE, IDS_MENUREBASE, IDS_MENUREBASE,
\r
99 ITEMIS_INSVN, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0},
\r
101 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
102 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
104 { ShellMenuStashSave, MENUSTASHSAVE, IDI_COMMIT, IDS_MENUSTASHSAVE, IDS_MENUSTASHSAVE,
\r
105 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
106 { ShellMenuStashApply, MENUSTASHAPPLY, IDI_RELOCATE, IDS_MENUSTASHAPPLY, IDS_MENUSTASHAPPLY,
\r
107 ITEMIS_INSVN|ITEMIS_STASH, 0, ITEMIS_FOLDERINSVN|ITEMIS_STASH, 0, 0, 0, 0, 0 },
\r
108 { ShellMenuStashPop, MENUSTASHPOP, IDI_RELOCATE, IDS_MENUSTASHPOP, IDS_MENUSTASHPOP,
\r
109 ITEMIS_INSVN|ITEMIS_STASH, 0, ITEMIS_FOLDERINSVN|ITEMIS_STASH, 0, 0, 0, 0, 0 },
\r
110 { ShellMenuStashList, MENUSTASHAPPLY, IDI_LOG, IDS_MENUSTASHLIST, IDS_MENUSTASHLIST,
\r
111 ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
114 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
116 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
117 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
119 { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
120 ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
123 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
124 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
126 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
127 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
129 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
130 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
132 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
133 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
135 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
136 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
138 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
139 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
141 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
142 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
144 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
145 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
147 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
148 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
150 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
151 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
153 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
155 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
156 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
158 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
159 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
161 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
162 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
163 // { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
164 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
166 { ShellMenuBranch, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
167 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
168 { ShellMenuTag, MENUTAG, IDI_TAG, IDS_MENUTAG, IDS_MENUDESCCOPY,
\r
169 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
171 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
172 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
174 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
175 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
177 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
179 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
180 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
182 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
183 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
185 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
186 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
188 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
189 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
191 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
192 ITEMIS_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
193 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
\r
194 // why was this changed, is this related to GitStatus?
\r
196 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
197 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
199 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
200 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
202 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
204 { ShellMenuSubAdd, MENUSUBADD, IDI_ADD, IDS_MENUSUBADD, IDS_MENUSUBADD,
\r
205 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
207 { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
208 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE, 0, 0, 0, 0, 0, 0, 0 },
\r
210 { ShellMenuSubSync, MENUSUBSYNC, IDI_MENUSYNC, IDS_MENUSUBSYNC, IDS_MENUSUBSYNC,
\r
211 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0, 0, 0 },
\r
215 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
217 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
218 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
220 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
221 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
223 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
224 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, ITEMIS_PATCHFILE, 0, 0, 0 },
\r
227 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
228 ITEMIS_INSVN|ITEMIS_EXTENDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
230 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
231 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0 },
\r
233 { ShellMenuSendMail, MENUSENDMAIL, IDI_MENUSENDMAIL, IDS_MENUSENDMAIL, IDS_MENUDESSENDMAIL,
\r
234 ITEMIS_PATCHFILE, 0, 0, 0, 0, 0, 0, 0 },
\r
236 // { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
237 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
239 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
240 { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
241 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
243 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
245 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
246 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
247 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
248 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
249 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
250 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
252 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
253 // but they still need to be in here, because we use the icon and string information anyway.
\r
254 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
255 0, 0, 0, 0, 0, 0, 0, 0 },
\r
256 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
257 0, 0, 0, 0, 0, 0, 0, 0 },
\r
258 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
259 0, 0, 0, 0, 0, 0, 0, 0 },
\r
260 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
261 0, 0, 0, 0, 0, 0, 0, 0 },
\r
262 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
263 0, 0, 0, 0, 0, 0, 0, 0 },
\r
264 // mark the last entry to tell the loop where to stop iterating over this array
\r
265 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
266 0, 0, 0, 0, 0, 0, 0, 0 },
\r
270 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
271 LPDATAOBJECT pDataObj,
\r
272 HKEY /* hRegKey */)
\r
275 ATLTRACE("Shell :: Initialize\n");
\r
276 PreserveChdir preserveChdir;
\r
279 uuidSource.erase();
\r
280 uuidTarget.erase();
\r
282 itemStatesFolder = 0;
\r
283 stdstring statuspath;
\r
284 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
285 // get selected files/folders
\r
289 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
290 (DVTARGETDEVICE FAR *)NULL,
\r
294 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
296 if (SUCCEEDED(hres) && medium.hGlobal)
\r
298 if (m_State == FileStateDropHandler)
\r
301 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
302 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
303 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
305 ReleaseStgMedium ( &medium );
\r
306 return E_INVALIDARG;
\r
310 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
311 if ( NULL == drop )
\r
313 ReleaseStgMedium ( &stg );
\r
314 ReleaseStgMedium ( &medium );
\r
315 return E_INVALIDARG;
\r
318 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
320 itemStates |= ITEMIS_ONLYONE;
\r
321 for (int i = 0; i < count; i++)
\r
323 // find the path length in chars
\r
324 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
327 TCHAR * szFileName = new TCHAR[len+1];
\r
328 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
330 delete [] szFileName;
\r
333 stdstring str = stdstring(szFileName);
\r
334 delete [] szFileName;
\r
335 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
337 if (itemStates & ITEMIS_ONLYONE)
\r
340 strpath.SetFromWin(str.c_str());
\r
341 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
342 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
344 files_.push_back(str);
\r
347 //get the Subversion status of the item
\r
348 git_wc_status_kind status = git_wc_status_none;
\r
349 CTGitPath askedpath;
\r
350 askedpath.SetFromWin(str.c_str());
\r
354 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
358 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
359 fetchedstatus = status;
\r
360 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
361 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
362 if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
364 itemStates |= ITEMIS_FOLDER;
\r
365 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
366 itemStates |= ITEMIS_FOLDERINSVN;
\r
368 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
370 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
371 // itemStates |= ITEMIS_NEEDSLOCK;
\r
373 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
374 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
378 // sometimes, git_client_status() returns with an error.
\r
379 // in that case, we have to check if the working copy is versioned
\r
380 // anyway to show the 'correct' context menu
\r
381 if (askedpath.HasAdminDir())
\r
382 status = git_wc_status_normal;
\r
387 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
390 // TODO: should we really assume any sub-directory to be versioned
\r
391 // or only if it contains versioned files
\r
392 itemStates |= askedpath.GetAdminDirMask();
\r
394 if ((status == git_wc_status_unversioned) || (status == git_wc_status_ignored) || (status == git_wc_status_none))
\r
395 itemStates &= ~ITEMIS_INSVN;
\r
397 if (status == git_wc_status_ignored)
\r
398 itemStates |= ITEMIS_IGNORED;
\r
399 if (status == git_wc_status_normal)
\r
400 itemStates |= ITEMIS_NORMAL;
\r
401 if (status == git_wc_status_conflicted)
\r
402 itemStates |= ITEMIS_CONFLICTED;
\r
403 if (status == git_wc_status_added)
\r
404 itemStates |= ITEMIS_ADDED;
\r
405 if (status == git_wc_status_deleted)
\r
406 itemStates |= ITEMIS_DELETED;
\r
409 } // for (int i = 0; i < count; i++)
\r
410 GlobalUnlock ( drop );
\r
411 ReleaseStgMedium ( &stg );
\r
413 } // if (m_State == FileStateDropHandler)
\r
417 //Enumerate PIDLs which the user has selected
\r
418 CIDA* cida = (CIDA*)GlobalLock(medium.hGlobal);
\r
419 ItemIDList parent( GetPIDLFolder (cida));
\r
421 int count = cida->cidl;
\r
422 BOOL statfetched = FALSE;
\r
423 for (int i = 0; i < count; ++i)
\r
425 ItemIDList child (GetPIDLItem (cida, i), &parent);
\r
426 stdstring str = child.toString();
\r
427 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(str.c_str())))
\r
429 //check if our menu is requested for a subversion admin directory
\r
430 if (g_GitAdminDir.IsAdminDirPath(str.c_str()))
\r
433 files_.push_back(str);
\r
435 strpath.SetFromWin(str.c_str());
\r
436 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
437 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
440 //get the Subversion status of the item
\r
441 git_wc_status_kind status = git_wc_status_none;
\r
442 if ((g_ShellCache.IsSimpleContext())&&(strpath.IsDirectory()))
\r
444 if (strpath.HasAdminDir())
\r
445 status = git_wc_status_normal;
\r
452 if (strpath.HasAdminDir())
\r
453 stat.GetStatus(strpath, false, true, true);
\r
457 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
458 fetchedstatus = status;
\r
459 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
460 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
461 if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
463 itemStates |= ITEMIS_FOLDER;
\r
464 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
465 itemStates |= ITEMIS_FOLDERINSVN;
\r
467 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
\r
468 if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
\r
469 itemStates |= ITEMIS_CONFLICTED;
\r
470 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
472 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
473 // itemStates |= ITEMIS_NEEDSLOCK;
\r
475 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
476 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
480 // sometimes, git_client_status() returns with an error.
\r
481 // in that case, we have to check if the working copy is versioned
\r
482 // anyway to show the 'correct' context menu
\r
483 if (strpath.HasAdminDir())
\r
485 status = git_wc_status_normal;
\r
486 fetchedstatus = status;
\r
489 statfetched = TRUE;
\r
493 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
497 itemStates |= strpath.GetAdminDirMask();
\r
499 if ((status == git_wc_status_unversioned)||(status == git_wc_status_ignored)||(status == git_wc_status_none))
\r
500 itemStates &= ~ITEMIS_INSVN;
\r
501 if (status == git_wc_status_ignored)
\r
503 itemStates |= ITEMIS_IGNORED;
\r
504 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
505 // offer a 'remove from ignored list' entry
\r
506 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
507 // ignoredprops.empty();
\r
508 // for (int p=0; p<props.GetCount(); ++p)
\r
510 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
512 // std::string st = props.GetItemValue(p);
\r
513 // ignoredprops = MultibyteToWide(st.c_str());
\r
514 // // remove all escape chars ('\\')
\r
515 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
521 if (status == git_wc_status_normal)
\r
522 itemStates |= ITEMIS_NORMAL;
\r
523 if (status == git_wc_status_conflicted)
\r
524 itemStates |= ITEMIS_CONFLICTED;
\r
525 if (status == git_wc_status_added)
\r
526 itemStates |= ITEMIS_ADDED;
\r
527 if (status == git_wc_status_deleted)
\r
528 itemStates |= ITEMIS_DELETED;
\r
531 } // for (int i = 0; i < count; ++i)
\r
532 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
533 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
534 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
535 GlobalUnlock(medium.hGlobal);
\r
537 // if the item is a versioned folder, check if there's a patch file
\r
538 // in the clipboard to be used in "Apply Patch"
\r
539 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
542 if (IsClipboardFormatAvailable(cFormatDiff))
\r
543 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
545 if (IsClipboardFormatAvailable(CF_HDROP))
\r
546 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
550 ReleaseStgMedium ( &medium );
\r
551 if (medium.pUnkForRelease)
\r
553 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
554 relInterface->Release();
\r
559 // get folder background
\r
563 ItemIDList list(pIDFolder);
\r
564 folder_ = list.toString();
\r
565 git_wc_status_kind status = git_wc_status_none;
\r
566 if (IsClipboardFormatAvailable(CF_HDROP))
\r
567 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
569 CTGitPath askedpath;
\r
570 askedpath.SetFromWin(folder_.c_str());
\r
572 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
578 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
581 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
582 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
583 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
584 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
586 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
587 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
589 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
590 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
595 // sometimes, git_client_status() returns with an error.
\r
596 // in that case, we have to check if the working copy is versioned
\r
597 // anyway to show the 'correct' context menu
\r
598 if (askedpath.HasAdminDir())
\r
599 status = git_wc_status_normal;
\r
602 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
603 itemStatesFolder |= askedpath.GetAdminDirMask();
\r
605 if (status == git_wc_status_normal)
\r
606 itemStatesFolder |= ITEMIS_NORMAL;
\r
607 if (status == git_wc_status_conflicted)
\r
608 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
609 if (status == git_wc_status_added)
\r
610 itemStatesFolder |= ITEMIS_ADDED;
\r
611 if (status == git_wc_status_deleted)
\r
612 itemStatesFolder |= ITEMIS_DELETED;
\r
617 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
622 status = fetchedstatus;
\r
624 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
625 itemStatesFolder |= askedpath.GetAdminDirMask();
\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 itemStates |= askedpath.GetAdminDirMask();
\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
700 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
702 TCHAR menutextbuffer[512] = {0};
\r
703 TCHAR verbsbuffer[255] = {0};
\r
704 MAKESTRING(stringid);
\r
708 //menu entry for the top context menu, so append an "Git " before
\r
709 //the menu text to indicate where the entry comes from
\r
710 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
712 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
714 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
\r
715 // so we have an easy and fast way to check the current branch
\r
716 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
\r
717 if (com == ShellMenuCommit)
\r
720 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
721 CString sProjectRoot;
\r
722 CString sBranchName;
\r
724 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
726 if (sBranchName.GetLength() == 40)
\r
728 // if SHA1 only show 4 first bytes
\r
729 BOOL bIsSha1 = TRUE;
\r
730 for (int i=0; i<40; i++)
\r
731 if ( !iswxdigit(sBranchName[i]) )
\r
737 sBranchName = sBranchName.Left(8) + _T("....");
\r
741 if (sBranchName.GetLength() > 64)
\r
742 sBranchName = sBranchName.Left(64) + _T("...");
\r
744 // scan to before "..."
\r
745 LPTSTR s = menutextbuffer + _tcslen(menutextbuffer)-1;
\r
746 if (s > menutextbuffer)
\r
748 while (s > menutextbuffer)
\r
760 s = menutextbuffer;
\r
763 // append branch name and end with ...
\r
764 _tcscpy(s, _T(" -> \"") + sBranchName + _T("\"..."));
\r
768 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
770 // on win2k, the context menu does not work properly if we use
\r
771 // icon bitmaps. At least the menu text is empty in the context menu
\r
772 // for folder backgrounds (seems like a win2k bug).
\r
773 // the workaround is to use the check/unchecked bitmaps, which are drawn
\r
774 // with AND raster op, but it's better than nothing at all
\r
775 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
778 HBITMAP bmp = IconToBitmap(icon);
\r
779 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
784 MENUITEMINFO menuiteminfo;
\r
785 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
786 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
787 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
\r
788 menuiteminfo.fType = MFT_STRING;
\r
789 menuiteminfo.dwTypeData = menutextbuffer;
\r
792 menuiteminfo.fMask |= MIIM_BITMAP;
\r
793 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
795 menuiteminfo.wID = id;
\r
796 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
801 //menu entry for the top context menu, so append an "Git " before
\r
802 //the menu text to indicate where the entry comes from
\r
803 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
805 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
806 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
807 stdstring verb = stdstring(menutextbuffer);
\r
808 if (verb.find('&') != -1)
\r
810 verb.erase(verb.find('&'),1);
\r
812 myVerbsMap[verb] = id - idCmdFirst;
\r
813 myVerbsMap[verb] = id;
\r
814 myVerbsIDMap[id - idCmdFirst] = verb;
\r
815 myVerbsIDMap[id] = verb;
\r
816 // We store the relative and absolute diameter
\r
817 // (drawitem callback uses absolute, others relative)
\r
818 myIDMap[id - idCmdFirst] = com;
\r
821 mySubMenuMap[pos] = com;
\r
824 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
826 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
827 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
828 return bitmap_it->second;
\r
830 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
836 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
837 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
839 rect.left = rect.top = 0;
\r
841 HWND desktop = ::GetDesktopWindow();
\r
842 if (desktop == NULL)
\r
844 DestroyIcon(hIcon);
\r
848 HDC screen_dev = ::GetDC(desktop);
\r
849 if (screen_dev == NULL)
\r
851 DestroyIcon(hIcon);
\r
855 // Create a compatible DC
\r
856 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
857 if (dst_hdc == NULL)
\r
859 DestroyIcon(hIcon);
\r
860 ::ReleaseDC(desktop, screen_dev);
\r
864 // Create a new bitmap of icon size
\r
865 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
868 DestroyIcon(hIcon);
\r
869 ::DeleteDC(dst_hdc);
\r
870 ::ReleaseDC(desktop, screen_dev);
\r
874 // Select it into the compatible DC
\r
875 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
876 if (old_dst_bmp == NULL)
\r
878 DestroyIcon(hIcon);
\r
882 // Fill the background of the compatible DC with the white color
\r
883 // that is taken by menu routines as transparent
\r
884 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
885 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
887 // Draw the icon into the compatible DC
\r
888 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
890 // Restore settings
\r
891 ::SelectObject(dst_hdc, old_dst_bmp);
\r
892 ::DeleteDC(dst_hdc);
\r
893 ::ReleaseDC(desktop, screen_dev);
\r
894 DestroyIcon(hIcon);
\r
896 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
900 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
903 tempfile = stdstring();
\r
904 //write all selected files and paths to a temporary file
\r
905 //for TortoiseProc.exe to read out again.
\r
907 DWORD pathlength = GetTempPath(0, NULL);
\r
908 TCHAR * path = new TCHAR[pathlength+1];
\r
909 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
910 GetTempPath (pathlength+1, path);
\r
911 GetTempFileName (path, _T("git"), 0, tempFile);
\r
912 tempfile = stdstring(tempFile);
\r
914 HANDLE file = ::CreateFile (tempFile,
\r
919 FILE_ATTRIBUTE_TEMPORARY,
\r
923 delete [] tempFile;
\r
924 if (file == INVALID_HANDLE_VALUE)
\r
927 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
929 if (!OpenClipboard(NULL))
\r
932 stdstring sClipboardText;
\r
933 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
934 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
937 TCHAR szFileName[MAX_PATH];
\r
938 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
939 for(UINT i = 0; i < cFiles; ++i)
\r
941 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
942 stdstring filename = szFileName;
\r
943 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
944 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
946 GlobalUnlock(hDrop);
\r
949 GlobalUnlock(hglb);
\r
952 ::CloseHandle(file);
\r
957 stdstring CShellExt::WriteFileListToTempFile()
\r
959 //write all selected files and paths to a temporary file
\r
960 //for TortoiseProc.exe to read out again.
\r
961 DWORD pathlength = GetTempPath(0, NULL);
\r
962 TCHAR * path = new TCHAR[pathlength+1];
\r
963 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
964 GetTempPath (pathlength+1, path);
\r
965 GetTempFileName (path, _T("git"), 0, tempFile);
\r
966 stdstring retFilePath = stdstring(tempFile);
\r
968 HANDLE file = ::CreateFile (tempFile,
\r
973 FILE_ATTRIBUTE_TEMPORARY,
\r
977 delete [] tempFile;
\r
978 if (file == INVALID_HANDLE_VALUE)
\r
979 return stdstring();
\r
982 if (files_.empty())
\r
984 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
985 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
988 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
990 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
991 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
993 ::CloseHandle(file);
\r
994 return retFilePath;
\r
997 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
999 PreserveChdir preserveChdir;
\r
1002 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1003 return NOERROR; //we don't change the default action
\r
1005 if ((files_.size() == 0)||(folder_.size() == 0))
\r
1008 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1011 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
1013 //the drop handler only has eight commands, but not all are visible at the same time:
\r
1014 //if the source file(s) are under version control then those files can be moved
\r
1015 //to the new location or they can be moved with a rename,
\r
1016 //if they are unversioned then they can be added to the working copy
\r
1017 //if they are versioned, they also can be exported to an unversioned location
\r
1018 UINT idCmd = idCmdFirst;
\r
1021 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1022 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
1023 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
1025 // Git move and rename here
\r
1026 // 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
1027 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1028 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
1031 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1032 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
1033 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
1035 // Git copy and rename here, source and target from same repository
\r
1036 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
1037 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1038 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
1041 // available if target is versioned and source is either unversioned or from another repository
\r
1042 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
1043 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
1045 // Git export here
\r
1046 // available if source is versioned and a folder
\r
1047 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1048 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
1050 // Git export all here
\r
1051 // available if source is versioned and a folder
\r
1052 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1053 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
1056 // available if source is a patchfile
\r
1057 if (itemStates & ITEMIS_PATCHFILE)
\r
1058 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
1061 if (idCmd != idCmdFirst)
\r
1062 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1064 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1067 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
1070 UINT /*idCmdLast*/,
\r
1073 ATLTRACE("Shell :: QueryContextMenu\n");
\r
1074 PreserveChdir preserveChdir;
\r
1076 //first check if our drop handler is called
\r
1077 //and then (if true) provide the context menu for the
\r
1079 if (m_State == FileStateDropHandler)
\r
1081 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
1084 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1085 return NOERROR; //we don't change the default action
\r
1087 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
1090 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1093 int csidlarray[] =
\r
1096 CSIDL_CDBURN_AREA,
\r
1097 CSIDL_COMMON_FAVORITES,
\r
1098 CSIDL_COMMON_STARTMENU,
\r
1099 CSIDL_COMPUTERSNEARME,
\r
1100 CSIDL_CONNECTIONS,
\r
1107 CSIDL_INTERNET_CACHE,
\r
1117 if (IsIllegalFolder(folder_, csidlarray))
\r
1120 if (folder_.empty())
\r
1122 // folder is empty, but maybe files are selected
\r
1123 if (files_.size() == 0)
\r
1124 return NOERROR; // nothing selected - we don't have a menu to show
\r
1125 // check whether a selected entry is an UID - those are namespace extensions
\r
1126 // which we can't handle
\r
1127 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1129 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1134 //check if our menu is requested for a subversion admin directory
\r
1135 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1138 if (uFlags & CMF_EXTENDEDVERBS)
\r
1139 itemStates |= ITEMIS_EXTENDED;
\r
1141 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1142 if ( bShortcut && (files_.size()==1))
\r
1144 // Don't show the context menu for a link if the
\r
1145 // destination is not part of a working copy.
\r
1146 // It would only show the standard menu items
\r
1147 // which are already shown for the lnk-file.
\r
1148 CString path = files_.front().c_str();
\r
1149 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1155 //check if we already added our menu entry for a folder.
\r
1156 //we check that by iterating through all menu entries and check if
\r
1157 //the dwItemData member points to our global ID string. That string is set
\r
1158 //by our shell extension when the folder menu is inserted.
\r
1159 TCHAR menubuf[MAX_PATH];
\r
1160 int count = GetMenuItemCount(hMenu);
\r
1161 for (int i=0; i<count; ++i)
\r
1163 MENUITEMINFO miif;
\r
1164 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1165 miif.cbSize = sizeof(MENUITEMINFO);
\r
1166 miif.fMask = MIIM_DATA;
\r
1167 miif.dwTypeData = menubuf;
\r
1168 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1169 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1170 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1175 UINT idCmd = idCmdFirst;
\r
1177 //create the sub menu
\r
1178 HMENU subMenu = CreateMenu();
\r
1179 int indexSubMenu = 0;
\r
1181 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1182 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1184 int menuIndex = 0;
\r
1185 bool bAddSeparator = false;
\r
1186 bool bMenuEntryAdded = false;
\r
1187 bool bMenuEmpty = true;
\r
1188 // insert separator at start
\r
1189 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1190 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1191 // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up
\r
1192 /*if (fullver <= 0x500)
\r
1193 bShowIcons = false;*/
\r
1196 if (itemStates & (ITEMIS_INSVN|ITEMIS_FOLDERINSVN))
\r
1198 // show current branch name (as a "read-only" menu entry)
\r
1200 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
1201 CString sProjectRoot;
\r
1202 CString sBranchName;
\r
1204 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
1206 if (sBranchName.GetLength() == 40)
\r
1208 // if SHA1 only show 4 first bytes
\r
1209 BOOL bIsSha1 = TRUE;
\r
1210 for (int i=0; i<40; i++)
\r
1211 if ( !iswxdigit(sBranchName[i]) )
\r
1217 sBranchName = sBranchName.Left(8) + _T("....");
\r
1220 sBranchName = _T('"') + sBranchName + _T('"');
\r
1222 const int icon = IDI_COPY;
\r
1223 const int pos = indexMenu++;
\r
1224 const int id = idCmd++;
\r
1226 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1228 InsertMenu(hMenu, pos, MF_DISABLED|MF_GRAYED|MF_BYPOSITION|MF_STRING, id, sBranchName);
\r
1229 HBITMAP bmp = IconToBitmap(icon);
\r
1230 SetMenuItemBitmaps(hMenu, pos, MF_BYPOSITION, bmp, bmp);
\r
1234 MENUITEMINFO menuiteminfo;
\r
1235 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1236 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1237 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
\r
1238 menuiteminfo.fState = MFS_DISABLED;
\r
1239 menuiteminfo.fType = MFT_STRING;
\r
1240 menuiteminfo.dwTypeData = (LPWSTR)sBranchName.GetString();
\r
1243 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1244 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
1246 if (menuiteminfo.hbmpItem == HBMMENU_CALLBACK)
\r
1248 // WM_DRAWITEM uses myIDMap to get icon, we use the same icon as create branch
\r
1249 myIDMap[id - idCmdFirst] = ShellMenuBranch;
\r
1250 myIDMap[id] = ShellMenuBranch;
\r
1253 menuiteminfo.wID = id;
\r
1254 InsertMenuItem(hMenu, pos, TRUE, &menuiteminfo);
\r
1260 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1262 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1264 // we don't add a separator immediately. Because there might not be
\r
1265 // another 'normal' menu entry after we insert a separator.
\r
1266 // we simply set a flag here, indicating that before the next
\r
1267 // 'normal' menu entry, a separator should be added.
\r
1269 bAddSeparator = true;
\r
1273 // check the conditions whether to show the menu entry or not
\r
1274 bool bInsertMenu = false;
\r
1276 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1278 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1280 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1281 bInsertMenu = true;
\r
1283 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1284 bInsertMenu = true;
\r
1285 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1286 bInsertMenu = true;
\r
1288 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1290 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1292 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1293 bInsertMenu = true;
\r
1295 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1296 bInsertMenu = true;
\r
1297 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1298 bInsertMenu = true;
\r
1300 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1302 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1304 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1305 bInsertMenu = true;
\r
1307 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1308 bInsertMenu = true;
\r
1309 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1310 bInsertMenu = true;
\r
1312 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1314 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1316 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1317 bInsertMenu = true;
\r
1319 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1320 bInsertMenu = true;
\r
1321 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1322 bInsertMenu = true;
\r
1324 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1328 // insert a separator
\r
1329 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1331 bAddSeparator = false;
\r
1332 bMenuEntryAdded = false;
\r
1333 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1337 // handle special cases (sub menus)
\r
1338 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1340 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons, uFlags);
\r
1341 bMenuEntryAdded = true;
\r
1342 bMenuEmpty = false;
\r
1346 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1348 // insert the menu entry
\r
1349 InsertGitMenu( bIsTop,
\r
1350 bIsTop ? hMenu : subMenu,
\r
1351 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1353 menuInfo[menuIndex].menuTextID,
\r
1354 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1356 menuInfo[menuIndex].command,
\r
1360 bMenuEntryAdded = true;
\r
1361 bMenuEmpty = false;
\r
1370 //add sub menu to main context menu
\r
1371 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1372 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1373 MAKESTRING(IDS_MENUSUBMENU);
\r
1374 MENUITEMINFO menuiteminfo;
\r
1375 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1376 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1377 menuiteminfo.fType = MFT_STRING;
\r
1378 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1380 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1381 if (folder_.size())
\r
1383 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1384 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1385 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1386 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1388 else if (!bShortcut && (files_.size()==1))
\r
1390 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1391 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1392 myIDMap[idCmd] = ShellSubMenuFile;
\r
1394 else if (bShortcut && (files_.size()==1))
\r
1396 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1397 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1398 myIDMap[idCmd] = ShellSubMenuLink;
\r
1400 else if (files_.size() > 1)
\r
1402 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1403 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1404 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1408 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1409 myIDMap[idCmd] = ShellSubMenu;
\r
1411 HBITMAP bmp = NULL;
\r
1412 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1414 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
1417 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
1418 bmp = IconToBitmap(uIcon);
\r
1419 menuiteminfo.hbmpChecked = bmp;
\r
1420 menuiteminfo.hbmpUnchecked = bmp;
\r
1425 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
1428 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1429 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1432 menuiteminfo.hSubMenu = subMenu;
\r
1433 menuiteminfo.wID = idCmd++;
\r
1434 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1437 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1439 //return number of menu items added
\r
1440 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1444 // This is called when you invoke a command on the menu:
\r
1445 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1447 PreserveChdir preserveChdir;
\r
1448 HRESULT hr = E_INVALIDARG;
\r
1449 if (lpcmi == NULL)
\r
1452 std::string command;
\r
1453 std::string parent;
\r
1456 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1458 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1460 if (HIWORD(lpcmi->lpVerb))
\r
1462 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1463 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1464 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1465 idCmd = verb_it->second;
\r
1470 // See if we have a handler interface for this id
\r
1471 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1472 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1474 STARTUPINFO startup;
\r
1475 PROCESS_INFORMATION process;
\r
1476 memset(&startup, 0, sizeof(startup));
\r
1477 startup.cb = sizeof(startup);
\r
1478 memset(&process, 0, sizeof(process));
\r
1479 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1480 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1482 //TortoiseProc expects a command line of the form:
\r
1483 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1485 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1487 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1488 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1489 stdstring svnCmd = _T(" /command:");
\r
1490 stdstring tempfile;
\r
1491 switch (id_it->second)
\r
1494 case ShellMenuSync:
\r
1495 svnCmd += _T("sync /path:\"");
\r
1496 svnCmd += folder_;
\r
1497 svnCmd += _T("\"");
\r
1499 case ShellMenuCheckout:
\r
1500 svnCmd += _T("checkout /path:\"");
\r
1501 svnCmd += folder_;
\r
1502 svnCmd += _T("\"");
\r
1504 case ShellMenuUpdate:
\r
1505 tempfile = WriteFileListToTempFile();
\r
1506 svnCmd += _T("update /pathfile:\"");
\r
1507 svnCmd += tempfile;
\r
1508 svnCmd += _T("\"");
\r
1509 svnCmd += _T(" /deletepathfile");
\r
1511 case ShellMenuSubSync:
\r
1512 tempfile = WriteFileListToTempFile();
\r
1513 svnCmd += _T("subsync /pathfile:\"");
\r
1514 svnCmd += tempfile;
\r
1515 svnCmd += _T("\"");
\r
1516 svnCmd += _T(" /deletepathfile");
\r
1517 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1519 svnCmd += _T(" /bkpath:");
\r
1520 svnCmd += folder_;
\r
1523 case ShellMenuUpdateExt:
\r
1524 tempfile = WriteFileListToTempFile();
\r
1525 svnCmd += _T("subupdate /pathfile:\"");
\r
1526 svnCmd += tempfile;
\r
1527 svnCmd += _T("\"");
\r
1528 svnCmd += _T(" /deletepathfile");
\r
1529 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1531 svnCmd += _T(" /bkpath:");
\r
1532 svnCmd += folder_;
\r
1535 case ShellMenuCommit:
\r
1536 tempfile = WriteFileListToTempFile();
\r
1537 svnCmd += _T("commit /pathfile:\"");
\r
1538 svnCmd += tempfile;
\r
1539 svnCmd += _T("\"");
\r
1540 svnCmd += _T(" /deletepathfile");
\r
1542 case ShellMenuAdd:
\r
1543 case ShellMenuAddAsReplacement:
\r
1544 tempfile = WriteFileListToTempFile();
\r
1545 svnCmd += _T("add /pathfile:\"");
\r
1546 svnCmd += tempfile;
\r
1547 svnCmd += _T("\"");
\r
1548 svnCmd += _T(" /deletepathfile");
\r
1550 case ShellMenuIgnore:
\r
1551 tempfile = WriteFileListToTempFile();
\r
1552 svnCmd += _T("ignore /pathfile:\"");
\r
1553 svnCmd += tempfile;
\r
1554 svnCmd += _T("\"");
\r
1555 svnCmd += _T(" /deletepathfile");
\r
1557 case ShellMenuIgnoreCaseSensitive:
\r
1558 tempfile = WriteFileListToTempFile();
\r
1559 svnCmd += _T("ignore /pathfile:\"");
\r
1560 svnCmd += tempfile;
\r
1561 svnCmd += _T("\"");
\r
1562 svnCmd += _T(" /deletepathfile");
\r
1563 svnCmd += _T(" /onlymask");
\r
1565 case ShellMenuUnIgnore:
\r
1566 tempfile = WriteFileListToTempFile();
\r
1567 svnCmd += _T("unignore /pathfile:\"");
\r
1568 svnCmd += tempfile;
\r
1569 svnCmd += _T("\"");
\r
1570 svnCmd += _T(" /deletepathfile");
\r
1572 case ShellMenuUnIgnoreCaseSensitive:
\r
1573 tempfile = WriteFileListToTempFile();
\r
1574 svnCmd += _T("unignore /pathfile:\"");
\r
1575 svnCmd += tempfile;
\r
1576 svnCmd += _T("\"");
\r
1577 svnCmd += _T(" /deletepathfile");
\r
1578 svnCmd += _T(" /onlymask");
\r
1580 case ShellMenuRevert:
\r
1581 tempfile = WriteFileListToTempFile();
\r
1582 svnCmd += _T("revert /pathfile:\"");
\r
1583 svnCmd += tempfile;
\r
1584 svnCmd += _T("\"");
\r
1585 svnCmd += _T(" /deletepathfile");
\r
1587 case ShellMenuDelUnversioned:
\r
1588 svnCmd += _T("delunversioned /path:\"");
\r
1589 svnCmd += folder_;
\r
1590 svnCmd += _T("\"");
\r
1592 case ShellMenuCleanup:
\r
1593 tempfile = WriteFileListToTempFile();
\r
1594 svnCmd += _T("cleanup /pathfile:\"");
\r
1595 svnCmd += tempfile;
\r
1596 svnCmd += _T("\"");
\r
1597 svnCmd += _T(" /deletepathfile");
\r
1599 case ShellMenuSendMail:
\r
1600 tempfile = WriteFileListToTempFile();
\r
1601 svnCmd += _T("sendmail /pathfile:\"");
\r
1602 svnCmd += tempfile;
\r
1603 svnCmd += _T("\"");
\r
1604 svnCmd += _T(" /deletepathfile");
\r
1606 case ShellMenuResolve:
\r
1607 tempfile = WriteFileListToTempFile();
\r
1608 svnCmd += _T("resolve /pathfile:\"");
\r
1609 svnCmd += tempfile;
\r
1610 svnCmd += _T("\"");
\r
1611 svnCmd += _T(" /deletepathfile");
\r
1613 case ShellMenuSwitch:
\r
1614 svnCmd += _T("switch /path:\"");
\r
1615 if (files_.size() > 0)
\r
1616 svnCmd += files_.front();
\r
1618 svnCmd += folder_;
\r
1619 svnCmd += _T("\"");
\r
1621 case ShellMenuImport:
\r
1622 svnCmd += _T("import /path:\"");
\r
1623 svnCmd += folder_;
\r
1624 svnCmd += _T("\"");
\r
1626 case ShellMenuExport:
\r
1627 svnCmd += _T("export /path:\"");
\r
1628 svnCmd += folder_;
\r
1629 svnCmd += _T("\"");
\r
1631 case ShellMenuAbout:
\r
1632 svnCmd += _T("about");
\r
1634 case ShellMenuCreateRepos:
\r
1635 svnCmd += _T("repocreate /path:\"");
\r
1636 svnCmd += folder_;
\r
1637 svnCmd += _T("\"");
\r
1639 case ShellMenuMerge:
\r
1640 svnCmd += _T("merge /path:\"");
\r
1641 if (files_.size() > 0)
\r
1642 svnCmd += files_.front();
\r
1644 svnCmd += folder_;
\r
1645 svnCmd += _T("\"");
\r
1647 case ShellMenuMergeAll:
\r
1648 svnCmd += _T("mergeall /path:\"");
\r
1649 if (files_.size() > 0)
\r
1650 svnCmd += files_.front();
\r
1652 svnCmd += folder_;
\r
1653 svnCmd += _T("\"");
\r
1655 case ShellMenuCopy:
\r
1656 svnCmd += _T("copy /path:\"");
\r
1657 if (files_.size() > 0)
\r
1658 svnCmd += files_.front();
\r
1660 svnCmd += folder_;
\r
1661 svnCmd += _T("\"");
\r
1663 case ShellMenuSettings:
\r
1664 svnCmd += _T("settings /path:\"");
\r
1665 if (files_.size() > 0)
\r
1666 svnCmd += files_.front();
\r
1668 svnCmd += folder_;
\r
1669 svnCmd += _T("\"");
\r
1671 case ShellMenuHelp:
\r
1672 svnCmd += _T("help");
\r
1674 case ShellMenuRename:
\r
1675 svnCmd += _T("rename /path:\"");
\r
1676 if (files_.size() > 0)
\r
1677 svnCmd += files_.front();
\r
1679 svnCmd += folder_;
\r
1680 svnCmd += _T("\"");
\r
1682 case ShellMenuRemove:
\r
1683 tempfile = WriteFileListToTempFile();
\r
1684 svnCmd += _T("remove /pathfile:\"");
\r
1685 svnCmd += tempfile;
\r
1686 svnCmd += _T("\"");
\r
1687 svnCmd += _T(" /deletepathfile");
\r
1689 case ShellMenuRemoveKeep:
\r
1690 tempfile = WriteFileListToTempFile();
\r
1691 svnCmd += _T("remove /pathfile:\"");
\r
1692 svnCmd += tempfile;
\r
1693 svnCmd += _T("\"");
\r
1694 svnCmd += _T(" /deletepathfile");
\r
1695 svnCmd += _T(" /keep");
\r
1697 case ShellMenuDiff:
\r
1698 svnCmd += _T("diff /path:\"");
\r
1699 if (files_.size() == 1)
\r
1700 svnCmd += files_.front();
\r
1701 else if (files_.size() == 2)
\r
1703 std::vector<stdstring>::iterator I = files_.begin();
\r
1706 svnCmd += _T("\" /path2:\"");
\r
1710 svnCmd += folder_;
\r
1711 svnCmd += _T("\"");
\r
1712 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1713 svnCmd += _T(" /alternative");
\r
1715 case ShellMenuPrevDiff:
\r
1716 svnCmd += _T("prevdiff /path:\"");
\r
1717 if (files_.size() == 1)
\r
1718 svnCmd += files_.front();
\r
1720 svnCmd += folder_;
\r
1721 svnCmd += _T("\"");
\r
1722 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1723 svnCmd += _T(" /alternative");
\r
1725 case ShellMenuUrlDiff:
\r
1726 svnCmd += _T("urldiff /path:\"");
\r
1727 if (files_.size() == 1)
\r
1728 svnCmd += files_.front();
\r
1730 svnCmd += folder_;
\r
1731 svnCmd += _T("\"");
\r
1733 case ShellMenuDropCopyAdd:
\r
1734 tempfile = WriteFileListToTempFile();
\r
1735 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1736 svnCmd += tempfile;
\r
1737 svnCmd += _T("\"");
\r
1738 svnCmd += _T(" /deletepathfile");
\r
1739 svnCmd += _T(" /droptarget:\"");
\r
1740 svnCmd += folder_;
\r
1741 svnCmd += _T("\"";)
\r
1743 case ShellMenuDropCopy:
\r
1744 tempfile = WriteFileListToTempFile();
\r
1745 svnCmd += _T("dropcopy /pathfile:\"");
\r
1746 svnCmd += tempfile;
\r
1747 svnCmd += _T("\"");
\r
1748 svnCmd += _T(" /deletepathfile");
\r
1749 svnCmd += _T(" /droptarget:\"");
\r
1750 svnCmd += folder_;
\r
1751 svnCmd += _T("\"";)
\r
1753 case ShellMenuDropCopyRename:
\r
1754 tempfile = WriteFileListToTempFile();
\r
1755 svnCmd += _T("dropcopy /pathfile:\"");
\r
1756 svnCmd += tempfile;
\r
1757 svnCmd += _T("\"");
\r
1758 svnCmd += _T(" /deletepathfile");
\r
1759 svnCmd += _T(" /droptarget:\"");
\r
1760 svnCmd += folder_;
\r
1761 svnCmd += _T("\" /rename";)
\r
1763 case ShellMenuDropMove:
\r
1764 tempfile = WriteFileListToTempFile();
\r
1765 svnCmd += _T("dropmove /pathfile:\"");
\r
1766 svnCmd += tempfile;
\r
1767 svnCmd += _T("\"");
\r
1768 svnCmd += _T(" /deletepathfile");
\r
1769 svnCmd += _T(" /droptarget:\"");
\r
1770 svnCmd += folder_;
\r
1771 svnCmd += _T("\"");
\r
1773 case ShellMenuDropMoveRename:
\r
1774 tempfile = WriteFileListToTempFile();
\r
1775 svnCmd += _T("dropmove /pathfile:\"");
\r
1776 svnCmd += tempfile;
\r
1777 svnCmd += _T("\"");
\r
1778 svnCmd += _T(" /deletepathfile");
\r
1779 svnCmd += _T(" /droptarget:\"");
\r
1780 svnCmd += folder_;
\r
1781 svnCmd += _T("\" /rename";)
\r
1783 case ShellMenuDropExport:
\r
1784 tempfile = WriteFileListToTempFile();
\r
1785 svnCmd += _T("dropexport /pathfile:\"");
\r
1786 svnCmd += tempfile;
\r
1787 svnCmd += _T("\"");
\r
1788 svnCmd += _T(" /deletepathfile");
\r
1789 svnCmd += _T(" /droptarget:\"");
\r
1790 svnCmd += folder_;
\r
1791 svnCmd += _T("\"");
\r
1793 case ShellMenuDropExportExtended:
\r
1794 tempfile = WriteFileListToTempFile();
\r
1795 svnCmd += _T("dropexport /pathfile:\"");
\r
1796 svnCmd += tempfile;
\r
1797 svnCmd += _T("\"");
\r
1798 svnCmd += _T(" /deletepathfile");
\r
1799 svnCmd += _T(" /droptarget:\"");
\r
1800 svnCmd += folder_;
\r
1801 svnCmd += _T("\"");
\r
1802 svnCmd += _T(" /extended");
\r
1804 case ShellMenuLog:
\r
1805 svnCmd += _T("log /path:\"");
\r
1806 if (files_.size() > 0)
\r
1807 svnCmd += files_.front();
\r
1809 svnCmd += folder_;
\r
1810 svnCmd += _T("\"");
\r
1812 case ShellMenuConflictEditor:
\r
1813 svnCmd += _T("conflicteditor /path:\"");
\r
1814 if (files_.size() > 0)
\r
1815 svnCmd += files_.front();
\r
1817 svnCmd += folder_;
\r
1818 svnCmd += _T("\"");
\r
1820 case ShellMenuRelocate:
\r
1821 svnCmd += _T("relocate /path:\"");
\r
1822 if (files_.size() > 0)
\r
1823 svnCmd += files_.front();
\r
1825 svnCmd += folder_;
\r
1826 svnCmd += _T("\"");
\r
1828 case ShellMenuGitSVNRebase:
\r
1829 svnCmd += _T("svnrebase /path:\"");
\r
1830 if (files_.size() > 0)
\r
1831 svnCmd += files_.front();
\r
1833 svnCmd += folder_;
\r
1834 svnCmd += _T("\"");
\r
1836 case ShellMenuGitSVNDCommit:
\r
1837 svnCmd += _T("svndcommit /path:\"");
\r
1838 if (files_.size() > 0)
\r
1839 svnCmd += files_.front();
\r
1841 svnCmd += folder_;
\r
1842 svnCmd += _T("\"");
\r
1844 case ShellMenuGitSVNIgnore:
\r
1845 svnCmd += _T("svnignore /path:\"");
\r
1846 if (files_.size() > 0)
\r
1847 svnCmd += files_.front();
\r
1849 svnCmd += folder_;
\r
1850 svnCmd += _T("\"");
\r
1852 case ShellMenuRebase:
\r
1853 svnCmd += _T("rebase /path:\"");
\r
1854 if (files_.size() > 0)
\r
1855 svnCmd += files_.front();
\r
1857 svnCmd += folder_;
\r
1858 svnCmd += _T("\"");
\r
1860 case ShellMenuShowChanged:
\r
1861 if (files_.size() > 1)
\r
1863 tempfile = WriteFileListToTempFile();
\r
1864 svnCmd += _T("repostatus /pathfile:\"");
\r
1865 svnCmd += tempfile;
\r
1866 svnCmd += _T("\"");
\r
1867 svnCmd += _T(" /deletepathfile");
\r
1871 svnCmd += _T("repostatus /path:\"");
\r
1872 if (files_.size() > 0)
\r
1873 svnCmd += files_.front();
\r
1875 svnCmd += folder_;
\r
1876 svnCmd += _T("\"");
\r
1879 case ShellMenuRefBrowse:
\r
1880 svnCmd += _T("refbrowse /path:\"");
\r
1881 if (files_.size() > 0)
\r
1882 svnCmd += files_.front();
\r
1884 svnCmd += folder_;
\r
1885 svnCmd += _T("\"");
\r
1887 case ShellMenuRefLog:
\r
1888 svnCmd += _T("reflog /path:\"");
\r
1889 if (files_.size() > 0)
\r
1890 svnCmd += files_.front();
\r
1892 svnCmd += folder_;
\r
1893 svnCmd += _T("\"");
\r
1896 case ShellMenuStashSave:
\r
1897 svnCmd += _T("stashsave /path:\"");
\r
1898 if (files_.size() > 0)
\r
1899 svnCmd += files_.front();
\r
1901 svnCmd += folder_;
\r
1902 svnCmd += _T("\"");
\r
1905 case ShellMenuStashApply:
\r
1906 svnCmd += _T("stashapply /path:\"");
\r
1907 if (files_.size() > 0)
\r
1908 svnCmd += files_.front();
\r
1910 svnCmd += folder_;
\r
1911 svnCmd += _T("\"");
\r
1914 case ShellMenuStashPop:
\r
1915 svnCmd += _T("stashpop /path:\"");
\r
1916 if (files_.size() > 0)
\r
1917 svnCmd += files_.front();
\r
1919 svnCmd += folder_;
\r
1920 svnCmd += _T("\"");
\r
1924 case ShellMenuStashList:
\r
1925 svnCmd += _T("reflog /path:\"");
\r
1926 if (files_.size() > 0)
\r
1927 svnCmd += files_.front();
\r
1929 svnCmd += folder_;
\r
1930 svnCmd += _T("\" /ref:refs/stash");
\r
1933 case ShellMenuSubAdd:
\r
1934 svnCmd += _T("subadd /path:\"");
\r
1935 if (files_.size() > 0)
\r
1936 svnCmd += files_.front();
\r
1938 svnCmd += folder_;
\r
1939 svnCmd += _T("\"");
\r
1942 case ShellMenuBlame:
\r
1943 svnCmd += _T("blame /path:\"");
\r
1944 if (files_.size() > 0)
\r
1945 svnCmd += files_.front();
\r
1947 svnCmd += folder_;
\r
1948 svnCmd += _T("\"");
\r
1950 case ShellMenuCreatePatch:
\r
1951 tempfile = WriteFileListToTempFile();
\r
1952 svnCmd += _T("createpatch /pathfile:\"");
\r
1953 svnCmd += tempfile;
\r
1954 svnCmd += _T("\"");
\r
1955 svnCmd += _T(" /deletepathfile");
\r
1957 case ShellMenuApplyPatch:
\r
1958 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1960 // if there's a patch file in the clipboard, we save it
\r
1961 // to a temporary file and tell TortoiseMerge to use that one
\r
1962 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1963 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1965 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1966 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1968 DWORD len = GetTempPath(0, NULL);
\r
1969 TCHAR * path = new TCHAR[len+1];
\r
1970 TCHAR * tempF = new TCHAR[len+100];
\r
1971 GetTempPath (len+1, path);
\r
1972 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1973 std::wstring sTempFile = std::wstring(tempF);
\r
1978 size_t patchlen = strlen(lpstr);
\r
1979 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1982 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1983 if (size == patchlen)
\r
1985 itemStates |= ITEMIS_PATCHFILE;
\r
1987 files_.push_back(sTempFile);
\r
1991 GlobalUnlock(hglb);
\r
1992 CloseClipboard();
\r
1995 if (itemStates & ITEMIS_PATCHFILE)
\r
1997 svnCmd = _T(" /diff:\"");
\r
1998 if (files_.size() > 0)
\r
2000 svnCmd += files_.front();
\r
2001 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
2003 svnCmd += _T("\" /patchpath:\"");
\r
2004 svnCmd += folder_;
\r
2008 svnCmd += folder_;
\r
2009 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
2010 svnCmd += _T("\" /wc");
\r
2012 svnCmd += _T("\"");
\r
2016 svnCmd = _T(" /patchpath:\"");
\r
2017 if (files_.size() > 0)
\r
2018 svnCmd += files_.front();
\r
2020 svnCmd += folder_;
\r
2021 svnCmd += _T("\"");
\r
2024 myVerbsIDMap.clear();
\r
2025 myVerbsMap.clear();
\r
2026 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2029 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2030 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2031 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2034 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2035 (LPTSTR) &lpMsgBuf,
\r
2039 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2040 LocalFree( lpMsgBuf );
\r
2042 CloseHandle(process.hThread);
\r
2043 CloseHandle(process.hProcess);
\r
2046 case ShellMenuRevisionGraph:
\r
2047 svnCmd += _T("revisiongraph /path:\"");
\r
2048 if (files_.size() > 0)
\r
2049 svnCmd += files_.front();
\r
2051 svnCmd += folder_;
\r
2052 svnCmd += _T("\"");
\r
2054 case ShellMenuProperties:
\r
2055 tempfile = WriteFileListToTempFile();
\r
2056 svnCmd += _T("properties /pathfile:\"");
\r
2057 svnCmd += tempfile;
\r
2058 svnCmd += _T("\"");
\r
2059 svnCmd += _T(" /deletepathfile");
\r
2061 case ShellMenuClipPaste:
\r
2062 if (WriteClipboardPathsToTempFile(tempfile))
\r
2064 bool bCopy = true;
\r
2065 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
2066 if (cPrefDropFormat)
\r
2068 if (OpenClipboard(lpcmi->hwnd))
\r
2070 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
2073 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
2074 if (*effect == DROPEFFECT_MOVE)
\r
2076 GlobalUnlock(hglb);
\r
2083 svnCmd += _T("pastecopy /pathfile:\"");
\r
2085 svnCmd += _T("pastemove /pathfile:\"");
\r
2086 svnCmd += tempfile;
\r
2087 svnCmd += _T("\"");
\r
2088 svnCmd += _T(" /deletepathfile");
\r
2089 svnCmd += _T(" /droptarget:\"");
\r
2090 svnCmd += folder_;
\r
2091 svnCmd += _T("\"");
\r
2093 else return NOERROR;
\r
2095 case ShellMenuClone:
\r
2096 svnCmd += _T("clone /path:\"");
\r
2097 svnCmd += folder_;
\r
2098 svnCmd += _T("\"");
\r
2100 case ShellMenuPull:
\r
2101 svnCmd += _T("pull /path:\"");
\r
2102 if (files_.size() > 0)
\r
2103 svnCmd += files_.front();
\r
2105 svnCmd += folder_;
\r
2106 svnCmd += _T("\"");
\r
2108 case ShellMenuPush:
\r
2109 svnCmd += _T("push /path:\"");
\r
2110 if (files_.size() > 0)
\r
2111 svnCmd += files_.front();
\r
2113 svnCmd += folder_;
\r
2114 svnCmd += _T("\"");
\r
2116 case ShellMenuBranch:
\r
2117 svnCmd += _T("branch /path:\"");
\r
2118 if (files_.size() > 0)
\r
2119 svnCmd += files_.front();
\r
2121 svnCmd += folder_;
\r
2122 svnCmd += _T("\"");
\r
2125 case ShellMenuTag:
\r
2126 svnCmd += _T("tag /path:\"");
\r
2127 if (files_.size() > 0)
\r
2128 svnCmd += files_.front();
\r
2130 svnCmd += folder_;
\r
2131 svnCmd += _T("\"");
\r
2134 case ShellMenuFormatPatch:
\r
2135 svnCmd += _T("formatpatch /path:\"");
\r
2136 if (files_.size() > 0)
\r
2137 svnCmd += files_.front();
\r
2139 svnCmd += folder_;
\r
2140 svnCmd += _T("\"");
\r
2143 case ShellMenuImportPatch:
\r
2144 tempfile = WriteFileListToTempFile();
\r
2145 svnCmd += _T("importpatch /pathfile:\"");
\r
2146 svnCmd += tempfile;
\r
2147 svnCmd += _T("\"");
\r
2148 svnCmd += _T(" /deletepathfile");
\r
2151 case ShellMenuCherryPick:
\r
2152 svnCmd += _T("cherrypick /path:\"");
\r
2153 if (files_.size() > 0)
\r
2154 svnCmd += files_.front();
\r
2156 svnCmd += folder_;
\r
2157 svnCmd += _T("\"");
\r
2159 case ShellMenuFetch:
\r
2160 svnCmd += _T("fetch /path:\"");
\r
2161 if (files_.size() > 0)
\r
2162 svnCmd += files_.front();
\r
2164 svnCmd += folder_;
\r
2165 svnCmd += _T("\"");
\r
2171 } // switch (id_it->second)
\r
2172 svnCmd += _T(" /hwnd:");
\r
2174 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
2177 myVerbsIDMap.clear();
\r
2178 myVerbsMap.clear();
\r
2179 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2182 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2183 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2184 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2187 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2188 (LPTSTR) &lpMsgBuf,
\r
2192 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2193 LocalFree( lpMsgBuf );
\r
2195 CloseHandle(process.hThread);
\r
2196 CloseHandle(process.hProcess);
\r
2198 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
2199 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
2204 // This is for the status bar and things like that:
\r
2205 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
2207 UINT FAR * /*reserved*/,
\r
2211 PreserveChdir preserveChdir;
\r
2212 //do we know the id?
\r
2213 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
2214 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
2216 return E_INVALIDARG; //no, we don't
\r
2220 HRESULT hr = E_INVALIDARG;
\r
2222 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
2223 int menuIndex = 0;
\r
2224 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2226 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
2228 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
2234 const TCHAR * desc = stringtablebuffer;
\r
2237 case GCS_HELPTEXTA:
\r
2239 std::string help = WideToMultibyte(desc);
\r
2240 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2244 case GCS_HELPTEXTW:
\r
2246 wide_string help = desc;
\r
2247 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2253 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2254 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2256 std::string help = WideToMultibyte(verb_id_it->second);
\r
2257 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2264 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2265 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2267 wide_string help = verb_id_it->second;
\r
2268 ATLTRACE("verb : %ws\n", help.c_str());
\r
2269 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2278 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2281 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2284 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2286 PreserveChdir preserveChdir;
\r
2289 if (pResult == NULL)
\r
2296 case WM_MEASUREITEM:
\r
2298 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2299 if (lpmis==NULL||lpmis->CtlType!=ODT_MENU)
\r
2301 lpmis->itemWidth += 2;
\r
2302 if (lpmis->itemHeight < 16)
\r
2303 lpmis->itemHeight = 16;
\r
2310 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2311 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2312 return S_OK; //not for a menu
\r
2313 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2314 if (resource == NULL)
\r
2316 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2317 if (hIcon == NULL)
\r
2319 DrawIconEx(lpdis->hDC,
\r
2320 lpdis->rcItem.left - 16,
\r
2321 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2323 0, NULL, DI_NORMAL);
\r
2324 DestroyIcon(hIcon);
\r
2332 if (HIWORD(wParam) != MF_POPUP)
\r
2334 int nChar = LOWORD(wParam);
\r
2335 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2336 nChar = tolower(nChar);
\r
2337 // we have the char the user pressed, now search that char in all our
\r
2339 std::vector<int> accmenus;
\r
2340 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2342 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2343 if (resource == NULL)
\r
2345 szItem = stringtablebuffer;
\r
2346 TCHAR * amp = _tcschr(szItem, '&');
\r
2350 int ampChar = LOWORD(*amp);
\r
2351 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2352 ampChar = tolower(ampChar);
\r
2353 if (ampChar == nChar)
\r
2355 // yep, we found a menu which has the pressed key
\r
2356 // as an accelerator. Add that menu to the list to
\r
2358 accmenus.push_back(It->first);
\r
2361 if (accmenus.size() == 0)
\r
2363 // no menu with that accelerator key.
\r
2364 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2367 if (accmenus.size() == 1)
\r
2369 // Only one menu with that accelerator key. We're lucky!
\r
2370 // So just execute that menu entry.
\r
2371 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2374 if (accmenus.size() > 1)
\r
2376 // we have more than one menu item with this accelerator key!
\r
2378 mif.cbSize = sizeof(MENUITEMINFO);
\r
2379 mif.fMask = MIIM_STATE;
\r
2380 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2382 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2383 if (mif.fState == MFS_HILITE)
\r
2385 // this is the selected item, so select the next one
\r
2387 if (it == accmenus.end())
\r
2388 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2390 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2394 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2405 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2407 TCHAR textbuf[255];
\r
2408 LPCTSTR resource = NULL;
\r
2409 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2412 int menuIndex = 0;
\r
2413 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2415 if (menuInfo[menuIndex].command == id)
\r
2417 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2418 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2421 case ShellSubMenuMultiple:
\r
2422 case ShellSubMenuLink:
\r
2423 case ShellSubMenuFolder:
\r
2424 case ShellSubMenuFile:
\r
2425 case ShellSubMenu:
\r
2429 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2430 if (layout & (menuInfo[menuIndex].menuID))
\r
2432 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2433 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2434 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2445 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2448 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2449 LPITEMIDLIST pidl = NULL;
\r
2450 while (cslidarray[i])
\r
2454 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2456 if (!SHGetPathFromIDList(pidl, buf))
\r
2458 // not a file system path, definitely illegal for our use
\r
2459 CoTaskMemFree(pidl);
\r
2462 CoTaskMemFree(pidl);
\r
2463 if (_tcslen(buf)==0)
\r
2465 if (_tcscmp(buf, folder.c_str())==0)
\r
2471 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags)
\r
2473 HMENU ignoresubmenu = NULL;
\r
2474 int indexignoresub = 0;
\r
2475 bool bShowIgnoreMenu = false;
\r
2476 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2477 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2478 if (files_.size() == 0)
\r
2480 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2482 std::vector<stdstring>::iterator I = files_.begin();
\r
2483 if (_tcsrchr(I->c_str(), '\\'))
\r
2484 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2486 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2487 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2489 // check if the item name is ignored or the mask
\r
2491 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2493 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2494 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2502 ignoresubmenu = CreateMenu();
\r
2503 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2504 stdstring verb = stdstring(ignorepath);
\r
2505 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2506 myVerbsMap[verb] = idCmd;
\r
2507 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2508 myVerbsIDMap[idCmd] = verb;
\r
2509 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2510 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2511 bShowIgnoreMenu = true;
\r
2513 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2514 if (_tcsrchr(ignorepath, '.'))
\r
2516 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2517 p = ignoredprops.find(maskbuf);
\r
2519 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2521 if (ignoresubmenu==NULL)
\r
2522 ignoresubmenu = CreateMenu();
\r
2524 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2525 stdstring verb = stdstring(maskbuf);
\r
2526 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2527 myVerbsMap[verb] = idCmd;
\r
2528 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2529 myVerbsIDMap[idCmd] = verb;
\r
2530 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2531 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2532 bShowIgnoreMenu = true;
\r
2536 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2538 bShowIgnoreMenu = true;
\r
2539 ignoresubmenu = CreateMenu();
\r
2540 if (itemStates & ITEMIS_ONLYONE)
\r
2542 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2543 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2544 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2546 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2547 if (_tcsrchr(ignorepath, '.'))
\r
2549 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2550 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2551 stdstring verb = stdstring(maskbuf);
\r
2552 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2553 myVerbsMap[verb] = idCmd;
\r
2554 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2555 myVerbsIDMap[idCmd] = verb;
\r
2556 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2557 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2562 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2563 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2564 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2565 stdstring verb = stdstring(ignorepath);
\r
2566 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2567 myVerbsMap[verb] = idCmd;
\r
2568 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2569 myVerbsIDMap[idCmd] = verb;
\r
2570 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2571 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2573 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2574 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2575 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2576 verb = stdstring(ignorepath);
\r
2577 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2578 myVerbsMap[verb] = idCmd;
\r
2579 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2580 myVerbsIDMap[idCmd] = verb;
\r
2581 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2582 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2586 if (bShowIgnoreMenu)
\r
2588 MENUITEMINFO menuiteminfo;
\r
2589 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2590 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2591 if (fullver < 0x500 || (fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
2593 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
2596 HBITMAP bmp = IconToBitmap(icon);
\r
2597 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
2598 menuiteminfo.hbmpChecked = bmp;
\r
2599 menuiteminfo.hbmpUnchecked = bmp;
\r
2604 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
2607 menuiteminfo.fMask |= MIIM_BITMAP;
\r
2608 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
2611 menuiteminfo.fType = MFT_STRING;
\r
2612 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2613 menuiteminfo.wID = idCmd;
\r
2614 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2615 if (itemStates & ITEMIS_IGNORED)
\r
2616 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2618 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2619 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2620 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2622 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2623 if (itemStates & ITEMIS_IGNORED)
\r
2625 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2626 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2630 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2631 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2636 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2638 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2639 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2640 return bitmap_it->second;
\r
2642 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2646 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2650 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2651 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2654 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2655 HBITMAP hBmp = NULL;
\r
2657 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2660 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2662 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2665 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2666 BP_PAINTPARAMS paintParams = {0};
\r
2667 paintParams.cbSize = sizeof(paintParams);
\r
2668 paintParams.dwFlags = BPPF_ERASE;
\r
2669 paintParams.pBlendFunction = &bfAlpha;
\r
2672 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2675 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2677 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2678 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2681 // This will write the buffer contents to the destination bitmap
\r
2682 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2685 SelectObject(hdcDest, hbmpOld);
\r
2689 DeleteDC(hdcDest);
\r
2692 DestroyIcon(hIcon);
\r
2695 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2699 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2704 ZeroMemory(&bmi, sizeof(bmi));
\r
2705 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2706 bmi.bmiHeader.biPlanes = 1;
\r
2707 bmi.bmiHeader.biCompression = BI_RGB;
\r
2709 bmi.bmiHeader.biWidth = psize->cx;
\r
2710 bmi.bmiHeader.biHeight = psize->cy;
\r
2711 bmi.bmiHeader.biBitCount = 32;
\r
2713 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2716 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2717 if (hdc != hdcUsed)
\r
2719 ReleaseDC(NULL, hdcUsed);
\r
2722 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2725 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2727 RGBQUAD *prgbQuad;
\r
2729 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2730 if (SUCCEEDED(hr))
\r
2732 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2733 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2736 if (GetIconInfo(hicon, &info))
\r
2740 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2743 DeleteObject(info.hbmColor);
\r
2744 DeleteObject(info.hbmMask);
\r
2752 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2754 ULONG cxDelta = cxRow - sizImage.cx;
\r
2755 for (ULONG y = sizImage.cy; y; --y)
\r
2757 for (ULONG x = sizImage.cx; x; --x)
\r
2759 if (*pargb++ & 0xFF000000)
\r
2771 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2774 ZeroMemory(&bmi, sizeof(bmi));
\r
2775 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2776 bmi.bmiHeader.biPlanes = 1;
\r
2777 bmi.bmiHeader.biCompression = BI_RGB;
\r
2779 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2780 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2781 bmi.bmiHeader.biBitCount = 32;
\r
2783 HRESULT hr = E_OUTOFMEMORY;
\r
2784 HANDLE hHeap = GetProcessHeap();
\r
2785 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2788 hr = E_UNEXPECTED;
\r
2789 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2791 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2792 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2794 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2796 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2800 // transparent pixel
\r
2806 *pargb++ |= 0xFF000000;
\r
2816 HeapFree(hHeap, 0, pvBits);
\r