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