1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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"
26 #include "HintListCtrl.h"
28 #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)
30 // these defines must be in the order the columns are inserted!
31 #define GITSLC_COLFILENAME 0x000000002
32 #define GITSLC_COLEXT 0x000000004
33 #define GITSLC_COLSTATUS 0x000000008
34 //#define SVNSLC_COLAUTHOR 0x000000040
35 //#define SVNSLC_COLREVISION 0x000000080
36 //#define SVNSLC_COLDATE 0x000000100
37 #define GITSLC_COLADD 0x000000010
38 #define GITSLC_COLDEL 0x000000020
39 #define GITSLC_COLMODIFICATIONDATE 0x000000040
40 #define GITSLC_COLSIZE 0x000000080
41 #define GITSLC_NUMCOLUMNS 8
43 //#define SVNSLC_COLURL 0x000000200
44 //#define SVNSLC_COLCOPYFROM 0x000020000
46 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
47 #define GITSLC_SHOWNORMAL 0x00000000
48 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
49 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
50 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
51 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
52 #define GITSLC_SHOWMISSING 0x00000000
53 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
54 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
55 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
56 #define GITSLC_SHOWOBSTRUCTED 0x00000000
57 #define GITSLC_SHOWEXTERNAL 0x00000000
58 #define GITSLC_SHOWINCOMPLETE 0x00000000
59 #define GITSLC_SHOWINEXTERNALS 0x00000000
60 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
61 #define GITSLC_SHOWLOCKS 0x00000000
62 #define GITSLC_SHOWDIRECTFILES 0x04000000
63 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
64 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
65 #define GITSLC_SHOWSWITCHED 0x00000000
66 #define GITSLC_SHOWINCHANGELIST 0x00000000
67 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
68 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
70 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
72 #define GITSLC_SHOWFILES 0x01000000
73 #define GITSLC_SHOWSUBMODULES 0x02000000
74 #define GITSLC_SHOWEVERYTHING 0xffffffff
76 #define GITSLC_SHOWVERSIONED (CTGitPath::LOGACTIONS_FORWORD|GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
77 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
78 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
79 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
80 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
82 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
83 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
84 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
85 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
86 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
88 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
89 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
90 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
91 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
93 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
94 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
95 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
96 GITSLC_SHOWINCOMPLETE)
98 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
100 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
101 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
102 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
103 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
104 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
105 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
106 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
107 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
108 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
109 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
110 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
111 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
112 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
113 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
114 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
115 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
116 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
117 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
118 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
119 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOFILES)
120 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
121 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
122 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
123 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
124 #define GITLC_POPUNSETIGNORELOCALCHANGES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNSETIGNORELOCALCHANGES)
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) {};
160 DWORD m_dwDefaultColumns
;
163 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int *withlist
=NULL
);
164 void WriteSettings() const;
166 /// read column definitions
168 int GetColumnCount() const; ///< total number of columns
169 bool IsVisible (int column
) const;
170 int GetInvisibleCount() const;
171 bool IsRelevant (int column
) const;
172 CString
GetName (int column
) const;
173 int SetNames(UINT
* buff
, int size
);
174 int GetWidth (int column
, bool useDefaults
= false) const;
175 int GetVisibleWidth (int column
, bool useDefaults
) 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
);
184 void ColumnResized (int column
);
186 /// call these to update the user-prop list
187 /// (will also auto-insert /-remove new list columns)
189 /// don't clutter the context menu with irrelevant prop info
191 void RemoveUnusedProps();
193 /// bring everything back to its "natural" order
195 void ResetColumns (DWORD defaultColumns
);
197 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
199 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
200 if ( (header
!= NULL
)
201 && (header
->iItem
>= 0)
202 && (header
->iItem
< GetColumnCount()))
204 ColumnResized (header
->iItem
);
209 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
211 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
213 if ( (header
!= NULL
)
214 && (header
->iItem
>= 0)
215 && (header
->iItem
< GetColumnCount())
216 // only allow the reordering if the column was not moved left of the first
217 // visible item - otherwise the 'invisible' columns are not at the far left
218 // anymore and we get all kinds of redrawing problems.
220 && (header
->pitem
->iOrder
>= GetInvisibleCount()))
222 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
226 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
228 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
230 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
233 if (IsVisible (phdr
->iItem
))
240 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
242 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
244 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
249 // visible columns may be modified
251 if (IsVisible (phdr
->iItem
))
256 // columns already marked as "invisible" internally may be (re-)sized to 0
258 if ( (phdr
->pitem
!= NULL
)
259 && (phdr
->pitem
->mask
== HDI_WIDTH
)
260 && (phdr
->pitem
->cxy
== 0))
265 if ( (phdr
->pitem
!= NULL
)
266 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
274 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
276 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
277 if ((point
.x
== -1) && (point
.y
== -1))
280 pHeaderCtrl
->GetItemRect(0, &rect
);
281 pHeaderCtrl
->ClientToScreen(&rect
);
282 point
= rect
.CenterPoint();
286 if (popup
.CreatePopupMenu())
288 int columnCount
= GetColumnCount();
291 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
292 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
294 // build control menu
296 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
297 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
299 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
300 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
301 popup
.AppendMenu(MF_SEPARATOR
);
306 // user-prop columns:
307 // find relevant ones and sort 'em
309 std::map
<CString
, int> sortedProps
;
310 for (int i
= (int)itemName
.size(); i
< columnCount
; ++i
)
312 sortedProps
[GetName(i
)] = i
;
314 if (!sortedProps
.empty())
316 // add 'em to the menu
318 popup
.AppendMenu(MF_SEPARATOR
);
320 typedef std::map
<CString
, int>::const_iterator CIT
;
321 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
325 popup
.AppendMenu ( IsVisible(iter
->second
)
333 // show menu & let user pick an entry
335 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
336 if ((cmd
>= 1)&&(cmd
< columnCount
))
338 SetVisible (cmd
, !IsVisible(cmd
));
340 else if (cmd
== columnCount
)
342 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
343 //EnableGroupView(!isGroundEnable);
345 else if (cmd
== columnCount
+1)
349 else if (cmd
== columnCount
+2)
351 temp
.LoadString(IDS_CONFIRMRESETCOLUMNORDER
);
352 if (MessageBox(pWnd
->m_hWnd
, temp
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
353 ResetColumns (m_dwDefaultColumns
);
358 void AddMenuItem(CMenu
*pop
)
360 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
361 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
363 for (int i
= 1; i
< (int)itemName
.size(); ++i
)
366 pop
->AppendMenu ( IsVisible(i
)
375 /// initialization utilities
377 void ParseWidths (const CString
& widths
);
378 void SetStandardColumnVisibility (DWORD visibility
);
379 void ParseColumnOrder (const CString
& widths
);
381 /// map internal column order onto visible column order
382 /// (all invisibles in front)
384 std::vector
<int> GetGridColumnOrder() const;
385 void ApplyColumnOrder();
387 /// utilities used when writing data to the registry
389 DWORD
GetSelectedStandardColumns() const;
390 CString
GetWidthString() const;
391 CString
GetColumnOrderString() const;
393 /// our parent control and its data
397 /// where to store in the registry
399 CString registryPrefix
;
401 /// all columns in their "natural" order
405 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
408 bool relevant
; ///< set to @a visible, if no *shown* item has that property
411 std::vector
<ColumnInfo
> columns
;
413 /// user-defined properties
415 std::set
<CString
> itemProps
;
417 /// global column ordering including unused user props
419 std::vector
<int> columnOrder
;
421 std::vector
<int> itemName
;
426 * \ingroup TortoiseProc
427 * Simple utility class that defines the sort column order.
433 CSorter ( ColumnManager
* columnManager
437 bool operator() ( const CTGitPath
* entry1
438 , const CTGitPath
* entry2
) const;
440 static int A2L(const CString
&str
)
450 ColumnManager
* columnManager
;
457 * A List control, based on the MFC CListCtrl which shows a list of
458 * files with their git status. The control also provides a context
459 * menu to do some git tasks on the selected files.
461 * This is the main control used in many dialogs to show a list of files to
464 class CGitStatusListCtrl
:
471 /** Compare with base version. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
476 /** Compare with base version and generate unified diff. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
480 IDGITLC_LOGSUBMODULE
,
481 IDGITLC_EDITCONFLICT
,
483 IDGITLC_IGNOREFOLDER
,
485 IDGITLC_RESOLVECONFLICT
,
488 IDGITLC_RESOLVETHEIRS
,
489 IDGITLC_RESOLVEMINE
,
494 IDGITLC_REMOVEFROMCS
,
496 IDGITLC_CREATEIGNORECS
,
498 IDGITLC_UNCHECKGROUP
,
499 /** Compare current version and working tree */
503 IDGITLC_REVERTTOREV
,
504 IDGITLC_REVERTTOPARENT
,
507 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
508 IDGITLC_COMPARETWOREVISIONS
,
509 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
510 IDGITLC_GNUDIFF2REVISIONS
,
511 /** Compare two selected files */
512 IDGITLC_COMPARETWOFILES
,
514 IDGITLC_CREATERESTORE
,
515 IDGITLC_RESTOREPATH
,
516 IDGITLC_ASSUMEVALID
,
517 IDGITLC_SKIPWORKTREE
,
519 IDGITLC_UNSETIGNORELOCALCHANGES
,
520 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
521 // the submenu items get command ID's sequent to this number
524 int GetColumnIndex(int colmask
);
525 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
527 * Sent to the parent window (using ::SendMessage) after a context menu
528 * command has finished if the item count has changed.
530 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
532 * Sent to the parent window (using ::SendMessage) when the control needs
533 * to be refreshed. Since this is done usually in the parent window using
534 * a thread, this message is used to tell the parent to do exactly that.
536 static const UINT GITSLNM_NEEDSREFRESH
;
539 * Sent to the parent window (using ::SendMessage) when the user drops
540 * files on the control. The LPARAM is a pointer to a TCHAR string
541 * containing the dropped path.
543 static const UINT GITSLNM_ADDFILE
;
546 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
547 * one or more items in the control. The WPARAM contains the number of
548 * checked items in the control.
550 static const UINT GITSLNM_CHECKCHANGED
;
552 static const UINT GITSLNM_ITEMCHANGED
;
554 CGitStatusListCtrl(void);
555 ~CGitStatusListCtrl(void);
561 * \ingroup TortoiseProc
562 * Helper class for CGitStatusListCtrl which represents
563 * the data for each file shown.
569 FileEntry() : status(git_wc_status_unversioned
)
570 // , copyfrom_rev(GIT_REV_ZERO)
571 , last_commit_date(0)
572 , last_commit_rev(GIT_REV_ZERO
)
573 // , remoterev(GIT_REV_ZERO)
574 , textstatus(git_wc_status_unversioned
)
575 , propstatus(git_wc_status_unversioned
)
576 // , remotestatus(git_wc_status_unversioned)
577 // , remotetextstatus(git_wc_status_unversioned)
578 // , remotepropstatus(git_wc_status_unversioned)
582 , inunversionedfolder(false)
584 , differentrepo(false)
588 , Revision(GIT_REV_ZERO
)
589 , isConflicted(false)
592 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
594 // , depth(git_depth_unknown)
597 const CTGitPath
& GetPath() const
601 const bool IsChecked() const
605 CString
GetRelativeGitPath() const
607 if (path
.IsEquivalentTo(basepath
))
608 return path
.GetGitPathString();
609 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
611 // const bool IsLocked() const
613 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
615 // const bool HasNeedsLock() const
619 const bool IsFolder() const
623 const bool IsInExternal() const
627 const bool IsNested() const
631 const bool IsFromDifferentRepository() const
633 return differentrepo
;
635 CString
GetDisplayName() const
637 CString
const& chopped
= path
.GetDisplayString(&basepath
);
638 if (!chopped
.IsEmpty())
644 // "Display name" must not be empty.
645 return path
.GetFileOrDirectoryName();
648 CString
GetChangeList() const
652 // CString GetURL() const
657 git_wc_status_kind status
; ///< local status
658 git_wc_status_kind textstatus
; ///< local text status
659 git_wc_status_kind propstatus
; ///< local property status
662 CTGitPath path
; ///< full path of the file
663 CTGitPath basepath
; ///< common ancestor path of all files
665 CString changelist
; ///< the name of the changelist the item belongs to
667 CString last_commit_author
; ///< the author which last committed this item
668 CTime last_commit_date
; ///< the date when this item was last committed
669 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
671 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
672 bool copied
; ///< if the file/folder is added-with-history
673 bool switched
; ///< if the file/folder is switched to another url
674 bool checked
; ///< if the file is checked in the list control
675 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
676 bool inexternal
; ///< if the item is in an external folder
677 bool differentrepo
; ///< if the item is from a different repository than the rest
678 bool direct
; ///< directly included (TRUE) or just a child of a folder
679 bool isfolder
; ///< TRUE if entry refers to a folder
680 bool isNested
; ///< TRUE if the folder from a different repository and/or path
681 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
682 bool needslock
; ///< TRUE if the Git:needs-lock property is set
683 git_revnum_t Revision
; ///< the base revision
684 // PropertyList present_props; ///< cacheable properties present in BASE
685 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
686 git_depth_t depth
; ///< the depth of this entry
687 friend class CGitStatusListCtrl
;
688 friend class CGitStatusListCtrlDropTarget
;
689 friend class CSorter
;
694 * Initializes the control, sets up the columns.
695 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
696 * \param sColumnInfoContainer Name of a registry key
697 * where the position and visibility of each column
698 * is saved and used from. If the registry key
699 * doesn't exist, the default order is used
700 * and dwColumns tells which columns are visible.
701 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
702 * Use the GitSLC_POPxxx defines.
703 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
704 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
706 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);
708 * Sets a background image for the list control.
709 * The image is shown in the right bottom corner.
710 * \param nID the resource ID of the bitmap to use as the background
712 bool SetBackgroundImage(UINT nID
);
714 * Makes the 'ignore' context menu only ignore the files and not add the
715 * folder which gets the Git:ignore property changed to the list.
716 * This is needed e.g. for the Add-dialog, where the modified folder
717 * showing up would break the resulting "add" command.
719 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
721 * The unversioned items are by default shown after all other files in the list.
722 * If that behavior should be changed, set this value to false.
724 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
726 * Fetches the git status of all files and stores the information
727 * about them in an internal array.
728 * \param sFilePath path to a file which contains a list of files and/or folders for which to
729 * fetch the status, separated by newlines.
730 * \param bUpdate TRUE if the remote status is requested too.
731 * \return TRUE on success.
733 BOOL
GetStatus ( const CTGitPathList
* pathList
=NULL
734 , bool bUpdate
= false
735 , bool bShowIgnores
= false
736 , bool bShowUnRev
= false
737 , bool bShowLocalChangesIgnored
= false);
740 * Populates the list control with the previously (with GetStatus) gathered status information.
741 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
742 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
744 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
745 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
748 * Copies the selected entries in the control to the clipboard. The entries
749 * are separated by newlines.
750 * \param dwCols the columns to copy. Each column is separated by a tab.
752 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
755 * If during the call to GetStatus() some Git:externals are found from different
756 * repositories than the first one checked, then this method returns TRUE.
758 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
761 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
763 BOOL
HasExternals() const {return m_bHasExternals
;}
766 * If unversioned files are found (but not necessarily shown) TRUE is returned.
768 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
771 * If there are any locks in the working copy, TRUE is returned
773 BOOL
HasLocks() const {return m_bHasLocks
;}
776 * If there are any change lists defined in the working copy, TRUE is returned
778 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
781 * Returns the file entry data for the list control index.
783 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
786 * Returns the file entry data for the specified path.
787 * \note The entry might not be shown in the list control.
789 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
792 * Returns the index of the list control entry with the specified path,
793 * or -1 if the path is not in the list control.
795 int GetIndex(const CTGitPath
& path
);
798 * Returns the file entry data for the specified path in the list control.
800 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
803 * Returns a String containing some statistics like number of modified, normal, deleted,...
806 CString
GetStatisticsString(bool simple
=false);
809 * Set a static control which will be updated automatically with
810 * the number of selected and total files shown in the list control.
812 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
815 * Set a tri-state checkbox which is updated automatically if the
816 * user checks/unchecks file entries in the list control to indicate
817 * if all files are checked, none are checked or some are checked.
819 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
822 * Set a button which is de-/activated automatically. The button is
823 * only set active if at least one item is selected.
825 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
828 * Select/unselect all entries in the list control.
829 * \param bSelect TRUE to check, FALSE to uncheck.
831 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
834 * Checks or unchecks all specified items
835 * \param dwCheck GITLC_SHOWxxx defines
836 * \param check if true matching items will be selected, false unchecks matching items
838 void Check(DWORD dwCheck
, bool check
= true);
840 /** Set a checkbox on an entry in the listbox
841 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
843 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
845 /** Write a list of the checked items' paths into a path list
847 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
849 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
850 * files/folders in the working copy.
851 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
852 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
854 * \remark Since an item can only be checked if it is visible/shown in the list control
855 * bShownOnly is automatically set to true if bCheckedOnly is true
857 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
860 * Returns the parent directory of all entries in the control.
861 * if \a bStrict is set to false, then the paths passed to the control
862 * to fetch the status (in GetStatus()) are used if possible.
864 CString
GetCommonDirectory(bool bStrict
);
867 * Returns the parent url of all entries in the control.
868 * if \a bStrict is set to false, then the paths passed to the control
869 * to fetch the status (in GetStatus()) are used if possible.
871 CTGitPath
GetCommonURL(bool bStrict
);
874 * Sets a pointer to a boolean variable which is checked periodically
875 * during the status fetching. As soon as the variable changes to true,
876 * the operations stops.
878 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
881 * Sets the string shown in the control while the status is fetched.
882 * If not set, it defaults to "please wait..."
884 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
885 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
888 * Sets the string shown in the control if no items are shown. This
889 * can happen for example if there's nothing modified and the unversioned
890 * files aren't shown either, so there's nothing to commit.
891 * If not set, it defaults to "file list is empty".
893 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
894 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
897 * Returns the number of selected items
899 LONG
GetSelected(){return m_nSelected
;};
902 * Enables dropping of files on the control.
904 bool EnableFileDrop();
907 * Checks if the path already exists in the list.
909 bool HasPath(const CTGitPath
& path
);
911 * Checks if the path is shown/visible in the list control.
913 bool IsPathShown(const CTGitPath
& path
);
915 * Forces the children to be checked when the parent folder is checked,
916 * and the parent folder to be unchecked if one of its children is unchecked.
918 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
921 * Allows checking the items if change lists are present. If set to false,
922 * items are not checked if at least one changelist is available.
924 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
926 * Returns the currently used show flags passed to the Show() method.
928 DWORD
GetShowFlags() {return m_dwShow
;}
931 CString
GetLastErrorMessage() {return m_sLastError
;}
933 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
935 LONG
GetUnversionedCount() { return m_nShownUnversioned
; }
936 LONG
GetModifiedCount() { return m_nShownModified
; }
937 LONG
GetAddedCount() { return m_nShownAdded
; }
938 LONG
GetDeletedCount() { return m_nShownDeleted
; }
939 LONG
GetConflictedCount() { return m_nShownConflicted
; }
940 LONG
GetFileCount() { return m_nShownFiles
; }
941 LONG
GetSubmoduleCount() { return m_nShownSubmodules
; }
943 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
945 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
947 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
949 bool m_amend
; ///< if true show the changes to the revision before the last commit
951 CString m_sUUID
; ///< the UUID of the associated repository
953 CString m_sDisplayedBranch
; ///< When on LogDialog, what is the current displayed branch
955 bool m_bIsRevertTheirMy
; ///< at rebase case, Their and My version is revert.
957 CWnd
*m_hwndLogicalParent
;
959 DECLARE_MESSAGE_MAP()
962 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
963 void SetHasCheckboxes(bool bHasCheckboxes
)
965 m_bHasCheckboxes
= bHasCheckboxes
;
966 DWORD exStyle
= GetExtendedStyle();
968 exStyle
|= LVS_EX_CHECKBOXES
;
970 exStyle
&= ~LVS_EX_CHECKBOXES
;
971 SetExtendedStyle(exStyle
);
975 void SaveColumnWidths(bool bSaveToRegistry
= false);
976 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
977 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
978 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
979 void StartDiff(int fileindex
); ///< start the external diff program
980 void StartDiffWC(int fileindex
); ///< start the external diff program
981 void StartDiffTwo(int fileindex
);
983 void SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
);
991 void OpenFile(CTGitPath
*path
,int mode
);
993 /// Clear the status vector (contains custodial pointers)
994 void ClearStatusArray();
996 /// Sort predicate function - Compare the paths of two entries without regard to case
997 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
999 /// Predicate used to build a list of only the versioned entries of the FileEntry array
1000 //static bool IsEntryVersioned(const FileEntry* pEntry1);
1002 /// Look up the relevant show flags for a particular Git status value
1003 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
1005 /// Adjust the checkbox-state on all descendants of a specific item
1006 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
1008 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
1009 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
1011 /// Enables/Disables group view and adds all groups to the list control.
1012 /// If bForce is true, then group view is enabled and the 'null' group is added.
1013 bool PrepareGroups(bool bForce
= false);
1014 /// Returns the group number to which the group header belongs
1015 /// If the point is not over a group header, -1 is returned
1016 int GetGroupFromPoint(POINT
* ppt
);
1017 /// Returns the number of change lists the selection has
1018 size_t GetNumberOfChangelistsInSelection();
1020 /// Puts the item to the corresponding group
1021 bool SetItemGroup(int item
, int groupindex
);
1023 void CheckEntry(int index
, int nListItems
);
1024 void UncheckEntry(int index
, int nListItems
);
1026 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1028 CWnd
* GetLogicalParent() { return m_hwndLogicalParent
!= NULL
? m_hwndLogicalParent
: this->GetParent(); }
1030 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1031 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1032 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1033 bool CheckMultipleDiffs();
1035 void DeleteSelectedFiles();
1037 virtual void PreSubclassWindow();
1038 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1039 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1040 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1041 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1042 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1043 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1044 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1045 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1046 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1048 void CreateChangeList(const CString
& name
);
1050 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1051 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1052 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1053 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1054 afx_msg UINT
OnGetDlgCode();
1055 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1056 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1057 afx_msg
void OnPaint();
1058 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1059 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1060 afx_msg
void OnDestroy();
1064 void FileSaveAs(CTGitPath
*path
);
1065 int RevertSelectedItemToVersion(bool parent
= false);
1068 bool * m_pbCanceled
;
1069 bool m_bAscending
; ///< sort direction
1070 int m_nSortedColumn
; ///< which column to sort
1071 bool m_bHasCheckboxes
;
1073 bool m_bUnversionedLast
;
1074 bool m_bHasExternalsFromDifferentRepos
;
1075 bool m_bHasExternals
;
1076 BOOL m_bHasUnversionedItems
;
1078 bool m_bHasChangeLists
;
1079 //typedef std::vector<FileEntry*> FileEntryVector;
1080 //FileEntryVector m_arStatusArray;
1081 std::vector
<CTGitPath
*> m_arStatusArray
;
1082 std::vector
<size_t> m_arListArray
;
1083 std::map
<CString
, int> m_changelists
;
1084 bool m_bHasIgnoreGroup
;
1085 //CTGitPathList m_ConflictFileList;
1086 CTGitPathList m_StatusFileList
;
1087 CTGitPathList m_UnRevFileList
;
1088 CTGitPathList m_IgnoreFileList
;
1089 CTGitPathList m_LocalChangesIgnoredFileList
; // assume valid & skip worktree
1090 //CTGitPathList m_StatusUrlList;
1091 CString m_sLastError
;
1093 LONG m_nUnversioned
;
1102 LONG m_nLineDeleted
;
1105 LONG m_nShownUnversioned
;
1106 LONG m_nShownModified
;
1108 LONG m_nShownDeleted
;
1109 LONG m_nShownConflicted
;
1111 LONG m_nShownSubmodules
;
1113 DWORD m_dwDefaultColumns
;
1115 bool m_bShowFolders
;
1116 bool m_bShowIgnores
;
1118 unsigned __int64 m_dwContextMenus
;
1123 bool m_bIgnoreRemoveOnly
;
1124 bool m_bCheckIfGroupsExist
;
1125 bool m_bFileDropsEnabled
;
1131 CWnd
* m_pStatLabel
;
1132 CButton
* m_pSelectButton
;
1133 CButton
* m_pConfirmButton
;
1138 CString m_sNoPropValueText
;
1140 bool m_bCheckChildrenWithParent
;
1141 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1143 ColumnManager m_ColumnManager
;
1145 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember de-/selected items
1146 std::map
<CString
,bool> m_mapDirectFiles
;
1147 CComCriticalSection m_critSec
;
1149 friend class CGitStatusListCtrlDropTarget
;
1153 FILELIST_MODIFY
= 0x1,
1154 FILELIST_UNVER
= 0x2,
1155 FILELIST_IGNORE
=0x4,
1156 FILELIST_LOCALCHANGESIGNORED
= 0x8, // assume valid & skip worktree files
1159 int UpdateFileList(git_revnum_t hash
,CTGitPathList
*List
=NULL
);
1160 int UpdateFileList(int mask
, bool once
=true,CTGitPathList
*List
=NULL
);
1161 int UpdateUnRevFileList(CTGitPathList
&list
);
1162 int UpdateUnRevFileList(CTGitPathList
*List
=NULL
);
1163 int UpdateIgnoreFileList(CTGitPathList
*List
=NULL
);
1164 int UpdateLocalChangesIgnoredFileList(CTGitPathList
* list
= nullptr);
1166 int UpdateWithGitPathList(CTGitPathList
&list
);
1168 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1171 git_revnum_t m_CurrentVersion
;
1172 bool m_bDoNotAutoselectSubmodules
;
1173 std::map
<CString
, CString
> m_restorepaths
;
1177 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1180 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1182 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1183 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1185 CGitStatusListCtrl
* m_pGitStatusListCtrl
;