1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013-2015 - TortoiseSVN
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.
23 #include "..\\TortoiseShell\resource.h"
24 #include "GitStatusListCtrl.h"
25 #include "MessageBox.h"
27 #include "UnicodeUtils.h"
29 #include "PathUtils.h"
31 #include "StringUtils.h"
32 #include "LoglistUtils.h"
36 #include "GitProgressDlg.h"
37 #include "SysImageList.h"
41 #include "GitAdminDir.h"
42 #include "GitDataObject.h"
43 #include "ProgressCommands/AddProgressCommand.h"
45 #include "FormatMessageWrapper.h"
46 #include "BrowseFolder.h"
49 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
50 = ::RegisterWindowMessage(L
"GITSLNM_ITEMCOUNTCHANGED");
51 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
52 = ::RegisterWindowMessage(L
"GITSLNM_NEEDSREFRESH");
53 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
54 = ::RegisterWindowMessage(L
"GITSLNM_ADDFILE");
55 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
56 = ::RegisterWindowMessage(L
"GITSLNM_CHECKCHANGED");
57 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
58 = ::RegisterWindowMessage(L
"GITSLNM_ITEMCHANGED");
62 bool operator() (const std::wstring
& lhs
, const std::wstring
& rhs
) const
64 // no logical comparison here: we need this sorted strictly
65 return _wcsicmp(lhs
.c_str(), rhs
.c_str()) < 0;
69 class CIShellFolderHook
: public IShellFolder
72 CIShellFolderHook(LPSHELLFOLDER sf
, const CTGitPathList
& pathlist
)
76 // it seems the paths in the HDROP need to be sorted, otherwise
77 // it might not work properly or even crash.
78 // to get the items sorted, we just add them to a set
79 for (int i
= 0; i
< pathlist
.GetCount(); ++i
)
80 sortedpaths
.insert((LPCTSTR
)g_Git
.CombinePath(pathlist
[i
].GetWinPath()));
83 ~CIShellFolderHook() { m_iSF
->Release(); }
85 // IUnknown methods --------
86 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, __RPC__deref_out
void **ppvObject
) { return m_iSF
->QueryInterface(riid
, ppvObject
); }
87 virtual ULONG STDMETHODCALLTYPE
AddRef(void) { return m_iSF
->AddRef(); }
88 virtual ULONG STDMETHODCALLTYPE
Release(void) { return m_iSF
->Release(); }
90 // IShellFolder methods ----
91 virtual HRESULT STDMETHODCALLTYPE
GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
);
93 virtual HRESULT STDMETHODCALLTYPE
CompareIDs(LPARAM lParam
, __RPC__in PCUIDLIST_RELATIVE pidl1
, __RPC__in PCUIDLIST_RELATIVE pidl2
) { return m_iSF
->CompareIDs(lParam
, pidl1
, pidl2
); }
94 virtual HRESULT STDMETHODCALLTYPE
GetDisplayNameOf(__RPC__in_opt PCUITEMID_CHILD pidl
, SHGDNF uFlags
, __RPC__out STRRET
*pName
) { return m_iSF
->GetDisplayNameOf(pidl
, uFlags
, pName
); }
95 virtual HRESULT STDMETHODCALLTYPE
CreateViewObject(__RPC__in_opt HWND hwndOwner
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->CreateViewObject(hwndOwner
, riid
, ppv
); }
96 virtual HRESULT STDMETHODCALLTYPE
EnumObjects(__RPC__in_opt HWND hwndOwner
, SHCONTF grfFlags
, __RPC__deref_out_opt IEnumIDList
**ppenumIDList
) { return m_iSF
->EnumObjects(hwndOwner
, grfFlags
, ppenumIDList
); }
97 virtual HRESULT STDMETHODCALLTYPE
BindToObject(__RPC__in PCUIDLIST_RELATIVE pidl
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->BindToObject(pidl
, pbc
, riid
, ppv
); }
98 virtual HRESULT STDMETHODCALLTYPE
ParseDisplayName(__RPC__in_opt HWND hwnd
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in_string LPWSTR pszDisplayName
, __reserved ULONG
*pchEaten
, __RPC__deref_out_opt PIDLIST_RELATIVE
*ppidl
, __RPC__inout_opt ULONG
*pdwAttributes
) { return m_iSF
->ParseDisplayName(hwnd
, pbc
, pszDisplayName
, pchEaten
, ppidl
, pdwAttributes
); }
99 virtual HRESULT STDMETHODCALLTYPE
GetAttributesOf(UINT cidl
, __RPC__in_ecount_full_opt(cidl
) PCUITEMID_CHILD_ARRAY apidl
, __RPC__inout SFGAOF
*rgfInOut
) { return m_iSF
->GetAttributesOf(cidl
, apidl
, rgfInOut
); }
100 virtual HRESULT STDMETHODCALLTYPE
BindToStorage(__RPC__in PCUIDLIST_RELATIVE pidl
, __RPC__in_opt IBindCtx
*pbc
, __RPC__in REFIID riid
, __RPC__deref_out_opt
void **ppv
) { return m_iSF
->BindToStorage(pidl
, pbc
, riid
, ppv
); }
101 virtual HRESULT STDMETHODCALLTYPE
SetNameOf(__in_opt HWND hwnd
, __in PCUITEMID_CHILD pidl
, __in LPCWSTR pszName
, __in SHGDNF uFlags
, __deref_opt_out PITEMID_CHILD
*ppidlOut
) { return m_iSF
->SetNameOf(hwnd
, pidl
, pszName
, uFlags
, ppidlOut
); }
105 std::set
<std::wstring
, icompare
> sortedpaths
;
108 HRESULT STDMETHODCALLTYPE
CIShellFolderHook::GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
)
110 if (InlineIsEqualGUID(riid
, IID_IDataObject
))
112 HRESULT hres
= m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, IID_IDataObject
, nullptr, ppv
);
116 IDataObject
* idata
= (LPDATAOBJECT
)(*ppv
);
117 // the IDataObject returned here doesn't have a HDROP, so we create one ourselves and add it to the IDataObject
118 // the HDROP is necessary for most context menu handlers
120 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
122 nLength
+= (int)it
->size();
123 nLength
+= 1; // '\0' separator
125 int nBufferSize
= sizeof(DROPFILES
) + ((nLength
+ 5)*sizeof(TCHAR
));
126 auto pBuffer
= std::make_unique
<char[]>(nBufferSize
);
127 SecureZeroMemory(pBuffer
.get(), nBufferSize
);
128 DROPFILES
* df
= (DROPFILES
*)pBuffer
.get();
129 df
->pFiles
= sizeof(DROPFILES
);
131 TCHAR
* pFilenames
= (TCHAR
*)((BYTE
*)(pBuffer
.get()) + sizeof(DROPFILES
));
132 TCHAR
* pCurrentFilename
= pFilenames
;
134 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
136 wcscpy_s(pCurrentFilename
, it
->size() + 1, it
->c_str());
137 pCurrentFilename
+= it
->size();
138 *pCurrentFilename
= '\0'; // separator between file names
141 *pCurrentFilename
= '\0'; // terminate array
143 *pCurrentFilename
= '\0'; // terminate array
144 STGMEDIUM medium
= { 0 };
145 medium
.tymed
= TYMED_HGLOBAL
;
146 medium
.hGlobal
= GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, nBufferSize
+ 20);
149 LPVOID pMem
= ::GlobalLock(medium
.hGlobal
);
152 memcpy(pMem
, pBuffer
.get(), nBufferSize
);
153 GlobalUnlock(medium
.hGlobal
);
154 FORMATETC formatetc
= { 0 };
155 formatetc
.cfFormat
= CF_HDROP
;
156 formatetc
.dwAspect
= DVASPECT_CONTENT
;
157 formatetc
.lindex
= -1;
158 formatetc
.tymed
= TYMED_HGLOBAL
;
159 medium
.pUnkForRelease
= nullptr;
160 hres
= idata
->SetData(&formatetc
, &medium
, TRUE
);
164 return E_OUTOFMEMORY
;
168 // just pass it on to the base object
169 return m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, riid
, rgfReserved
, ppv
);
173 IContextMenu2
* g_IContext2
= nullptr;
174 IContextMenu3
* g_IContext3
= nullptr;
175 CIShellFolderHook
* g_pFolderhook
= nullptr;
176 IShellFolder
* g_psfDesktopFolder
= nullptr;
177 LPITEMIDLIST
* g_pidlArray
= nullptr;
178 int g_pidlArrayItems
= 0;
180 #define SHELL_MIN_CMD 10000
181 #define SHELL_MAX_CMD 20000
183 HRESULT CALLBACK
dfmCallback(IShellFolder
* /*psf*/, HWND
/*hwnd*/, IDataObject
* /*pdtobj*/, UINT uMsg
, WPARAM
/*wParam*/, LPARAM
/*lParam*/)
187 case DFM_MERGECONTEXTMENU
:
189 case DFM_INVOKECOMMAND
:
190 case DFM_INVOKECOMMANDEX
:
191 case DFM_GETDEFSTATICID
: // Required for Windows 7 to pick a default
197 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CResizableColumnsListCtrl
<CListCtrl
>)
198 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
199 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
200 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
202 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
203 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
204 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
205 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfo
)
208 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
211 ON_WM_SYSCOLORCHANGE()
212 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
215 CGitStatusListCtrl::CGitStatusListCtrl() : CResizableColumnsListCtrl
<CListCtrl
>()
216 , m_pbCanceled(nullptr)
217 , m_pStatLabel(nullptr)
218 , m_pSelectButton(nullptr)
219 , m_pConfirmButton(nullptr)
221 , m_bWaitCursor(false)
223 , m_bShowIgnores(false)
224 , m_bIgnoreRemoveOnly(false)
225 , m_bCheckChildrenWithParent(false)
226 , m_bUnversionedLast(true)
227 , m_bHasChangeLists(false)
228 , m_bHasCheckboxes(false)
229 , m_bCheckIfGroupsExist(true)
230 , m_bFileDropsEnabled(false)
232 , m_dwDefaultColumns(0)
233 , m_bAscending(false)
234 , m_nSortedColumn(-1)
235 , m_bHasExternalsFromDifferentRepos(false)
237 , m_bDoNotAutoselectSubmodules(false)
238 , m_bNoAutoselectMissing(false)
240 , m_hwndLogicalParent(nullptr)
241 , m_bHasUnversionedItems(FALSE
)
243 , m_bHasExternals(false)
244 , m_bHasIgnoreGroup(false)
254 , m_nShownUnversioned(0)
255 , m_nShownModified(0)
258 , m_nShownConflicted(0)
260 , m_nShownSubmodules(0)
262 , m_bShowFolders(false)
264 , m_dwContextMenus(0)
267 , m_pContextMenu(nullptr)
268 , m_hShellMenu(nullptr)
269 , m_nBackgroundImageID(0)
271 , m_bIsRevertTheirMy(false)
274 , m_nBlockItemChangeHandler(0)
277 m_bNoAutoselectMissing
= CRegDWORD(L
"Software\\TortoiseGit\\AutoselectMissingFiles", FALSE
) == TRUE
;
280 CGitStatusListCtrl::~CGitStatusListCtrl()
285 void CGitStatusListCtrl::ClearStatusArray()
288 CAutoWriteLock
locker(m_guard
);
289 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
291 delete m_arStatusArray
[i
];
293 m_arStatusArray
.clear();
297 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
299 CAutoWriteLock
locker(m_guard
);
301 m_dwDefaultColumns
= dwColumns
| 1;
302 m_dwContextMenus
= dwContextMenus
;
303 m_bHasCheckboxes
= bHasCheckboxes
;
305 m_bWaitCursor
= true;
307 // set the extended style of the listcontrol
308 DWORD exStyle
= LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
309 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
311 SetExtendedStyle(exStyle
);
312 CResizableColumnsListCtrl::Init();
314 SetWindowTheme(m_hWnd
, L
"Explorer", nullptr);
316 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
317 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
318 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
319 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
321 // keep CSorter::operator() in sync!!
322 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
323 = { IDS_STATUSLIST_COLFILE
324 , IDS_STATUSLIST_COLFILENAME
325 , IDS_STATUSLIST_COLEXT
326 , IDS_STATUSLIST_COLSTATUS
327 , IDS_STATUSLIST_COLADD
328 , IDS_STATUSLIST_COLDEL
329 , IDS_STATUSLIST_COLLASTMODIFIED
330 , IDS_STATUSLIST_COLSIZE
333 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
334 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
335 m_ColumnManager
.SetRightAlign(4);
336 m_ColumnManager
.SetRightAlign(5);
337 m_ColumnManager
.SetRightAlign(7);
342 m_pDropTarget
= std::make_unique
<CGitStatusListCtrlDropTarget
>(this);
343 RegisterDragDrop(m_hWnd
, m_pDropTarget
.get());
344 // create the supported formats:
345 FORMATETC ftetc
= { 0 };
346 ftetc
.dwAspect
= DVASPECT_CONTENT
;
348 ftetc
.tymed
= TYMED_HGLOBAL
;
349 ftetc
.cfFormat
= CF_HDROP
;
350 m_pDropTarget
->AddSuportedFormat(ftetc
);
354 m_bWaitCursor
= false;
357 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
359 m_nBackgroundImageID
= nID
;
360 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
363 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
364 , bool bUpdate
/* = FALSE */
365 , bool bShowIgnores
/* = false */
366 , bool bShowUnRev
/* = false */
367 , bool bShowLocalChangesIgnored
/* = false */)
369 CAutoWriteLock
locker(m_guard
);
373 m_bWaitCursor
= true;
376 m_bIsRevertTheirMy
= g_Git
.IsRebaseRunning() > 0;
378 int mask
= CGitStatusListCtrl::FILELIST_MODIFY
;
380 mask
|= CGitStatusListCtrl::FILELIST_IGNORE
;
382 mask
|= CGitStatusListCtrl::FILELIST_UNVER
;
383 if (bShowLocalChangesIgnored
)
384 mask
|= CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
;
385 this->UpdateFileList(mask
, bUpdate
, pathList
);
387 if (pathList
&& m_setDirectFiles
.empty())
389 // remember files which are selected by users so that those can be preselected
390 for (int i
= 0; i
< pathList
->GetCount(); ++i
)
391 if (!(*pathList
)[i
].IsDirectory())
392 m_setDirectFiles
.insert((*pathList
)[i
].GetGitPathString());
396 int refetchcounter
= 0;
399 // force the cursor to change
402 SetCursorPos(pt
.x
, pt
.y
);
404 m_mapFilenameToChecked
.clear();
405 //m_StatusUrlList.Clear();
406 bool bHasChangelists
= (m_changelists
.size() > 1 || (!m_changelists
.empty() && !m_bHasIgnoreGroup
));
407 m_changelists
.clear();
408 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
410 FileEntry
* entry
= m_arStatusArray
[i
];
411 if ( bHasChangelists
&& entry
->checked
)
413 // If change lists are present, remember all checked entries
414 CString path
= entry
->GetPath().GetGitPathString();
415 m_mapFilenameToChecked
[path
] = true;
417 if ( (entry
->status
==git_wc_status_unversioned
|| entry
->status
==git_wc_status_missing
) && entry
->checked
)
419 // The user manually selected an unversioned or missing file. We remember
420 // this so that the selection can be restored when refreshing.
421 CString path
= entry
->GetPath().GetGitPathString();
422 m_mapFilenameToChecked
[path
] = true;
424 else if ( entry
->status
> git_wc_status_normal
&& !entry
->checked
)
426 // The user manually deselected a versioned file. We remember
427 // this so that the deselection can be restored when refreshing.
428 CString path
= entry
->GetPath().GetGitPathString();
429 m_mapFilenameToChecked
[path
] = false;
433 // use a sorted path list to make sure we fetch the status of
434 // parent items first, *then* the child items (if any)
435 CTGitPathList sortedPathList
= pathList
;
436 sortedPathList
.SortByPathname();
441 m_bHasExternalsFromDifferentRepos
= FALSE
;
442 m_bHasExternals
= FALSE
;
443 m_bHasUnversionedItems
= FALSE
;
444 m_bHasChangeLists
= false;
445 m_bShowIgnores
= bShowIgnores
;
452 // first clear possible status data left from
453 // previous GetStatus() calls
456 m_StatusFileList
= sortedPathList
;
458 // Since Git_client_status() returns all files, even those in
459 // folders included with Git:externals we need to check if all
460 // files we get here belongs to the same repository.
461 // It is possible to commit changes in an external folder, as long
462 // as the folder belongs to the same repository (but another path),
463 // but it is not possible to commit all files if the externals are
464 // from a different repository.
466 // To check if all files belong to the same repository, we compare the
467 // UUID's - if they're identical then the files belong to the same
468 // repository and can be committed. But if they're different, then
469 // tell the user to commit all changes in the external folders
471 CStringA sUUID
; // holds the repo UUID
472 CTGitPathList arExtPaths
; // list of Git:external paths
478 m_nTargetCount
= sortedPathList
.GetCount();
480 GitStatus
status(m_pbCanceled
);
481 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
483 // This is a special case, where we've been given a list of files
484 // all from one folder
485 // We handle them by setting a status filter, then requesting the Git status of
486 // all the files in the directory, filtering for the ones we're interested in
487 status
.SetFilter(sortedPathList
);
489 // if all selected entries are files, we don't do a recursive status
490 // fetching. But if only one is a directory, we have to recurse.
491 git_depth_t depth
= git_depth_files
;
492 // We have set a filter. If all selected items were files or we fetch
493 // the status not recursively, then we have to include
494 // ignored items too - the user has selected them
495 bool bShowIgnoresRight
= true;
496 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
498 if (sortedPathList
[fcindex
].IsDirectory())
500 depth
= git_depth_infinity
;
501 bShowIgnoresRight
= false;
505 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
510 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
512 // check whether the path we want the status for is already fetched due to status-fetching
514 // this check is only done for file paths, because folder paths could be included already
515 // but not recursively
516 if (sortedPathList
[nTarget
].IsDirectory() || !GetListEntry(sortedPathList
[nTarget
]))
518 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
519 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
527 // remove the 'helper' files of conflicted items from the list.
528 // otherwise they would appear as unversioned files.
529 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
531 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
533 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
535 delete m_arStatusArray
[i
];
536 m_arStatusArray
.erase(m_arStatusArray
.cbegin() + i
);
542 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
547 SetCursorPos(pt
.x
, pt
.y
);
551 m_bWaitCursor
= false;
556 // Get the show-flags bitmap value which corresponds to a particular Git status
557 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
561 case git_wc_status_none
:
562 case git_wc_status_unversioned
:
563 return GITSLC_SHOWUNVERSIONED
;
564 case git_wc_status_ignored
:
566 return GITSLC_SHOWDIRECTS
;
567 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
568 case git_wc_status_normal
:
569 return GITSLC_SHOWNORMAL
;
570 case git_wc_status_added
:
571 return GITSLC_SHOWADDED
;
572 case git_wc_status_deleted
:
573 return GITSLC_SHOWREMOVED
;
574 case git_wc_status_modified
:
575 return GITSLC_SHOWMODIFIED
;
576 case git_wc_status_conflicted
:
577 return GITSLC_SHOWCONFLICTED
;
579 // we should NEVER get here!
586 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
588 m_bWaitCursor
= true;
593 WORD langID
= (WORD
)CRegStdDWORD(L
"Software\\TortoiseGit\\LanguageID", GetUserDefaultLangID());
596 CAutoWriteLock
locker(m_guard
);
600 m_nShownUnversioned
= 0;
601 m_nShownModified
= 0;
604 m_nShownConflicted
= 0;
606 m_nShownSubmodules
= 0;
610 if (UpdateStatusList
)
612 m_arStatusArray
.clear();
613 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
614 m_arStatusArray
.push_back(&m_StatusFileList
[i
]);
616 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
617 m_arStatusArray
.push_back(&m_UnRevFileList
[i
]);
619 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
620 m_arStatusArray
.push_back(&m_IgnoreFileList
[i
]);
623 if (m_nSortedColumn
>= 0)
625 CSorter
predicate(&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
626 std::stable_sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
630 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
632 //set default checkbox status
633 auto entry
= const_cast<CTGitPath
*>(m_arStatusArray
[i
]);
634 CString path
= entry
->GetGitPathString();
635 if (!m_mapFilenameToChecked
.empty() && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
636 entry
->m_Checked
= m_mapFilenameToChecked
[path
];
637 else if (!UseStoredCheckStatus
)
639 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
640 if (((entry
->m_Action
& dwCheck
) && !(m_bNoAutoselectMissing
&& entry
->m_Action
& CTGitPath::LOGACTIONS_MISSING
) || dwShow
& GITSLC_SHOWDIRECTFILES
&& m_setDirectFiles
.find(path
) != m_setDirectFiles
.end()) && autoSelectSubmodules
)
641 entry
->m_Checked
= true;
643 entry
->m_Checked
= false;
644 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
647 if (entry
->m_Action
& dwShow
)
649 AddEntry(entry
, langID
, index
);
655 AdjustColumnWidths();
658 GetStatisticsString();
660 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
661 HDITEM HeaderItem
= {0};
662 HeaderItem
.mask
= HDI_FORMAT
;
663 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
665 pHeader
->GetItem(i
, &HeaderItem
);
666 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
667 pHeader
->SetItem(i
, &HeaderItem
);
669 if (m_nSortedColumn
>= 0)
671 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
672 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
673 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
678 m_bWaitCursor
= false;
680 m_bEmpty
= (GetItemCount() == 0);
683 this->BuildStatistics();
687 m_bShowFolders
= bShowFolders
;
689 int nTopIndex
= GetTopIndex();
690 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
691 int nSelectedEntry
= 0;
692 if (posSelectedEntry
)
693 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
699 m_arListArray
.clear();
701 m_arListArray
.reserve(m_arStatusArray
.size());
702 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
705 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
707 FileEntry
* entry
= m_arStatusArray
[i
];
708 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
710 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
712 if (entry
->IsFolder() && (!bShowFolders
))
713 continue; // don't show folders if they're not wanted.
716 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
717 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
719 showFlags
|= SVNSLC_SHOWSWITCHED
;
720 if (!entry
->changelist
.IsEmpty())
721 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
723 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
724 && (m_bCheckIfGroupsExist
|| (m_changelists
.empty() || (m_changelists
.size() == 1 && m_bHasIgnoreGroup
))));
726 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
728 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
730 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
732 if (PathFileExists(entry
->GetPath().GetWinPath()))
734 m_arListArray
.push_back(i
);
735 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
738 entry
->checked
= true;
740 AddEntry(entry
, langID
, listIndex
++);
743 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
745 m_arListArray
.push_back(i
);
746 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
749 entry
->checked
= true;
751 AddEntry(entry
, langID
, listIndex
++);
753 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
755 m_arListArray
.push_back(i
);
756 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
759 entry
->checked
= true;
761 AddEntry(entry
, langID
, listIndex
++);
767 SetItemCount(listIndex
);
769 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
771 AdjustColumnWidths();
774 GetStatisticsString();
776 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
777 HDITEM HeaderItem
= {0};
778 HeaderItem
.mask
= HDI_FORMAT
;
779 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
781 pHeader
->GetItem(i
, &HeaderItem
);
782 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
783 pHeader
->SetItem(i
, &HeaderItem
);
787 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
788 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
789 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
794 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
795 EnsureVisible(nSelectedEntry
, false);
799 // Restore the item at the top of the list.
800 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
802 if ( !EnsureVisible(nTopIndex
+i
,false) )
807 m_bEmpty
= (GetItemCount() == 0);
812 void CGitStatusListCtrl::StoreScrollPos()
814 m_sScrollPos
.enabled
= true;
815 m_sScrollPos
.nTopIndex
= GetTopIndex();
816 m_sScrollPos
.selMark
= GetSelectionMark();
817 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
818 m_sScrollPos
.nSelectedEntry
= 0;
819 if (posSelectedEntry
)
820 m_sScrollPos
.nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
823 void CGitStatusListCtrl::RestoreScrollPos()
825 if (!m_sScrollPos
.enabled
|| CRegDWORD(L
"Software\\TortoiseGit\\RememberFileListPosition", TRUE
) != TRUE
)
828 if (m_sScrollPos
.nSelectedEntry
)
830 SetItemState(m_sScrollPos
.nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
831 EnsureVisible(m_sScrollPos
.nSelectedEntry
, false);
835 // Restore the item at the top of the list.
836 for (int i
= 0; GetTopIndex() != m_sScrollPos
.nTopIndex
; ++i
)
838 if (!EnsureVisible(m_sScrollPos
.nTopIndex
+ i
, false))
842 if (m_sScrollPos
.selMark
>= 0)
844 SetSelectionMark(m_sScrollPos
.selMark
);
845 SetItemState(m_sScrollPos
.selMark
, LVIS_FOCUSED
, LVIS_FOCUSED
);
847 m_sScrollPos
.enabled
= false;
850 int CGitStatusListCtrl::GetColumnIndex(int mask
)
852 for (int i
= 0; i
< 32; ++i
)
860 CString
CGitStatusListCtrl::GetCellText(int listIndex
, int column
)
862 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
863 static bool abbreviateRenamings(((DWORD
)CRegDWORD(L
"Software\\TortoiseGit\\AbbreviateRenamings", FALSE
)) == TRUE
);
864 static bool relativeTimes
= (CRegDWORD(L
"Software\\TortoiseGit\\RelativeTimes", FALSE
) != FALSE
);
865 static const CString empty
;
867 CAutoReadLock
locker(m_guard
);
868 const auto* entry
= GetListEntry(listIndex
);
874 case 0: // relative path
875 if (!(entry
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
| CTGitPath::LOGACTIONS_COPY
) && !entry
->GetGitOldPathString().IsEmpty()))
876 return entry
->GetGitPathString();
878 if (!abbreviateRenamings
)
880 CString entryname
= entry
->GetGitPathString();
883 entryname
.AppendFormat(from
, (LPCTSTR
)entry
->GetGitOldPathString());
887 return entry
->GetAbbreviatedRename();
889 case 1: // GITSLC_COLFILENAME
890 return entry
->GetFileOrDirectoryName();
892 case 2: // GITSLC_COLEXT
893 return entry
->GetFileExtension();
895 case 3: // GITSLC_COLSTATUS
896 return entry
->GetActionName();
898 case 4: // GITSLC_COLADD
899 return entry
->m_StatAdd
;
901 case 5: // GITSLC_COLDEL
902 return entry
->m_StatDel
;
904 case 6: // GITSLC_COLMODIFICATIONDATE
905 if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
) && m_ColumnManager
.IsRelevant(GetColumnIndex(GITSLC_COLMODIFICATIONDATE
)))
907 CString modificationDate
;
908 __int64 filetime
= entry
->GetLastWriteTime();
911 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
912 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(CGit::filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
914 return modificationDate
;
918 case 7: // GITSLC_COLSIZE
919 if (!(entry
->IsDirectory() || !m_ColumnManager
.IsRelevant(GetColumnIndex(GITSLC_COLSIZE
))))
921 TCHAR buf
[100] = { 0 };
922 StrFormatByteSize64(entry
->GetFileSize(), buf
, 100);
928 default: // user-defined properties
929 if (column
< m_ColumnManager
.GetColumnCount())
931 assert(m_ColumnManager
.IsUserProp(column
));
933 const CString
& name
= m_ColumnManager
.GetName(column
);
934 auto propEntry
= m_PropertyMap
.find(entry
->GetPath());
935 if (propEntry
!= m_PropertyMap
.end())
937 if (propEntry
->second
.HasProperty(name
))
939 const CString
& propVal
= propEntry
->second
[name
];
940 return propVal
.IsEmpty()
951 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
953 CAutoWriteLock
locker(m_guard
);
954 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
955 CString path
= GitPath
->GetGitPathString();
957 int index
= listIndex
;
958 // Load the icons *now* so the icons are cached when showing them later in the
960 // Problem is that (at least on Win10), loading the icons in the WM_PAINT
961 // handler triggers an OLE operation, which should not happen in WM_PAINT at all
962 // (see ..\VC\atlmfc\src\mfc\olemsgf.cpp, COleMessageFilter::OnMessagePending() for details about this)
963 // By loading the icons here, they get cached and the OLE operation won't happen
964 // later in the WM_PAINT handler.
965 // This solves the 'hang' which happens in the commit dialog if images are
966 // shown in the file list.
968 if (GitPath
->IsDirectory())
970 icon_idx
= m_nIconFolder
;
971 m_nShownSubmodules
++;
975 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
978 switch (GitPath
->m_Action
)
980 case CTGitPath::LOGACTIONS_ADDED
:
981 case CTGitPath::LOGACTIONS_COPY
:
984 case CTGitPath::LOGACTIONS_DELETED
:
985 case CTGitPath::LOGACTIONS_MISSING
:
986 case CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
:
989 case CTGitPath::LOGACTIONS_REPLACED
:
990 case CTGitPath::LOGACTIONS_MODIFIED
:
991 case CTGitPath::LOGACTIONS_MERGED
:
994 case CTGitPath::LOGACTIONS_UNMERGED
:
995 case CTGitPath::LOGACTIONS_UNMERGED
| CTGitPath::LOGACTIONS_ADDED
:
996 case CTGitPath::LOGACTIONS_UNMERGED
| CTGitPath::LOGACTIONS_MODIFIED
:
997 m_nShownConflicted
++;
999 case CTGitPath::LOGACTIONS_UNVER
:
1000 m_nShownUnversioned
++;
1003 m_nShownUnversioned
++;
1007 LVITEM lvItem
= { 0 };
1008 lvItem
.iItem
= listIndex
;
1009 lvItem
.lParam
= (LPARAM
)GitPath
;
1010 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_PARAM
;
1011 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1012 lvItem
.stateMask
= LVIS_OVERLAYMASK
;
1013 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
1014 lvItem
.state
= INDEXTOOVERLAYMASK(OVL_RESTORE
);
1015 lvItem
.iImage
= icon_idx
;
1016 InsertItem(&lvItem
);
1018 SetCheck(index
, GitPath
->m_Checked
);
1019 if (GitPath
->m_Checked
)
1022 if ((GitPath
->m_Action
& CTGitPath::LOGACTIONS_SKIPWORKTREE
) || (GitPath
->m_Action
& CTGitPath::LOGACTIONS_ASSUMEVALID
))
1023 SetItemGroup(index
, 3);
1024 else if (GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1025 SetItemGroup(index
, 2);
1026 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1027 SetItemGroup(index
,1);
1029 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1032 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1034 CAutoWriteLock
locker(m_guard
);
1035 // if (!(m_dwContextMenus & SVNSLC_POPCHANGELISTS))
1040 i
.mask
= LVIF_GROUPID
;
1043 i
.iGroupId
= groupindex
;
1045 return !!SetItem(&i
);
1048 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1050 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1053 CAutoReadWeakLock
lock(m_guard
);
1054 if (!lock
.IsAcquired())
1057 if (m_arStatusArray
.empty())
1060 if (m_nSortedColumn
== phdr
->iItem
)
1061 m_bAscending
= !m_bAscending
;
1063 m_bAscending
= TRUE
;
1064 m_nSortedColumn
= phdr
->iItem
;
1065 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1068 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1070 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1072 CWnd
* pParent
= GetLogicalParent();
1073 if (pParent
&& pParent
->GetSafeHwnd())
1074 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1076 if (m_nBlockItemChangeHandler
)
1079 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1082 CAutoWriteWeakLock
writeLock(m_guard
);
1083 if (!writeLock
.IsAcquired())
1089 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1090 int nListItems
= GetItemCount();
1092 // was the item checked?
1094 if (GetCheck(pNMLV
->iItem
))
1097 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
1098 CheckEntry(pNMLV
->iItem
, nListItems
);
1102 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
1103 POSITION pos
= GetFirstSelectedItemPosition();
1105 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1107 if (index
!= pNMLV
->iItem
)
1108 CheckEntry(index
, nListItems
);
1115 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
1116 UncheckEntry(pNMLV
->iItem
, nListItems
);
1120 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
1121 POSITION pos
= GetFirstSelectedItemPosition();
1123 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1125 if (index
!= pNMLV
->iItem
)
1126 UncheckEntry(index
, nListItems
);
1131 GetStatisticsString();
1137 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1139 CAutoWriteLock
locker(m_guard
);
1140 auto path
= GetListEntry(index
);
1143 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1144 SetCheck(index
, TRUE
);
1145 // if an unversioned item was checked, then we need to check if
1146 // the parent folders are unversioned too. If the parent folders actually
1147 // are unversioned, then check those too.
1149 if (entry
->status
== git_wc_status_unversioned
)
1151 // we need to check the parent folder too
1152 const CTGitPath
& folderpath
= entry
->path
;
1153 for (int i
=0; i
< nListItems
; ++i
)
1155 FileEntry
* testEntry
= GetListEntry(i
);
1159 if (!testEntry
->checked
)
1161 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1163 SetEntryCheck(testEntry
,i
,true);
1169 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1170 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1172 // if a deleted folder gets checked, we have to check all
1173 // children of that folder too.
1174 if (entry
->path
.IsDirectory())
1175 SetCheckOnAllDescendentsOf(entry
, true);
1177 // if a deleted file or folder gets checked, we have to
1178 // check all parents of this item too.
1179 for (int i
=0; i
<nListItems
; ++i
)
1181 FileEntry
* testEntry
= GetListEntry(i
);
1185 if (!testEntry
->checked
)
1187 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1189 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1191 SetEntryCheck(testEntry
,i
,true);
1193 // now we need to check all children of this parent folder
1194 SetCheckOnAllDescendentsOf(testEntry
, true);
1201 if ( !path
->m_Checked
)
1203 path
->m_Checked
= TRUE
;
1208 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1210 CAutoWriteLock
locker(m_guard
);
1211 auto path
= GetListEntry(index
);
1214 SetCheck(index
, FALSE
);
1215 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1216 // item was unchecked
1218 if (entry
->path
.IsDirectory())
1220 // disable all files within an unselected folder, except when unchecking a folder with property changes
1221 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1222 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1224 SetCheckOnAllDescendentsOf(entry
, false);
1227 else if (entry
->status
== git_wc_status_deleted
)
1229 // a "deleted" file was unchecked, so uncheck all parent folders
1230 // and all children of those parents
1231 for (int i
=0; i
<nListItems
; i
++)
1233 FileEntry
* testEntry
= GetListEntry(i
);
1237 if (testEntry
->checked
)
1239 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1241 if (testEntry
->status
== git_wc_status_deleted
)
1243 SetEntryCheck(testEntry
,i
,false);
1246 SetCheckOnAllDescendentsOf(testEntry
, false);
1253 if ( path
->m_Checked
)
1255 path
->m_Checked
= FALSE
;
1259 void CGitStatusListCtrl::BuildStatistics()
1261 CAutoReadLock
locker(m_guard
);
1263 // now gather some statistics
1276 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
1278 int status
= m_arStatusArray
[i
]->m_Action
;
1280 m_nLineAdded
+= _wtol(m_arStatusArray
[i
]->m_StatAdd
);
1281 m_nLineDeleted
+= _wtol(m_arStatusArray
[i
]->m_StatDel
);
1283 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1286 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1289 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1292 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1295 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1298 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1301 if (m_arStatusArray
[i
]->m_Checked
)
1306 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1308 // the point must be relative to the upper left corner of the control
1312 if (!IsGroupViewEnabled())
1321 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1323 nItem
= HitTest(pt
, &flags
);
1324 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1326 // the first item below the point
1328 // check if the point is too much right (i.e. if the point
1329 // is farther to the right than the width of the item)
1331 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1332 if (ppt
->x
> r
.right
)
1336 lv
.mask
= LVIF_GROUPID
;
1339 int groupID
= lv
.iGroupId
;
1340 // now we search upwards and check if the item above this one
1341 // belongs to another group. If it belongs to the same group,
1342 // we're not over a group header
1346 nItem
= HitTest(pt
, &flags
);
1347 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1349 // the first item below the point
1351 lv2
.mask
= LVIF_GROUPID
;
1354 if (lv2
.iGroupId
!= groupID
)
1369 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1371 POINT clientpoint
= point
;
1372 ScreenToClient(&clientpoint
);
1373 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1375 CAutoReadWeakLock
readLock(m_guard
);
1376 if (!readLock
.IsAcquired())
1380 if (popup
.CreatePopupMenu())
1383 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1384 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1385 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1386 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1387 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
1388 bool bCheck
= false;
1391 case IDGITLC_CHECKGROUP
:
1393 // fall through here
1394 case IDGITLC_UNCHECKGROUP
:
1396 int group
= GetGroupFromPoint(&clientpoint
);
1397 // go through all items and check/uncheck those assigned to the group
1398 // but block the OnLvnItemChanged handler
1399 for (int i
=0; i
<GetItemCount(); ++i
)
1402 lv
.mask
= LVIF_GROUPID
;
1406 if (lv
.iGroupId
== group
)
1408 auto entry
= GetListEntry(i
);
1411 bool bOldCheck
= entry
->m_Checked
;
1412 SetEntryCheck(entry
, i
, bCheck
);
1413 if (bCheck
!= bOldCheck
)
1424 GetStatisticsString();
1433 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1435 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1437 CAutoWriteWeakLock
writeLock(m_guard
);
1438 if (!writeLock
.IsAcquired())
1441 auto selectedCount
= GetSelectedCount();
1442 int selIndex
= GetSelectionMark();
1443 int selSubitem
= -1;
1444 if (selectedCount
> 0)
1447 ScreenToClient(&pt
);
1448 LVHITTESTINFO hittest
= { 0 };
1449 hittest
.flags
= LVHT_ONITEM
;
1451 if (this->SubItemHitTest(&hittest
) >= 0)
1452 selSubitem
= hittest
.iSubItem
;
1454 if ((point
.x
== -1) && (point
.y
== -1))
1457 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1458 ClientToScreen(&rect
);
1459 point
= rect
.CenterPoint();
1461 if (selectedCount
== 0 && m_bHasCheckboxes
)
1463 // nothing selected could mean the context menu is requested for
1465 OnContextMenuGroup(pWnd
, point
);
1467 else if (selIndex
>= 0)
1469 auto filepath
= GetListEntry(selIndex
);
1473 //const CTGitPath& filepath = entry->path;
1474 int wcStatus
= filepath
->m_Action
;
1475 // entry is selected, now show the popup menu
1477 CMenu changelistSubMenu
;
1478 CMenu ignoreSubMenu
;
1479 CIconMenu clipSubMenu
;
1481 if (popup
.CreatePopupMenu())
1483 //Add Menu for version controlled file
1485 if (selectedCount
> 0 && (wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
))
1487 if (selectedCount
== 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
))
1489 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1490 popup
.SetDefaultItem(IDGITLC_EDITCONFLICT
, FALSE
);
1492 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1494 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1495 CString tmp
, mineTitle
, theirsTitle
;
1496 CAppUtils::GetConflictTitles(nullptr, mineTitle
, theirsTitle
, m_bIsRevertTheirMy
);
1497 tmp
.Format(IDS_SVNPROGRESS_MENURESOLVEUSING
, (LPCTSTR
)theirsTitle
);
1498 if (m_bIsRevertTheirMy
)
1500 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, tmp
, IDI_RESOLVE
);
1501 tmp
.Format(IDS_SVNPROGRESS_MENURESOLVEUSING
, (LPCTSTR
)mineTitle
);
1502 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, tmp
, IDI_RESOLVE
);
1506 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, tmp
, IDI_RESOLVE
);
1507 tmp
.Format(IDS_SVNPROGRESS_MENURESOLVEUSING
, (LPCTSTR
)mineTitle
);
1508 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, tmp
, IDI_RESOLVE
);
1511 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1512 popup
.AppendMenu(MF_SEPARATOR
);
1515 if (selectedCount
> 0)
1517 if (wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
1519 if (m_dwContextMenus
& GITSLC_POPADD
)
1520 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1521 if (m_dwContextMenus
& GITSLC_POPCOMMIT
)
1522 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1526 if (!(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) && !((wcStatus
& CTGitPath::LOGACTIONS_MISSING
) && wcStatus
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
) && wcStatus
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MODIFIED
)) && selectedCount
> 0)
1528 bool bEntryAdded
= false;
1529 if (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
)
1531 if(filepath
->m_ParentNo
& MERGE_MASK
)
1532 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1534 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1536 if (!(wcStatus
& (CTGitPath::LOGACTIONS_UNMERGED
)) || selectedCount
!= 1)
1537 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1541 if (!g_Git
.IsInitRepos() && (m_dwContextMenus
& GITSLC_POPGNUDIFF
))
1543 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1547 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && m_bHasWC
)
1549 if ((!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1551 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1557 popup
.AppendMenu(MF_SEPARATOR
);
1560 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
1562 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWOREVISIONS
))
1564 popup
.AppendMenuIcon(IDGITLC_COMPARETWOREVISIONS
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1565 popup
.SetDefaultItem(IDGITLC_COMPARETWOREVISIONS
, FALSE
);
1567 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2REVISIONS
))
1568 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2REVISIONS
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1572 if (selectedCount
> 0)
1574 if (selectedCount
== 2 && (m_dwContextMenus
& GITSLC_POPCOMPARETWOFILES
) && (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
))
1576 POSITION pos
= GetFirstSelectedItemPosition();
1577 int index
= GetNextSelectedItem(pos
);
1580 auto entry2
= GetListEntry(index
);
1581 bool firstEntryExistsAndIsFile
= entry2
&& !entry2
->IsDirectory();
1582 index
= GetNextSelectedItem(pos
);
1585 entry2
= GetListEntry(index
);
1586 if (firstEntryExistsAndIsFile
&& entry2
&& !entry2
->IsDirectory())
1587 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1593 if (selectedCount
> 0 && (!(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))) && m_bHasWC
)
1595 if ((m_dwContextMenus
& GITSLC_POPCOMMIT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1596 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1598 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1599 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1601 if ((m_dwContextMenus
& GITSLC_POPSKIPWORKTREE
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_UNMERGED
| CTGitPath::LOGACTIONS_SKIPWORKTREE
)))
1602 popup
.AppendMenuIcon(IDGITLC_SKIPWORKTREE
, IDS_STATUSLIST_SKIPWORKTREE
);
1604 if ((m_dwContextMenus
& GITSLC_POPASSUMEVALID
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_UNMERGED
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1605 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1607 if ((m_dwContextMenus
& GITLC_POPUNSETIGNORELOCALCHANGES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && (wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1608 popup
.AppendMenuIcon(IDGITLC_UNSETIGNORELOCALCHANGES
, IDS_STATUSLIST_UNSETIGNORELOCALCHANGES
);
1610 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1612 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1613 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1615 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1618 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1619 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1621 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1624 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOPARENT
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1625 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_ADDED
))
1627 popup
.AppendMenuIcon(IDGITLC_REVERTTOPARENT
, IDS_LOG_POPUP_REVERTTOPARENT
, IDI_REVERT
);
1631 if (selectedCount
== 1 && !(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)))
1633 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1634 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1635 if (m_dwContextMenus
& GITSLC_POPSHOWLOGSUBMODULE
&& filepath
->IsDirectory())
1636 popup
.AppendMenuIcon(IDGITLC_LOGSUBMODULE
, IDS_LOG_SUBMODULE
, IDI_LOG
);
1637 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1638 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1639 if ((m_dwContextMenus
& GITSLC_POPBLAME
) && !filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && !((wcStatus
& CTGitPath::LOGACTIONS_ADDED
) && (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)) && m_bHasWC
)
1640 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1643 if (selectedCount
> 0)
1645 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_EXPORT
)) && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)))
1646 popup
.AppendMenuIcon(IDGITLC_EXPORT
, IDS_LOG_POPUP_EXPORT
, IDI_EXPORT
);
1649 if (selectedCount
== 1)
1651 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1652 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1654 if (m_dwContextMenus
& GITSLC_POPOPEN
&& !filepath
->IsDirectory() && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)))
1656 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1657 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1658 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1661 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1662 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1664 if (m_dwContextMenus
& GITSLC_PREPAREDIFF
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1666 popup
.AppendMenu(MF_SEPARATOR
);
1667 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF
, IDS_PREPAREDIFF
, IDI_DIFF
);
1668 if (!m_sMarkForDiffFilename
.IsEmpty())
1671 if (filepath
->GetGitPathString() == m_sMarkForDiffFilename
)
1672 diffWith
= m_sMarkForDiffVersion
;
1675 PathCompactPathEx(CStrBuf(diffWith
, 2 * GIT_HASH_SIZE
), m_sMarkForDiffFilename
, 2 * GIT_HASH_SIZE
, 0);
1676 diffWith
+= L
':' + m_sMarkForDiffVersion
.Left(g_Git
.GetShortHASHLength());
1679 menuEntry
.Format(IDS_MENUDIFFNOW
, (LPCTSTR
)diffWith
);
1680 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF_COMPARE
, menuEntry
, IDI_DIFF
);
1684 if (selectedCount
> 0)
1686 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1687 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1688 // if ((wcStatus != Git_wc_status_unversioned)&&(wcStatus != git_wc_status_ignored)&&(wcStatus != Git_wc_status_deleted)&&(wcStatus != Git_wc_status_added)&&(m_dwContextMenus & GitSLC_POPDELETE))
1691 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1693 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1695 if ((wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
| CTGitPath::LOGACTIONS_MISSING
))/*||(wcStatus == git_wc_status_deleted)*/)
1697 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1698 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1700 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1702 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1704 CTGitPathList ignorelist
;
1705 FillListOfSelectedItemPaths(ignorelist
);
1706 //check if all selected entries have the same extension
1707 bool bSameExt
= true;
1709 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1711 if (sExt
.IsEmpty() && (i
==0))
1712 sExt
= ignorelist
[i
].GetFileExtension();
1713 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1718 if (ignoreSubMenu
.CreateMenu())
1721 if (ignorelist
.GetCount()==1)
1722 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1724 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1725 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1726 ignorepath
= L
'*' + sExt
;
1727 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1728 if (ignorelist
.GetCount() == 1 && !ignorelist
[0].GetContainingDirectory().GetGitPathString().IsEmpty())
1729 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREFOLDER
, ignorelist
[0].GetContainingDirectory().GetGitPathString());
1731 temp
.LoadString(IDS_MENUIGNORE
);
1732 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1738 if (ignorelist
.GetCount()==1)
1739 temp
.LoadString(IDS_MENUIGNORE
);
1741 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1742 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1743 temp
.Format(IDS_MENUIGNOREMULTIPLEMASK
, ignorelist
.GetCount());
1744 popup
.AppendMenuIcon(IDGITLC_IGNOREMASK
, temp
, IDI_IGNORE
);
1752 if (selectedCount
> 0)
1754 popup
.AppendMenu(MF_SEPARATOR
);
1756 if (clipSubMenu
.CreatePopupMenu())
1759 clipSubMenu
.AppendMenuIcon(IDGITLC_COPYFULL
, IDS_STATUSLIST_CONTEXT_COPYFULLPATHS
, IDI_COPYCLIP
);
1760 clipSubMenu
.AppendMenuIcon(IDGITLC_COPYRELPATHS
, IDS_STATUSLIST_CONTEXT_COPYRELPATHS
, IDI_COPYCLIP
);
1761 clipSubMenu
.AppendMenuIcon(IDGITLC_COPYFILENAMES
, IDS_STATUSLIST_CONTEXT_COPYFILENAMES
, IDI_COPYCLIP
);
1762 clipSubMenu
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1763 if (selSubitem
>= 0)
1765 temp
.Format(IDS_STATUSLIST_CONTEXT_COPYCOL
, (LPCWSTR
)m_ColumnManager
.GetName(selSubitem
));
1766 clipSubMenu
.AppendMenuIcon(IDGITLC_COPYCOL
, temp
, IDI_COPYCLIP
);
1768 temp
.LoadString(IDS_LOG_POPUP_COPYTOCLIPBOARD
);
1769 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)clipSubMenu
.m_hMenu
, temp
);
1773 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1774 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1776 popup
.AppendMenu(MF_SEPARATOR
);
1777 // changelist commands
1778 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1779 if (numChangelists
> 0)
1780 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1781 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1784 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1785 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1787 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1789 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1790 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1793 if (!m_changelists
.empty())
1795 // find the changelist names
1796 bool bNeedSeparator
= true;
1797 int cmdID
= IDSVNLC_MOVETOCS
;
1798 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
1800 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1804 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1805 bNeedSeparator
= false;
1807 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1812 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1813 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1819 m_hShellMenu
= nullptr;
1820 if (selectedCount
> 0 && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)) && m_bHasWC
&& (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
) && shellMenu
.CreatePopupMenu())
1822 // insert the shell context menu
1823 popup
.AppendMenu(MF_SEPARATOR
);
1824 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)shellMenu
.m_hMenu
, CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_SHELL
)));
1825 m_hShellMenu
= shellMenu
.m_hMenu
;
1828 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this);
1829 g_IContext2
= nullptr;
1830 g_IContext3
= nullptr;
1833 if (cmd
>= SHELL_MIN_CMD
&& cmd
<= SHELL_MAX_CMD
) // see if returned idCommand belongs to shell menu entries)
1835 CMINVOKECOMMANDINFOEX cmi
= { 0 };
1836 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFOEX
);
1837 cmi
.fMask
= CMIC_MASK_UNICODE
| CMIC_MASK_PTINVOKE
;
1838 if (GetKeyState(VK_CONTROL
) < 0)
1839 cmi
.fMask
|= CMIC_MASK_CONTROL_DOWN
;
1841 cmi
.fMask
|= CMIC_MASK_SHIFT_DOWN
;
1843 cmi
.lpVerb
= MAKEINTRESOURCEA(cmd
- SHELL_MIN_CMD
);
1844 cmi
.lpVerbW
= MAKEINTRESOURCEW(cmd
- SHELL_MIN_CMD
);
1845 cmi
.nShow
= SW_SHOWNORMAL
;
1846 cmi
.ptInvoke
= point
;
1848 m_pContextMenu
->InvokeCommand((LPCMINVOKECOMMANDINFO
)&cmi
);
1852 m_pContextMenu
->Release();
1853 m_pContextMenu
= nullptr;
1857 delete g_pFolderhook
;
1858 g_pFolderhook
= nullptr;
1860 if (g_psfDesktopFolder
)
1862 g_psfDesktopFolder
->Release();
1863 g_psfDesktopFolder
= nullptr;
1865 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
1868 CoTaskMemFree(g_pidlArray
[i
]);
1871 CoTaskMemFree(g_pidlArray
);
1872 g_pidlArray
= nullptr;
1873 g_pidlArrayItems
= 0;
1875 m_bWaitCursor
= true;
1876 bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1877 //int iItemCountBeforeMenuCmd = GetItemCount();
1878 //bool bForce = false;
1881 case IDGITLC_VIEWREV
:
1882 OpenFile(filepath
, ALTERNATIVEEDITOR
);
1886 OpenFile(filepath
,OPEN
);
1889 case IDGITLC_OPENWITH
:
1890 OpenFile(filepath
,OPEN_WITH
);
1893 case IDGITLC_EXPLORE
:
1894 CAppUtils::ExploreTo(GetSafeHwnd(), g_Git
.CombinePath(filepath
));
1897 case IDGITLC_PREPAREDIFF
:
1898 m_sMarkForDiffFilename
= filepath
->GetGitPathString();
1899 m_sMarkForDiffVersion
= m_CurrentVersion
;
1902 case IDGITLC_PREPAREDIFF_COMPARE
:
1904 CTGitPath
savedFile(m_sMarkForDiffFilename
);
1905 CGitDiff::Diff(filepath
, &savedFile
, m_CurrentVersion
, m_sMarkForDiffVersion
, false, false, 0, bShift
);
1909 case IDGITLC_CREATERESTORE
:
1911 POSITION pos
= GetFirstSelectedItemPosition();
1914 int index
= GetNextSelectedItem(pos
);
1915 auto entry2
= GetListEntry(index
);
1916 if (!entry2
|| entry2
->IsDirectory())
1918 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
1920 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
1921 // delete the temp file: the temp file has the FILE_ATTRIBUTE_TEMPORARY flag set
1922 // and copying the real file over it would leave that temp flag.
1923 DeleteFile(tempFile
.GetWinPath());
1924 if (CopyFile(g_Git
.CombinePath(entry2
), tempFile
.GetWinPath(), FALSE
))
1926 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
1927 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
1934 case IDGITLC_RESTOREPATH
:
1936 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
1938 POSITION pos
= GetFirstSelectedItemPosition();
1941 int index
= GetNextSelectedItem(pos
);
1942 auto entry2
= GetListEntry(index
);
1945 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
1947 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.CombinePath(entry2
), FALSE
))
1949 m_restorepaths
.erase(entry2
->GetWinPathString());
1950 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
1957 // Compare current version and work copy.
1958 case IDGITLC_COMPAREWC
:
1960 if (!CheckMultipleDiffs())
1962 POSITION pos
= GetFirstSelectedItemPosition();
1965 int index
= GetNextSelectedItem(pos
);
1971 // Compare with base version. when current version is zero, compare workcopy and HEAD.
1972 case IDGITLC_COMPARE
:
1974 if (!CheckMultipleDiffs())
1976 POSITION pos
= GetFirstSelectedItemPosition();
1979 int index
= GetNextSelectedItem(pos
);
1985 case IDGITLC_COMPARETWOREVISIONS
:
1987 if (!CheckMultipleDiffs())
1989 POSITION pos
= GetFirstSelectedItemPosition();
1992 int index
= GetNextSelectedItem(pos
);
1993 StartDiffTwo(index
);
1998 case IDGITLC_COMPARETWOFILES
:
2000 POSITION pos
= GetFirstSelectedItemPosition();
2003 auto firstfilepath
= GetListEntry(GetNextSelectedItem(pos
));
2007 auto secondfilepath
= GetListEntry(GetNextSelectedItem(pos
));
2008 if (!secondfilepath
)
2012 sCmd
.Format(L
"/command:diff /path:\"%s\" /endrev:%s /path2:\"%s\" /startrev:%s /hwnd:%p", firstfilepath
->GetWinPath(), firstfilepath
->Exists() ? GIT_REV_ZERO
: L
"HEAD", secondfilepath
->GetWinPath(), secondfilepath
->Exists() ? GIT_REV_ZERO
: L
"HEAD", (void*)m_hWnd
);
2014 sCmd
+= L
" /alternative";
2015 CAppUtils::RunTortoiseGitProc(sCmd
);
2020 case IDGITLC_GNUDIFF1
:
2022 if (!CheckMultipleDiffs())
2024 POSITION pos
= GetFirstSelectedItemPosition();
2027 auto selectedFilepath
= GetListEntry(GetNextSelectedItem(pos
));
2028 if (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2033 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, GitRev::GetHead() + fromwhere
, *selectedFilepath
, GitRev::GetWorkingCopy(), bShift
);
2037 if ((selectedFilepath
->m_ParentNo
& (PARENT_MASK
| MERGE_MASK
)) == 0)
2038 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, m_CurrentVersion
+ L
"~1", *selectedFilepath
, m_CurrentVersion
, bShift
);
2042 if (!(selectedFilepath
->m_ParentNo
& MERGE_MASK
))
2043 str
.Format(L
"%s^%d", (LPCTSTR
)m_CurrentVersion
, (selectedFilepath
->m_ParentNo
& PARENT_MASK
) + 1);
2045 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, str
, *selectedFilepath
, m_CurrentVersion
, bShift
, false, false, false, !!(selectedFilepath
->m_ParentNo
& MERGE_MASK
));
2052 case IDGITLC_GNUDIFF2REVISIONS
:
2054 if (!CheckMultipleDiffs())
2056 POSITION pos
= GetFirstSelectedItemPosition();
2059 auto entry
= GetListEntry(GetNextSelectedItem(pos
));
2060 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *entry
, m_Rev2
, *entry
, m_Rev1
, bShift
);
2067 CTGitPathList paths
;
2068 FillListOfSelectedItemPaths(paths
, true);
2070 CGitProgressDlg progDlg
;
2071 AddProgressCommand addCommand
;
2072 progDlg
.SetCommand(&addCommand
);
2073 addCommand
.SetShowCommitButtonAfterAdd((m_dwContextMenus
& GITSLC_POPCOMMIT
) != 0);
2074 addCommand
.SetPathList(paths
);
2075 progDlg
.SetItemCount(paths
.GetCount());
2078 // reset unchecked status
2079 POSITION pos
= GetFirstSelectedItemPosition();
2081 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2082 m_mapFilenameToChecked
.erase(GetListEntry(index
)->GetGitPathString());
2084 if (GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2085 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2091 case IDGITLC_DELETE
:
2092 DeleteSelectedFiles();
2097 CAppUtils::LaunchTortoiseBlame(g_Git
.CombinePath(filepath
), m_CurrentVersion
);
2102 case IDGITLC_LOGSUBMODULE
:
2105 sCmd
.Format(L
"/command:log /path:\"%s\"", (LPCTSTR
)g_Git
.CombinePath(filepath
));
2106 if (cmd
== IDGITLC_LOG
&& filepath
->IsDirectory())
2107 sCmd
+= L
" /submodule";
2108 if (!m_sDisplayedBranch
.IsEmpty())
2109 sCmd
+= L
" /range:\"" + m_sDisplayedBranch
+ L
'"';
2110 CAppUtils::RunTortoiseGitProc(sCmd
, false, !(cmd
== IDGITLC_LOGSUBMODULE
));
2114 case IDGITLC_LOGOLDNAME
:
2116 CTGitPath
oldName(filepath
->GetGitOldPathString());
2118 sCmd
.Format(L
"/command:log /path:\"%s\"", (LPCTSTR
)g_Git
.CombinePath(oldName
));
2119 if (!m_sDisplayedBranch
.IsEmpty())
2120 sCmd
+= L
" /range:\"" + m_sDisplayedBranch
+ L
'"';
2121 CAppUtils::RunTortoiseGitProc(sCmd
);
2125 case IDGITLC_EDITCONFLICT
:
2127 if (CAppUtils::ConflictEdit(*filepath
, bShift
, m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2129 CString conflictedFile
= g_Git
.CombinePath(filepath
);
2130 if (!PathFileExists(conflictedFile
) && GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2132 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2136 Show(m_dwShow
, 0, m_bShowFolders
, 0, true);
2141 case IDGITLC_RESOLVETHEIRS
: //follow up
2142 case IDGITLC_RESOLVEMINE
: //follow up
2143 case IDGITLC_RESOLVECONFLICT
:
2145 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2147 bool needsFullRefresh
= false;
2148 POSITION pos
= GetFirstSelectedItemPosition();
2152 index
= GetNextSelectedItem(pos
);
2153 auto fentry
= GetListEntry(index
);
2157 CAppUtils::resolve_with resolveWith
= CAppUtils::RESOLVE_WITH_CURRENT
;
2158 if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
))
2159 resolveWith
= CAppUtils::RESOLVE_WITH_THEIRS
;
2160 else if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
))
2161 resolveWith
= CAppUtils::RESOLVE_WITH_MINE
;
2162 if (CAppUtils::ResolveConflict(*fentry
, resolveWith
) == 0 && fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2163 needsFullRefresh
= true;
2165 if (needsFullRefresh
&& CRegDWORD(L
"Software\\TortoiseGit\\RefreshFileListAfterResolvingConflict", TRUE
) == TRUE
)
2167 CWnd
* pParent
= GetLogicalParent();
2168 if (pParent
&& pParent
->GetSafeHwnd())
2169 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2174 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2179 case IDGITLC_IGNORE
:
2181 CTGitPathList ignorelist
;
2182 //std::vector<CString> toremove;
2183 FillListOfSelectedItemPaths(ignorelist
, true);
2185 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2189 CWnd
* pParent
= GetLogicalParent();
2190 if (pParent
&& pParent
->GetSafeHwnd())
2192 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2198 case IDGITLC_IGNOREMASK
:
2201 CString ext
=filepath
->GetFileExtension();
2202 CTGitPathList ignorelist
;
2203 FillListOfSelectedItemPaths(ignorelist
, true);
2205 if (!CAppUtils::IgnoreFile(ignorelist
,true))
2209 CWnd
* pParent
= GetLogicalParent();
2210 if (pParent
&& pParent
->GetSafeHwnd())
2212 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2219 case IDGITLC_IGNOREFOLDER
:
2221 CTGitPathList ignorelist
;
2222 ignorelist
.AddPath(filepath
->GetContainingDirectory());
2224 if (!CAppUtils::IgnoreFile(ignorelist
, false))
2228 CWnd
*pParent
= GetLogicalParent();
2229 if (pParent
&& pParent
->GetSafeHwnd())
2230 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2235 case IDGITLC_COMMIT
:
2237 CTGitPathList targetList
;
2238 FillListOfSelectedItemPaths(targetList
);
2239 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2240 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2241 CString commandline
= L
"/command:commit /pathfile:\"";
2242 commandline
+= tempFile
.GetWinPathString();
2243 commandline
+= L
'"';
2244 commandline
+= L
" /deletepathfile";
2245 CAppUtils::RunTortoiseGitProc(commandline
);
2248 case IDGITLC_REVERT
:
2250 // If at least one item is not in the status "added"
2251 // we ask for a confirmation
2252 BOOL bConfirm
= FALSE
;
2253 POSITION pos
= GetFirstSelectedItemPosition();
2255 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2257 auto fentry
= GetListEntry(index
);
2258 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2266 str
.Format(IDS_PROC_WARNREVERT
, selectedCount
);
2268 if (!bConfirm
|| MessageBox(str
, L
"TortoiseGit", MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
2270 CTGitPathList targetList
;
2271 FillListOfSelectedItemPaths(targetList
);
2273 // make sure that the list is reverse sorted, so that
2274 // children are removed before any parents
2275 targetList
.SortByPathname(true);
2277 // put all reverted files in the trashbin, except the ones with 'added'
2278 // status because they are not restored by the revert.
2279 CTGitPathList delList
;
2280 POSITION pos2
= GetFirstSelectedItemPosition();
2282 while ((index2
= GetNextSelectedItem(pos2
)) >= 0)
2284 auto entry
= GetListEntry(index2
);
2285 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2286 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2289 fullpath
.SetFromWin(g_Git
.CombinePath(entry
));
2290 delList
.AddPath(fullpath
);
2293 if (DWORD(CRegDWORD(L
"Software\\TortoiseGit\\RevertWithRecycleBin", TRUE
)))
2294 delList
.DeleteAllFiles(true);
2296 CString revertToCommit
= L
"HEAD";
2298 revertToCommit
= L
"HEAD~1";
2300 if (g_Git
.Revert(revertToCommit
, targetList
, err
))
2301 MessageBox(L
"Revert failed:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2304 bool updateStatusList
= false;
2305 for (int i
= 0 ; i
< targetList
.GetCount(); ++i
)
2307 int nListboxEntries
= GetItemCount();
2308 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2310 auto path
= GetListEntry(nItem
);
2311 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2313 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2315 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2316 SetEntryCheck(path
,nItem
,false);
2317 updateStatusList
= true;
2318 #if 0 // revert an added file and some entry will be cloned (part 1/2)
2319 SetItemGroup(nItem
,1);
2320 this->m_StatusFileList
.RemoveItem(*path
);
2321 this->m_UnRevFileList
.AddPath(*path
);
2322 //this->m_IgnoreFileList.RemoveItem(*path);
2327 if (GetCheck(nItem
))
2329 RemoveListEntry(nItem
);
2333 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2336 sCmd
.Format(L
"/command:revert /path:\"%s\"", (LPCTSTR
)path
->GetGitPathString());
2337 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
2342 #if 0 // revert an added file and some entry will be cloned (part 2/2)
2343 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2346 if (updateStatusList
&& GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2347 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2354 case IDGITLC_ASSUMEVALID
:
2355 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_ASSUMEVALID
, BST_CHECKED
, BST_INDETERMINATE
);
2357 case IDGITLC_SKIPWORKTREE
:
2358 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_SKIPWORKTREE
, BST_INDETERMINATE
, BST_CHECKED
);
2360 case IDGITLC_UNSETIGNORELOCALCHANGES
:
2361 SetGitIndexFlagsForSelectedFiles(IDS_PROC_UNSET_IGNORELOCALCHANGES
, BST_UNCHECKED
, BST_UNCHECKED
);
2363 case IDGITLC_COPYFULL
:
2364 case IDGITLC_COPYRELPATHS
:
2365 case IDGITLC_COPYFILENAMES
:
2366 CopySelectedEntriesToClipboard(GITSLC_COLFILENAME
, cmd
);
2368 case IDGITLC_COPYEXT
:
2369 CopySelectedEntriesToClipboard((DWORD
)-1, 0);
2371 case IDGITLC_COPYCOL
:
2372 CopySelectedEntriesToClipboard((DWORD
)1 << selSubitem
, 0);
2374 case IDGITLC_EXPORT
:
2377 case IDGITLC_SAVEAS
:
2378 FileSaveAs(filepath
);
2381 case IDGITLC_REVERTTOREV
:
2382 RevertSelectedItemToVersion();
2384 case IDGITLC_REVERTTOPARENT
:
2385 RevertSelectedItemToVersion(true);
2388 case IDSVNLC_COMMIT
:
2390 CTSVNPathList targetList
;
2391 FillListOfSelectedItemPaths(targetList
);
2392 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2393 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2394 CString commandline
= CPathUtils::GetAppDirectory();
2395 commandline
+= L
"TortoiseGitProc.exe /command:commit /pathfile:\"";
2396 commandline
+= tempFile
.GetWinPathString();
2397 commandline
+= L
'"';
2398 commandline
+= L
" /deletepathfile";
2399 CAppUtils::LaunchApplication(commandline
, nullptr, false);
2402 case IDSVNLC_CREATEIGNORECS
:
2403 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2405 case IDSVNLC_CREATECS
:
2407 CCreateChangelistDlg dlg
;
2408 if (dlg
.DoModal() == IDOK
)
2409 CreateChangeList(dlg
.m_sName
);
2414 if (cmd
< IDSVNLC_MOVETOCS
)
2416 CTSVNPathList changelistItems
;
2417 FillListOfSelectedItemPaths(changelistItems
);
2419 // find the changelist name
2420 CString sChangelist
;
2421 int cmdID
= IDSVNLC_MOVETOCS
;
2423 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
2425 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2428 sChangelist
= it
->first
;
2432 if (!sChangelist
.IsEmpty())
2435 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2437 // The changelists were moved, but we now need to run through the selected items again
2438 // and update their changelist
2439 POSITION pos
= GetFirstSelectedItemPosition();
2441 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2443 FileEntry
* e
= GetListEntry(index
);
2444 e
->changelist
= sChangelist
;
2447 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2448 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2450 SetItemGroup(index
, 0);
2455 MessageBox(git
.GetLastErrorMessage(), L
"TortoiseGit", MB_ICONERROR
);
2463 m_bWaitCursor
= false;
2464 GetStatisticsString();
2465 //int iItemCountAfterMenuCmd = GetItemCount();
2466 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2468 // CWnd* pParent = GetParent();
2469 // if (pParent && pParent->GetSafeHwnd())
2471 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2474 } // if (popup.CreatePopupMenu())
2475 } // if (selIndex >= 0)
2478 void CGitStatusListCtrl::SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
)
2480 if (CMessageBox::Show(GetSafeHwnd(), message
, IDS_APPNAME
, MB_YESNO
| MB_DEFBUTTON2
| MB_ICONQUESTION
) != IDYES
)
2483 CAutoReadLock
locker(m_guard
);
2485 CAutoRepository
repository(g_Git
.GetGitRepository());
2488 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONERROR
);
2492 CAutoIndex gitindex
;
2493 if (git_repository_index(gitindex
.GetPointer(), repository
))
2495 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONERROR
);
2499 POSITION pos
= GetFirstSelectedItemPosition();
2501 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2503 auto path
= GetListEntry(index
);
2504 if (path
== nullptr)
2508 if (!git_index_find(&idx
, gitindex
, CUnicodeUtils::GetMulti(path
->GetGitPathString(), CP_UTF8
)))
2510 git_index_entry
*e
= const_cast<git_index_entry
*>(git_index_get_byindex(gitindex
, idx
)); // HACK
2511 if (assumevalid
== BST_UNCHECKED
)
2512 e
->flags
&= ~GIT_IDXENTRY_VALID
;
2513 else if (assumevalid
== BST_CHECKED
)
2514 e
->flags
|= GIT_IDXENTRY_VALID
;
2515 if (skipworktree
== BST_UNCHECKED
)
2516 e
->flags_extended
&= ~GIT_IDXENTRY_SKIP_WORKTREE
;
2517 else if (skipworktree
== BST_CHECKED
)
2518 e
->flags_extended
|= GIT_IDXENTRY_SKIP_WORKTREE
;
2519 git_index_add(gitindex
, e
);
2522 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONERROR
);
2525 if (git_index_write(gitindex
))
2527 MessageBox(g_Git
.GetLibGit2LastErr(), L
"TortoiseGit", MB_ICONERROR
);
2531 if (nullptr != GetLogicalParent() && nullptr != GetLogicalParent()->GetSafeHwnd())
2532 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2537 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2539 __super::OnContextMenu(pWnd
, point
);
2541 OnContextMenuList(pWnd
, point
);
2544 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2546 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2549 CAutoReadWeakLock
readLock(m_guard
);
2550 if (!readLock
.IsAcquired())
2553 if (pNMLV
->iItem
< 0)
2556 auto file
= GetListEntry(pNMLV
->iItem
);
2558 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) {
2559 StartDiffWC(pNMLV
->iItem
);
2562 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2564 if (CAppUtils::ConflictEdit(*file
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2566 CString conflictedFile
= g_Git
.CombinePath(file
);
2567 if (!PathFileExists(conflictedFile
) && GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2569 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2573 Show(m_dwShow
, 0, m_bShowFolders
, 0, true);
2576 else if ((file
->m_Action
& CTGitPath::LOGACTIONS_MISSING
) && file
->m_Action
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
) && file
->m_Action
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MODIFIED
))
2580 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
2581 StartDiffTwo(pNMLV
->iItem
);
2583 StartDiff(pNMLV
->iItem
);
2586 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2591 CAutoReadLock
locker(m_guard
);
2592 auto ptr
= GetListEntry(fileindex
);
2595 CTGitPath file1
= *ptr
;
2597 if (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2598 CGitDiff::DiffNull(&file1
, m_Rev1
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2599 else if (file1
.m_Action
& CTGitPath::LOGACTIONS_DELETED
)
2600 CGitDiff::DiffNull(&file1
, m_Rev2
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2602 CGitDiff::Diff(&file1
, &file1
, m_Rev1
, m_Rev2
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2605 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2610 CAutoReadLock
locker(m_guard
);
2611 if (m_CurrentVersion
.IsEmpty())
2612 m_CurrentVersion
== GIT_REV_ZERO
;
2614 auto ptr
= GetListEntry(fileindex
);
2617 CTGitPath file1
= *ptr
;
2618 file1
.m_Action
= 0; // reset action, so that diff is not started as added/deleted file; see issue #1757
2620 CGitDiff::Diff(&file1
, &file1
, GIT_REV_ZERO
, m_CurrentVersion
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2623 void CGitStatusListCtrl::StartDiff(int fileindex
)
2628 CAutoReadLock
locker(m_guard
);
2629 auto ptr
= GetListEntry(fileindex
);
2632 CTGitPath file1
= *ptr
;
2634 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2635 file2
.SetFromGit(file1
.GetGitOldPathString());
2639 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2642 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2644 if( g_Git
.IsInitRepos())
2645 CGitDiff::DiffNull(GetListEntry(fileindex
),
2646 GIT_REV_ZERO
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2647 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2648 CGitDiff::DiffNull(GetListEntry(fileindex
),
2649 m_CurrentVersion
+ fromwhere
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2650 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2651 CGitDiff::DiffNull(GetListEntry(fileindex
),
2652 GitRev::GetHead() + fromwhere
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2654 CGitDiff::Diff(&file1
,&file2
,
2655 CString(GIT_REV_ZERO
),
2656 GitRev::GetHead() + fromwhere
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2661 CString fromwhere
= m_CurrentVersion
+ L
"~1";
2663 fromwhere
= m_CurrentVersion
+ L
"~2";
2664 bool revfail
= !!g_Git
.GetHash(hash
, fromwhere
);
2665 if (revfail
|| (file1
.m_Action
& file1
.LOGACTIONS_ADDED
))
2666 CGitDiff::DiffNull(&file1
, m_CurrentVersion
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2667 else if (file1
.m_Action
& file1
.LOGACTIONS_DELETED
)
2669 if (file1
.m_ParentNo
> 0)
2670 fromwhere
.Format(L
"%s^%d", (LPCTSTR
)m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2672 CGitDiff::DiffNull(&file1
, fromwhere
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2676 if( file1
.m_ParentNo
& MERGE_MASK
)
2678 CTGitPath base
, theirs
, mine
, merge
;
2681 GetTempPath(temppath
);
2682 temppath
.TrimRight(L
'\\');
2684 mine
.SetFromGit(temppath
+ L
'\\' + file1
.GetFileOrDirectoryName() + L
".LOCAL" + file1
.GetFileExtension());
2685 theirs
.SetFromGit(temppath
+ L
'\\' + file1
.GetFileOrDirectoryName() + L
".REMOTE" + file1
.GetFileExtension());
2686 base
.SetFromGit(temppath
+ L
'\\' + file1
.GetFileOrDirectoryName() + L
".BASE" + file1
.GetFileExtension());
2689 //create a empty file, incase stage is not three
2690 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2692 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2694 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2697 merge
.SetFromGit(temppath
+ L
'\\' + file1
.GetFileOrDirectoryName() + L
".Merged" + file1
.GetFileExtension());
2699 int parent1
=-1, parent2
=-1;
2700 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
2702 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2704 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2710 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2711 else if (parent2
<0)
2712 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2717 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2718 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2723 str
.Format(L
"%s^%d", (LPCTSTR
)this->m_CurrentVersion
, parent1
+ 1);
2725 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2726 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2732 str
.Format(L
"%s^%d", (LPCTSTR
)this->m_CurrentVersion
, parent2
+ 1);
2734 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2735 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2738 if(parent1
>=0 && parent2
>=0)
2740 CString cmd
, output
;
2741 cmd
.Format(L
"git.exe merge-base %s^%d %s^%d", (LPCTSTR
)this->m_CurrentVersion
, parent1
+ 1,
2742 (LPCTSTR
)m_CurrentVersion
, parent2
+ 1);
2744 if (!g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
))
2746 if (g_Git
.GetOneFile(output
.Left(2 * GIT_HASH_SIZE
), file1
, (CString
&)base
.GetWinPathString()))
2747 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2750 CAppUtils::StartExtMerge(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), base
, theirs
, mine
, merge
, L
"BASE", L
"REMOTE", L
"LOCAL");
2755 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2758 str
.Format(L
"^%d", (file1
.m_ParentNo
& PARENT_MASK
) + 1);
2759 CGitDiff::Diff(&file1
,&file2
,
2761 m_CurrentVersion
+ str
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2767 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2769 CString sNormal
= CString(MAKEINTRESOURCE(IDS_STATUSNORMAL
));
2770 CString sAdded
= CString(MAKEINTRESOURCE(IDS_STATUSADDED
));
2771 CString sDeleted
= CString(MAKEINTRESOURCE(IDS_STATUSDELETED
));
2772 CString sModified
= CString(MAKEINTRESOURCE(IDS_STATUSMODIFIED
));
2773 CString sConflicted
= CString(MAKEINTRESOURCE(IDS_STATUSCONFLICTED
));
2774 CString sUnversioned
= CString(MAKEINTRESOURCE(IDS_STATUSUNVERSIONED
));
2775 CString sRenamed
= CString(MAKEINTRESOURCE(IDS_STATUSREPLACED
));
2779 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2780 this->m_nLineAdded
,this->m_nLineDeleted
,
2781 (LPCTSTR
)sModified
, m_nModified
,
2782 (LPCTSTR
)sAdded
, m_nAdded
,
2783 (LPCTSTR
)sDeleted
, m_nDeleted
,
2784 (LPCTSTR
)sRenamed
, m_nRenamed
2789 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2790 this->m_nLineAdded
,this->m_nLineDeleted
,
2791 (LPCTSTR
)sNormal
, m_nNormal
,
2792 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2793 (LPCTSTR
)sModified
, m_nModified
,
2794 (LPCTSTR
)sAdded
, m_nAdded
,
2795 (LPCTSTR
)sDeleted
, m_nDeleted
,
2796 (LPCTSTR
)sConflicted
, m_nConflicted
2800 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
2802 m_pStatLabel
->SetWindowText(sStats
);
2804 if (m_pSelectButton
)
2806 if (m_nSelected
== 0)
2807 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
2808 else if (m_nSelected
!= GetItemCount())
2809 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
2811 m_pSelectButton
->SetCheck(BST_CHECKED
);
2814 if (m_pConfirmButton
)
2815 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
2820 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
2822 CAutoReadLock
locker(m_guard
);
2825 // not strict means that the selected folder has priority
2826 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
2827 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
2831 int nListItems
= GetItemCount();
2832 for (int i
=0; i
<nListItems
; ++i
)
2834 auto* entry
= GetListEntry(i
);
2835 if (entry
->IsEmpty())
2837 list
.AddPath(*entry
);
2839 return list
.GetCommonRoot().GetWinPath();
2842 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
2844 CWaitCursor waitCursor
;
2845 // block here so the LVN_ITEMCHANGED messages
2847 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
2850 CAutoWriteLock
locker(m_guard
);
2853 int nListItems
= GetItemCount();
2855 m_nSelected
= nListItems
;
2859 for (int i
=0; i
<nListItems
; ++i
)
2861 auto path
= GetListEntry(i
);
2864 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2865 SetEntryCheck(path
,i
,bSelect
);
2869 GetStatisticsString();
2873 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool check
)
2875 CWaitCursor waitCursor
;
2876 // block here so the LVN_ITEMCHANGED messages
2879 CAutoWriteLock
locker(m_guard
);
2881 ScopedInDecrement
blocker(m_nBlockItemChangeHandler
);
2883 int nListItems
= GetItemCount();
2885 for (int i
= 0; i
< nListItems
; ++i
)
2887 auto entry
= GetListEntry(i
);
2891 DWORD showFlags
= entry
->m_Action
;
2892 if (entry
->IsDirectory())
2893 showFlags
|= GITSLC_SHOWSUBMODULES
;
2895 showFlags
|= GITSLC_SHOWFILES
;
2897 if (check
&& (showFlags
& dwCheck
) && !GetCheck(i
) && !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
2899 SetEntryCheck(entry
, i
, true);
2902 else if (!check
&& (showFlags
& dwCheck
) && GetCheck(i
))
2904 SetEntryCheck(entry
, i
, false);
2910 GetStatisticsString();
2914 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2916 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
2918 if (CRegDWORD(L
"Software\\TortoiseGit\\ShowListFullPathTooltip", TRUE
) != TRUE
)
2921 CAutoReadWeakLock
readLock(m_guard
);
2922 if (!readLock
.IsAcquired())
2925 auto entry
= GetListEntry(pGetInfoTip
->iItem
);
2928 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
2930 CString str
= g_Git
.CombinePath(entry
->GetWinPathString());
2931 wcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), pGetInfoTip
->cchTextMax
- 1);
2935 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2937 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
2939 // Take the default processing unless we set this to something else below.
2940 *pResult
= CDRF_DODEFAULT
;
2942 // First thing - check the draw stage. If it's the control's prepaint
2943 // stage, then tell Windows we want messages for every item.
2945 switch (pLVCD
->nmcd
.dwDrawStage
)
2948 *pResult
= CDRF_NOTIFYITEMDRAW
;
2950 case CDDS_ITEMPREPAINT
:
2952 // This is the prepaint stage for an item. Here's where we set the
2953 // item's text color. Our return value will tell Windows to draw the
2954 // item itself, but it will use the new color we set here.
2956 // Tell Windows to paint the control itself.
2957 *pResult
= CDRF_DODEFAULT
;
2958 CAutoReadWeakLock
readLock(m_guard
, 0);
2959 if (!readLock
.IsAcquired())
2962 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
2964 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
2966 auto entry
= GetListEntry((int)pLVCD
->nmcd
.dwItemSpec
);
2972 // black : unversioned, normal
2975 // brown : missing, deleted, replaced
2976 // green : merged (or potential merges)
2977 // red : conflicts or sure conflicts
2978 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
2979 crText
= RGB(128,128,128);
2980 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2981 crText
= m_Colors
.GetColor(CColors::Conflict
);
2982 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
2983 crText
= m_Colors
.GetColor(CColors::Modified
);
2984 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
2985 crText
= m_Colors
.GetColor(CColors::Added
);
2986 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
2987 crText
= m_Colors
.GetColor(CColors::Deleted
);
2988 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
2989 crText
= m_Colors
.GetColor(CColors::Renamed
);
2990 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
2991 crText
= m_Colors
.GetColor(CColors::Merged
);
2993 crText
= GetSysColor(COLOR_WINDOWTEXT
);
2994 // Store the color back in the NMLVCUSTOMDRAW struct.
2995 pLVCD
->clrText
= crText
;
3002 void CGitStatusListCtrl::OnLvnGetdispinfo(NMHDR
* pNMHDR
, LRESULT
* pResult
)
3004 auto pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
3007 // Create a pointer to the item
3008 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
3010 CAutoReadWeakLock
readLock(m_guard
, 0);
3011 if (readLock
.IsAcquired())
3013 if (pItem
->mask
& LVIF_TEXT
)
3015 CString text
= GetCellText(pItem
->iItem
, pItem
->iSubItem
);
3016 lstrcpyn(pItem
->pszText
, text
, pItem
->cchTextMax
- 1);
3023 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3026 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3027 if (!m_bWaitCursor
&& !m_bBusy
)
3029 HCURSOR hCur
= LoadCursor(nullptr, IDC_ARROW
);
3031 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3033 HCURSOR hCur
= LoadCursor(nullptr, IDC_WAIT
);
3038 void CGitStatusListCtrl::RemoveListEntry(int index
)
3040 CAutoWriteLock
locker(m_guard
);
3043 m_arStatusArray
.erase(m_arStatusArray
.cbegin() + index
);
3046 delete m_arStatusArray
[m_arListArray
[index
]];
3047 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3048 m_arListArray
.erase(m_arListArray
.begin()+index
);
3049 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3056 ///< Set a checkbox on an entry in the listbox
3057 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3058 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3060 CAutoWriteLock
locker(m_guard
);
3061 pEntry
->m_Checked
= bCheck
;
3062 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3063 SetCheck(listboxIndex
, bCheck
);
3066 void CGitStatusListCtrl::ResetChecked(const CTGitPath
& entry
)
3068 CAutoWriteLock
locker(m_guard
);
3069 CTGitPath adjustedEntry
;
3070 if (g_Git
.m_CurrentDir
[g_Git
.m_CurrentDir
.GetLength() - 1] == L
'\\')
3071 adjustedEntry
.SetFromWin(entry
.GetWinPathString().Right(entry
.GetWinPathString().GetLength() - g_Git
.m_CurrentDir
.GetLength()));
3073 adjustedEntry
.SetFromWin(entry
.GetWinPathString().Right(entry
.GetWinPathString().GetLength() - g_Git
.m_CurrentDir
.GetLength() - 1));
3074 if (entry
.IsDirectory())
3076 STRING_VECTOR toDelete
;
3077 for (auto it
= m_mapFilenameToChecked
.begin(); it
!= m_mapFilenameToChecked
.end(); ++it
)
3079 if (adjustedEntry
.IsAncestorOf(it
->first
))
3080 toDelete
.emplace_back(it
->first
);
3082 for (const auto& file
: toDelete
)
3083 m_mapFilenameToChecked
.erase(file
);
3086 m_mapFilenameToChecked
.erase(adjustedEntry
.GetGitPathString());
3090 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3092 CAutoWriteLock
locker(m_guard
);
3093 int nListItems
= GetItemCount();
3094 for (int j
=0; j
< nListItems
; ++j
)
3096 FileEntry
* childEntry
= GetListEntry(j
);
3098 if (!childEntry
|| childEntry
== parentEntry
)
3100 if (childEntry
->checked
!= bCheck
)
3102 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3104 SetEntryCheck(childEntry
,j
,bCheck
);
3115 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3118 CAutoReadLock
locker(m_guard
);
3119 int nListItems
= GetItemCount();
3120 for (int i
= 0; i
< nListItems
; ++i
)
3122 auto entry
= GetListEntry(i
);
3123 if (entry
->m_Checked
)
3124 pathList
.AddPath(*entry
);
3126 pathList
.SortByPathname();
3130 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3131 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3135 CAutoReadLock
locker(m_guard
);
3136 POSITION pos
= GetFirstSelectedItemPosition();
3138 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3140 auto entry
= GetListEntry(index
);
3141 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3143 pathList
.AddPath(*entry
);
3147 UINT
CGitStatusListCtrl::OnGetDlgCode()
3149 // we want to process the return key and not have that one
3150 // routed to the default pushbutton
3151 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3154 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3157 CAutoReadWeakLock
readLock(m_guard
);
3158 if (!readLock
.IsAcquired())
3160 if (!CheckMultipleDiffs())
3162 bool needsRefresh
= false;
3163 bool resolvedTreeConfict
= false;
3164 POSITION pos
= GetFirstSelectedItemPosition();
3167 int index
= GetNextSelectedItem(pos
);
3170 auto file
= GetListEntry(index
);
3171 if (file
== nullptr)
3173 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
3175 else if ((file
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
))
3177 if (CAppUtils::ConflictEdit(*file
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
3179 CString conflictedFile
= g_Git
.CombinePath(file
);
3180 needsRefresh
= needsRefresh
|| !PathFileExists(conflictedFile
);
3181 resolvedTreeConfict
= resolvedTreeConfict
|| (file
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
) == 0;
3184 else if ((file
->m_Action
& CTGitPath::LOGACTIONS_MISSING
) && file
->m_Action
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
) && file
->m_Action
!= (CTGitPath::LOGACTIONS_MISSING
| CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MODIFIED
))
3188 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
3189 StartDiffTwo(index
);
3194 if (needsRefresh
&& GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
3195 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
3196 else if (resolvedTreeConfict
)
3199 Show(m_dwShow
, 0, m_bShowFolders
, 0, true);
3203 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3205 // Since we catch all keystrokes (to have the enter key processed here instead
3206 // of routed to the default pushbutton) we have to make sure that other
3207 // keys like Tab and Esc still do what they're supposed to do
3208 // Tab = change focus to next/previous control
3209 // Esc = quit the dialog
3214 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3220 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3225 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3228 void CGitStatusListCtrl::PreSubclassWindow()
3230 __super::PreSubclassWindow();
3231 EnableToolTips(TRUE
);
3232 SetWindowTheme(GetSafeHwnd(), L
"Explorer", nullptr);
3235 void CGitStatusListCtrl::OnPaint()
3237 LRESULT defres
= Default();
3238 if ((m_bBusy
) || (m_bEmpty
))
3243 if (m_sBusy
.IsEmpty())
3244 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3250 if (m_sEmpty
.IsEmpty())
3251 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3255 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3257 if (IsWindowEnabled())
3258 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3260 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3264 CHeaderCtrl
* pHC
= GetHeaderCtrl();
3268 pHC
->GetItemRect(0, &rcH
);
3269 rc
.top
+= rcH
.bottom
;
3273 CMyMemDC
memDC(pDC
, &rc
);
3275 memDC
.SetTextColor(clrText
);
3276 memDC
.SetBkColor(clrTextBk
);
3277 memDC
.BitBlt(rc
.left
, rc
.top
, rc
.Width(), rc
.Height(), pDC
, rc
.left
, rc
.top
, SRCCOPY
);
3279 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3280 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3281 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3282 memDC
.SelectObject(oldfont
);
3288 // the Default() call did not process the WM_PAINT message!
3289 // Validate the update region ourselves to avoid
3290 // an endless loop repainting
3292 GetUpdateRect(&rc
, FALSE
);
3293 if (!rc
.IsRectEmpty())
3298 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
)
3300 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3302 CAutoReadLock
locker(m_guard
);
3304 CTGitPathList pathList
;
3305 FillListOfSelectedItemPaths(pathList
);
3306 if (pathList
.IsEmpty())
3309 auto pdsrc
= std::make_unique
<CIDropSource
>();
3314 GitDataObject
* pdobj
= new GitDataObject(pathList
, m_Rev2
.IsEmpty() ? m_CurrentVersion
: m_Rev2
);
3319 CDragSourceHelper dragsrchelper
;
3322 dragsrchelper
.InitializeFromWindow(m_hWnd
, pNMLV
->ptAction
, pdobj
);
3324 //dragsrchelper.InitializeFromBitmap()
3325 pdsrc
->m_pIDataObj
= pdobj
;
3326 pdsrc
->m_pIDataObj
->AddRef();
3328 // Initiate the Drag & Drop
3331 ::DoDragDrop(pdobj
, pdsrc
.get(), DROPEFFECT_MOVE
| DROPEFFECT_COPY
, &dwEffect
);
3340 bool CGitStatusListCtrl::EnableFileDrop()
3342 m_bFileDropsEnabled
= true;
3346 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3348 CAutoReadLock
locker(m_guard
);
3349 CTGitPath adjustedEntry
;
3350 if (g_Git
.m_CurrentDir
[g_Git
.m_CurrentDir
.GetLength() - 1] == L
'\\')
3351 adjustedEntry
.SetFromWin(path
.GetWinPathString().Right(path
.GetWinPathString().GetLength() - g_Git
.m_CurrentDir
.GetLength()));
3353 adjustedEntry
.SetFromWin(path
.GetWinPathString().Right(path
.GetWinPathString().GetLength() - g_Git
.m_CurrentDir
.GetLength() - 1));
3354 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
3356 if (m_arStatusArray
[i
]->IsEquivalentTo(adjustedEntry
))
3363 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3365 if (pMsg
->message
== WM_KEYDOWN
)
3367 switch (pMsg
->wParam
)
3371 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3373 // select all entries
3374 for (int i
=0; i
<GetItemCount(); ++i
)
3375 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3383 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3385 // copy all selected paths to the clipboard
3386 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3387 CopySelectedEntriesToClipboard(GITSLC_COLFILENAME
| GITSLC_COLSTATUS
, IDGITLC_COPYRELPATHS
);
3389 CopySelectedEntriesToClipboard(GITSLC_COLFILENAME
, IDGITLC_COPYRELPATHS
);
3396 if ((GetSelectedCount() > 0) && (m_dwContextMenus
& GITSLC_POPDELETE
))
3398 CAutoReadLock
locker(m_guard
);
3399 auto filepath
= GetListEntry(GetSelectionMark());
3400 if (filepath
!= nullptr && (filepath
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)))
3401 DeleteSelectedFiles();
3408 return __super::PreTranslateMessage(pMsg
);
3411 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
, int cmd
)
3413 if (GetSelectedCount() == 0)
3418 bool bMultipleColumnSelected
= ((dwCols
& dwCols
- 1) != 0); // multiple columns are selected (clear least signifient bit and check for zero)
3420 #define ADDTOCLIPBOARDSTRING(x) sClipboard += (sClipboard.IsEmpty() || (sClipboard.Right(1)==L"\n")) ? (x) : ('\t' + x)
3421 #define ADDNEWLINETOCLIPBOARDSTRING() sClipboard += (sClipboard.IsEmpty()) ? L"" : L"\r\n"
3423 // first add the column titles as the first line
3424 DWORD selection
= 0;
3425 int count
= m_ColumnManager
.GetColumnCount();
3426 for (int column
= 0; column
< count
; ++column
)
3428 if ((dwCols
== -1 && m_ColumnManager
.IsVisible(column
)) || (column
< GITSLC_NUMCOLUMNS
&& (dwCols
& (1 << column
))))
3430 if (bMultipleColumnSelected
)
3431 ADDTOCLIPBOARDSTRING(m_ColumnManager
.GetName(column
));
3433 selection
|= 1 << column
;
3437 if (bMultipleColumnSelected
)
3438 ADDNEWLINETOCLIPBOARDSTRING();
3440 // maybe clear first line when only one column is selected (btw by select not by dwCols) is simpler(not faster) way
3441 // but why no title on single column output ?
3442 // if (selection & selection-1) == 0 ) sClipboard = "";
3444 CAutoReadLock
locker(m_guard
);
3446 POSITION pos
= GetFirstSelectedItemPosition();
3449 int index
= GetNextSelectedItem(pos
);
3450 // we selected only cols we want, so not other then select test needed
3451 for (int column
= 0; column
< count
; ++column
)
3453 if (cmd
&& (GITSLC_COLFILENAME
& (1 << column
)))
3455 auto* entry
= GetListEntry(index
);
3461 case IDGITLC_COPYFULL
:
3462 sPath
= g_Git
.CombinePath(entry
);
3464 case IDGITLC_COPYRELPATHS
:
3465 sPath
= entry
->GetGitPathString();
3467 case IDGITLC_COPYFILENAMES
:
3468 sPath
= entry
->GetFileOrDirectoryName();
3471 ADDTOCLIPBOARDSTRING(sPath
);
3474 else if (selection
& (1 << column
))
3475 ADDTOCLIPBOARDSTRING(GetCellText(index
, column
));
3478 ADDNEWLINETOCLIPBOARDSTRING();
3481 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3484 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3487 CAutoReadLock
locker(m_guard
);
3488 std::set
<CString
> changelists
;
3489 POSITION pos
= GetFirstSelectedItemPosition();
3491 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3493 FileEntry
* entry
= GetListEntry(index
);
3494 if (!entry
->changelist
.IsEmpty())
3495 changelists
.insert(entry
->changelist
);
3497 return changelists
.size();
3502 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3504 CAutoWriteLock
locker(m_guard
);
3505 bool bHasGroups
=false;
3508 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
3510 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3512 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3515 if (((m_dwShow
& GITSLC_SHOWUNVERSIONED
) && !m_UnRevFileList
.IsEmpty()) ||
3516 ((m_dwShow
& GITSLC_SHOWIGNORED
) && !m_IgnoreFileList
.IsEmpty()) ||
3517 (m_dwShow
& (GITSLC_SHOWASSUMEVALID
| GITSLC_SHOWSKIPWORKTREE
) && !m_LocalChangesIgnoredFileList
.IsEmpty()) ||
3524 EnableGroupView(bHasGroups
);
3526 TCHAR groupname
[1024] = { 0 };
3532 grp
.cbSize
= sizeof(LVGROUP
);
3533 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3536 //if(m_UnRevFileList.GetCount()>0)
3539 wcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3540 grp
.pszHeader
= groupname
;
3541 grp
.iGroupId
= MERGE_MASK
;
3542 grp
.uAlign
= LVGA_HEADER_LEFT
;
3543 InsertGroup(0, &grp
);
3545 CAutoRepository
repository(g_Git
.GetGitRepository());
3547 MessageBox(CGit::GetLibGit2LastErr(L
"Could not open repository."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
3548 for (int i
= 0; i
<= max
; ++i
)
3551 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3555 rev
.Format(L
"%s^%d", (LPCTSTR
)m_CurrentVersion
, i
+ 1);
3557 if (!CGit::GetHash(repository
, hash
, rev
))
3558 str
+= L
": " + hash
.ToString().Left(g_Git
.GetShortHASHLength());
3560 grp
.pszHeader
= str
.GetBuffer();
3561 str
.ReleaseBuffer();
3563 grp
.uAlign
= LVGA_HEADER_LEFT
;
3564 InsertGroup(i
+1, &grp
);
3569 wcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3570 grp
.pszHeader
= groupname
;
3571 grp
.iGroupId
= groupindex
;
3572 grp
.uAlign
= LVGA_HEADER_LEFT
;
3573 InsertGroup(groupindex
++, &grp
);
3576 wcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3577 grp
.pszHeader
= groupname
;
3578 grp
.iGroupId
= groupindex
;
3579 grp
.uAlign
= LVGA_HEADER_LEFT
;
3580 InsertGroup(groupindex
++, &grp
);
3583 //if(m_IgnoreFileList.GetCount()>0)
3585 wcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3586 grp
.pszHeader
= groupname
;
3587 grp
.iGroupId
= groupindex
;
3588 grp
.uAlign
= LVGA_HEADER_LEFT
;
3589 InsertGroup(groupindex
++, &grp
);
3593 wcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNORELOCALCHANGES
)), 1023);
3594 grp
.pszHeader
= groupname
;
3595 grp
.iGroupId
= groupindex
;
3596 grp
.uAlign
= LVGA_HEADER_LEFT
;
3597 InsertGroup(groupindex
++, &grp
);
3603 m_bHasIgnoreGroup
= false;
3605 // now add the items which don't belong to a group
3607 grp
.cbSize
= sizeof(LVGROUP
);
3608 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3609 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3610 wcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3611 grp
.pszHeader
= groupname
;
3612 grp
.iGroupId
= groupindex
;
3613 grp
.uAlign
= LVGA_HEADER_LEFT
;
3614 InsertGroup(groupindex
++, &grp
);
3616 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
3618 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3621 grp
.cbSize
= sizeof(LVGROUP
);
3622 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3623 wcsncpy_s(groupname
, 1024, it
->first
, 1023);
3624 grp
.pszHeader
= groupname
;
3625 grp
.iGroupId
= groupindex
;
3626 grp
.uAlign
= LVGA_HEADER_LEFT
;
3627 it
->second
= InsertGroup(groupindex
++, &grp
);
3630 m_bHasIgnoreGroup
= true;
3633 if (m_bHasIgnoreGroup
)
3635 // and now add the group 'ignore-on-commit'
3636 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3637 if (it
!= m_changelists
.end())
3639 grp
.cbSize
= sizeof(LVGROUP
);
3640 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3641 wcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3642 grp
.pszHeader
= groupname
;
3643 grp
.iGroupId
= groupindex
;
3644 grp
.uAlign
= LVGA_HEADER_LEFT
;
3645 it
->second
= InsertGroup(groupindex
, &grp
);
3652 void CGitStatusListCtrl::NotifyCheck()
3654 CWnd
* pParent
= GetLogicalParent();
3655 if (pParent
&& pParent
->GetSafeHwnd())
3657 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3661 int CGitStatusListCtrl::UpdateFileList(const CTGitPathList
* list
)
3663 CAutoWriteLock
locker(m_guard
);
3664 m_CurrentVersion
= GIT_REV_ZERO
;
3666 g_Git
.GetWorkingTreeChanges(m_StatusFileList
, m_amend
, list
);
3668 BOOL bDeleteChecked
= FALSE
;
3669 int deleteFromIndex
= 0;
3670 bool needsRefresh
= false;
3671 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
3673 auto gitpatch
= const_cast<CTGitPath
*>(&m_StatusFileList
[i
]);
3674 gitpatch
->m_Checked
= TRUE
;
3676 if ((gitpatch
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_REPLACED
| CTGitPath::LOGACTIONS_MODIFIED
)) && !gitpatch
->Exists())
3678 if (!bDeleteChecked
)
3681 message
.Format(IDS_ASK_REMOVE_FROM_INDEX
, gitpatch
->GetWinPath());
3682 deleteFromIndex
= CMessageBox::ShowCheck(GetSafeHwnd(), message
, L
"TortoiseGit", 1, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_RESTORE_FROM_INDEX
)), CString(MAKEINTRESOURCE(IDS_REMOVE_FROM_INDEX
)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), nullptr, CString(MAKEINTRESOURCE(IDS_DO_SAME_FOR_REST
)), &bDeleteChecked
);
3684 if (deleteFromIndex
== 1)
3687 if (g_Git
.Run(L
"git.exe checkout -- \"" + gitpatch
->GetWinPathString() + L
'"', &err
, CP_UTF8
))
3688 MessageBox(L
"Restoring from index failed:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3690 needsRefresh
= true;
3692 else if (deleteFromIndex
== 2)
3695 if (g_Git
.Run(L
"git.exe rm -f --cache -- \"" + gitpatch
->GetWinPathString() + L
'"', &err
, CP_UTF8
))
3696 MessageBox(L
"Removing from index failed:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
3698 needsRefresh
= true;
3702 m_arStatusArray
.push_back(&m_StatusFileList
[i
]);
3706 MessageBox(L
"Due to changes to the index, please refresh the dialog (e.g., by pressing F5).", L
"TortoiseGit", MB_ICONINFORMATION
);
3711 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3713 CAutoWriteLock
locker(m_guard
);
3714 m_arStatusArray
.clear();
3715 for (int i
= 0; i
< list
.GetCount(); ++i
)
3717 auto gitpath
= const_cast<CTGitPath
*>(&list
[i
]);
3719 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3722 gitpath
->m_Checked
= TRUE
;
3723 m_arStatusArray
.push_back(&list
[i
]);
3728 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
&list
)
3730 CAutoWriteLock
locker(m_guard
);
3731 m_UnRevFileList
= list
;
3732 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3734 auto gitpatch
= const_cast<CTGitPath
*>(&m_UnRevFileList
[i
]);
3735 gitpatch
->m_Checked
= FALSE
;
3736 m_arStatusArray
.push_back(&m_UnRevFileList
[i
]);
3741 int CGitStatusListCtrl::UpdateUnRevFileList(const CTGitPathList
* List
)
3743 CAutoWriteLock
locker(m_guard
);
3745 if (m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
, List
, &err
))
3747 MessageBox(L
"Failed to get UnRev file list\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
3751 if (m_StatusFileList
.m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3755 while (unrev
< m_UnRevFileList
.GetCount() && status
< m_StatusFileList
.GetCount())
3757 auto cmp
= CTGitPath::Compare(m_UnRevFileList
[unrev
], m_StatusFileList
[status
]);
3764 m_UnRevFileList
.RemovePath(m_StatusFileList
[status
]);
3769 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3771 auto gitpatch
= const_cast<CTGitPath
*>(&m_UnRevFileList
[i
]);
3772 gitpatch
->m_Checked
= FALSE
;
3773 m_arStatusArray
.push_back(&m_UnRevFileList
[i
]);
3778 int CGitStatusListCtrl::UpdateIgnoreFileList(const CTGitPathList
* List
)
3780 CAutoWriteLock
locker(m_guard
);
3782 if (m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, List
, &err
))
3784 MessageBox(L
"Failed to get Ignore file list\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
3788 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
3790 auto gitpatch
= const_cast<CTGitPath
*>(&m_IgnoreFileList
[i
]);
3791 gitpatch
->m_Checked
= FALSE
;
3792 m_arStatusArray
.push_back(&m_IgnoreFileList
[i
]);
3797 int CGitStatusListCtrl::UpdateLocalChangesIgnoredFileList(const CTGitPathList
* list
)
3799 CAutoWriteLock
locker(m_guard
);
3800 m_LocalChangesIgnoredFileList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, GIT_IDXENTRY_SKIP_WORKTREE
, list
);
3801 for (int i
= 0; i
< m_LocalChangesIgnoredFileList
.GetCount(); ++i
)
3803 auto gitpatch
= const_cast<CTGitPath
*>(&m_LocalChangesIgnoredFileList
[i
]);
3804 gitpatch
->m_Checked
= FALSE
;
3805 m_arStatusArray
.push_back(&m_LocalChangesIgnoredFileList
[i
]);
3810 int CGitStatusListCtrl::UpdateFileList(int mask
, bool once
, const CTGitPathList
* List
)
3812 CAutoWriteLock
locker(m_guard
);
3813 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
3815 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
3817 UpdateFileList(List
);
3818 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
3821 if (mask
& CGitStatusListCtrl::FILELIST_UNVER
|| mask
& CGitStatusListCtrl::FILELIST_IGNORE
)
3823 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
3825 UpdateUnRevFileList(List
);
3826 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3828 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
3830 UpdateIgnoreFileList(List
);
3831 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_IGNORE
;
3834 if (mask
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
&& (once
|| (!(m_FileLoaded
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
))))
3836 UpdateLocalChangesIgnoredFileList(List
);
3837 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
;
3842 void CGitStatusListCtrl::Clear()
3844 CAutoWriteLock
locker(m_guard
);
3846 this->DeleteAllItems();
3847 this->m_arListArray
.clear();
3848 this->m_arStatusArray
.clear();
3849 this->m_changelists
.clear();
3852 bool CGitStatusListCtrl::CheckMultipleDiffs()
3854 UINT selCount
= GetSelectedCount();
3855 if (selCount
> max(3, (DWORD
)CRegDWORD(L
"Software\\TortoiseGit\\NumDiffWarning", 10)))
3858 message
.Format(IDS_STATUSLIST_WARN_MAXDIFF
, selCount
);
3859 return MessageBox(message
, L
"TortoiseGit", MB_YESNO
| MB_ICONQUESTION
) == IDYES
;
3864 //////////////////////////////////////////////////////////////////////////
3865 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
3867 if (pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
3869 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
3872 TCHAR szFileName
[MAX_PATH
] = {0};
3874 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, nullptr, 0);
3877 clientpoint
.x
= pt
.x
;
3878 clientpoint
.y
= pt
.y
;
3879 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3880 if ((m_pGitStatusListCtrl
->IsGroupViewEnabled()) && (m_pGitStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3883 CTGitPathList changelistItems
;
3884 for (UINT i
= 0; i
< cFiles
; ++i
)
3886 if (DragQueryFile(hDrop
, i
, szFileName
, _countof(szFileName
)))
3887 changelistItems
.AddPath(CTGitPath(szFileName
));
3889 // find the changelist name
3890 CString sChangelist
;
3891 LONG_PTR nGroup
= m_pGitStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
3892 for (std::map
<CString
, int>::iterator it
= m_pGitStatusListCtrl
->m_changelists
.begin(); it
!= m_pGitStatusListCtrl
->m_changelists
.end(); ++it
)
3893 if (it
->second
== nGroup
)
3894 sChangelist
= it
->first
;
3896 if (!sChangelist
.IsEmpty())
3899 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3901 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3903 int index
= m_pGitStatusListCtrl
->GetIndex(changelistItems
[l
]);
3906 auto e
= m_pGitStatusListCtrl
->GetListEntry(index
);
3909 e
->changelist
= sChangelist
;
3912 if (m_pGitStatusListCtrl
->m_changelists
.find(e
->changelist
) != m_pGitStatusListCtrl
->m_changelists
.end())
3913 m_pGitStatusListCtrl
->SetItemGroup(index
, m_pGitStatusListCtrl
->m_changelists
[e
->changelist
]);
3915 m_pGitStatusListCtrl
->SetItemGroup(index
, 0);
3921 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3923 ::SendMessage(hParentWnd
, CGitStatusListCtrl::GITSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
3928 CMessageBox::Show(m_pGitStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), L
"TortoiseGit", MB_ICONERROR
);
3933 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3935 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3937 int index
= m_pGitStatusListCtrl
->GetIndex(changelistItems
[l
]);
3940 auto e
= m_pGitStatusListCtrl
->GetListEntry(index
);
3943 e
->changelist
= sChangelist
;
3944 m_pGitStatusListCtrl
->SetItemGroup(index
, 0);
3949 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3951 ::SendMessage(hParentWnd
, CGitStatusListCtrl::GITSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
3956 CMessageBox::Show(m_pGitStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), L
"TortoiseGit", MB_ICONERROR
);
3962 for (UINT i
= 0; i
< cFiles
; ++i
)
3964 if (!DragQueryFile(hDrop
, i
, szFileName
, _countof(szFileName
)))
3967 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3969 ::SendMessage(hParentWnd
, CGitStatusListCtrl::GITSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
3973 GlobalUnlock(medium
.hGlobal
);
3975 return true; //let base free the medium
3978 HRESULT STDMETHODCALLTYPE
CGitStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
* pdwEffect
)
3980 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
3981 *pdwEffect
= DROPEFFECT_COPY
;
3982 if (m_pGitStatusListCtrl
)
3985 clientpoint
.x
= pt
.x
;
3986 clientpoint
.y
= pt
.y
;
3987 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3988 if ((m_pGitStatusListCtrl
->IsGroupViewEnabled()) && (m_pGitStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3989 *pdwEffect
= DROPEFFECT_NONE
;
3990 else if ((!m_pGitStatusListCtrl
->m_bFileDropsEnabled
) || (m_pGitStatusListCtrl
->m_bOwnDrag
))
3991 *pdwEffect
= DROPEFFECT_NONE
;
3996 void CGitStatusListCtrl::FilesExport()
3998 CAutoReadLock
locker(m_guard
);
4000 // export all changed files to a folder
4001 CBrowseFolder browseFolder
;
4002 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
4003 if (browseFolder
.Show(GetSafeHwnd(), exportDir
) != CBrowseFolder::OK
)
4006 POSITION pos
= GetFirstSelectedItemPosition();
4008 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4010 auto fd
= GetListEntry(index
);
4011 // we cannot export directories or folders
4012 if ((fd
->m_Action
& CTGitPath::LOGACTIONS_DELETED
) || fd
->IsDirectory())
4015 CPathUtils::MakeSureDirectoryPathExists(exportDir
+ L
'\\' + fd
->GetContainingDirectory().GetWinPathString());
4016 CString filename
= exportDir
+ L
'\\' + fd
->GetWinPathString();
4017 if (m_CurrentVersion
== GIT_REV_ZERO
)
4019 if (!CopyFile(g_Git
.CombinePath(fd
), filename
, false))
4021 MessageBox(CFormatMessageWrapper(), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
4027 if (g_Git
.GetOneFile(m_CurrentVersion
, *fd
, filename
))
4030 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)fd
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)filename
);
4031 if (CMessageBox::Show(GetSafeHwnd(), g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), L
"TortoiseGit", 2, IDI_WARNING
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
4038 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4040 CAutoReadLock
locker(m_guard
);
4042 filename
.Format(L
"%s\\%s-%s%s", (LPCTSTR
)g_Git
.CombinePath(path
->GetContainingDirectory()), (LPCTSTR
)path
->GetBaseFilename(), (LPCTSTR
)m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), (LPCTSTR
)path
->GetFileExtension());
4043 if (!CAppUtils::FileOpenSave(filename
, nullptr, 0, 0, false, GetSafeHwnd()))
4045 if (m_CurrentVersion
== GIT_REV_ZERO
)
4047 if (!CopyFile(g_Git
.CombinePath(path
), filename
, false))
4049 MessageBox(CFormatMessageWrapper(), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
4055 if (g_Git
.GetOneFile(m_CurrentVersion
, *path
, filename
))
4058 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)path
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)filename
);
4059 CMessageBox::Show(GetSafeHwnd(), g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), L
"TortoiseGit", MB_OK
);
4065 int CGitStatusListCtrl::RevertSelectedItemToVersion(bool parent
)
4067 CAutoReadLock
locker(m_guard
);
4068 if(this->m_CurrentVersion
.IsEmpty())
4070 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4073 POSITION pos
= GetFirstSelectedItemPosition();
4076 std::map
<CString
, int> versionMap
;
4077 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4079 auto fentry
= GetListEntry(index
);
4083 int parentNo
= fentry
->m_ParentNo
& PARENT_MASK
;
4085 ref
.Format(L
"%s^%d", (LPCTSTR
)m_CurrentVersion
, parentNo
+ 1);
4087 if (g_Git
.GetHash(hash
, ref
))
4089 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + ref
+ L
"\"."), L
"TortoiseGit", MB_ICONERROR
);
4093 version
= hash
.ToString();
4096 version
= m_CurrentVersion
;
4098 CString filename
= fentry
->GetGitPathString();
4099 if (!fentry
->GetGitOldPathString().IsEmpty())
4100 filename
= fentry
->GetGitOldPathString();
4101 cmd
.Format(L
"git.exe checkout %s -- \"%s\"", (LPCTSTR
)version
, (LPCTSTR
)filename
);
4103 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4105 if (MessageBox(out
, L
"TortoiseGit", MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4109 versionMap
[version
]++;
4113 for (auto it
= versionMap
.cbegin(); it
!= versionMap
.cend(); ++it
)
4115 CString versionEntry
;
4116 versionEntry
.Format(IDS_STATUSLIST_FILESREVERTED
, it
->second
, (LPCTSTR
)it
->first
);
4117 out
+= versionEntry
+ L
"\r\n";
4121 if (GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
4122 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
4123 CMessageBox::Show(GetSafeHwnd(), out
, L
"TortoiseGit", MB_OK
);
4128 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4131 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4132 file
= g_Git
.CombinePath(filepath
);
4135 file
= CTempFiles::Instance().GetTempFilePath(false, *filepath
, m_CurrentVersion
).GetWinPathString();
4137 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4139 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)filepath
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)file
);
4140 CMessageBox::Show(GetSafeHwnd(), g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), L
"TortoiseGit", MB_OK
);
4143 SetFileAttributes(file
, FILE_ATTRIBUTE_READONLY
);
4145 if(mode
== ALTERNATIVEEDITOR
)
4147 CAppUtils::LaunchAlternativeEditor(file
);
4152 CAppUtils::ShellOpen(file
, GetSafeHwnd());
4154 CAppUtils::ShowOpenWithDialog(file
, GetSafeHwnd());
4157 void CGitStatusListCtrl::DeleteSelectedFiles()
4159 CAutoWriteLock
locker(m_guard
);
4161 std::vector
<int> selectIndex
;
4163 POSITION pos
= GetFirstSelectedItemPosition();
4165 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4166 selectIndex
.push_back(index
);
4168 CAutoRepository repo
= g_Git
.GetGitRepository();
4171 MessageBox(g_Git
.GetLibGit2LastErr(L
"Could not open repository."), L
"TortoiseGit", MB_OK
);
4174 CAutoIndex gitIndex
;
4175 if (git_repository_index(gitIndex
.GetPointer(), repo
))
4177 g_Git
.GetLibGit2LastErr(L
"Could not open index.");
4180 int needWriteIndex
= 0;
4182 //Create file-list ('\0' separated) for SHFileOperation
4184 for (size_t i
= 0; i
< selectIndex
.size(); ++i
)
4186 index
= selectIndex
[i
];
4188 auto path
= GetListEntry(index
);
4189 if (path
== nullptr)
4192 // do not report errors as we could remove an unversioned file
4193 needWriteIndex
+= git_index_remove_bypath(gitIndex
, CUnicodeUtils::GetUTF8(path
->GetGitPathString())) == 0 ? 1 : 0;
4195 if (!path
->Exists())
4198 filelist
+= path
->GetWinPathString();
4202 int len
= filelist
.GetLength();
4203 auto buf
= std::make_unique
<TCHAR
[]>(len
+ 2);
4204 wcscpy_s(buf
.get(), len
+ 2, filelist
);
4205 CStringUtils::PipesToNulls(buf
.get(), len
+ 2);
4206 SHFILEOPSTRUCT fileop
;
4207 fileop
.hwnd
= this->m_hWnd
;
4208 fileop
.wFunc
= FO_DELETE
;
4209 fileop
.pFrom
= buf
.get();
4210 fileop
.pTo
= nullptr;
4211 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
4212 fileop
.lpszProgressTitle
= L
"deleting file";
4213 int result
= SHFileOperation(&fileop
);
4215 if ((result
== 0 || len
== 1) && (!fileop
.fAnyOperationsAborted
))
4217 if (needWriteIndex
&& git_index_write(gitIndex
))
4218 MessageBox(g_Git
.GetLibGit2LastErr(L
"Could not write index."), L
"TortoiseGit", MB_OK
);
4222 CWnd
* pParent
= GetLogicalParent();
4223 if (pParent
&& pParent
->GetSafeHwnd())
4224 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
4230 POSITION pos2
= nullptr;
4231 while ((pos2
= GetFirstSelectedItemPosition()) != nullptr)
4233 int index2
= GetNextSelectedItem(pos2
);
4234 if (GetCheck(index2
))
4238 RemoveListEntry(index2
);
4244 BOOL
CGitStatusListCtrl::OnWndMsg(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
)
4248 case WM_MENUCHAR
: // only supported by IContextMenu3
4251 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4257 case WM_MEASUREITEM
:
4259 break; // if wParam != 0 then the message is not menu-related
4262 case WM_INITMENUPOPUP
:
4264 HMENU hMenu
= (HMENU
)wParam
;
4265 if ((hMenu
== m_hShellMenu
) && (GetMenuItemCount(hMenu
) == 0))
4267 // the shell submenu is populated only on request, i.e. right
4268 // before the submenu is shown
4271 delete g_pFolderhook
;
4272 g_pFolderhook
= nullptr;
4274 CTGitPathList targetList
;
4275 FillListOfSelectedItemPaths(targetList
);
4276 if (!targetList
.IsEmpty())
4278 // get IShellFolder interface of Desktop (root of shell namespace)
4279 if (g_psfDesktopFolder
)
4280 g_psfDesktopFolder
->Release();
4281 SHGetDesktopFolder(&g_psfDesktopFolder
); // needed to obtain full qualified pidl
4283 // ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
4284 // but since we use the Desktop as our interface and the Desktop is the namespace root
4285 // that means that it's a fully qualified PIDL, which is what we need
4289 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
4292 CoTaskMemFree(g_pidlArray
[i
]);
4294 CoTaskMemFree(g_pidlArray
);
4295 g_pidlArray
= nullptr;
4296 g_pidlArrayItems
= 0;
4298 int nItems
= targetList
.GetCount();
4299 g_pidlArray
= (LPITEMIDLIST
*)CoTaskMemAlloc((nItems
+ 10) * sizeof(LPITEMIDLIST
));
4300 SecureZeroMemory(g_pidlArray
, (nItems
+ 10) * sizeof(LPITEMIDLIST
));
4301 int succeededItems
= 0;
4302 PIDLIST_RELATIVE pidl
= nullptr;
4305 auto filepath
= std::make_unique
<WCHAR
[]>(bufsize
);
4306 for (int i
= 0; i
< nItems
; i
++)
4308 CString fullPath
= g_Git
.CombinePath(targetList
[i
].GetWinPath());
4309 if (bufsize
< fullPath
.GetLength())
4311 bufsize
= fullPath
.GetLength() + 3;
4312 filepath
= std::make_unique
<WCHAR
[]>(bufsize
);
4314 wcscpy_s(filepath
.get(), bufsize
, fullPath
);
4315 if (SUCCEEDED(g_psfDesktopFolder
->ParseDisplayName(nullptr, 0, filepath
.get(), nullptr, &pidl
, nullptr)))
4316 g_pidlArray
[succeededItems
++] = pidl
; // copy pidl to pidlArray
4318 if (succeededItems
== 0)
4320 CoTaskMemFree(g_pidlArray
);
4321 g_pidlArray
= nullptr;
4324 g_pidlArrayItems
= succeededItems
;
4326 if (g_pidlArrayItems
)
4328 CString ext
= targetList
[0].GetFileExtension();
4330 ASSOCIATIONELEMENT
const rgAssocItem
[] =
4332 { ASSOCCLASS_PROGID_STR
, nullptr, ext
},
4333 { ASSOCCLASS_SYSTEM_STR
, nullptr, ext
},
4334 { ASSOCCLASS_APP_STR
, nullptr, ext
},
4335 { ASSOCCLASS_STAR
, nullptr, nullptr },
4336 { ASSOCCLASS_FOLDER
, nullptr, nullptr },
4338 IQueryAssociations
* pIQueryAssociations
= nullptr;
4339 if (FAILED(AssocCreateForClasses(rgAssocItem
, ARRAYSIZE(rgAssocItem
), IID_IQueryAssociations
, (void**)&pIQueryAssociations
)))
4340 pIQueryAssociations
= nullptr; // not a problem, it works without this
4342 g_pFolderhook
= new CIShellFolderHook(g_psfDesktopFolder
, targetList
);
4343 LPCONTEXTMENU icm1
= nullptr;
4345 DEFCONTEXTMENU dcm
= { 0 };
4347 dcm
.psf
= g_pFolderhook
;
4348 dcm
.cidl
= g_pidlArrayItems
;
4349 dcm
.apidl
= (PCUITEMID_CHILD_ARRAY
)g_pidlArray
;
4350 dcm
.punkAssociationInfo
= pIQueryAssociations
;
4351 if (SUCCEEDED(SHCreateDefaultContextMenu(&dcm
, IID_IContextMenu
, (void**)&icm1
)))
4353 int iMenuType
= 0; // to know which version of IContextMenu is supported
4355 { // since we got an IContextMenu interface we can now obtain the higher version interfaces via that
4356 if (icm1
->QueryInterface(IID_IContextMenu3
, (void**)&m_pContextMenu
) == S_OK
)
4358 else if (icm1
->QueryInterface(IID_IContextMenu2
, (void**)&m_pContextMenu
) == S_OK
)
4362 icm1
->Release(); // we can now release version 1 interface, cause we got a higher one
4365 // since no higher versions were found
4366 // redirect ppContextMenu to version 1 interface
4368 m_pContextMenu
= icm1
;
4373 // lets fill the our popup menu
4374 UINT flags
= CMF_NORMAL
;
4375 flags
|= (GetKeyState(VK_SHIFT
) & 0x8000) != 0 ? CMF_EXTENDEDVERBS
: 0;
4376 m_pContextMenu
->QueryContextMenu(hMenu
, 0, SHELL_MIN_CMD
, SHELL_MAX_CMD
, flags
);
4379 // subclass window to handle menu related messages in CShellContextMenu
4380 if (iMenuType
> 1) // only subclass if its version 2 or 3
4383 g_IContext2
= (LPCONTEXTMENU2
)m_pContextMenu
;
4385 g_IContext3
= (LPCONTEXTMENU3
)m_pContextMenu
;
4389 if (pIQueryAssociations
)
4390 pIQueryAssociations
->Release();
4394 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4395 else if (g_IContext2
)
4396 g_IContext2
->HandleMenuMsg(message
, wParam
, lParam
);
4406 return __super::OnWndMsg(message
, wParam
, lParam
, pResult
);
4409 CTGitPath
* CGitStatusListCtrl::GetListEntry(int index
)
4411 ATLASSERT(m_guard
.GetCurrentThreadStatus());
4412 auto entry
= reinterpret_cast<CTGitPath
*>(GetItemData(index
));
4417 void CGitStatusListCtrl::OnSysColorChange()
4419 __super::OnSysColorChange();
4420 if (m_nBackgroundImageID
)
4421 CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), m_nBackgroundImageID
);