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_MENUPULL
,
45 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
47 // { ShellMenuCheckout, MENUCHECKOUT, IDI_CHECKOUT, IDS_MENUCHECKOUT, IDS_MENUDESCCHECKOUT,
48 // ITEMIS_FOLDER, ITEMIS_INSVN|ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0, 0 },
50 // { ShellMenuUpdate, MENUSUBUPDATE, IDI_UPDATE, IDS_MENUUPDATE, IDS_MENUDESCUPDATE,
51 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
54 { ShellMenuCommit
, MENUCOMMIT
, IDI_COMMIT
, IDS_MENUCOMMIT
, IDS_MENUDESCCOMMIT
,
55 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
57 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
59 { ShellMenuDiff
, MENUDIFF
, IDI_DIFF
, IDS_MENUDIFF
, IDS_MENUDESCDIFF
,
60 ITEMIS_INSVN
|ITEMIS_ONLYONE
, ITEMIS_FOLDER
|ITEMIS_NORMAL
, ITEMIS_TWO
, 0, 0, 0, 0, 0 },
62 { ShellMenuPrevDiff
, MENUPREVDIFF
, IDI_DIFF
, IDS_MENUPREVDIFF
, IDS_MENUDESCPREVDIFF
,
63 ITEMIS_INSVN
|ITEMIS_ONLYONE
, ITEMIS_FOLDER
, 0, 0, 0, 0, 0, 0 },
65 // { ShellMenuUrlDiff, MENUURLDIFF, IDI_DIFF, IDS_MENUURLDIFF, IDS_MENUDESCURLDIFF,
66 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, ITEMIS_FOLDERINSVN|ITEMIS_EXTENDED|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
68 { ShellMenuLog
, MENULOG
, IDI_LOG
, IDS_MENULOG
, IDS_MENUDESCLOG
,
69 ITEMIS_INSVN
|ITEMIS_ONLYONE
, ITEMIS_ADDED
, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, ITEMIS_ADDED
, ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, ITEMIS_ADDED
, 0, 0 },
71 { ShellMenuRefLog
, MENUREFLOG
, IDI_LOG
, IDS_MENUREFLOG
, IDS_MENUDESCREFLOG
,
72 ITEMIS_INSVN
|ITEMIS_ONLYONE
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, 0, 0 },
74 // { ShellMenuRepoBrowse, MENUREPOBROWSE, IDI_REPOBROWSE, IDS_MENUREPOBROWSE, IDS_MENUDESCREPOBROWSE,
75 // ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
77 { ShellMenuShowChanged
, MENUSHOWCHANGED
, IDI_SHOWCHANGED
, IDS_MENUSHOWCHANGED
, IDS_MENUDESCSHOWCHANGED
,
78 ITEMIS_INSVN
|ITEMIS_ONLYONE
, 0, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, 0, 0, 0, 0, 0},
80 { ShellMenuRebase
, MENUREBASE
, IDI_REBASE
, IDS_MENUREBASE
, IDS_MENUREBASE
,
81 ITEMIS_INSVN
|ITEMIS_ONLYONE
, 0, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, 0, 0, 0, 0, 0},
83 // { ShellMenuRevisionGraph, MENUREVISIONGRAPH, IDI_REVISIONGRAPH, IDS_MENUREVISIONGRAPH, IDS_MENUDESCREVISIONGRAPH,
84 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, 0, 0, 0, 0},
86 { ShellMenuStashSave
, MENUSTASHSAVE
, IDI_COMMIT
, IDS_MENUSTASHSAVE
, IDS_MENUSTASHSAVE
,
87 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
88 { ShellMenuStashApply
, MENUSTASHAPPLY
, IDI_RELOCATE
, IDS_MENUSTASHAPPLY
, IDS_MENUSTASHAPPLY
,
89 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
90 { ShellMenuStashList
, MENUSTASHAPPLY
, IDI_LOG
, IDS_MENUSTASHLIST
, IDS_MENUSTASHLIST
,
91 ITEMIS_INSVN
|ITEMIS_EXTENDED
, 0, ITEMIS_FOLDERINSVN
|ITEMIS_EXTENDED
, 0, 0, 0, 0, 0 },
94 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
96 { ShellMenuConflictEditor
, MENUCONFLICTEDITOR
, IDI_CONFLICT
, IDS_MENUCONFLICT
, IDS_MENUDESCCONFLICT
,
97 ITEMIS_INSVN
|ITEMIS_CONFLICTED
, ITEMIS_FOLDER
, 0, 0, 0, 0, 0, 0 },
99 { ShellMenuResolve
, MENURESOLVE
, IDI_RESOLVE
, IDS_MENURESOLVE
, IDS_MENUDESCRESOLVE
,
100 ITEMIS_INSVN
|ITEMIS_CONFLICTED
, 0, ITEMIS_INSVN
|ITEMIS_FOLDER
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0 },
103 { ShellMenuRename
, MENURENAME
, IDI_RENAME
, IDS_MENURENAME
, IDS_MENUDESCRENAME
,
104 ITEMIS_INSVN
|ITEMIS_ONLYONE
|ITEMIS_INVERSIONEDFOLDER
, 0, 0, 0, 0, 0, 0, 0 },
106 { ShellMenuRemove
, MENUREMOVE
, IDI_DELETE
, IDS_MENUREMOVE
, IDS_MENUDESCREMOVE
,
107 ITEMIS_INSVN
|ITEMIS_INVERSIONEDFOLDER
, ITEMIS_ADDED
, 0, 0, 0, 0, 0, 0 },
109 { ShellMenuRemoveKeep
, MENUREMOVE
, IDI_DELETE
, IDS_MENUREMOVEKEEP
, IDS_MENUDESCREMOVEKEEP
,
110 ITEMIS_INSVN
|ITEMIS_INVERSIONEDFOLDER
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, 0, 0, 0, 0, 0, 0 },
112 { ShellMenuRevert
, MENUREVERT
, IDI_REVERT
, IDS_MENUREVERT
, IDS_MENUDESCREVERT
,
113 ITEMIS_INSVN
, ITEMIS_NORMAL
|ITEMIS_ADDED
, ITEMIS_FOLDERINSVN
, ITEMIS_ADDED
, 0, 0, 0, 0 },
115 { ShellMenuRevert
, MENUREVERT
, IDI_REVERT
, IDS_MENUUNDOADD
, IDS_MENUDESCUNDOADD
,
116 ITEMIS_ADDED
, ITEMIS_NORMAL
, ITEMIS_FOLDERINSVN
|ITEMIS_ADDED
, 0, 0, 0, 0, 0 },
118 { ShellMenuDelUnversioned
, MENUDELUNVERSIONED
, IDI_DELUNVERSIONED
, IDS_MENUDELUNVERSIONED
, IDS_MENUDESCDELUNVERSIONED
,
119 ITEMIS_FOLDER
|ITEMIS_INSVN
|ITEMIS_EXTENDED
, 0, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_EXTENDED
, 0, 0, 0, 0, 0 },
121 { ShellMenuCleanup
, MENUCLEANUP
, IDI_CLEANUP
, IDS_MENUCLEANUP
, IDS_MENUDESCCLEANUP
,
122 ITEMIS_INSVN
|ITEMIS_FOLDER
, 0, ITEMIS_FOLDERINSVN
|ITEMIS_FOLDER
, 0, 0, 0, 0, 0 },
124 // { ShellMenuLock, MENULOCK, IDI_LOCK, IDS_MENU_LOCK, IDS_MENUDESC_LOCK,
125 // ITEMIS_INSVN, ITEMIS_LOCKED|ITEMIS_ADDED, ITEMIS_FOLDERINSVN, ITEMIS_LOCKED|ITEMIS_ADDED, 0, 0, 0, 0 },
127 // { ShellMenuUnlock, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCK, IDS_MENUDESC_UNLOCK,
128 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0 },
130 // { ShellMenuUnlockForce, MENUUNLOCK, IDI_UNLOCK, IDS_MENU_UNLOCKFORCE, IDS_MENUDESC_UNLOCKFORCE,
131 // ITEMIS_INSVN|ITEMIS_LOCKED, 0, ITEMIS_FOLDER|ITEMIS_INSVN|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
133 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
135 // { ShellMenuCopy, MENUCOPY, IDI_COPY, IDS_MENUBRANCH, IDS_MENUDESCCOPY,
136 // ITEMIS_INSVN|ITEMIS_ONLYONE, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
138 { ShellMenuSwitch
, MENUSWITCH
, IDI_SWITCH
, IDS_MENUSWITCH
, IDS_MENUDESCSWITCH
,
139 ITEMIS_INSVN
|ITEMIS_ONLYONE
, ITEMIS_ADDED
, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, 0, 0, 0, 0, 0 },
141 { ShellMenuMerge
, MENUMERGE
, IDI_MERGE
, IDS_MENUMERGE
, IDS_MENUDESCMERGE
,
142 ITEMIS_INSVN
|ITEMIS_ONLYONE
, ITEMIS_ADDED
, ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_ONLYONE
, 0, 0, 0, 0, 0 },
143 // { ShellMenuMergeAll, MENUMERGEALL, IDI_MERGE, IDS_MENUMERGEALL, IDS_MENUDESCMERGEALL,
144 // ITEMIS_INSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, ITEMIS_ADDED, ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE|ITEMIS_EXTENDED, 0, 0, 0, 0, 0 },
146 { ShellMenuBranch
, MENUCOPY
, IDI_COPY
, IDS_MENUBRANCH
, IDS_MENUDESCCOPY
,
147 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
148 { ShellMenuTag
, MENUTAG
, IDI_TAG
, IDS_MENUTAG
, IDS_MENUDESCCOPY
,
149 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
151 { ShellMenuExport
, MENUEXPORT
, IDI_EXPORT
, IDS_MENUEXPORT
, IDS_MENUDESCEXPORT
,
152 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
154 // { ShellMenuRelocate, MENURELOCATE, IDI_RELOCATE, IDS_MENURELOCATE, IDS_MENUDESCRELOCATE,
155 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, ITEMIS_FOLDERINSVN|ITEMIS_ONLYONE, 0, 0, 0, 0, 0 },
157 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
159 { ShellMenuCreateRepos
, MENUCREATEREPOS
, IDI_CREATEREPOS
, IDS_MENUCREATEREPOS
, IDS_MENUDESCCREATEREPOS
,
160 ITEMIS_FOLDER
, ITEMIS_INSVN
|ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0, 0 },
162 { ShellMenuAdd
, MENUADD
, IDI_ADD
, IDS_MENUADD
, IDS_MENUDESCADD
,
163 ITEMIS_INVERSIONEDFOLDER
, ITEMIS_INSVN
, ITEMIS_INSVN
|ITEMIS_FOLDER
, 0, ITEMIS_IGNORED
, 0, ITEMIS_DELETED
, ITEMIS_FOLDER
|ITEMIS_ONLYONE
},
165 // { ShellMenuAddAsReplacement, MENUADD, IDI_ADD, IDS_MENUADDASREPLACEMENT, IDS_MENUADDASREPLACEMENT,
166 // ITEMIS_DELETED|ITEMIS_ONLYONE, ITEMIS_FOLDER, 0, 0, 0, 0, 0, 0 },
168 // { ShellMenuImport, MENUIMPORT, IDI_IMPORT, IDS_MENUIMPORT, IDS_MENUDESCIMPORT,
169 // ITEMIS_FOLDER, ITEMIS_INSVN, 0, 0, 0, 0, 0, 0 },
171 { ShellMenuBlame
, MENUBLAME
, IDI_BLAME
, IDS_MENUBLAME
, IDS_MENUDESCBLAME
,
172 ITEMIS_NORMAL
|ITEMIS_ONLYONE
, ITEMIS_FOLDER
|ITEMIS_ADDED
, 0, 0, 0, 0, 0, 0 },
173 // TODO: original code is ITEMIS_INSVN|ITEMIS_ONLYONE, makes sense to only allow blaming of versioned files
174 // why was this changed, is this related to GitStatus?
176 { ShellMenuIgnoreSub
, MENUIGNORE
, IDI_IGNORE
, IDS_MENUIGNORE
, IDS_MENUDESCIGNORE
,
177 ITEMIS_INVERSIONEDFOLDER
, ITEMIS_IGNORED
|ITEMIS_INSVN
, 0, 0, 0, 0, 0, 0 },
179 { ShellMenuUnIgnoreSub
, MENUIGNORE
, IDI_IGNORE
, IDS_MENUUNIGNORE
, IDS_MENUDESCUNIGNORE
,
180 ITEMIS_IGNORED
, 0, 0, 0, 0, 0, 0, 0 },
182 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
184 { ShellMenuSubAdd
, MENUSUBADD
, IDI_ADD
, IDS_MENUSUBADD
, IDS_MENUSUBADD
,
185 ITEMIS_INSVN
, 0, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
187 { ShellMenuUpdateExt
, MENUUPDATEEXT
, IDI_UPDATE
, IDS_MENUUPDATEEXT
, IDS_MENUDESCUPDATEEXT
,
188 ITEMIS_FOLDERINSVN
|ITEMIS_SUBMODULE
, 0, 0, 0, 0, 0, 0, 0 },
191 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
193 // { ShellMenuCherryPick, MENUCHERRYPICK, IDI_CREATEPATCH, IDS_MENUCHERRYPICK, IDS_MENUDESCCREATEPATCH,
194 // ITEMIS_INSVN, ITEMIS_NORMAL, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
196 { ShellMenuFormatPatch
, MENUFORMATPATCH
, IDI_CREATEPATCH
, IDS_MENUFORMATPATCH
, IDS_MENUDESCCREATEPATCH
,
197 ITEMIS_INSVN
, ITEMIS_NORMAL
, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
199 { ShellMenuImportPatch
, MENUIMPORTPATCH
, IDI_PATCH
, IDS_MENUIMPORTPATCH
, IDS_MENUDESCCREATEPATCH
,
200 ITEMIS_INSVN
, ITEMIS_NORMAL
, ITEMIS_FOLDERINSVN
, 0, 0, 0, 0, 0 },
203 { ShellMenuCreatePatch
, MENUCREATEPATCH
, IDI_CREATEPATCH
, IDS_MENUCREATEPATCH
, IDS_MENUDESCCREATEPATCH
,
204 ITEMIS_INSVN
|ITEMIS_EXTENDED
, ITEMIS_NORMAL
, ITEMIS_FOLDERINSVN
|ITEMIS_EXTENDED
, 0, 0, 0, 0, 0 },
206 { ShellMenuApplyPatch
, MENUAPPLYPATCH
, IDI_PATCH
, IDS_MENUAPPLYPATCH
, IDS_MENUDESCAPPLYPATCH
,
207 ITEMIS_INSVN
|ITEMIS_FOLDER
|ITEMIS_FOLDERINSVN
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, ITEMIS_ONLYONE
|ITEMIS_PATCHFILE
|ITEMIS_EXTENDED
, 0, ITEMIS_FOLDERINSVN
|ITEMIS_EXTENDED
, ITEMIS_ADDED
, 0, 0 },
209 // { ShellMenuProperties, MENUPROPERTIES, IDI_PROPERTIES, IDS_MENUPROPERTIES, IDS_MENUDESCPROPERTIES,
210 // ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },
212 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
213 // { ShellMenuClipPaste, MENUCLIPPASTE, IDI_CLIPPASTE, IDS_MENUCLIPPASTE, IDS_MENUDESCCLIPPASTE,
214 // ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },
216 { ShellSeparator
, 0, 0, 0, 0, 0, 0, 0, 0},
218 { ShellMenuSettings
, MENUSETTINGS
, IDI_SETTINGS
, IDS_MENUSETTINGS
, IDS_MENUDESCSETTINGS
,
219 ITEMIS_FOLDER
, 0, 0, ITEMIS_FOLDER
, 0, 0, 0, 0 },
220 { ShellMenuHelp
, MENUHELP
, IDI_HELP
, IDS_MENUHELP
, IDS_MENUDESCHELP
,
221 ITEMIS_FOLDER
, 0, 0, ITEMIS_FOLDER
, 0, 0, 0, 0 },
222 { ShellMenuAbout
, MENUABOUT
, IDI_ABOUT
, IDS_MENUABOUT
, IDS_MENUDESCABOUT
,
223 ITEMIS_FOLDER
, 0, 0, ITEMIS_FOLDER
, 0, 0, 0, 0 },
225 // the sub menus - they're not added like the the commands, therefore the menu ID is zero
226 // but they still need to be in here, because we use the icon and string information anyway.
227 { ShellSubMenu
, NULL
, IDI_APP
, IDS_MENUSUBMENU
, 0,
228 0, 0, 0, 0, 0, 0, 0, 0 },
229 { ShellSubMenuFile
, NULL
, IDI_MENUFILE
, IDS_MENUSUBMENU
, 0,
230 0, 0, 0, 0, 0, 0, 0, 0 },
231 { ShellSubMenuFolder
, NULL
, IDI_MENUFOLDER
, IDS_MENUSUBMENU
, 0,
232 0, 0, 0, 0, 0, 0, 0, 0 },
233 { ShellSubMenuLink
, NULL
, IDI_MENULINK
, IDS_MENUSUBMENU
, 0,
234 0, 0, 0, 0, 0, 0, 0, 0 },
235 { ShellSubMenuMultiple
, NULL
, IDI_MENUMULTIPLE
, IDS_MENUSUBMENU
, 0,
236 0, 0, 0, 0, 0, 0, 0, 0 },
237 // mark the last entry to tell the loop where to stop iterating over this array
238 { ShellMenuLastEntry
, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0 },
243 STDMETHODIMP
CShellExt::Initialize(LPCITEMIDLIST pIDFolder
,
244 LPDATAOBJECT pDataObj
,
248 ATLTRACE("Shell :: Initialize\n");
249 PreserveChdir preserveChdir
;
255 itemStatesFolder
= 0;
256 stdstring statuspath
;
257 git_wc_status_kind fetchedstatus
= git_wc_status_none
;
258 // get selected files/folders
262 FORMATETC fmte
= {(CLIPFORMAT
)g_shellidlist
,
263 (DVTARGETDEVICE FAR
*)NULL
,
267 HRESULT hres
= pDataObj
->GetData(&fmte
, &medium
);
269 if (SUCCEEDED(hres
) && medium
.hGlobal
)
271 if (m_State
== FileStateDropHandler
)
274 FORMATETC etc
= { CF_HDROP
, NULL
, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
275 STGMEDIUM stg
= { TYMED_HGLOBAL
};
276 if ( FAILED( pDataObj
->GetData ( &etc
, &stg
)))
278 ReleaseStgMedium ( &medium
);
283 HDROP drop
= (HDROP
)GlobalLock(stg
.hGlobal
);
286 ReleaseStgMedium ( &stg
);
287 ReleaseStgMedium ( &medium
);
291 int count
= DragQueryFile(drop
, (UINT
)-1, NULL
, 0);
293 itemStates
|= ITEMIS_ONLYONE
;
294 for (int i
= 0; i
< count
; i
++)
296 // find the path length in chars
297 UINT len
= DragQueryFile(drop
, i
, NULL
, 0);
300 TCHAR
* szFileName
= new TCHAR
[len
+1];
301 if (0 == DragQueryFile(drop
, i
, szFileName
, len
+1))
303 delete [] szFileName
;
306 stdstring str
= stdstring(szFileName
);
307 delete [] szFileName
;
308 if ((str
.empty() == false)&&(g_ShellCache
.IsContextPathAllowed(szFileName
)))
310 if (itemStates
& ITEMIS_ONLYONE
)
313 strpath
.SetFromWin(str
.c_str());
314 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE
: 0;
315 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE
: 0;
317 files_
.push_back(str
);
320 //get the Subversion status of the item
321 git_wc_status_kind status
= git_wc_status_none
;
323 askedpath
.SetFromWin(str
.c_str());
327 stat
.GetStatus(CTGitPath(str
.c_str()), false, true, true);
331 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
332 fetchedstatus
= status
;
333 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
334 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
335 if ( askedpath
.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
337 itemStates
|= ITEMIS_FOLDER
;
338 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
339 itemStates
|= ITEMIS_FOLDERINSVN
;
341 //if ((stat.status->entry)&&(stat.status->entry->present_props))
343 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
344 // itemStates |= ITEMIS_NEEDSLOCK;
346 //if ((stat.status->entry)&&(stat.status->entry->uuid))
347 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
351 // sometimes, git_client_status() returns with an error.
352 // in that case, we have to check if the working copy is versioned
353 // anyway to show the 'correct' context menu
354 if (askedpath
.HasAdminDir())
355 status
= git_wc_status_normal
;
360 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
363 // TODO: should we really assume any sub-directory to be versioned
364 // or only if it contains versioned files
365 if ( askedpath
.IsDirectory() )
367 if (askedpath
.HasAdminDir())
368 itemStates
|= ITEMIS_INSVN
;
370 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
371 itemStates
|= ITEMIS_INSVN
;
372 if (status
== git_wc_status_ignored
)
373 itemStates
|= ITEMIS_IGNORED
;
374 if (status
== git_wc_status_normal
)
375 itemStates
|= ITEMIS_NORMAL
;
376 if (status
== git_wc_status_conflicted
)
377 itemStates
|= ITEMIS_CONFLICTED
;
378 if (status
== git_wc_status_added
)
379 itemStates
|= ITEMIS_ADDED
;
380 if (status
== git_wc_status_deleted
)
381 itemStates
|= ITEMIS_DELETED
;
384 } // for (int i = 0; i < count; i++)
385 GlobalUnlock ( drop
);
386 ReleaseStgMedium ( &stg
);
388 } // if (m_State == FileStateDropHandler)
392 //Enumerate PIDLs which the user has selected
393 CIDA
* cida
= (CIDA
*)GlobalLock(medium
.hGlobal
);
394 ItemIDList
parent( GetPIDLFolder (cida
));
396 int count
= cida
->cidl
;
397 BOOL statfetched
= FALSE
;
398 for (int i
= 0; i
< count
; ++i
)
400 ItemIDList
child (GetPIDLItem (cida
, i
), &parent
);
401 stdstring str
= child
.toString();
402 if ((str
.empty() == false)&&(g_ShellCache
.IsContextPathAllowed(str
.c_str())))
404 //check if our menu is requested for a subversion admin directory
405 if (g_GitAdminDir
.IsAdminDirPath(str
.c_str()))
408 files_
.push_back(str
);
410 strpath
.SetFromWin(str
.c_str());
411 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE
: 0;
412 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE
: 0;
415 //get the Subversion status of the item
416 git_wc_status_kind status
= git_wc_status_none
;
417 if ((g_ShellCache
.IsSimpleContext())&&(strpath
.IsDirectory()))
419 if (strpath
.HasAdminDir())
420 status
= git_wc_status_normal
;
427 if (strpath
.HasAdminDir())
428 stat
.GetStatus(strpath
, false, true, true);
432 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
433 fetchedstatus
= status
;
434 //if ((stat.status->entry)&&(stat.status->entry->lock_token))
435 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
436 if ( strpath
.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
438 itemStates
|= ITEMIS_FOLDER
;
439 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
440 itemStates
|= ITEMIS_FOLDERINSVN
;
442 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
443 if (status
== git_wc_status_conflicted
)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
444 itemStates
|= ITEMIS_CONFLICTED
;
445 //if ((stat.status->entry)&&(stat.status->entry->present_props))
447 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
448 // itemStates |= ITEMIS_NEEDSLOCK;
450 //if ((stat.status->entry)&&(stat.status->entry->uuid))
451 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
455 // sometimes, git_client_status() returns with an error.
456 // in that case, we have to check if the working copy is versioned
457 // anyway to show the 'correct' context menu
458 if (strpath
.HasAdminDir())
460 status
= git_wc_status_normal
;
461 fetchedstatus
= status
;
468 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
472 // TODO: should we really assume any sub-directory to be versioned
473 // or only if it contains versioned files
474 if ( strpath
.IsDirectory() )
476 if (strpath
.HasAdminDir())
477 itemStates
|= ITEMIS_INSVN
;
479 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
480 itemStates
|= ITEMIS_INSVN
;
481 if (status
== git_wc_status_ignored
)
483 itemStates
|= ITEMIS_IGNORED
;
484 // the item is ignored. Get the svn:ignored properties so we can (maybe) later
485 // offer a 'remove from ignored list' entry
486 // GitProperties props(strpath.GetContainingDirectory(), false);
487 // ignoredprops.empty();
488 // for (int p=0; p<props.GetCount(); ++p)
490 // if (props.GetItemName(p).compare(stdstring(_T("svn:ignore")))==0)
492 // std::string st = props.GetItemValue(p);
493 // ignoredprops = MultibyteToWide(st.c_str());
494 // // remove all escape chars ('\\')
495 // std::remove(ignoredprops.begin(), ignoredprops.end(), '\\');
500 if (status
== git_wc_status_normal
)
501 itemStates
|= ITEMIS_NORMAL
;
502 if (status
== git_wc_status_conflicted
)
503 itemStates
|= ITEMIS_CONFLICTED
;
504 if (status
== git_wc_status_added
)
505 itemStates
|= ITEMIS_ADDED
;
506 if (status
== git_wc_status_deleted
)
507 itemStates
|= ITEMIS_DELETED
;
510 } // for (int i = 0; i < count; ++i)
511 ItemIDList
child (GetPIDLItem (cida
, 0), &parent
);
512 if (g_ShellCache
.HasSVNAdminDir(child
.toString().c_str(), FALSE
))
513 itemStates
|= ITEMIS_INVERSIONEDFOLDER
;
514 GlobalUnlock(medium
.hGlobal
);
516 // if the item is a versioned folder, check if there's a patch file
517 // in the clipboard to be used in "Apply Patch"
518 UINT cFormatDiff
= RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
521 if (IsClipboardFormatAvailable(cFormatDiff
))
522 itemStates
|= ITEMIS_PATCHINCLIPBOARD
;
524 if (IsClipboardFormatAvailable(CF_HDROP
))
525 itemStates
|= ITEMIS_PATHINCLIPBOARD
;
529 ReleaseStgMedium ( &medium
);
530 if (medium
.pUnkForRelease
)
532 IUnknown
* relInterface
= (IUnknown
*)medium
.pUnkForRelease
;
533 relInterface
->Release();
538 // get folder background
542 ItemIDList
list(pIDFolder
);
543 folder_
= list
.toString();
544 git_wc_status_kind status
= git_wc_status_none
;
545 if (IsClipboardFormatAvailable(CF_HDROP
))
546 itemStatesFolder
|= ITEMIS_PATHINCLIPBOARD
;
549 askedpath
.SetFromWin(folder_
.c_str());
551 if ((folder_
.compare(statuspath
)!=0)&&(g_ShellCache
.IsContextPathAllowed(folder_
.c_str())))
557 stat
.GetStatus(CTGitPath(folder_
.c_str()), false, true, true);
560 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
561 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
562 // itemStatesFolder |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
563 // if ((stat.status->entry)&&(stat.status->entry->present_props))
565 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
566 // itemStatesFolder |= ITEMIS_NEEDSLOCK;
568 // if ((stat.status->entry)&&(stat.status->entry->uuid))
569 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
574 // sometimes, git_client_status() returns with an error.
575 // in that case, we have to check if the working copy is versioned
576 // anyway to show the 'correct' context menu
577 if (askedpath
.HasAdminDir())
578 status
= git_wc_status_normal
;
581 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
582 if (askedpath
.HasAdminDir())
583 itemStatesFolder
|= ITEMIS_INSVN
;
584 if (status
== git_wc_status_normal
)
585 itemStatesFolder
|= ITEMIS_NORMAL
;
586 if (status
== git_wc_status_conflicted
)
587 itemStatesFolder
|= ITEMIS_CONFLICTED
;
588 if (status
== git_wc_status_added
)
589 itemStatesFolder
|= ITEMIS_ADDED
;
590 if (status
== git_wc_status_deleted
)
591 itemStatesFolder
|= ITEMIS_DELETED
;
596 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
601 status
= fetchedstatus
;
603 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
604 if (askedpath
.HasAdminDir())
606 itemStatesFolder
|= ITEMIS_FOLDERINSVN
;
608 if (askedpath
.HasSubmodules())
610 itemStatesFolder
|= ITEMIS_SUBMODULE
;
612 if (status
== git_wc_status_ignored
)
613 itemStatesFolder
|= ITEMIS_IGNORED
;
614 itemStatesFolder
|= ITEMIS_FOLDER
;
615 if (files_
.size() == 0)
616 itemStates
|= ITEMIS_ONLYONE
;
617 if (m_State
!= FileStateDropHandler
)
618 itemStates
|= itemStatesFolder
;
622 if (files_
.size() == 2)
623 itemStates
|= ITEMIS_TWO
;
624 if ((files_
.size() == 1)&&(g_ShellCache
.IsContextPathAllowed(files_
.front().c_str())))
627 itemStates
|= ITEMIS_ONLYONE
;
628 if (m_State
!= FileStateDropHandler
)
630 if (PathIsDirectory(files_
.front().c_str()))
632 folder_
= files_
.front();
633 git_wc_status_kind status
= git_wc_status_none
;
635 askedpath
.SetFromWin(folder_
.c_str());
637 if (folder_
.compare(statuspath
)!=0)
642 stat
.GetStatus(CTGitPath(folder_
.c_str()), false, true, true);
645 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
646 // if ((stat.status->entry)&&(stat.status->entry->lock_token))
647 // itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;
648 // if ((stat.status->entry)&&(stat.status->entry->present_props))
650 // if (strstr(stat.status->entry->present_props, "svn:needs-lock"))
651 // itemStates |= ITEMIS_NEEDSLOCK;
653 // if ((stat.status->entry)&&(stat.status->entry->uuid))
654 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
659 ATLTRACE2(_T("Exception in GitStatus::GetStatus()\n"));
664 status
= fetchedstatus
;
666 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
667 if (askedpath
.HasAdminDir())
668 itemStates
|= ITEMIS_FOLDERINSVN
;
669 if (status
== git_wc_status_ignored
)
670 itemStates
|= ITEMIS_IGNORED
;
671 itemStates
|= ITEMIS_FOLDER
;
672 if (status
== git_wc_status_added
)
673 itemStates
|= ITEMIS_ADDED
;
674 if (status
== git_wc_status_deleted
)
675 itemStates
|= ITEMIS_DELETED
;
684 void CShellExt::InsertGitMenu(BOOL istop
, HMENU menu
, UINT pos
, UINT_PTR id
, UINT stringid
, UINT icon
, UINT idCmdFirst
, GitCommands com
, UINT uFlags
)
686 TCHAR menutextbuffer
[512] = {0};
687 TCHAR verbsbuffer
[255] = {0};
688 MAKESTRING(stringid
);
692 //menu entry for the top context menu, so append an "Git " before
693 //the menu text to indicate where the entry comes from
694 _tcscpy_s(menutextbuffer
, 255, _T("Git "));
696 _tcscat_s(menutextbuffer
, 255, stringtablebuffer
);
698 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
699 // so we have an easy and fast way to check the current branch
700 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
701 if (com
== ShellMenuCommit
)
704 CTGitPath
path(folder_
.empty() ? files_
.front().c_str() : folder_
.c_str());
705 CString sProjectRoot
;
708 if (path
.HasAdminDir(&sProjectRoot
) && !g_Git
.GetCurrentBranchFromFile(sProjectRoot
, sBranchName
))
710 if (sBranchName
.GetLength() == 40)
712 // if SHA1 only show 4 first bytes
714 for (int i
=0; i
<40; i
++)
715 if ( !iswxdigit(sBranchName
[i
]) )
721 sBranchName
= sBranchName
.Left(8) + _T("....");
725 if (sBranchName
.GetLength() > 64)
726 sBranchName
= sBranchName
.Left(64) + _T("...");
728 // scan to before "..."
729 LPTSTR s
= menutextbuffer
+ _tcslen(menutextbuffer
)-1;
730 if (s
> menutextbuffer
)
732 while (s
> menutextbuffer
)
747 // append branch name and end with ...
748 _tcscpy(s
, _T(" -> \"") + sBranchName
+ _T("\"..."));
752 if ((fullver
< 0x500)||(fullver
== 0x500 && !(uFlags
&~(CMF_RESERVED
|CMF_EXPLORE
))))
754 // on win2k, the context menu does not work properly if we use
755 // icon bitmaps. At least the menu text is empty in the context menu
756 // for folder backgrounds (seems like a win2k bug).
757 // the workaround is to use the check/unchecked bitmaps, which are drawn
758 // with AND raster op, but it's better than nothing at all
759 InsertMenu(menu
, pos
, MF_BYPOSITION
| MF_STRING
, id
, menutextbuffer
);
762 HBITMAP bmp
= IconToBitmap(icon
);
763 SetMenuItemBitmaps(menu
, pos
, MF_BYPOSITION
, bmp
, bmp
);
768 MENUITEMINFO menuiteminfo
;
769 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
770 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
771 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
772 menuiteminfo
.fType
= MFT_STRING
;
773 menuiteminfo
.dwTypeData
= menutextbuffer
;
776 menuiteminfo
.fMask
|= MIIM_BITMAP
;
777 menuiteminfo
.hbmpItem
= (fullver
>= 0x600) ? IconToBitmapPARGB32(icon
) : HBMMENU_CALLBACK
;
779 menuiteminfo
.wID
= id
;
780 InsertMenuItem(menu
, pos
, TRUE
, &menuiteminfo
);
785 //menu entry for the top context menu, so append an "Git " before
786 //the menu text to indicate where the entry comes from
787 _tcscpy_s(menutextbuffer
, 255, _T("Git "));
789 LoadString(g_hResInst
, stringid
, verbsbuffer
, sizeof(verbsbuffer
));
790 _tcscat_s(menutextbuffer
, 255, verbsbuffer
);
791 stdstring verb
= stdstring(menutextbuffer
);
792 if (verb
.find('&') != -1)
794 verb
.erase(verb
.find('&'),1);
796 myVerbsMap
[verb
] = id
- idCmdFirst
;
797 myVerbsMap
[verb
] = id
;
798 myVerbsIDMap
[id
- idCmdFirst
] = verb
;
799 myVerbsIDMap
[id
] = verb
;
800 // We store the relative and absolute diameter
801 // (drawitem callback uses absolute, others relative)
802 myIDMap
[id
- idCmdFirst
] = com
;
805 mySubMenuMap
[pos
] = com
;
808 HBITMAP
CShellExt::IconToBitmap(UINT uIcon
)
810 std::map
<UINT
, HBITMAP
>::iterator bitmap_it
= bitmaps
.lower_bound(uIcon
);
811 if (bitmap_it
!= bitmaps
.end() && bitmap_it
->first
== uIcon
)
812 return bitmap_it
->second
;
814 HICON hIcon
= (HICON
)LoadImage(g_hResInst
, MAKEINTRESOURCE(uIcon
), IMAGE_ICON
, 12, 12, LR_DEFAULTCOLOR
);
820 rect
.right
= ::GetSystemMetrics(SM_CXMENUCHECK
);
821 rect
.bottom
= ::GetSystemMetrics(SM_CYMENUCHECK
);
823 rect
.left
= rect
.top
= 0;
825 HWND desktop
= ::GetDesktopWindow();
832 HDC screen_dev
= ::GetDC(desktop
);
833 if (screen_dev
== NULL
)
839 // Create a compatible DC
840 HDC dst_hdc
= ::CreateCompatibleDC(screen_dev
);
844 ::ReleaseDC(desktop
, screen_dev
);
848 // Create a new bitmap of icon size
849 HBITMAP bmp
= ::CreateCompatibleBitmap(screen_dev
, rect
.right
, rect
.bottom
);
854 ::ReleaseDC(desktop
, screen_dev
);
858 // Select it into the compatible DC
859 HBITMAP old_dst_bmp
= (HBITMAP
)::SelectObject(dst_hdc
, bmp
);
860 if (old_dst_bmp
== NULL
)
866 // Fill the background of the compatible DC with the white color
867 // that is taken by menu routines as transparent
868 ::SetBkColor(dst_hdc
, RGB(255, 255, 255));
869 ::ExtTextOut(dst_hdc
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
871 // Draw the icon into the compatible DC
872 ::DrawIconEx(dst_hdc
, 0, 0, hIcon
, rect
.right
, rect
.bottom
, 0, NULL
, DI_NORMAL
);
875 ::SelectObject(dst_hdc
, old_dst_bmp
);
877 ::ReleaseDC(desktop
, screen_dev
);
880 bitmaps
.insert(bitmap_it
, std::make_pair(uIcon
, bmp
));
884 bool CShellExt::WriteClipboardPathsToTempFile(stdstring
& tempfile
)
887 tempfile
= stdstring();
888 //write all selected files and paths to a temporary file
889 //for TortoiseProc.exe to read out again.
891 DWORD pathlength
= GetTempPath(0, NULL
);
892 TCHAR
* path
= new TCHAR
[pathlength
+1];
893 TCHAR
* tempFile
= new TCHAR
[pathlength
+ 100];
894 GetTempPath (pathlength
+1, path
);
895 GetTempFileName (path
, _T("git"), 0, tempFile
);
896 tempfile
= stdstring(tempFile
);
898 HANDLE file
= ::CreateFile (tempFile
,
903 FILE_ATTRIBUTE_TEMPORARY
,
908 if (file
== INVALID_HANDLE_VALUE
)
911 if (!IsClipboardFormatAvailable(CF_HDROP
))
913 if (!OpenClipboard(NULL
))
916 stdstring sClipboardText
;
917 HGLOBAL hglb
= GetClipboardData(CF_HDROP
);
918 HDROP hDrop
= (HDROP
)GlobalLock(hglb
);
921 TCHAR szFileName
[MAX_PATH
];
922 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
923 for(UINT i
= 0; i
< cFiles
; ++i
)
925 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
926 stdstring filename
= szFileName
;
927 ::WriteFile (file
, filename
.c_str(), filename
.size()*sizeof(TCHAR
), &written
, 0);
928 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
941 stdstring
CShellExt::WriteFileListToTempFile()
943 //write all selected files and paths to a temporary file
944 //for TortoiseProc.exe to read out again.
945 DWORD pathlength
= GetTempPath(0, NULL
);
946 TCHAR
* path
= new TCHAR
[pathlength
+1];
947 TCHAR
* tempFile
= new TCHAR
[pathlength
+ 100];
948 GetTempPath (pathlength
+1, path
);
949 GetTempFileName (path
, _T("git"), 0, tempFile
);
950 stdstring retFilePath
= stdstring(tempFile
);
952 HANDLE file
= ::CreateFile (tempFile
,
957 FILE_ATTRIBUTE_TEMPORARY
,
962 if (file
== INVALID_HANDLE_VALUE
)
968 ::WriteFile (file
, folder_
.c_str(), folder_
.size()*sizeof(TCHAR
), &written
, 0);
969 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
972 for (std::vector
<stdstring
>::iterator I
= files_
.begin(); I
!= files_
.end(); ++I
)
974 ::WriteFile (file
, I
->c_str(), I
->size()*sizeof(TCHAR
), &written
, 0);
975 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
981 STDMETHODIMP
CShellExt::QueryDropContext(UINT uFlags
, UINT idCmdFirst
, HMENU hMenu
, UINT
&indexMenu
)
983 PreserveChdir preserveChdir
;
986 if ((uFlags
& CMF_DEFAULTONLY
)!=0)
987 return NOERROR
; //we don't change the default action
989 if ((files_
.size() == 0)||(folder_
.size() == 0))
992 if (((uFlags
& 0x000f)!=CMF_NORMAL
)&&(!(uFlags
& CMF_EXPLORE
))&&(!(uFlags
& CMF_VERBSONLY
)))
995 bool bSourceAndTargetFromSameRepository
= (uuidSource
.compare(uuidTarget
) == 0) || uuidSource
.empty() || uuidTarget
.empty();
997 //the drop handler only has eight commands, but not all are visible at the same time:
998 //if the source file(s) are under version control then those files can be moved
999 //to the new location or they can be moved with a rename,
1000 //if they are unversioned then they can be added to the working copy
1001 //if they are versioned, they also can be exported to an unversioned location
1002 UINT idCmd
= idCmdFirst
;
1005 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
1006 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINSVN
)&&((itemStates
& ITEMIS_INSVN
)&&((~itemStates
) & ITEMIS_ADDED
)))
1007 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPMOVEMENU
, 0, idCmdFirst
, ShellMenuDropMove
, uFlags
);
1009 // Git move and rename here
1010 // 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
1011 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINSVN
)&&(itemStates
& ITEMIS_INSVN
)&&(itemStates
& ITEMIS_ONLYONE
)&&((~itemStates
) & ITEMIS_ADDED
))
1012 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPMOVERENAMEMENU
, 0, idCmdFirst
, ShellMenuDropMoveRename
, uFlags
);
1015 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
1016 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINSVN
)&&(itemStates
& ITEMIS_INSVN
)&&((~itemStates
) & ITEMIS_ADDED
))
1017 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPCOPYMENU
, 0, idCmdFirst
, ShellMenuDropCopy
, uFlags
);
1019 // Git copy and rename here, source and target from same repository
1020 // available if source is a single, versioned but not added item, target is versioned or target folder is added
1021 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINSVN
)&&(itemStates
& ITEMIS_INSVN
)&&(itemStates
& ITEMIS_ONLYONE
)&&((~itemStates
) & ITEMIS_ADDED
))
1022 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPCOPYRENAMEMENU
, 0, idCmdFirst
, ShellMenuDropCopyRename
, uFlags
);
1025 // available if target is versioned and source is either unversioned or from another repository
1026 if ((itemStatesFolder
& ITEMIS_FOLDERINSVN
)&&(((~itemStates
) & ITEMIS_INSVN
)||!bSourceAndTargetFromSameRepository
))
1027 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPCOPYADDMENU
, 0, idCmdFirst
, ShellMenuDropCopyAdd
, uFlags
);
1030 // available if source is versioned and a folder
1031 if ((itemStates
& ITEMIS_INSVN
)&&(itemStates
& ITEMIS_FOLDER
))
1032 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPEXPORTMENU
, 0, idCmdFirst
, ShellMenuDropExport
, uFlags
);
1034 // Git export all here
1035 // available if source is versioned and a folder
1036 if ((itemStates
& ITEMIS_INSVN
)&&(itemStates
& ITEMIS_FOLDER
))
1037 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPEXPORTEXTENDEDMENU
, 0, idCmdFirst
, ShellMenuDropExportExtended
, uFlags
);
1040 // available if source is a patchfile
1041 if (itemStates
& ITEMIS_PATCHFILE
)
1042 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_MENUAPPLYPATCH
, 0, idCmdFirst
, ShellMenuApplyPatch
, uFlags
);
1045 if (idCmd
!= idCmdFirst
)
1046 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
);
1048 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS
, 0, (USHORT
)(idCmd
- idCmdFirst
)));
1051 STDMETHODIMP
CShellExt::QueryContextMenu(HMENU hMenu
,
1057 ATLTRACE("Shell :: QueryContextMenu\n");
1058 PreserveChdir preserveChdir
;
1060 //first check if our drop handler is called
1061 //and then (if true) provide the context menu for the
1063 if (m_State
== FileStateDropHandler
)
1065 return QueryDropContext(uFlags
, idCmdFirst
, hMenu
, indexMenu
);
1068 if ((uFlags
& CMF_DEFAULTONLY
)!=0)
1069 return NOERROR
; //we don't change the default action
1071 if ((files_
.size() == 0)&&(folder_
.size() == 0))
1074 if (((uFlags
& 0x000f)!=CMF_NORMAL
)&&(!(uFlags
& CMF_EXPLORE
))&&(!(uFlags
& CMF_VERBSONLY
)))
1081 CSIDL_COMMON_FAVORITES
,
1082 CSIDL_COMMON_STARTMENU
,
1083 CSIDL_COMPUTERSNEARME
,
1091 CSIDL_INTERNET_CACHE
,
1101 if (IsIllegalFolder(folder_
, csidlarray
))
1104 if (folder_
.empty())
1106 // folder is empty, but maybe files are selected
1107 if (files_
.size() == 0)
1108 return NOERROR
; // nothing selected - we don't have a menu to show
1109 // check whether a selected entry is an UID - those are namespace extensions
1110 // which we can't handle
1111 for (std::vector
<stdstring
>::const_iterator it
= files_
.begin(); it
!= files_
.end(); ++it
)
1113 if (_tcsncmp(it
->c_str(), _T("::{"), 3)==0)
1118 //check if our menu is requested for a subversion admin directory
1119 if (g_GitAdminDir
.IsAdminDirPath(folder_
.c_str()))
1122 if (uFlags
& CMF_EXTENDEDVERBS
)
1123 itemStates
|= ITEMIS_EXTENDED
;
1125 const BOOL bShortcut
= !!(uFlags
& CMF_VERBSONLY
);
1126 if ( bShortcut
&& (files_
.size()==1))
1128 // Don't show the context menu for a link if the
1129 // destination is not part of a working copy.
1130 // It would only show the standard menu items
1131 // which are already shown for the lnk-file.
1132 CString path
= files_
.front().c_str();
1133 if ( !g_GitAdminDir
.HasAdminDir(path
) )
1139 //check if we already added our menu entry for a folder.
1140 //we check that by iterating through all menu entries and check if
1141 //the dwItemData member points to our global ID string. That string is set
1142 //by our shell extension when the folder menu is inserted.
1143 TCHAR menubuf
[MAX_PATH
];
1144 int count
= GetMenuItemCount(hMenu
);
1145 for (int i
=0; i
<count
; ++i
)
1148 SecureZeroMemory(&miif
, sizeof(MENUITEMINFO
));
1149 miif
.cbSize
= sizeof(MENUITEMINFO
);
1150 miif
.fMask
= MIIM_DATA
;
1151 miif
.dwTypeData
= menubuf
;
1152 miif
.cch
= sizeof(menubuf
)/sizeof(TCHAR
);
1153 GetMenuItemInfo(hMenu
, i
, TRUE
, &miif
);
1154 if (miif
.dwItemData
== (ULONG_PTR
)g_MenuIDString
)
1159 UINT idCmd
= idCmdFirst
;
1161 //create the sub menu
1162 HMENU subMenu
= CreateMenu();
1163 int indexSubMenu
= 0;
1165 unsigned __int64 topmenu
= g_ShellCache
.GetMenuLayout();
1166 unsigned __int64 menumask
= g_ShellCache
.GetMenuMask();
1169 bool bAddSeparator
= false;
1170 bool bMenuEntryAdded
= false;
1171 bool bMenuEmpty
= true;
1172 // insert separator at start
1173 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
); idCmd
++;
1174 bool bShowIcons
= !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE
));
1175 // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up
1176 /*if (fullver <= 0x500)
1177 bShowIcons = false;*/
1180 if (itemStates
& (ITEMIS_INSVN
|ITEMIS_FOLDERINSVN
))
1182 // show current branch name (as a "read-only" menu entry)
1184 CTGitPath
path(folder_
.empty() ? files_
.front().c_str() : folder_
.c_str());
1185 CString sProjectRoot
;
1186 CString sBranchName
;
1188 if (path
.HasAdminDir(&sProjectRoot
) && !g_Git
.GetCurrentBranchFromFile(sProjectRoot
, sBranchName
))
1190 if (sBranchName
.GetLength() == 40)
1192 // if SHA1 only show 4 first bytes
1193 BOOL bIsSha1
= TRUE
;
1194 for (int i
=0; i
<40; i
++)
1195 if ( !iswxdigit(sBranchName
[i
]) )
1201 sBranchName
= sBranchName
.Left(8) + _T("....");
1204 sBranchName
= _T('"') + sBranchName
+ _T('"');
1206 const int icon
= IDI_COPY
;
1207 const int pos
= indexMenu
++;
1208 const int id
= idCmd
++;
1210 if ((fullver
< 0x500)||(fullver
== 0x500 && !(uFlags
&~(CMF_RESERVED
|CMF_EXPLORE
))))
1212 InsertMenu(hMenu
, pos
, MF_DISABLED
|MF_GRAYED
|MF_BYPOSITION
|MF_STRING
, id
, sBranchName
);
1213 HBITMAP bmp
= IconToBitmap(icon
);
1214 SetMenuItemBitmaps(hMenu
, pos
, MF_BYPOSITION
, bmp
, bmp
);
1218 MENUITEMINFO menuiteminfo
;
1219 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
1220 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
1221 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
| MIIM_STATE
;
1222 menuiteminfo
.fState
= MFS_DISABLED
;
1223 menuiteminfo
.fType
= MFT_STRING
;
1224 menuiteminfo
.dwTypeData
= (LPWSTR
)sBranchName
.GetString();
1227 menuiteminfo
.fMask
|= MIIM_BITMAP
;
1228 menuiteminfo
.hbmpItem
= (fullver
>= 0x600) ? IconToBitmapPARGB32(icon
) : HBMMENU_CALLBACK
;
1230 if (menuiteminfo
.hbmpItem
== HBMMENU_CALLBACK
)
1232 // WM_DRAWITEM uses myIDMap to get icon, we use the same icon as create branch
1233 myIDMap
[id
- idCmdFirst
] = ShellMenuBranch
;
1234 myIDMap
[id
] = ShellMenuBranch
;
1237 menuiteminfo
.wID
= id
;
1238 InsertMenuItem(hMenu
, pos
, TRUE
, &menuiteminfo
);
1244 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
1246 if (menuInfo
[menuIndex
].command
== ShellSeparator
)
1248 // we don't add a separator immediately. Because there might not be
1249 // another 'normal' menu entry after we insert a separator.
1250 // we simply set a flag here, indicating that before the next
1251 // 'normal' menu entry, a separator should be added.
1253 bAddSeparator
= true;
1257 // check the conditions whether to show the menu entry or not
1258 bool bInsertMenu
= false;
1260 if (menuInfo
[menuIndex
].firstyes
&& menuInfo
[menuIndex
].firstno
)
1262 if (((menuInfo
[menuIndex
].firstyes
& itemStates
) == menuInfo
[menuIndex
].firstyes
)
1264 ((menuInfo
[menuIndex
].firstno
& (~itemStates
)) == menuInfo
[menuIndex
].firstno
))
1267 else if ((menuInfo
[menuIndex
].firstyes
)&&((menuInfo
[menuIndex
].firstyes
& itemStates
) == menuInfo
[menuIndex
].firstyes
))
1269 else if ((menuInfo
[menuIndex
].firstno
)&&((menuInfo
[menuIndex
].firstno
& (~itemStates
)) == menuInfo
[menuIndex
].firstno
))
1272 if (menuInfo
[menuIndex
].secondyes
&& menuInfo
[menuIndex
].secondno
)
1274 if (((menuInfo
[menuIndex
].secondyes
& itemStates
) == menuInfo
[menuIndex
].secondyes
)
1276 ((menuInfo
[menuIndex
].secondno
& (~itemStates
)) == menuInfo
[menuIndex
].secondno
))
1279 else if ((menuInfo
[menuIndex
].secondyes
)&&((menuInfo
[menuIndex
].secondyes
& itemStates
) == menuInfo
[menuIndex
].secondyes
))
1281 else if ((menuInfo
[menuIndex
].secondno
)&&((menuInfo
[menuIndex
].secondno
& (~itemStates
)) == menuInfo
[menuIndex
].secondno
))
1284 if (menuInfo
[menuIndex
].thirdyes
&& menuInfo
[menuIndex
].thirdno
)
1286 if (((menuInfo
[menuIndex
].thirdyes
& itemStates
) == menuInfo
[menuIndex
].thirdyes
)
1288 ((menuInfo
[menuIndex
].thirdno
& (~itemStates
)) == menuInfo
[menuIndex
].thirdno
))
1291 else if ((menuInfo
[menuIndex
].thirdyes
)&&((menuInfo
[menuIndex
].thirdyes
& itemStates
) == menuInfo
[menuIndex
].thirdyes
))
1293 else if ((menuInfo
[menuIndex
].thirdno
)&&((menuInfo
[menuIndex
].thirdno
& (~itemStates
)) == menuInfo
[menuIndex
].thirdno
))
1296 if (menuInfo
[menuIndex
].fourthyes
&& menuInfo
[menuIndex
].fourthno
)
1298 if (((menuInfo
[menuIndex
].fourthyes
& itemStates
) == menuInfo
[menuIndex
].fourthyes
)
1300 ((menuInfo
[menuIndex
].fourthno
& (~itemStates
)) == menuInfo
[menuIndex
].fourthno
))
1303 else if ((menuInfo
[menuIndex
].fourthyes
)&&((menuInfo
[menuIndex
].fourthyes
& itemStates
) == menuInfo
[menuIndex
].fourthyes
))
1305 else if ((menuInfo
[menuIndex
].fourthno
)&&((menuInfo
[menuIndex
].fourthno
& (~itemStates
)) == menuInfo
[menuIndex
].fourthno
))
1308 if (menuInfo
[menuIndex
].menuID
& (~menumask
))
1312 // insert a separator
1313 if ((bMenuEntryAdded
)&&(bAddSeparator
))
1315 bAddSeparator
= false;
1316 bMenuEntryAdded
= false;
1317 InsertMenu(subMenu
, indexSubMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
);
1321 // handle special cases (sub menus)
1322 if ((menuInfo
[menuIndex
].command
== ShellMenuIgnoreSub
)||(menuInfo
[menuIndex
].command
== ShellMenuUnIgnoreSub
))
1324 InsertIgnoreSubmenus(idCmd
, idCmdFirst
, hMenu
, subMenu
, indexMenu
, indexSubMenu
, topmenu
, bShowIcons
, uFlags
);
1325 bMenuEntryAdded
= true;
1330 bool bIsTop
= ((topmenu
& menuInfo
[menuIndex
].menuID
) != 0);
1332 // insert the menu entry
1333 InsertGitMenu( bIsTop
,
1334 bIsTop
? hMenu
: subMenu
,
1335 bIsTop
? indexMenu
++ : indexSubMenu
++,
1337 menuInfo
[menuIndex
].menuTextID
,
1338 bShowIcons
? menuInfo
[menuIndex
].iconID
: 0,
1340 menuInfo
[menuIndex
].command
,
1344 bMenuEntryAdded
= true;
1354 //add sub menu to main context menu
1355 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
1356 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
1357 MAKESTRING(IDS_MENUSUBMENU
);
1358 MENUITEMINFO menuiteminfo
;
1359 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
1360 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
1361 menuiteminfo
.fType
= MFT_STRING
;
1362 menuiteminfo
.dwTypeData
= stringtablebuffer
;
1364 UINT uIcon
= bShowIcons
? IDI_APP
: 0;
1367 uIcon
= bShowIcons
? IDI_MENUFOLDER
: 0;
1368 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuFolder
;
1369 myIDMap
[idCmd
] = ShellSubMenuFolder
;
1370 menuiteminfo
.dwItemData
= (ULONG_PTR
)g_MenuIDString
;
1372 else if (!bShortcut
&& (files_
.size()==1))
1374 uIcon
= bShowIcons
? IDI_MENUFILE
: 0;
1375 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuFile
;
1376 myIDMap
[idCmd
] = ShellSubMenuFile
;
1378 else if (bShortcut
&& (files_
.size()==1))
1380 uIcon
= bShowIcons
? IDI_MENULINK
: 0;
1381 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuLink
;
1382 myIDMap
[idCmd
] = ShellSubMenuLink
;
1384 else if (files_
.size() > 1)
1386 uIcon
= bShowIcons
? IDI_MENUMULTIPLE
: 0;
1387 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuMultiple
;
1388 myIDMap
[idCmd
] = ShellSubMenuMultiple
;
1392 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenu
;
1393 myIDMap
[idCmd
] = ShellSubMenu
;
1396 if ((fullver
< 0x500)||(fullver
== 0x500 && !(uFlags
&~(CMF_RESERVED
|CMF_EXPLORE
))))
1398 menuiteminfo
.fMask
= MIIM_STRING
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
;
1401 menuiteminfo
.fMask
|= MIIM_CHECKMARKS
;
1402 bmp
= IconToBitmap(uIcon
);
1403 menuiteminfo
.hbmpChecked
= bmp
;
1404 menuiteminfo
.hbmpUnchecked
= bmp
;
1409 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
| MIIM_STRING
;
1412 menuiteminfo
.fMask
|= MIIM_BITMAP
;
1413 menuiteminfo
.hbmpItem
= (fullver
>= 0x600) ? IconToBitmapPARGB32(uIcon
) : HBMMENU_CALLBACK
;
1416 menuiteminfo
.hSubMenu
= subMenu
;
1417 menuiteminfo
.wID
= idCmd
++;
1418 InsertMenuItem(hMenu
, indexMenu
++, TRUE
, &menuiteminfo
);
1421 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
); idCmd
++;
1423 //return number of menu items added
1424 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS
, 0, (USHORT
)(idCmd
- idCmdFirst
)));
1428 // This is called when you invoke a command on the menu:
1429 STDMETHODIMP
CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi
)
1431 PreserveChdir preserveChdir
;
1432 HRESULT hr
= E_INVALIDARG
;
1436 std::string command
;
1440 if ((files_
.size() > 0)||(folder_
.size() > 0))
1442 UINT idCmd
= LOWORD(lpcmi
->lpVerb
);
1444 if (HIWORD(lpcmi
->lpVerb
))
1446 stdstring verb
= stdstring(MultibyteToWide(lpcmi
->lpVerb
));
1447 std::map
<stdstring
, UINT_PTR
>::const_iterator verb_it
= myVerbsMap
.lower_bound(verb
);
1448 if (verb_it
!= myVerbsMap
.end() && verb_it
->first
== verb
)
1449 idCmd
= verb_it
->second
;
1454 // See if we have a handler interface for this id
1455 std::map
<UINT_PTR
, UINT_PTR
>::const_iterator id_it
= myIDMap
.lower_bound(idCmd
);
1456 if (id_it
!= myIDMap
.end() && id_it
->first
== idCmd
)
1458 STARTUPINFO startup
;
1459 PROCESS_INFORMATION process
;
1460 memset(&startup
, 0, sizeof(startup
));
1461 startup
.cb
= sizeof(startup
);
1462 memset(&process
, 0, sizeof(process
));
1463 CRegStdString
tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE
);
1464 CRegStdString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE
);
1466 //TortoiseProc expects a command line of the form:
1467 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
1469 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
1471 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
1472 //* pathfile is a path to a temporary file which contains a list of file paths
1473 stdstring svnCmd
= _T(" /command:");
1475 switch (id_it
->second
)
1478 case ShellMenuCheckout
:
1479 svnCmd
+= _T("checkout /path:\"");
1483 case ShellMenuUpdate
:
1484 tempfile
= WriteFileListToTempFile();
1485 svnCmd
+= _T("update /pathfile:\"");
1488 svnCmd
+= _T(" /deletepathfile");
1490 case ShellMenuUpdateExt
:
1491 tempfile
= WriteFileListToTempFile();
1492 svnCmd
+= _T("subupdate /pathfile:\"");
1495 svnCmd
+= _T(" /deletepathfile");
1496 svnCmd
+= _T(" /bkpath:");
1499 case ShellMenuCommit
:
1500 tempfile
= WriteFileListToTempFile();
1501 svnCmd
+= _T("commit /pathfile:\"");
1504 svnCmd
+= _T(" /deletepathfile");
1507 case ShellMenuAddAsReplacement
:
1508 tempfile
= WriteFileListToTempFile();
1509 svnCmd
+= _T("add /pathfile:\"");
1512 svnCmd
+= _T(" /deletepathfile");
1514 case ShellMenuIgnore
:
1515 tempfile
= WriteFileListToTempFile();
1516 svnCmd
+= _T("ignore /pathfile:\"");
1519 svnCmd
+= _T(" /deletepathfile");
1521 case ShellMenuIgnoreCaseSensitive
:
1522 tempfile
= WriteFileListToTempFile();
1523 svnCmd
+= _T("ignore /pathfile:\"");
1526 svnCmd
+= _T(" /deletepathfile");
1527 svnCmd
+= _T(" /onlymask");
1529 case ShellMenuUnIgnore
:
1530 tempfile
= WriteFileListToTempFile();
1531 svnCmd
+= _T("unignore /pathfile:\"");
1534 svnCmd
+= _T(" /deletepathfile");
1536 case ShellMenuUnIgnoreCaseSensitive
:
1537 tempfile
= WriteFileListToTempFile();
1538 svnCmd
+= _T("unignore /pathfile:\"");
1541 svnCmd
+= _T(" /deletepathfile");
1542 svnCmd
+= _T(" /onlymask");
1544 case ShellMenuRevert
:
1545 tempfile
= WriteFileListToTempFile();
1546 svnCmd
+= _T("revert /pathfile:\"");
1549 svnCmd
+= _T(" /deletepathfile");
1551 case ShellMenuDelUnversioned
:
1552 svnCmd
+= _T("delunversioned /path:\"");
1556 case ShellMenuCleanup
:
1557 tempfile
= WriteFileListToTempFile();
1558 svnCmd
+= _T("cleanup /pathfile:\"");
1561 svnCmd
+= _T(" /deletepathfile");
1563 case ShellMenuResolve
:
1564 tempfile
= WriteFileListToTempFile();
1565 svnCmd
+= _T("resolve /pathfile:\"");
1568 svnCmd
+= _T(" /deletepathfile");
1570 case ShellMenuSwitch
:
1571 svnCmd
+= _T("switch /path:\"");
1572 if (files_
.size() > 0)
1573 svnCmd
+= files_
.front();
1578 case ShellMenuImport
:
1579 svnCmd
+= _T("import /path:\"");
1583 case ShellMenuExport
:
1584 svnCmd
+= _T("export /path:\"");
1588 case ShellMenuAbout
:
1589 svnCmd
+= _T("about");
1591 case ShellMenuCreateRepos
:
1592 svnCmd
+= _T("repocreate /path:\"");
1596 case ShellMenuMerge
:
1597 svnCmd
+= _T("merge /path:\"");
1598 if (files_
.size() > 0)
1599 svnCmd
+= files_
.front();
1604 case ShellMenuMergeAll
:
1605 svnCmd
+= _T("mergeall /path:\"");
1606 if (files_
.size() > 0)
1607 svnCmd
+= files_
.front();
1613 svnCmd
+= _T("copy /path:\"");
1614 if (files_
.size() > 0)
1615 svnCmd
+= files_
.front();
1620 case ShellMenuSettings
:
1621 svnCmd
+= _T("settings");
1624 svnCmd
+= _T("help");
1626 case ShellMenuRename
:
1627 svnCmd
+= _T("rename /path:\"");
1628 if (files_
.size() > 0)
1629 svnCmd
+= files_
.front();
1634 case ShellMenuRemove
:
1635 tempfile
= WriteFileListToTempFile();
1636 svnCmd
+= _T("remove /pathfile:\"");
1639 svnCmd
+= _T(" /deletepathfile");
1641 case ShellMenuRemoveKeep
:
1642 tempfile
= WriteFileListToTempFile();
1643 svnCmd
+= _T("remove /pathfile:\"");
1646 svnCmd
+= _T(" /deletepathfile");
1647 svnCmd
+= _T(" /keep");
1650 svnCmd
+= _T("diff /path:\"");
1651 if (files_
.size() == 1)
1652 svnCmd
+= files_
.front();
1653 else if (files_
.size() == 2)
1655 std::vector
<stdstring
>::iterator I
= files_
.begin();
1658 svnCmd
+= _T("\" /path2:\"");
1664 if (GetAsyncKeyState(VK_SHIFT
) & 0x8000)
1665 svnCmd
+= _T(" /alternative");
1667 case ShellMenuPrevDiff
:
1668 svnCmd
+= _T("prevdiff /path:\"");
1669 if (files_
.size() == 1)
1670 svnCmd
+= files_
.front();
1674 if (GetAsyncKeyState(VK_SHIFT
) & 0x8000)
1675 svnCmd
+= _T(" /alternative");
1677 case ShellMenuUrlDiff
:
1678 svnCmd
+= _T("urldiff /path:\"");
1679 if (files_
.size() == 1)
1680 svnCmd
+= files_
.front();
1685 case ShellMenuDropCopyAdd
:
1686 tempfile
= WriteFileListToTempFile();
1687 svnCmd
+= _T("dropcopyadd /pathfile:\"");
1690 svnCmd
+= _T(" /deletepathfile");
1691 svnCmd
+= _T(" /droptarget:\"");
1695 case ShellMenuDropCopy
:
1696 tempfile
= WriteFileListToTempFile();
1697 svnCmd
+= _T("dropcopy /pathfile:\"");
1700 svnCmd
+= _T(" /deletepathfile");
1701 svnCmd
+= _T(" /droptarget:\"");
1705 case ShellMenuDropCopyRename
:
1706 tempfile
= WriteFileListToTempFile();
1707 svnCmd
+= _T("dropcopy /pathfile:\"");
1710 svnCmd
+= _T(" /deletepathfile");
1711 svnCmd
+= _T(" /droptarget:\"");
1713 svnCmd
+= _T("\" /rename";)
1715 case ShellMenuDropMove
:
1716 tempfile
= WriteFileListToTempFile();
1717 svnCmd
+= _T("dropmove /pathfile:\"");
1720 svnCmd
+= _T(" /deletepathfile");
1721 svnCmd
+= _T(" /droptarget:\"");
1725 case ShellMenuDropMoveRename
:
1726 tempfile
= WriteFileListToTempFile();
1727 svnCmd
+= _T("dropmove /pathfile:\"");
1730 svnCmd
+= _T(" /deletepathfile");
1731 svnCmd
+= _T(" /droptarget:\"");
1733 svnCmd
+= _T("\" /rename";)
1735 case ShellMenuDropExport
:
1736 tempfile
= WriteFileListToTempFile();
1737 svnCmd
+= _T("dropexport /pathfile:\"");
1740 svnCmd
+= _T(" /deletepathfile");
1741 svnCmd
+= _T(" /droptarget:\"");
1745 case ShellMenuDropExportExtended
:
1746 tempfile
= WriteFileListToTempFile();
1747 svnCmd
+= _T("dropexport /pathfile:\"");
1750 svnCmd
+= _T(" /deletepathfile");
1751 svnCmd
+= _T(" /droptarget:\"");
1754 svnCmd
+= _T(" /extended");
1757 svnCmd
+= _T("log /path:\"");
1758 if (files_
.size() > 0)
1759 svnCmd
+= files_
.front();
1764 case ShellMenuConflictEditor
:
1765 svnCmd
+= _T("conflicteditor /path:\"");
1766 if (files_
.size() > 0)
1767 svnCmd
+= files_
.front();
1772 case ShellMenuRelocate
:
1773 svnCmd
+= _T("relocate /path:\"");
1774 if (files_
.size() > 0)
1775 svnCmd
+= files_
.front();
1780 case ShellMenuRebase
:
1781 svnCmd
+= _T("rebase /path:\"");
1782 if (files_
.size() > 0)
1783 svnCmd
+= files_
.front();
1788 case ShellMenuShowChanged
:
1789 if (files_
.size() > 1)
1791 tempfile
= WriteFileListToTempFile();
1792 svnCmd
+= _T("repostatus /pathfile:\"");
1795 svnCmd
+= _T(" /deletepathfile");
1799 svnCmd
+= _T("repostatus /path:\"");
1800 if (files_
.size() > 0)
1801 svnCmd
+= files_
.front();
1807 case ShellMenuRefLog
:
1808 svnCmd
+= _T("reflog /path:\"");
1809 if (files_
.size() > 0)
1810 svnCmd
+= files_
.front();
1816 case ShellMenuStashSave
:
1817 svnCmd
+= _T("stashsave /path:\"");
1818 if (files_
.size() > 0)
1819 svnCmd
+= files_
.front();
1825 case ShellMenuStashApply
:
1826 svnCmd
+= _T("stashapply /path:\"");
1827 if (files_
.size() > 0)
1828 svnCmd
+= files_
.front();
1834 case ShellMenuStashList
:
1835 svnCmd
+= _T("reflog /path:\"");
1836 if (files_
.size() > 0)
1837 svnCmd
+= files_
.front();
1840 svnCmd
+= _T("\" /ref:refs/stash");
1843 case ShellMenuSubAdd
:
1844 svnCmd
+= _T("subadd /path:\"");
1845 if (files_
.size() > 0)
1846 svnCmd
+= files_
.front();
1852 case ShellMenuBlame
:
1853 svnCmd
+= _T("blame /path:\"");
1854 if (files_
.size() > 0)
1855 svnCmd
+= files_
.front();
1860 case ShellMenuCreatePatch
:
1861 tempfile
= WriteFileListToTempFile();
1862 svnCmd
+= _T("createpatch /pathfile:\"");
1865 svnCmd
+= _T(" /deletepathfile");
1867 case ShellMenuApplyPatch
:
1868 if ((itemStates
& ITEMIS_PATCHINCLIPBOARD
) && ((~itemStates
) & ITEMIS_PATCHFILE
))
1870 // if there's a patch file in the clipboard, we save it
1871 // to a temporary file and tell TortoiseMerge to use that one
1872 UINT cFormat
= RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
1873 if ((cFormat
)&&(OpenClipboard(NULL
)))
1875 HGLOBAL hglb
= GetClipboardData(cFormat
);
1876 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1878 DWORD len
= GetTempPath(0, NULL
);
1879 TCHAR
* path
= new TCHAR
[len
+1];
1880 TCHAR
* tempF
= new TCHAR
[len
+100];
1881 GetTempPath (len
+1, path
);
1882 GetTempFileName (path
, TEXT("git"), 0, tempF
);
1883 std::wstring sTempFile
= std::wstring(tempF
);
1888 size_t patchlen
= strlen(lpstr
);
1889 _tfopen_s(&outFile
, sTempFile
.c_str(), _T("wb"));
1892 size_t size
= fwrite(lpstr
, sizeof(char), patchlen
, outFile
);
1893 if (size
== patchlen
)
1895 itemStates
|= ITEMIS_PATCHFILE
;
1897 files_
.push_back(sTempFile
);
1905 if (itemStates
& ITEMIS_PATCHFILE
)
1907 svnCmd
= _T(" /diff:\"");
1908 if (files_
.size() > 0)
1910 svnCmd
+= files_
.front();
1911 if (itemStatesFolder
& ITEMIS_FOLDERINSVN
)
1913 svnCmd
+= _T("\" /patchpath:\"");
1919 if (itemStates
& ITEMIS_INVERSIONEDFOLDER
)
1920 svnCmd
+= _T("\" /wc");
1926 svnCmd
= _T(" /patchpath:\"");
1927 if (files_
.size() > 0)
1928 svnCmd
+= files_
.front();
1934 myVerbsIDMap
.clear();
1936 if (CreateProcess(((stdstring
)tortoiseMergePath
).c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
)==0)
1939 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1940 FORMAT_MESSAGE_FROM_SYSTEM
|
1941 FORMAT_MESSAGE_IGNORE_INSERTS
,
1944 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
1949 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, _T("TortoiseMerge launch failed"), MB_OK
| MB_ICONINFORMATION
);
1950 LocalFree( lpMsgBuf
);
1952 CloseHandle(process
.hThread
);
1953 CloseHandle(process
.hProcess
);
1956 case ShellMenuRevisionGraph
:
1957 svnCmd
+= _T("revisiongraph /path:\"");
1958 if (files_
.size() > 0)
1959 svnCmd
+= files_
.front();
1964 case ShellMenuProperties
:
1965 tempfile
= WriteFileListToTempFile();
1966 svnCmd
+= _T("properties /pathfile:\"");
1969 svnCmd
+= _T(" /deletepathfile");
1971 case ShellMenuClipPaste
:
1972 if (WriteClipboardPathsToTempFile(tempfile
))
1975 UINT cPrefDropFormat
= RegisterClipboardFormat(_T("Preferred DropEffect"));
1976 if (cPrefDropFormat
)
1978 if (OpenClipboard(lpcmi
->hwnd
))
1980 HGLOBAL hglb
= GetClipboardData(cPrefDropFormat
);
1983 DWORD
* effect
= (DWORD
*) GlobalLock(hglb
);
1984 if (*effect
== DROPEFFECT_MOVE
)
1993 svnCmd
+= _T("pastecopy /pathfile:\"");
1995 svnCmd
+= _T("pastemove /pathfile:\"");
1998 svnCmd
+= _T(" /deletepathfile");
1999 svnCmd
+= _T(" /droptarget:\"");
2003 else return NOERROR
;
2005 case ShellMenuClone
:
2006 svnCmd
+= _T("clone /path:\"");
2011 svnCmd
+= _T("pull /path:\"");
2012 if (files_
.size() > 0)
2013 svnCmd
+= files_
.front();
2019 svnCmd
+= _T("push /path:\"");
2020 if (files_
.size() > 0)
2021 svnCmd
+= files_
.front();
2026 case ShellMenuBranch
:
2027 svnCmd
+= _T("branch /path:\"");
2028 if (files_
.size() > 0)
2029 svnCmd
+= files_
.front();
2036 svnCmd
+= _T("tag /path:\"");
2037 if (files_
.size() > 0)
2038 svnCmd
+= files_
.front();
2044 case ShellMenuFormatPatch
:
2045 svnCmd
+= _T("formatpatch /path:\"");
2046 if (files_
.size() > 0)
2047 svnCmd
+= files_
.front();
2053 case ShellMenuImportPatch
:
2054 svnCmd
+= _T("importpatch /path:\"");
2055 if (files_
.size() > 0)
2056 svnCmd
+= files_
.front();
2062 case ShellMenuCherryPick
:
2063 svnCmd
+= _T("cherrypick /path:\"");
2064 if (files_
.size() > 0)
2065 svnCmd
+= files_
.front();
2070 case ShellMenuFetch
:
2071 svnCmd
+= _T("fetch /path:\"");
2072 if (files_
.size() > 0)
2073 svnCmd
+= files_
.front();
2082 } // switch (id_it->second)
2083 svnCmd
+= _T(" /hwnd:");
2085 _stprintf_s(buf
, 30, _T("%d"), lpcmi
->hwnd
);
2088 myVerbsIDMap
.clear();
2090 if (CreateProcess(((stdstring
)tortoiseProcPath
).c_str(), const_cast<TCHAR
*>(svnCmd
.c_str()), NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
)==0)
2093 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
2094 FORMAT_MESSAGE_FROM_SYSTEM
|
2095 FORMAT_MESSAGE_IGNORE_INSERTS
,
2098 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
2103 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, _T("TortoiseProc Launch failed"), MB_OK
| MB_ICONINFORMATION
);
2104 LocalFree( lpMsgBuf
);
2106 CloseHandle(process
.hThread
);
2107 CloseHandle(process
.hProcess
);
2109 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
2110 } // if ((files_.size() > 0)||(folder_.size() > 0))
2115 // This is for the status bar and things like that:
2116 STDMETHODIMP
CShellExt::GetCommandString(UINT_PTR idCmd
,
2118 UINT FAR
* /*reserved*/,
2122 PreserveChdir preserveChdir
;
2123 //do we know the id?
2124 std::map
<UINT_PTR
, UINT_PTR
>::const_iterator id_it
= myIDMap
.lower_bound(idCmd
);
2125 if (id_it
== myIDMap
.end() || id_it
->first
!= idCmd
)
2127 return E_INVALIDARG
; //no, we don't
2131 HRESULT hr
= E_INVALIDARG
;
2133 MAKESTRING(IDS_MENUDESCDEFAULT
);
2135 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
2137 if (menuInfo
[menuIndex
].command
== (GitCommands
)id_it
->second
)
2139 MAKESTRING(menuInfo
[menuIndex
].menuDescID
);
2145 const TCHAR
* desc
= stringtablebuffer
;
2150 std::string help
= WideToMultibyte(desc
);
2151 lstrcpynA(pszName
, help
.c_str(), cchMax
);
2157 wide_string help
= desc
;
2158 lstrcpynW((LPWSTR
)pszName
, help
.c_str(), cchMax
);
2164 std::map
<UINT_PTR
, stdstring
>::const_iterator verb_id_it
= myVerbsIDMap
.lower_bound(idCmd
);
2165 if (verb_id_it
!= myVerbsIDMap
.end() && verb_id_it
->first
== idCmd
)
2167 std::string help
= WideToMultibyte(verb_id_it
->second
);
2168 lstrcpynA(pszName
, help
.c_str(), cchMax
);
2175 std::map
<UINT_PTR
, stdstring
>::const_iterator verb_id_it
= myVerbsIDMap
.lower_bound(idCmd
);
2176 if (verb_id_it
!= myVerbsIDMap
.end() && verb_id_it
->first
== idCmd
)
2178 wide_string help
= verb_id_it
->second
;
2179 ATLTRACE("verb : %ws\n", help
.c_str());
2180 lstrcpynW((LPWSTR
)pszName
, help
.c_str(), cchMax
);
2189 STDMETHODIMP
CShellExt::HandleMenuMsg(UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2192 return HandleMenuMsg2(uMsg
, wParam
, lParam
, &res
);
2195 STDMETHODIMP
CShellExt::HandleMenuMsg2(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
)
2197 PreserveChdir preserveChdir
;
2200 if (pResult
== NULL
)
2207 case WM_MEASUREITEM
:
2209 MEASUREITEMSTRUCT
* lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2210 if (lpmis
==NULL
||lpmis
->CtlType
!=ODT_MENU
)
2212 lpmis
->itemWidth
+= 2;
2213 if (lpmis
->itemHeight
< 16)
2214 lpmis
->itemHeight
= 16;
2221 DRAWITEMSTRUCT
* lpdis
= (DRAWITEMSTRUCT
*)lParam
;
2222 if ((lpdis
==NULL
)||(lpdis
->CtlType
!= ODT_MENU
))
2223 return S_OK
; //not for a menu
2224 resource
= GetMenuTextFromResource(myIDMap
[lpdis
->itemID
]);
2225 if (resource
== NULL
)
2227 HICON hIcon
= (HICON
)LoadImage(g_hResInst
, resource
, IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
2230 DrawIconEx(lpdis
->hDC
,
2231 lpdis
->rcItem
.left
- 16,
2232 lpdis
->rcItem
.top
+ (lpdis
->rcItem
.bottom
- lpdis
->rcItem
.top
- 16) / 2,
2234 0, NULL
, DI_NORMAL
);
2243 if (HIWORD(wParam
) != MF_POPUP
)
2245 int nChar
= LOWORD(wParam
);
2246 if (_istascii((wint_t)nChar
) && _istupper((wint_t)nChar
))
2247 nChar
= tolower(nChar
);
2248 // we have the char the user pressed, now search that char in all our
2250 std::vector
<int> accmenus
;
2251 for (std::map
<UINT_PTR
, UINT_PTR
>::iterator It
= mySubMenuMap
.begin(); It
!= mySubMenuMap
.end(); ++It
)
2253 resource
= GetMenuTextFromResource(mySubMenuMap
[It
->first
]);
2254 if (resource
== NULL
)
2256 szItem
= stringtablebuffer
;
2257 TCHAR
* amp
= _tcschr(szItem
, '&');
2261 int ampChar
= LOWORD(*amp
);
2262 if (_istascii((wint_t)ampChar
) && _istupper((wint_t)ampChar
))
2263 ampChar
= tolower(ampChar
);
2264 if (ampChar
== nChar
)
2266 // yep, we found a menu which has the pressed key
2267 // as an accelerator. Add that menu to the list to
2269 accmenus
.push_back(It
->first
);
2272 if (accmenus
.size() == 0)
2274 // no menu with that accelerator key.
2275 *pResult
= MAKELONG(0, MNC_IGNORE
);
2278 if (accmenus
.size() == 1)
2280 // Only one menu with that accelerator key. We're lucky!
2281 // So just execute that menu entry.
2282 *pResult
= MAKELONG(accmenus
[0], MNC_EXECUTE
);
2285 if (accmenus
.size() > 1)
2287 // we have more than one menu item with this accelerator key!
2289 mif
.cbSize
= sizeof(MENUITEMINFO
);
2290 mif
.fMask
= MIIM_STATE
;
2291 for (std::vector
<int>::iterator it
= accmenus
.begin(); it
!= accmenus
.end(); ++it
)
2293 GetMenuItemInfo((HMENU
)lParam
, *it
, TRUE
, &mif
);
2294 if (mif
.fState
== MFS_HILITE
)
2296 // this is the selected item, so select the next one
2298 if (it
== accmenus
.end())
2299 *pResult
= MAKELONG(accmenus
[0], MNC_SELECT
);
2301 *pResult
= MAKELONG(*it
, MNC_SELECT
);
2305 *pResult
= MAKELONG(accmenus
[0], MNC_SELECT
);
2316 LPCTSTR
CShellExt::GetMenuTextFromResource(int id
)
2319 LPCTSTR resource
= NULL
;
2320 unsigned __int64 layout
= g_ShellCache
.GetMenuLayout();
2324 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
2326 if (menuInfo
[menuIndex
].command
== id
)
2328 MAKESTRING(menuInfo
[menuIndex
].menuTextID
);
2329 resource
= MAKEINTRESOURCE(menuInfo
[menuIndex
].iconID
);
2332 case ShellSubMenuMultiple
:
2333 case ShellSubMenuLink
:
2334 case ShellSubMenuFolder
:
2335 case ShellSubMenuFile
:
2340 space
= layout
& menuInfo
[menuIndex
].menuID
? 0 : 6;
2341 if (layout
& (menuInfo
[menuIndex
].menuID
))
2343 _tcscpy_s(textbuf
, 255, _T("Git "));
2344 _tcscat_s(textbuf
, 255, stringtablebuffer
);
2345 _tcscpy_s(stringtablebuffer
, 255, textbuf
);
2356 bool CShellExt::IsIllegalFolder(std::wstring folder
, int * cslidarray
)
2359 TCHAR buf
[MAX_PATH
]; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
2360 LPITEMIDLIST pidl
= NULL
;
2361 while (cslidarray
[i
])
2365 if (SHGetFolderLocation(NULL
, cslidarray
[i
-1], NULL
, 0, &pidl
)!=S_OK
)
2367 if (!SHGetPathFromIDList(pidl
, buf
))
2369 // not a file system path, definitely illegal for our use
2370 CoTaskMemFree(pidl
);
2373 CoTaskMemFree(pidl
);
2374 if (_tcslen(buf
)==0)
2376 if (_tcscmp(buf
, folder
.c_str())==0)
2382 void CShellExt::InsertIgnoreSubmenus(UINT
&idCmd
, UINT idCmdFirst
, HMENU hMenu
, HMENU subMenu
, UINT
&indexMenu
, int &indexSubMenu
, unsigned __int64 topmenu
, bool bShowIcons
, UINT uFlags
)
2384 HMENU ignoresubmenu
= NULL
;
2385 int indexignoresub
= 0;
2386 bool bShowIgnoreMenu
= false;
2387 TCHAR maskbuf
[MAX_PATH
]; // MAX_PATH is ok, since this only holds a filename
2388 TCHAR ignorepath
[MAX_PATH
]; // MAX_PATH is ok, since this only holds a filename
2389 if (files_
.size() == 0)
2391 UINT icon
= bShowIcons
? IDI_IGNORE
: 0;
2393 std::vector
<stdstring
>::iterator I
= files_
.begin();
2394 if (_tcsrchr(I
->c_str(), '\\'))
2395 _tcscpy_s(ignorepath
, MAX_PATH
, _tcsrchr(I
->c_str(), '\\')+1);
2397 _tcscpy_s(ignorepath
, MAX_PATH
, I
->c_str());
2398 if ((itemStates
& ITEMIS_IGNORED
)&&(ignoredprops
.size() > 0))
2400 // check if the item name is ignored or the mask
2402 while ( (p
=ignoredprops
.find( ignorepath
,p
)) != -1 )
2404 if ( (p
==0 || ignoredprops
[p
-1]==TCHAR('\n'))
2405 && (p
+_tcslen(ignorepath
)==ignoredprops
.length() || ignoredprops
[p
+_tcslen(ignorepath
)+1]==TCHAR('\n')) )
2413 ignoresubmenu
= CreateMenu();
2414 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2415 stdstring verb
= stdstring(ignorepath
);
2416 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2417 myVerbsMap
[verb
] = idCmd
;
2418 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2419 myVerbsIDMap
[idCmd
] = verb
;
2420 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnore
;
2421 myIDMap
[idCmd
++] = ShellMenuUnIgnore
;
2422 bShowIgnoreMenu
= true;
2424 _tcscpy_s(maskbuf
, MAX_PATH
, _T("*"));
2425 if (_tcsrchr(ignorepath
, '.'))
2427 _tcscat_s(maskbuf
, MAX_PATH
, _tcsrchr(ignorepath
, '.'));
2428 p
= ignoredprops
.find(maskbuf
);
2430 ((ignoredprops
.compare(maskbuf
)==0) || (ignoredprops
.find('\n', p
)==p
+_tcslen(maskbuf
)+1) || (ignoredprops
.rfind('\n', p
)==p
-1)))
2432 if (ignoresubmenu
==NULL
)
2433 ignoresubmenu
= CreateMenu();
2435 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, maskbuf
);
2436 stdstring verb
= stdstring(maskbuf
);
2437 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2438 myVerbsMap
[verb
] = idCmd
;
2439 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2440 myVerbsIDMap
[idCmd
] = verb
;
2441 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnoreCaseSensitive
;
2442 myIDMap
[idCmd
++] = ShellMenuUnIgnoreCaseSensitive
;
2443 bShowIgnoreMenu
= true;
2447 else if ((itemStates
& ITEMIS_IGNORED
) == 0)
2449 bShowIgnoreMenu
= true;
2450 ignoresubmenu
= CreateMenu();
2451 if (itemStates
& ITEMIS_ONLYONE
)
2453 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2454 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnore
;
2455 myIDMap
[idCmd
++] = ShellMenuIgnore
;
2457 _tcscpy_s(maskbuf
, MAX_PATH
, _T("*"));
2458 if (_tcsrchr(ignorepath
, '.'))
2460 _tcscat_s(maskbuf
, MAX_PATH
, _tcsrchr(ignorepath
, '.'));
2461 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, maskbuf
);
2462 stdstring verb
= stdstring(maskbuf
);
2463 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2464 myVerbsMap
[verb
] = idCmd
;
2465 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2466 myVerbsIDMap
[idCmd
] = verb
;
2467 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreCaseSensitive
;
2468 myIDMap
[idCmd
++] = ShellMenuIgnoreCaseSensitive
;
2473 MAKESTRING(IDS_MENUIGNOREMULTIPLE
);
2474 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2475 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2476 stdstring verb
= stdstring(ignorepath
);
2477 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2478 myVerbsMap
[verb
] = idCmd
;
2479 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2480 myVerbsIDMap
[idCmd
] = verb
;
2481 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnore
;
2482 myIDMap
[idCmd
++] = ShellMenuIgnore
;
2484 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK
);
2485 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2486 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2487 verb
= stdstring(ignorepath
);
2488 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2489 myVerbsMap
[verb
] = idCmd
;
2490 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2491 myVerbsIDMap
[idCmd
] = verb
;
2492 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreCaseSensitive
;
2493 myIDMap
[idCmd
++] = ShellMenuIgnoreCaseSensitive
;
2497 if (bShowIgnoreMenu
)
2499 MENUITEMINFO menuiteminfo
;
2500 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
2501 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
2502 if (fullver
< 0x500 || (fullver
== 0x500 && !(uFlags
&~(CMF_RESERVED
|CMF_EXPLORE
))))
2504 menuiteminfo
.fMask
= MIIM_STRING
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
;
2507 HBITMAP bmp
= IconToBitmap(icon
);
2508 menuiteminfo
.fMask
|= MIIM_CHECKMARKS
;
2509 menuiteminfo
.hbmpChecked
= bmp
;
2510 menuiteminfo
.hbmpUnchecked
= bmp
;
2515 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
| MIIM_STRING
;
2518 menuiteminfo
.fMask
|= MIIM_BITMAP
;
2519 menuiteminfo
.hbmpItem
= (fullver
>= 0x600) ? IconToBitmapPARGB32(icon
) : HBMMENU_CALLBACK
;
2522 menuiteminfo
.fType
= MFT_STRING
;
2523 menuiteminfo
.hSubMenu
= ignoresubmenu
;
2524 menuiteminfo
.wID
= idCmd
;
2525 SecureZeroMemory(stringtablebuffer
, sizeof(stringtablebuffer
));
2526 if (itemStates
& ITEMIS_IGNORED
)
2527 GetMenuTextFromResource(ShellMenuUnIgnoreSub
);
2529 GetMenuTextFromResource(ShellMenuIgnoreSub
);
2530 menuiteminfo
.dwTypeData
= stringtablebuffer
;
2531 menuiteminfo
.cch
= (UINT
)min(_tcslen(menuiteminfo
.dwTypeData
), UINT_MAX
);
2533 InsertMenuItem((topmenu
& MENUIGNORE
) ? hMenu
: subMenu
, (topmenu
& MENUIGNORE
) ? indexMenu
++ : indexSubMenu
++, TRUE
, &menuiteminfo
);
2534 if (itemStates
& ITEMIS_IGNORED
)
2536 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnoreSub
;
2537 myIDMap
[idCmd
++] = ShellMenuUnIgnoreSub
;
2541 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreSub
;
2542 myIDMap
[idCmd
++] = ShellMenuIgnoreSub
;
2547 HBITMAP
CShellExt::IconToBitmapPARGB32(UINT uIcon
)
2549 std::map
<UINT
, HBITMAP
>::iterator bitmap_it
= bitmaps
.lower_bound(uIcon
);
2550 if (bitmap_it
!= bitmaps
.end() && bitmap_it
->first
== uIcon
)
2551 return bitmap_it
->second
;
2553 HICON hIcon
= (HICON
)LoadImage(g_hResInst
, MAKEINTRESOURCE(uIcon
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
2557 if (pfnBeginBufferedPaint
== NULL
|| pfnEndBufferedPaint
== NULL
|| pfnGetBufferedPaintBits
== NULL
)
2561 sizIcon
.cx
= GetSystemMetrics(SM_CXSMICON
);
2562 sizIcon
.cy
= GetSystemMetrics(SM_CYSMICON
);
2565 SetRect(&rcIcon
, 0, 0, sizIcon
.cx
, sizIcon
.cy
);
2566 HBITMAP hBmp
= NULL
;
2568 HDC hdcDest
= CreateCompatibleDC(NULL
);
2571 if (SUCCEEDED(Create32BitHBITMAP(hdcDest
, &sizIcon
, NULL
, &hBmp
)))
2573 HBITMAP hbmpOld
= (HBITMAP
)SelectObject(hdcDest
, hBmp
);
2576 BLENDFUNCTION bfAlpha
= { AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
};
2577 BP_PAINTPARAMS paintParams
= {0};
2578 paintParams
.cbSize
= sizeof(paintParams
);
2579 paintParams
.dwFlags
= BPPF_ERASE
;
2580 paintParams
.pBlendFunction
= &bfAlpha
;
2583 HPAINTBUFFER hPaintBuffer
= pfnBeginBufferedPaint(hdcDest
, &rcIcon
, BPBF_DIB
, &paintParams
, &hdcBuffer
);
2586 if (DrawIconEx(hdcBuffer
, 0, 0, hIcon
, sizIcon
.cx
, sizIcon
.cy
, 0, NULL
, DI_NORMAL
))
2588 // If icon did not have an alpha channel we need to convert buffer to PARGB
2589 ConvertBufferToPARGB32(hPaintBuffer
, hdcDest
, hIcon
, sizIcon
);
2592 // This will write the buffer contents to the destination bitmap
2593 pfnEndBufferedPaint(hPaintBuffer
, TRUE
);
2596 SelectObject(hdcDest
, hbmpOld
);
2606 bitmaps
.insert(bitmap_it
, std::make_pair(uIcon
, hBmp
));
2610 HRESULT
CShellExt::Create32BitHBITMAP(HDC hdc
, const SIZE
*psize
, __deref_opt_out
void **ppvBits
, __out HBITMAP
* phBmp
)
2615 ZeroMemory(&bmi
, sizeof(bmi
));
2616 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2617 bmi
.bmiHeader
.biPlanes
= 1;
2618 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2620 bmi
.bmiHeader
.biWidth
= psize
->cx
;
2621 bmi
.bmiHeader
.biHeight
= psize
->cy
;
2622 bmi
.bmiHeader
.biBitCount
= 32;
2624 HDC hdcUsed
= hdc
? hdc
: GetDC(NULL
);
2627 *phBmp
= CreateDIBSection(hdcUsed
, &bmi
, DIB_RGB_COLORS
, ppvBits
, NULL
, 0);
2630 ReleaseDC(NULL
, hdcUsed
);
2633 return (NULL
== *phBmp
) ? E_OUTOFMEMORY
: S_OK
;
2636 HRESULT
CShellExt::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer
, HDC hdc
, HICON hicon
, SIZE
& sizIcon
)
2640 HRESULT hr
= pfnGetBufferedPaintBits(hPaintBuffer
, &prgbQuad
, &cxRow
);
2643 ARGB
*pargb
= reinterpret_cast<ARGB
*>(prgbQuad
);
2644 if (!HasAlpha(pargb
, sizIcon
, cxRow
))
2647 if (GetIconInfo(hicon
, &info
))
2651 hr
= ConvertToPARGB32(hdc
, pargb
, info
.hbmMask
, sizIcon
, cxRow
);
2654 DeleteObject(info
.hbmColor
);
2655 DeleteObject(info
.hbmMask
);
2663 bool CShellExt::HasAlpha(__in ARGB
*pargb
, SIZE
& sizImage
, int cxRow
)
2665 ULONG cxDelta
= cxRow
- sizImage
.cx
;
2666 for (ULONG y
= sizImage
.cy
; y
; --y
)
2668 for (ULONG x
= sizImage
.cx
; x
; --x
)
2670 if (*pargb
++ & 0xFF000000)
2682 HRESULT
CShellExt::ConvertToPARGB32(HDC hdc
, __inout ARGB
*pargb
, HBITMAP hbmp
, SIZE
& sizImage
, int cxRow
)
2685 ZeroMemory(&bmi
, sizeof(bmi
));
2686 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2687 bmi
.bmiHeader
.biPlanes
= 1;
2688 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2690 bmi
.bmiHeader
.biWidth
= sizImage
.cx
;
2691 bmi
.bmiHeader
.biHeight
= sizImage
.cy
;
2692 bmi
.bmiHeader
.biBitCount
= 32;
2694 HRESULT hr
= E_OUTOFMEMORY
;
2695 HANDLE hHeap
= GetProcessHeap();
2696 void *pvBits
= HeapAlloc(hHeap
, 0, bmi
.bmiHeader
.biWidth
* 4 * bmi
.bmiHeader
.biHeight
);
2700 if (GetDIBits(hdc
, hbmp
, 0, bmi
.bmiHeader
.biHeight
, pvBits
, &bmi
, DIB_RGB_COLORS
) == bmi
.bmiHeader
.biHeight
)
2702 ULONG cxDelta
= cxRow
- bmi
.bmiHeader
.biWidth
;
2703 ARGB
*pargbMask
= static_cast<ARGB
*>(pvBits
);
2705 for (ULONG y
= bmi
.bmiHeader
.biHeight
; y
; --y
)
2707 for (ULONG x
= bmi
.bmiHeader
.biWidth
; x
; --x
)
2711 // transparent pixel
2717 *pargb
++ |= 0xFF000000;
2727 HeapFree(hHeap
, 0, pvBits
);