1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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"
35 #include "GitProgressDlg.h"
36 #include "SysImageList.h"
40 #include "GitAdminDir.h"
41 #include "DragDropImpl.h"
42 #include "GitDataObject.h"
43 #include "ProgressCommands/AddProgressCommand.h"
45 #include "FormatMessageWrapper.h"
46 #include "BrowseFolder.h"
48 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
49 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCOUNTCHANGED"));
50 const UINT
CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
51 = ::RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
52 const UINT
CGitStatusListCtrl::GITSLNM_ADDFILE
53 = ::RegisterWindowMessage(_T("GITSLNM_ADDFILE"));
54 const UINT
CGitStatusListCtrl::GITSLNM_CHECKCHANGED
55 = ::RegisterWindowMessage(_T("GITSLNM_CHECKCHANGED"));
56 const UINT
CGitStatusListCtrl::GITSLNM_ITEMCHANGED
57 = ::RegisterWindowMessage(_T("GITSLNM_ITEMCHANGED"));
61 bool operator() (const std::wstring
& lhs
, const std::wstring
& rhs
) const
63 // no logical comparison here: we need this sorted strictly
64 return _wcsicmp(lhs
.c_str(), rhs
.c_str()) < 0;
68 class CIShellFolderHook
: public IShellFolder
71 CIShellFolderHook(LPSHELLFOLDER sf
, const CTGitPathList
& pathlist
)
75 // it seems the paths in the HDROP need to be sorted, otherwise
76 // it might not work properly or even crash.
77 // to get the items sorted, we just add them to a set
78 for (int i
= 0; i
< pathlist
.GetCount(); ++i
)
79 sortedpaths
.insert((LPCTSTR
)g_Git
.CombinePath(pathlist
[i
].GetWinPath()));
82 ~CIShellFolderHook() { m_iSF
->Release(); }
84 // IUnknown methods --------
85 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, __RPC__deref_out
void **ppvObject
) { return m_iSF
->QueryInterface(riid
, ppvObject
); }
86 virtual ULONG STDMETHODCALLTYPE
AddRef(void) { return m_iSF
->AddRef(); }
87 virtual ULONG STDMETHODCALLTYPE
Release(void) { return m_iSF
->Release(); }
89 // IShellFolder methods ----
90 virtual HRESULT STDMETHODCALLTYPE
GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
);
92 virtual HRESULT STDMETHODCALLTYPE
CompareIDs(LPARAM lParam
, __RPC__in PCUIDLIST_RELATIVE pidl1
, __RPC__in PCUIDLIST_RELATIVE pidl2
) { return m_iSF
->CompareIDs(lParam
, pidl1
, pidl2
); }
93 virtual HRESULT STDMETHODCALLTYPE
GetDisplayNameOf(__RPC__in_opt PCUITEMID_CHILD pidl
, SHGDNF uFlags
, __RPC__out STRRET
*pName
) { return m_iSF
->GetDisplayNameOf(pidl
, uFlags
, pName
); }
94 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
); }
95 virtual HRESULT STDMETHODCALLTYPE
EnumObjects(__RPC__in_opt HWND hwndOwner
, SHCONTF grfFlags
, __RPC__deref_out_opt IEnumIDList
**ppenumIDList
) { return m_iSF
->EnumObjects(hwndOwner
, grfFlags
, ppenumIDList
); }
96 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
); }
97 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
); }
98 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
); }
99 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
); }
100 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
); }
104 std::set
<std::wstring
, icompare
> sortedpaths
;
107 HRESULT STDMETHODCALLTYPE
CIShellFolderHook::GetUIObjectOf(HWND hwndOwner
, UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
, REFIID riid
, UINT
*rgfReserved
, void **ppv
)
109 if (InlineIsEqualGUID(riid
, IID_IDataObject
))
111 HRESULT hres
= m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, IID_IDataObject
, nullptr, ppv
);
115 IDataObject
* idata
= (LPDATAOBJECT
)(*ppv
);
116 // the IDataObject returned here doesn't have a HDROP, so we create one ourselves and add it to the IDataObject
117 // the HDROP is necessary for most context menu handlers
119 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
121 nLength
+= (int)it
->size();
122 nLength
+= 1; // '\0' separator
124 int nBufferSize
= sizeof(DROPFILES
) + ((nLength
+ 5)*sizeof(TCHAR
));
125 auto pBuffer
= std::make_unique
<char[]>(nBufferSize
);
126 SecureZeroMemory(pBuffer
.get(), nBufferSize
);
127 DROPFILES
* df
= (DROPFILES
*)pBuffer
.get();
128 df
->pFiles
= sizeof(DROPFILES
);
130 TCHAR
* pFilenames
= (TCHAR
*)((BYTE
*)(pBuffer
.get()) + sizeof(DROPFILES
));
131 TCHAR
* pCurrentFilename
= pFilenames
;
133 for (auto it
= sortedpaths
.cbegin(); it
!= sortedpaths
.cend(); ++it
)
135 wcscpy_s(pCurrentFilename
, it
->size() + 1, it
->c_str());
136 pCurrentFilename
+= it
->size();
137 *pCurrentFilename
= '\0'; // separator between file names
140 *pCurrentFilename
= '\0'; // terminate array
142 *pCurrentFilename
= '\0'; // terminate array
143 STGMEDIUM medium
= { 0 };
144 medium
.tymed
= TYMED_HGLOBAL
;
145 medium
.hGlobal
= GlobalAlloc(GMEM_ZEROINIT
| GMEM_MOVEABLE
, nBufferSize
+ 20);
148 LPVOID pMem
= ::GlobalLock(medium
.hGlobal
);
151 memcpy(pMem
, pBuffer
.get(), nBufferSize
);
152 GlobalUnlock(medium
.hGlobal
);
153 FORMATETC formatetc
= { 0 };
154 formatetc
.cfFormat
= CF_HDROP
;
155 formatetc
.dwAspect
= DVASPECT_CONTENT
;
156 formatetc
.lindex
= -1;
157 formatetc
.tymed
= TYMED_HGLOBAL
;
158 medium
.pUnkForRelease
= nullptr;
159 hres
= idata
->SetData(&formatetc
, &medium
, TRUE
);
163 return E_OUTOFMEMORY
;
167 // just pass it on to the base object
168 return m_iSF
->GetUIObjectOf(hwndOwner
, cidl
, apidl
, riid
, rgfReserved
, ppv
);
172 IContextMenu2
* g_IContext2
= nullptr;
173 IContextMenu3
* g_IContext3
= nullptr;
174 CIShellFolderHook
* g_pFolderhook
= nullptr;
175 IShellFolder
* g_psfDesktopFolder
= nullptr;
176 LPITEMIDLIST
* g_pidlArray
= nullptr;
177 int g_pidlArrayItems
= 0;
179 #define SHELL_MIN_CMD 10000
180 #define SHELL_MAX_CMD 20000
182 HRESULT CALLBACK
dfmCallback(IShellFolder
* /*psf*/, HWND
/*hwnd*/, IDataObject
* /*pdtobj*/, UINT uMsg
, WPARAM
/*wParam*/, LPARAM
/*lParam*/)
186 case DFM_MERGECONTEXTMENU
:
188 case DFM_INVOKECOMMAND
:
189 case DFM_INVOKECOMMANDEX
:
190 case DFM_GETDEFSTATICID
: // Required for Windows 7 to pick a default
196 BEGIN_MESSAGE_MAP(CGitStatusListCtrl
, CResizableColumnsListCtrl
<CListCtrl
>)
197 ON_NOTIFY(HDN_ITEMCLICKA
, 0, OnHdnItemclick
)
198 ON_NOTIFY(HDN_ITEMCLICKW
, 0, OnHdnItemclick
)
199 ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED
, OnLvnItemchanged
)
201 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclk
)
202 ON_NOTIFY_REFLECT(LVN_GETINFOTIP
, OnLvnGetInfoTip
)
203 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
206 ON_NOTIFY_REFLECT(NM_RETURN
, OnNMReturn
)
209 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
210 ON_NOTIFY_REFLECT(LVN_ITEMCHANGING
, &CGitStatusListCtrl::OnLvnItemchanging
)
213 CGitStatusListCtrl::CGitStatusListCtrl() : CResizableColumnsListCtrl
<CListCtrl
>()
214 //, m_HeadRev(GitRev::REV_HEAD)
215 , m_pbCanceled(nullptr)
216 , m_pStatLabel(nullptr)
217 , m_pSelectButton(nullptr)
218 , m_pConfirmButton(nullptr)
221 , m_bShowIgnores(false)
222 , m_pDropTarget(nullptr)
223 , m_bIgnoreRemoveOnly(false)
224 , m_bCheckChildrenWithParent(false)
225 , m_bUnversionedLast(true)
226 , m_bHasChangeLists(false)
230 , m_bHasCheckboxes(false)
231 , m_bCheckIfGroupsExist(true)
232 , m_bFileDropsEnabled(false)
234 , m_dwDefaultColumns(0)
235 , m_bAscending(false)
236 , m_nSortedColumn(-1)
237 , m_bHasExternalsFromDifferentRepos(false)
238 , m_sNoPropValueText(MAKEINTRESOURCE(IDS_STATUSLIST_NOPROPVALUE
))
240 , m_bDoNotAutoselectSubmodules(false)
241 , m_bNoAutoselectMissing(false)
243 , m_hwndLogicalParent(nullptr)
244 , m_bHasUnversionedItems(FALSE
)
246 , m_bHasExternals(false)
247 , m_bHasIgnoreGroup(false)
257 , m_nShownUnversioned(0)
258 , m_nShownModified(0)
261 , m_nShownConflicted(0)
263 , m_nShownSubmodules(0)
265 , m_bShowFolders(false)
267 , m_dwContextMenus(0)
270 , m_pContextMenu(nullptr)
271 , m_hShellMenu(nullptr)
274 m_dwDefaultColumns
= 0;
276 m_bIsRevertTheirMy
= false;
277 m_bNoAutoselectMissing
= CRegDWORD(L
"Software\\TortoiseGit\\AutoselectMissingFiles", FALSE
) == TRUE
;
278 this->m_nLineAdded
=this->m_nLineDeleted
=0;
281 CGitStatusListCtrl::~CGitStatusListCtrl()
283 // if (m_pDropTarget)
284 // delete m_pDropTarget;
288 void CGitStatusListCtrl::ClearStatusArray()
291 Locker
lock(m_critSec
);
292 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
294 delete m_arStatusArray
[i
];
296 m_arStatusArray
.clear();
300 void CGitStatusListCtrl::Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
/* = GitSLC_POPALL */, bool bHasCheckboxes
/* = true */, bool bHasWC
/* = true */, DWORD allowedColumns
/* = 0xffffffff */)
302 Locker
lock(m_critSec
);
304 m_dwDefaultColumns
= dwColumns
| 1;
305 m_dwContextMenus
= dwContextMenus
;
306 m_bHasCheckboxes
= bHasCheckboxes
;
309 // set the extended style of the listcontrol
310 DWORD exStyle
= LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
311 exStyle
|= (bHasCheckboxes
? LVS_EX_CHECKBOXES
: 0);
313 SetExtendedStyle(exStyle
);
314 CResizableColumnsListCtrl::Init();
316 SetWindowTheme(m_hWnd
, L
"Explorer", nullptr);
318 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
319 m_nRestoreOvl
= SYS_IMAGE_LIST().AddIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_RESTOREOVL
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
));
320 SYS_IMAGE_LIST().SetOverlayImage(m_nRestoreOvl
, OVL_RESTORE
);
321 SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
323 // keep CSorter::operator() in sync!!
324 static UINT standardColumnNames
[GITSLC_NUMCOLUMNS
]
325 = { IDS_STATUSLIST_COLFILE
326 , IDS_STATUSLIST_COLFILENAME
327 , IDS_STATUSLIST_COLEXT
328 , IDS_STATUSLIST_COLSTATUS
329 , IDS_STATUSLIST_COLADD
330 , IDS_STATUSLIST_COLDEL
331 , IDS_STATUSLIST_COLLASTMODIFIED
332 , IDS_STATUSLIST_COLSIZE
335 m_ColumnManager
.SetNames(standardColumnNames
,GITSLC_NUMCOLUMNS
);
336 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, 0xffffffff & ~(allowedColumns
| m_dwDefaultColumns
), sColumnInfoContainer
, GITSLC_NUMCOLUMNS
);
337 m_ColumnManager
.SetRightAlign(4);
338 m_ColumnManager
.SetRightAlign(5);
339 m_ColumnManager
.SetRightAlign(7);
345 m_pDropTarget
= new CGitStatusListCtrlDropTarget(this);
346 RegisterDragDrop(m_hWnd
,m_pDropTarget
);
347 // create the supported formats:
349 ftetc
.dwAspect
= DVASPECT_CONTENT
;
351 ftetc
.tymed
= TYMED_HGLOBAL
;
352 ftetc
.cfFormat
=CF_HDROP
;
353 m_pDropTarget
->AddSuportedFormat(ftetc
);
360 bool CGitStatusListCtrl::SetBackgroundImage(UINT nID
)
362 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
365 BOOL
CGitStatusListCtrl::GetStatus ( const CTGitPathList
* pathList
366 , bool bUpdate
/* = FALSE */
367 , bool bShowIgnores
/* = false */
368 , bool bShowUnRev
/* = false */
369 , bool bShowLocalChangesIgnored
/* = false */)
375 m_bIsRevertTheirMy
= g_Git
.IsRebaseRunning() > 0;
377 Locker
lock(m_critSec
);
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
,(CTGitPathList
*)pathList
);
387 if (pathList
&& m_mapDirectFiles
.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_mapDirectFiles
[(*pathList
)[i
].GetGitPathString()] = true;
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
;
445 m_bHasChangeLists
= false;
446 m_bShowIgnores
= bShowIgnores
;
453 // first clear possible status data left from
454 // previous GetStatus() calls
457 m_StatusFileList
= sortedPathList
;
459 // Since Git_client_status() returns all files, even those in
460 // folders included with Git:externals we need to check if all
461 // files we get here belongs to the same repository.
462 // It is possible to commit changes in an external folder, as long
463 // as the folder belongs to the same repository (but another path),
464 // but it is not possible to commit all files if the externals are
465 // from a different repository.
467 // To check if all files belong to the same repository, we compare the
468 // UUID's - if they're identical then the files belong to the same
469 // repository and can be committed. But if they're different, then
470 // tell the user to commit all changes in the external folders
472 CStringA sUUID
; // holds the repo UUID
473 CTGitPathList arExtPaths
; // list of Git:external paths
479 m_nTargetCount
= sortedPathList
.GetCount();
481 GitStatus
status(m_pbCanceled
);
482 if(m_nTargetCount
> 1 && sortedPathList
.AreAllPathsFilesInOneDirectory())
484 // This is a special case, where we've been given a list of files
485 // all from one folder
486 // We handle them by setting a status filter, then requesting the Git status of
487 // all the files in the directory, filtering for the ones we're interested in
488 status
.SetFilter(sortedPathList
);
490 // if all selected entries are files, we don't do a recursive status
491 // fetching. But if only one is a directory, we have to recurse.
492 git_depth_t depth
= git_depth_files
;
493 // We have set a filter. If all selected items were files or we fetch
494 // the status not recursively, then we have to include
495 // ignored items too - the user has selected them
496 bool bShowIgnoresRight
= true;
497 for (int fcindex
=0; fcindex
<sortedPathList
.GetCount(); ++fcindex
)
499 if (sortedPathList
[fcindex
].IsDirectory())
501 depth
= git_depth_infinity
;
502 bShowIgnoresRight
= false;
506 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
.GetCommonDirectory(), bUpdate
, sUUID
, arExtPaths
, true, depth
, bShowIgnoresRight
))
511 for(int nTarget
= 0; nTarget
< m_nTargetCount
; nTarget
++)
513 // check whether the path we want the status for is already fetched due to status-fetching
515 // this check is only done for file paths, because folder paths could be included already
516 // but not recursively
517 if (sortedPathList
[nTarget
].IsDirectory() || !GetListEntry(sortedPathList
[nTarget
]))
519 if(!FetchStatusForSingleTarget(config
, status
, sortedPathList
[nTarget
], bUpdate
, sUUID
,
520 arExtPaths
, false, git_depth_infinity
, bShowIgnores
))
528 // remove the 'helper' files of conflicted items from the list.
529 // otherwise they would appear as unversioned files.
530 for (INT_PTR cind
= 0; cind
< m_ConflictFileList
.GetCount(); ++cind
)
532 for (size_t i
=0; i
< m_arStatusArray
.size(); i
++)
534 if (m_arStatusArray
[i
]->GetPath().IsEquivalentTo(m_ConflictFileList
[cind
]))
536 delete m_arStatusArray
[i
];
537 m_arStatusArray
.erase(m_arStatusArray
.cbegin() + i
);
543 } while(!BuildStatistics() && (refetchcounter
< 2) && (*m_pbCanceled
==false));
548 SetCursorPos(pt
.x
, pt
.y
);
555 // Get the show-flags bitmap value which corresponds to a particular Git status
556 DWORD
CGitStatusListCtrl::GetShowFlagsFromGitStatus(git_wc_status_kind status
)
560 case git_wc_status_none
:
561 case git_wc_status_unversioned
:
562 return GITSLC_SHOWUNVERSIONED
;
563 case git_wc_status_ignored
:
565 return GITSLC_SHOWDIRECTS
;
566 return GITSLC_SHOWDIRECTS
|GITSLC_SHOWIGNORED
;
567 case git_wc_status_incomplete
:
568 return GITSLC_SHOWINCOMPLETE
;
569 case git_wc_status_normal
:
570 return GITSLC_SHOWNORMAL
;
571 case git_wc_status_external
:
572 return GITSLC_SHOWEXTERNAL
;
573 case git_wc_status_added
:
574 return GITSLC_SHOWADDED
;
575 case git_wc_status_missing
:
576 return GITSLC_SHOWMISSING
;
577 case git_wc_status_deleted
:
578 return GITSLC_SHOWREMOVED
;
579 case git_wc_status_replaced
:
580 return GITSLC_SHOWREPLACED
;
581 case git_wc_status_modified
:
582 return GITSLC_SHOWMODIFIED
;
583 case git_wc_status_merged
:
584 return GITSLC_SHOWMERGED
;
585 case git_wc_status_conflicted
:
586 return GITSLC_SHOWCONFLICTED
;
587 case git_wc_status_obstructed
:
588 return GITSLC_SHOWOBSTRUCTED
;
590 // we should NEVER get here!
597 void CGitStatusListCtrl::Show(unsigned int dwShow
, unsigned int dwCheck
/*=0*/, bool /*bShowFolders*/ /* = true */,BOOL UpdateStatusList
,bool UseStoredCheckStatus
)
603 CWinApp
* pApp
= AfxGetApp();
605 pApp
->DoWaitCursor(1);
607 Locker
lock(m_critSec
);
608 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
610 //SetItemCount(listIndex);
615 m_nShownUnversioned
= 0;
616 m_nShownModified
= 0;
619 m_nShownConflicted
= 0;
621 m_nShownSubmodules
= 0;
627 m_arStatusArray
.clear();
628 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
629 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
631 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
632 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
634 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
635 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
638 if (m_nSortedColumn
>= 0)
640 CSorter
predicate (&m_ColumnManager
, m_nSortedColumn
, m_bAscending
);
641 std::sort(m_arStatusArray
.begin(), m_arStatusArray
.end(), predicate
);
645 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
647 //set default checkbox status
648 CTGitPath
* entry
= ((CTGitPath
*)m_arStatusArray
[i
]);
649 CString path
= entry
->GetGitPathString();
650 if (!m_mapFilenameToChecked
.empty() && m_mapFilenameToChecked
.find(path
) != m_mapFilenameToChecked
.end())
651 entry
->m_Checked
=m_mapFilenameToChecked
[path
];
652 else if (!UseStoredCheckStatus
)
654 bool autoSelectSubmodules
= !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
);
655 if (((entry
->m_Action
& dwCheck
) && !(m_bNoAutoselectMissing
&& entry
->m_Action
& CTGitPath::LOGACTIONS_MISSING
) || dwShow
& GITSLC_SHOWDIRECTFILES
&& m_mapDirectFiles
.find(path
) != m_mapDirectFiles
.end()) && autoSelectSubmodules
)
656 entry
->m_Checked
=true;
658 entry
->m_Checked
=false;
659 m_mapFilenameToChecked
[path
] = entry
->m_Checked
;
662 if(entry
->m_Action
& dwShow
)
664 AddEntry(entry
,langID
,index
);
669 AdjustColumnWidths();
672 GetStatisticsString();
674 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
675 HDITEM HeaderItem
= {0};
676 HeaderItem
.mask
= HDI_FORMAT
;
677 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
679 pHeader
->GetItem(i
, &HeaderItem
);
680 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
681 pHeader
->SetItem(i
, &HeaderItem
);
683 if (m_nSortedColumn
>= 0)
685 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
686 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
687 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
693 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
694 EnsureVisible(nSelectedEntry
, false);
698 // Restore the item at the top of the list.
699 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
701 if ( !EnsureVisible(nTopIndex
+i
,false) )
707 pApp
->DoWaitCursor(-1);
710 m_bEmpty
= (GetItemCount() == 0);
713 this->BuildStatistics();
717 CWinApp
* pApp
= AfxGetApp();
719 pApp
->DoWaitCursor(1);
721 m_bShowFolders
= bShowFolders
;
723 int nTopIndex
= GetTopIndex();
724 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
725 int nSelectedEntry
= 0;
726 if (posSelectedEntry
)
727 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
733 m_arListArray
.clear();
735 m_arListArray
.reserve(m_arStatusArray
.size());
736 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
739 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
741 FileEntry
* entry
= m_arStatusArray
[i
];
742 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
744 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
746 if (entry
->IsFolder() && (!bShowFolders
))
747 continue; // don't show folders if they're not wanted.
750 git_wc_status_kind status
= GitStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
751 DWORD showFlags
= GetShowFlagsFromGitStatus(status
);
752 if (entry
->IsLocked())
753 showFlags
|= SVNSLC_SHOWLOCKS
;
755 showFlags
|= SVNSLC_SHOWSWITCHED
;
756 if (!entry
->changelist
.IsEmpty())
757 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
759 bool bAllowCheck
= ((entry
->changelist
.Compare(GITSLC_IGNORECHANGELIST
) != 0)
760 && (m_bCheckIfGroupsExist
|| (m_changelists
.empty() || (m_changelists
.size() == 1 && m_bHasIgnoreGroup
))));
762 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
764 if (status
!= Git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& GitSLC_SHOWIGNORED
))
766 if ((!entry
->IsFolder()) && (status
== Git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
768 if (PathFileExists(entry
->GetPath().GetWinPath()))
770 m_arListArray
.push_back(i
);
771 if ((dwCheck
& SVNSLC_SHOWREMOVEDANDPRESENT
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
774 entry
->checked
= true;
776 AddEntry(entry
, langID
, listIndex
++);
779 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
781 m_arListArray
.push_back(i
);
782 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
785 entry
->checked
= true;
787 AddEntry(entry
, langID
, listIndex
++);
789 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
791 m_arListArray
.push_back(i
);
792 if ((dwCheck
& showFlags
)||((dwCheck
& SVNSLC_SHOWDIRECTS
)&&(entry
->direct
)))
795 entry
->checked
= true;
797 AddEntry(entry
, langID
, listIndex
++);
803 SetItemCount(listIndex
);
805 m_ColumnManager
.UpdateRelevance (m_arStatusArray
, m_arListArray
);
807 AdjustColumnWidths();
810 GetStatisticsString();
812 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
813 HDITEM HeaderItem
= {0};
814 HeaderItem
.mask
= HDI_FORMAT
;
815 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
817 pHeader
->GetItem(i
, &HeaderItem
);
818 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
819 pHeader
->SetItem(i
, &HeaderItem
);
823 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
824 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
825 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
830 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
831 EnsureVisible(nSelectedEntry
, false);
835 // Restore the item at the top of the list.
836 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
838 if ( !EnsureVisible(nTopIndex
+i
,false) )
844 pApp
->DoWaitCursor(-1);
846 m_bEmpty
= (GetItemCount() == 0);
851 void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList
& checkedList
, bool /*bShowFolders*/ /* = true */)
854 for (int i
= 0; i
< checkedList
.GetCount(); ++i
)
855 this->AddEntry((CTGitPath
*)&checkedList
[i
],0,i
);
857 AdjustColumnWidths();
861 Locker
lock(m_critSec
);
862 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
864 CWinApp
* pApp
= AfxGetApp();
866 pApp
->DoWaitCursor(1);
868 m_bShowFolders
= bShowFolders
;
870 int nTopIndex
= GetTopIndex();
871 POSITION posSelectedEntry
= GetFirstSelectedItemPosition();
872 int nSelectedEntry
= 0;
873 if (posSelectedEntry
)
874 nSelectedEntry
= GetNextSelectedItem(posSelectedEntry
);
880 m_arListArray
.clear();
882 m_arListArray
.reserve(m_arStatusArray
.size());
883 SetItemCount (static_cast<int>(m_arStatusArray
.size()));
886 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
888 FileEntry
* entry
= m_arStatusArray
[i
];
889 if ((entry
->inexternal
) && (!(dwShow
& SVNSLC_SHOWINEXTERNALS
)))
891 if ((entry
->differentrepo
|| entry
->isNested
) && (! (dwShow
& SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
)))
893 if (entry
->IsFolder() && (!bShowFolders
))
894 continue; // don't show folders if they're not wanted.
896 git_wc_status_kind status
= SVNStatus::GetMoreImportant(entry
->status
, entry
->remotestatus
);
897 DWORD showFlags
= GetShowFlagsFromSVNStatus(status
);
898 if (entry
->IsLocked())
899 showFlags
|= SVNSLC_SHOWLOCKS
;
900 if (!entry
->changelist
.IsEmpty())
901 showFlags
|= SVNSLC_SHOWINCHANGELIST
;
903 // status_ignored is a special case - we must have the 'direct' flag set to add a status_ignored item
904 if (status
!= git_wc_status_ignored
|| (entry
->direct
) || (dwShow
& SVNSLC_SHOWIGNORED
))
906 for (int npath
= 0; npath
< checkedList
.GetCount(); ++npath
)
908 if (entry
->GetPath().IsEquivalentTo(checkedList
[npath
]))
910 entry
->checked
= true;
914 if ((!entry
->IsFolder()) && (status
== git_wc_status_deleted
) && (dwShow
& SVNSLC_SHOWREMOVEDANDPRESENT
))
916 if (PathFileExists(entry
->GetPath().GetWinPath()))
918 m_arListArray
.push_back(i
);
919 AddEntry(entry
, langID
, listIndex
++);
922 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFILES
)&&(entry
->direct
)&&(!entry
->IsFolder())))
924 m_arListArray
.push_back(i
);
925 AddEntry(entry
, langID
, listIndex
++);
927 else if ((dwShow
& showFlags
)||((dwShow
& SVNSLC_SHOWDIRECTFOLDER
)&&(entry
->direct
)&&entry
->IsFolder()))
929 m_arListArray
.push_back(i
);
930 AddEntry(entry
, langID
, listIndex
++);
932 else if (entry
->switched
)
934 m_arListArray
.push_back(i
);
935 AddEntry(entry
, langID
, listIndex
++);
941 SetItemCount(listIndex
);
943 AdjustColumnWidths();
946 GetStatisticsString();
948 CHeaderCtrl
* pHeader
= GetHeaderCtrl();
949 HDITEM HeaderItem
= {0};
950 HeaderItem
.mask
= HDI_FORMAT
;
951 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
953 pHeader
->GetItem(i
, &HeaderItem
);
954 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
955 pHeader
->SetItem(i
, &HeaderItem
);
959 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
960 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
961 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
966 SetItemState(nSelectedEntry
, LVIS_SELECTED
, LVIS_SELECTED
);
967 EnsureVisible(nSelectedEntry
, false);
971 // Restore the item at the top of the list.
972 for (int i
=0;GetTopIndex() != nTopIndex
;i
++)
974 if ( !EnsureVisible(nTopIndex
+i
,false) )
980 pApp
->DoWaitCursor(-1);
982 m_bEmpty
= (GetItemCount() == 0);
986 int CGitStatusListCtrl::GetColumnIndex(int mask
)
988 for (int i
= 0; i
< 32; ++i
)
995 void CGitStatusListCtrl::AddEntry(CTGitPath
* GitPath
, WORD
/*langID*/, int listIndex
)
997 static CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
998 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
999 static bool abbreviateRenamings(((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\AbbreviateRenamings"), FALSE
)) == TRUE
);
1000 static bool relativeTimes
= (CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
) != FALSE
);
1002 CString path
= GitPath
->GetGitPathString();
1005 int index
= listIndex
;
1007 CString entryname
= GitPath
->GetGitPathString();
1009 if (GitPath
->IsDirectory())
1011 icon_idx
= m_nIconFolder
;
1012 m_nShownSubmodules
++;
1016 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(*GitPath
);
1019 switch (GitPath
->m_Action
)
1021 case CTGitPath::LOGACTIONS_ADDED
:
1022 case CTGitPath::LOGACTIONS_COPY
:
1025 case CTGitPath::LOGACTIONS_DELETED
:
1026 case CTGitPath::LOGACTIONS_MISSING
:
1027 case CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
:
1030 case CTGitPath::LOGACTIONS_REPLACED
:
1031 case CTGitPath::LOGACTIONS_MODIFIED
:
1032 case CTGitPath::LOGACTIONS_MERGED
:
1035 case CTGitPath::LOGACTIONS_UNMERGED
:
1036 m_nShownConflicted
++;
1038 case CTGitPath::LOGACTIONS_UNVER
:
1039 m_nShownUnversioned
++;
1042 m_nShownUnversioned
++;
1045 if(GitPath
->m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !GitPath
->GetGitOldPathString().IsEmpty())
1047 if (!abbreviateRenamings
)
1051 entryname
.AppendFormat(from
, (LPCTSTR
)GitPath
->GetGitOldPathString());
1054 entryname
= GitPath
->GetAbbreviatedRename();
1057 InsertItem(index
, entryname
, icon_idx
);
1058 if (m_restorepaths
.find(GitPath
->GetWinPathString()) != m_restorepaths
.end())
1059 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), TVIS_OVERLAYMASK
);
1061 this->SetItemData(index
, (DWORD_PTR
)GitPath
);
1062 // SVNSLC_COLFILENAME
1063 SetItemText(index
, nCol
++, GitPath
->GetFileOrDirectoryName());
1065 SetItemText(index
, nCol
++, GitPath
->GetFileExtension());
1067 SetItemText(index
, nCol
++, GitPath
->GetActionName());
1069 SetItemText(index
, GetColumnIndex(GITSLC_COLADD
),GitPath
->m_StatAdd
);
1070 SetItemText(index
, GetColumnIndex(GITSLC_COLDEL
),GitPath
->m_StatDel
);
1073 CString modificationDate
;
1074 __int64 filetime
= GitPath
->GetLastWriteTime();
1075 if (filetime
&& !(GitPath
->m_Action
& CTGitPath::LOGACTIONS_DELETED
))
1077 FILETIME
* f
= (FILETIME
*)(__int64
*)&filetime
;
1078 modificationDate
= CLoglistUtils::FormatDateAndTime(CTime(CGit::filetime_to_time_t(f
)), DATE_SHORTDATE
, true, relativeTimes
);
1080 SetItemText(index
, GetColumnIndex(GITSLC_COLMODIFICATIONDATE
), modificationDate
);
1083 if (GitPath
->IsDirectory())
1084 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), _T(""));
1087 TCHAR buf
[100] = { 0 };
1088 StrFormatByteSize64(GitPath
->GetFileSize(), buf
, 100);
1089 SetItemText(index
, GetColumnIndex(GITSLC_COLSIZE
), buf
);
1092 SetCheck(index
, GitPath
->m_Checked
);
1093 if (GitPath
->m_Checked
)
1096 if ((GitPath
->m_Action
& CTGitPath::LOGACTIONS_SKIPWORKTREE
) || (GitPath
->m_Action
& CTGitPath::LOGACTIONS_ASSUMEVALID
))
1097 SetItemGroup(index
, 3);
1098 else if (GitPath
->m_Action
& CTGitPath::LOGACTIONS_IGNORE
)
1099 SetItemGroup(index
, 2);
1100 else if( GitPath
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1101 SetItemGroup(index
,1);
1103 SetItemGroup(index
, GitPath
->m_ParentNo
&(PARENT_MASK
|MERGE_MASK
));
1108 bool CGitStatusListCtrl::SetItemGroup(int item
, int groupindex
)
1110 // if (!(m_dwContextMenus & SVNSLC_POPCHANGELISTS))
1115 i
.mask
= LVIF_GROUPID
;
1118 i
.iGroupId
= groupindex
;
1120 return !!SetItem(&i
);
1123 void CGitStatusListCtrl::OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1125 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1127 if (m_bBlock
|| m_arStatusArray
.empty())
1130 if (m_nSortedColumn
== phdr
->iItem
)
1131 m_bAscending
= !m_bAscending
;
1133 m_bAscending
= TRUE
;
1134 m_nSortedColumn
= phdr
->iItem
;
1135 Show(m_dwShow
, 0, m_bShowFolders
,false,true);
1140 void CGitStatusListCtrl::OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1142 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1145 #define ISCHECKED(x) ((x) ? ((((x)&LVIS_STATEIMAGEMASK)>>12)-1) : FALSE)
1146 if ((m_bBlock
)&&(m_bBlockUI
))
1148 // if we're blocked, prevent changing of the check state
1149 if ((!ISCHECKED(pNMLV
->uOldState
) && ISCHECKED(pNMLV
->uNewState
))||
1150 (ISCHECKED(pNMLV
->uOldState
) && !ISCHECKED(pNMLV
->uNewState
)))
1155 BOOL
CGitStatusListCtrl::OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1157 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1159 CWnd
* pParent
= GetLogicalParent();
1160 if (pParent
&& pParent
->GetSafeHwnd())
1161 pParent
->SendMessage(GITSLNM_ITEMCHANGED
, pNMLV
->iItem
);
1163 if ((pNMLV
->uNewState
==0)||(pNMLV
->uNewState
& LVIS_SELECTED
)||(pNMLV
->uNewState
& LVIS_FOCUSED
))
1169 bool bSelected
= !!(ListView_GetItemState(m_hWnd
, pNMLV
->iItem
, LVIS_SELECTED
) & LVIS_SELECTED
);
1170 int nListItems
= GetItemCount();
1173 // was the item checked?
1175 //CTGitPath *gitpath=(CTGitPath*)GetItemData(pNMLV->iItem);
1176 //gitpath->m_Checked=GetCheck(pNMLV->iItem);
1178 if (GetCheck(pNMLV
->iItem
))
1180 CheckEntry(pNMLV
->iItem
, nListItems
);
1183 POSITION pos
= GetFirstSelectedItemPosition();
1185 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1187 if (index
!= pNMLV
->iItem
)
1188 CheckEntry(index
, nListItems
);
1194 UncheckEntry(pNMLV
->iItem
, nListItems
);
1197 POSITION pos
= GetFirstSelectedItemPosition();
1199 while ((index
= GetNextSelectedItem(pos
)) >= 0)
1201 if (index
!= pNMLV
->iItem
)
1202 UncheckEntry(index
, nListItems
);
1207 GetStatisticsString();
1214 void CGitStatusListCtrl::CheckEntry(int index
, int /*nListItems*/)
1216 Locker
lock(m_critSec
);
1217 //FileEntry * entry = GetListEntry(index);
1218 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1222 m_mapFilenameToChecked
[path
->GetGitPathString()] = true;
1223 SetCheck(index
, TRUE
);
1224 //entry = GetListEntry(index);
1225 // if an unversioned item was checked, then we need to check if
1226 // the parent folders are unversioned too. If the parent folders actually
1227 // are unversioned, then check those too.
1229 if (entry
->status
== git_wc_status_unversioned
)
1231 // we need to check the parent folder too
1232 const CTGitPath
& folderpath
= entry
->path
;
1233 for (int i
=0; i
< nListItems
; ++i
)
1235 FileEntry
* testEntry
= GetListEntry(i
);
1239 if (!testEntry
->checked
)
1241 if (testEntry
->path
.IsAncestorOf(folderpath
) && (!testEntry
->path
.IsEquivalentTo(folderpath
)))
1243 SetEntryCheck(testEntry
,i
,true);
1249 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1250 if ( (entry
->status
== git_wc_status_deleted
) || (m_bCheckChildrenWithParent
) || (bShift
) )
1252 // if a deleted folder gets checked, we have to check all
1253 // children of that folder too.
1254 if (entry
->path
.IsDirectory())
1255 SetCheckOnAllDescendentsOf(entry
, true);
1257 // if a deleted file or folder gets checked, we have to
1258 // check all parents of this item too.
1259 for (int i
=0; i
<nListItems
; ++i
)
1261 FileEntry
* testEntry
= GetListEntry(i
);
1265 if (!testEntry
->checked
)
1267 if (testEntry
->path
.IsAncestorOf(entry
->path
) && (!testEntry
->path
.IsEquivalentTo(entry
->path
)))
1269 if ((testEntry
->status
== git_wc_status_deleted
)||(m_bCheckChildrenWithParent
))
1271 SetEntryCheck(testEntry
,i
,true);
1273 // now we need to check all children of this parent folder
1274 SetCheckOnAllDescendentsOf(testEntry
, true);
1281 if ( !path
->m_Checked
)
1283 path
->m_Checked
= TRUE
;
1288 void CGitStatusListCtrl::UncheckEntry(int index
, int /*nListItems*/)
1290 Locker
lock(m_critSec
);
1291 CTGitPath
*path
=(CTGitPath
*)GetItemData(index
);
1295 SetCheck(index
, FALSE
);
1296 m_mapFilenameToChecked
[path
->GetGitPathString()] = false;
1297 //entry = GetListEntry(index);
1298 // item was unchecked
1300 if (entry
->path
.IsDirectory())
1302 // disable all files within an unselected folder, except when unchecking a folder with property changes
1303 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1304 if ( (entry
->status
!= git_wc_status_modified
) || (bShift
) )
1306 SetCheckOnAllDescendentsOf(entry
, false);
1309 else if (entry
->status
== git_wc_status_deleted
)
1311 // a "deleted" file was unchecked, so uncheck all parent folders
1312 // and all children of those parents
1313 for (int i
=0; i
<nListItems
; i
++)
1315 FileEntry
* testEntry
= GetListEntry(i
);
1319 if (testEntry
->checked
)
1321 if (testEntry
->path
.IsAncestorOf(entry
->path
))
1323 if (testEntry
->status
== git_wc_status_deleted
)
1325 SetEntryCheck(testEntry
,i
,false);
1328 SetCheckOnAllDescendentsOf(testEntry
, false);
1335 if ( path
->m_Checked
)
1337 path
->m_Checked
= FALSE
;
1341 bool CGitStatusListCtrl::BuildStatistics()
1343 bool bRefetchStatus
= false;
1345 // now gather some statistics
1358 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
1360 int status
=((CTGitPath
*)m_arStatusArray
[i
])->m_Action
;
1362 m_nLineAdded
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatAdd
);
1363 m_nLineDeleted
+= _tstol(((CTGitPath
*)m_arStatusArray
[i
])->m_StatDel
);
1365 if(status
&(CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
1368 if(status
&CTGitPath::LOGACTIONS_DELETED
)
1371 if(status
&(CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_MODIFIED
))
1374 if(status
&CTGitPath::LOGACTIONS_UNMERGED
)
1377 if(status
&(CTGitPath::LOGACTIONS_IGNORE
|CTGitPath::LOGACTIONS_UNVER
))
1380 if(status
&(CTGitPath::LOGACTIONS_REPLACED
))
1383 if(((CTGitPath
*)m_arStatusArray
[i
])->m_Checked
)
1386 return !bRefetchStatus
;
1390 int CGitStatusListCtrl::GetGroupFromPoint(POINT
* ppt
)
1392 // the point must be relative to the upper left corner of the control
1396 if (!IsGroupViewEnabled())
1405 while (((flags
& LVHT_BELOW
) == 0)&&(pt
.y
< rc
.bottom
))
1407 nItem
= HitTest(pt
, &flags
);
1408 if ((flags
& LVHT_ONITEM
)||(flags
& LVHT_EX_GROUP_HEADER
))
1410 // the first item below the point
1412 // check if the point is too much right (i.e. if the point
1413 // is farther to the right than the width of the item)
1415 GetItemRect(nItem
, &r
, LVIR_LABEL
);
1416 if (ppt
->x
> r
.right
)
1420 lv
.mask
= LVIF_GROUPID
;
1423 int groupID
= lv
.iGroupId
;
1424 // now we search upwards and check if the item above this one
1425 // belongs to another group. If it belongs to the same group,
1426 // we're not over a group header
1430 nItem
= HitTest(pt
, &flags
);
1431 if ((flags
& LVHT_ONITEM
)&&(nItem
>= 0))
1433 // the first item below the point
1435 lv2
.mask
= LVIF_GROUPID
;
1438 if (lv2
.iGroupId
!= groupID
)
1453 void CGitStatusListCtrl::OnContextMenuGroup(CWnd
* /*pWnd*/, CPoint point
)
1455 POINT clientpoint
= point
;
1456 ScreenToClient(&clientpoint
);
1457 if ((IsGroupViewEnabled())&&(GetGroupFromPoint(&clientpoint
) >= 0))
1460 if (popup
.CreatePopupMenu())
1463 temp
.LoadString(IDS_STATUSLIST_CHECKGROUP
);
1464 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_CHECKGROUP
, temp
);
1465 temp
.LoadString(IDS_STATUSLIST_UNCHECKGROUP
);
1466 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_UNCHECKGROUP
, temp
);
1467 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
1468 bool bCheck
= false;
1471 case IDGITLC_CHECKGROUP
:
1473 // fall through here
1474 case IDGITLC_UNCHECKGROUP
:
1476 int group
= GetGroupFromPoint(&clientpoint
);
1477 // go through all items and check/uncheck those assigned to the group
1478 // but block the OnLvnItemChanged handler
1480 for (int i
=0; i
<GetItemCount(); ++i
)
1483 lv
.mask
= LVIF_GROUPID
;
1487 if (lv
.iGroupId
== group
)
1489 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
1492 bool bOldCheck
= entry
->m_Checked
;
1493 SetEntryCheck(entry
, i
, bCheck
);
1494 if (bCheck
!= bOldCheck
)
1505 GetStatisticsString();
1515 void CGitStatusListCtrl::OnContextMenuList(CWnd
* pWnd
, CPoint point
)
1517 //WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1519 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1520 CTGitPath
* filepath
;
1522 int selIndex
= GetSelectionMark();
1523 if ((point
.x
== -1) && (point
.y
== -1))
1526 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1527 ClientToScreen(&rect
);
1528 point
= rect
.CenterPoint();
1530 if ((GetSelectedCount() == 0) && (m_bHasCheckboxes
))
1532 // nothing selected could mean the context menu is requested for
1534 OnContextMenuGroup(pWnd
, point
);
1536 else if (selIndex
>= 0)
1538 //FileEntry * entry = GetListEntry(selIndex);
1540 filepath
= (CTGitPath
* )GetItemData(selIndex
);
1546 //const CTGitPath& filepath = entry->path;
1547 int wcStatus
= filepath
->m_Action
;
1548 // entry is selected, now show the popup menu
1549 Locker
lock(m_critSec
);
1551 CMenu changelistSubMenu
;
1552 CMenu ignoreSubMenu
;
1554 if (popup
.CreatePopupMenu())
1556 //Add Menu for version controlled file
1558 if (GetSelectedCount() > 0 && wcStatus
& CTGitPath::LOGACTIONS_UNMERGED
)
1560 if (GetSelectedCount() == 1 && (m_dwContextMenus
& GITSLC_POPCONFLICT
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1562 popup
.AppendMenuIcon(IDGITLC_EDITCONFLICT
, IDS_MENUCONFLICT
, IDI_CONFLICT
);
1563 popup
.SetDefaultItem(IDGITLC_EDITCONFLICT
, FALSE
);
1565 if (m_dwContextMenus
& GITSLC_POPRESOLVE
)
1566 popup
.AppendMenuIcon(IDGITLC_RESOLVECONFLICT
, IDS_STATUSLIST_CONTEXT_RESOLVED
, IDI_RESOLVE
);
1567 if ((m_dwContextMenus
& GITSLC_POPRESOLVE
)/*&&(entry->textstatus == git_wc_status_conflicted)*/)
1569 popup
.AppendMenuIcon(IDGITLC_RESOLVETHEIRS
, IDS_SVNPROGRESS_MENUUSETHEIRS
, IDI_RESOLVE
);
1570 popup
.AppendMenuIcon(IDGITLC_RESOLVEMINE
, IDS_SVNPROGRESS_MENUUSEMINE
, IDI_RESOLVE
);
1572 if ((m_dwContextMenus
& GITSLC_POPCONFLICT
)||(m_dwContextMenus
& GITSLC_POPRESOLVE
))
1573 popup
.AppendMenu(MF_SEPARATOR
);
1576 if (GetSelectedCount() > 0)
1578 if (wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
1580 if (m_dwContextMenus
& GITSLC_POPADD
)
1582 //if ( entry->IsFolder() )
1584 // popup.AppendMenuIcon(IDSVNLC_ADD_RECURSIVE, IDS_STATUSLIST_CONTEXT_ADD_RECURSIVE, IDI_ADD);
1588 popup
.AppendMenuIcon(IDGITLC_ADD
, IDS_STATUSLIST_CONTEXT_ADD
, IDI_ADD
);
1591 if (m_dwContextMenus
& GITSLC_POPCOMMIT
)
1592 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1596 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
)) && GetSelectedCount() > 0)
1598 bool bEntryAdded
= false;
1599 if (m_dwContextMenus
& GITSLC_POPCOMPAREWITHBASE
)
1601 if(filepath
->m_ParentNo
& MERGE_MASK
)
1602 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_TREE_DIFF
, IDI_DIFF
);
1604 popup
.AppendMenuIcon(IDGITLC_COMPARE
, IDS_LOG_COMPAREWITHBASE
, IDI_DIFF
);
1606 if (!(wcStatus
& (CTGitPath::LOGACTIONS_UNMERGED
)) || GetSelectedCount() != 1)
1607 popup
.SetDefaultItem(IDGITLC_COMPARE
, FALSE
);
1611 if (!g_Git
.IsInitRepos() && (m_dwContextMenus
& GITSLC_POPGNUDIFF
))
1613 popup
.AppendMenuIcon(IDGITLC_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1617 if ((m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPAREWC
)) && m_bHasWC
)
1619 if ((!m_CurrentVersion
.IsEmpty()) && m_CurrentVersion
!= GIT_REV_ZERO
)
1621 popup
.AppendMenuIcon(IDGITLC_COMPAREWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1627 popup
.AppendMenu(MF_SEPARATOR
);
1630 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
1632 if(GetSelectedCount() == 1)
1634 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_COMPARETWOREVISIONS
))
1636 popup
.AppendMenuIcon(IDGITLC_COMPARETWOREVISIONS
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1637 popup
.SetDefaultItem(IDGITLC_COMPARETWOREVISIONS
, FALSE
);
1639 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_GNUDIFF2REVISIONS
))
1640 popup
.AppendMenuIcon(IDGITLC_GNUDIFF2REVISIONS
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1645 if (GetSelectedCount() > 0)
1647 if ((GetSelectedCount() == 2) && (m_dwContextMenus
& GITSLC_POPCOMPARETWOFILES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1649 POSITION pos
= GetFirstSelectedItemPosition();
1650 int index
= GetNextSelectedItem(pos
);
1653 CTGitPath
* entry2
= nullptr;
1654 entry2
= (CTGitPath
*)GetItemData(index
);
1655 bool firstEntryExistsAndIsFile
= entry2
&& !entry2
->IsDirectory();
1656 index
= GetNextSelectedItem(pos
);
1659 entry2
= (CTGitPath
* )GetItemData(index
);
1660 if (firstEntryExistsAndIsFile
&& entry2
&& !entry2
->IsDirectory())
1661 popup
.AppendMenuIcon(IDGITLC_COMPARETWOFILES
, IDS_STATUSLIST_CONTEXT_COMPARETWOFILES
, IDI_DIFF
);
1667 if ( (GetSelectedCount() >0 ) && (!(wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))) && m_bHasWC
)
1669 if ((m_dwContextMenus
& GITSLC_POPCOMMIT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && !(wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1670 popup
.AppendMenuIcon(IDGITLC_COMMIT
, IDS_STATUSLIST_CONTEXT_COMMIT
, IDI_COMMIT
);
1672 if ((m_dwContextMenus
& GITSLC_POPREVERT
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
))
1673 popup
.AppendMenuIcon(IDGITLC_REVERT
, IDS_MENUREVERT
, IDI_REVERT
);
1675 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
)))
1676 popup
.AppendMenuIcon(IDGITLC_SKIPWORKTREE
, IDS_STATUSLIST_SKIPWORKTREE
);
1678 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
)))
1679 popup
.AppendMenuIcon(IDGITLC_ASSUMEVALID
, IDS_MENUASSUMEVALID
);
1681 if ((m_dwContextMenus
& GITLC_POPUNSETIGNORELOCALCHANGES
) && (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && (wcStatus
& (CTGitPath::LOGACTIONS_SKIPWORKTREE
| CTGitPath::LOGACTIONS_ASSUMEVALID
)))
1682 popup
.AppendMenuIcon(IDGITLC_UNSETIGNORELOCALCHANGES
, IDS_STATUSLIST_UNSETIGNORELOCALCHANGES
);
1684 if (m_dwContextMenus
& GITSLC_POPRESTORE
&& !filepath
->IsDirectory())
1686 if (m_restorepaths
.find(filepath
->GetWinPathString()) == m_restorepaths
.end())
1687 popup
.AppendMenuIcon(IDGITLC_CREATERESTORE
, IDS_MENUCREATERESTORE
, IDI_RESTORE
);
1689 popup
.AppendMenuIcon(IDGITLC_RESTOREPATH
, IDS_MENURESTORE
, IDI_RESTORE
);
1692 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOREV
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1693 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1695 popup
.AppendMenuIcon(IDGITLC_REVERTTOREV
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
1698 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_REVERTTOPARENT
)) && ( !this->m_CurrentVersion
.IsEmpty() )
1699 && this->m_CurrentVersion
!= GIT_REV_ZERO
&& !(wcStatus
& CTGitPath::LOGACTIONS_ADDED
))
1701 popup
.AppendMenuIcon(IDGITLC_REVERTTOPARENT
, IDS_LOG_POPUP_REVERTTOPARENT
, IDI_REVERT
);
1705 if ((GetSelectedCount() == 1)&&(!(wcStatus
& CTGitPath::LOGACTIONS_UNVER
))
1706 &&(!(wcStatus
& CTGitPath::LOGACTIONS_IGNORE
)))
1708 if (m_dwContextMenus
& GITSLC_POPSHOWLOG
)
1709 popup
.AppendMenuIcon(IDGITLC_LOG
, IDS_REPOBROWSE_SHOWLOG
, IDI_LOG
);
1710 if (m_dwContextMenus
& GITSLC_POPSHOWLOGSUBMODULE
&& filepath
->IsDirectory())
1711 popup
.AppendMenuIcon(IDGITLC_LOGSUBMODULE
, IDS_LOG_SUBMODULE
, IDI_LOG
);
1712 if (m_dwContextMenus
& GITSLC_POPSHOWLOGOLDNAME
&& (wcStatus
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !filepath
->GetGitOldPathString().IsEmpty()))
1713 popup
.AppendMenuIcon(IDGITLC_LOGOLDNAME
, IDS_STATUSLIST_SHOWLOGOLDNAME
, IDI_LOG
);
1714 if (m_dwContextMenus
& GITSLC_POPBLAME
&& ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1715 popup
.AppendMenuIcon(IDGITLC_BLAME
, IDS_MENUBLAME
, IDI_BLAME
);
1718 if (GetSelectedCount() > 0)
1720 if ((m_dwContextMenus
& GetContextMenuBit(IDGITLC_EXPORT
)) && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)))
1721 popup
.AppendMenuIcon(IDGITLC_EXPORT
, IDS_LOG_POPUP_EXPORT
, IDI_EXPORT
);
1724 // if ((wcStatus != git_wc_status_deleted)&&(wcStatus != git_wc_status_missing) && (GetSelectedCount() == 1))
1725 if ( (GetSelectedCount() == 1) )
1727 if (m_dwContextMenus
& this->GetContextMenuBit(IDGITLC_SAVEAS
) && ! filepath
->IsDirectory() && !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1728 popup
.AppendMenuIcon(IDGITLC_SAVEAS
, IDS_LOG_POPUP_SAVE
, IDI_SAVEAS
);
1730 if (m_dwContextMenus
& GITSLC_POPOPEN
&& !filepath
->IsDirectory() && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)))
1732 popup
.AppendMenuIcon(IDGITLC_VIEWREV
, IDS_LOG_POPUP_VIEWREV
);
1733 popup
.AppendMenuIcon(IDGITLC_OPEN
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
1734 popup
.AppendMenuIcon(IDGITLC_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1737 if (m_dwContextMenus
& GITSLC_POPEXPLORE
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
) && m_bHasWC
)
1738 popup
.AppendMenuIcon(IDGITLC_EXPLORE
, IDS_STATUSLIST_CONTEXT_EXPLORE
, IDI_EXPLORER
);
1740 if (m_dwContextMenus
& GITSLC_PREPAREDIFF
&& !(wcStatus
& CTGitPath::LOGACTIONS_DELETED
))
1742 popup
.AppendMenu(MF_SEPARATOR
);
1743 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF
, IDS_PREPAREDIFF
, IDI_DIFF
);
1744 if (!m_sMarkForDiffFilename
.IsEmpty())
1747 if (filepath
->GetGitPathString() == m_sMarkForDiffFilename
)
1748 diffWith
= m_sMarkForDiffVersion
;
1751 PathCompactPathEx(CStrBuf(diffWith
, 40), m_sMarkForDiffFilename
, 40, 0);
1752 diffWith
+= _T(":") + m_sMarkForDiffVersion
.Left(g_Git
.GetShortHASHLength());
1755 menuEntry
.Format(IDS_MENUDIFFNOW
, (LPCTSTR
)diffWith
);
1756 popup
.AppendMenuIcon(IDGITLC_PREPAREDIFF_COMPARE
, menuEntry
, IDI_DIFF
);
1760 if (GetSelectedCount() > 0)
1762 // if (((wcStatus == git_wc_status_unversioned)||(wcStatus == git_wc_status_ignored))&&(m_dwContextMenus & SVNSLC_POPDELETE))
1763 // popup.AppendMenuIcon(IDSVNLC_DELETE, IDS_MENUREMOVE, IDI_DELETE);
1764 // 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))
1767 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVEKEEP, IDI_DELETE);
1769 // popup.AppendMenuIcon(IDGitLC_REMOVE, IDS_MENUREMOVE, IDI_DELETE);
1771 if ((wcStatus
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
| CTGitPath::LOGACTIONS_MISSING
))/*||(wcStatus == git_wc_status_deleted)*/)
1773 if (m_dwContextMenus
& GITSLC_POPDELETE
)
1774 popup
.AppendMenuIcon(IDGITLC_DELETE
, IDS_MENUREMOVE
, IDI_DELETE
);
1776 if ( (wcStatus
& CTGitPath::LOGACTIONS_UNVER
|| wcStatus
& CTGitPath::LOGACTIONS_DELETED
) )
1778 if (m_dwContextMenus
& GITSLC_POPIGNORE
)
1780 CTGitPathList ignorelist
;
1781 FillListOfSelectedItemPaths(ignorelist
);
1782 //check if all selected entries have the same extension
1783 bool bSameExt
= true;
1785 for (int i
=0; i
<ignorelist
.GetCount(); ++i
)
1787 if (sExt
.IsEmpty() && (i
==0))
1788 sExt
= ignorelist
[i
].GetFileExtension();
1789 else if (sExt
.CompareNoCase(ignorelist
[i
].GetFileExtension())!=0)
1794 if (ignoreSubMenu
.CreateMenu())
1797 if (ignorelist
.GetCount()==1)
1798 ignorepath
= ignorelist
[0].GetFileOrDirectoryName();
1800 ignorepath
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1801 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNORE
, ignorepath
);
1802 ignorepath
= _T("*")+sExt
;
1803 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREMASK
, ignorepath
);
1804 if (ignorelist
.GetCount() == 1 && !ignorelist
[0].GetContainingDirectory().GetGitPathString().IsEmpty())
1805 ignoreSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDGITLC_IGNOREFOLDER
, ignorelist
[0].GetContainingDirectory().GetGitPathString());
1807 temp
.LoadString(IDS_MENUIGNORE
);
1808 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)ignoreSubMenu
.m_hMenu
, temp
);
1814 if (ignorelist
.GetCount()==1)
1815 temp
.LoadString(IDS_MENUIGNORE
);
1817 temp
.Format(IDS_MENUIGNOREMULTIPLE
, ignorelist
.GetCount());
1818 popup
.AppendMenuIcon(IDGITLC_IGNORE
, temp
, IDI_IGNORE
);
1819 temp
.Format(IDS_MENUIGNOREMULTIPLEMASK
, ignorelist
.GetCount());
1820 popup
.AppendMenuIcon(IDGITLC_IGNOREMASK
, temp
, IDI_IGNORE
);
1828 if (GetSelectedCount() > 0)
1830 popup
.AppendMenu(MF_SEPARATOR
);
1831 popup
.AppendMenuIcon(IDGITLC_COPY
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
1832 popup
.AppendMenuIcon(IDGITLC_COPYEXT
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
1834 if ((m_dwContextMenus
& SVNSLC_POPCHANGELISTS
))
1835 &&(wcStatus
!= git_wc_status_unversioned
)&&(wcStatus
!= git_wc_status_none
))
1837 popup
.AppendMenu(MF_SEPARATOR
);
1838 // changelist commands
1839 size_t numChangelists
= GetNumberOfChangelistsInSelection();
1840 if (numChangelists
> 0)
1841 popup
.AppendMenuIcon(IDSVNLC_REMOVEFROMCS
, IDS_STATUSLIST_CONTEXT_REMOVEFROMCS
);
1842 if ((!entry
->IsFolder())&&(changelistSubMenu
.CreateMenu()))
1845 temp
.LoadString(IDS_STATUSLIST_CONTEXT_CREATECS
);
1846 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATECS
, temp
);
1848 if (entry
->changelist
.Compare(SVNSLC_IGNORECHANGELIST
))
1850 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1851 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, IDSVNLC_CREATEIGNORECS
, SVNSLC_IGNORECHANGELIST
);
1854 if (!m_changelists
.empty())
1856 // find the changelist names
1857 bool bNeedSeparator
= true;
1858 int cmdID
= IDSVNLC_MOVETOCS
;
1859 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
1861 if ((entry
->changelist
.Compare(it
->first
))&&(it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)))
1865 changelistSubMenu
.AppendMenu(MF_SEPARATOR
);
1866 bNeedSeparator
= false;
1868 changelistSubMenu
.AppendMenu(MF_STRING
| MF_ENABLED
, cmdID
, it
->first
);
1873 temp
.LoadString(IDS_STATUSLIST_CONTEXT_MOVETOCS
);
1874 popup
.AppendMenu(MF_POPUP
|MF_STRING
, (UINT_PTR
)changelistSubMenu
.GetSafeHmenu(), temp
);
1880 m_hShellMenu
= nullptr;
1881 if (GetSelectedCount() > 0 && !(wcStatus
& (CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
)) && m_bHasWC
&& (this->m_CurrentVersion
.IsEmpty() || this->m_CurrentVersion
== GIT_REV_ZERO
) && shellMenu
.CreatePopupMenu())
1883 // insert the shell context menu
1884 popup
.AppendMenu(MF_SEPARATOR
);
1885 popup
.InsertMenu((UINT
)-1, MF_BYPOSITION
| MF_POPUP
, (UINT_PTR
)shellMenu
.m_hMenu
, CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_SHELL
)));
1886 m_hShellMenu
= shellMenu
.m_hMenu
;
1889 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this);
1890 g_IContext2
= nullptr;
1891 g_IContext3
= nullptr;
1894 if (cmd
>= SHELL_MIN_CMD
&& cmd
<= SHELL_MAX_CMD
) // see if returned idCommand belongs to shell menu entries)
1896 CMINVOKECOMMANDINFOEX cmi
= { 0 };
1897 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFOEX
);
1898 cmi
.fMask
= CMIC_MASK_UNICODE
| CMIC_MASK_PTINVOKE
;
1899 if (GetKeyState(VK_CONTROL
) < 0)
1900 cmi
.fMask
|= CMIC_MASK_CONTROL_DOWN
;
1902 cmi
.fMask
|= CMIC_MASK_SHIFT_DOWN
;
1904 cmi
.lpVerb
= MAKEINTRESOURCEA(cmd
- SHELL_MIN_CMD
);
1905 cmi
.lpVerbW
= MAKEINTRESOURCEW(cmd
- SHELL_MIN_CMD
);
1906 cmi
.nShow
= SW_SHOWNORMAL
;
1907 cmi
.ptInvoke
= point
;
1909 m_pContextMenu
->InvokeCommand((LPCMINVOKECOMMANDINFO
)&cmi
);
1913 m_pContextMenu
->Release();
1914 m_pContextMenu
= nullptr;
1918 delete g_pFolderhook
;
1919 g_pFolderhook
= nullptr;
1921 if (g_psfDesktopFolder
)
1923 g_psfDesktopFolder
->Release();
1924 g_psfDesktopFolder
= nullptr;
1926 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
1929 CoTaskMemFree(g_pidlArray
[i
]);
1932 CoTaskMemFree(g_pidlArray
);
1933 g_pidlArray
= nullptr;
1934 g_pidlArrayItems
= 0;
1937 AfxGetApp()->DoWaitCursor(1);
1938 bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
1939 //int iItemCountBeforeMenuCmd = GetItemCount();
1940 //bool bForce = false;
1943 case IDGITLC_VIEWREV
:
1944 OpenFile(filepath
, ALTERNATIVEEDITOR
);
1948 OpenFile(filepath
,OPEN
);
1951 case IDGITLC_OPENWITH
:
1952 OpenFile(filepath
,OPEN_WITH
);
1955 case IDGITLC_EXPLORE
:
1956 CAppUtils::ExploreTo(GetSafeHwnd(), g_Git
.CombinePath(filepath
));
1959 case IDGITLC_PREPAREDIFF
:
1960 m_sMarkForDiffFilename
= filepath
->GetGitPathString();
1961 m_sMarkForDiffVersion
= m_CurrentVersion
;
1964 case IDGITLC_PREPAREDIFF_COMPARE
:
1966 CTGitPath
savedFile(m_sMarkForDiffFilename
);
1967 CGitDiff::Diff(filepath
, &savedFile
, m_CurrentVersion
, m_sMarkForDiffVersion
, false, false, 0, bShift
);
1971 case IDGITLC_CREATERESTORE
:
1973 POSITION pos
= GetFirstSelectedItemPosition();
1976 int index
= GetNextSelectedItem(pos
);
1977 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
1979 if (!entry2
|| entry2
->IsDirectory())
1981 if (m_restorepaths
.find(entry2
->GetWinPathString()) != m_restorepaths
.end())
1983 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
1984 // delete the temp file: the temp file has the FILE_ATTRIBUTE_TEMPORARY flag set
1985 // and copying the real file over it would leave that temp flag.
1986 DeleteFile(tempFile
.GetWinPath());
1987 if (CopyFile(g_Git
.CombinePath(entry2
), tempFile
.GetWinPath(), FALSE
))
1989 m_restorepaths
[entry2
->GetWinPathString()] = tempFile
.GetWinPathString();
1990 SetItemState(index
, INDEXTOOVERLAYMASK(OVL_RESTORE
), LVIS_OVERLAYMASK
);
1997 case IDGITLC_RESTOREPATH
:
1999 if (CMessageBox::Show(m_hWnd
, IDS_STATUSLIST_RESTOREPATH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_RESTOREBUTTON
, IDS_ABORTBUTTON
) == 2)
2001 POSITION pos
= GetFirstSelectedItemPosition();
2004 int index
= GetNextSelectedItem(pos
);
2005 CTGitPath
* entry2
= (CTGitPath
* )GetItemData(index
);
2009 if (m_restorepaths
.find(entry2
->GetWinPathString()) == m_restorepaths
.end())
2011 if (CopyFile(m_restorepaths
[entry2
->GetWinPathString()], g_Git
.CombinePath(entry2
), FALSE
))
2013 m_restorepaths
.erase(entry2
->GetWinPathString());
2014 SetItemState(index
, 0, LVIS_OVERLAYMASK
);
2021 // Compare current version and work copy.
2022 case IDGITLC_COMPAREWC
:
2024 if (!CheckMultipleDiffs())
2026 POSITION pos
= GetFirstSelectedItemPosition();
2029 int index
= GetNextSelectedItem(pos
);
2035 // Compare with base version. when current version is zero, compare workcopy and HEAD.
2036 case IDGITLC_COMPARE
:
2038 if (!CheckMultipleDiffs())
2040 POSITION pos
= GetFirstSelectedItemPosition();
2043 int index
= GetNextSelectedItem(pos
);
2049 case IDGITLC_COMPARETWOREVISIONS
:
2051 if (!CheckMultipleDiffs())
2053 POSITION pos
= GetFirstSelectedItemPosition();
2056 int index
= GetNextSelectedItem(pos
);
2057 StartDiffTwo(index
);
2062 case IDGITLC_COMPARETWOFILES
:
2064 POSITION pos
= GetFirstSelectedItemPosition();
2067 CTGitPath
* firstfilepath
= (CTGitPath
*)GetItemData(GetNextSelectedItem(pos
));
2068 ASSERT(firstfilepath
);
2072 CTGitPath
* secondfilepath
= (CTGitPath
*)GetItemData(GetNextSelectedItem(pos
));
2073 ASSERT(secondfilepath
);
2074 if (!secondfilepath
)
2078 sCmd
.Format(_T("/command:diff /path:\"%s\" /endrev:%s /path2:\"%s\" /startrev:%s /hwnd:%p"), firstfilepath
->GetWinPath(), firstfilepath
->Exists() ? GIT_REV_ZERO
: _T("HEAD"), secondfilepath
->GetWinPath(), secondfilepath
->Exists() ? GIT_REV_ZERO
: _T("HEAD"), (void*)m_hWnd
);
2080 sCmd
+= L
" /alternative";
2081 CAppUtils::RunTortoiseGitProc(sCmd
);
2086 case IDGITLC_GNUDIFF1
:
2088 if (!CheckMultipleDiffs())
2090 POSITION pos
= GetFirstSelectedItemPosition();
2093 CTGitPath
* selectedFilepath
= (CTGitPath
* )GetItemData(GetNextSelectedItem(pos
));
2094 if (m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2098 fromwhere
= _T("~1");
2099 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, GitRev::GetHead() + fromwhere
, *selectedFilepath
, GitRev::GetWorkingCopy(), bShift
);
2103 if ((selectedFilepath
->m_ParentNo
& (PARENT_MASK
| MERGE_MASK
)) == 0)
2104 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, m_CurrentVersion
+ _T("~1"), *selectedFilepath
, m_CurrentVersion
, bShift
);
2108 if (!(selectedFilepath
->m_ParentNo
& MERGE_MASK
))
2109 str
.Format(_T("%s^%d"), (LPCTSTR
)m_CurrentVersion
, (selectedFilepath
->m_ParentNo
& PARENT_MASK
) + 1);
2111 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *selectedFilepath
, str
, *selectedFilepath
, m_CurrentVersion
, bShift
, false, false, false, !!(selectedFilepath
->m_ParentNo
& MERGE_MASK
));
2118 case IDGITLC_GNUDIFF2REVISIONS
:
2120 CAppUtils::StartShowUnifiedDiff(m_hWnd
, *filepath
, m_Rev2
, *filepath
, m_Rev1
, bShift
);
2126 CTGitPathList paths
;
2127 FillListOfSelectedItemPaths(paths
, true);
2129 CGitProgressDlg progDlg
;
2130 AddProgressCommand addCommand
;
2131 progDlg
.SetCommand(&addCommand
);
2132 addCommand
.SetShowCommitButtonAfterAdd((m_dwContextMenus
& GITSLC_POPCOMMIT
) != 0);
2133 addCommand
.SetPathList(paths
);
2134 progDlg
.SetItemCount(paths
.GetCount());
2137 // reset unchecked status
2138 POSITION pos
= GetFirstSelectedItemPosition();
2140 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2141 m_mapFilenameToChecked
.erase(((CTGitPath
*)GetItemData(index
))->GetGitPathString());
2143 if (GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2144 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2150 case IDGITLC_DELETE
:
2151 DeleteSelectedFiles();
2156 CAppUtils::LaunchTortoiseBlame(g_Git
.CombinePath(filepath
), m_CurrentVersion
);
2161 case IDGITLC_LOGSUBMODULE
:
2164 sCmd
.Format(_T("/command:log /path:\"%s\""), (LPCTSTR
)g_Git
.CombinePath(filepath
));
2165 if (cmd
== IDGITLC_LOG
&& filepath
->IsDirectory())
2166 sCmd
+= _T(" /submodule");
2167 if (!m_sDisplayedBranch
.IsEmpty())
2168 sCmd
+= _T(" /range:\"") + m_sDisplayedBranch
+ _T("\"");
2169 CAppUtils::RunTortoiseGitProc(sCmd
, false, !(cmd
== IDGITLC_LOGSUBMODULE
));
2173 case IDGITLC_LOGOLDNAME
:
2175 CTGitPath
oldName(filepath
->GetGitOldPathString());
2177 sCmd
.Format(_T("/command:log /path:\"%s\""), (LPCTSTR
)g_Git
.CombinePath(oldName
));
2178 if (!m_sDisplayedBranch
.IsEmpty())
2179 sCmd
+= _T(" /range:\"") + m_sDisplayedBranch
+ _T("\"");
2180 CAppUtils::RunTortoiseGitProc(sCmd
);
2184 case IDGITLC_EDITCONFLICT
:
2186 if (CAppUtils::ConflictEdit(*filepath
, bShift
, m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2188 CString conflictedFile
= g_Git
.CombinePath(filepath
);
2189 if (!PathFileExists(conflictedFile
) && GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2190 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2195 case IDGITLC_RESOLVETHEIRS
: //follow up
2196 case IDGITLC_RESOLVEMINE
: //follow up
2197 case IDGITLC_RESOLVECONFLICT
:
2199 if (CMessageBox::Show(m_hWnd
, IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
)==IDYES
)
2201 bool needsFullRefresh
= false;
2202 POSITION pos
= GetFirstSelectedItemPosition();
2206 index
= GetNextSelectedItem(pos
);
2207 CTGitPath
* fentry
=(CTGitPath
*) this->GetItemData(index
);
2211 CAppUtils::resolve_with resolveWith
= CAppUtils::RESOLVE_WITH_CURRENT
;
2212 if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
))
2213 resolveWith
= CAppUtils::RESOLVE_WITH_THEIRS
;
2214 else if (((!this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVEMINE
) || ((this->m_bIsRevertTheirMy
) && cmd
== IDGITLC_RESOLVETHEIRS
))
2215 resolveWith
= CAppUtils::RESOLVE_WITH_MINE
;
2216 if (CAppUtils::ResolveConflict(*fentry
, resolveWith
) == 0 && fentry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
2217 needsFullRefresh
= true;
2219 if (needsFullRefresh
&& CRegDWORD(_T("Software\\TortoiseGit\\RefreshFileListAfterResolvingConflict"), TRUE
) == TRUE
)
2221 CWnd
* pParent
= GetLogicalParent();
2222 if (pParent
&& pParent
->GetSafeHwnd())
2223 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2227 Show(m_dwShow
, 0, m_bShowFolders
,0,true);
2232 case IDGITLC_IGNORE
:
2234 CTGitPathList ignorelist
;
2235 //std::vector<CString> toremove;
2236 FillListOfSelectedItemPaths(ignorelist
, true);
2238 if(!CAppUtils::IgnoreFile(ignorelist
,false))
2242 CWnd
* pParent
= GetLogicalParent();
2243 if (pParent
&& pParent
->GetSafeHwnd())
2245 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2251 case IDGITLC_IGNOREMASK
:
2254 CString ext
=filepath
->GetFileExtension();
2255 CTGitPathList ignorelist
;
2256 FillListOfSelectedItemPaths(ignorelist
, true);
2258 if (!CAppUtils::IgnoreFile(ignorelist
,true))
2262 CWnd
* pParent
= GetLogicalParent();
2263 if (pParent
&& pParent
->GetSafeHwnd())
2265 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2272 case IDGITLC_IGNOREFOLDER
:
2274 CTGitPathList ignorelist
;
2275 ignorelist
.AddPath(filepath
->GetContainingDirectory());
2277 if (!CAppUtils::IgnoreFile(ignorelist
, false))
2281 CWnd
*pParent
= GetLogicalParent();
2282 if (pParent
&& pParent
->GetSafeHwnd())
2283 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
2288 case IDGITLC_COMMIT
:
2290 CTGitPathList targetList
;
2291 FillListOfSelectedItemPaths(targetList
);
2292 CTGitPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2293 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2294 CString commandline
= _T("/command:commit /pathfile:\"");
2295 commandline
+= tempFile
.GetWinPathString();
2296 commandline
+= _T("\"");
2297 commandline
+= _T(" /deletepathfile");
2298 CAppUtils::RunTortoiseGitProc(commandline
);
2301 case IDGITLC_REVERT
:
2303 // If at least one item is not in the status "added"
2304 // we ask for a confirmation
2305 BOOL bConfirm
= FALSE
;
2306 POSITION pos
= GetFirstSelectedItemPosition();
2308 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2310 //FileEntry * fentry = GetListEntry(index);
2311 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
2312 if(fentry
&& fentry
->m_Action
&CTGitPath::LOGACTIONS_MODIFIED
&& !fentry
->IsDirectory())
2320 str
.Format(IDS_PROC_WARNREVERT
,GetSelectedCount());
2322 if (!bConfirm
|| CMessageBox::Show(this->m_hWnd
, str
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2324 CTGitPathList targetList
;
2325 FillListOfSelectedItemPaths(targetList
);
2327 // make sure that the list is reverse sorted, so that
2328 // children are removed before any parents
2329 targetList
.SortByPathname(true);
2331 // put all reverted files in the trashbin, except the ones with 'added'
2332 // status because they are not restored by the revert.
2333 CTGitPathList delList
;
2334 POSITION pos2
= GetFirstSelectedItemPosition();
2336 while ((index2
= GetNextSelectedItem(pos2
)) >= 0)
2338 CTGitPath
*entry
=(CTGitPath
*)GetItemData(index2
);
2339 if (entry
&&(!(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
))
2340 && (!(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)) && !entry
->IsDirectory())
2343 fullpath
.SetFromWin(g_Git
.CombinePath(entry
));
2344 delList
.AddPath(fullpath
);
2347 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2348 delList
.DeleteAllFiles(true);
2350 CString revertToCommit
= _T("HEAD");
2352 revertToCommit
= _T("HEAD~1");
2354 if (g_Git
.Revert(revertToCommit
, targetList
, err
))
2355 CMessageBox::Show(this->m_hWnd
, _T("Revert failed:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2358 bool updateStatusList
= false;
2359 for (int i
= 0 ; i
< targetList
.GetCount(); ++i
)
2361 int nListboxEntries
= GetItemCount();
2362 for (int nItem
=0; nItem
<nListboxEntries
; ++nItem
)
2364 CTGitPath
*path
=(CTGitPath
*)GetItemData(nItem
);
2365 if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && !path
->IsDirectory())
2367 if(path
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2369 path
->m_Action
= CTGitPath::LOGACTIONS_UNVER
;
2370 SetEntryCheck(path
,nItem
,false);
2371 updateStatusList
= true;
2372 #if 0 // revert an added file and some entry will be cloned (part 1/2)
2373 SetItemGroup(nItem
,1);
2374 this->m_StatusFileList
.RemoveItem(*path
);
2375 this->m_UnRevFileList
.AddPath(*path
);
2376 //this->m_IgnoreFileList.RemoveItem(*path);
2381 if (GetCheck(nItem
))
2383 RemoveListEntry(nItem
);
2387 else if (path
->GetGitPathString()==targetList
[i
].GetGitPathString() && path
->IsDirectory() && path
->IsWCRoot())
2390 sCmd
.Format(_T("/command:revert /path:\"%s\""), (LPCTSTR
)path
->GetGitPathString());
2391 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
2396 #if 0 // revert an added file and some entry will be cloned (part 2/2)
2397 Show(m_dwShow
, 0, m_bShowFolders
,updateStatusList
,true);
2400 if (updateStatusList
&& GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2401 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2408 case IDGITLC_ASSUMEVALID
:
2409 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_ASSUMEVALID
, BST_CHECKED
, BST_INDETERMINATE
);
2411 case IDGITLC_SKIPWORKTREE
:
2412 SetGitIndexFlagsForSelectedFiles(IDS_PROC_MARK_SKIPWORKTREE
, BST_INDETERMINATE
, BST_CHECKED
);
2414 case IDGITLC_UNSETIGNORELOCALCHANGES
:
2415 SetGitIndexFlagsForSelectedFiles(IDS_PROC_UNSET_IGNORELOCALCHANGES
, BST_UNCHECKED
, BST_UNCHECKED
);
2418 CopySelectedEntriesToClipboard(0);
2420 case IDGITLC_COPYEXT
:
2421 CopySelectedEntriesToClipboard((DWORD
)-1);
2423 case IDGITLC_EXPORT
:
2426 case IDGITLC_SAVEAS
:
2427 FileSaveAs(filepath
);
2430 case IDGITLC_REVERTTOREV
:
2431 RevertSelectedItemToVersion();
2433 case IDGITLC_REVERTTOPARENT
:
2434 RevertSelectedItemToVersion(true);
2437 case IDSVNLC_COMMIT
:
2439 CTSVNPathList targetList
;
2440 FillListOfSelectedItemPaths(targetList
);
2441 CTSVNPath tempFile
= CTempFiles::Instance().GetTempFilePath(false);
2442 VERIFY(targetList
.WriteToFile(tempFile
.GetWinPathString()));
2443 CString commandline
= CPathUtils::GetAppDirectory();
2444 commandline
+= _T("TortoiseGitProc.exe /command:commit /pathfile:\"");
2445 commandline
+= tempFile
.GetWinPathString();
2446 commandline
+= _T("\"");
2447 commandline
+= _T(" /deletepathfile");
2448 CAppUtils::LaunchApplication(commandline
, nullptr, false);
2451 case IDSVNLC_CREATEIGNORECS
:
2452 CreateChangeList(SVNSLC_IGNORECHANGELIST
);
2454 case IDSVNLC_CREATECS
:
2456 CCreateChangelistDlg dlg
;
2457 if (dlg
.DoModal() == IDOK
)
2458 CreateChangeList(dlg
.m_sName
);
2463 if (cmd
< IDSVNLC_MOVETOCS
)
2465 CTSVNPathList changelistItems
;
2466 FillListOfSelectedItemPaths(changelistItems
);
2468 // find the changelist name
2469 CString sChangelist
;
2470 int cmdID
= IDSVNLC_MOVETOCS
;
2472 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
2474 if ((it
->first
.Compare(SVNSLC_IGNORECHANGELIST
))&&(entry
->changelist
.Compare(it
->first
)))
2477 sChangelist
= it
->first
;
2481 if (!sChangelist
.IsEmpty())
2484 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
2486 // The changelists were moved, but we now need to run through the selected items again
2487 // and update their changelist
2488 POSITION pos
= GetFirstSelectedItemPosition();
2490 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2492 FileEntry
* e
= GetListEntry(index
);
2493 e
->changelist
= sChangelist
;
2496 if (m_changelists
.find(e
->changelist
)!=m_changelists
.end())
2497 SetItemGroup(index
, m_changelists
[e
->changelist
]);
2499 SetItemGroup(index
, 0);
2504 CMessageBox::Show(m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
2513 AfxGetApp()->DoWaitCursor(-1);
2514 GetStatisticsString();
2515 //int iItemCountAfterMenuCmd = GetItemCount();
2516 //if (iItemCountAfterMenuCmd != iItemCountBeforeMenuCmd)
2518 // CWnd* pParent = GetParent();
2519 // if (pParent && pParent->GetSafeHwnd())
2521 // pParent->SendMessage(SVNSLNM_ITEMCOUNTCHANGED);
2524 } // if (popup.CreatePopupMenu())
2525 } // if (selIndex >= 0)
2528 void CGitStatusListCtrl::SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
)
2530 if (CMessageBox::Show(GetSafeHwnd(), message
, IDS_APPNAME
, MB_YESNO
| MB_DEFBUTTON2
| MB_ICONQUESTION
) != IDYES
)
2533 CAutoRepository
repository(g_Git
.GetGitRepository());
2536 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2540 CAutoIndex gitindex
;
2541 if (git_repository_index(gitindex
.GetPointer(), repository
))
2543 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2547 POSITION pos
= GetFirstSelectedItemPosition();
2549 while ((index
= GetNextSelectedItem(pos
)) >= 0)
2551 CTGitPath
* path
= (CTGitPath
*)GetItemData(index
);
2553 if (path
== nullptr)
2557 if (!git_index_find(&idx
, gitindex
, CUnicodeUtils::GetMulti(path
->GetGitPathString(), CP_UTF8
)))
2559 git_index_entry
*e
= const_cast<git_index_entry
*>(git_index_get_byindex(gitindex
, idx
)); // HACK
2560 if (assumevalid
== BST_UNCHECKED
)
2561 e
->flags
&= ~GIT_IDXENTRY_VALID
;
2562 else if (assumevalid
== BST_CHECKED
)
2563 e
->flags
|= GIT_IDXENTRY_VALID
;
2564 if (skipworktree
== BST_UNCHECKED
)
2565 e
->flags_extended
&= ~GIT_IDXENTRY_SKIP_WORKTREE
;
2566 else if (skipworktree
== BST_CHECKED
)
2567 e
->flags_extended
|= GIT_IDXENTRY_SKIP_WORKTREE
;
2568 git_index_add(gitindex
, e
);
2571 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2574 if (git_index_write(gitindex
))
2576 CMessageBox::Show(m_hWnd
, g_Git
.GetLibGit2LastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2580 if (nullptr != GetLogicalParent() && nullptr != GetLogicalParent()->GetSafeHwnd())
2581 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2586 void CGitStatusListCtrl::OnContextMenu(CWnd
* pWnd
, CPoint point
)
2588 __super::OnContextMenu(pWnd
, point
);
2590 OnContextMenuList(pWnd
, point
);
2593 void CGitStatusListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2595 Locker
lock(m_critSec
);
2596 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2601 if (pNMLV
->iItem
< 0)
2604 CTGitPath
*file
=(CTGitPath
*)GetItemData(pNMLV
->iItem
);
2606 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)) {
2607 StartDiffWC(pNMLV
->iItem
);
2610 if( file
->m_Action
&CTGitPath::LOGACTIONS_UNMERGED
)
2612 if (CAppUtils::ConflictEdit(*file
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
2614 CString conflictedFile
= g_Git
.CombinePath(file
);
2615 if (!PathFileExists(conflictedFile
) && GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
2616 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
2619 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
))
2623 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
2624 StartDiffTwo(pNMLV
->iItem
);
2626 StartDiff(pNMLV
->iItem
);
2629 void CGitStatusListCtrl::StartDiffTwo(int fileindex
)
2634 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2637 CTGitPath file1
= *ptr
;
2639 if (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
)
2640 CGitDiff::DiffNull(&file1
, m_Rev1
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2641 else if (file1
.m_Action
& CTGitPath::LOGACTIONS_DELETED
)
2642 CGitDiff::DiffNull(&file1
, m_Rev2
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2644 CGitDiff::Diff(&file1
, &file1
, m_Rev1
, m_Rev2
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2647 void CGitStatusListCtrl::StartDiffWC(int fileindex
)
2653 if (m_CurrentVersion
.IsEmpty())
2654 m_CurrentVersion
== GIT_REV_ZERO
;
2656 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2659 CTGitPath file1
= *ptr
;
2660 file1
.m_Action
= 0; // reset action, so that diff is not started as added/deleted file; see issue #1757
2662 CGitDiff::Diff(&file1
, &file1
, GIT_REV_ZERO
, m_CurrentVersion
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2665 void CGitStatusListCtrl::StartDiff(int fileindex
)
2670 auto ptr
= (CTGitPath
*)GetItemData(fileindex
);
2673 CTGitPath file1
= *ptr
;
2675 if(file1
.m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
))
2676 file2
.SetFromGit(file1
.GetGitOldPathString());
2680 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
2683 if(m_amend
&& (file1
.m_Action
& CTGitPath::LOGACTIONS_ADDED
) == 0)
2684 fromwhere
= _T("~1");
2685 if( g_Git
.IsInitRepos())
2686 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2687 GIT_REV_ZERO
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2688 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_ADDED
)
2689 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2690 m_CurrentVersion
+ fromwhere
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2691 else if( file1
.m_Action
&CTGitPath::LOGACTIONS_DELETED
)
2692 CGitDiff::DiffNull((CTGitPath
*)GetItemData(fileindex
),
2693 GitRev::GetHead() + fromwhere
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2695 CGitDiff::Diff(&file1
,&file2
,
2696 CString(GIT_REV_ZERO
),
2697 GitRev::GetHead() + fromwhere
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2702 CString fromwhere
= m_CurrentVersion
+_T("~1");
2704 fromwhere
= m_CurrentVersion
+_T("~2");
2705 bool revfail
= !!g_Git
.GetHash(hash
, fromwhere
);
2706 if (revfail
|| (file1
.m_Action
& file1
.LOGACTIONS_ADDED
))
2707 CGitDiff::DiffNull(&file1
, m_CurrentVersion
, true, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2708 else if (file1
.m_Action
& file1
.LOGACTIONS_DELETED
)
2710 if (file1
.m_ParentNo
> 0)
2711 fromwhere
.Format(_T("%s^%d"), (LPCTSTR
)m_CurrentVersion
, file1
.m_ParentNo
+ 1);
2713 CGitDiff::DiffNull(&file1
, fromwhere
, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2717 if( file1
.m_ParentNo
& MERGE_MASK
)
2719 CTGitPath base
, theirs
, mine
, merge
;
2722 GetTempPath(temppath
);
2723 temppath
.TrimRight(_T("\\"));
2725 mine
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".LOCAL") + file1
.GetFileExtension());
2726 theirs
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".REMOTE") + file1
.GetFileExtension());
2727 base
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".BASE") + file1
.GetFileExtension());
2730 //create a empty file, incase stage is not three
2731 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2733 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2735 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
2738 merge
.SetFromGit(temppath
+ _T("\\") + file1
.GetFileOrDirectoryName() + _T(".Merged") + file1
.GetFileExtension());
2740 int parent1
=-1, parent2
=-1;
2741 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
2743 if(m_arStatusArray
[i
]->GetGitPathString() == file1
.GetGitPathString())
2745 if(m_arStatusArray
[i
]->m_ParentNo
& MERGE_MASK
)
2751 parent1
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2752 else if (parent2
<0)
2753 parent2
= m_arStatusArray
[i
]->m_ParentNo
& PARENT_MASK
;
2758 if(g_Git
.GetOneFile(m_CurrentVersion
, file1
, (CString
&)merge
.GetWinPathString()))
2759 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2764 str
.Format(_T("%s^%d"), (LPCTSTR
)this->m_CurrentVersion
, parent1
+ 1);
2766 if(g_Git
.GetOneFile(str
, file1
, (CString
&)mine
.GetWinPathString()))
2767 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2773 str
.Format(_T("%s^%d"), (LPCTSTR
)this->m_CurrentVersion
, parent2
+ 1);
2775 if(g_Git
.GetOneFile(str
, file1
, (CString
&)theirs
.GetWinPathString()))
2776 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETMERGEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2779 if(parent1
>=0 && parent2
>=0)
2781 CString cmd
, output
;
2782 cmd
.Format(_T("git.exe merge-base %s^%d %s^%d"), (LPCTSTR
)this->m_CurrentVersion
, parent1
+ 1,
2783 this->m_CurrentVersion
,parent2
+1);
2785 if (!g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
))
2787 if(g_Git
.GetOneFile(output
.Left(40), file1
, (CString
&)base
.GetWinPathString()))
2788 CMessageBox::Show(GetSafeHwnd(), IDS_STATUSLIST_FAILEDGETBASEFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2791 CAppUtils::StartExtMerge(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), base
, theirs
, mine
, merge
, L
"BASE", L
"REMOTE", L
"LOCAL");
2796 if( (file1
.m_ParentNo
&PARENT_MASK
) == 0)
2799 str
.Format(_T("^%d"), (file1
.m_ParentNo
&PARENT_MASK
)+1);
2800 CGitDiff::Diff(&file1
,&file2
,
2802 m_CurrentVersion
+ str
, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2808 CString
CGitStatusListCtrl::GetStatisticsString(bool simple
)
2810 CString sNormal
= CString(MAKEINTRESOURCE(IDS_STATUSNORMAL
));
2811 CString sAdded
= CString(MAKEINTRESOURCE(IDS_STATUSADDED
));
2812 CString sDeleted
= CString(MAKEINTRESOURCE(IDS_STATUSDELETED
));
2813 CString sModified
= CString(MAKEINTRESOURCE(IDS_STATUSMODIFIED
));
2814 CString sConflicted
= CString(MAKEINTRESOURCE(IDS_STATUSCONFLICTED
));
2815 CString sUnversioned
= CString(MAKEINTRESOURCE(IDS_STATUSUNVERSIONED
));
2816 CString sRenamed
= CString(MAKEINTRESOURCE(IDS_STATUSREPLACED
));
2820 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE1
,
2821 this->m_nLineAdded
,this->m_nLineDeleted
,
2822 (LPCTSTR
)sModified
, m_nModified
,
2823 (LPCTSTR
)sAdded
, m_nAdded
,
2824 (LPCTSTR
)sDeleted
, m_nDeleted
,
2825 (LPCTSTR
)sRenamed
, m_nRenamed
2830 sToolTip
.Format(IDS_STATUSLIST_STATUSLINE2
,
2831 this->m_nLineAdded
,this->m_nLineDeleted
,
2832 (LPCTSTR
)sNormal
, m_nNormal
,
2833 (LPCTSTR
)sUnversioned
, m_nUnversioned
,
2834 (LPCTSTR
)sModified
, m_nModified
,
2835 (LPCTSTR
)sAdded
, m_nAdded
,
2836 (LPCTSTR
)sDeleted
, m_nDeleted
,
2837 (LPCTSTR
)sConflicted
, m_nConflicted
2841 sStats
.Format(IDS_COMMITDLG_STATISTICSFORMAT
, m_nSelected
, GetItemCount());
2843 m_pStatLabel
->SetWindowText(sStats
);
2845 if (m_pSelectButton
)
2847 if (m_nSelected
== 0)
2848 m_pSelectButton
->SetCheck(BST_UNCHECKED
);
2849 else if (m_nSelected
!= GetItemCount())
2850 m_pSelectButton
->SetCheck(BST_INDETERMINATE
);
2852 m_pSelectButton
->SetCheck(BST_CHECKED
);
2855 if (m_pConfirmButton
)
2856 m_pConfirmButton
->EnableWindow(m_nSelected
>0);
2861 CString
CGitStatusListCtrl::GetCommonDirectory(bool bStrict
)
2865 // not strict means that the selected folder has priority
2866 if (!m_StatusFileList
.GetCommonDirectory().IsEmpty())
2867 return m_StatusFileList
.GetCommonDirectory().GetWinPath();
2870 CTGitPath commonBaseDirectory
;
2871 int nListItems
= GetItemCount();
2872 for (int i
=0; i
<nListItems
; ++i
)
2874 CTGitPath baseDirectory
,*p
= (CTGitPath
*)this->GetItemData(i
);
2878 baseDirectory
= p
->GetDirectory();
2880 if(commonBaseDirectory
.IsEmpty())
2881 commonBaseDirectory
= baseDirectory
;
2884 if (commonBaseDirectory
.GetWinPathString().GetLength() > baseDirectory
.GetWinPathString().GetLength())
2886 if (baseDirectory
.IsAncestorOf(commonBaseDirectory
))
2887 commonBaseDirectory
= baseDirectory
;
2891 return g_Git
.CombinePath(commonBaseDirectory
);
2894 void CGitStatusListCtrl::SelectAll(bool bSelect
, bool /*bIncludeNoCommits*/)
2896 CWaitCursor waitCursor
;
2897 // block here so the LVN_ITEMCHANGED messages
2902 int nListItems
= GetItemCount();
2904 m_nSelected
= nListItems
;
2908 for (int i
=0; i
<nListItems
; ++i
)
2910 //FileEntry * entry = GetListEntry(i);
2912 CTGitPath
*path
= (CTGitPath
*) GetItemData(i
);
2915 //if ((bIncludeNoCommits)||(entry->GetChangeList().Compare(SVNSLC_IGNORECHANGELIST)))
2916 SetEntryCheck(path
,i
,bSelect
);
2919 // unblock before redrawing
2922 GetStatisticsString();
2926 void CGitStatusListCtrl::Check(DWORD dwCheck
, bool check
)
2928 CWaitCursor waitCursor
;
2929 // block here so the LVN_ITEMCHANGED messages
2934 int nListItems
= GetItemCount();
2936 for (int i
= 0; i
< nListItems
; ++i
)
2938 CTGitPath
*entry
= (CTGitPath
*) GetItemData(i
);
2942 DWORD showFlags
= entry
->m_Action
;
2943 if (entry
->IsDirectory())
2944 showFlags
|= GITSLC_SHOWSUBMODULES
;
2946 showFlags
|= GITSLC_SHOWFILES
;
2948 if (check
&& (showFlags
& dwCheck
) && !GetCheck(i
) && !(entry
->IsDirectory() && m_bDoNotAutoselectSubmodules
&& !(dwCheck
& GITSLC_SHOWSUBMODULES
)))
2950 SetEntryCheck(entry
, i
, true);
2953 else if (!check
&& (showFlags
& dwCheck
) && GetCheck(i
))
2955 SetEntryCheck(entry
, i
, false);
2959 // unblock before redrawing
2962 GetStatisticsString();
2966 void CGitStatusListCtrl::OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2968 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
2973 CTGitPath
*entry
=(CTGitPath
*)GetItemData(pGetInfoTip
->iItem
);
2976 if (pGetInfoTip
->cchTextMax
> entry
->GetGitPathString().GetLength() + g_Git
.m_CurrentDir
.GetLength())
2978 CString str
= g_Git
.CombinePath(entry
->GetWinPathString());
2979 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, str
.GetBuffer(), pGetInfoTip
->cchTextMax
- 1);
2983 void CGitStatusListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2985 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
2987 // Take the default processing unless we set this to something else below.
2988 *pResult
= CDRF_DODEFAULT
;
2990 // First thing - check the draw stage. If it's the control's prepaint
2991 // stage, then tell Windows we want messages for every item.
2993 switch (pLVCD
->nmcd
.dwDrawStage
)
2996 *pResult
= CDRF_NOTIFYITEMDRAW
;
2998 case CDDS_ITEMPREPAINT
:
3000 // This is the prepaint stage for an item. Here's where we set the
3001 // item's text color. Our return value will tell Windows to draw the
3002 // item itself, but it will use the new color we set here.
3004 // Tell Windows to paint the control itself.
3005 *pResult
= CDRF_DODEFAULT
;
3009 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
3011 if (m_arStatusArray
.size() > (DWORD_PTR
)pLVCD
->nmcd
.dwItemSpec
)
3013 //FileEntry * entry = GetListEntry((int)pLVCD->nmcd.dwItemSpec);
3014 CTGitPath
*entry
=(CTGitPath
*)GetItemData((int)pLVCD
->nmcd
.dwItemSpec
);
3020 // black : unversioned, normal
3023 // brown : missing, deleted, replaced
3024 // green : merged (or potential merges)
3025 // red : conflicts or sure conflicts
3026 if(entry
->m_Action
& CTGitPath::LOGACTIONS_GRAY
)
3027 crText
= RGB(128,128,128);
3028 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3029 crText
= m_Colors
.GetColor(CColors::Conflict
);
3030 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_MODIFIED
))
3031 crText
= m_Colors
.GetColor(CColors::Modified
);
3032 else if(entry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
))
3033 crText
= m_Colors
.GetColor(CColors::Added
);
3034 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
3035 crText
= m_Colors
.GetColor(CColors::Deleted
);
3036 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
3037 crText
= m_Colors
.GetColor(CColors::Renamed
);
3038 else if(entry
->m_Action
& CTGitPath::LOGACTIONS_MERGED
)
3039 crText
= m_Colors
.GetColor(CColors::Merged
);
3041 crText
= GetSysColor(COLOR_WINDOWTEXT
);
3042 // Store the color back in the NMLVCUSTOMDRAW struct.
3043 pLVCD
->clrText
= crText
;
3050 BOOL
CGitStatusListCtrl::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
3053 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3056 HCURSOR hCur
= LoadCursor(nullptr, IDC_ARROW
);
3058 return CListCtrl::OnSetCursor(pWnd
, nHitTest
, message
);
3060 HCURSOR hCur
= LoadCursor(nullptr, IDC_WAIT
);
3065 void CGitStatusListCtrl::RemoveListEntry(int index
)
3067 Locker
lock(m_critSec
);
3070 m_arStatusArray
.erase(m_arStatusArray
.cbegin() + index
);
3073 delete m_arStatusArray
[m_arListArray
[index
]];
3074 m_arStatusArray
.erase(m_arStatusArray
.begin()+m_arListArray
[index
]);
3075 m_arListArray
.erase(m_arListArray
.begin()+index
);
3076 for (int i
=index
; i
< (int)m_arListArray
.size(); ++i
)
3083 ///< Set a checkbox on an entry in the listbox
3084 // NEVER, EVER call SetCheck directly, because you'll end-up with the checkboxes and the 'checked' flag getting out of sync
3085 void CGitStatusListCtrl::SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
)
3087 pEntry
->m_Checked
= bCheck
;
3088 m_mapFilenameToChecked
[pEntry
->GetGitPathString()] = bCheck
;
3089 SetCheck(listboxIndex
, bCheck
);
3093 void CGitStatusListCtrl::SetCheckOnAllDescendentsOf(const FileEntry
* parentEntry
, bool bCheck
)
3095 int nListItems
= GetItemCount();
3096 for (int j
=0; j
< nListItems
; ++j
)
3098 FileEntry
* childEntry
= GetListEntry(j
);
3100 if (!childEntry
|| childEntry
== parentEntry
)
3102 if (childEntry
->checked
!= bCheck
)
3104 if (parentEntry
->path
.IsAncestorOf(childEntry
->path
))
3106 SetEntryCheck(childEntry
,j
,bCheck
);
3117 void CGitStatusListCtrl::WriteCheckedNamesToPathList(CTGitPathList
& pathList
)
3120 int nListItems
= GetItemCount();
3121 for (int i
= 0; i
< nListItems
; ++i
)
3123 CTGitPath
* entry
= (CTGitPath
*)GetItemData(i
);
3125 if (entry
->m_Checked
)
3126 pathList
.AddPath(*entry
);
3128 pathList
.SortByPathname();
3132 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
3133 void CGitStatusListCtrl::FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool /*bNoIgnored*/)
3137 POSITION pos
= GetFirstSelectedItemPosition();
3139 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3141 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3142 //if ((bNoIgnored)&&(entry->status == git_wc_status_ignored))
3144 pathList
.AddPath(*entry
);
3148 UINT
CGitStatusListCtrl::OnGetDlgCode()
3150 // we want to process the return key and not have that one
3151 // routed to the default pushbutton
3152 return CListCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS
;
3155 void CGitStatusListCtrl::OnNMReturn(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
3160 if (!CheckMultipleDiffs())
3162 bool needsRefresh
= false;
3163 POSITION pos
= GetFirstSelectedItemPosition();
3166 int index
= GetNextSelectedItem(pos
);
3169 CTGitPath
*file
=(CTGitPath
*)GetItemData(index
);
3170 if (file
== nullptr)
3172 if (file
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
))
3174 else if ((file
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
))
3176 if (CAppUtils::ConflictEdit(*file
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), m_bIsRevertTheirMy
, GetLogicalParent() ? GetLogicalParent()->GetSafeHwnd() : nullptr))
3178 CString conflictedFile
= g_Git
.CombinePath(file
);
3179 needsRefresh
= needsRefresh
|| !PathFileExists(conflictedFile
);
3182 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
))
3186 if (!m_Rev1
.IsEmpty() && !m_Rev2
.IsEmpty())
3187 StartDiffTwo(index
);
3192 if (needsRefresh
&& GetLogicalParent() && GetLogicalParent()->GetSafeHwnd())
3193 GetLogicalParent()->SendMessage(GITSLNM_NEEDSREFRESH
);
3196 void CGitStatusListCtrl::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3198 // Since we catch all keystrokes (to have the enter key processed here instead
3199 // of routed to the default pushbutton) we have to make sure that other
3200 // keys like Tab and Esc still do what they're supposed to do
3201 // Tab = change focus to next/previous control
3202 // Esc = quit the dialog
3207 ::PostMessage(GetLogicalParent()->GetSafeHwnd(), WM_NEXTDLGCTL
, GetKeyState(VK_SHIFT
)&0x8000, 0);
3213 ::SendMessage(GetLogicalParent()->GetSafeHwnd(), WM_CLOSE
, 0, 0);
3218 CListCtrl::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3221 void CGitStatusListCtrl::PreSubclassWindow()
3223 __super::PreSubclassWindow();
3224 EnableToolTips(TRUE
);
3225 SetWindowTheme(GetSafeHwnd(), L
"Explorer", nullptr);
3228 void CGitStatusListCtrl::OnPaint()
3230 LRESULT defres
= Default();
3231 if ((m_bBusy
) || (m_bEmpty
))
3236 if (m_sBusy
.IsEmpty())
3237 str
.LoadString(IDS_STATUSLIST_BUSYMSG
);
3243 if (m_sEmpty
.IsEmpty())
3244 str
.LoadString(IDS_STATUSLIST_EMPTYMSG
);
3248 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
3250 if (IsWindowEnabled())
3251 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
3253 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
3257 CHeaderCtrl
* pHC
= GetHeaderCtrl();
3261 pHC
->GetItemRect(0, &rcH
);
3262 rc
.top
+= rcH
.bottom
;
3266 CMyMemDC
memDC(pDC
, &rc
);
3268 memDC
.SetTextColor(clrText
);
3269 memDC
.SetBkColor(clrTextBk
);
3270 memDC
.BitBlt(rc
.left
, rc
.top
, rc
.Width(), rc
.Height(), pDC
, rc
.left
, rc
.top
, SRCCOPY
);
3272 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
3273 memDC
.DrawText(str
, rc
, DT_CENTER
| DT_VCENTER
|
3274 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
3275 memDC
.SelectObject(oldfont
);
3281 // the Default() call did not process the WM_PAINT message!
3282 // Validate the update region ourselves to avoid
3283 // an endless loop repainting
3285 GetUpdateRect(&rc
, FALSE
);
3286 if (!rc
.IsRectEmpty())
3291 void CGitStatusListCtrl::OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
)
3293 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
3295 Locker
lock(m_critSec
);
3297 CTGitPathList pathList
;
3298 FillListOfSelectedItemPaths(pathList
);
3299 if (pathList
.IsEmpty())
3302 auto pdsrc
= std::make_unique
<CIDropSource
>();
3307 GitDataObject
* pdobj
= new GitDataObject(pathList
, m_CurrentVersion
);
3312 CDragSourceHelper dragsrchelper
;
3314 // Something strange is going on here:
3315 // InitializeFromWindow() crashes bad if group view is enabled.
3316 // Since I haven't been able to find out *why* it crashes, I'm disabling
3317 // the group view right before the call to InitializeFromWindow() and
3318 // re-enable it again after the call is finished.
3321 BOOL bGroupView
= IsGroupViewEnabled();
3323 EnableGroupView(false);
3324 dragsrchelper
.InitializeFromWindow(m_hWnd
, pNMLV
->ptAction
, pdobj
);
3326 EnableGroupView(true);
3328 //dragsrchelper.InitializeFromBitmap()
3329 pdsrc
->m_pIDataObj
= pdobj
;
3330 pdsrc
->m_pIDataObj
->AddRef();
3332 // Initiate the Drag & Drop
3335 ::DoDragDrop(pdobj
, pdsrc
.get(), DROPEFFECT_MOVE
| DROPEFFECT_COPY
, &dwEffect
);
3344 bool CGitStatusListCtrl::EnableFileDrop()
3346 m_bFileDropsEnabled
= true;
3350 bool CGitStatusListCtrl::HasPath(const CTGitPath
& path
)
3352 for (size_t i
=0; i
< m_arStatusArray
.size(); ++i
)
3354 if (m_arStatusArray
[i
]->IsEquivalentTo(path
))
3361 BOOL
CGitStatusListCtrl::PreTranslateMessage(MSG
* pMsg
)
3363 if (pMsg
->message
== WM_KEYDOWN
)
3365 switch (pMsg
->wParam
)
3369 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3371 // select all entries
3372 for (int i
=0; i
<GetItemCount(); ++i
)
3373 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3381 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
3383 // copy all selected paths to the clipboard
3384 if (GetAsyncKeyState(VK_SHIFT
)&0x8000)
3385 CopySelectedEntriesToClipboard(GITSLC_COLSTATUS
);
3387 CopySelectedEntriesToClipboard(0);
3394 if ((GetSelectedCount() > 0) && (m_dwContextMenus
& GITSLC_POPDELETE
))
3397 CTGitPath
* filepath
= (CTGitPath
*)GetItemData(GetSelectionMark());
3398 if (filepath
!= nullptr && (filepath
->m_Action
& (CTGitPath::LOGACTIONS_UNVER
| CTGitPath::LOGACTIONS_IGNORE
)))
3399 DeleteSelectedFiles();
3407 return __super::PreTranslateMessage(pMsg
);
3410 bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols
)
3412 static HINSTANCE
hResourceHandle(AfxGetResourceHandle());
3413 // WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
3418 if (GetSelectedCount() == 0)
3421 // first add the column titles as the first line
3422 // We needn't head when only path copy
3423 //temp.LoadString(IDS_STATUSLIST_COLFILE);
3424 //sClipboard = temp;
3426 DWORD selection
= 0;
3427 for (int i
= 0, count
= m_ColumnManager
.GetColumnCount(); i
< count
; ++i
)
3428 if ( ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3429 || ((dwCols
!= 1) && (i
< 32) && ((dwCols
& (1 << i
)) != 0)))
3431 sClipboard
+= _T("\t") + m_ColumnManager
.GetName(i
);
3434 selection
+= 1 << i
;
3438 sClipboard
+= _T("\r\n");
3440 POSITION pos
= GetFirstSelectedItemPosition();
3442 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3444 CTGitPath
* entry
= (CTGitPath
*)GetItemData(index
);
3448 sClipboard
+= entry
->GetWinPathString();
3449 if (selection
& GITSLC_COLFILENAME
)
3450 sClipboard
+= _T("\t")+entry
->GetFileOrDirectoryName();
3451 if (selection
& GITSLC_COLEXT
)
3452 sClipboard
+= _T("\t")+entry
->GetFileExtension();
3454 if (selection
& GITSLC_COLSTATUS
)
3455 sClipboard
+= _T("\t")+entry
->GetActionName();
3457 if (selection
& SVNSLC_COLDATE
)
3459 TCHAR datebuf
[SVN_DATE_BUFFER
];
3460 apr_time_t date
= entry
->last_commit_date
;
3461 SVN::formatDate(datebuf
, date
, true);
3466 sClipboard
+= _T("\t")+temp
;
3468 for ( int i
= SVNSLC_NUMCOLUMNS
, count
= m_ColumnManager
.GetColumnCount()
3472 if ((dwCols
== -1) && m_ColumnManager
.IsVisible (i
))
3475 = entry
->present_props
[m_ColumnManager
.GetName(i
)];
3476 sClipboard
+= _T("\t") + value
;
3480 if (selection
& GITSLC_COLADD
)
3481 sClipboard
+= _T("\t")+entry
->m_StatAdd
;
3482 if (selection
& GITSLC_COLDEL
)
3483 sClipboard
+= _T("\t")+entry
->m_StatDel
;
3485 sClipboard
+= _T("\r\n");
3488 return CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
3491 size_t CGitStatusListCtrl::GetNumberOfChangelistsInSelection()
3494 std::set
<CString
> changelists
;
3495 POSITION pos
= GetFirstSelectedItemPosition();
3497 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3499 FileEntry
* entry
= GetListEntry(index
);
3500 if (!entry
->changelist
.IsEmpty())
3501 changelists
.insert(entry
->changelist
);
3503 return changelists
.size();
3508 bool CGitStatusListCtrl::PrepareGroups(bool bForce
/* = false */)
3510 bool bHasGroups
=false;
3513 for (size_t i
= 0; i
< m_arStatusArray
.size(); ++i
)
3515 int ParentNo
= m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3517 max
=m_arStatusArray
[i
]->m_ParentNo
&PARENT_MASK
;
3520 if (((m_dwShow
& GITSLC_SHOWUNVERSIONED
) && !m_UnRevFileList
.IsEmpty()) ||
3521 ((m_dwShow
& GITSLC_SHOWIGNORED
) && !m_IgnoreFileList
.IsEmpty()) ||
3522 (m_dwShow
& (GITSLC_SHOWASSUMEVALID
| GITSLC_SHOWSKIPWORKTREE
) && !m_LocalChangesIgnoredFileList
.IsEmpty()) ||
3529 EnableGroupView(bHasGroups
);
3531 TCHAR groupname
[1024] = { 0 };
3537 grp
.cbSize
= sizeof(LVGROUP
);
3538 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3541 //if(m_UnRevFileList.GetCount()>0)
3544 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MERGEDFILES
)), 1023);
3545 grp
.pszHeader
= groupname
;
3546 grp
.iGroupId
= MERGE_MASK
;
3547 grp
.uAlign
= LVGA_HEADER_LEFT
;
3548 InsertGroup(0, &grp
);
3550 CAutoRepository
repository(g_Git
.GetGitRepository());
3552 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3553 for (int i
= 0; i
<= max
; ++i
)
3556 str
.Format(IDS_STATUSLIST_GROUP_DIFFWITHPARENT
, i
+1);
3560 rev
.Format(_T("%s^%d"), (LPCTSTR
)m_CurrentVersion
, i
+ 1);
3562 if (!CGit::GetHash(repository
, hash
, rev
))
3563 str
+= _T(": ") + hash
.ToString().Left(g_Git
.GetShortHASHLength());
3565 grp
.pszHeader
= str
.GetBuffer();
3566 str
.ReleaseBuffer();
3568 grp
.uAlign
= LVGA_HEADER_LEFT
;
3569 InsertGroup(i
+1, &grp
);
3574 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_MODIFIEDFILES
)), 1023);
3575 grp
.pszHeader
= groupname
;
3576 grp
.iGroupId
= groupindex
;
3577 grp
.uAlign
= LVGA_HEADER_LEFT
;
3578 InsertGroup(groupindex
++, &grp
);
3581 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_NOTVERSIONEDFILES
)), 1023);
3582 grp
.pszHeader
= groupname
;
3583 grp
.iGroupId
= groupindex
;
3584 grp
.uAlign
= LVGA_HEADER_LEFT
;
3585 InsertGroup(groupindex
++, &grp
);
3588 //if(m_IgnoreFileList.GetCount()>0)
3590 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNOREDFILES
)), 1023);
3591 grp
.pszHeader
= groupname
;
3592 grp
.iGroupId
= groupindex
;
3593 grp
.uAlign
= LVGA_HEADER_LEFT
;
3594 InsertGroup(groupindex
++, &grp
);
3598 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)CString(MAKEINTRESOURCE(IDS_STATUSLIST_GROUP_IGNORELOCALCHANGES
)), 1023);
3599 grp
.pszHeader
= groupname
;
3600 grp
.iGroupId
= groupindex
;
3601 grp
.uAlign
= LVGA_HEADER_LEFT
;
3602 InsertGroup(groupindex
++, &grp
);
3608 m_bHasIgnoreGroup
= false;
3610 // now add the items which don't belong to a group
3612 grp
.cbSize
= sizeof(LVGROUP
);
3613 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3614 CString
sUnassignedName(MAKEINTRESOURCE(IDS_STATUSLIST_UNASSIGNED_CHANGESET
));
3615 _tcsncpy_s(groupname
, 1024, (LPCTSTR
)sUnassignedName
, 1023);
3616 grp
.pszHeader
= groupname
;
3617 grp
.iGroupId
= groupindex
;
3618 grp
.uAlign
= LVGA_HEADER_LEFT
;
3619 InsertGroup(groupindex
++, &grp
);
3621 for (auto it
= m_changelists
.cbegin(); it
!= m_changelists
.cend(); ++it
)
3623 if (it
->first
.Compare(SVNSLC_IGNORECHANGELIST
)!=0)
3626 grp
.cbSize
= sizeof(LVGROUP
);
3627 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3628 _tcsncpy_s(groupname
, 1024, it
->first
, 1023);
3629 grp
.pszHeader
= groupname
;
3630 grp
.iGroupId
= groupindex
;
3631 grp
.uAlign
= LVGA_HEADER_LEFT
;
3632 it
->second
= InsertGroup(groupindex
++, &grp
);
3635 m_bHasIgnoreGroup
= true;
3638 if (m_bHasIgnoreGroup
)
3640 // and now add the group 'ignore-on-commit'
3641 std::map
<CString
,int>::iterator it
= m_changelists
.find(SVNSLC_IGNORECHANGELIST
);
3642 if (it
!= m_changelists
.end())
3644 grp
.cbSize
= sizeof(LVGROUP
);
3645 grp
.mask
= LVGF_ALIGN
| LVGF_GROUPID
| LVGF_HEADER
;
3646 _tcsncpy_s(groupname
, 1024, SVNSLC_IGNORECHANGELIST
, 1023);
3647 grp
.pszHeader
= groupname
;
3648 grp
.iGroupId
= groupindex
;
3649 grp
.uAlign
= LVGA_HEADER_LEFT
;
3650 it
->second
= InsertGroup(groupindex
, &grp
);
3657 void CGitStatusListCtrl::NotifyCheck()
3659 CWnd
* pParent
= GetLogicalParent();
3660 if (pParent
&& pParent
->GetSafeHwnd())
3662 pParent
->SendMessage(GITSLNM_CHECKCHANGED
, m_nSelected
);
3666 int CGitStatusListCtrl::UpdateFileList(CTGitPathList
*list
)
3668 m_CurrentVersion
= GIT_REV_ZERO
;
3670 g_Git
.GetWorkingTreeChanges(m_StatusFileList
, m_amend
, list
);
3672 BOOL bDeleteChecked
= FALSE
;
3673 int deleteFromIndex
= 0;
3674 bool needsRefresh
= false;
3675 for (int i
= 0; i
< m_StatusFileList
.GetCount(); ++i
)
3677 CTGitPath
* gitpatch
=(CTGitPath
*)&m_StatusFileList
[i
];
3678 gitpatch
->m_Checked
= TRUE
;
3680 if ((gitpatch
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_REPLACED
| CTGitPath::LOGACTIONS_MODIFIED
)) && !gitpatch
->Exists())
3682 if (!bDeleteChecked
)
3685 message
.Format(IDS_ASK_REMOVE_FROM_INDEX
, gitpatch
->GetWinPath());
3686 deleteFromIndex
= CMessageBox::ShowCheck(GetSafeHwnd(), message
, _T("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
);
3688 if (deleteFromIndex
== 1)
3691 if (g_Git
.Run(_T("git.exe checkout -- \"") + gitpatch
->GetWinPathString() + _T("\""), &err
, CP_UTF8
))
3692 MessageBox(_T("Restoring from index failed:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
3694 needsRefresh
= true;
3696 else if (deleteFromIndex
== 2)
3699 if (g_Git
.Run(_T("git.exe rm -f --cache -- \"") + gitpatch
->GetWinPathString() + _T("\""), &err
, CP_UTF8
))
3700 MessageBox(_T("Removing from index failed:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
3702 needsRefresh
= true;
3706 m_arStatusArray
.push_back((CTGitPath
*)&m_StatusFileList
[i
]);
3710 MessageBox(_T("Due to changes to the index, please refresh the dialog (e.g., by pressing F5)."), _T("TortoiseGit"), MB_ICONINFORMATION
);
3715 int CGitStatusListCtrl::UpdateWithGitPathList(CTGitPathList
&list
)
3717 m_arStatusArray
.clear();
3718 for (int i
= 0; i
< list
.GetCount(); ++i
)
3720 CTGitPath
* gitpath
=(CTGitPath
*)&list
[i
];
3722 if(gitpath
->m_Action
& CTGitPath::LOGACTIONS_HIDE
)
3725 gitpath
->m_Checked
= TRUE
;
3726 m_arStatusArray
.push_back((CTGitPath
*)&list
[i
]);
3731 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
&list
)
3733 m_UnRevFileList
= list
;
3734 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3736 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3737 gitpatch
->m_Checked
= FALSE
;
3738 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3743 int CGitStatusListCtrl::UpdateUnRevFileList(CTGitPathList
*List
)
3746 if (m_UnRevFileList
.FillUnRev(CTGitPath::LOGACTIONS_UNVER
, List
, &err
))
3748 CMessageBox::Show(GetSafeHwnd(), _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3752 for (int i
= 0; i
< m_UnRevFileList
.GetCount(); ++i
)
3754 CTGitPath
* gitpatch
=(CTGitPath
*)&m_UnRevFileList
[i
];
3755 gitpatch
->m_Checked
= FALSE
;
3756 m_arStatusArray
.push_back((CTGitPath
*)&m_UnRevFileList
[i
]);
3761 int CGitStatusListCtrl::UpdateIgnoreFileList(CTGitPathList
*List
)
3764 if (m_IgnoreFileList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, List
, &err
))
3766 CMessageBox::Show(GetSafeHwnd(), _T("Failed to get Ignore file list\n") + err
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3770 for (int i
= 0; i
< m_IgnoreFileList
.GetCount(); ++i
)
3772 CTGitPath
* gitpatch
=(CTGitPath
*)&m_IgnoreFileList
[i
];
3773 gitpatch
->m_Checked
= FALSE
;
3774 m_arStatusArray
.push_back((CTGitPath
*)&m_IgnoreFileList
[i
]);
3779 int CGitStatusListCtrl::UpdateLocalChangesIgnoredFileList(CTGitPathList
*list
)
3781 m_LocalChangesIgnoredFileList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, GIT_IDXENTRY_SKIP_WORKTREE
, list
);
3782 for (int i
= 0; i
< m_LocalChangesIgnoredFileList
.GetCount(); ++i
)
3784 CTGitPath
* gitpatch
= (CTGitPath
*)&m_LocalChangesIgnoredFileList
[i
];
3785 gitpatch
->m_Checked
= FALSE
;
3786 m_arStatusArray
.push_back((CTGitPath
*)&m_LocalChangesIgnoredFileList
[i
]);
3791 int CGitStatusListCtrl::UpdateFileList(int mask
,bool once
,CTGitPathList
*List
)
3793 if(mask
&CGitStatusListCtrl::FILELIST_MODIFY
)
3795 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_MODIFY
)))
3797 UpdateFileList(List
);
3798 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_MODIFY
;
3801 if (mask
& CGitStatusListCtrl::FILELIST_UNVER
|| mask
& CGitStatusListCtrl::FILELIST_IGNORE
)
3803 if(once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_UNVER
)))
3805 UpdateUnRevFileList(List
);
3806 m_FileLoaded
|=CGitStatusListCtrl::FILELIST_UNVER
;
3808 if(mask
&CGitStatusListCtrl::FILELIST_IGNORE
&& (once
|| (!(m_FileLoaded
&CGitStatusListCtrl::FILELIST_IGNORE
))))
3810 UpdateIgnoreFileList(List
);
3811 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_IGNORE
;
3814 if (mask
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
&& (once
|| (!(m_FileLoaded
& CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
))))
3816 UpdateLocalChangesIgnoredFileList(List
);
3817 m_FileLoaded
|= CGitStatusListCtrl::FILELIST_LOCALCHANGESIGNORED
;
3822 void CGitStatusListCtrl::Clear()
3825 this->DeleteAllItems();
3826 this->m_arListArray
.clear();
3827 this->m_arStatusArray
.clear();
3828 this->m_changelists
.clear();
3831 bool CGitStatusListCtrl::CheckMultipleDiffs()
3833 UINT selCount
= GetSelectedCount();
3834 if (selCount
> max(3, (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\NumDiffWarning"), 10)))
3837 message
.Format(IDS_STATUSLIST_WARN_MAXDIFF
, selCount
);
3838 return ::MessageBox(GetSafeHwnd(), message
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
;
3843 //////////////////////////////////////////////////////////////////////////
3845 bool CGitStatusListCtrlDropTarget::OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
)
3847 if(pFmtEtc
->cfFormat
== CF_HDROP
&& medium
.tymed
== TYMED_HGLOBAL
)
3849 HDROP hDrop
= (HDROP
)GlobalLock(medium
.hGlobal
);
3852 TCHAR szFileName
[MAX_PATH
] = {0};
3854 UINT cFiles
= DragQueryFile(hDrop
, 0xFFFFFFFF, nullptr, 0);
3857 clientpoint
.x
= pt
.x
;
3858 clientpoint
.y
= pt
.y
;
3859 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3860 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3862 CTSVNPathList changelistItems
;
3863 for(UINT i
= 0; i
< cFiles
; ++i
)
3865 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
3866 changelistItems
.AddPath(CTSVNPath(szFileName
));
3868 // find the changelist name
3869 CString sChangelist
;
3870 LONG_PTR nGroup
= m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
);
3871 for (std::map
<CString
, int>::iterator it
= m_pSVNStatusListCtrl
->m_changelists
.begin(); it
!= m_pSVNStatusListCtrl
->m_changelists
.end(); ++it
)
3872 if (it
->second
== nGroup
)
3873 sChangelist
= it
->first
;
3874 if (!sChangelist
.IsEmpty())
3877 if (git
.AddToChangeList(changelistItems
, sChangelist
, git_depth_empty
))
3879 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3881 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
3884 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
3887 e
->changelist
= sChangelist
;
3890 if (m_pSVNStatusListCtrl
->m_changelists
.find(e
->changelist
)!=m_pSVNStatusListCtrl
->m_changelists
.end())
3891 m_pSVNStatusListCtrl
->SetItemGroup(index
, m_pSVNStatusListCtrl
->m_changelists
[e
->changelist
]);
3893 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
3899 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3901 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
3906 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3911 if (git
.RemoveFromChangeList(changelistItems
, CStringArray(), git_depth_empty
))
3913 for (int l
=0; l
<changelistItems
.GetCount(); ++l
)
3915 int index
= m_pSVNStatusListCtrl
->GetIndex(changelistItems
[l
]);
3918 CSVNStatusListCtrl::FileEntry
* e
= m_pSVNStatusListCtrl
->GetListEntry(index
);
3921 e
->changelist
= sChangelist
;
3922 m_pSVNStatusListCtrl
->SetItemGroup(index
, 0);
3927 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3929 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)changelistItems
[l
].GetWinPath());
3934 CMessageBox::Show(m_pSVNStatusListCtrl
->m_hWnd
, git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
3939 for(UINT i
= 0; i
< cFiles
; ++i
)
3941 DragQueryFile(hDrop
, i
, szFileName
, sizeof(szFileName
));
3942 HWND hParentWnd
= GetParent(m_hTargetWnd
);
3944 ::SendMessage(hParentWnd
, CSVNStatusListCtrl::SVNSLNM_ADDFILE
, 0, (LPARAM
)szFileName
);
3948 GlobalUnlock(medium
.hGlobal
);
3950 return true; //let base free the medium
3953 HRESULT STDMETHODCALLTYPE
CSVNStatusListCtrlDropTarget::DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
)
3955 CIDropTarget::DragOver(grfKeyState
, pt
, pdwEffect
);
3956 *pdwEffect
= DROPEFFECT_COPY
;
3957 if (m_pSVNStatusListCtrl
)
3960 clientpoint
.x
= pt
.x
;
3961 clientpoint
.y
= pt
.y
;
3962 ScreenToClient(m_hTargetWnd
, &clientpoint
);
3963 if ((m_pSVNStatusListCtrl
->IsGroupViewEnabled())&&(m_pSVNStatusListCtrl
->GetGroupFromPoint(&clientpoint
) >= 0))
3964 *pdwEffect
= DROPEFFECT_MOVE
;
3965 else if ((!m_pSVNStatusListCtrl
->m_bFileDropsEnabled
)||(m_pSVNStatusListCtrl
->m_bOwnDrag
))
3966 *pdwEffect
= DROPEFFECT_NONE
;
3973 void CGitStatusListCtrl::FilesExport()
3976 // export all changed files to a folder
3977 CBrowseFolder browseFolder
;
3978 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
3979 if (browseFolder
.Show(GetSafeHwnd(), exportDir
) != CBrowseFolder::OK
)
3982 POSITION pos
= GetFirstSelectedItemPosition();
3984 while ((index
= GetNextSelectedItem(pos
)) >= 0)
3986 CTGitPath
*fd
= (CTGitPath
*)GetItemData(index
);
3987 // we cannot export directories or folders
3988 if ((fd
->m_Action
& CTGitPath::LOGACTIONS_DELETED
) || fd
->IsDirectory())
3991 CPathUtils::MakeSureDirectoryPathExists(exportDir
+ _T("\\") + fd
->GetContainingDirectory().GetWinPathString());
3992 CString filename
= exportDir
+ _T("\\") + fd
->GetWinPathString();
3993 if (m_CurrentVersion
== GIT_REV_ZERO
)
3995 if (!CopyFile(g_Git
.CombinePath(fd
), filename
, false))
3997 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4003 if (g_Git
.GetOneFile(m_CurrentVersion
, *fd
, filename
))
4006 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)fd
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)filename
);
4007 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)
4014 void CGitStatusListCtrl::FileSaveAs(CTGitPath
*path
)
4017 filename
.Format(_T("%s-%s%s"), (LPCTSTR
)path
->GetBaseFilename(), (LPCTSTR
)this->m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()), (LPCTSTR
)path
->GetFileExtension());
4018 CFileDialog
dlg(FALSE
, nullptr, filename
, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
, nullptr);
4020 CString currentpath
= g_Git
.CombinePath(path
->GetContainingDirectory());
4021 dlg
.m_ofn
.lpstrInitialDir
= currentpath
;
4024 INT_PTR ret
= dlg
.DoModal();
4025 SetCurrentDirectory(g_Git
.m_CurrentDir
);
4028 filename
= dlg
.GetPathName();
4029 if(m_CurrentVersion
== GIT_REV_ZERO
)
4031 if(!CopyFile(g_Git
.CombinePath(path
), filename
, false))
4033 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
4039 if(g_Git
.GetOneFile(m_CurrentVersion
,*path
,filename
))
4041 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)path
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)filename
);
4042 CMessageBox::Show(GetSafeHwnd(), g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), L
"TortoiseGit", MB_OK
);
4049 int CGitStatusListCtrl::RevertSelectedItemToVersion(bool parent
)
4051 if(this->m_CurrentVersion
.IsEmpty())
4053 if(this->m_CurrentVersion
== GIT_REV_ZERO
)
4056 POSITION pos
= GetFirstSelectedItemPosition();
4059 std::map
<CString
, int> versionMap
;
4060 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4062 CTGitPath
*fentry
=(CTGitPath
*)GetItemData(index
);
4066 int parentNo
= fentry
->m_ParentNo
& PARENT_MASK
;
4068 ref
.Format(_T("%s^%d"), (LPCTSTR
)m_CurrentVersion
, parentNo
+ 1);
4070 if (g_Git
.GetHash(hash
, ref
))
4072 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + ref
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
4076 version
= hash
.ToString();
4079 version
= m_CurrentVersion
;
4081 CString filename
= fentry
->GetGitPathString();
4082 if (!fentry
->GetGitOldPathString().IsEmpty())
4083 filename
= fentry
->GetGitOldPathString();
4084 cmd
.Format(_T("git.exe checkout %s -- \"%s\""), (LPCTSTR
)version
, (LPCTSTR
)filename
);
4086 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
4088 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)
4092 versionMap
[version
]++;
4096 for (auto it
= versionMap
.cbegin(); it
!= versionMap
.cend(); ++it
)
4098 CString versionEntry
;
4099 versionEntry
.Format(IDS_STATUSLIST_FILESREVERTED
, it
->second
, (LPCTSTR
)it
->first
);
4100 out
+= versionEntry
+ _T("\r\n");
4103 CMessageBox::Show(GetSafeHwnd(), out
, L
"TortoiseGit", MB_OK
);
4107 void CGitStatusListCtrl::OpenFile(CTGitPath
*filepath
,int mode
)
4110 if(this->m_CurrentVersion
.IsEmpty() || m_CurrentVersion
== GIT_REV_ZERO
)
4111 file
= g_Git
.CombinePath(filepath
);
4115 GetTempPath(temppath
);
4116 TCHAR szTempName
[MAX_PATH
] = {0};
4117 GetTempFileName(temppath
, filepath
->GetBaseFilename(), 0, szTempName
);
4118 CString
temp(szTempName
);
4119 DeleteFile(szTempName
);
4120 CreateDirectory(szTempName
, nullptr);
4121 file
.Format(_T("%s\\%s_%s%s"),
4123 (LPCTSTR
)filepath
->GetBaseFilename(),
4124 (LPCTSTR
)m_CurrentVersion
.Left(g_Git
.GetShortHASHLength()),
4125 (LPCTSTR
)filepath
->GetFileExtension());
4127 if(g_Git
.GetOneFile(m_CurrentVersion
, *filepath
, file
))
4129 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, (LPCTSTR
)filepath
->GetGitPathString(), (LPCTSTR
)m_CurrentVersion
, (LPCTSTR
)file
);
4130 CMessageBox::Show(GetSafeHwnd(), g_Git
.GetGitLastErr(out
, CGit::GIT_CMD_GETONEFILE
), L
"TortoiseGit", MB_OK
);
4133 SetFileAttributes(file
, FILE_ATTRIBUTE_READONLY
);
4135 if(mode
== ALTERNATIVEEDITOR
)
4137 CAppUtils::LaunchAlternativeEditor(file
);
4142 CAppUtils::ShellOpen(file
, GetSafeHwnd());
4144 CAppUtils::ShowOpenWithDialog(file
, GetSafeHwnd());
4147 void CGitStatusListCtrl::DeleteSelectedFiles()
4150 std::vector
<int> selectIndex
;
4152 POSITION pos
= GetFirstSelectedItemPosition();
4154 while ((index
= GetNextSelectedItem(pos
)) >= 0)
4155 selectIndex
.push_back(index
);
4157 CAutoRepository repo
= g_Git
.GetGitRepository();
4160 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
);
4163 CAutoIndex gitIndex
;
4164 if (git_repository_index(gitIndex
.GetPointer(), repo
))
4166 g_Git
.GetLibGit2LastErr(_T("Could not open index."));
4169 int needWriteIndex
= 0;
4171 //Create file-list ('\0' separated) for SHFileOperation
4173 for (size_t i
= 0; i
< selectIndex
.size(); ++i
)
4175 index
= selectIndex
[i
];
4177 CTGitPath
* path
=(CTGitPath
*)GetItemData(index
);
4179 if (path
== nullptr)
4182 // do not report errors as we could remove an unversioned file
4183 needWriteIndex
+= git_index_remove_bypath(gitIndex
, CUnicodeUtils::GetUTF8(path
->GetGitPathString())) == 0 ? 1 : 0;
4185 if (!path
->Exists())
4188 filelist
+= path
->GetWinPathString();
4189 filelist
+= _T("|");
4191 filelist
+= _T("|");
4192 int len
= filelist
.GetLength();
4193 auto buf
= std::make_unique
<TCHAR
[]>(len
+ 2);
4194 _tcscpy_s(buf
.get(), len
+ 2, filelist
);
4195 CStringUtils::PipesToNulls(buf
.get(), len
+ 2);
4196 SHFILEOPSTRUCT fileop
;
4197 fileop
.hwnd
= this->m_hWnd
;
4198 fileop
.wFunc
= FO_DELETE
;
4199 fileop
.pFrom
= buf
.get();
4200 fileop
.pTo
= nullptr;
4201 fileop
.fFlags
= FOF_NO_CONNECTED_ELEMENTS
| ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) ? 0 : FOF_ALLOWUNDO
);
4202 fileop
.lpszProgressTitle
= _T("deleting file");
4203 int result
= SHFileOperation(&fileop
);
4205 if ((result
== 0 || len
== 1) && (!fileop
.fAnyOperationsAborted
))
4207 if (needWriteIndex
&& git_index_write(gitIndex
))
4208 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not write index.")), _T("TortoiseGit"), MB_OK
);
4212 CWnd
* pParent
= GetLogicalParent();
4213 if (pParent
&& pParent
->GetSafeHwnd())
4214 pParent
->SendMessage(GITSLNM_NEEDSREFRESH
);
4220 POSITION pos2
= nullptr;
4221 while ((pos2
= GetFirstSelectedItemPosition()) != nullptr)
4223 int index2
= GetNextSelectedItem(pos2
);
4224 if (GetCheck(index2
))
4228 RemoveListEntry(index2
);
4234 BOOL
CGitStatusListCtrl::OnWndMsg(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
)
4238 case WM_MENUCHAR
: // only supported by IContextMenu3
4241 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4247 case WM_MEASUREITEM
:
4249 break; // if wParam != 0 then the message is not menu-related
4252 case WM_INITMENUPOPUP
:
4254 HMENU hMenu
= (HMENU
)wParam
;
4255 if ((hMenu
== m_hShellMenu
) && (GetMenuItemCount(hMenu
) == 0))
4257 // the shell submenu is populated only on request, i.e. right
4258 // before the submenu is shown
4261 delete g_pFolderhook
;
4262 g_pFolderhook
= nullptr;
4264 CTGitPathList targetList
;
4265 FillListOfSelectedItemPaths(targetList
);
4266 if (!targetList
.IsEmpty())
4268 // get IShellFolder interface of Desktop (root of shell namespace)
4269 if (g_psfDesktopFolder
)
4270 g_psfDesktopFolder
->Release();
4271 SHGetDesktopFolder(&g_psfDesktopFolder
); // needed to obtain full qualified pidl
4273 // ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
4274 // but since we use the Desktop as our interface and the Desktop is the namespace root
4275 // that means that it's a fully qualified PIDL, which is what we need
4279 for (int i
= 0; i
< g_pidlArrayItems
; i
++)
4282 CoTaskMemFree(g_pidlArray
[i
]);
4284 CoTaskMemFree(g_pidlArray
);
4285 g_pidlArray
= nullptr;
4286 g_pidlArrayItems
= 0;
4288 int nItems
= targetList
.GetCount();
4289 g_pidlArray
= (LPITEMIDLIST
*)CoTaskMemAlloc((nItems
+ 10) * sizeof(LPITEMIDLIST
));
4290 SecureZeroMemory(g_pidlArray
, (nItems
+ 10) * sizeof(LPITEMIDLIST
));
4291 int succeededItems
= 0;
4292 PIDLIST_RELATIVE pidl
= nullptr;
4295 auto filepath
= std::make_unique
<WCHAR
[]>(bufsize
);
4296 for (int i
= 0; i
< nItems
; i
++)
4298 CString fullPath
= g_Git
.CombinePath(targetList
[i
].GetWinPath());
4299 if (bufsize
< fullPath
.GetLength())
4301 bufsize
= fullPath
.GetLength() + 3;
4302 filepath
= std::make_unique
<WCHAR
[]>(bufsize
);
4304 wcscpy_s(filepath
.get(), bufsize
, fullPath
);
4305 if (SUCCEEDED(g_psfDesktopFolder
->ParseDisplayName(nullptr, 0, filepath
.get(), nullptr, &pidl
, nullptr)))
4306 g_pidlArray
[succeededItems
++] = pidl
; // copy pidl to pidlArray
4308 if (succeededItems
== 0)
4310 CoTaskMemFree(g_pidlArray
);
4311 g_pidlArray
= nullptr;
4314 g_pidlArrayItems
= succeededItems
;
4316 if (g_pidlArrayItems
)
4318 CString ext
= targetList
[0].GetFileExtension();
4320 ASSOCIATIONELEMENT
const rgAssocItem
[] =
4322 { ASSOCCLASS_PROGID_STR
, nullptr, ext
},
4323 { ASSOCCLASS_SYSTEM_STR
, nullptr, ext
},
4324 { ASSOCCLASS_APP_STR
, nullptr, ext
},
4325 { ASSOCCLASS_STAR
, nullptr, nullptr },
4326 { ASSOCCLASS_FOLDER
, nullptr, nullptr },
4328 IQueryAssociations
* pIQueryAssociations
= nullptr;
4329 if (FAILED(AssocCreateForClasses(rgAssocItem
, ARRAYSIZE(rgAssocItem
), IID_IQueryAssociations
, (void**)&pIQueryAssociations
)))
4330 pIQueryAssociations
= nullptr; // not a problem, it works without this
4332 g_pFolderhook
= new CIShellFolderHook(g_psfDesktopFolder
, targetList
);
4333 LPCONTEXTMENU icm1
= nullptr;
4335 DEFCONTEXTMENU dcm
= { 0 };
4337 dcm
.psf
= g_pFolderhook
;
4338 dcm
.cidl
= g_pidlArrayItems
;
4339 dcm
.apidl
= (PCUITEMID_CHILD_ARRAY
)g_pidlArray
;
4340 dcm
.punkAssociationInfo
= pIQueryAssociations
;
4341 if (SUCCEEDED(SHCreateDefaultContextMenu(&dcm
, IID_IContextMenu
, (void**)&icm1
)))
4343 int iMenuType
= 0; // to know which version of IContextMenu is supported
4345 { // since we got an IContextMenu interface we can now obtain the higher version interfaces via that
4346 if (icm1
->QueryInterface(IID_IContextMenu3
, (void**)&m_pContextMenu
) == S_OK
)
4348 else if (icm1
->QueryInterface(IID_IContextMenu2
, (void**)&m_pContextMenu
) == S_OK
)
4352 icm1
->Release(); // we can now release version 1 interface, cause we got a higher one
4355 // since no higher versions were found
4356 // redirect ppContextMenu to version 1 interface
4358 m_pContextMenu
= icm1
;
4363 // lets fill the our popup menu
4364 UINT flags
= CMF_NORMAL
;
4365 flags
|= (GetKeyState(VK_SHIFT
) & 0x8000) != 0 ? CMF_EXTENDEDVERBS
: 0;
4366 m_pContextMenu
->QueryContextMenu(hMenu
, 0, SHELL_MIN_CMD
, SHELL_MAX_CMD
, flags
);
4369 // subclass window to handle menu related messages in CShellContextMenu
4370 if (iMenuType
> 1) // only subclass if its version 2 or 3
4373 g_IContext2
= (LPCONTEXTMENU2
)m_pContextMenu
;
4375 g_IContext3
= (LPCONTEXTMENU3
)m_pContextMenu
;
4379 if (pIQueryAssociations
)
4380 pIQueryAssociations
->Release();
4384 g_IContext3
->HandleMenuMsg2(message
, wParam
, lParam
, pResult
);
4385 else if (g_IContext2
)
4386 g_IContext2
->HandleMenuMsg(message
, wParam
, lParam
);
4396 return __super::OnWndMsg(message
, wParam
, lParam
, pResult
);