1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - 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.
22 #include "GitStatus.h"
25 #include "LoglistCommonResource.h"
27 #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)
29 // these defines must be in the order the columns are inserted!
30 #define GITSLC_COLFILENAME 0x000000002
31 #define GITSLC_COLEXT 0x000000004
32 #define GITSLC_COLSTATUS 0x000000008
33 //#define SVNSLC_COLAUTHOR 0x000000040
34 //#define SVNSLC_COLREVISION 0x000000080
35 //#define SVNSLC_COLDATE 0x000000100
36 #define GITSLC_COLADD 0x000000010
37 #define GITSLC_COLDEL 0x000000020
38 #define GITSLC_COLMODIFICATIONDATE 0x000000040
39 #define GITSLC_COLSIZE 0x000000080
40 #define GITSLC_NUMCOLUMNS 8
42 //#define SVNSLC_COLURL 0x000000200
43 //#define SVNSLC_COLCOPYFROM 0x000020000
45 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
46 #define GITSLC_SHOWNORMAL 0x00000000
47 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
48 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
49 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
50 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
51 #define GITSLC_SHOWMISSING 0x00000000
52 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
53 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
54 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
55 #define GITSLC_SHOWOBSTRUCTED 0x00000000
56 #define GITSLC_SHOWEXTERNAL 0x00000000
57 #define GITSLC_SHOWINCOMPLETE 0x00000000
58 #define GITSLC_SHOWINEXTERNALS 0x00000000
59 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
60 #define GITSLC_SHOWLOCKS 0x00000000
61 #define GITSLC_SHOWDIRECTFILES 0x04000000
62 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
63 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
64 #define GITSLC_SHOWSWITCHED 0x00000000
65 #define GITSLC_SHOWINCHANGELIST 0x00000000
66 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
67 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
69 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
71 #define GITSLC_SHOWFILES 0x01000000
72 #define GITSLC_SHOWSUBMODULES 0x02000000
73 #define GITSLC_SHOWEVERYTHING 0xffffffff
75 #define GITSLC_SHOWVERSIONED (GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
76 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
77 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
78 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
79 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
81 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
82 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
83 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
84 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
85 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
87 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
88 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
89 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
90 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
92 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
93 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
94 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
95 GITSLC_SHOWINCOMPLETE)
97 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
99 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
100 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
101 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
102 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
103 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
104 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
105 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
106 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
107 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
108 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
109 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
110 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
111 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
112 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
113 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
114 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
115 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
116 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
117 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
118 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOFILES)
119 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
120 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
121 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
122 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
123 #define GITLC_POPUNSETIGNORELOCALCHANGES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNSETIGNORELOCALCHANGES)
124 #define GITSLC_PREPAREDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_PREPAREDIFF)
126 #define GITSLC_IGNORECHANGELIST _T("ignore-on-commit")
128 // This gives up to 64 standard properties and menu entries
129 #define GITSLC_MAXCOLUMNCOUNT 0xff
131 #define OVL_RESTORE 1
133 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
134 typedef CComCritSecLock
<CComCriticalSection
> Locker
;
136 class CGitStatusListCtrlDropTarget
;
139 * \ingroup TortoiseProc
140 * Helper class for CGitStatusListCtrl that represents
141 * the columns visible and their order as well as
142 * persisting that data in the registry.
144 * It assigns logical index values to the (potential) columns:
145 * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes
147 * The column vector contains the columns that are actually
148 * available in the control.
155 /// construction / destruction
157 ColumnManager (CListCtrl
* control
) : control (control
), m_dwDefaultColumns(0) {};
162 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int* withlist
= nullptr);
163 void WriteSettings() const;
165 /// read column definitions
167 int GetColumnCount() const; ///< total number of columns
168 bool IsVisible (int column
) const;
169 int GetInvisibleCount() const;
170 bool IsRelevant (int column
) const;
171 CString
GetName (int column
) const;
172 int SetNames(UINT
* buff
, int size
);
173 int GetWidth (int column
, bool useDefaults
= false) const;
174 int GetVisibleWidth (int column
, bool useDefaults
) const;
175 void SetRightAlign(int column
) const;
177 /// switch columns on and off
179 void SetVisible (int column
, bool visible
);
181 /// tracking column modifications
183 void ColumnMoved (int column
, int position
);
185 manual: 0: automatic updates, 1: manual updates, 2: manual updates and set to optimal width, 3: reset manual adjusted state
187 void ColumnResized(int column
, int manual
= 0);
189 /// call these to update the user-prop list
190 /// (will also auto-insert /-remove new list columns)
192 /// don't clutter the context menu with irrelevant prop info
194 void RemoveUnusedProps();
196 /// bring everything back to its "natural" order
198 void ResetColumns (DWORD defaultColumns
);
200 void OnHeaderDblClick(NMHDR
* pNMHDR
, LRESULT
* pResult
)
202 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
204 && (header
->iItem
>= 0)
205 && (header
->iItem
< GetColumnCount()))
207 bool bShift
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
208 ColumnResized(header
->iItem
, bShift
? 3: 2);
213 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
215 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
217 && (header
->iItem
>= 0)
218 && (header
->iItem
< GetColumnCount()))
220 ColumnResized (header
->iItem
, 1);
225 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
227 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
230 && (header
->iItem
>= 0)
231 && (header
->iItem
< GetColumnCount())
232 // only allow the reordering if the column was not moved left of the first
233 // visible item - otherwise the 'invisible' columns are not at the far left
234 // anymore and we get all kinds of redrawing problems.
236 && (header
->pitem
->iOrder
>= GetInvisibleCount()))
238 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
242 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
244 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
246 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
249 if (IsVisible (phdr
->iItem
))
254 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
256 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
258 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
261 // visible columns may be modified
263 if (IsVisible (phdr
->iItem
))
266 // columns already marked as "invisible" internally may be (re-)sized to 0
269 && (phdr
->pitem
->mask
== HDI_WIDTH
)
270 && (phdr
->pitem
->cxy
== 0))
276 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
284 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
286 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
287 if ((point
.x
== -1) && (point
.y
== -1))
290 pHeaderCtrl
->GetItemRect(0, &rect
);
291 pHeaderCtrl
->ClientToScreen(&rect
);
292 point
= rect
.CenterPoint();
296 if (popup
.CreatePopupMenu())
298 int columnCount
= GetColumnCount();
301 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
302 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
304 // build control menu
306 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
307 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
309 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
310 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
311 popup
.AppendMenu(MF_SEPARATOR
);
316 // user-prop columns:
317 // find relevant ones and sort 'em
319 std::map
<CString
, int> sortedProps
;
320 for (int i
= (int)itemName
.size(); i
< columnCount
; ++i
)
322 sortedProps
[GetName(i
)] = i
;
324 if (!sortedProps
.empty())
326 // add 'em to the menu
328 popup
.AppendMenu(MF_SEPARATOR
);
330 for (auto iter
= sortedProps
.cbegin(), end
= sortedProps
.cend()
334 popup
.AppendMenu ( IsVisible(iter
->second
)
342 // show menu & let user pick an entry
344 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
345 if ((cmd
>= 1)&&(cmd
< columnCount
))
346 SetVisible (cmd
, !IsVisible(cmd
));
347 else if (cmd
== columnCount
)
349 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
350 //EnableGroupView(!isGroundEnable);
352 else if (cmd
== columnCount
+1)
354 else if (cmd
== columnCount
+2)
356 temp
.LoadString(IDS_CONFIRMRESETCOLUMNORDER
);
357 if (MessageBox(pWnd
->m_hWnd
, temp
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
358 ResetColumns (m_dwDefaultColumns
);
364 void AddMenuItem(CMenu
*pop
)
366 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
367 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
369 for (int i
= 1; i
< (int)itemName
.size(); ++i
)
372 pop
->AppendMenu ( IsVisible(i
)
380 DWORD m_dwDefaultColumns
;
382 /// initialization utilities
384 void ParseWidths (const CString
& widths
);
385 void SetStandardColumnVisibility (DWORD visibility
);
386 void ParseColumnOrder (const CString
& widths
);
388 /// map internal column order onto visible column order
389 /// (all invisibles in front)
391 std::vector
<int> GetGridColumnOrder() const;
392 void ApplyColumnOrder();
394 /// utilities used when writing data to the registry
396 DWORD
GetSelectedStandardColumns() const;
397 CString
GetWidthString() const;
398 CString
GetColumnOrderString() const;
400 /// our parent control and its data
404 /// where to store in the registry
406 CString registryPrefix
;
408 /// all columns in their "natural" order
412 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
415 bool relevant
; ///< set to @a visible, if no *shown* item has that property
419 std::vector
<ColumnInfo
> columns
;
421 /// user-defined properties
423 std::set
<CString
> itemProps
;
425 /// global column ordering including unused user props
427 std::vector
<int> columnOrder
;
429 std::vector
<int> itemName
;
433 * \ingroup TortoiseProc
434 * Simple utility class that defines the sort column order.
440 CSorter ( ColumnManager
* columnManager
444 bool operator() ( const CTGitPath
* entry1
445 , const CTGitPath
* entry2
) const;
447 static int A2L(const CString
&str
)
457 ColumnManager
* columnManager
;
464 * A List control, based on the MFC CListCtrl which shows a list of
465 * files with their git status. The control also provides a context
466 * menu to do some git tasks on the selected files.
468 * This is the main control used in many dialogs to show a list of files to
471 class CGitStatusListCtrl
:
478 /** Compare with base version. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
483 /** Compare with base version and generate unified diff. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
487 IDGITLC_LOGSUBMODULE
,
488 IDGITLC_EDITCONFLICT
,
490 IDGITLC_IGNOREFOLDER
,
492 IDGITLC_RESOLVECONFLICT
,
495 IDGITLC_RESOLVETHEIRS
,
496 IDGITLC_RESOLVEMINE
,
501 IDGITLC_REMOVEFROMCS
,
503 IDGITLC_CREATEIGNORECS
,
505 IDGITLC_UNCHECKGROUP
,
506 /** Compare current version and working tree */
510 IDGITLC_REVERTTOREV
,
511 IDGITLC_REVERTTOPARENT
,
514 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
515 IDGITLC_COMPARETWOREVISIONS
,
516 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
517 IDGITLC_GNUDIFF2REVISIONS
,
518 /** Compare two selected files */
519 IDGITLC_COMPARETWOFILES
,
521 IDGITLC_CREATERESTORE
,
522 IDGITLC_RESTOREPATH
,
523 IDGITLC_ASSUMEVALID
,
524 IDGITLC_SKIPWORKTREE
,
526 IDGITLC_UNSETIGNORELOCALCHANGES
,
527 IDGITLC_PREPAREDIFF
,
528 IDGITLC_PREPAREDIFF_COMPARE
,
529 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
530 // the submenu items get command ID's sequent to this number
533 int GetColumnIndex(int colmask
);
534 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
536 * Sent to the parent window (using ::SendMessage) after a context menu
537 * command has finished if the item count has changed.
539 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
541 * Sent to the parent window (using ::SendMessage) when the control needs
542 * to be refreshed. Since this is done usually in the parent window using
543 * a thread, this message is used to tell the parent to do exactly that.
545 static const UINT GITSLNM_NEEDSREFRESH
;
548 * Sent to the parent window (using ::SendMessage) when the user drops
549 * files on the control. The LPARAM is a pointer to a TCHAR string
550 * containing the dropped path.
552 static const UINT GITSLNM_ADDFILE
;
555 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
556 * one or more items in the control. The WPARAM contains the number of
557 * checked items in the control.
559 static const UINT GITSLNM_CHECKCHANGED
;
561 static const UINT GITSLNM_ITEMCHANGED
;
563 CGitStatusListCtrl(void);
564 ~CGitStatusListCtrl(void);
570 * \ingroup TortoiseProc
571 * Helper class for CGitStatusListCtrl which represents
572 * the data for each file shown.
578 FileEntry() : status(git_wc_status_unversioned
)
579 // , copyfrom_rev(GIT_REV_ZERO)
580 , last_commit_date(0)
581 , last_commit_rev(GIT_REV_ZERO
)
582 // , remoterev(GIT_REV_ZERO)
583 , textstatus(git_wc_status_unversioned
)
584 , propstatus(git_wc_status_unversioned
)
585 // , remotestatus(git_wc_status_unversioned)
586 // , remotetextstatus(git_wc_status_unversioned)
587 // , remotepropstatus(git_wc_status_unversioned)
591 , inunversionedfolder(false)
593 , differentrepo(false)
597 , Revision(GIT_REV_ZERO
)
598 , isConflicted(false)
601 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
603 // , depth(git_depth_unknown)
606 const CTGitPath
& GetPath() const
610 const bool IsChecked() const
614 CString
GetRelativeGitPath() const
616 if (path
.IsEquivalentTo(basepath
))
617 return path
.GetGitPathString();
618 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
620 // const bool IsLocked() const
622 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
624 // const bool HasNeedsLock() const
628 const bool IsFolder() const
632 const bool IsInExternal() const
636 const bool IsNested() const
640 const bool IsFromDifferentRepository() const
642 return differentrepo
;
644 CString
GetDisplayName() const
646 CString
const& chopped
= path
.GetDisplayString(&basepath
);
647 if (!chopped
.IsEmpty())
653 // "Display name" must not be empty.
654 return path
.GetFileOrDirectoryName();
657 CString
GetChangeList() const
661 // CString GetURL() const
666 git_wc_status_kind status
; ///< local status
667 git_wc_status_kind textstatus
; ///< local text status
668 git_wc_status_kind propstatus
; ///< local property status
671 CTGitPath path
; ///< full path of the file
672 CTGitPath basepath
; ///< common ancestor path of all files
674 CString changelist
; ///< the name of the changelist the item belongs to
676 CString last_commit_author
; ///< the author which last committed this item
677 CTime last_commit_date
; ///< the date when this item was last committed
678 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
680 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
681 bool copied
; ///< if the file/folder is added-with-history
682 bool switched
; ///< if the file/folder is switched to another url
683 bool checked
; ///< if the file is checked in the list control
684 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
685 bool inexternal
; ///< if the item is in an external folder
686 bool differentrepo
; ///< if the item is from a different repository than the rest
687 bool direct
; ///< directly included (TRUE) or just a child of a folder
688 bool isfolder
; ///< TRUE if entry refers to a folder
689 bool isNested
; ///< TRUE if the folder from a different repository and/or path
690 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
691 bool needslock
; ///< TRUE if the Git:needs-lock property is set
692 git_revnum_t Revision
; ///< the base revision
693 // PropertyList present_props; ///< cacheable properties present in BASE
694 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
695 git_depth_t depth
; ///< the depth of this entry
696 friend class CGitStatusListCtrl
;
697 friend class CGitStatusListCtrlDropTarget
;
698 friend class CSorter
;
703 * Initializes the control, sets up the columns.
704 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
705 * \param sColumnInfoContainer Name of a registry key
706 * where the position and visibility of each column
707 * is saved and used from. If the registry key
708 * doesn't exist, the default order is used
709 * and dwColumns tells which columns are visible.
710 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
711 * Use the GitSLC_POPxxx defines.
712 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
713 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
715 void Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
= ((GITSLC_POPALL
^ GITSLC_POPCOMMIT
) ^ GITSLC_POPRESTORE
), bool bHasCheckboxes
= true, bool bHasWC
= true, DWORD allowedColumns
= 0xffffffff);
717 * Sets a background image for the list control.
718 * The image is shown in the right bottom corner.
719 * \param nID the resource ID of the bitmap to use as the background
721 bool SetBackgroundImage(UINT nID
);
723 * Makes the 'ignore' context menu only ignore the files and not add the
724 * folder which gets the Git:ignore property changed to the list.
725 * This is needed e.g. for the Add-dialog, where the modified folder
726 * showing up would break the resulting "add" command.
728 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
730 * The unversioned items are by default shown after all other files in the list.
731 * If that behavior should be changed, set this value to false.
733 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
735 * Fetches the git status of all files and stores the information
736 * about them in an internal array.
737 * \param sFilePath path to a file which contains a list of files and/or folders for which to
738 * fetch the status, separated by newlines.
739 * \param bUpdate TRUE if the remote status is requested too.
740 * \return TRUE on success.
742 BOOL
GetStatus (const CTGitPathList
* pathList
= nullptr
743 , bool bUpdate
= false
744 , bool bShowIgnores
= false
745 , bool bShowUnRev
= false
746 , bool bShowLocalChangesIgnored
= false);
749 * Populates the list control with the previously (with GetStatus) gathered status information.
750 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
751 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
753 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
754 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
757 * Copies the selected entries in the control to the clipboard. The entries
758 * are separated by newlines.
759 * \param dwCols the columns to copy. Each column is separated by a tab.
761 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
764 * If during the call to GetStatus() some Git:externals are found from different
765 * repositories than the first one checked, then this method returns TRUE.
767 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
770 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
772 BOOL
HasExternals() const {return m_bHasExternals
;}
775 * If unversioned files are found (but not necessarily shown) TRUE is returned.
777 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
780 * If there are any locks in the working copy, TRUE is returned
782 BOOL
HasLocks() const {return m_bHasLocks
;}
785 * If there are any change lists defined in the working copy, TRUE is returned
787 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
790 * Returns the file entry data for the list control index.
792 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
795 * Returns the file entry data for the specified path.
796 * \note The entry might not be shown in the list control.
798 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
801 * Returns the index of the list control entry with the specified path,
802 * or -1 if the path is not in the list control.
804 int GetIndex(const CTGitPath
& path
);
807 * Returns the file entry data for the specified path in the list control.
809 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
812 * Returns a String containing some statistics like number of modified, normal, deleted,...
815 CString
GetStatisticsString(bool simple
=false);
818 * Set a static control which will be updated automatically with
819 * the number of selected and total files shown in the list control.
821 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
824 * Set a tri-state checkbox which is updated automatically if the
825 * user checks/unchecks file entries in the list control to indicate
826 * if all files are checked, none are checked or some are checked.
828 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
831 * Set a button which is de-/activated automatically. The button is
832 * only set active if at least one item is selected.
834 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
837 * Select/unselect all entries in the list control.
838 * \param bSelect TRUE to check, FALSE to uncheck.
840 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
843 * Checks or unchecks all specified items
844 * \param dwCheck GITLC_SHOWxxx defines
845 * \param check if true matching items will be selected, false unchecks matching items
847 void Check(DWORD dwCheck
, bool check
= true);
849 /** Set a checkbox on an entry in the listbox
850 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
852 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
854 /** Write a list of the checked items' paths into a path list
856 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
858 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
859 * files/folders in the working copy.
860 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
861 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
863 * \remark Since an item can only be checked if it is visible/shown in the list control
864 * bShownOnly is automatically set to true if bCheckedOnly is true
866 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
869 * Returns the parent directory of all entries in the control.
870 * if \a bStrict is set to false, then the paths passed to the control
871 * to fetch the status (in GetStatus()) are used if possible.
873 CString
GetCommonDirectory(bool bStrict
);
876 * Returns the parent url of all entries in the control.
877 * if \a bStrict is set to false, then the paths passed to the control
878 * to fetch the status (in GetStatus()) are used if possible.
880 CTGitPath
GetCommonURL(bool bStrict
);
883 * Sets a pointer to a boolean variable which is checked periodically
884 * during the status fetching. As soon as the variable changes to true,
885 * the operations stops.
887 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
890 * Sets the string shown in the control while the status is fetched.
891 * If not set, it defaults to "please wait..."
893 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
894 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
897 * Sets the string shown in the control if no items are shown. This
898 * can happen for example if there's nothing modified and the unversioned
899 * files aren't shown either, so there's nothing to commit.
900 * If not set, it defaults to "file list is empty".
902 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
903 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
906 * Returns the number of selected items
908 LONG
GetSelected(){return m_nSelected
;};
911 * Enables dropping of files on the control.
913 bool EnableFileDrop();
916 * Checks if the path already exists in the list.
918 bool HasPath(const CTGitPath
& path
);
920 * Checks if the path is shown/visible in the list control.
922 bool IsPathShown(const CTGitPath
& path
);
924 * Forces the children to be checked when the parent folder is checked,
925 * and the parent folder to be unchecked if one of its children is unchecked.
927 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
930 * Allows checking the items if change lists are present. If set to false,
931 * items are not checked if at least one changelist is available.
933 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
935 * Returns the currently used show flags passed to the Show() method.
937 DWORD
GetShowFlags() {return m_dwShow
;}
940 CString
GetLastErrorMessage() {return m_sLastError
;}
942 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
944 LONG
GetUnversionedCount() { return m_nShownUnversioned
; }
945 LONG
GetModifiedCount() { return m_nShownModified
; }
946 LONG
GetAddedCount() { return m_nShownAdded
; }
947 LONG
GetDeletedCount() { return m_nShownDeleted
; }
948 LONG
GetConflictedCount() { return m_nShownConflicted
; }
949 LONG
GetFileCount() { return m_nShownFiles
; }
950 LONG
GetSubmoduleCount() { return m_nShownSubmodules
; }
952 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
954 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
956 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
958 bool m_amend
; ///< if true show the changes to the revision before the last commit
960 CString m_sUUID
; ///< the UUID of the associated repository
962 CString m_sDisplayedBranch
; ///< When on LogDialog, what is the current displayed branch
964 CWnd
*m_hwndLogicalParent
;
966 DECLARE_MESSAGE_MAP()
969 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
970 bool IsBusy() const { return m_bBusy
; }
971 void SetHasCheckboxes(bool bHasCheckboxes
)
973 m_bHasCheckboxes
= bHasCheckboxes
;
974 DWORD exStyle
= GetExtendedStyle();
976 exStyle
|= LVS_EX_CHECKBOXES
;
978 exStyle
&= ~LVS_EX_CHECKBOXES
;
979 SetExtendedStyle(exStyle
);
983 void SaveColumnWidths(bool bSaveToRegistry
= false);
984 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
985 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
986 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
987 void StartDiff(int fileindex
); ///< start the external diff program
988 void StartDiffWC(int fileindex
); ///< start the external diff program
989 void StartDiffTwo(int fileindex
);
991 void SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
);
993 CString m_sMarkForDiffFilename
;
994 CString m_sMarkForDiffVersion
;
996 /* while rebasing, Their and My versios are swapped. */
997 bool m_bIsRevertTheirMy
;
1005 void OpenFile(CTGitPath
*path
,int mode
);
1007 /// Clear the status vector (contains custodial pointers)
1008 void ClearStatusArray();
1010 /// Sort predicate function - Compare the paths of two entries without regard to case
1011 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
1013 /// Predicate used to build a list of only the versioned entries of the FileEntry array
1014 //static bool IsEntryVersioned(const FileEntry* pEntry1);
1016 /// Look up the relevant show flags for a particular Git status value
1017 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
1019 /// Adjust the checkbox-state on all descendants of a specific item
1020 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
1022 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
1023 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
1025 /// Enables/Disables group view and adds all groups to the list control.
1026 /// If bForce is true, then group view is enabled and the 'null' group is added.
1027 bool PrepareGroups(bool bForce
= false);
1028 /// Returns the group number to which the group header belongs
1029 /// If the point is not over a group header, -1 is returned
1030 int GetGroupFromPoint(POINT
* ppt
);
1031 /// Returns the number of change lists the selection has
1032 size_t GetNumberOfChangelistsInSelection();
1034 /// Puts the item to the corresponding group
1035 bool SetItemGroup(int item
, int groupindex
);
1037 void CheckEntry(int index
, int nListItems
);
1038 void UncheckEntry(int index
, int nListItems
);
1040 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1042 CWnd
* GetLogicalParent() { return m_hwndLogicalParent
? m_hwndLogicalParent
: this->GetParent(); }
1044 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1045 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1046 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1047 bool CheckMultipleDiffs();
1049 void DeleteSelectedFiles();
1051 virtual void PreSubclassWindow();
1052 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1053 virtual BOOL
OnWndMsg(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
);
1054 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1055 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1056 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1057 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1058 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1059 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1060 afx_msg
void OnHeaderDblClick(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1061 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1062 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1064 void CreateChangeList(const CString
& name
);
1066 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1067 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1068 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1069 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1070 afx_msg UINT
OnGetDlgCode();
1071 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1072 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1073 afx_msg
void OnPaint();
1074 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1075 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1076 afx_msg
void OnDestroy();
1080 void FileSaveAs(CTGitPath
*path
);
1081 int RevertSelectedItemToVersion(bool parent
= false);
1084 bool * m_pbCanceled
;
1085 bool m_bAscending
; ///< sort direction
1086 int m_nSortedColumn
; ///< which column to sort
1087 bool m_bHasCheckboxes
;
1089 bool m_bUnversionedLast
;
1090 bool m_bHasExternalsFromDifferentRepos
;
1091 bool m_bHasExternals
;
1092 BOOL m_bHasUnversionedItems
;
1094 bool m_bHasChangeLists
;
1095 //typedef std::vector<FileEntry*> FileEntryVector;
1096 //FileEntryVector m_arStatusArray;
1097 std::vector
<CTGitPath
*> m_arStatusArray
;
1098 std::vector
<size_t> m_arListArray
;
1099 std::map
<CString
, int> m_changelists
;
1100 bool m_bHasIgnoreGroup
;
1101 //CTGitPathList m_ConflictFileList;
1102 CTGitPathList m_StatusFileList
;
1103 CTGitPathList m_UnRevFileList
;
1104 CTGitPathList m_IgnoreFileList
;
1105 CTGitPathList m_LocalChangesIgnoredFileList
; // assume valid & skip worktree
1106 //CTGitPathList m_StatusUrlList;
1107 CString m_sLastError
;
1109 LONG m_nUnversioned
;
1118 LONG m_nLineDeleted
;
1121 LONG m_nShownUnversioned
;
1122 LONG m_nShownModified
;
1124 LONG m_nShownDeleted
;
1125 LONG m_nShownConflicted
;
1127 LONG m_nShownSubmodules
;
1129 DWORD m_dwDefaultColumns
;
1131 bool m_bShowFolders
;
1132 bool m_bShowIgnores
;
1134 unsigned __int64 m_dwContextMenus
;
1139 bool m_bIgnoreRemoveOnly
;
1140 bool m_bCheckIfGroupsExist
;
1141 bool m_bFileDropsEnabled
;
1147 CWnd
* m_pStatLabel
;
1148 CButton
* m_pSelectButton
;
1149 CButton
* m_pConfirmButton
;
1154 CString m_sNoPropValueText
;
1156 bool m_bCheckChildrenWithParent
;
1157 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1159 ColumnManager m_ColumnManager
;
1161 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember de-/selected items
1162 std::map
<CString
,bool> m_mapDirectFiles
;
1163 CComCriticalSection m_critSec
;
1165 friend class CGitStatusListCtrlDropTarget
;
1169 FILELIST_MODIFY
= 0x1,
1170 FILELIST_UNVER
= 0x2,
1171 FILELIST_IGNORE
=0x4,
1172 FILELIST_LOCALCHANGESIGNORED
= 0x8, // assume valid & skip worktree files
1175 int UpdateFileList(CTGitPathList
* List
= nullptr);
1177 int UpdateFileList(int mask
, bool once
= true, CTGitPathList
* List
= nullptr);
1178 int UpdateUnRevFileList(CTGitPathList
&list
);
1179 int UpdateUnRevFileList(CTGitPathList
* List
= nullptr);
1180 int UpdateIgnoreFileList(CTGitPathList
* List
= nullptr);
1181 int UpdateLocalChangesIgnoredFileList(CTGitPathList
* list
= nullptr);
1183 int UpdateWithGitPathList(CTGitPathList
&list
);
1185 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1188 git_revnum_t m_CurrentVersion
;
1189 bool m_bDoNotAutoselectSubmodules
;
1190 bool m_bNoAutoselectMissing
;
1191 std::map
<CString
, CString
> m_restorepaths
;
1194 LPCONTEXTMENU m_pContextMenu
;
1198 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1201 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1203 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1204 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1206 CGitStatusListCtrl
* m_pGitStatusListCtrl
;