1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012 - TortoiseSVN
4 // Copyright (C) 2008-2014 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ItemIDList.h"
23 #include "PreserveChdir.h"
24 #include "UnicodeUtils.h"
25 #include "GitStatus.h"
27 #include "PathUtils.h"
28 #include "CreateProcessHelper.h"
29 #include "FormatMessageWrapper.h"
30 #include "..\TGitCache\CacheInterface.h"
33 #define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
34 #define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
36 int g_shellidlist
=RegisterClipboardFormat(CFSTR_SHELLIDLIST
);
38 extern MenuInfo menuInfo
[];
39 static int g_syncSeq
= 0;
41 STDMETHODIMP
CShellExt::Initialize(LPCITEMIDLIST pIDFolder
,
42 LPDATAOBJECT pDataObj
,
47 return Initialize_Wrap(pIDFolder
, pDataObj
, hRegKey
);
49 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
55 STDMETHODIMP
CShellExt::Initialize_Wrap(LPCITEMIDLIST pIDFolder
,
56 LPDATAOBJECT pDataObj
,
59 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Shell :: Initialize\n");
60 PreserveChdir preserveChdir
;
68 git_wc_status_kind fetchedstatus
= git_wc_status_none
;
69 // get selected files/folders
73 FORMATETC fmte
= {(CLIPFORMAT
)g_shellidlist
,
74 (DVTARGETDEVICE FAR
*)NULL
,
78 HRESULT hres
= pDataObj
->GetData(&fmte
, &medium
);
80 if (SUCCEEDED(hres
) && medium
.hGlobal
)
82 if (m_State
== FileStateDropHandler
)
85 FORMATETC etc
= { CF_HDROP
, NULL
, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
86 STGMEDIUM stg
= { TYMED_HGLOBAL
};
87 if ( FAILED( pDataObj
->GetData ( &etc
, &stg
)))
89 ReleaseStgMedium ( &medium
);
94 HDROP drop
= (HDROP
)GlobalLock(stg
.hGlobal
);
97 ReleaseStgMedium ( &stg
);
98 ReleaseStgMedium ( &medium
);
102 int count
= DragQueryFile(drop
, (UINT
)-1, NULL
, 0);
104 itemStates
|= ITEMIS_ONLYONE
;
105 for (int i
= 0; i
< count
; i
++)
107 // find the path length in chars
108 UINT len
= DragQueryFile(drop
, i
, NULL
, 0);
111 std::unique_ptr
<TCHAR
[]> szFileName(new TCHAR
[len
+ 1]);
112 if (0 == DragQueryFile(drop
, i
, szFileName
.get(), len
+ 1))
114 stdstring str
= stdstring(szFileName
.get());
115 if ((!str
.empty()) && (g_ShellCache
.IsContextPathAllowed(szFileName
.get())))
117 if (itemStates
& ITEMIS_ONLYONE
)
120 strpath
.SetFromWin(str
.c_str());
121 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE
: 0;
122 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE
: 0;
124 files_
.push_back(str
);
127 //get the Subversion status of the item
128 git_wc_status_kind status
= git_wc_status_none
;
130 askedpath
.SetFromWin(str
.c_str());
131 CString workTreePath
;
132 askedpath
.HasAdminDir(&workTreePath
);
133 uuidSource
= workTreePath
;
136 if (g_ShellCache
.GetCacheType() == ShellCache::exe
&& g_ShellCache
.IsPathAllowed(str
.c_str()))
138 CTGitPath
tpath(str
.c_str());
139 if (!tpath
.HasAdminDir())
141 status
= git_wc_status_none
;
144 if (tpath
.IsAdminDir())
146 status
= git_wc_status_none
;
149 TGITCacheResponse itemStatus
;
150 SecureZeroMemory(&itemStatus
, sizeof(itemStatus
));
151 if (m_remoteCacheLink
.GetStatusFromRemoteCache(tpath
, &itemStatus
, true))
153 fetchedstatus
= status
= GitStatus::GetMoreImportant(itemStatus
.m_status
.text_status
, itemStatus
.m_status
.prop_status
);
154 if (askedpath
.IsDirectory())//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
156 itemStates
|= ITEMIS_FOLDER
;
157 if ((status
!= git_wc_status_unversioned
) && (status
!= git_wc_status_ignored
) && (status
!= git_wc_status_none
))
158 itemStates
|= ITEMIS_FOLDERINGIT
;
165 stat
.GetStatus(CTGitPath(str
.c_str()), false, false, true);
169 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
170 fetchedstatus
= status
;
171 if ( askedpath
.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
173 itemStates
|= ITEMIS_FOLDER
;
174 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
175 itemStates
|= ITEMIS_FOLDERINGIT
;
177 //if ((stat.status->entry)&&(stat.status->entry->uuid))
178 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
182 // sometimes, git_client_status() returns with an error.
183 // in that case, we have to check if the working copy is versioned
184 // anyway to show the 'correct' context menu
185 if (askedpath
.HasAdminDir())
186 status
= git_wc_status_normal
;
192 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Exception in GitStatus::GetStatus()\n");
195 // TODO: should we really assume any sub-directory to be versioned
196 // or only if it contains versioned files
197 itemStates
|= askedpath
.GetAdminDirMask();
199 if ((status
== git_wc_status_unversioned
) || (status
== git_wc_status_ignored
) || (status
== git_wc_status_none
))
200 itemStates
&= ~ITEMIS_INGIT
;
202 if (status
== git_wc_status_ignored
)
203 itemStates
|= ITEMIS_IGNORED
;
204 if (status
== git_wc_status_normal
)
205 itemStates
|= ITEMIS_NORMAL
;
206 if (status
== git_wc_status_conflicted
)
207 itemStates
|= ITEMIS_CONFLICTED
;
208 if (status
== git_wc_status_added
)
209 itemStates
|= ITEMIS_ADDED
;
210 if (status
== git_wc_status_deleted
)
211 itemStates
|= ITEMIS_DELETED
;
214 } // for (int i = 0; i < count; i++)
215 GlobalUnlock ( drop
);
216 ReleaseStgMedium ( &stg
);
218 } // if (m_State == FileStateDropHandler)
222 //Enumerate PIDLs which the user has selected
223 CIDA
* cida
= (CIDA
*)GlobalLock(medium
.hGlobal
);
224 ItemIDList
parent( GetPIDLFolder (cida
));
226 int count
= cida
->cidl
;
227 BOOL statfetched
= FALSE
;
228 for (int i
= 0; i
< count
; ++i
)
230 ItemIDList
child (GetPIDLItem (cida
, i
), &parent
);
231 stdstring str
= child
.toString();
232 if ((str
.empty() == false)&&(g_ShellCache
.IsContextPathAllowed(str
.c_str())))
234 //check if our menu is requested for a subversion admin directory
235 if (g_GitAdminDir
.IsAdminDirPath(str
.c_str()))
238 files_
.push_back(str
);
240 strpath
.SetFromWin(str
.c_str());
241 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".diff"))==0) ? ITEMIS_PATCHFILE
: 0;
242 itemStates
|= (strpath
.GetFileExtension().CompareNoCase(_T(".patch"))==0) ? ITEMIS_PATCHFILE
: 0;
245 //get the Subversion status of the item
246 git_wc_status_kind status
= git_wc_status_none
;
247 if ((g_ShellCache
.IsSimpleContext())&&(strpath
.IsDirectory()))
249 if (strpath
.HasAdminDir())
250 status
= git_wc_status_normal
;
256 if (g_ShellCache
.GetCacheType() == ShellCache::exe
&& g_ShellCache
.IsPathAllowed(str
.c_str()))
258 CTGitPath
tpath(str
.c_str());
259 if(!tpath
.HasAdminDir())
261 status
= git_wc_status_none
;
264 if(tpath
.IsAdminDir())
266 status
= git_wc_status_none
;
269 TGITCacheResponse itemStatus
;
270 SecureZeroMemory(&itemStatus
, sizeof(itemStatus
));
271 if (m_remoteCacheLink
.GetStatusFromRemoteCache(tpath
, &itemStatus
, true))
273 fetchedstatus
= status
= GitStatus::GetMoreImportant(itemStatus
.m_status
.text_status
, itemStatus
.m_status
.prop_status
);
274 if (strpath
.IsDirectory())//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
276 itemStates
|= ITEMIS_FOLDER
;
277 if ((status
!= git_wc_status_unversioned
) && (status
!= git_wc_status_ignored
) && (status
!= git_wc_status_none
))
278 itemStates
|= ITEMIS_FOLDERINGIT
;
280 if (status
== git_wc_status_conflicted
)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
281 itemStates
|= ITEMIS_CONFLICTED
;
287 if (strpath
.HasAdminDir())
288 stat
.GetStatus(strpath
, false, false, true);
292 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
293 fetchedstatus
= status
;
294 if ( strpath
.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))
296 itemStates
|= ITEMIS_FOLDER
;
297 if ((status
!= git_wc_status_unversioned
)&&(status
!= git_wc_status_ignored
)&&(status
!= git_wc_status_none
))
298 itemStates
|= ITEMIS_FOLDERINGIT
;
300 // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?
301 if (status
== git_wc_status_conflicted
)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
302 itemStates
|= ITEMIS_CONFLICTED
;
303 //if ((stat.status->entry)&&(stat.status->entry->uuid))
304 // uuidSource = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
308 // sometimes, git_client_status() returns with an error.
309 // in that case, we have to check if the working copy is versioned
310 // anyway to show the 'correct' context menu
311 if (strpath
.HasAdminDir())
313 status
= git_wc_status_normal
;
314 fetchedstatus
= status
;
322 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Exception in GitStatus::GetStatus()\n");
326 itemStates
|= strpath
.GetAdminDirMask();
328 if ((status
== git_wc_status_unversioned
)||(status
== git_wc_status_ignored
)||(status
== git_wc_status_none
))
329 itemStates
&= ~ITEMIS_INGIT
;
330 if (status
== git_wc_status_ignored
)
332 itemStates
|= ITEMIS_IGNORED
;
335 if (status
== git_wc_status_normal
)
336 itemStates
|= ITEMIS_NORMAL
;
337 if (status
== git_wc_status_conflicted
)
338 itemStates
|= ITEMIS_CONFLICTED
;
339 if (status
== git_wc_status_added
)
340 itemStates
|= ITEMIS_ADDED
;
341 if (status
== git_wc_status_deleted
)
342 itemStates
|= ITEMIS_DELETED
;
345 } // for (int i = 0; i < count; ++i)
346 ItemIDList
child (GetPIDLItem (cida
, 0), &parent
);
347 if (g_ShellCache
.HasGITAdminDir(child
.toString().c_str(), FALSE
))
348 itemStates
|= ITEMIS_INVERSIONEDFOLDER
;
350 if (g_GitAdminDir
.IsBareRepo(child
.toString().c_str()))
351 itemStates
= ITEMIS_BAREREPO
;
353 GlobalUnlock(medium
.hGlobal
);
355 // if the item is a versioned folder, check if there's a patch file
356 // in the clipboard to be used in "Apply Patch"
357 UINT cFormatDiff
= RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
360 if (IsClipboardFormatAvailable(cFormatDiff
))
361 itemStates
|= ITEMIS_PATCHINCLIPBOARD
;
363 if (IsClipboardFormatAvailable(CF_HDROP
))
364 itemStates
|= ITEMIS_PATHINCLIPBOARD
;
368 ReleaseStgMedium ( &medium
);
369 if (medium
.pUnkForRelease
)
371 IUnknown
* relInterface
= (IUnknown
*)medium
.pUnkForRelease
;
372 relInterface
->Release();
377 // get folder background
381 ItemIDList
list(pIDFolder
);
382 folder_
= list
.toString();
383 git_wc_status_kind status
= git_wc_status_none
;
384 if (IsClipboardFormatAvailable(CF_HDROP
))
385 itemStatesFolder
|= ITEMIS_PATHINCLIPBOARD
;
388 askedpath
.SetFromWin(folder_
.c_str());
390 if (g_ShellCache
.IsContextPathAllowed(folder_
.c_str()))
392 if (folder_
.compare(statuspath
)!=0)
394 CString worktreePath
;
395 askedpath
.HasAdminDir(&worktreePath
);
396 uuidTarget
= worktreePath
;
399 if (g_ShellCache
.GetCacheType() == ShellCache::exe
&& g_ShellCache
.IsPathAllowed(folder_
.c_str()))
401 CTGitPath
tpath(folder_
.c_str());
402 if(!tpath
.HasAdminDir())
403 status
= git_wc_status_none
;
404 else if(tpath
.IsAdminDir())
405 status
= git_wc_status_none
;
408 TGITCacheResponse itemStatus
;
409 SecureZeroMemory(&itemStatus
, sizeof(itemStatus
));
410 if (m_remoteCacheLink
.GetStatusFromRemoteCache(tpath
, &itemStatus
, true))
411 status
= GitStatus::GetMoreImportant(itemStatus
.m_status
.text_status
, itemStatus
.m_status
.prop_status
);
417 stat
.GetStatus(CTGitPath(folder_
.c_str()), false, false, true);
420 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
421 // if ((stat.status->entry)&&(stat.status->entry->uuid))
422 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
427 // sometimes, git_client_status() returns with an error.
428 // in that case, we have to check if the working copy is versioned
429 // anyway to show the 'correct' context menu
430 if (askedpath
.HasAdminDir())
431 status
= git_wc_status_normal
;
435 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
436 itemStatesFolder
|= askedpath
.GetAdminDirMask();
438 if ((status
== git_wc_status_unversioned
)||(status
== git_wc_status_ignored
)||(status
== git_wc_status_none
))
439 itemStates
&= ~ITEMIS_INGIT
;
441 if (status
== git_wc_status_normal
)
442 itemStatesFolder
|= ITEMIS_NORMAL
;
443 if (status
== git_wc_status_conflicted
)
444 itemStatesFolder
|= ITEMIS_CONFLICTED
;
445 if (status
== git_wc_status_added
)
446 itemStatesFolder
|= ITEMIS_ADDED
;
447 if (status
== git_wc_status_deleted
)
448 itemStatesFolder
|= ITEMIS_DELETED
;
453 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Exception in GitStatus::GetStatus()\n");
458 status
= fetchedstatus
;
460 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
461 itemStatesFolder
|= askedpath
.GetAdminDirMask();
463 if (status
== git_wc_status_ignored
)
464 itemStatesFolder
|= ITEMIS_IGNORED
;
465 itemStatesFolder
|= ITEMIS_FOLDER
;
467 itemStates
|= ITEMIS_ONLYONE
;
468 if (m_State
!= FileStateDropHandler
)
469 itemStates
|= itemStatesFolder
;
474 status
= fetchedstatus
;
477 if (files_
.size() == 2)
478 itemStates
|= ITEMIS_TWO
;
479 if ((files_
.size() == 1)&&(g_ShellCache
.IsContextPathAllowed(files_
.front().c_str())))
482 itemStates
|= ITEMIS_ONLYONE
;
483 if (m_State
!= FileStateDropHandler
)
485 if (PathIsDirectory(files_
.front().c_str()))
487 folder_
= files_
.front();
488 git_wc_status_kind status
= git_wc_status_none
;
490 askedpath
.SetFromWin(folder_
.c_str());
492 if (folder_
.compare(statuspath
)!=0)
497 stat
.GetStatus(CTGitPath(folder_
.c_str()), false, false, true);
500 status
= GitStatus::GetMoreImportant(stat
.status
->text_status
, stat
.status
->prop_status
);
501 // if ((stat.status->entry)&&(stat.status->entry->uuid))
502 // uuidTarget = CUnicodeUtils::StdGetUnicode(stat.status->entry->uuid);
507 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Exception in GitStatus::GetStatus()\n");
512 status
= fetchedstatus
;
514 //if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))
515 itemStates
|= askedpath
.GetAdminDirMask();
517 if ((status
== git_wc_status_unversioned
)||(status
== git_wc_status_ignored
)||(status
== git_wc_status_none
))
518 itemStates
&= ~ITEMIS_INGIT
;
520 if (status
== git_wc_status_ignored
)
521 itemStates
|= ITEMIS_IGNORED
;
522 itemStates
|= ITEMIS_FOLDER
;
523 if (status
== git_wc_status_added
)
524 itemStates
|= ITEMIS_ADDED
;
525 if (status
== git_wc_status_deleted
)
526 itemStates
|= ITEMIS_DELETED
;
536 void CShellExt::InsertGitMenu(BOOL istop
, HMENU menu
, UINT pos
, UINT_PTR id
, UINT stringid
, UINT icon
, UINT idCmdFirst
, GitCommands com
, UINT
/*uFlags*/)
538 TCHAR menutextbuffer
[512] = {0};
539 TCHAR verbsbuffer
[255] = {0};
540 MAKESTRING(stringid
);
544 //menu entry for the top context menu, so append an "Git " before
545 //the menu text to indicate where the entry comes from
546 _tcscpy_s(menutextbuffer
, 255, _T("Git "));
547 if (!g_ShellCache
.HasShellMenuAccelerators())
549 // remove the accelerators
550 tstring temp
= stringtablebuffer
;
551 temp
.erase(std::remove(temp
.begin(), temp
.end(), '&'), temp
.end());
552 _tcscpy_s(stringtablebuffer
, 255, temp
.c_str());
555 _tcscat_s(menutextbuffer
, 255, stringtablebuffer
);
557 // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..."
558 // so we have an easy and fast way to check the current branch
559 // (the other alternative is using a separate disabled menu entry, the code is already done but commented out)
560 if (com
== ShellMenuCommit
)
563 CTGitPath
path(folder_
.empty() ? files_
.front().c_str() : folder_
.c_str());
564 CString sProjectRoot
;
567 if (path
.GetAdminDirMask() & ITEMIS_SUBMODULE
)
570 _tcscpy_s(menutextbuffer
, 255, _T("Git "));
571 _tcscat_s(menutextbuffer
, 255, CString(MAKEINTRESOURCE(IDS_MENUCOMMITSUBMODULE
)));
574 if (path
.HasAdminDir(&sProjectRoot
) && !CGit::GetCurrentBranchFromFile(sProjectRoot
, sBranchName
))
576 if (sBranchName
.GetLength() == 40)
578 // if SHA1 only show 4 first bytes
580 for (int i
=0; i
<40; i
++)
581 if ( !iswxdigit(sBranchName
[i
]) )
587 sBranchName
= sBranchName
.Left(8) + _T("....");
591 if (sBranchName
.GetLength() > 64)
592 sBranchName
= sBranchName
.Left(64) + _T("...");
594 // scan to before "..."
595 LPTSTR s
= menutextbuffer
+ _tcslen(menutextbuffer
)-1;
596 if (s
> menutextbuffer
)
598 while (s
> menutextbuffer
)
613 // append branch name and end with ...
614 _tcscpy_s(s
, 255 - _tcslen(menutextbuffer
) - 1, _T(" -> \"") + sBranchName
+ _T("\"..."));
618 if (com
== ShellMenuDiffLater
)
620 std::wstring sPath
= regDiffLater
;
623 // add the path of the saved file
624 wchar_t compact
[40] = {0};
625 PathCompactPathEx(compact
, sPath
.c_str(), _countof(compact
) - 1, 0);
627 sMenu
.Format(IDS_MENUDIFFNOW
, compact
);
628 wcscpy_s(menutextbuffer
, sMenu
);
632 MENUITEMINFO menuiteminfo
;
633 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
634 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
635 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_STRING
;
636 menuiteminfo
.fType
= MFT_STRING
;
637 menuiteminfo
.dwTypeData
= menutextbuffer
;
640 menuiteminfo
.fMask
|= MIIM_BITMAP
;
641 menuiteminfo
.hbmpItem
= SysInfo::Instance().IsVistaOrLater() ? m_iconBitmapUtils
.IconToBitmapPARGB32(g_hResInst
, icon
) : HBMMENU_CALLBACK
;
643 menuiteminfo
.wID
= (UINT
)id
;
644 InsertMenuItem(menu
, pos
, TRUE
, &menuiteminfo
);
648 //menu entry for the top context menu, so append an "Git " before
649 //the menu text to indicate where the entry comes from
650 _tcscpy_s(menutextbuffer
, 255, _T("Git "));
652 LoadString(g_hResInst
, stringid
, verbsbuffer
, _countof(verbsbuffer
));
653 _tcscat_s(menutextbuffer
, 255, verbsbuffer
);
654 stdstring verb
= stdstring(menutextbuffer
);
655 if (verb
.find('&') != -1)
657 verb
.erase(verb
.find('&'),1);
659 myVerbsMap
[verb
] = id
- idCmdFirst
;
660 myVerbsMap
[verb
] = id
;
661 myVerbsIDMap
[id
- idCmdFirst
] = verb
;
662 myVerbsIDMap
[id
] = verb
;
663 // We store the relative and absolute diameter
664 // (drawitem callback uses absolute, others relative)
665 myIDMap
[id
- idCmdFirst
] = com
;
668 mySubMenuMap
[pos
] = com
;
671 bool CShellExt::WriteClipboardPathsToTempFile(stdstring
& tempfile
)
674 tempfile
= stdstring();
675 //write all selected files and paths to a temporary file
676 //for TortoiseGitProc.exe to read out again.
678 DWORD pathlength
= GetTortoiseGitTempPath(0, NULL
);
679 std::unique_ptr
<TCHAR
[]> path(new TCHAR
[pathlength
+ 1]);
680 std::unique_ptr
<TCHAR
[]> tempFile(new TCHAR
[pathlength
+ 100]);
681 GetTortoiseGitTempPath(pathlength
+1, path
.get());
682 GetTempFileName(path
.get(), _T("git"), 0, tempFile
.get());
683 tempfile
= stdstring(tempFile
.get());
685 CAutoFile file
= ::CreateFile(tempFile
.get(),
690 FILE_ATTRIBUTE_TEMPORARY
,
696 if (!IsClipboardFormatAvailable(CF_HDROP
))
698 if (!OpenClipboard(NULL
))
701 stdstring sClipboardText
;
702 HGLOBAL hglb
= GetClipboardData(CF_HDROP
);
703 HDROP hDrop
= (HDROP
)GlobalLock(hglb
);
706 TCHAR szFileName
[MAX_PATH
] = {0};
707 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, NULL
, 0);
708 for(UINT i
= 0; i
< cFiles
; ++i
)
710 DragQueryFile(hDrop
, i
, szFileName
, _countof(szFileName
));
711 stdstring filename
= szFileName
;
712 ::WriteFile (file
, filename
.c_str(), (DWORD
)filename
.size()*sizeof(TCHAR
), &written
, 0);
713 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
725 stdstring
CShellExt::WriteFileListToTempFile()
727 //write all selected files and paths to a temporary file
728 //for TortoiseGitProc.exe to read out again.
729 DWORD pathlength
= GetTortoiseGitTempPath(0, NULL
);
730 std::unique_ptr
<TCHAR
[]> path(new TCHAR
[pathlength
+ 1]);
731 std::unique_ptr
<TCHAR
[]> tempFile(new TCHAR
[pathlength
+ 100]);
732 GetTortoiseGitTempPath(pathlength
+ 1, path
.get());
733 GetTempFileName(path
.get(), _T("git"), 0, tempFile
.get());
734 stdstring retFilePath
= stdstring(tempFile
.get());
736 CAutoFile file
= ::CreateFile (tempFile
.get(),
741 FILE_ATTRIBUTE_TEMPORARY
,
750 ::WriteFile (file
, folder_
.c_str(), (DWORD
)folder_
.size()*sizeof(TCHAR
), &written
, 0);
751 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
754 for (std::vector
<stdstring
>::iterator I
= files_
.begin(); I
!= files_
.end(); ++I
)
756 ::WriteFile (file
, I
->c_str(), (DWORD
)I
->size()*sizeof(TCHAR
), &written
, 0);
757 ::WriteFile (file
, _T("\n"), 2, &written
, 0);
762 STDMETHODIMP
CShellExt::QueryDropContext(UINT uFlags
, UINT idCmdFirst
, HMENU hMenu
, UINT
&indexMenu
)
764 PreserveChdir preserveChdir
;
767 if ((uFlags
& CMF_DEFAULTONLY
)!=0)
768 return S_OK
; //we don't change the default action
770 if (files_
.empty() || folder_
.empty())
773 if (((uFlags
& 0x000f)!=CMF_NORMAL
)&&(!(uFlags
& CMF_EXPLORE
))&&(!(uFlags
& CMF_VERBSONLY
)))
776 bool bSourceAndTargetFromSameRepository
= (uuidSource
.compare(uuidTarget
) == 0) || uuidSource
.empty() || uuidTarget
.empty();
778 //the drop handler only has eight commands, but not all are visible at the same time:
779 //if the source file(s) are under version control then those files can be moved
780 //to the new location or they can be moved with a rename,
781 //if they are unversioned then they can be added to the working copy
782 //if they are versioned, they also can be exported to an unversioned location
783 UINT idCmd
= idCmdFirst
;
786 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
787 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINGIT
)&&((itemStates
& ITEMIS_INGIT
)&&((~itemStates
) & ITEMIS_ADDED
)))
788 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPMOVEMENU
, 0, idCmdFirst
, ShellMenuDropMove
, uFlags
);
790 // Git move and rename here
791 // 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
792 if ((bSourceAndTargetFromSameRepository
||(itemStatesFolder
& ITEMIS_ADDED
))&&(itemStatesFolder
& ITEMIS_FOLDERINGIT
)&&(itemStates
& ITEMIS_INGIT
)&&(itemStates
& ITEMIS_ONLYONE
)&&((~itemStates
) & ITEMIS_ADDED
))
793 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPMOVERENAMEMENU
, 0, idCmdFirst
, ShellMenuDropMoveRename
, uFlags
);
796 // available if source is versioned but not added, target is versioned, source and target from same repository or target folder is added
797 //if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINGIT)&&(itemStates & ITEMIS_INGIT)&&((~itemStates) & ITEMIS_ADDED))
798 // InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYMENU, 0, idCmdFirst, ShellMenuDropCopy, uFlags);
800 // Git copy and rename here, source and target from same repository
801 // available if source is a single, versioned but not added item, target is versioned or target folder is added
802 //if ((bSourceAndTargetFromSameRepository||(itemStatesFolder & ITEMIS_ADDED))&&(itemStatesFolder & ITEMIS_FOLDERINGIT)&&(itemStates & ITEMIS_INGIT)&&(itemStates & ITEMIS_ONLYONE)&&((~itemStates) & ITEMIS_ADDED))
803 // InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPCOPYRENAMEMENU, 0, idCmdFirst, ShellMenuDropCopyRename, uFlags);
806 // available if target is versioned and source is either unversioned or from another repository
807 if ((itemStatesFolder
& ITEMIS_FOLDERINGIT
)&&(((~itemStates
) & ITEMIS_INGIT
)||!bSourceAndTargetFromSameRepository
))
808 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_DROPCOPYADDMENU
, 0, idCmdFirst
, ShellMenuDropCopyAdd
, uFlags
);
811 // available if source is versioned and a folder
812 //if ((itemStates & ITEMIS_INGIT)&&(itemStates & ITEMIS_FOLDER))
813 // InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTMENU, 0, idCmdFirst, ShellMenuDropExport, uFlags);
815 // Git export all here
816 // available if source is versioned and a folder
817 //if ((itemStates & ITEMIS_INGIT)&&(itemStates & ITEMIS_FOLDER))
818 // InsertGitMenu(FALSE, hMenu, indexMenu++, idCmd++, IDS_DROPEXPORTEXTENDEDMENU, 0, idCmdFirst, ShellMenuDropExportExtended, uFlags);
821 // available if source is a patchfile
822 if (itemStates
& ITEMIS_PATCHFILE
)
823 InsertGitMenu(FALSE
, hMenu
, indexMenu
++, idCmd
++, IDS_MENUAPPLYPATCH
, 0, idCmdFirst
, ShellMenuApplyPatch
, uFlags
);
826 if (idCmd
!= idCmdFirst
)
827 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
);
831 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS
, 0, (USHORT
)(idCmd
- idCmdFirst
)));
834 STDMETHODIMP
CShellExt::QueryContextMenu(HMENU hMenu
,
842 return QueryContextMenu_Wrap(hMenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
844 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
850 STDMETHODIMP
CShellExt::QueryContextMenu_Wrap(HMENU hMenu
,
856 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Shell :: QueryContextMenu itemStates=%ld\n", itemStates
);
857 PreserveChdir preserveChdir
;
859 //first check if our drop handler is called
860 //and then (if true) provide the context menu for the
862 if (m_State
== FileStateDropHandler
)
864 return QueryDropContext(uFlags
, idCmdFirst
, hMenu
, indexMenu
);
867 if ((uFlags
& CMF_DEFAULTONLY
)!=0)
868 return S_OK
; //we don't change the default action
870 if (files_
.empty() && folder_
.empty())
873 if (((uFlags
& 0x000f)!=CMF_NORMAL
)&&(!(uFlags
& CMF_EXPLORE
))&&(!(uFlags
& CMF_VERBSONLY
)))
880 CSIDL_COMMON_FAVORITES
,
881 CSIDL_COMMON_STARTMENU
,
882 CSIDL_COMPUTERSNEARME
,
890 CSIDL_INTERNET_CACHE
,
900 if (IsIllegalFolder(folder_
, csidlarray
))
905 // folder is empty, but maybe files are selected
907 return S_OK
; // nothing selected - we don't have a menu to show
908 // check whether a selected entry is an UID - those are namespace extensions
909 // which we can't handle
910 for (std::vector
<stdstring
>::const_iterator it
= files_
.begin(); it
!= files_
.end(); ++it
)
912 if (_tcsncmp(it
->c_str(), _T("::{"), 3)==0)
918 if (_tcsncmp(folder_
.c_str(), _T("::{"), 3) == 0)
922 if (((uFlags
& CMF_EXTENDEDVERBS
) == 0) && g_ShellCache
.HideMenusForUnversionedItems())
924 if ((itemStates
& (ITEMIS_INGIT
|ITEMIS_INVERSIONEDFOLDER
|ITEMIS_FOLDERINGIT
|ITEMIS_BAREREPO
|ITEMIS_TWO
))==0)
928 //check if our menu is requested for a subversion admin directory
929 if (g_GitAdminDir
.IsAdminDirPath(folder_
.c_str()))
932 if (uFlags
& CMF_EXTENDEDVERBS
)
933 itemStates
|= ITEMIS_EXTENDED
;
936 if (!std::wstring(regDiffLater
).empty())
937 itemStates
|= ITEMIS_HASDIFFLATER
;
939 const BOOL bShortcut
= !!(uFlags
& CMF_VERBSONLY
);
940 if ( bShortcut
&& (files_
.size()==1))
942 // Don't show the context menu for a link if the
943 // destination is not part of a working copy.
944 // It would only show the standard menu items
945 // which are already shown for the lnk-file.
946 CString path
= files_
.front().c_str();
947 if ( !g_GitAdminDir
.HasAdminDir(path
) )
953 //check if we already added our menu entry for a folder.
954 //we check that by iterating through all menu entries and check if
955 //the dwItemData member points to our global ID string. That string is set
956 //by our shell extension when the folder menu is inserted.
957 TCHAR menubuf
[MAX_PATH
] = {0};
958 int count
= GetMenuItemCount(hMenu
);
959 for (int i
=0; i
<count
; ++i
)
962 SecureZeroMemory(&miif
, sizeof(MENUITEMINFO
));
963 miif
.cbSize
= sizeof(MENUITEMINFO
);
964 miif
.fMask
= MIIM_DATA
;
965 miif
.dwTypeData
= menubuf
;
966 miif
.cch
= _countof(menubuf
);
967 GetMenuItemInfo(hMenu
, i
, TRUE
, &miif
);
968 if (miif
.dwItemData
== (ULONG_PTR
)g_MenuIDString
)
973 UINT idCmd
= idCmdFirst
;
975 //create the sub menu
976 HMENU subMenu
= CreateMenu();
977 int indexSubMenu
= 0;
979 unsigned __int64 topmenu
= g_ShellCache
.GetMenuLayout();
980 unsigned __int64 menumask
= g_ShellCache
.GetMenuMask();
981 unsigned __int64 menuex
= g_ShellCache
.GetMenuExt();
984 bool bAddSeparator
= false;
985 bool bMenuEntryAdded
= false;
986 bool bMenuEmpty
= true;
987 // insert separator at start
988 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
); idCmd
++;
989 bool bShowIcons
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE
));
991 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
993 if (menuInfo
[menuIndex
].command
== ShellSeparator
)
995 // we don't add a separator immediately. Because there might not be
996 // another 'normal' menu entry after we insert a separator.
997 // we simply set a flag here, indicating that before the next
998 // 'normal' menu entry, a separator should be added.
1000 bAddSeparator
= true;
1001 if (bMenuEntryAdded
)
1002 bAddSeparator
= true;
1006 // check the conditions whether to show the menu entry or not
1007 bool bInsertMenu
= ShouldInsertItem(menuInfo
[menuIndex
]);
1008 if (menuInfo
[menuIndex
].menuID
& menuex
)
1010 if( !(itemStates
& ITEMIS_EXTENDED
) )
1012 bInsertMenu
= false;
1016 if (menuInfo
[menuIndex
].menuID
& (~menumask
))
1020 bool bIsTop
= ((topmenu
& menuInfo
[menuIndex
].menuID
) != 0);
1021 // insert a separator
1022 if ((bMenuEntryAdded
)&&(bAddSeparator
)&&(!bIsTop
))
1024 bAddSeparator
= false;
1025 bMenuEntryAdded
= false;
1026 InsertMenu(subMenu
, indexSubMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
);
1030 // handle special cases (sub menus)
1031 if ((menuInfo
[menuIndex
].command
== ShellMenuIgnoreSub
)||(menuInfo
[menuIndex
].command
== ShellMenuUnIgnoreSub
)||(menuInfo
[menuIndex
].command
== ShellMenuDeleteIgnoreSub
))
1033 if(InsertIgnoreSubmenus(idCmd
, idCmdFirst
, hMenu
, subMenu
, indexMenu
, indexSubMenu
, topmenu
, bShowIcons
, uFlags
))
1034 bMenuEntryAdded
= true;
1038 bool bIsTop
= ((topmenu
& menuInfo
[menuIndex
].menuID
) != 0);
1040 // insert the menu entry
1041 InsertGitMenu( bIsTop
,
1042 bIsTop
? hMenu
: subMenu
,
1043 bIsTop
? indexMenu
++ : indexSubMenu
++,
1045 menuInfo
[menuIndex
].menuTextID
,
1046 bShowIcons
? menuInfo
[menuIndex
].iconID
: 0,
1048 menuInfo
[menuIndex
].command
,
1052 bMenuEntryAdded
= true;
1054 bAddSeparator
= false;
1063 // do not show TortoiseGit menu if it's empty
1066 if (idCmd
- idCmdFirst
> 0)
1069 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
); idCmd
++;
1073 //return number of menu items added
1074 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS
, 0, (USHORT
)(idCmd
- idCmdFirst
)));
1077 //add sub menu to main context menu
1078 //don't use InsertMenu because this will lead to multiple menu entries in the explorer file menu.
1079 //see http://support.microsoft.com/default.aspx?scid=kb;en-us;214477 for details of that.
1080 MAKESTRING(IDS_MENUSUBMENU
);
1081 if (!g_ShellCache
.HasShellMenuAccelerators())
1083 // remove the accelerators
1084 tstring temp
= stringtablebuffer
;
1085 temp
.erase(std::remove(temp
.begin(), temp
.end(), '&'), temp
.end());
1086 _tcscpy_s(stringtablebuffer
, temp
.c_str());
1088 MENUITEMINFO menuiteminfo
;
1089 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
1090 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
1091 menuiteminfo
.fType
= MFT_STRING
;
1092 menuiteminfo
.dwTypeData
= stringtablebuffer
;
1094 UINT uIcon
= bShowIcons
? IDI_APP
: 0;
1095 if (!folder_
.empty())
1097 uIcon
= bShowIcons
? IDI_MENUFOLDER
: 0;
1098 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuFolder
;
1099 myIDMap
[idCmd
] = ShellSubMenuFolder
;
1100 menuiteminfo
.dwItemData
= (ULONG_PTR
)g_MenuIDString
;
1102 else if (!bShortcut
&& (files_
.size()==1))
1104 uIcon
= bShowIcons
? IDI_MENUFILE
: 0;
1105 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuFile
;
1106 myIDMap
[idCmd
] = ShellSubMenuFile
;
1108 else if (bShortcut
&& (files_
.size()==1))
1110 uIcon
= bShowIcons
? IDI_MENULINK
: 0;
1111 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuLink
;
1112 myIDMap
[idCmd
] = ShellSubMenuLink
;
1114 else if (!files_
.empty())
1116 uIcon
= bShowIcons
? IDI_MENUMULTIPLE
: 0;
1117 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenuMultiple
;
1118 myIDMap
[idCmd
] = ShellSubMenuMultiple
;
1122 myIDMap
[idCmd
- idCmdFirst
] = ShellSubMenu
;
1123 myIDMap
[idCmd
] = ShellSubMenu
;
1125 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
| MIIM_STRING
;
1128 menuiteminfo
.fMask
|= MIIM_BITMAP
;
1129 menuiteminfo
.hbmpItem
= SysInfo::Instance().IsVistaOrLater() ? m_iconBitmapUtils
.IconToBitmapPARGB32(g_hResInst
, uIcon
) : HBMMENU_CALLBACK
;
1131 menuiteminfo
.hSubMenu
= subMenu
;
1132 menuiteminfo
.wID
= idCmd
++;
1133 InsertMenuItem(hMenu
, indexMenu
++, TRUE
, &menuiteminfo
);
1136 InsertMenu(hMenu
, indexMenu
++, MF_SEPARATOR
|MF_BYPOSITION
, 0, NULL
); idCmd
++;
1140 //return number of menu items added
1141 return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS
, 0, (USHORT
)(idCmd
- idCmdFirst
)));
1144 void CShellExt::TweakMenu(HMENU hMenu
)
1146 MENUINFO MenuInfo
= {};
1147 MenuInfo
.cbSize
= sizeof(MenuInfo
);
1148 MenuInfo
.fMask
= MIM_STYLE
| MIM_APPLYTOSUBMENUS
;
1149 MenuInfo
.dwStyle
= MNS_CHECKORBMP
;
1150 SetMenuInfo(hMenu
, &MenuInfo
);
1153 void CShellExt::AddPathCommand(tstring
& gitCmd
, LPCTSTR command
, bool bFilesAllowed
)
1156 gitCmd
+= _T(" /path:\"");
1157 if ((bFilesAllowed
) && !files_
.empty())
1158 gitCmd
+= files_
.front();
1164 void CShellExt::AddPathFileCommand(tstring
& gitCmd
, LPCTSTR command
)
1166 tstring tempfile
= WriteFileListToTempFile();
1168 gitCmd
+= _T(" /pathfile:\"");
1171 gitCmd
+= _T(" /deletepathfile");
1174 void CShellExt::AddPathFileDropCommand(tstring
& gitCmd
, LPCTSTR command
)
1176 tstring tempfile
= WriteFileListToTempFile();
1178 gitCmd
+= _T(" /pathfile:\"");
1181 gitCmd
+= _T(" /deletepathfile");
1182 gitCmd
+= _T(" /droptarget:\"");
1187 STDMETHODIMP
CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi
)
1191 return InvokeCommand_Wrap(lpcmi
);
1193 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
1199 // This is called when you invoke a command on the menu:
1200 STDMETHODIMP
CShellExt::InvokeCommand_Wrap(LPCMINVOKECOMMANDINFO lpcmi
)
1202 PreserveChdir preserveChdir
;
1203 HRESULT hr
= E_INVALIDARG
;
1207 if (!files_
.empty() || !folder_
.empty())
1209 UINT_PTR idCmd
= LOWORD(lpcmi
->lpVerb
);
1211 if (HIWORD(lpcmi
->lpVerb
))
1213 stdstring verb
= stdstring(MultibyteToWide(lpcmi
->lpVerb
));
1214 std::map
<stdstring
, UINT_PTR
>::const_iterator verb_it
= myVerbsMap
.lower_bound(verb
);
1215 if (verb_it
!= myVerbsMap
.end() && verb_it
->first
== verb
)
1216 idCmd
= verb_it
->second
;
1221 // See if we have a handler interface for this id
1222 std::map
<UINT_PTR
, UINT_PTR
>::const_iterator id_it
= myIDMap
.lower_bound(idCmd
);
1223 if (id_it
!= myIDMap
.end() && id_it
->first
== idCmd
)
1225 tstring tortoiseProcPath
= CPathUtils::GetAppDirectory(g_hmodThisDll
) + _T("TortoiseGitProc.exe");
1226 tstring tortoiseMergePath
= CPathUtils::GetAppDirectory(g_hmodThisDll
) + _T("TortoiseGitMerge.exe");
1228 //TortoiseGitProc expects a command line of the form:
1229 //"/command:<commandname> /pathfile:<path> /startrev:<startrevision> /endrev:<endrevision> /deletepathfile
1231 //"/command:<commandname> /path:<path> /startrev:<startrevision> /endrev:<endrevision>
1233 //* path is a path to a single file/directory for commands which only act on single items (log, checkout, ...)
1234 //* pathfile is a path to a temporary file which contains a list of file paths
1235 stdstring gitCmd
= _T(" /command:");
1237 switch (id_it
->second
)
1242 TCHAR syncSeq
[12] = { 0 };
1243 _stprintf_s(syncSeq
, _T("%d"), g_syncSeq
++);
1244 AddPathCommand(gitCmd
, L
"sync", false);
1245 gitCmd
+= _T(" /seq:");
1249 case ShellMenuSubSync
:
1250 AddPathFileCommand(gitCmd
, L
"subsync");
1251 if (itemStatesFolder
& ITEMIS_SUBMODULECONTAINER
|| (itemStates
& ITEMIS_SUBMODULECONTAINER
&& itemStates
& ITEMIS_WCROOT
&& itemStates
& ITEMIS_ONLYONE
))
1253 gitCmd
+= _T(" /bkpath:\"");
1258 case ShellMenuUpdateExt
:
1259 AddPathFileCommand(gitCmd
, L
"subupdate");
1260 if (itemStatesFolder
& ITEMIS_SUBMODULECONTAINER
|| (itemStates
& ITEMIS_SUBMODULECONTAINER
&& itemStates
& ITEMIS_WCROOT
&& itemStates
& ITEMIS_ONLYONE
))
1262 gitCmd
+= _T(" /bkpath:\"");
1267 case ShellMenuCommit
:
1268 AddPathFileCommand(gitCmd
, L
"commit");
1271 AddPathFileCommand(gitCmd
, L
"add");
1273 case ShellMenuIgnore
:
1274 AddPathFileCommand(gitCmd
, L
"ignore");
1276 case ShellMenuIgnoreCaseSensitive
:
1277 AddPathFileCommand(gitCmd
, L
"ignore");
1278 gitCmd
+= _T(" /onlymask");
1280 case ShellMenuDeleteIgnore
:
1281 AddPathFileCommand(gitCmd
, L
"ignore");
1282 gitCmd
+= _T(" /delete");
1284 case ShellMenuDeleteIgnoreCaseSensitive
:
1285 AddPathFileCommand(gitCmd
, L
"ignore");
1286 gitCmd
+= _T(" /delete /onlymask");
1288 case ShellMenuUnIgnore
:
1289 AddPathFileCommand(gitCmd
, L
"unignore");
1291 case ShellMenuUnIgnoreCaseSensitive
:
1292 AddPathFileCommand(gitCmd
, L
"unignore");
1293 gitCmd
+= _T(" /onlymask");
1295 case ShellMenuMergeAbort
:
1296 AddPathCommand(gitCmd
, L
"merge", false);
1297 gitCmd
+= _T(" /abort");
1299 case ShellMenuRevert
:
1300 AddPathFileCommand(gitCmd
, L
"revert");
1302 case ShellMenuCleanup
:
1303 AddPathFileCommand(gitCmd
, L
"cleanup");
1305 case ShellMenuSendMail
:
1306 AddPathFileCommand(gitCmd
, L
"sendmail");
1308 case ShellMenuResolve
:
1309 AddPathFileCommand(gitCmd
, L
"resolve");
1311 case ShellMenuSwitch
:
1312 AddPathCommand(gitCmd
, L
"switch", false);
1314 case ShellMenuExport
:
1315 AddPathCommand(gitCmd
, L
"export", false);
1317 case ShellMenuAbout
:
1318 gitCmd
+= _T("about");
1320 case ShellMenuCreateRepos
:
1321 AddPathCommand(gitCmd
, L
"repocreate", false);
1323 case ShellMenuMerge
:
1324 AddPathCommand(gitCmd
, L
"merge", false);
1327 AddPathCommand(gitCmd
, L
"copy", true);
1329 case ShellMenuSettings
:
1330 AddPathCommand(gitCmd
, L
"settings", true);
1333 gitCmd
+= _T("help");
1335 case ShellMenuRename
:
1336 AddPathCommand(gitCmd
, L
"rename", true);
1338 case ShellMenuRemove
:
1339 AddPathFileCommand(gitCmd
, L
"remove");
1341 case ShellMenuRemoveKeep
:
1342 AddPathFileCommand(gitCmd
, L
"remove");
1343 gitCmd
+= _T(" /keep");
1346 gitCmd
+= _T("diff /path:\"");
1347 if (files_
.size() == 1)
1348 gitCmd
+= files_
.front();
1349 else if (files_
.size() == 2)
1351 std::vector
<stdstring
>::iterator I
= files_
.begin();
1354 gitCmd
+= _T("\" /path2:\"");
1360 if (GetAsyncKeyState(VK_SHIFT
) & 0x8000)
1361 gitCmd
+= _T(" /alternative");
1363 case ShellMenuDiffLater
:
1364 if (lpcmi
->fMask
& CMIC_MASK_CONTROL_DOWN
)
1367 regDiffLater
.removeValue();
1369 else if (files_
.size() == 1)
1371 if (std::wstring(regDiffLater
).empty())
1374 regDiffLater
= files_
[0];
1378 AddPathCommand(gitCmd
, L
"diff", true);
1379 gitCmd
+= _T(" /path2:\"");
1380 gitCmd
+= std::wstring(regDiffLater
);
1382 if (GetAsyncKeyState(VK_SHIFT
) & 0x8000)
1383 gitCmd
+= _T(" /alternative");
1384 regDiffLater
.removeValue();
1392 case ShellMenuPrevDiff
:
1393 AddPathCommand(gitCmd
, L
"prevdiff", true);
1394 if (GetAsyncKeyState(VK_SHIFT
) & 0x8000)
1395 gitCmd
+= _T(" /alternative");
1397 case ShellMenuDiffTwo
:
1398 AddPathCommand(gitCmd
, L
"diffcommits", true);
1400 case ShellMenuDropCopyAdd
:
1401 AddPathFileDropCommand(gitCmd
, L
"dropcopyadd");
1403 case ShellMenuDropCopy
:
1404 AddPathFileDropCommand(gitCmd
, L
"dropcopy");
1406 case ShellMenuDropCopyRename
:
1407 AddPathFileDropCommand(gitCmd
, L
"dropcopy");
1408 gitCmd
+= _T("\" /rename";)
1410 case ShellMenuDropMove
:
1411 AddPathFileDropCommand(gitCmd
, L
"dropmove");
1413 case ShellMenuDropMoveRename
:
1414 AddPathFileDropCommand(gitCmd
, L
"dropmove");
1415 gitCmd
+= _T("\" /rename";)
1417 case ShellMenuDropExport
:
1418 AddPathFileDropCommand(gitCmd
, L
"dropexport");
1420 case ShellMenuDropExportExtended
:
1421 AddPathFileDropCommand(gitCmd
, L
"dropexport");
1422 gitCmd
+= _T(" /extended");
1425 case ShellMenuLogSubmoduleFolder
:
1426 AddPathCommand(gitCmd
, L
"log", true);
1427 if (id_it
->second
== ShellMenuLogSubmoduleFolder
)
1428 gitCmd
+= _T(" /submodule");
1430 case ShellMenuDaemon
:
1431 AddPathCommand(gitCmd
, L
"daemon", true);
1433 case ShellMenuRevisionGraph
:
1434 AddPathCommand(gitCmd
, L
"revisiongraph", true);
1436 case ShellMenuConflictEditor
:
1437 AddPathCommand(gitCmd
, L
"conflicteditor", true);
1439 case ShellMenuGitSVNRebase
:
1440 AddPathCommand(gitCmd
, L
"svnrebase", false);
1442 case ShellMenuGitSVNDCommit
:
1443 AddPathCommand(gitCmd
, L
"svndcommit", true);
1445 case ShellMenuGitSVNDFetch
:
1446 AddPathCommand(gitCmd
, L
"svnfetch", false);
1448 case ShellMenuGitSVNIgnore
:
1449 AddPathCommand(gitCmd
, L
"svnignore", false);
1451 case ShellMenuRebase
:
1452 AddPathCommand(gitCmd
, L
"rebase", false);
1454 case ShellMenuShowChanged
:
1455 if (files_
.size() > 1)
1457 AddPathFileCommand(gitCmd
, L
"repostatus");
1461 AddPathCommand(gitCmd
, L
"repostatus", true);
1464 case ShellMenuRepoBrowse
:
1465 AddPathCommand(gitCmd
, L
"repobrowser", false);
1467 case ShellMenuRefBrowse
:
1468 AddPathCommand(gitCmd
, L
"refbrowse", false);
1470 case ShellMenuRefLog
:
1471 AddPathCommand(gitCmd
, L
"reflog", false);
1473 case ShellMenuStashSave
:
1474 AddPathCommand(gitCmd
, L
"stashsave", true);
1476 case ShellMenuStashApply
:
1477 AddPathCommand(gitCmd
, L
"stashapply", false);
1479 case ShellMenuStashPop
:
1480 AddPathCommand(gitCmd
, L
"stashpop", false);
1482 case ShellMenuStashList
:
1483 AddPathCommand(gitCmd
, L
"reflog", false);
1484 gitCmd
+= _T(" /ref:refs/stash");
1486 case ShellMenuBisectStart
:
1487 AddPathCommand(gitCmd
, L
"bisect", false);
1488 gitCmd
+= _T("\" /start");
1490 case ShellMenuBisectGood
:
1491 AddPathCommand(gitCmd
, L
"bisect", false);
1492 gitCmd
+= _T("\" /good");
1494 case ShellMenuBisectBad
:
1495 AddPathCommand(gitCmd
, L
"bisect", false);
1496 gitCmd
+= _T("\" /bad");
1498 case ShellMenuBisectReset
:
1499 AddPathCommand(gitCmd
, L
"bisect", false);
1500 gitCmd
+= _T("\" /reset");
1502 case ShellMenuSubAdd
:
1503 AddPathCommand(gitCmd
, L
"subadd", false);
1505 case ShellMenuBlame
:
1506 AddPathCommand(gitCmd
, L
"blame", true);
1508 case ShellMenuApplyPatch
:
1509 if ((itemStates
& ITEMIS_PATCHINCLIPBOARD
) && ((~itemStates
) & ITEMIS_PATCHFILE
))
1511 // if there's a patch file in the clipboard, we save it
1512 // to a temporary file and tell TortoiseGitMerge to use that one
1513 UINT cFormat
= RegisterClipboardFormat(_T("TGIT_UNIFIEDDIFF"));
1514 if ((cFormat
)&&(OpenClipboard(NULL
)))
1516 HGLOBAL hglb
= GetClipboardData(cFormat
);
1517 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1519 DWORD len
= GetTortoiseGitTempPath(0, NULL
);
1520 std::unique_ptr
<TCHAR
[]> path(new TCHAR
[len
+ 1]);
1521 std::unique_ptr
<TCHAR
[]> tempF(new TCHAR
[len
+ 100]);
1522 GetTortoiseGitTempPath(len
+ 1, path
.get());
1523 GetTempFileName(path
.get(), TEXT("git"), 0, tempF
.get());
1524 std::wstring sTempFile
= std::wstring(tempF
.get());
1527 size_t patchlen
= strlen(lpstr
);
1528 _tfopen_s(&outFile
, sTempFile
.c_str(), _T("wb"));
1531 size_t size
= fwrite(lpstr
, sizeof(char), patchlen
, outFile
);
1532 if (size
== patchlen
)
1534 itemStates
|= ITEMIS_PATCHFILE
;
1536 files_
.push_back(sTempFile
);
1544 if (itemStates
& ITEMIS_PATCHFILE
)
1546 gitCmd
= _T(" /diff:\"");
1547 if (!files_
.empty())
1549 gitCmd
+= files_
.front();
1550 if (itemStatesFolder
& ITEMIS_FOLDERINGIT
)
1552 gitCmd
+= _T("\" /patchpath:\"");
1558 if (itemStates
& ITEMIS_INVERSIONEDFOLDER
)
1559 gitCmd
+= _T("\" /wc");
1565 gitCmd
= _T(" /patchpath:\"");
1566 if (!files_
.empty())
1567 gitCmd
+= files_
.front();
1573 myVerbsIDMap
.clear();
1575 RunCommand(tortoiseMergePath
, gitCmd
, _T("TortoiseGitMerge launch failed"));
1578 case ShellMenuClipPaste
:
1579 if (WriteClipboardPathsToTempFile(tempfile
))
1582 UINT cPrefDropFormat
= RegisterClipboardFormat(_T("Preferred DropEffect"));
1583 if (cPrefDropFormat
)
1585 if (OpenClipboard(lpcmi
->hwnd
))
1587 HGLOBAL hglb
= GetClipboardData(cPrefDropFormat
);
1590 DWORD
* effect
= (DWORD
*) GlobalLock(hglb
);
1591 if (*effect
== DROPEFFECT_MOVE
)
1600 gitCmd
+= _T("pastecopy /pathfile:\"");
1602 gitCmd
+= _T("pastemove /pathfile:\"");
1605 gitCmd
+= _T(" /deletepathfile");
1606 gitCmd
+= _T(" /droptarget:\"");
1612 case ShellMenuClone
:
1613 AddPathCommand(gitCmd
, L
"clone", false);
1616 AddPathCommand(gitCmd
, L
"pull", false);
1619 AddPathCommand(gitCmd
, L
"push", false);
1621 case ShellMenuBranch
:
1622 AddPathCommand(gitCmd
, L
"branch", false);
1625 AddPathCommand(gitCmd
, L
"tag", false);
1627 case ShellMenuFormatPatch
:
1628 AddPathCommand(gitCmd
, L
"formatpatch", false);
1630 case ShellMenuImportPatch
:
1631 AddPathFileCommand(gitCmd
, L
"importpatch");
1633 case ShellMenuFetch
:
1634 AddPathCommand(gitCmd
, L
"fetch", false);
1640 } // switch (id_it->second)
1641 if (!gitCmd
.empty())
1643 gitCmd
+= _T(" /hwnd:");
1644 TCHAR buf
[30] = { 0 };
1645 _stprintf_s(buf
, _T("%p"), (void*)lpcmi
->hwnd
);
1648 myVerbsIDMap
.clear();
1650 RunCommand(tortoiseProcPath
, gitCmd
, _T("TortoiseProc launch failed"));
1653 } // if (id_it != myIDMap.end() && id_it->first == idCmd)
1654 } // if (files_.empty() || folder_.empty())
1659 // This is for the status bar and things like that:
1660 STDMETHODIMP
CShellExt::GetCommandString(UINT_PTR idCmd
,
1662 UINT FAR
* reserved
,
1668 return GetCommandString_Wrap(idCmd
, uFlags
, reserved
, pszName
, cchMax
);
1670 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
1676 // This is for the status bar and things like that:
1677 STDMETHODIMP
CShellExt::GetCommandString_Wrap(UINT_PTR idCmd
,
1679 UINT FAR
* /*reserved*/,
1683 PreserveChdir preserveChdir
;
1684 //do we know the id?
1685 std::map
<UINT_PTR
, UINT_PTR
>::const_iterator id_it
= myIDMap
.lower_bound(idCmd
);
1686 if (id_it
== myIDMap
.end() || id_it
->first
!= idCmd
)
1688 return E_INVALIDARG
; //no, we don't
1692 HRESULT hr
= E_INVALIDARG
;
1694 MAKESTRING(IDS_MENUDESCDEFAULT
);
1696 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
1698 if (menuInfo
[menuIndex
].command
== (GitCommands
)id_it
->second
)
1700 MAKESTRING(menuInfo
[menuIndex
].menuDescID
);
1706 const TCHAR
* desc
= stringtablebuffer
;
1711 std::string help
= WideToMultibyte(desc
);
1712 lstrcpynA(pszName
, help
.c_str(), cchMax
);
1718 wide_string help
= desc
;
1719 lstrcpynW((LPWSTR
)pszName
, help
.c_str(), cchMax
);
1725 std::map
<UINT_PTR
, stdstring
>::const_iterator verb_id_it
= myVerbsIDMap
.lower_bound(idCmd
);
1726 if (verb_id_it
!= myVerbsIDMap
.end() && verb_id_it
->first
== idCmd
)
1728 std::string help
= WideToMultibyte(verb_id_it
->second
);
1729 lstrcpynA(pszName
, help
.c_str(), cchMax
);
1736 std::map
<UINT_PTR
, stdstring
>::const_iterator verb_id_it
= myVerbsIDMap
.lower_bound(idCmd
);
1737 if (verb_id_it
!= myVerbsIDMap
.end() && verb_id_it
->first
== idCmd
)
1739 wide_string help
= verb_id_it
->second
;
1740 CTraceToOutputDebugString::Instance()(__FUNCTION__
": verb : %ws\n", help
.c_str());
1741 lstrcpynW((LPWSTR
)pszName
, help
.c_str(), cchMax
);
1750 STDMETHODIMP
CShellExt::HandleMenuMsg(UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1754 return HandleMenuMsg_Wrap(uMsg
, wParam
, lParam
);
1756 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
1762 STDMETHODIMP
CShellExt::HandleMenuMsg_Wrap(UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1765 return HandleMenuMsg2(uMsg
, wParam
, lParam
, &res
);
1768 STDMETHODIMP
CShellExt::HandleMenuMsg2(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
)
1772 return HandleMenuMsg2_Wrap(uMsg
, wParam
, lParam
, pResult
);
1774 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
1780 STDMETHODIMP
CShellExt::HandleMenuMsg2_Wrap(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
)
1782 PreserveChdir preserveChdir
;
1785 if (pResult
== NULL
)
1792 case WM_MEASUREITEM
:
1794 MEASUREITEMSTRUCT
* lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
1797 lpmis
->itemWidth
= 16;
1798 lpmis
->itemHeight
= 16;
1805 DRAWITEMSTRUCT
* lpdis
= (DRAWITEMSTRUCT
*)lParam
;
1806 if ((lpdis
==NULL
)||(lpdis
->CtlType
!= ODT_MENU
))
1807 return S_OK
; //not for a menu
1808 resource
= GetMenuTextFromResource((int)myIDMap
[lpdis
->itemID
]);
1809 if (resource
== NULL
)
1811 HICON hIcon
= (HICON
)LoadImage(g_hResInst
, resource
, IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
1814 DrawIconEx(lpdis
->hDC
,
1816 lpdis
->rcItem
.top
+ (lpdis
->rcItem
.bottom
- lpdis
->rcItem
.top
- 16) / 2,
1818 0, NULL
, DI_NORMAL
);
1826 if (HIWORD(wParam
) != MF_POPUP
)
1828 int nChar
= LOWORD(wParam
);
1829 if (_istascii((wint_t)nChar
) && _istupper((wint_t)nChar
))
1830 nChar
= tolower(nChar
);
1831 // we have the char the user pressed, now search that char in all our
1833 std::vector
<UINT_PTR
> accmenus
;
1834 for (std::map
<UINT_PTR
, UINT_PTR
>::iterator It
= mySubMenuMap
.begin(); It
!= mySubMenuMap
.end(); ++It
)
1836 LPCTSTR resource
= GetMenuTextFromResource((int)mySubMenuMap
[It
->first
]);
1837 if (resource
== NULL
)
1839 szItem
= stringtablebuffer
;
1840 TCHAR
* amp
= _tcschr(szItem
, '&');
1844 int ampChar
= LOWORD(*amp
);
1845 if (_istascii((wint_t)ampChar
) && _istupper((wint_t)ampChar
))
1846 ampChar
= tolower(ampChar
);
1847 if (ampChar
== nChar
)
1849 // yep, we found a menu which has the pressed key
1850 // as an accelerator. Add that menu to the list to
1852 accmenus
.push_back(It
->first
);
1855 if (accmenus
.empty())
1857 // no menu with that accelerator key.
1858 *pResult
= MAKELONG(0, MNC_IGNORE
);
1861 if (accmenus
.size() == 1)
1863 // Only one menu with that accelerator key. We're lucky!
1864 // So just execute that menu entry.
1865 *pResult
= MAKELONG(accmenus
[0], MNC_EXECUTE
);
1868 if (accmenus
.size() > 1)
1870 // we have more than one menu item with this accelerator key!
1872 mif
.cbSize
= sizeof(MENUITEMINFO
);
1873 mif
.fMask
= MIIM_STATE
;
1874 for (std::vector
<UINT_PTR
>::iterator it
= accmenus
.begin(); it
!= accmenus
.end(); ++it
)
1876 GetMenuItemInfo((HMENU
)lParam
, (UINT
)*it
, TRUE
, &mif
);
1877 if (mif
.fState
== MFS_HILITE
)
1879 // this is the selected item, so select the next one
1881 if (it
== accmenus
.end())
1882 *pResult
= MAKELONG(accmenus
[0], MNC_SELECT
);
1884 *pResult
= MAKELONG(*it
, MNC_SELECT
);
1888 *pResult
= MAKELONG(accmenus
[0], MNC_SELECT
);
1899 LPCTSTR
CShellExt::GetMenuTextFromResource(int id
)
1901 TCHAR textbuf
[255] = { 0 };
1902 LPCTSTR resource
= NULL
;
1903 unsigned __int64 layout
= g_ShellCache
.GetMenuLayout();
1907 while (menuInfo
[menuIndex
].command
!= ShellMenuLastEntry
)
1909 if (menuInfo
[menuIndex
].command
== id
)
1911 MAKESTRING(menuInfo
[menuIndex
].menuTextID
);
1912 resource
= MAKEINTRESOURCE(menuInfo
[menuIndex
].iconID
);
1915 case ShellSubMenuMultiple
:
1916 case ShellSubMenuLink
:
1917 case ShellSubMenuFolder
:
1918 case ShellSubMenuFile
:
1923 space
= layout
& menuInfo
[menuIndex
].menuID
? 0 : 6;
1924 if (layout
& (menuInfo
[menuIndex
].menuID
))
1926 _tcscpy_s(textbuf
, 255, _T("Git "));
1927 _tcscat_s(textbuf
, 255, stringtablebuffer
);
1928 _tcscpy_s(stringtablebuffer
, 255, textbuf
);
1939 bool CShellExt::IsIllegalFolder(std::wstring folder
, int * cslidarray
)
1942 TCHAR buf
[MAX_PATH
] = {0}; //MAX_PATH ok, since SHGetSpecialFolderPath doesn't return the required buffer length!
1943 LPITEMIDLIST pidl
= NULL
;
1944 while (cslidarray
[i
])
1948 if (SHGetFolderLocation(NULL
, cslidarray
[i
-1], NULL
, 0, &pidl
)!=S_OK
)
1950 if (!SHGetPathFromIDList(pidl
, buf
))
1952 // not a file system path, definitely illegal for our use
1953 CoTaskMemFree(pidl
);
1956 CoTaskMemFree(pidl
);
1957 if (_tcslen(buf
)==0)
1959 if (_tcscmp(buf
, folder
.c_str())==0)
1965 bool CShellExt::InsertIgnoreSubmenus(UINT
&idCmd
, UINT idCmdFirst
, HMENU hMenu
, HMENU subMenu
, UINT
&indexMenu
, int &indexSubMenu
, unsigned __int64 topmenu
, bool bShowIcons
, UINT
/*uFlags*/)
1967 HMENU ignoresubmenu
= NULL
;
1968 int indexignoresub
= 0;
1969 bool bShowIgnoreMenu
= false;
1970 TCHAR maskbuf
[MAX_PATH
] = {0}; // MAX_PATH is ok, since this only holds a filename
1971 TCHAR ignorepath
[MAX_PATH
] = {0}; // MAX_PATH is ok, since this only holds a filename
1974 UINT icon
= bShowIcons
? IDI_IGNORE
: 0;
1976 std::vector
<stdstring
>::iterator I
= files_
.begin();
1977 if (_tcsrchr(I
->c_str(), '\\'))
1978 _tcscpy_s(ignorepath
, MAX_PATH
, _tcsrchr(I
->c_str(), '\\')+1);
1980 _tcscpy_s(ignorepath
, MAX_PATH
, I
->c_str());
1981 if ((itemStates
& ITEMIS_IGNORED
) && (!ignoredprops
.empty()))
1983 // check if the item name is ignored or the mask
1985 while ( (p
=ignoredprops
.find( ignorepath
,p
)) != -1 )
1987 if ( (p
==0 || ignoredprops
[p
-1]==TCHAR('\n'))
1988 && (p
+_tcslen(ignorepath
)==ignoredprops
.length() || ignoredprops
[p
+_tcslen(ignorepath
)+1]==TCHAR('\n')) )
1996 ignoresubmenu
= CreateMenu();
1997 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
1998 stdstring verb
= stdstring(ignorepath
);
1999 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2000 myVerbsMap
[verb
] = idCmd
;
2001 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2002 myVerbsIDMap
[idCmd
] = verb
;
2003 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnore
;
2004 myIDMap
[idCmd
++] = ShellMenuUnIgnore
;
2005 bShowIgnoreMenu
= true;
2007 _tcscpy_s(maskbuf
, MAX_PATH
, _T("*"));
2008 if (_tcsrchr(ignorepath
, '.'))
2010 _tcscat_s(maskbuf
, MAX_PATH
, _tcsrchr(ignorepath
, '.'));
2011 p
= ignoredprops
.find(maskbuf
);
2013 ((ignoredprops
.compare(maskbuf
)==0) || (ignoredprops
.find('\n', p
)==p
+_tcslen(maskbuf
)+1) || (ignoredprops
.rfind('\n', p
)==p
-1)))
2015 if (ignoresubmenu
==NULL
)
2016 ignoresubmenu
= CreateMenu();
2018 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, maskbuf
);
2019 stdstring verb
= stdstring(maskbuf
);
2020 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2021 myVerbsMap
[verb
] = idCmd
;
2022 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2023 myVerbsIDMap
[idCmd
] = verb
;
2024 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnoreCaseSensitive
;
2025 myIDMap
[idCmd
++] = ShellMenuUnIgnoreCaseSensitive
;
2026 bShowIgnoreMenu
= true;
2030 else if ((itemStates
& ITEMIS_IGNORED
) == 0)
2032 bShowIgnoreMenu
= true;
2033 ignoresubmenu
= CreateMenu();
2034 if (itemStates
& ITEMIS_ONLYONE
)
2036 if (itemStates
& ITEMIS_INGIT
)
2038 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2039 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuDeleteIgnore
;
2040 myIDMap
[idCmd
++] = ShellMenuDeleteIgnore
;
2042 _tcscpy_s(maskbuf
, MAX_PATH
, _T("*"));
2043 if (!(itemStates
& ITEMIS_FOLDER
) && _tcsrchr(ignorepath
, '.'))
2045 _tcscat_s(maskbuf
, MAX_PATH
, _tcsrchr(ignorepath
, '.'));
2046 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, maskbuf
);
2047 stdstring verb
= stdstring(maskbuf
);
2048 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2049 myVerbsMap
[verb
] = idCmd
;
2050 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2051 myVerbsIDMap
[idCmd
] = verb
;
2052 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuDeleteIgnoreCaseSensitive
;
2053 myIDMap
[idCmd
++] = ShellMenuDeleteIgnoreCaseSensitive
;
2058 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2059 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnore
;
2060 myIDMap
[idCmd
++] = ShellMenuIgnore
;
2062 _tcscpy_s(maskbuf
, MAX_PATH
, _T("*"));
2063 if (!(itemStates
& ITEMIS_FOLDER
) && _tcsrchr(ignorepath
, '.'))
2065 _tcscat_s(maskbuf
, MAX_PATH
, _tcsrchr(ignorepath
, '.'));
2066 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, maskbuf
);
2067 stdstring verb
= stdstring(maskbuf
);
2068 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2069 myVerbsMap
[verb
] = idCmd
;
2070 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2071 myVerbsIDMap
[idCmd
] = verb
;
2072 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreCaseSensitive
;
2073 myIDMap
[idCmd
++] = ShellMenuIgnoreCaseSensitive
;
2079 if (itemStates
& ITEMIS_INGIT
)
2081 MAKESTRING(IDS_MENUDELETEIGNOREMULTIPLE
);
2082 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2083 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2084 stdstring verb
= stdstring(ignorepath
);
2085 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2086 myVerbsMap
[verb
] = idCmd
;
2087 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2088 myVerbsIDMap
[idCmd
] = verb
;
2089 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuDeleteIgnore
;
2090 myIDMap
[idCmd
++] = ShellMenuDeleteIgnore
;
2092 MAKESTRING(IDS_MENUDELETEIGNOREMULTIPLEMASK
);
2093 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2094 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2095 verb
= stdstring(ignorepath
);
2096 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2097 myVerbsMap
[verb
] = idCmd
;
2098 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2099 myVerbsIDMap
[idCmd
] = verb
;
2100 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuDeleteIgnoreCaseSensitive
;
2101 myIDMap
[idCmd
++] = ShellMenuDeleteIgnoreCaseSensitive
;
2105 MAKESTRING(IDS_MENUIGNOREMULTIPLE
);
2106 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2107 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2108 stdstring verb
= stdstring(ignorepath
);
2109 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2110 myVerbsMap
[verb
] = idCmd
;
2111 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2112 myVerbsIDMap
[idCmd
] = verb
;
2113 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnore
;
2114 myIDMap
[idCmd
++] = ShellMenuIgnore
;
2116 MAKESTRING(IDS_MENUIGNOREMULTIPLEMASK
);
2117 _stprintf_s(ignorepath
, MAX_PATH
, stringtablebuffer
, files_
.size());
2118 InsertMenu(ignoresubmenu
, indexignoresub
++, MF_BYPOSITION
| MF_STRING
, idCmd
, ignorepath
);
2119 verb
= stdstring(ignorepath
);
2120 myVerbsMap
[verb
] = idCmd
- idCmdFirst
;
2121 myVerbsMap
[verb
] = idCmd
;
2122 myVerbsIDMap
[idCmd
- idCmdFirst
] = verb
;
2123 myVerbsIDMap
[idCmd
] = verb
;
2124 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreCaseSensitive
;
2125 myIDMap
[idCmd
++] = ShellMenuIgnoreCaseSensitive
;
2130 if (bShowIgnoreMenu
)
2132 MENUITEMINFO menuiteminfo
;
2133 SecureZeroMemory(&menuiteminfo
, sizeof(menuiteminfo
));
2134 menuiteminfo
.cbSize
= sizeof(menuiteminfo
);
2135 menuiteminfo
.fMask
= MIIM_FTYPE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_DATA
| MIIM_STRING
;
2138 menuiteminfo
.fMask
|= MIIM_BITMAP
;
2139 menuiteminfo
.hbmpItem
= SysInfo::Instance().IsVistaOrLater() ? m_iconBitmapUtils
.IconToBitmapPARGB32(g_hResInst
, icon
) : m_iconBitmapUtils
.IconToBitmap(g_hResInst
, icon
);
2141 menuiteminfo
.fType
= MFT_STRING
;
2142 menuiteminfo
.hSubMenu
= ignoresubmenu
;
2143 menuiteminfo
.wID
= idCmd
;
2144 SecureZeroMemory(stringtablebuffer
, sizeof(stringtablebuffer
));
2145 if (itemStates
& ITEMIS_IGNORED
)
2146 GetMenuTextFromResource(ShellMenuUnIgnoreSub
);
2147 else if (itemStates
& ITEMIS_INGIT
)
2148 GetMenuTextFromResource(ShellMenuDeleteIgnoreSub
);
2150 GetMenuTextFromResource(ShellMenuIgnoreSub
);
2151 menuiteminfo
.dwTypeData
= stringtablebuffer
;
2152 menuiteminfo
.cch
= (UINT
)min(_tcslen(menuiteminfo
.dwTypeData
), UINT_MAX
);
2154 InsertMenuItem((topmenu
& MENUIGNORE
) ? hMenu
: subMenu
, (topmenu
& MENUIGNORE
) ? indexMenu
++ : indexSubMenu
++, TRUE
, &menuiteminfo
);
2155 if (itemStates
& ITEMIS_IGNORED
)
2157 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuUnIgnoreSub
;
2158 myIDMap
[idCmd
++] = ShellMenuUnIgnoreSub
;
2162 myIDMap
[idCmd
- idCmdFirst
] = ShellMenuIgnoreSub
;
2163 myIDMap
[idCmd
++] = ShellMenuIgnoreSub
;
2166 return bShowIgnoreMenu
;
2169 void CShellExt::RunCommand(const tstring
& path
, const tstring
& command
, LPCTSTR errorMessage
)
2171 if (CCreateProcessHelper::CreateProcessDetached(path
.c_str(), const_cast<TCHAR
*>(command
.c_str())))
2173 // process started - exit
2177 MessageBox(NULL
, CFormatMessageWrapper(), errorMessage
, MB_OK
| MB_ICONINFORMATION
);
2180 bool CShellExt::ShouldInsertItem(const MenuInfo
& item
) const
2182 return ShouldEnableMenu(item
.first
) || ShouldEnableMenu(item
.second
) ||
2183 ShouldEnableMenu(item
.third
) || ShouldEnableMenu(item
.fourth
);
2186 bool CShellExt::ShouldEnableMenu(const YesNoPair
& pair
) const
2188 if (pair
.yes
&& pair
.no
)
2190 if (((pair
.yes
& itemStates
) == pair
.yes
) && ((pair
.no
& (~itemStates
)) == pair
.no
))
2193 else if ((pair
.yes
) && ((pair
.yes
& itemStates
) == pair
.yes
))
2195 else if ((pair
.no
) && ((pair
.no
& (~itemStates
)) == pair
.no
))