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 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
70 { ShellMenuDiff, MENUDIFF, IDI_DIFF, IDS_MENUDIFF, IDS_MENUDESCDIFF,
\r
71 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_NORMAL, ITEMIS_TWO, 0, 0, 0, 0, 0 },
\r
73 { ShellMenuPrevDiff, MENUPREVDIFF, IDI_DIFF, IDS_MENUPREVDIFF, IDS_MENUDESCPREVDIFF,
\r
74 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
76 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
\r
77 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
79 { ShellMenuLog, MENULOG, IDI_LOG, IDS_MENULOG, IDS_MENUDESCLOG,
\r
80 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0 },
\r
82 { ShellMenuRefLog, MENUREFLOG, IDI_LOG, IDS_MENUREFLOG, IDS_MENUDESCREFLOG,
\r
83 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 { ShellMenuRefBrowse, MENUREFBROWSE, IDI_REPOBROWSE, IDS_MENUREFBROWSE, IDS_MENUDESCREFBROWSE,
\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
89 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
\r
90 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
92 { ShellMenuShowChanged, MENUSHOWCHANGED, IDI_SHOWCHANGED, IDS_MENUSHOWCHANGED, IDS_MENUDESCSHOWCHANGED,
\r
93 ITEMIS_INSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0},
\r
95 { ShellMenuRebase, MENUREBASE, IDI_REBASE, IDS_MENUREBASE, IDS_MENUREBASE,
\r
96 ITEMIS_INSVN, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0},
\r
98 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
\r
99 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
\r
101 { ShellMenuStashSave, MENUSTASHSAVE, IDI_COMMIT, IDS_MENUSTASHSAVE, IDS_MENUSTASHSAVE,
\r
102 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
103 { ShellMenuStashApply, MENUSTASHAPPLY, IDI_RELOCATE, IDS_MENUSTASHAPPLY, IDS_MENUSTASHAPPLY,
\r
104 ITEMIS_INSVN|ITEMIS_STASH, 0, ITEMIS_FOLDERINSVN|ITEMIS_STASH, 0, 0, 0, 0, 0 },
\r
105 { ShellMenuStashPop, MENUSTASHPOP, IDI_RELOCATE, IDS_MENUSTASHPOP, IDS_MENUSTASHPOP,
\r
106 ITEMIS_INSVN|ITEMIS_STASH, 0, ITEMIS_FOLDERINSVN|ITEMIS_STASH, 0, 0, 0, 0, 0 },
\r
107 { ShellMenuStashList, MENUSTASHAPPLY, IDI_LOG, IDS_MENUSTASHLIST, IDS_MENUSTASHLIST,
\r
108 ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
111 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
113 { ShellMenuConflictEditor, MENUCONFLICTEDITOR, IDI_CONFLICT, IDS_MENUCONFLICT, IDS_MENUDESCCONFLICT,
\r
114 ITEMIS_INSVN|ITEMIS_CONFLICTED, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
116 { ShellMenuResolve, MENURESOLVE, IDI_RESOLVE, IDS_MENURESOLVE, IDS_MENUDESCRESOLVE,
\r
117 ITEMIS_INSVN|ITEMIS_CONFLICTED, 0, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
120 { ShellMenuRename, MENURENAME, IDI_RENAME, IDS_MENURENAME, IDS_MENUDESCRENAME,
\r
121 ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_INVERSIONEDFOLDER, 0, 0, 0, 0, 0, 0, 0 },
\r
123 { ShellMenuRemove, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVE, IDS_MENUDESCREMOVE,
\r
124 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
126 { ShellMenuRemoveKeep, MENUREMOVE, IDI_DELETE, IDS_MENUREMOVEKEEP, IDS_MENUDESCREMOVEKEEP,
\r
127 ITEMIS_INSVN|ITEMIS_INVERSIONEDFOLDER|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
129 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUREVERT, IDS_MENUDESCREVERT,
\r
130 ITEMIS_INSVN, ITEMIS_NORMAL|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_ADDED, 0, 0, 0, 0 },
\r
132 { ShellMenuRevert, MENUREVERT, IDI_REVERT, IDS_MENUUNDOADD, IDS_MENUDESCUNDOADD,
\r
133 ITEMIS_ADDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_ADDED, 0, 0, 0, 0, 0 },
\r
135 { ShellMenuDelUnversioned, MENUDELUNVERSIONED, IDI_DELUNVERSIONED, IDS_MENUDELUNVERSIONED, IDS_MENUDESCDELUNVERSIONED,
\r
136 ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
138 { ShellMenuCleanup, MENUCLEANUP, IDI_CLEANUP, IDS_MENUCLEANUP, IDS_MENUDESCCLEANUP,
\r
139 ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_FOLDERINSVN|ITEMIS_FOLDER, 0, 0, 0, 0, 0 },
\r
141 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
\r
142 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
\r
144 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
\r
145 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
\r
147 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
\r
148 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
150 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
152 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
153 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
155 { ShellMenuSwitch, MENUSWITCH, IDI_SWITCH, IDS_MENUSWITCH, IDS_MENUDESCSWITCH,
\r
156 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
158 { ShellMenuMerge, MENUMERGE, IDI_MERGE, IDS_MENUMERGE, IDS_MENUDESCMERGE,
\r
159 ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
160 // { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
\r
161 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
163 { ShellMenuBranch, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
\r
164 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
165 { ShellMenuTag, MENUTAG, IDI_TAG, IDS_MENUTAG, IDS_MENUDESCCOPY,
\r
166 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
168 { ShellMenuExport, MENUEXPORT, IDI_EXPORT, IDS_MENUEXPORT, IDS_MENUDESCEXPORT,
\r
169 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
171 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
\r
172 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
\r
174 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
176 { ShellMenuCreateRepos, MENUCREATEREPOS, IDI_CREATEREPOS, IDS_MENUCREATEREPOS, IDS_MENUDESCCREATEREPOS,
\r
177 ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
\r
179 { ShellMenuAdd, MENUADD, IDI_ADD, IDS_MENUADD, IDS_MENUDESCADD,
\r
180 ITEMIS_INVERSIONEDFOLDER, ITEMIS_INSVN, ITEMIS_INSVN|ITEMIS_FOLDER, 0, ITEMIS_IGNORED, 0, ITEMIS_DELETED, ITEMIS_FOLDER|ITEMIS_ONLYONE },
\r
182 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
\r
183 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
\r
185 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
\r
186 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
188 { ShellMenuBlame, MENUBLAME, IDI_BLAME, IDS_MENUBLAME, IDS_MENUDESCBLAME,
\r
189 ITEMIS_NORMAL|ITEMIS_ONLYONE, ITEMIS_FOLDER|ITEMIS_ADDED, 0, 0, 0, 0, 0, 0 },
\r
190 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
\r
191 // why was this changed, is this related to GitStatus?
\r
193 { ShellMenuIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUIGNORE, IDS_MENUDESCIGNORE,
\r
194 ITEMIS_INVERSIONEDFOLDER, ITEMIS_IGNORED|ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
\r
196 { ShellMenuUnIgnoreSub, MENUIGNORE, IDI_IGNORE, IDS_MENUUNIGNORE, IDS_MENUDESCUNIGNORE,
\r
197 ITEMIS_IGNORED, 0, 0, 0, 0, 0, 0, 0 },
\r
199 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
201 { ShellMenuSubAdd, MENUSUBADD, IDI_ADD, IDS_MENUSUBADD, IDS_MENUSUBADD,
\r
202 ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
204 { ShellMenuUpdateExt, MENUUPDATEEXT, IDI_UPDATE, IDS_MENUUPDATEEXT, IDS_MENUDESCUPDATEEXT,
\r
205 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE, 0, 0, 0, 0, 0, 0, 0 },
\r
207 { ShellMenuSubSync, MENUSUBSYNC, IDI_MENUSYNC, IDS_MENUSUBSYNC, IDS_MENUSUBSYNC,
\r
208 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_SUBMODULE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0, 0, 0 },
\r
212 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
214 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
\r
215 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
217 { ShellMenuFormatPatch, MENUFORMATPATCH, IDI_CREATEPATCH, IDS_MENUFORMATPATCH, IDS_MENUDESCCREATEPATCH,
\r
218 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
220 { ShellMenuImportPatch, MENUIMPORTPATCH, IDI_PATCH, IDS_MENUIMPORTPATCH, IDS_MENUDESCCREATEPATCH,
\r
221 ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, ITEMIS_PATCHFILE, 0, 0, 0 },
\r
224 { ShellMenuCreatePatch, MENUCREATEPATCH, IDI_CREATEPATCH, IDS_MENUCREATEPATCH, IDS_MENUDESCCREATEPATCH,
\r
225 ITEMIS_INSVN|ITEMIS_EXTENDED, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
\r
227 { ShellMenuApplyPatch, MENUAPPLYPATCH, IDI_PATCH, IDS_MENUAPPLYPATCH, IDS_MENUDESCAPPLYPATCH,
\r
228 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_ONLYONE|ITEMIS_PATCHFILE, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED, ITEMIS_ADDED, 0, 0 },
\r
230 { ShellMenuSendMail, MENUSENDMAIL, IDI_MENUSENDMAIL, IDS_MENUSENDMAIL, IDS_MENUDESSENDMAIL,
\r
231 ITEMIS_PATCHFILE, 0, 0, 0, 0, 0, 0, 0 },
\r
233 // { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
\r
234 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
\r
236 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
237 { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
\r
238 ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
\r
240 { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},
\r
242 { ShellMenuSettings, MENUSETTINGS, IDI_SETTINGS, IDS_MENUSETTINGS, IDS_MENUDESCSETTINGS,
\r
243 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
244 { ShellMenuHelp, MENUHELP, IDI_HELP, IDS_MENUHELP, IDS_MENUDESCHELP,
\r
245 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
246 { ShellMenuAbout, MENUABOUT, IDI_ABOUT, IDS_MENUABOUT, IDS_MENUDESCABOUT,
\r
247 ITEMIS_FOLDER, 0, 0, ITEMIS_FOLDER, 0, 0, 0, 0 },
\r
249 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
\r
250 // but they still need to be in here, because we use the icon and string information anyway.
\r
251 { ShellSubMenu, NULL, IDI_APP, IDS_MENUSUBMENU, 0,
\r
252 0, 0, 0, 0, 0, 0, 0, 0 },
\r
253 { ShellSubMenuFile, NULL, IDI_MENUFILE, IDS_MENUSUBMENU, 0,
\r
254 0, 0, 0, 0, 0, 0, 0, 0 },
\r
255 { ShellSubMenuFolder, NULL, IDI_MENUFOLDER, IDS_MENUSUBMENU, 0,
\r
256 0, 0, 0, 0, 0, 0, 0, 0 },
\r
257 { ShellSubMenuLink, NULL, IDI_MENULINK, IDS_MENUSUBMENU, 0,
\r
258 0, 0, 0, 0, 0, 0, 0, 0 },
\r
259 { ShellSubMenuMultiple, NULL, IDI_MENUMULTIPLE, IDS_MENUSUBMENU, 0,
\r
260 0, 0, 0, 0, 0, 0, 0, 0 },
\r
261 // mark the last entry to tell the loop where to stop iterating over this array
\r
262 { ShellMenuLastEntry, 0, 0, 0, 0,
\r
263 0, 0, 0, 0, 0, 0, 0, 0 },
\r
267 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
\r
268 LPDATAOBJECT pDataObj,
\r
269 HKEY /* hRegKey */)
\r
272 ATLTRACE("Shell :: Initialize\n");
\r
273 PreserveChdir preserveChdir;
\r
276 uuidSource.erase();
\r
277 uuidTarget.erase();
\r
279 itemStatesFolder = 0;
\r
280 stdstring statuspath;
\r
281 git_wc_status_kind fetchedstatus = git_wc_status_none;
\r
282 // get selected files/folders
\r
286 FORMATETC fmte = {(CLIPFORMAT)g_shellidlist,
\r
287 (DVTARGETDEVICE FAR *)NULL,
\r
291 HRESULT hres = pDataObj->GetData(&fmte, &medium);
\r
293 if (SUCCEEDED(hres) && medium.hGlobal)
\r
295 if (m_State == FileStateDropHandler)
\r
298 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
\r
299 STGMEDIUM stg = { TYMED_HGLOBAL };
\r
300 if ( FAILED( pDataObj->GetData ( &etc, &stg )))
\r
302 ReleaseStgMedium ( &medium );
\r
303 return E_INVALIDARG;
\r
307 HDROP drop = (HDROP)GlobalLock(stg.hGlobal);
\r
308 if ( NULL == drop )
\r
310 ReleaseStgMedium ( &stg );
\r
311 ReleaseStgMedium ( &medium );
\r
312 return E_INVALIDARG;
\r
315 int count = DragQueryFile(drop, (UINT)-1, NULL, 0);
\r
317 itemStates |= ITEMIS_ONLYONE;
\r
318 for (int i = 0; i < count; i++)
\r
320 // find the path length in chars
\r
321 UINT len = DragQueryFile(drop, i, NULL, 0);
\r
324 TCHAR * szFileName = new TCHAR[len+1];
\r
325 if (0 == DragQueryFile(drop, i, szFileName, len+1))
\r
327 delete [] szFileName;
\r
330 stdstring str = stdstring(szFileName);
\r
331 delete [] szFileName;
\r
332 if ((str.empty() == false)&&(g_ShellCache.IsContextPathAllowed(szFileName)))
\r
334 if (itemStates & ITEMIS_ONLYONE)
\r
337 strpath.SetFromWin(str.c_str());
\r
338 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE : 0;
\r
339 itemStates |= (strpath.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE : 0;
\r
341 files_.push_back(str);
\r
344 //get the Subversion status of the item
\r
345 git_wc_status_kind status = git_wc_status_none;
\r
346 CTGitPath askedpath;
\r
347 askedpath.SetFromWin(str.c_str());
\r
351 stat.GetStatus(CTGitPath(str.c_str()), false, true, true);
\r
355 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
356 fetchedstatus = status;
\r
357 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
358 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
359 if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
\r
361 itemStates |= ITEMIS_FOLDER;
\r
362 if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
363 itemStates |= ITEMIS_FOLDERINSVN;
\r
365 //if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
367 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
368 // itemStates |= ITEMIS_NEEDSLOCK;
\r
370 //if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
371 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
375 // sometimes, git_client_status() returns with an error.
\r
376 // in that case, we have to check if the working copy is versioned
\r
377 // anyway to show the 'correct' context menu
\r
378 if (askedpath.HasAdminDir())
\r
379 status = git_wc_status_normal;
\r
384 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
387 // TODO: should we really assume any sub-directory to be versioned
\r
388 // or only if it contains versioned files
\r
389 itemStates |= askedpath.GetAdminDirMask();
\r
391 if ((status == git_wc_status_unversioned) || (status == git_wc_status_ignored) || (status == git_wc_status_none))
\r
392 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 itemStates |= strpath.GetAdminDirMask();
\r
496 if ((status == git_wc_status_unversioned)||(status == git_wc_status_ignored)||(status == git_wc_status_none))
\r
497 itemStates &= ~ITEMIS_INSVN;
\r
498 if (status == git_wc_status_ignored)
\r
500 itemStates |= ITEMIS_IGNORED;
\r
501 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
\r
502 // offer a 'remove from ignored list' entry
\r
503 // GitProperties props(strpath.GetContainingDirectory(), false);
\r
504 // ignoredprops.empty();
\r
505 // for (int p=0; p<props.GetCount(); ++p)
\r
507 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
\r
509 // std::string st = props.GetItemValue(p);
\r
510 // ignoredprops = MultibyteToWide(st.c_str());
\r
511 // // remove all escape chars ('\\')
\r
512 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
\r
518 if (status == git_wc_status_normal)
\r
519 itemStates |= ITEMIS_NORMAL;
\r
520 if (status == git_wc_status_conflicted)
\r
521 itemStates |= ITEMIS_CONFLICTED;
\r
522 if (status == git_wc_status_added)
\r
523 itemStates |= ITEMIS_ADDED;
\r
524 if (status == git_wc_status_deleted)
\r
525 itemStates |= ITEMIS_DELETED;
\r
528 } // for (int i = 0; i < count; ++i)
\r
529 ItemIDList child (GetPIDLItem (cida, 0), &parent);
\r
530 if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))
\r
531 itemStates |= ITEMIS_INVERSIONEDFOLDER;
\r
532 GlobalUnlock(medium.hGlobal);
\r
534 // if the item is a versioned folder, check if there's a patch file
\r
535 // in the clipboard to be used in "Apply Patch"
\r
536 UINT cFormatDiff = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
539 if (IsClipboardFormatAvailable(cFormatDiff))
\r
540 itemStates |= ITEMIS_PATCHINCLIPBOARD;
\r
542 if (IsClipboardFormatAvailable(CF_HDROP))
\r
543 itemStates |= ITEMIS_PATHINCLIPBOARD;
\r
547 ReleaseStgMedium ( &medium );
\r
548 if (medium.pUnkForRelease)
\r
550 IUnknown* relInterface = (IUnknown*)medium.pUnkForRelease;
\r
551 relInterface->Release();
\r
556 // get folder background
\r
560 ItemIDList list(pIDFolder);
\r
561 folder_ = list.toString();
\r
562 git_wc_status_kind status = git_wc_status_none;
\r
563 if (IsClipboardFormatAvailable(CF_HDROP))
\r
564 itemStatesFolder |= ITEMIS_PATHINCLIPBOARD;
\r
566 CTGitPath askedpath;
\r
567 askedpath.SetFromWin(folder_.c_str());
\r
569 if ((folder_.compare(statuspath)!=0)&&(g_ShellCache.IsContextPathAllowed(folder_.c_str())))
\r
575 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
578 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
579 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
580 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
581 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
583 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
584 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
\r
586 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
587 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
592 // sometimes, git_client_status() returns with an error.
\r
593 // in that case, we have to check if the working copy is versioned
\r
594 // anyway to show the 'correct' context menu
\r
595 if (askedpath.HasAdminDir())
\r
596 status = git_wc_status_normal;
\r
599 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
600 itemStatesFolder |= askedpath.GetAdminDirMask();
\r
602 if (status == git_wc_status_normal)
\r
603 itemStatesFolder |= ITEMIS_NORMAL;
\r
604 if (status == git_wc_status_conflicted)
\r
605 itemStatesFolder |= ITEMIS_CONFLICTED;
\r
606 if (status == git_wc_status_added)
\r
607 itemStatesFolder |= ITEMIS_ADDED;
\r
608 if (status == git_wc_status_deleted)
\r
609 itemStatesFolder |= ITEMIS_DELETED;
\r
614 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
619 status = fetchedstatus;
\r
621 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
622 itemStatesFolder |= askedpath.GetAdminDirMask();
\r
624 if (status == git_wc_status_ignored)
\r
625 itemStatesFolder |= ITEMIS_IGNORED;
\r
626 itemStatesFolder |= ITEMIS_FOLDER;
\r
627 if (files_.size() == 0)
\r
628 itemStates |= ITEMIS_ONLYONE;
\r
629 if (m_State != FileStateDropHandler)
\r
630 itemStates |= itemStatesFolder;
\r
634 if (files_.size() == 2)
\r
635 itemStates |= ITEMIS_TWO;
\r
636 if ((files_.size() == 1)&&(g_ShellCache.IsContextPathAllowed(files_.front().c_str())))
\r
639 itemStates |= ITEMIS_ONLYONE;
\r
640 if (m_State != FileStateDropHandler)
\r
642 if (PathIsDirectory(files_.front().c_str()))
\r
644 folder_ = files_.front();
\r
645 git_wc_status_kind status = git_wc_status_none;
\r
646 CTGitPath askedpath;
\r
647 askedpath.SetFromWin(folder_.c_str());
\r
649 if (folder_.compare(statuspath)!=0)
\r
654 stat.GetStatus(CTGitPath(folder_.c_str()), false, true, true);
\r
657 status = GitStatus::GetMoreImportant(stat.status->text_status, stat.status->prop_status);
\r
658 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
\r
659 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
\r
660 // if ((stat.status->entry)&&(stat.status->entry->present_props))
\r
662 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
\r
663 // itemStates |= ITEMIS_NEEDSLOCK;
\r
665 // if ((stat.status->entry)&&(stat.status->entry->uuid))
\r
666 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
\r
671 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
\r
676 status = fetchedstatus;
\r
678 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
\r
679 itemStates |= askedpath.GetAdminDirMask();
\r
681 if (status == git_wc_status_ignored)
\r
682 itemStates |= ITEMIS_IGNORED;
\r
683 itemStates |= ITEMIS_FOLDER;
\r
684 if (status == git_wc_status_added)
\r
685 itemStates |= ITEMIS_ADDED;
\r
686 if (status == git_wc_status_deleted)
\r
687 itemStates |= ITEMIS_DELETED;
\r
697 void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags)
\r
699 TCHAR menutextbuffer[512] = {0};
\r
700 TCHAR verbsbuffer[255] = {0};
\r
701 MAKESTRING(stringid);
\r
705 //menu entry for the top context menu, so append an "Git " before
\r
706 //the menu text to indicate where the entry comes from
\r
707 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
709 _tcscat_s(menutextbuffer, 255, stringtablebuffer);
\r
711 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
\r
712 // so we have an easy and fast way to check the current branch
\r
713 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
\r
714 if (com == ShellMenuCommit)
\r
717 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
718 CString sProjectRoot;
\r
719 CString sBranchName;
\r
721 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
723 if (sBranchName.GetLength() == 40)
\r
725 // if SHA1 only show 4 first bytes
\r
726 BOOL bIsSha1 = TRUE;
\r
727 for (int i=0; i<40; i++)
\r
728 if ( !iswxdigit(sBranchName[i]) )
\r
734 sBranchName = sBranchName.Left(8) + _T("....");
\r
738 if (sBranchName.GetLength() > 64)
\r
739 sBranchName = sBranchName.Left(64) + _T("...");
\r
741 // scan to before "..."
\r
742 LPTSTR s = menutextbuffer + _tcslen(menutextbuffer)-1;
\r
743 if (s > menutextbuffer)
\r
745 while (s > menutextbuffer)
\r
757 s = menutextbuffer;
\r
760 // append branch name and end with ...
\r
761 _tcscpy(s, _T(" -> \"") + sBranchName + _T("\"..."));
\r
765 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
767 // on win2k, the context menu does not work properly if we use
\r
768 // icon bitmaps. At least the menu text is empty in the context menu
\r
769 // for folder backgrounds (seems like a win2k bug).
\r
770 // the workaround is to use the check/unchecked bitmaps, which are drawn
\r
771 // with AND raster op, but it's better than nothing at all
\r
772 InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);
\r
775 HBITMAP bmp = IconToBitmap(icon);
\r
776 SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);
\r
781 MENUITEMINFO menuiteminfo;
\r
782 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
783 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
784 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
\r
785 menuiteminfo.fType = MFT_STRING;
\r
786 menuiteminfo.dwTypeData = menutextbuffer;
\r
789 menuiteminfo.fMask |= MIIM_BITMAP;
\r
790 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
792 menuiteminfo.wID = id;
\r
793 InsertMenuItem(menu, pos, TRUE, &menuiteminfo);
\r
798 //menu entry for the top context menu, so append an "Git " before
\r
799 //the menu text to indicate where the entry comes from
\r
800 _tcscpy_s(menutextbuffer, 255, _T("Git "));
\r
802 LoadString(g_hResInst, stringid, verbsbuffer, sizeof(verbsbuffer));
\r
803 _tcscat_s(menutextbuffer, 255, verbsbuffer);
\r
804 stdstring verb = stdstring(menutextbuffer);
\r
805 if (verb.find('&') != -1)
\r
807 verb.erase(verb.find('&'),1);
\r
809 myVerbsMap[verb] = id - idCmdFirst;
\r
810 myVerbsMap[verb] = id;
\r
811 myVerbsIDMap[id - idCmdFirst] = verb;
\r
812 myVerbsIDMap[id] = verb;
\r
813 // We store the relative and absolute diameter
\r
814 // (drawitem callback uses absolute, others relative)
\r
815 myIDMap[id - idCmdFirst] = com;
\r
818 mySubMenuMap[pos] = com;
\r
821 HBITMAP CShellExt::IconToBitmap(UINT uIcon)
\r
823 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
824 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
825 return bitmap_it->second;
\r
827 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 12, 12, LR_DEFAULTCOLOR);
\r
833 rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
\r
834 rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
\r
836 rect.left = rect.top = 0;
\r
838 HWND desktop = ::GetDesktopWindow();
\r
839 if (desktop == NULL)
\r
841 DestroyIcon(hIcon);
\r
845 HDC screen_dev = ::GetDC(desktop);
\r
846 if (screen_dev == NULL)
\r
848 DestroyIcon(hIcon);
\r
852 // Create a compatible DC
\r
853 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
\r
854 if (dst_hdc == NULL)
\r
856 DestroyIcon(hIcon);
\r
857 ::ReleaseDC(desktop, screen_dev);
\r
861 // Create a new bitmap of icon size
\r
862 HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
\r
865 DestroyIcon(hIcon);
\r
866 ::DeleteDC(dst_hdc);
\r
867 ::ReleaseDC(desktop, screen_dev);
\r
871 // Select it into the compatible DC
\r
872 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
\r
873 if (old_dst_bmp == NULL)
\r
875 DestroyIcon(hIcon);
\r
879 // Fill the background of the compatible DC with the white color
\r
880 // that is taken by menu routines as transparent
\r
881 ::SetBkColor(dst_hdc, RGB(255, 255, 255));
\r
882 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
\r
884 // Draw the icon into the compatible DC
\r
885 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
\r
887 // Restore settings
\r
888 ::SelectObject(dst_hdc, old_dst_bmp);
\r
889 ::DeleteDC(dst_hdc);
\r
890 ::ReleaseDC(desktop, screen_dev);
\r
891 DestroyIcon(hIcon);
\r
893 bitmaps.insert(bitmap_it, std::make_pair(uIcon, bmp));
\r
897 bool CShellExt::WriteClipboardPathsToTempFile(stdstring& tempfile)
\r
900 tempfile = stdstring();
\r
901 //write all selected files and paths to a temporary file
\r
902 //for TortoiseProc.exe to read out again.
\r
904 DWORD pathlength = GetTempPath(0, NULL);
\r
905 TCHAR * path = new TCHAR[pathlength+1];
\r
906 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
907 GetTempPath (pathlength+1, path);
\r
908 GetTempFileName (path, _T("git"), 0, tempFile);
\r
909 tempfile = stdstring(tempFile);
\r
911 HANDLE file = ::CreateFile (tempFile,
\r
916 FILE_ATTRIBUTE_TEMPORARY,
\r
920 delete [] tempFile;
\r
921 if (file == INVALID_HANDLE_VALUE)
\r
924 if (!IsClipboardFormatAvailable(CF_HDROP))
\r
926 if (!OpenClipboard(NULL))
\r
929 stdstring sClipboardText;
\r
930 HGLOBAL hglb = GetClipboardData(CF_HDROP);
\r
931 HDROP hDrop = (HDROP)GlobalLock(hglb);
\r
934 TCHAR szFileName[MAX_PATH];
\r
935 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
\r
936 for(UINT i = 0; i < cFiles; ++i)
\r
938 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
\r
939 stdstring filename = szFileName;
\r
940 ::WriteFile (file, filename.c_str(), filename.size()*sizeof(TCHAR), &written, 0);
\r
941 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
943 GlobalUnlock(hDrop);
\r
946 GlobalUnlock(hglb);
\r
949 ::CloseHandle(file);
\r
954 stdstring CShellExt::WriteFileListToTempFile()
\r
956 //write all selected files and paths to a temporary file
\r
957 //for TortoiseProc.exe to read out again.
\r
958 DWORD pathlength = GetTempPath(0, NULL);
\r
959 TCHAR * path = new TCHAR[pathlength+1];
\r
960 TCHAR * tempFile = new TCHAR[pathlength + 100];
\r
961 GetTempPath (pathlength+1, path);
\r
962 GetTempFileName (path, _T("git"), 0, tempFile);
\r
963 stdstring retFilePath = stdstring(tempFile);
\r
965 HANDLE file = ::CreateFile (tempFile,
\r
970 FILE_ATTRIBUTE_TEMPORARY,
\r
974 delete [] tempFile;
\r
975 if (file == INVALID_HANDLE_VALUE)
\r
976 return stdstring();
\r
979 if (files_.empty())
\r
981 ::WriteFile (file, folder_.c_str(), folder_.size()*sizeof(TCHAR), &written, 0);
\r
982 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
985 for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)
\r
987 ::WriteFile (file, I->c_str(), I->size()*sizeof(TCHAR), &written, 0);
\r
988 ::WriteFile (file, _T("\n"), 2, &written, 0);
\r
990 ::CloseHandle(file);
\r
991 return retFilePath;
\r
994 STDMETHODIMP CShellExt::QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu)
\r
996 PreserveChdir preserveChdir;
\r
999 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1000 return NOERROR; //we don't change the default action
\r
1002 if ((files_.size() == 0)||(folder_.size() == 0))
\r
1005 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1008 bool bSourceAndTargetFromSameRepository = (uuidSource.compare(uuidTarget) == 0) || uuidSource.empty() || uuidTarget.empty();
\r
1010 //the drop handler only has eight commands, but not all are visible at the same time:
\r
1011 //if the source file(s) are under version control then those files can be moved
\r
1012 //to the new location or they can be moved with a rename,
\r
1013 //if they are unversioned then they can be added to the working copy
\r
1014 //if they are versioned, they also can be exported to an unversioned location
\r
1015 UINT idCmd = idCmdFirst;
\r
1018 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1019 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&((itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED)))
\r
1020 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVEMENU, 0, idCmdFirst, ShellMenuDropMove, uFlags);
\r
1022 // Git move and rename here
\r
1023 // 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
1024 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1025 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPMOVERENAMEMENU, 0, idCmdFirst, ShellMenuDropMoveRename, uFlags);
\r
1028 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
\r
1029 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&((~itemStates) & ITEMIS_ADDED))
\r
1030 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
\r
1032 // Git copy and rename here, source and target from same repository
\r
1033 // available if source is a single, versioned but not added item, target is versioned or target folder is added
\r
1034 if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINSVN)&&(itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
\r
1035 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
\r
1038 // available if target is versioned and source is either unversioned or from another repository
\r
1039 if ((itemStatesFolder & ITEMIS_FOLDERINSVN)&&(((~itemStates) & ITEMIS_INSVN)||!bSourceAndTargetFromSameRepository))
\r
1040 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYADDMENU, 0, idCmdFirst, ShellMenuDropCopyAdd, uFlags);
\r
1042 // Git export here
\r
1043 // available if source is versioned and a folder
\r
1044 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1045 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
\r
1047 // Git export all here
\r
1048 // available if source is versioned and a folder
\r
1049 if ((itemStates & ITEMIS_INSVN)&&(itemStates & ITEMIS_FOLDER))
\r
1050 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
\r
1053 // available if source is a patchfile
\r
1054 if (itemStates & ITEMIS_PATCHFILE)
\r
1055 InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_MENUAPPLYPATCH, 0, idCmdFirst, ShellMenuApplyPatch, uFlags);
\r
1058 if (idCmd != idCmdFirst)
\r
1059 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1061 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1064 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
\r
1067 UINT /*idCmdLast*/,
\r
1070 ATLTRACE("Shell :: QueryContextMenu\n");
\r
1071 PreserveChdir preserveChdir;
\r
1073 //first check if our drop handler is called
\r
1074 //and then (if true) provide the context menu for the
\r
1076 if (m_State == FileStateDropHandler)
\r
1078 return QueryDropContext(uFlags, idCmdFirst, hMenu, indexMenu);
\r
1081 if ((uFlags & CMF_DEFAULTONLY)!=0)
\r
1082 return NOERROR; //we don't change the default action
\r
1084 if ((files_.size() == 0)&&(folder_.size() == 0))
\r
1087 if (((uFlags & 0x000f)!=CMF_NORMAL)&&(!(uFlags & CMF_EXPLORE))&&(!(uFlags & CMF_VERBSONLY)))
\r
1090 int csidlarray[] =
\r
1093 CSIDL_CDBURN_AREA,
\r
1094 CSIDL_COMMON_FAVORITES,
\r
1095 CSIDL_COMMON_STARTMENU,
\r
1096 CSIDL_COMPUTERSNEARME,
\r
1097 CSIDL_CONNECTIONS,
\r
1104 CSIDL_INTERNET_CACHE,
\r
1114 if (IsIllegalFolder(folder_, csidlarray))
\r
1117 if (folder_.empty())
\r
1119 // folder is empty, but maybe files are selected
\r
1120 if (files_.size() == 0)
\r
1121 return NOERROR; // nothing selected - we don't have a menu to show
\r
1122 // check whether a selected entry is an UID - those are namespace extensions
\r
1123 // which we can't handle
\r
1124 for (std::vector<stdstring>::const_iterator it = files_.begin(); it != files_.end(); ++it)
\r
1126 if (_tcsncmp(it->c_str(), _T("::{"), 3)==0)
\r
1131 //check if our menu is requested for a subversion admin directory
\r
1132 if (g_GitAdminDir.IsAdminDirPath(folder_.c_str()))
\r
1135 if (uFlags & CMF_EXTENDEDVERBS)
\r
1136 itemStates |= ITEMIS_EXTENDED;
\r
1138 const BOOL bShortcut = !!(uFlags & CMF_VERBSONLY);
\r
1139 if ( bShortcut && (files_.size()==1))
\r
1141 // Don't show the context menu for a link if the
\r
1142 // destination is not part of a working copy.
\r
1143 // It would only show the standard menu items
\r
1144 // which are already shown for the lnk-file.
\r
1145 CString path = files_.front().c_str();
\r
1146 if ( !g_GitAdminDir.HasAdminDir(path) )
\r
1152 //check if we already added our menu entry for a folder.
\r
1153 //we check that by iterating through all menu entries and check if
\r
1154 //the dwItemData member points to our global ID string. That string is set
\r
1155 //by our shell extension when the folder menu is inserted.
\r
1156 TCHAR menubuf[MAX_PATH];
\r
1157 int count = GetMenuItemCount(hMenu);
\r
1158 for (int i=0; i<count; ++i)
\r
1160 MENUITEMINFO miif;
\r
1161 SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
\r
1162 miif.cbSize = sizeof(MENUITEMINFO);
\r
1163 miif.fMask = MIIM_DATA;
\r
1164 miif.dwTypeData = menubuf;
\r
1165 miif.cch = sizeof(menubuf)/sizeof(TCHAR);
\r
1166 GetMenuItemInfo(hMenu, i, TRUE, &miif);
\r
1167 if (miif.dwItemData == (ULONG_PTR)g_MenuIDString)
\r
1172 UINT idCmd = idCmdFirst;
\r
1174 //create the sub menu
\r
1175 HMENU subMenu = CreateMenu();
\r
1176 int indexSubMenu = 0;
\r
1178 unsigned __int64 topmenu = g_ShellCache.GetMenuLayout();
\r
1179 unsigned __int64 menumask = g_ShellCache.GetMenuMask();
\r
1181 int menuIndex = 0;
\r
1182 bool bAddSeparator = false;
\r
1183 bool bMenuEntryAdded = false;
\r
1184 bool bMenuEmpty = true;
\r
1185 // insert separator at start
\r
1186 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1187 bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));
\r
1188 // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up
\r
1189 /*if (fullver <= 0x500)
\r
1190 bShowIcons = false;*/
\r
1193 if (itemStates & (ITEMIS_INSVN|ITEMIS_FOLDERINSVN))
\r
1195 // show current branch name (as a "read-only" menu entry)
\r
1197 CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str());
\r
1198 CString sProjectRoot;
\r
1199 CString sBranchName;
\r
1201 if (path.HasAdminDir(&sProjectRoot) && !g_Git.GetCurrentBranchFromFile(sProjectRoot, sBranchName))
\r
1203 if (sBranchName.GetLength() == 40)
\r
1205 // if SHA1 only show 4 first bytes
\r
1206 BOOL bIsSha1 = TRUE;
\r
1207 for (int i=0; i<40; i++)
\r
1208 if ( !iswxdigit(sBranchName[i]) )
\r
1214 sBranchName = sBranchName.Left(8) + _T("....");
\r
1217 sBranchName = _T('"') + sBranchName + _T('"');
\r
1219 const int icon = IDI_COPY;
\r
1220 const int pos = indexMenu++;
\r
1221 const int id = idCmd++;
\r
1223 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1225 InsertMenu(hMenu, pos, MF_DISABLED|MF_GRAYED|MF_BYPOSITION|MF_STRING, id, sBranchName);
\r
1226 HBITMAP bmp = IconToBitmap(icon);
\r
1227 SetMenuItemBitmaps(hMenu, pos, MF_BYPOSITION, bmp, bmp);
\r
1231 MENUITEMINFO menuiteminfo;
\r
1232 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1233 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1234 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
\r
1235 menuiteminfo.fState = MFS_DISABLED;
\r
1236 menuiteminfo.fType = MFT_STRING;
\r
1237 menuiteminfo.dwTypeData = (LPWSTR)sBranchName.GetString();
\r
1240 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1241 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
1243 if (menuiteminfo.hbmpItem == HBMMENU_CALLBACK)
\r
1245 // WM_DRAWITEM uses myIDMap to get icon, we use the same icon as create branch
\r
1246 myIDMap[id - idCmdFirst] = ShellMenuBranch;
\r
1247 myIDMap[id] = ShellMenuBranch;
\r
1250 menuiteminfo.wID = id;
\r
1251 InsertMenuItem(hMenu, pos, TRUE, &menuiteminfo);
\r
1257 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
1259 if (menuInfo[menuIndex].command == ShellSeparator)
\r
1261 // we don't add a separator immediately. Because there might not be
\r
1262 // another 'normal' menu entry after we insert a separator.
\r
1263 // we simply set a flag here, indicating that before the next
\r
1264 // 'normal' menu entry, a separator should be added.
\r
1266 bAddSeparator = true;
\r
1270 // check the conditions whether to show the menu entry or not
\r
1271 bool bInsertMenu = false;
\r
1273 if (menuInfo[menuIndex].firstyes && menuInfo[menuIndex].firstno)
\r
1275 if (((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes)
\r
1277 ((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1278 bInsertMenu = true;
\r
1280 else if ((menuInfo[menuIndex].firstyes)&&((menuInfo[menuIndex].firstyes & itemStates) == menuInfo[menuIndex].firstyes))
\r
1281 bInsertMenu = true;
\r
1282 else if ((menuInfo[menuIndex].firstno)&&((menuInfo[menuIndex].firstno & (~itemStates)) == menuInfo[menuIndex].firstno))
\r
1283 bInsertMenu = true;
\r
1285 if (menuInfo[menuIndex].secondyes && menuInfo[menuIndex].secondno)
\r
1287 if (((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes)
\r
1289 ((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1290 bInsertMenu = true;
\r
1292 else if ((menuInfo[menuIndex].secondyes)&&((menuInfo[menuIndex].secondyes & itemStates) == menuInfo[menuIndex].secondyes))
\r
1293 bInsertMenu = true;
\r
1294 else if ((menuInfo[menuIndex].secondno)&&((menuInfo[menuIndex].secondno & (~itemStates)) == menuInfo[menuIndex].secondno))
\r
1295 bInsertMenu = true;
\r
1297 if (menuInfo[menuIndex].thirdyes && menuInfo[menuIndex].thirdno)
\r
1299 if (((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes)
\r
1301 ((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1302 bInsertMenu = true;
\r
1304 else if ((menuInfo[menuIndex].thirdyes)&&((menuInfo[menuIndex].thirdyes & itemStates) == menuInfo[menuIndex].thirdyes))
\r
1305 bInsertMenu = true;
\r
1306 else if ((menuInfo[menuIndex].thirdno)&&((menuInfo[menuIndex].thirdno & (~itemStates)) == menuInfo[menuIndex].thirdno))
\r
1307 bInsertMenu = true;
\r
1309 if (menuInfo[menuIndex].fourthyes && menuInfo[menuIndex].fourthno)
\r
1311 if (((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes)
\r
1313 ((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1314 bInsertMenu = true;
\r
1316 else if ((menuInfo[menuIndex].fourthyes)&&((menuInfo[menuIndex].fourthyes & itemStates) == menuInfo[menuIndex].fourthyes))
\r
1317 bInsertMenu = true;
\r
1318 else if ((menuInfo[menuIndex].fourthno)&&((menuInfo[menuIndex].fourthno & (~itemStates)) == menuInfo[menuIndex].fourthno))
\r
1319 bInsertMenu = true;
\r
1321 if (menuInfo[menuIndex].menuID & (~menumask))
\r
1325 // insert a separator
\r
1326 if ((bMenuEntryAdded)&&(bAddSeparator))
\r
1328 bAddSeparator = false;
\r
1329 bMenuEntryAdded = false;
\r
1330 InsertMenu(subMenu, indexSubMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
\r
1334 // handle special cases (sub menus)
\r
1335 if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))
\r
1337 InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons, uFlags);
\r
1338 bMenuEntryAdded = true;
\r
1339 bMenuEmpty = false;
\r
1343 bool bIsTop = ((topmenu & menuInfo[menuIndex].menuID) != 0);
\r
1345 // insert the menu entry
\r
1346 InsertGitMenu( bIsTop,
\r
1347 bIsTop ? hMenu : subMenu,
\r
1348 bIsTop ? indexMenu++ : indexSubMenu++,
\r
1350 menuInfo[menuIndex].menuTextID,
\r
1351 bShowIcons ? menuInfo[menuIndex].iconID : 0,
\r
1353 menuInfo[menuIndex].command,
\r
1357 bMenuEntryAdded = true;
\r
1358 bMenuEmpty = false;
\r
1367 //add sub menu to main context menu
\r
1368 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
\r
1369 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
\r
1370 MAKESTRING(IDS_MENUSUBMENU);
\r
1371 MENUITEMINFO menuiteminfo;
\r
1372 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
1373 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
1374 menuiteminfo.fType = MFT_STRING;
\r
1375 menuiteminfo.dwTypeData = stringtablebuffer;
\r
1377 UINT uIcon = bShowIcons ? IDI_APP : 0;
\r
1378 if (folder_.size())
\r
1380 uIcon = bShowIcons ? IDI_MENUFOLDER : 0;
\r
1381 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFolder;
\r
1382 myIDMap[idCmd] = ShellSubMenuFolder;
\r
1383 menuiteminfo.dwItemData = (ULONG_PTR)g_MenuIDString;
\r
1385 else if (!bShortcut && (files_.size()==1))
\r
1387 uIcon = bShowIcons ? IDI_MENUFILE : 0;
\r
1388 myIDMap[idCmd - idCmdFirst] = ShellSubMenuFile;
\r
1389 myIDMap[idCmd] = ShellSubMenuFile;
\r
1391 else if (bShortcut && (files_.size()==1))
\r
1393 uIcon = bShowIcons ? IDI_MENULINK : 0;
\r
1394 myIDMap[idCmd - idCmdFirst] = ShellSubMenuLink;
\r
1395 myIDMap[idCmd] = ShellSubMenuLink;
\r
1397 else if (files_.size() > 1)
\r
1399 uIcon = bShowIcons ? IDI_MENUMULTIPLE : 0;
\r
1400 myIDMap[idCmd - idCmdFirst] = ShellSubMenuMultiple;
\r
1401 myIDMap[idCmd] = ShellSubMenuMultiple;
\r
1405 myIDMap[idCmd - idCmdFirst] = ShellSubMenu;
\r
1406 myIDMap[idCmd] = ShellSubMenu;
\r
1408 HBITMAP bmp = NULL;
\r
1409 if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
1411 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
1414 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
1415 bmp = IconToBitmap(uIcon);
\r
1416 menuiteminfo.hbmpChecked = bmp;
\r
1417 menuiteminfo.hbmpUnchecked = bmp;
\r
1422 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
1425 menuiteminfo.fMask |= MIIM_BITMAP;
\r
1426 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;
\r
1429 menuiteminfo.hSubMenu = subMenu;
\r
1430 menuiteminfo.wID = idCmd++;
\r
1431 InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);
\r
1434 InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;
\r
1436 //return number of menu items added
\r
1437 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(idCmd - idCmdFirst)));
\r
1441 // This is called when you invoke a command on the menu:
\r
1442 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
\r
1444 PreserveChdir preserveChdir;
\r
1445 HRESULT hr = E_INVALIDARG;
\r
1446 if (lpcmi == NULL)
\r
1449 std::string command;
\r
1450 std::string parent;
\r
1453 if ((files_.size() > 0)||(folder_.size() > 0))
\r
1455 UINT idCmd = LOWORD(lpcmi->lpVerb);
\r
1457 if (HIWORD(lpcmi->lpVerb))
\r
1459 stdstring verb = stdstring(MultibyteToWide(lpcmi->lpVerb));
\r
1460 std::map<stdstring, UINT_PTR>::const_iterator verb_it = myVerbsMap.lower_bound(verb);
\r
1461 if (verb_it != myVerbsMap.end() && verb_it->first == verb)
\r
1462 idCmd = verb_it->second;
\r
1467 // See if we have a handler interface for this id
\r
1468 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
1469 if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
1471 STARTUPINFO startup;
\r
1472 PROCESS_INFORMATION process;
\r
1473 memset(&startup, 0, sizeof(startup));
\r
1474 startup.cb = sizeof(startup);
\r
1475 memset(&process, 0, sizeof(process));
\r
1476 CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE);
\r
1477 CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE);
\r
1479 //TortoiseProc expects a command line of the form:
\r
1480 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
\r
1482 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
\r
1484 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
\r
1485 //* pathfile is a path to a temporary file which contains a list of file paths
\r
1486 stdstring svnCmd = _T(" /command:");
\r
1487 stdstring tempfile;
\r
1488 switch (id_it->second)
\r
1491 case ShellMenuSync:
\r
1492 svnCmd += _T("sync /path:\"");
\r
1493 svnCmd += folder_;
\r
1494 svnCmd += _T("\"");
\r
1496 case ShellMenuCheckout:
\r
1497 svnCmd += _T("checkout /path:\"");
\r
1498 svnCmd += folder_;
\r
1499 svnCmd += _T("\"");
\r
1501 case ShellMenuUpdate:
\r
1502 tempfile = WriteFileListToTempFile();
\r
1503 svnCmd += _T("update /pathfile:\"");
\r
1504 svnCmd += tempfile;
\r
1505 svnCmd += _T("\"");
\r
1506 svnCmd += _T(" /deletepathfile");
\r
1508 case ShellMenuSubSync:
\r
1509 tempfile = WriteFileListToTempFile();
\r
1510 svnCmd += _T("subsync /pathfile:\"");
\r
1511 svnCmd += tempfile;
\r
1512 svnCmd += _T("\"");
\r
1513 svnCmd += _T(" /deletepathfile");
\r
1514 if(itemStatesFolder&ITEMIS_SUBMODULE)
\r
1516 svnCmd += _T(" /bkpath:");
\r
1517 svnCmd += folder_;
\r
1520 case ShellMenuUpdateExt:
\r
1521 tempfile = WriteFileListToTempFile();
\r
1522 svnCmd += _T("subupdate /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 ShellMenuCommit:
\r
1533 tempfile = WriteFileListToTempFile();
\r
1534 svnCmd += _T("commit /pathfile:\"");
\r
1535 svnCmd += tempfile;
\r
1536 svnCmd += _T("\"");
\r
1537 svnCmd += _T(" /deletepathfile");
\r
1539 case ShellMenuAdd:
\r
1540 case ShellMenuAddAsReplacement:
\r
1541 tempfile = WriteFileListToTempFile();
\r
1542 svnCmd += _T("add /pathfile:\"");
\r
1543 svnCmd += tempfile;
\r
1544 svnCmd += _T("\"");
\r
1545 svnCmd += _T(" /deletepathfile");
\r
1547 case ShellMenuIgnore:
\r
1548 tempfile = WriteFileListToTempFile();
\r
1549 svnCmd += _T("ignore /pathfile:\"");
\r
1550 svnCmd += tempfile;
\r
1551 svnCmd += _T("\"");
\r
1552 svnCmd += _T(" /deletepathfile");
\r
1554 case ShellMenuIgnoreCaseSensitive:
\r
1555 tempfile = WriteFileListToTempFile();
\r
1556 svnCmd += _T("ignore /pathfile:\"");
\r
1557 svnCmd += tempfile;
\r
1558 svnCmd += _T("\"");
\r
1559 svnCmd += _T(" /deletepathfile");
\r
1560 svnCmd += _T(" /onlymask");
\r
1562 case ShellMenuUnIgnore:
\r
1563 tempfile = WriteFileListToTempFile();
\r
1564 svnCmd += _T("unignore /pathfile:\"");
\r
1565 svnCmd += tempfile;
\r
1566 svnCmd += _T("\"");
\r
1567 svnCmd += _T(" /deletepathfile");
\r
1569 case ShellMenuUnIgnoreCaseSensitive:
\r
1570 tempfile = WriteFileListToTempFile();
\r
1571 svnCmd += _T("unignore /pathfile:\"");
\r
1572 svnCmd += tempfile;
\r
1573 svnCmd += _T("\"");
\r
1574 svnCmd += _T(" /deletepathfile");
\r
1575 svnCmd += _T(" /onlymask");
\r
1577 case ShellMenuRevert:
\r
1578 tempfile = WriteFileListToTempFile();
\r
1579 svnCmd += _T("revert /pathfile:\"");
\r
1580 svnCmd += tempfile;
\r
1581 svnCmd += _T("\"");
\r
1582 svnCmd += _T(" /deletepathfile");
\r
1584 case ShellMenuDelUnversioned:
\r
1585 svnCmd += _T("delunversioned /path:\"");
\r
1586 svnCmd += folder_;
\r
1587 svnCmd += _T("\"");
\r
1589 case ShellMenuCleanup:
\r
1590 tempfile = WriteFileListToTempFile();
\r
1591 svnCmd += _T("cleanup /pathfile:\"");
\r
1592 svnCmd += tempfile;
\r
1593 svnCmd += _T("\"");
\r
1594 svnCmd += _T(" /deletepathfile");
\r
1596 case ShellMenuSendMail:
\r
1597 tempfile = WriteFileListToTempFile();
\r
1598 svnCmd += _T("sendmail /pathfile:\"");
\r
1599 svnCmd += tempfile;
\r
1600 svnCmd += _T("\"");
\r
1601 svnCmd += _T(" /deletepathfile");
\r
1603 case ShellMenuResolve:
\r
1604 tempfile = WriteFileListToTempFile();
\r
1605 svnCmd += _T("resolve /pathfile:\"");
\r
1606 svnCmd += tempfile;
\r
1607 svnCmd += _T("\"");
\r
1608 svnCmd += _T(" /deletepathfile");
\r
1610 case ShellMenuSwitch:
\r
1611 svnCmd += _T("switch /path:\"");
\r
1612 if (files_.size() > 0)
\r
1613 svnCmd += files_.front();
\r
1615 svnCmd += folder_;
\r
1616 svnCmd += _T("\"");
\r
1618 case ShellMenuImport:
\r
1619 svnCmd += _T("import /path:\"");
\r
1620 svnCmd += folder_;
\r
1621 svnCmd += _T("\"");
\r
1623 case ShellMenuExport:
\r
1624 svnCmd += _T("export /path:\"");
\r
1625 svnCmd += folder_;
\r
1626 svnCmd += _T("\"");
\r
1628 case ShellMenuAbout:
\r
1629 svnCmd += _T("about");
\r
1631 case ShellMenuCreateRepos:
\r
1632 svnCmd += _T("repocreate /path:\"");
\r
1633 svnCmd += folder_;
\r
1634 svnCmd += _T("\"");
\r
1636 case ShellMenuMerge:
\r
1637 svnCmd += _T("merge /path:\"");
\r
1638 if (files_.size() > 0)
\r
1639 svnCmd += files_.front();
\r
1641 svnCmd += folder_;
\r
1642 svnCmd += _T("\"");
\r
1644 case ShellMenuMergeAll:
\r
1645 svnCmd += _T("mergeall /path:\"");
\r
1646 if (files_.size() > 0)
\r
1647 svnCmd += files_.front();
\r
1649 svnCmd += folder_;
\r
1650 svnCmd += _T("\"");
\r
1652 case ShellMenuCopy:
\r
1653 svnCmd += _T("copy /path:\"");
\r
1654 if (files_.size() > 0)
\r
1655 svnCmd += files_.front();
\r
1657 svnCmd += folder_;
\r
1658 svnCmd += _T("\"");
\r
1660 case ShellMenuSettings:
\r
1661 svnCmd += _T("settings /path:\"");
\r
1662 if (files_.size() > 0)
\r
1663 svnCmd += files_.front();
\r
1665 svnCmd += folder_;
\r
1666 svnCmd += _T("\"");
\r
1668 case ShellMenuHelp:
\r
1669 svnCmd += _T("help");
\r
1671 case ShellMenuRename:
\r
1672 svnCmd += _T("rename /path:\"");
\r
1673 if (files_.size() > 0)
\r
1674 svnCmd += files_.front();
\r
1676 svnCmd += folder_;
\r
1677 svnCmd += _T("\"");
\r
1679 case ShellMenuRemove:
\r
1680 tempfile = WriteFileListToTempFile();
\r
1681 svnCmd += _T("remove /pathfile:\"");
\r
1682 svnCmd += tempfile;
\r
1683 svnCmd += _T("\"");
\r
1684 svnCmd += _T(" /deletepathfile");
\r
1686 case ShellMenuRemoveKeep:
\r
1687 tempfile = WriteFileListToTempFile();
\r
1688 svnCmd += _T("remove /pathfile:\"");
\r
1689 svnCmd += tempfile;
\r
1690 svnCmd += _T("\"");
\r
1691 svnCmd += _T(" /deletepathfile");
\r
1692 svnCmd += _T(" /keep");
\r
1694 case ShellMenuDiff:
\r
1695 svnCmd += _T("diff /path:\"");
\r
1696 if (files_.size() == 1)
\r
1697 svnCmd += files_.front();
\r
1698 else if (files_.size() == 2)
\r
1700 std::vector<stdstring>::iterator I = files_.begin();
\r
1703 svnCmd += _T("\" /path2:\"");
\r
1707 svnCmd += folder_;
\r
1708 svnCmd += _T("\"");
\r
1709 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1710 svnCmd += _T(" /alternative");
\r
1712 case ShellMenuPrevDiff:
\r
1713 svnCmd += _T("prevdiff /path:\"");
\r
1714 if (files_.size() == 1)
\r
1715 svnCmd += files_.front();
\r
1717 svnCmd += folder_;
\r
1718 svnCmd += _T("\"");
\r
1719 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
\r
1720 svnCmd += _T(" /alternative");
\r
1722 case ShellMenuUrlDiff:
\r
1723 svnCmd += _T("urldiff /path:\"");
\r
1724 if (files_.size() == 1)
\r
1725 svnCmd += files_.front();
\r
1727 svnCmd += folder_;
\r
1728 svnCmd += _T("\"");
\r
1730 case ShellMenuDropCopyAdd:
\r
1731 tempfile = WriteFileListToTempFile();
\r
1732 svnCmd += _T("dropcopyadd /pathfile:\"");
\r
1733 svnCmd += tempfile;
\r
1734 svnCmd += _T("\"");
\r
1735 svnCmd += _T(" /deletepathfile");
\r
1736 svnCmd += _T(" /droptarget:\"");
\r
1737 svnCmd += folder_;
\r
1738 svnCmd += _T("\"";)
\r
1740 case ShellMenuDropCopy:
\r
1741 tempfile = WriteFileListToTempFile();
\r
1742 svnCmd += _T("dropcopy /pathfile:\"");
\r
1743 svnCmd += tempfile;
\r
1744 svnCmd += _T("\"");
\r
1745 svnCmd += _T(" /deletepathfile");
\r
1746 svnCmd += _T(" /droptarget:\"");
\r
1747 svnCmd += folder_;
\r
1748 svnCmd += _T("\"";)
\r
1750 case ShellMenuDropCopyRename:
\r
1751 tempfile = WriteFileListToTempFile();
\r
1752 svnCmd += _T("dropcopy /pathfile:\"");
\r
1753 svnCmd += tempfile;
\r
1754 svnCmd += _T("\"");
\r
1755 svnCmd += _T(" /deletepathfile");
\r
1756 svnCmd += _T(" /droptarget:\"");
\r
1757 svnCmd += folder_;
\r
1758 svnCmd += _T("\" /rename";)
\r
1760 case ShellMenuDropMove:
\r
1761 tempfile = WriteFileListToTempFile();
\r
1762 svnCmd += _T("dropmove /pathfile:\"");
\r
1763 svnCmd += tempfile;
\r
1764 svnCmd += _T("\"");
\r
1765 svnCmd += _T(" /deletepathfile");
\r
1766 svnCmd += _T(" /droptarget:\"");
\r
1767 svnCmd += folder_;
\r
1768 svnCmd += _T("\"");
\r
1770 case ShellMenuDropMoveRename:
\r
1771 tempfile = WriteFileListToTempFile();
\r
1772 svnCmd += _T("dropmove /pathfile:\"");
\r
1773 svnCmd += tempfile;
\r
1774 svnCmd += _T("\"");
\r
1775 svnCmd += _T(" /deletepathfile");
\r
1776 svnCmd += _T(" /droptarget:\"");
\r
1777 svnCmd += folder_;
\r
1778 svnCmd += _T("\" /rename";)
\r
1780 case ShellMenuDropExport:
\r
1781 tempfile = WriteFileListToTempFile();
\r
1782 svnCmd += _T("dropexport /pathfile:\"");
\r
1783 svnCmd += tempfile;
\r
1784 svnCmd += _T("\"");
\r
1785 svnCmd += _T(" /deletepathfile");
\r
1786 svnCmd += _T(" /droptarget:\"");
\r
1787 svnCmd += folder_;
\r
1788 svnCmd += _T("\"");
\r
1790 case ShellMenuDropExportExtended:
\r
1791 tempfile = WriteFileListToTempFile();
\r
1792 svnCmd += _T("dropexport /pathfile:\"");
\r
1793 svnCmd += tempfile;
\r
1794 svnCmd += _T("\"");
\r
1795 svnCmd += _T(" /deletepathfile");
\r
1796 svnCmd += _T(" /droptarget:\"");
\r
1797 svnCmd += folder_;
\r
1798 svnCmd += _T("\"");
\r
1799 svnCmd += _T(" /extended");
\r
1801 case ShellMenuLog:
\r
1802 svnCmd += _T("log /path:\"");
\r
1803 if (files_.size() > 0)
\r
1804 svnCmd += files_.front();
\r
1806 svnCmd += folder_;
\r
1807 svnCmd += _T("\"");
\r
1809 case ShellMenuConflictEditor:
\r
1810 svnCmd += _T("conflicteditor /path:\"");
\r
1811 if (files_.size() > 0)
\r
1812 svnCmd += files_.front();
\r
1814 svnCmd += folder_;
\r
1815 svnCmd += _T("\"");
\r
1817 case ShellMenuRelocate:
\r
1818 svnCmd += _T("relocate /path:\"");
\r
1819 if (files_.size() > 0)
\r
1820 svnCmd += files_.front();
\r
1822 svnCmd += folder_;
\r
1823 svnCmd += _T("\"");
\r
1825 case ShellMenuGitSVNRebase:
\r
1826 svnCmd += _T("svnrebase /path:\"");
\r
1827 if (files_.size() > 0)
\r
1828 svnCmd += files_.front();
\r
1830 svnCmd += folder_;
\r
1831 svnCmd += _T("\"");
\r
1833 case ShellMenuGitSVNDCommit:
\r
1834 svnCmd += _T("svndcommit /path:\"");
\r
1835 if (files_.size() > 0)
\r
1836 svnCmd += files_.front();
\r
1838 svnCmd += folder_;
\r
1839 svnCmd += _T("\"");
\r
1841 case ShellMenuRebase:
\r
1842 svnCmd += _T("rebase /path:\"");
\r
1843 if (files_.size() > 0)
\r
1844 svnCmd += files_.front();
\r
1846 svnCmd += folder_;
\r
1847 svnCmd += _T("\"");
\r
1849 case ShellMenuShowChanged:
\r
1850 if (files_.size() > 1)
\r
1852 tempfile = WriteFileListToTempFile();
\r
1853 svnCmd += _T("repostatus /pathfile:\"");
\r
1854 svnCmd += tempfile;
\r
1855 svnCmd += _T("\"");
\r
1856 svnCmd += _T(" /deletepathfile");
\r
1860 svnCmd += _T("repostatus /path:\"");
\r
1861 if (files_.size() > 0)
\r
1862 svnCmd += files_.front();
\r
1864 svnCmd += folder_;
\r
1865 svnCmd += _T("\"");
\r
1868 case ShellMenuRefBrowse:
\r
1869 svnCmd += _T("refbrowse /path:\"");
\r
1870 if (files_.size() > 0)
\r
1871 svnCmd += files_.front();
\r
1873 svnCmd += folder_;
\r
1874 svnCmd += _T("\"");
\r
1876 case ShellMenuRefLog:
\r
1877 svnCmd += _T("reflog /path:\"");
\r
1878 if (files_.size() > 0)
\r
1879 svnCmd += files_.front();
\r
1881 svnCmd += folder_;
\r
1882 svnCmd += _T("\"");
\r
1885 case ShellMenuStashSave:
\r
1886 svnCmd += _T("stashsave /path:\"");
\r
1887 if (files_.size() > 0)
\r
1888 svnCmd += files_.front();
\r
1890 svnCmd += folder_;
\r
1891 svnCmd += _T("\"");
\r
1894 case ShellMenuStashApply:
\r
1895 svnCmd += _T("stashapply /path:\"");
\r
1896 if (files_.size() > 0)
\r
1897 svnCmd += files_.front();
\r
1899 svnCmd += folder_;
\r
1900 svnCmd += _T("\"");
\r
1903 case ShellMenuStashPop:
\r
1904 svnCmd += _T("stashpop /path:\"");
\r
1905 if (files_.size() > 0)
\r
1906 svnCmd += files_.front();
\r
1908 svnCmd += folder_;
\r
1909 svnCmd += _T("\"");
\r
1913 case ShellMenuStashList:
\r
1914 svnCmd += _T("reflog /path:\"");
\r
1915 if (files_.size() > 0)
\r
1916 svnCmd += files_.front();
\r
1918 svnCmd += folder_;
\r
1919 svnCmd += _T("\" /ref:refs/stash");
\r
1922 case ShellMenuSubAdd:
\r
1923 svnCmd += _T("subadd /path:\"");
\r
1924 if (files_.size() > 0)
\r
1925 svnCmd += files_.front();
\r
1927 svnCmd += folder_;
\r
1928 svnCmd += _T("\"");
\r
1931 case ShellMenuBlame:
\r
1932 svnCmd += _T("blame /path:\"");
\r
1933 if (files_.size() > 0)
\r
1934 svnCmd += files_.front();
\r
1936 svnCmd += folder_;
\r
1937 svnCmd += _T("\"");
\r
1939 case ShellMenuCreatePatch:
\r
1940 tempfile = WriteFileListToTempFile();
\r
1941 svnCmd += _T("createpatch /pathfile:\"");
\r
1942 svnCmd += tempfile;
\r
1943 svnCmd += _T("\"");
\r
1944 svnCmd += _T(" /deletepathfile");
\r
1946 case ShellMenuApplyPatch:
\r
1947 if ((itemStates & ITEMIS_PATCHINCLIPBOARD) && ((~itemStates) & ITEMIS_PATCHFILE))
\r
1949 // if there's a patch file in the clipboard, we save it
\r
1950 // to a temporary file and tell TortoiseMerge to use that one
\r
1951 UINT cFormat = RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
\r
1952 if ((cFormat)&&(OpenClipboard(NULL)))
\r
1954 HGLOBAL hglb = GetClipboardData(cFormat);
\r
1955 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
1957 DWORD len = GetTempPath(0, NULL);
\r
1958 TCHAR * path = new TCHAR[len+1];
\r
1959 TCHAR * tempF = new TCHAR[len+100];
\r
1960 GetTempPath (len+1, path);
\r
1961 GetTempFileName (path, TEXT("git"), 0, tempF);
\r
1962 std::wstring sTempFile = std::wstring(tempF);
\r
1967 size_t patchlen = strlen(lpstr);
\r
1968 _tfopen_s(&outFile, sTempFile.c_str(), _T("wb"));
\r
1971 size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile);
\r
1972 if (size == patchlen)
\r
1974 itemStates |= ITEMIS_PATCHFILE;
\r
1976 files_.push_back(sTempFile);
\r
1980 GlobalUnlock(hglb);
\r
1981 CloseClipboard();
\r
1984 if (itemStates & ITEMIS_PATCHFILE)
\r
1986 svnCmd = _T(" /diff:\"");
\r
1987 if (files_.size() > 0)
\r
1989 svnCmd += files_.front();
\r
1990 if (itemStatesFolder & ITEMIS_FOLDERINSVN)
\r
1992 svnCmd += _T("\" /patchpath:\"");
\r
1993 svnCmd += folder_;
\r
1997 svnCmd += folder_;
\r
1998 if (itemStates & ITEMIS_INVERSIONEDFOLDER)
\r
1999 svnCmd += _T("\" /wc");
\r
2001 svnCmd += _T("\"");
\r
2005 svnCmd = _T(" /patchpath:\"");
\r
2006 if (files_.size() > 0)
\r
2007 svnCmd += files_.front();
\r
2009 svnCmd += folder_;
\r
2010 svnCmd += _T("\"");
\r
2013 myVerbsIDMap.clear();
\r
2014 myVerbsMap.clear();
\r
2015 if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2018 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2019 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2020 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2023 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2024 (LPTSTR) &lpMsgBuf,
\r
2028 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2029 LocalFree( lpMsgBuf );
\r
2031 CloseHandle(process.hThread);
\r
2032 CloseHandle(process.hProcess);
\r
2035 case ShellMenuRevisionGraph:
\r
2036 svnCmd += _T("revisiongraph /path:\"");
\r
2037 if (files_.size() > 0)
\r
2038 svnCmd += files_.front();
\r
2040 svnCmd += folder_;
\r
2041 svnCmd += _T("\"");
\r
2043 case ShellMenuProperties:
\r
2044 tempfile = WriteFileListToTempFile();
\r
2045 svnCmd += _T("properties /pathfile:\"");
\r
2046 svnCmd += tempfile;
\r
2047 svnCmd += _T("\"");
\r
2048 svnCmd += _T(" /deletepathfile");
\r
2050 case ShellMenuClipPaste:
\r
2051 if (WriteClipboardPathsToTempFile(tempfile))
\r
2053 bool bCopy = true;
\r
2054 UINT cPrefDropFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
\r
2055 if (cPrefDropFormat)
\r
2057 if (OpenClipboard(lpcmi->hwnd))
\r
2059 HGLOBAL hglb = GetClipboardData(cPrefDropFormat);
\r
2062 DWORD* effect = (DWORD*) GlobalLock(hglb);
\r
2063 if (*effect == DROPEFFECT_MOVE)
\r
2065 GlobalUnlock(hglb);
\r
2072 svnCmd += _T("pastecopy /pathfile:\"");
\r
2074 svnCmd += _T("pastemove /pathfile:\"");
\r
2075 svnCmd += tempfile;
\r
2076 svnCmd += _T("\"");
\r
2077 svnCmd += _T(" /deletepathfile");
\r
2078 svnCmd += _T(" /droptarget:\"");
\r
2079 svnCmd += folder_;
\r
2080 svnCmd += _T("\"");
\r
2082 else return NOERROR;
\r
2084 case ShellMenuClone:
\r
2085 svnCmd += _T("clone /path:\"");
\r
2086 svnCmd += folder_;
\r
2087 svnCmd += _T("\"");
\r
2089 case ShellMenuPull:
\r
2090 svnCmd += _T("pull /path:\"");
\r
2091 if (files_.size() > 0)
\r
2092 svnCmd += files_.front();
\r
2094 svnCmd += folder_;
\r
2095 svnCmd += _T("\"");
\r
2097 case ShellMenuPush:
\r
2098 svnCmd += _T("push /path:\"");
\r
2099 if (files_.size() > 0)
\r
2100 svnCmd += files_.front();
\r
2102 svnCmd += folder_;
\r
2103 svnCmd += _T("\"");
\r
2105 case ShellMenuBranch:
\r
2106 svnCmd += _T("branch /path:\"");
\r
2107 if (files_.size() > 0)
\r
2108 svnCmd += files_.front();
\r
2110 svnCmd += folder_;
\r
2111 svnCmd += _T("\"");
\r
2114 case ShellMenuTag:
\r
2115 svnCmd += _T("tag /path:\"");
\r
2116 if (files_.size() > 0)
\r
2117 svnCmd += files_.front();
\r
2119 svnCmd += folder_;
\r
2120 svnCmd += _T("\"");
\r
2123 case ShellMenuFormatPatch:
\r
2124 svnCmd += _T("formatpatch /path:\"");
\r
2125 if (files_.size() > 0)
\r
2126 svnCmd += files_.front();
\r
2128 svnCmd += folder_;
\r
2129 svnCmd += _T("\"");
\r
2132 case ShellMenuImportPatch:
\r
2133 tempfile = WriteFileListToTempFile();
\r
2134 svnCmd += _T("importpatch /pathfile:\"");
\r
2135 svnCmd += tempfile;
\r
2136 svnCmd += _T("\"");
\r
2137 svnCmd += _T(" /deletepathfile");
\r
2140 case ShellMenuCherryPick:
\r
2141 svnCmd += _T("cherrypick /path:\"");
\r
2142 if (files_.size() > 0)
\r
2143 svnCmd += files_.front();
\r
2145 svnCmd += folder_;
\r
2146 svnCmd += _T("\"");
\r
2148 case ShellMenuFetch:
\r
2149 svnCmd += _T("fetch /path:\"");
\r
2150 if (files_.size() > 0)
\r
2151 svnCmd += files_.front();
\r
2153 svnCmd += folder_;
\r
2154 svnCmd += _T("\"");
\r
2160 } // switch (id_it->second)
\r
2161 svnCmd += _T(" /hwnd:");
\r
2163 _stprintf_s(buf, 30, _T("%d"), lpcmi->hwnd);
\r
2166 myVerbsIDMap.clear();
\r
2167 myVerbsMap.clear();
\r
2168 if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast<TCHAR*>(svnCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
2171 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
2172 FORMAT_MESSAGE_FROM_SYSTEM |
\r
2173 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
2176 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
2177 (LPTSTR) &lpMsgBuf,
\r
2181 MessageBox( NULL, (LPCTSTR)lpMsgBuf, _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION );
\r
2182 LocalFree( lpMsgBuf );
\r
2184 CloseHandle(process.hThread);
\r
2185 CloseHandle(process.hProcess);
\r
2187 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
\r
2188 } // if ((files_.size() > 0)||(folder_.size() > 0))
\r
2193 // This is for the status bar and things like that:
\r
2194 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR idCmd,
\r
2196 UINT FAR * /*reserved*/,
\r
2200 PreserveChdir preserveChdir;
\r
2201 //do we know the id?
\r
2202 std::map<UINT_PTR, UINT_PTR>::const_iterator id_it = myIDMap.lower_bound(idCmd);
\r
2203 if (id_it == myIDMap.end() || id_it->first != idCmd)
\r
2205 return E_INVALIDARG; //no, we don't
\r
2209 HRESULT hr = E_INVALIDARG;
\r
2211 MAKESTRING(IDS_MENUDESCDEFAULT);
\r
2212 int menuIndex = 0;
\r
2213 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2215 if (menuInfo[menuIndex].command == (GitCommands)id_it->second)
\r
2217 MAKESTRING(menuInfo[menuIndex].menuDescID);
\r
2223 const TCHAR * desc = stringtablebuffer;
\r
2226 case GCS_HELPTEXTA:
\r
2228 std::string help = WideToMultibyte(desc);
\r
2229 lstrcpynA(pszName, help.c_str(), cchMax);
\r
2233 case GCS_HELPTEXTW:
\r
2235 wide_string help = desc;
\r
2236 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2242 std::map<UINT_PTR, stdstring>::const_iterator verb_id_it = myVerbsIDMap.lower_bound(idCmd);
\r
2243 if (verb_id_it != myVerbsIDMap.end() && verb_id_it->first == idCmd)
\r
2245 std::string help = WideToMultibyte(verb_id_it->second);
\r
2246 lstrcpynA(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 wide_string help = verb_id_it->second;
\r
2257 ATLTRACE("verb : %ws\n", help.c_str());
\r
2258 lstrcpynW((LPWSTR)pszName, help.c_str(), cchMax);
\r
2267 STDMETHODIMP CShellExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
2270 return HandleMenuMsg2(uMsg, wParam, lParam, &res);
\r
2273 STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
\r
2275 PreserveChdir preserveChdir;
\r
2278 if (pResult == NULL)
\r
2285 case WM_MEASUREITEM:
\r
2287 MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;
\r
2288 if (lpmis==NULL||lpmis->CtlType!=ODT_MENU)
\r
2290 lpmis->itemWidth += 2;
\r
2291 if (lpmis->itemHeight < 16)
\r
2292 lpmis->itemHeight = 16;
\r
2299 DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
\r
2300 if ((lpdis==NULL)||(lpdis->CtlType != ODT_MENU))
\r
2301 return S_OK; //not for a menu
\r
2302 resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]);
\r
2303 if (resource == NULL)
\r
2305 HICON hIcon = (HICON)LoadImage(g_hResInst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2306 if (hIcon == NULL)
\r
2308 DrawIconEx(lpdis->hDC,
\r
2309 lpdis->rcItem.left - 16,
\r
2310 lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2,
\r
2312 0, NULL, DI_NORMAL);
\r
2313 DestroyIcon(hIcon);
\r
2321 if (HIWORD(wParam) != MF_POPUP)
\r
2323 int nChar = LOWORD(wParam);
\r
2324 if (_istascii((wint_t)nChar) && _istupper((wint_t)nChar))
\r
2325 nChar = tolower(nChar);
\r
2326 // we have the char the user pressed, now search that char in all our
\r
2328 std::vector<int> accmenus;
\r
2329 for (std::map<UINT_PTR, UINT_PTR>::iterator It = mySubMenuMap.begin(); It != mySubMenuMap.end(); ++It)
\r
2331 resource = GetMenuTextFromResource(mySubMenuMap[It->first]);
\r
2332 if (resource == NULL)
\r
2334 szItem = stringtablebuffer;
\r
2335 TCHAR * amp = _tcschr(szItem, '&');
\r
2339 int ampChar = LOWORD(*amp);
\r
2340 if (_istascii((wint_t)ampChar) && _istupper((wint_t)ampChar))
\r
2341 ampChar = tolower(ampChar);
\r
2342 if (ampChar == nChar)
\r
2344 // yep, we found a menu which has the pressed key
\r
2345 // as an accelerator. Add that menu to the list to
\r
2347 accmenus.push_back(It->first);
\r
2350 if (accmenus.size() == 0)
\r
2352 // no menu with that accelerator key.
\r
2353 *pResult = MAKELONG(0, MNC_IGNORE);
\r
2356 if (accmenus.size() == 1)
\r
2358 // Only one menu with that accelerator key. We're lucky!
\r
2359 // So just execute that menu entry.
\r
2360 *pResult = MAKELONG(accmenus[0], MNC_EXECUTE);
\r
2363 if (accmenus.size() > 1)
\r
2365 // we have more than one menu item with this accelerator key!
\r
2367 mif.cbSize = sizeof(MENUITEMINFO);
\r
2368 mif.fMask = MIIM_STATE;
\r
2369 for (std::vector<int>::iterator it = accmenus.begin(); it != accmenus.end(); ++it)
\r
2371 GetMenuItemInfo((HMENU)lParam, *it, TRUE, &mif);
\r
2372 if (mif.fState == MFS_HILITE)
\r
2374 // this is the selected item, so select the next one
\r
2376 if (it == accmenus.end())
\r
2377 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2379 *pResult = MAKELONG(*it, MNC_SELECT);
\r
2383 *pResult = MAKELONG(accmenus[0], MNC_SELECT);
\r
2394 LPCTSTR CShellExt::GetMenuTextFromResource(int id)
\r
2396 TCHAR textbuf[255];
\r
2397 LPCTSTR resource = NULL;
\r
2398 unsigned __int64 layout = g_ShellCache.GetMenuLayout();
\r
2401 int menuIndex = 0;
\r
2402 while (menuInfo[menuIndex].command != ShellMenuLastEntry)
\r
2404 if (menuInfo[menuIndex].command == id)
\r
2406 MAKESTRING(menuInfo[menuIndex].menuTextID);
\r
2407 resource = MAKEINTRESOURCE(menuInfo[menuIndex].iconID);
\r
2410 case ShellSubMenuMultiple:
\r
2411 case ShellSubMenuLink:
\r
2412 case ShellSubMenuFolder:
\r
2413 case ShellSubMenuFile:
\r
2414 case ShellSubMenu:
\r
2418 space = layout & menuInfo[menuIndex].menuID ? 0 : 6;
\r
2419 if (layout & (menuInfo[menuIndex].menuID))
\r
2421 _tcscpy_s(textbuf, 255, _T("Git "));
\r
2422 _tcscat_s(textbuf, 255, stringtablebuffer);
\r
2423 _tcscpy_s(stringtablebuffer, 255, textbuf);
\r
2434 bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
\r
2437 TCHAR buf[MAX_PATH]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
\r
2438 LPITEMIDLIST pidl = NULL;
\r
2439 while (cslidarray[i])
\r
2443 if (SHGetFolderLocation(NULL, cslidarray[i-1], NULL, 0, &pidl)!=S_OK)
\r
2445 if (!SHGetPathFromIDList(pidl, buf))
\r
2447 // not a file system path, definitely illegal for our use
\r
2448 CoTaskMemFree(pidl);
\r
2451 CoTaskMemFree(pidl);
\r
2452 if (_tcslen(buf)==0)
\r
2454 if (_tcscmp(buf, folder.c_str())==0)
\r
2460 void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags)
\r
2462 HMENU ignoresubmenu = NULL;
\r
2463 int indexignoresub = 0;
\r
2464 bool bShowIgnoreMenu = false;
\r
2465 TCHAR maskbuf[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2466 TCHAR ignorepath[MAX_PATH]; // MAX_PATH is ok, since this only holds a filename
\r
2467 if (files_.size() == 0)
\r
2469 UINT icon = bShowIcons ? IDI_IGNORE : 0;
\r
2471 std::vector<stdstring>::iterator I = files_.begin();
\r
2472 if (_tcsrchr(I->c_str(), '\\'))
\r
2473 _tcscpy_s(ignorepath, MAX_PATH, _tcsrchr(I->c_str(), '\\')+1);
\r
2475 _tcscpy_s(ignorepath, MAX_PATH, I->c_str());
\r
2476 if ((itemStates & ITEMIS_IGNORED)&&(ignoredprops.size() > 0))
\r
2478 // check if the item name is ignored or the mask
\r
2480 while ( (p=ignoredprops.find( ignorepath,p )) != -1 )
\r
2482 if ( (p==0 || ignoredprops[p-1]==TCHAR('\n'))
\r
2483 && (p+_tcslen(ignorepath)==ignoredprops.length() || ignoredprops[p+_tcslen(ignorepath)+1]==TCHAR('\n')) )
\r
2491 ignoresubmenu = CreateMenu();
\r
2492 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2493 stdstring verb = stdstring(ignorepath);
\r
2494 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2495 myVerbsMap[verb] = idCmd;
\r
2496 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2497 myVerbsIDMap[idCmd] = verb;
\r
2498 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnore;
\r
2499 myIDMap[idCmd++] = ShellMenuUnIgnore;
\r
2500 bShowIgnoreMenu = true;
\r
2502 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2503 if (_tcsrchr(ignorepath, '.'))
\r
2505 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2506 p = ignoredprops.find(maskbuf);
\r
2508 ((ignoredprops.compare(maskbuf)==0) || (ignoredprops.find('\n', p)==p+_tcslen(maskbuf)+1) || (ignoredprops.rfind('\n', p)==p-1)))
\r
2510 if (ignoresubmenu==NULL)
\r
2511 ignoresubmenu = CreateMenu();
\r
2513 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2514 stdstring verb = stdstring(maskbuf);
\r
2515 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2516 myVerbsMap[verb] = idCmd;
\r
2517 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2518 myVerbsIDMap[idCmd] = verb;
\r
2519 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreCaseSensitive;
\r
2520 myIDMap[idCmd++] = ShellMenuUnIgnoreCaseSensitive;
\r
2521 bShowIgnoreMenu = true;
\r
2525 else if ((itemStates & ITEMIS_IGNORED) == 0)
\r
2527 bShowIgnoreMenu = true;
\r
2528 ignoresubmenu = CreateMenu();
\r
2529 if (itemStates & ITEMIS_ONLYONE)
\r
2531 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2532 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2533 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2535 _tcscpy_s(maskbuf, MAX_PATH, _T("*"));
\r
2536 if (_tcsrchr(ignorepath, '.'))
\r
2538 _tcscat_s(maskbuf, MAX_PATH, _tcsrchr(ignorepath, '.'));
\r
2539 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, maskbuf);
\r
2540 stdstring verb = stdstring(maskbuf);
\r
2541 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2542 myVerbsMap[verb] = idCmd;
\r
2543 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2544 myVerbsIDMap[idCmd] = verb;
\r
2545 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreCaseSensitive;
\r
2546 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2551 MAKESTRING(IDS_MENUIGNOREMULTIPLE);
\r
2552 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2553 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2554 stdstring verb = stdstring(ignorepath);
\r
2555 myVerbsMap[verb] = idCmd - idCmdFirst;
\r
2556 myVerbsMap[verb] = idCmd;
\r
2557 myVerbsIDMap[idCmd - idCmdFirst] = verb;
\r
2558 myVerbsIDMap[idCmd] = verb;
\r
2559 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnore;
\r
2560 myIDMap[idCmd++] = ShellMenuIgnore;
\r
2562 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK);
\r
2563 _stprintf_s(ignorepath, MAX_PATH, stringtablebuffer, files_.size());
\r
2564 InsertMenu(ignoresubmenu, indexignoresub++, MF_BYPOSITION | MF_STRING , idCmd, ignorepath);
\r
2565 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] = ShellMenuIgnoreCaseSensitive;
\r
2571 myIDMap[idCmd++] = ShellMenuIgnoreCaseSensitive;
\r
2575 if (bShowIgnoreMenu)
\r
2577 MENUITEMINFO menuiteminfo;
\r
2578 SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
\r
2579 menuiteminfo.cbSize = sizeof(menuiteminfo);
\r
2580 if (fullver < 0x500 || (fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE|CMF_EXTENDEDVERBS))))
\r
2582 menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;
\r
2585 HBITMAP bmp = IconToBitmap(icon);
\r
2586 menuiteminfo.fMask |= MIIM_CHECKMARKS;
\r
2587 menuiteminfo.hbmpChecked = bmp;
\r
2588 menuiteminfo.hbmpUnchecked = bmp;
\r
2593 menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;
\r
2596 menuiteminfo.fMask |= MIIM_BITMAP;
\r
2597 menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;
\r
2600 menuiteminfo.fType = MFT_STRING;
\r
2601 menuiteminfo.hSubMenu = ignoresubmenu;
\r
2602 menuiteminfo.wID = idCmd;
\r
2603 SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));
\r
2604 if (itemStates & ITEMIS_IGNORED)
\r
2605 GetMenuTextFromResource(ShellMenuUnIgnoreSub);
\r
2607 GetMenuTextFromResource(ShellMenuIgnoreSub);
\r
2608 menuiteminfo.dwTypeData = stringtablebuffer;
\r
2609 menuiteminfo.cch = (UINT)min(_tcslen(menuiteminfo.dwTypeData), UINT_MAX);
\r
2611 InsertMenuItem((topmenu & MENUIGNORE) ? hMenu : subMenu, (topmenu & MENUIGNORE) ? indexMenu++ : indexSubMenu++, TRUE, &menuiteminfo);
\r
2612 if (itemStates & ITEMIS_IGNORED)
\r
2614 myIDMap[idCmd - idCmdFirst] = ShellMenuUnIgnoreSub;
\r
2615 myIDMap[idCmd++] = ShellMenuUnIgnoreSub;
\r
2619 myIDMap[idCmd - idCmdFirst] = ShellMenuIgnoreSub;
\r
2620 myIDMap[idCmd++] = ShellMenuIgnoreSub;
\r
2625 HBITMAP CShellExt::IconToBitmapPARGB32(UINT uIcon)
\r
2627 std::map<UINT, HBITMAP>::iterator bitmap_it = bitmaps.lower_bound(uIcon);
\r
2628 if (bitmap_it != bitmaps.end() && bitmap_it->first == uIcon)
\r
2629 return bitmap_it->second;
\r
2631 HICON hIcon = (HICON)LoadImage(g_hResInst, MAKEINTRESOURCE(uIcon), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
2635 if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL)
\r
2639 sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
\r
2640 sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
\r
2643 SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
\r
2644 HBITMAP hBmp = NULL;
\r
2646 HDC hdcDest = CreateCompatibleDC(NULL);
\r
2649 if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp)))
\r
2651 HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp);
\r
2654 BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
\r
2655 BP_PAINTPARAMS paintParams = {0};
\r
2656 paintParams.cbSize = sizeof(paintParams);
\r
2657 paintParams.dwFlags = BPPF_ERASE;
\r
2658 paintParams.pBlendFunction = &bfAlpha;
\r
2661 HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
\r
2664 if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL))
\r
2666 // If icon did not have an alpha channel we need to convert buffer to PARGB
\r
2667 ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon);
\r
2670 // This will write the buffer contents to the destination bitmap
\r
2671 pfnEndBufferedPaint(hPaintBuffer, TRUE);
\r
2674 SelectObject(hdcDest, hbmpOld);
\r
2678 DeleteDC(hdcDest);
\r
2681 DestroyIcon(hIcon);
\r
2684 bitmaps.insert(bitmap_it, std::make_pair(uIcon, hBmp));
\r
2688 HRESULT CShellExt::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
\r
2693 ZeroMemory(&bmi, sizeof(bmi));
\r
2694 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2695 bmi.bmiHeader.biPlanes = 1;
\r
2696 bmi.bmiHeader.biCompression = BI_RGB;
\r
2698 bmi.bmiHeader.biWidth = psize->cx;
\r
2699 bmi.bmiHeader.biHeight = psize->cy;
\r
2700 bmi.bmiHeader.biBitCount = 32;
\r
2702 HDC hdcUsed = hdc ? hdc : GetDC(NULL);
\r
2705 *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
\r
2706 if (hdc != hdcUsed)
\r
2708 ReleaseDC(NULL, hdcUsed);
\r
2711 return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK;
\r
2714 HRESULT CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon)
\r
2716 RGBQUAD *prgbQuad;
\r
2718 HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
\r
2719 if (SUCCEEDED(hr))
\r
2721 ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad);
\r
2722 if (!HasAlpha(pargb, sizIcon, cxRow))
\r
2725 if (GetIconInfo(hicon, &info))
\r
2729 hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
\r
2732 DeleteObject(info.hbmColor);
\r
2733 DeleteObject(info.hbmMask);
\r
2741 bool CShellExt::HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow)
\r
2743 ULONG cxDelta = cxRow - sizImage.cx;
\r
2744 for (ULONG y = sizImage.cy; y; --y)
\r
2746 for (ULONG x = sizImage.cx; x; --x)
\r
2748 if (*pargb++ & 0xFF000000)
\r
2760 HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
\r
2763 ZeroMemory(&bmi, sizeof(bmi));
\r
2764 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
2765 bmi.bmiHeader.biPlanes = 1;
\r
2766 bmi.bmiHeader.biCompression = BI_RGB;
\r
2768 bmi.bmiHeader.biWidth = sizImage.cx;
\r
2769 bmi.bmiHeader.biHeight = sizImage.cy;
\r
2770 bmi.bmiHeader.biBitCount = 32;
\r
2772 HRESULT hr = E_OUTOFMEMORY;
\r
2773 HANDLE hHeap = GetProcessHeap();
\r
2774 void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
\r
2777 hr = E_UNEXPECTED;
\r
2778 if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
\r
2780 ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
\r
2781 ARGB *pargbMask = static_cast<ARGB *>(pvBits);
\r
2783 for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
\r
2785 for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
\r
2789 // transparent pixel
\r
2795 *pargb++ |= 0xFF000000;
\r
2805 HeapFree(hHeap, 0, pvBits);
\r