1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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"
27 #include "SmartHandle.h"
29 #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)
31 // these defines must be in the order the columns are inserted!
32 #define GITSLC_COLFILENAME 0x000000002
33 #define GITSLC_COLEXT 0x000000004
34 #define GITSLC_COLSTATUS 0x000000008
35 //#define SVNSLC_COLAUTHOR 0x000000040
36 //#define SVNSLC_COLREVISION 0x000000080
37 //#define SVNSLC_COLDATE 0x000000100
38 #define GITSLC_COLADD 0x000000010
39 #define GITSLC_COLDEL 0x000000020
40 #define GITSLC_COLMODIFICATIONDATE 0x000000040
41 #define GITSLC_COLSIZE 0x000000080
42 #define GITSLC_NUMCOLUMNS 8
44 //#define SVNSLC_COLURL 0x000000200
45 //#define SVNSLC_COLCOPYFROM 0x000020000
47 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
48 #define GITSLC_SHOWNORMAL 0x00000000
49 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
50 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
51 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
52 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
53 #define GITSLC_SHOWMISSING 0x00000000
54 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
55 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
56 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
57 #define GITSLC_SHOWOBSTRUCTED 0x00000000
58 #define GITSLC_SHOWEXTERNAL 0x00000000
59 #define GITSLC_SHOWINCOMPLETE 0x00000000
60 #define GITSLC_SHOWINEXTERNALS 0x00000000
61 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
62 #define GITSLC_SHOWLOCKS 0x00000000
63 #define GITSLC_SHOWDIRECTFILES 0x04000000
64 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
65 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
66 #define GITSLC_SHOWSWITCHED 0x00000000
67 #define GITSLC_SHOWINCHANGELIST 0x00000000
68 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
69 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
71 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
73 #define GITSLC_SHOWFILES 0x01000000
74 #define GITSLC_SHOWSUBMODULES 0x02000000
75 #define GITSLC_SHOWEVERYTHING 0xffffffff
77 #define GITSLC_SHOWVERSIONED (GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
78 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
79 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
80 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
81 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
83 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
84 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
85 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
86 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
87 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
89 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
90 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
91 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
92 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
94 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
95 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
96 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
97 GITSLC_SHOWINCOMPLETE)
99 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
101 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
102 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
103 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
104 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
105 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
106 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
107 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
108 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
109 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
110 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
111 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
112 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
113 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
114 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
115 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
116 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
117 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
118 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
119 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
120 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOFILES)
121 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
122 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
123 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
124 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
125 #define GITLC_POPUNSETIGNORELOCALCHANGES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNSETIGNORELOCALCHANGES)
126 #define GITSLC_PREPAREDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_PREPAREDIFF)
128 #define GITSLC_IGNORECHANGELIST _T("ignore-on-commit")
130 // This gives up to 64 standard properties and menu entries
131 #define GITSLC_MAXCOLUMNCOUNT 0xff
133 #define OVL_RESTORE 1
135 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
136 typedef CComCritSecLock
<CComCriticalSection
> Locker
;
138 class CGitStatusListCtrlDropTarget
;
141 * \ingroup TortoiseProc
142 * Helper class for CGitStatusListCtrl that represents
143 * the columns visible and their order as well as
144 * persisting that data in the registry.
146 * It assigns logical index values to the (potential) columns:
147 * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes
149 * The column vector contains the columns that are actually
150 * available in the control.
157 /// construction / destruction
159 ColumnManager (CListCtrl
* control
) : control (control
), m_dwDefaultColumns(0) {};
162 DWORD m_dwDefaultColumns
;
165 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int *withlist
=NULL
);
166 void WriteSettings() const;
168 /// read column definitions
170 int GetColumnCount() const; ///< total number of columns
171 bool IsVisible (int column
) const;
172 int GetInvisibleCount() const;
173 bool IsRelevant (int column
) const;
174 CString
GetName (int column
) const;
175 int SetNames(UINT
* buff
, int size
);
176 int GetWidth (int column
, bool useDefaults
= false) const;
177 int GetVisibleWidth (int column
, bool useDefaults
) const;
179 /// switch columns on and off
181 void SetVisible (int column
, bool visible
);
183 /// tracking column modifications
185 void ColumnMoved (int column
, int position
);
186 void ColumnResized (int column
);
188 /// call these to update the user-prop list
189 /// (will also auto-insert /-remove new list columns)
191 /// don't clutter the context menu with irrelevant prop info
193 void RemoveUnusedProps();
195 /// bring everything back to its "natural" order
197 void ResetColumns (DWORD defaultColumns
);
199 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
201 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
202 if ( (header
!= NULL
)
203 && (header
->iItem
>= 0)
204 && (header
->iItem
< GetColumnCount()))
206 ColumnResized (header
->iItem
);
211 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
213 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
215 if ( (header
!= NULL
)
216 && (header
->iItem
>= 0)
217 && (header
->iItem
< GetColumnCount())
218 // only allow the reordering if the column was not moved left of the first
219 // visible item - otherwise the 'invisible' columns are not at the far left
220 // anymore and we get all kinds of redrawing problems.
222 && (header
->pitem
->iOrder
>= GetInvisibleCount()))
224 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
228 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
230 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
232 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
235 if (IsVisible (phdr
->iItem
))
242 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
244 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
246 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
251 // visible columns may be modified
253 if (IsVisible (phdr
->iItem
))
258 // columns already marked as "invisible" internally may be (re-)sized to 0
260 if ( (phdr
->pitem
!= NULL
)
261 && (phdr
->pitem
->mask
== HDI_WIDTH
)
262 && (phdr
->pitem
->cxy
== 0))
267 if ( (phdr
->pitem
!= NULL
)
268 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
276 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
278 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
279 if ((point
.x
== -1) && (point
.y
== -1))
282 pHeaderCtrl
->GetItemRect(0, &rect
);
283 pHeaderCtrl
->ClientToScreen(&rect
);
284 point
= rect
.CenterPoint();
288 if (popup
.CreatePopupMenu())
290 int columnCount
= GetColumnCount();
293 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
294 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
296 // build control menu
298 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
299 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
301 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
302 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
303 popup
.AppendMenu(MF_SEPARATOR
);
308 // user-prop columns:
309 // find relevant ones and sort 'em
311 std::map
<CString
, int> sortedProps
;
312 for (int i
= (int)itemName
.size(); i
< columnCount
; ++i
)
314 sortedProps
[GetName(i
)] = i
;
316 if (!sortedProps
.empty())
318 // add 'em to the menu
320 popup
.AppendMenu(MF_SEPARATOR
);
322 typedef std::map
<CString
, int>::const_iterator CIT
;
323 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
327 popup
.AppendMenu ( IsVisible(iter
->second
)
335 // show menu & let user pick an entry
337 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
338 if ((cmd
>= 1)&&(cmd
< columnCount
))
340 SetVisible (cmd
, !IsVisible(cmd
));
342 else if (cmd
== columnCount
)
344 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
345 //EnableGroupView(!isGroundEnable);
347 else if (cmd
== columnCount
+1)
351 else if (cmd
== columnCount
+2)
353 temp
.LoadString(IDS_CONFIRMRESETCOLUMNORDER
);
354 if (MessageBox(pWnd
->m_hWnd
, temp
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
355 ResetColumns (m_dwDefaultColumns
);
360 void AddMenuItem(CMenu
*pop
)
362 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
363 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
365 for (int i
= 1; i
< (int)itemName
.size(); ++i
)
368 pop
->AppendMenu ( IsVisible(i
)
377 /// initialization utilities
379 void ParseWidths (const CString
& widths
);
380 void SetStandardColumnVisibility (DWORD visibility
);
381 void ParseColumnOrder (const CString
& widths
);
383 /// map internal column order onto visible column order
384 /// (all invisibles in front)
386 std::vector
<int> GetGridColumnOrder() const;
387 void ApplyColumnOrder();
389 /// utilities used when writing data to the registry
391 DWORD
GetSelectedStandardColumns() const;
392 CString
GetWidthString() const;
393 CString
GetColumnOrderString() const;
395 /// our parent control and its data
399 /// where to store in the registry
401 CString registryPrefix
;
403 /// all columns in their "natural" order
407 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
410 bool relevant
; ///< set to @a visible, if no *shown* item has that property
413 std::vector
<ColumnInfo
> columns
;
415 /// user-defined properties
417 std::set
<CString
> itemProps
;
419 /// global column ordering including unused user props
421 std::vector
<int> columnOrder
;
423 std::vector
<int> itemName
;
428 * \ingroup TortoiseProc
429 * Simple utility class that defines the sort column order.
435 CSorter ( ColumnManager
* columnManager
439 bool operator() ( const CTGitPath
* entry1
440 , const CTGitPath
* entry2
) const;
442 static int A2L(const CString
&str
)
452 ColumnManager
* columnManager
;
459 * A List control, based on the MFC CListCtrl which shows a list of
460 * files with their git status. The control also provides a context
461 * menu to do some git tasks on the selected files.
463 * This is the main control used in many dialogs to show a list of files to
466 class CGitStatusListCtrl
:
473 /** Compare with base version. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
478 /** Compare with base version and generate unified diff. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
482 IDGITLC_LOGSUBMODULE
,
483 IDGITLC_EDITCONFLICT
,
485 IDGITLC_IGNOREFOLDER
,
487 IDGITLC_RESOLVECONFLICT
,
490 IDGITLC_RESOLVETHEIRS
,
491 IDGITLC_RESOLVEMINE
,
496 IDGITLC_REMOVEFROMCS
,
498 IDGITLC_CREATEIGNORECS
,
500 IDGITLC_UNCHECKGROUP
,
501 /** Compare current version and working tree */
505 IDGITLC_REVERTTOREV
,
506 IDGITLC_REVERTTOPARENT
,
509 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
510 IDGITLC_COMPARETWOREVISIONS
,
511 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
512 IDGITLC_GNUDIFF2REVISIONS
,
513 /** Compare two selected files */
514 IDGITLC_COMPARETWOFILES
,
516 IDGITLC_CREATERESTORE
,
517 IDGITLC_RESTOREPATH
,
518 IDGITLC_ASSUMEVALID
,
519 IDGITLC_SKIPWORKTREE
,
521 IDGITLC_UNSETIGNORELOCALCHANGES
,
522 IDGITLC_PREPAREDIFF
,
523 IDGITLC_PREPAREDIFF_COMPARE
,
524 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
525 // the submenu items get command ID's sequent to this number
528 int GetColumnIndex(int colmask
);
529 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
531 * Sent to the parent window (using ::SendMessage) after a context menu
532 * command has finished if the item count has changed.
534 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
536 * Sent to the parent window (using ::SendMessage) when the control needs
537 * to be refreshed. Since this is done usually in the parent window using
538 * a thread, this message is used to tell the parent to do exactly that.
540 static const UINT GITSLNM_NEEDSREFRESH
;
543 * Sent to the parent window (using ::SendMessage) when the user drops
544 * files on the control. The LPARAM is a pointer to a TCHAR string
545 * containing the dropped path.
547 static const UINT GITSLNM_ADDFILE
;
550 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
551 * one or more items in the control. The WPARAM contains the number of
552 * checked items in the control.
554 static const UINT GITSLNM_CHECKCHANGED
;
556 static const UINT GITSLNM_ITEMCHANGED
;
558 CGitStatusListCtrl(void);
559 ~CGitStatusListCtrl(void);
565 * \ingroup TortoiseProc
566 * Helper class for CGitStatusListCtrl which represents
567 * the data for each file shown.
573 FileEntry() : status(git_wc_status_unversioned
)
574 // , copyfrom_rev(GIT_REV_ZERO)
575 , last_commit_date(0)
576 , last_commit_rev(GIT_REV_ZERO
)
577 // , remoterev(GIT_REV_ZERO)
578 , textstatus(git_wc_status_unversioned
)
579 , propstatus(git_wc_status_unversioned
)
580 // , remotestatus(git_wc_status_unversioned)
581 // , remotetextstatus(git_wc_status_unversioned)
582 // , remotepropstatus(git_wc_status_unversioned)
586 , inunversionedfolder(false)
588 , differentrepo(false)
592 , Revision(GIT_REV_ZERO
)
593 , isConflicted(false)
596 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
598 // , depth(git_depth_unknown)
601 const CTGitPath
& GetPath() const
605 const bool IsChecked() const
609 CString
GetRelativeGitPath() const
611 if (path
.IsEquivalentTo(basepath
))
612 return path
.GetGitPathString();
613 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
615 // const bool IsLocked() const
617 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
619 // const bool HasNeedsLock() const
623 const bool IsFolder() const
627 const bool IsInExternal() const
631 const bool IsNested() const
635 const bool IsFromDifferentRepository() const
637 return differentrepo
;
639 CString
GetDisplayName() const
641 CString
const& chopped
= path
.GetDisplayString(&basepath
);
642 if (!chopped
.IsEmpty())
648 // "Display name" must not be empty.
649 return path
.GetFileOrDirectoryName();
652 CString
GetChangeList() const
656 // CString GetURL() const
661 git_wc_status_kind status
; ///< local status
662 git_wc_status_kind textstatus
; ///< local text status
663 git_wc_status_kind propstatus
; ///< local property status
666 CTGitPath path
; ///< full path of the file
667 CTGitPath basepath
; ///< common ancestor path of all files
669 CString changelist
; ///< the name of the changelist the item belongs to
671 CString last_commit_author
; ///< the author which last committed this item
672 CTime last_commit_date
; ///< the date when this item was last committed
673 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
675 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
676 bool copied
; ///< if the file/folder is added-with-history
677 bool switched
; ///< if the file/folder is switched to another url
678 bool checked
; ///< if the file is checked in the list control
679 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
680 bool inexternal
; ///< if the item is in an external folder
681 bool differentrepo
; ///< if the item is from a different repository than the rest
682 bool direct
; ///< directly included (TRUE) or just a child of a folder
683 bool isfolder
; ///< TRUE if entry refers to a folder
684 bool isNested
; ///< TRUE if the folder from a different repository and/or path
685 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
686 bool needslock
; ///< TRUE if the Git:needs-lock property is set
687 git_revnum_t Revision
; ///< the base revision
688 // PropertyList present_props; ///< cacheable properties present in BASE
689 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
690 git_depth_t depth
; ///< the depth of this entry
691 friend class CGitStatusListCtrl
;
692 friend class CGitStatusListCtrlDropTarget
;
693 friend class CSorter
;
698 * Initializes the control, sets up the columns.
699 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
700 * \param sColumnInfoContainer Name of a registry key
701 * where the position and visibility of each column
702 * is saved and used from. If the registry key
703 * doesn't exist, the default order is used
704 * and dwColumns tells which columns are visible.
705 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
706 * Use the GitSLC_POPxxx defines.
707 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
708 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
710 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);
712 * Sets a background image for the list control.
713 * The image is shown in the right bottom corner.
714 * \param nID the resource ID of the bitmap to use as the background
716 bool SetBackgroundImage(UINT nID
);
718 * Makes the 'ignore' context menu only ignore the files and not add the
719 * folder which gets the Git:ignore property changed to the list.
720 * This is needed e.g. for the Add-dialog, where the modified folder
721 * showing up would break the resulting "add" command.
723 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
725 * The unversioned items are by default shown after all other files in the list.
726 * If that behavior should be changed, set this value to false.
728 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
730 * Fetches the git status of all files and stores the information
731 * about them in an internal array.
732 * \param sFilePath path to a file which contains a list of files and/or folders for which to
733 * fetch the status, separated by newlines.
734 * \param bUpdate TRUE if the remote status is requested too.
735 * \return TRUE on success.
737 BOOL
GetStatus ( const CTGitPathList
* pathList
=NULL
738 , bool bUpdate
= false
739 , bool bShowIgnores
= false
740 , bool bShowUnRev
= false
741 , bool bShowLocalChangesIgnored
= false);
744 * Populates the list control with the previously (with GetStatus) gathered status information.
745 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
746 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
748 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
749 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
752 * Copies the selected entries in the control to the clipboard. The entries
753 * are separated by newlines.
754 * \param dwCols the columns to copy. Each column is separated by a tab.
756 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
759 * If during the call to GetStatus() some Git:externals are found from different
760 * repositories than the first one checked, then this method returns TRUE.
762 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
765 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
767 BOOL
HasExternals() const {return m_bHasExternals
;}
770 * If unversioned files are found (but not necessarily shown) TRUE is returned.
772 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
775 * If there are any locks in the working copy, TRUE is returned
777 BOOL
HasLocks() const {return m_bHasLocks
;}
780 * If there are any change lists defined in the working copy, TRUE is returned
782 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
785 * Returns the file entry data for the list control index.
787 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
790 * Returns the file entry data for the specified path.
791 * \note The entry might not be shown in the list control.
793 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
796 * Returns the index of the list control entry with the specified path,
797 * or -1 if the path is not in the list control.
799 int GetIndex(const CTGitPath
& path
);
802 * Returns the file entry data for the specified path in the list control.
804 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
807 * Returns a String containing some statistics like number of modified, normal, deleted,...
810 CString
GetStatisticsString(bool simple
=false);
813 * Set a static control which will be updated automatically with
814 * the number of selected and total files shown in the list control.
816 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
819 * Set a tri-state checkbox which is updated automatically if the
820 * user checks/unchecks file entries in the list control to indicate
821 * if all files are checked, none are checked or some are checked.
823 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
826 * Set a button which is de-/activated automatically. The button is
827 * only set active if at least one item is selected.
829 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
832 * Select/unselect all entries in the list control.
833 * \param bSelect TRUE to check, FALSE to uncheck.
835 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
838 * Checks or unchecks all specified items
839 * \param dwCheck GITLC_SHOWxxx defines
840 * \param check if true matching items will be selected, false unchecks matching items
842 void Check(DWORD dwCheck
, bool check
= true);
844 /** Set a checkbox on an entry in the listbox
845 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
847 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
849 /** Write a list of the checked items' paths into a path list
851 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
853 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
854 * files/folders in the working copy.
855 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
856 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
858 * \remark Since an item can only be checked if it is visible/shown in the list control
859 * bShownOnly is automatically set to true if bCheckedOnly is true
861 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
864 * Returns the parent directory of all entries in the control.
865 * if \a bStrict is set to false, then the paths passed to the control
866 * to fetch the status (in GetStatus()) are used if possible.
868 CString
GetCommonDirectory(bool bStrict
);
871 * Returns the parent url of all entries in the control.
872 * if \a bStrict is set to false, then the paths passed to the control
873 * to fetch the status (in GetStatus()) are used if possible.
875 CTGitPath
GetCommonURL(bool bStrict
);
878 * Sets a pointer to a boolean variable which is checked periodically
879 * during the status fetching. As soon as the variable changes to true,
880 * the operations stops.
882 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
885 * Sets the string shown in the control while the status is fetched.
886 * If not set, it defaults to "please wait..."
888 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
889 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
892 * Sets the string shown in the control if no items are shown. This
893 * can happen for example if there's nothing modified and the unversioned
894 * files aren't shown either, so there's nothing to commit.
895 * If not set, it defaults to "file list is empty".
897 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
898 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
901 * Returns the number of selected items
903 LONG
GetSelected(){return m_nSelected
;};
906 * Enables dropping of files on the control.
908 bool EnableFileDrop();
911 * Checks if the path already exists in the list.
913 bool HasPath(const CTGitPath
& path
);
915 * Checks if the path is shown/visible in the list control.
917 bool IsPathShown(const CTGitPath
& path
);
919 * Forces the children to be checked when the parent folder is checked,
920 * and the parent folder to be unchecked if one of its children is unchecked.
922 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
925 * Allows checking the items if change lists are present. If set to false,
926 * items are not checked if at least one changelist is available.
928 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
930 * Returns the currently used show flags passed to the Show() method.
932 DWORD
GetShowFlags() {return m_dwShow
;}
935 CString
GetLastErrorMessage() {return m_sLastError
;}
937 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
939 LONG
GetUnversionedCount() { return m_nShownUnversioned
; }
940 LONG
GetModifiedCount() { return m_nShownModified
; }
941 LONG
GetAddedCount() { return m_nShownAdded
; }
942 LONG
GetDeletedCount() { return m_nShownDeleted
; }
943 LONG
GetConflictedCount() { return m_nShownConflicted
; }
944 LONG
GetFileCount() { return m_nShownFiles
; }
945 LONG
GetSubmoduleCount() { return m_nShownSubmodules
; }
947 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
949 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
951 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
953 bool m_amend
; ///< if true show the changes to the revision before the last commit
955 CString m_sUUID
; ///< the UUID of the associated repository
957 CString m_sDisplayedBranch
; ///< When on LogDialog, what is the current displayed branch
959 bool m_bIsRevertTheirMy
; ///< at rebase case, Their and My version is revert.
961 CWnd
*m_hwndLogicalParent
;
963 DECLARE_MESSAGE_MAP()
966 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
967 void SetHasCheckboxes(bool bHasCheckboxes
)
969 m_bHasCheckboxes
= bHasCheckboxes
;
970 DWORD exStyle
= GetExtendedStyle();
972 exStyle
|= LVS_EX_CHECKBOXES
;
974 exStyle
&= ~LVS_EX_CHECKBOXES
;
975 SetExtendedStyle(exStyle
);
979 void SaveColumnWidths(bool bSaveToRegistry
= false);
980 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
981 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
982 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
983 void StartDiff(int fileindex
); ///< start the external diff program
984 void StartDiffWC(int fileindex
); ///< start the external diff program
985 void StartDiffTwo(int fileindex
);
987 void SetGitIndexFlagsForSelectedFiles(UINT message
, BOOL assumevalid
, BOOL skipworktree
);
989 CString m_sMarkForDiffFilename
;
990 CString m_sMarkForDiffVersion
;
998 void OpenFile(CTGitPath
*path
,int mode
);
1000 /// Clear the status vector (contains custodial pointers)
1001 void ClearStatusArray();
1003 /// Sort predicate function - Compare the paths of two entries without regard to case
1004 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
1006 /// Predicate used to build a list of only the versioned entries of the FileEntry array
1007 //static bool IsEntryVersioned(const FileEntry* pEntry1);
1009 /// Look up the relevant show flags for a particular Git status value
1010 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
1012 /// Adjust the checkbox-state on all descendants of a specific item
1013 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
1015 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
1016 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
1018 /// Enables/Disables group view and adds all groups to the list control.
1019 /// If bForce is true, then group view is enabled and the 'null' group is added.
1020 bool PrepareGroups(bool bForce
= false);
1021 /// Returns the group number to which the group header belongs
1022 /// If the point is not over a group header, -1 is returned
1023 int GetGroupFromPoint(POINT
* ppt
);
1024 /// Returns the number of change lists the selection has
1025 size_t GetNumberOfChangelistsInSelection();
1027 /// Puts the item to the corresponding group
1028 bool SetItemGroup(int item
, int groupindex
);
1030 void CheckEntry(int index
, int nListItems
);
1031 void UncheckEntry(int index
, int nListItems
);
1033 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1035 CWnd
* GetLogicalParent() { return m_hwndLogicalParent
!= NULL
? m_hwndLogicalParent
: this->GetParent(); }
1037 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1038 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1039 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1040 bool CheckMultipleDiffs();
1042 void DeleteSelectedFiles();
1044 virtual void PreSubclassWindow();
1045 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1046 virtual BOOL
OnWndMsg(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pResult
);
1047 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1048 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1049 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1050 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1051 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1052 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1053 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1054 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1056 void CreateChangeList(const CString
& name
);
1058 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1059 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1060 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1061 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1062 afx_msg UINT
OnGetDlgCode();
1063 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1064 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1065 afx_msg
void OnPaint();
1066 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1067 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1068 afx_msg
void OnDestroy();
1072 void FileSaveAs(CTGitPath
*path
);
1073 int RevertSelectedItemToVersion(bool parent
= false);
1076 bool * m_pbCanceled
;
1077 bool m_bAscending
; ///< sort direction
1078 int m_nSortedColumn
; ///< which column to sort
1079 bool m_bHasCheckboxes
;
1081 bool m_bUnversionedLast
;
1082 bool m_bHasExternalsFromDifferentRepos
;
1083 bool m_bHasExternals
;
1084 BOOL m_bHasUnversionedItems
;
1086 bool m_bHasChangeLists
;
1087 //typedef std::vector<FileEntry*> FileEntryVector;
1088 //FileEntryVector m_arStatusArray;
1089 std::vector
<CTGitPath
*> m_arStatusArray
;
1090 std::vector
<size_t> m_arListArray
;
1091 std::map
<CString
, int> m_changelists
;
1092 bool m_bHasIgnoreGroup
;
1093 //CTGitPathList m_ConflictFileList;
1094 CTGitPathList m_StatusFileList
;
1095 CTGitPathList m_UnRevFileList
;
1096 CTGitPathList m_IgnoreFileList
;
1097 CTGitPathList m_LocalChangesIgnoredFileList
; // assume valid & skip worktree
1098 //CTGitPathList m_StatusUrlList;
1099 CString m_sLastError
;
1101 LONG m_nUnversioned
;
1110 LONG m_nLineDeleted
;
1113 LONG m_nShownUnversioned
;
1114 LONG m_nShownModified
;
1116 LONG m_nShownDeleted
;
1117 LONG m_nShownConflicted
;
1119 LONG m_nShownSubmodules
;
1121 DWORD m_dwDefaultColumns
;
1123 bool m_bShowFolders
;
1124 bool m_bShowIgnores
;
1126 unsigned __int64 m_dwContextMenus
;
1131 bool m_bIgnoreRemoveOnly
;
1132 bool m_bCheckIfGroupsExist
;
1133 bool m_bFileDropsEnabled
;
1139 CWnd
* m_pStatLabel
;
1140 CButton
* m_pSelectButton
;
1141 CButton
* m_pConfirmButton
;
1146 CString m_sNoPropValueText
;
1148 bool m_bCheckChildrenWithParent
;
1149 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1151 ColumnManager m_ColumnManager
;
1153 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember de-/selected items
1154 std::map
<CString
,bool> m_mapDirectFiles
;
1155 CComCriticalSection m_critSec
;
1157 CAutoLibrary m_ShellDll
;
1158 typedef HRESULT(WINAPI
* FNSHCreateDefaultContextMenu
) (const DEFCONTEXTMENU
*pdcm
, REFIID riid
, void **ppv
);
1159 FNSHCreateDefaultContextMenu pfnSHCreateDefaultContextMenu
;
1160 typedef HRESULT(WINAPI
* FNAssocCreateForClasses
) (const ASSOCIATIONELEMENT
*rgClasses
, ULONG cClasses
, REFIID riid
, void **ppv
);
1161 FNAssocCreateForClasses pfnAssocCreateForClasses
;
1163 friend class CGitStatusListCtrlDropTarget
;
1167 FILELIST_MODIFY
= 0x1,
1168 FILELIST_UNVER
= 0x2,
1169 FILELIST_IGNORE
=0x4,
1170 FILELIST_LOCALCHANGESIGNORED
= 0x8, // assume valid & skip worktree files
1173 int UpdateFileList(CTGitPathList
*List
= NULL
);
1175 int UpdateFileList(int mask
, bool once
=true,CTGitPathList
*List
=NULL
);
1176 int UpdateUnRevFileList(CTGitPathList
&list
);
1177 int UpdateUnRevFileList(CTGitPathList
*List
=NULL
);
1178 int UpdateIgnoreFileList(CTGitPathList
*List
=NULL
);
1179 int UpdateLocalChangesIgnoredFileList(CTGitPathList
* list
= nullptr);
1181 int UpdateWithGitPathList(CTGitPathList
&list
);
1183 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1186 git_revnum_t m_CurrentVersion
;
1187 bool m_bDoNotAutoselectSubmodules
;
1188 std::map
<CString
, CString
> m_restorepaths
;
1191 LPCONTEXTMENU m_pContextMenu
;
1195 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1198 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1200 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1201 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1203 CGitStatusListCtrl
* m_pGitStatusListCtrl
;