1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2013 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "GitStatus.h"
25 #include "GitConfig.h"
27 #include "LoglistCommonResource.h"
28 #include "HintListCtrl.h"
30 #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)
32 // these defines must be in the order the columns are inserted!
33 #define GITSLC_COLFILENAME 0x000000002
34 #define GITSLC_COLEXT 0x000000004
35 #define GITSLC_COLSTATUS 0x000000008
36 //#define SVNSLC_COLAUTHOR 0x000000040
37 //#define SVNSLC_COLREVISION 0x000000080
38 //#define SVNSLC_COLDATE 0x000000100
39 #define GITSLC_COLADD 0x000000010
40 #define GITSLC_COLDEL 0x000000020
41 #define GITSLC_COLMODIFICATIONDATE 0x000000040
42 #define GITSLC_COLSIZE 0x000000080
43 #define GITSLC_NUMCOLUMNS 8
45 //#define SVNSLC_COLURL 0x000000200
46 //#define SVNSLC_COLCOPYFROM 0x000020000
48 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
49 #define GITSLC_SHOWNORMAL 0x00000000
50 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
51 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
52 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
53 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
54 #define GITSLC_SHOWMISSING 0x00000000
55 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
56 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
57 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
58 #define GITSLC_SHOWOBSTRUCTED 0x00000000
59 #define GITSLC_SHOWEXTERNAL 0x00000000
60 #define GITSLC_SHOWINCOMPLETE 0x00000000
61 #define GITSLC_SHOWINEXTERNALS 0x00000000
62 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
63 #define GITSLC_SHOWLOCKS 0x00000000
64 #define GITSLC_SHOWDIRECTFILES 0x04000000
65 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
66 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
67 #define GITSLC_SHOWSWITCHED 0x00000000
68 #define GITSLC_SHOWINCHANGELIST 0x00000000
69 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
70 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
72 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
74 #define GITSLC_SHOWFILES 0x01000000
75 #define GITSLC_SHOWSUBMODULES 0x02000000
76 #define GITSLC_SHOWEVERYTHING 0xffffffff
78 #define GITSLC_SHOWVERSIONED (CTGitPath::LOGACTIONS_FORWORD|GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
79 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
80 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
81 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
82 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
84 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
85 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
86 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
87 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
88 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
90 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
91 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
92 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
93 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
95 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
96 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
97 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
98 GITSLC_SHOWINCOMPLETE)
100 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
102 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
103 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
104 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
105 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
106 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
107 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
108 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
109 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
110 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
111 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
112 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
113 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
114 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
115 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
116 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
117 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
118 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
119 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
120 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
121 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)
122 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
123 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
124 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
125 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
127 #define GITSLC_IGNORECHANGELIST _T("ignore-on-commit")
129 // This gives up to 64 standard properties and menu entries
130 #define GITSLC_MAXCOLUMNCOUNT 0xff
132 #define OVL_RESTORE 1
134 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
135 typedef CComCritSecLock
<CComCriticalSection
> Locker
;
137 class CGitStatusListCtrlDropTarget
;
140 * \ingroup TortoiseProc
141 * Helper class for CGitStatusListCtrl that represents
142 * the columns visible and their order as well as
143 * persisting that data in the registry.
145 * It assigns logical index values to the (potential) columns:
146 * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes
148 * The column vector contains the columns that are actually
149 * available in the control.
156 /// construction / destruction
158 ColumnManager (CListCtrl
* control
) : control (control
), m_dwDefaultColumns(0) {};
161 DWORD m_dwDefaultColumns
;
164 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int *withlist
=NULL
);
165 void WriteSettings() const;
167 /// read column definitions
169 int GetColumnCount() const; ///< total number of columns
170 bool IsVisible (int column
) const;
171 int GetInvisibleCount() const;
172 bool IsRelevant (int column
) const;
173 CString
GetName (int column
) const;
174 int SetNames(UINT
* buff
, int size
);
175 int GetWidth (int column
, bool useDefaults
= false) const;
176 int GetVisibleWidth (int column
, bool useDefaults
) const;
178 /// switch columns on and off
180 void SetVisible (int column
, bool visible
);
182 /// tracking column modifications
184 void ColumnMoved (int column
, int position
);
185 void ColumnResized (int column
);
187 /// call these to update the user-prop list
188 /// (will also auto-insert /-remove new list columns)
190 /// don't clutter the context menu with irrelevant prop info
192 void RemoveUnusedProps();
194 /// bring everything back to its "natural" order
196 void ResetColumns (DWORD defaultColumns
);
198 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
200 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
201 if ( (header
!= NULL
)
202 && (header
->iItem
>= 0)
203 && (header
->iItem
< GetColumnCount()))
205 ColumnResized (header
->iItem
);
210 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
212 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
214 if ( (header
!= NULL
)
215 && (header
->iItem
>= 0)
216 && (header
->iItem
< GetColumnCount())
217 // only allow the reordering if the column was not moved left of the first
218 // visible item - otherwise the 'invisible' columns are not at the far left
219 // anymore and we get all kinds of redrawing problems.
221 && (header
->pitem
->iOrder
>= GetInvisibleCount()))
223 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
227 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
229 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
231 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
234 if (IsVisible (phdr
->iItem
))
241 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
243 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
245 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= (int)itemName
.size()))
250 // visible columns may be modified
252 if (IsVisible (phdr
->iItem
))
257 // columns already marked as "invisible" internally may be (re-)sized to 0
259 if ( (phdr
->pitem
!= NULL
)
260 && (phdr
->pitem
->mask
== HDI_WIDTH
)
261 && (phdr
->pitem
->cxy
== 0))
266 if ( (phdr
->pitem
!= NULL
)
267 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
275 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
277 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
278 if ((point
.x
== -1) && (point
.y
== -1))
281 pHeaderCtrl
->GetItemRect(0, &rect
);
282 pHeaderCtrl
->ClientToScreen(&rect
);
283 point
= rect
.CenterPoint();
287 if (popup
.CreatePopupMenu())
289 int columnCount
= GetColumnCount();
292 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
293 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
295 // build control menu
297 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
298 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
300 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
301 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
302 popup
.AppendMenu(MF_SEPARATOR
);
307 // user-prop columns:
308 // find relevant ones and sort 'em
310 std::map
<CString
, int> sortedProps
;
311 for (int i
= (int)itemName
.size(); i
< columnCount
; ++i
)
313 sortedProps
[GetName(i
)] = i
;
315 if (!sortedProps
.empty())
317 // add 'em to the menu
319 popup
.AppendMenu(MF_SEPARATOR
);
321 typedef std::map
<CString
, int>::const_iterator CIT
;
322 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
326 popup
.AppendMenu ( IsVisible(iter
->second
)
334 // show menu & let user pick an entry
336 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
337 if ((cmd
>= 1)&&(cmd
< columnCount
))
339 SetVisible (cmd
, !IsVisible(cmd
));
341 else if (cmd
== columnCount
)
343 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
344 //EnableGroupView(!isGroundEnable);
346 else if (cmd
== columnCount
+1)
350 else if (cmd
== columnCount
+2)
352 ResetColumns (m_dwDefaultColumns
);
357 void AddMenuItem(CMenu
*pop
)
359 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
360 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
362 for (int i
= 1; i
< (int)itemName
.size(); ++i
)
365 pop
->AppendMenu ( IsVisible(i
)
374 /// initialization utilities
376 void ParseWidths (const CString
& widths
);
377 void SetStandardColumnVisibility (DWORD visibility
);
378 void ParseColumnOrder (const CString
& widths
);
380 /// map internal column order onto visible column order
381 /// (all invisibles in front)
383 std::vector
<int> GetGridColumnOrder();
384 void ApplyColumnOrder();
386 /// utilities used when writing data to the registry
388 DWORD
GetSelectedStandardColumns() const;
389 CString
GetWidthString() const;
390 CString
GetColumnOrderString() const;
392 /// our parent control and its data
396 /// where to store in the registry
398 CString registryPrefix
;
400 /// all columns in their "natural" order
404 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
407 bool relevant
; ///< set to @a visible, if no *shown* item has that property
410 std::vector
<ColumnInfo
> columns
;
412 /// user-defined properties
414 std::set
<CString
> itemProps
;
416 /// global column ordering including unused user props
418 std::vector
<int> columnOrder
;
420 std::vector
<int> itemName
;
425 * \ingroup TortoiseProc
426 * Simple utility class that defines the sort column order.
432 CSorter ( ColumnManager
* columnManager
436 bool operator() ( const CTGitPath
* entry1
437 , const CTGitPath
* entry2
) const;
439 static int A2L(const CString
&str
)
449 ColumnManager
* columnManager
;
456 * A List control, based on the MFC CListCtrl which shows a list of
457 * files with their Subversion status. The control also provides a context
458 * menu to do some Subversion tasks on the selected files.
460 * This is the main control used in many dialogs to show a list of files to
463 class CGitStatusListCtrl
:
477 IDGITLC_LOGSUBMODULE
,
478 IDGITLC_EDITCONFLICT
,
480 IDGITLC_IGNOREFOLDER
,
482 IDGITLC_RESOLVECONFLICT
,
485 IDGITLC_RESOLVETHEIRS
,
486 IDGITLC_RESOLVEMINE
,
491 IDGITLC_REMOVEFROMCS
,
493 IDGITLC_CREATEIGNORECS
,
495 IDGITLC_UNCHECKGROUP
,
499 IDGITLC_REVERTTOREV
,
500 IDGITLC_REVERTTOPARENT
,
505 IDGITLC_COMPARETWOFILES
,
507 IDGITLC_CREATERESTORE
,
508 IDGITLC_RESTOREPATH
,
509 IDGITLC_ASSUMEVALID
,
510 IDGITLC_SKIPWORKTREE
,
512 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
513 // the submenu items get command ID's sequent to this number
516 int GetColumnIndex(int colmask
);
517 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
519 * Sent to the parent window (using ::SendMessage) after a context menu
520 * command has finished if the item count has changed.
522 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
524 * Sent to the parent window (using ::SendMessage) when the control needs
525 * to be refreshed. Since this is done usually in the parent window using
526 * a thread, this message is used to tell the parent to do exactly that.
528 static const UINT GITSLNM_NEEDSREFRESH
;
531 * Sent to the parent window (using ::SendMessage) when the user drops
532 * files on the control. The LPARAM is a pointer to a TCHAR string
533 * containing the dropped path.
535 static const UINT GITSLNM_ADDFILE
;
538 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
539 * one or more items in the control. The WPARAM contains the number of
540 * checked items in the control.
542 static const UINT GITSLNM_CHECKCHANGED
;
544 static const UINT GITSLNM_ITEMCHANGED
;
546 CGitStatusListCtrl(void);
547 ~CGitStatusListCtrl(void);
553 * \ingroup TortoiseProc
554 * Helper class for CGitStatusListCtrl which represents
555 * the data for each file shown.
561 FileEntry() : status(git_wc_status_unversioned
)
562 // , copyfrom_rev(GIT_REV_ZERO)
563 , last_commit_date(0)
564 , last_commit_rev(GIT_REV_ZERO
)
565 // , remoterev(GIT_REV_ZERO)
566 , textstatus(git_wc_status_unversioned
)
567 , propstatus(git_wc_status_unversioned
)
568 // , remotestatus(git_wc_status_unversioned)
569 // , remotetextstatus(git_wc_status_unversioned)
570 // , remotepropstatus(git_wc_status_unversioned)
574 , inunversionedfolder(false)
576 , differentrepo(false)
580 , Revision(GIT_REV_ZERO
)
581 , isConflicted(false)
584 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
586 // , depth(git_depth_unknown)
589 const CTGitPath
& GetPath() const
593 const bool IsChecked() const
597 CString
GetRelativeGitPath() const
599 if (path
.IsEquivalentTo(basepath
))
600 return path
.GetGitPathString();
601 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
603 // const bool IsLocked() const
605 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
607 // const bool HasNeedsLock() const
611 const bool IsFolder() const
615 const bool IsInExternal() const
619 const bool IsNested() const
623 const bool IsFromDifferentRepository() const
625 return differentrepo
;
627 CString
GetDisplayName() const
629 CString
const& chopped
= path
.GetDisplayString(&basepath
);
630 if (!chopped
.IsEmpty())
636 // "Display name" must not be empty.
637 return path
.GetFileOrDirectoryName();
640 CString
GetChangeList() const
644 // CString GetURL() const
649 git_wc_status_kind status
; ///< local status
650 git_wc_status_kind textstatus
; ///< local text status
651 git_wc_status_kind propstatus
; ///< local property status
654 CTGitPath path
; ///< full path of the file
655 CTGitPath basepath
; ///< common ancestor path of all files
657 CString changelist
; ///< the name of the changelist the item belongs to
659 CString last_commit_author
; ///< the author which last committed this item
660 CTime last_commit_date
; ///< the date when this item was last committed
661 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
663 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
664 bool copied
; ///< if the file/folder is added-with-history
665 bool switched
; ///< if the file/folder is switched to another url
666 bool checked
; ///< if the file is checked in the list control
667 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
668 bool inexternal
; ///< if the item is in an external folder
669 bool differentrepo
; ///< if the item is from a different repository than the rest
670 bool direct
; ///< directly included (TRUE) or just a child of a folder
671 bool isfolder
; ///< TRUE if entry refers to a folder
672 bool isNested
; ///< TRUE if the folder from a different repository and/or path
673 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
674 bool needslock
; ///< TRUE if the Git:needs-lock property is set
675 git_revnum_t Revision
; ///< the base revision
676 // PropertyList present_props; ///< cacheable properties present in BASE
677 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
678 git_depth_t depth
; ///< the depth of this entry
679 friend class CGitStatusListCtrl
;
680 friend class CGitStatusListCtrlDropTarget
;
681 friend class CSorter
;
686 * Initializes the control, sets up the columns.
687 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
688 * \param sColumnInfoContainer Name of a registry key
689 * where the position and visibility of each column
690 * is saved and used from. If the registry key
691 * doesn't exist, the default order is used
692 * and dwColumns tells which columns are visible.
693 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
694 * Use the GitSLC_POPxxx defines.
695 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
696 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
698 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);
700 * Sets a background image for the list control.
701 * The image is shown in the right bottom corner.
702 * \param nID the resource ID of the bitmap to use as the background
704 bool SetBackgroundImage(UINT nID
);
706 * Makes the 'ignore' context menu only ignore the files and not add the
707 * folder which gets the Git:ignore property changed to the list.
708 * This is needed e.g. for the Add-dialog, where the modified folder
709 * showing up would break the resulting "add" command.
711 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
713 * The unversioned items are by default shown after all other files in the list.
714 * If that behavior should be changed, set this value to false.
716 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
718 * Fetches the Subversion status of all files and stores the information
719 * about them in an internal array.
720 * \param sFilePath path to a file which contains a list of files and/or folders for which to
721 * fetch the status, separated by newlines.
722 * \param bUpdate TRUE if the remote status is requested too.
723 * \return TRUE on success.
725 BOOL
GetStatus ( const CTGitPathList
* pathList
=NULL
726 , bool bUpdate
= false
727 , bool bShowIgnores
= false
728 , bool bShowUnRev
= false
729 , bool bShowLocalChangesIgnored
= false);
732 * Populates the list control with the previously (with GetStatus) gathered status information.
733 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
734 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
736 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
737 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
740 * Copies the selected entries in the control to the clipboard. The entries
741 * are separated by newlines.
742 * \param dwCols the columns to copy. Each column is separated by a tab.
744 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
747 * If during the call to GetStatus() some Git:externals are found from different
748 * repositories than the first one checked, then this method returns TRUE.
750 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
753 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
755 BOOL
HasExternals() const {return m_bHasExternals
;}
758 * If unversioned files are found (but not necessarily shown) TRUE is returned.
760 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
763 * If there are any locks in the working copy, TRUE is returned
765 BOOL
HasLocks() const {return m_bHasLocks
;}
768 * If there are any change lists defined in the working copy, TRUE is returned
770 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
773 * Returns the file entry data for the list control index.
775 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
778 * Returns the file entry data for the specified path.
779 * \note The entry might not be shown in the list control.
781 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
784 * Returns the index of the list control entry with the specified path,
785 * or -1 if the path is not in the list control.
787 int GetIndex(const CTGitPath
& path
);
790 * Returns the file entry data for the specified path in the list control.
792 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
795 * Returns a String containing some statistics like number of modified, normal, deleted,...
798 CString
GetStatisticsString(bool simple
=false);
801 * Set a static control which will be updated automatically with
802 * the number of selected and total files shown in the list control.
804 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
807 * Set a tri-state checkbox which is updated automatically if the
808 * user checks/unchecks file entries in the list control to indicate
809 * if all files are checked, none are checked or some are checked.
811 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
814 * Set a button which is de-/activated automatically. The button is
815 * only set active if at least one item is selected.
817 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
820 * Select/unselect all entries in the list control.
821 * \param bSelect TRUE to check, FALSE to uncheck.
823 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
826 * Checks or unchecks all specified items
827 * \param dwCheck GITLC_SHOWxxx defines
828 * \param check if true matching items will be selected, false unchecks matching items
830 void Check(DWORD dwCheck
, bool check
= true);
832 /** Set a checkbox on an entry in the listbox
833 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
835 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
837 /** Write a list of the checked items' paths into a path list
839 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
841 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
842 * files/folders in the working copy.
843 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
844 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
846 * \remark Since an item can only be checked if it is visible/shown in the list control
847 * bShownOnly is automatically set to true if bCheckedOnly is true
849 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
852 * Returns the parent directory of all entries in the control.
853 * if \a bStrict is set to false, then the paths passed to the control
854 * to fetch the status (in GetStatus()) are used if possible.
856 CString
GetCommonDirectory(bool bStrict
);
859 * Returns the parent url of all entries in the control.
860 * if \a bStrict is set to false, then the paths passed to the control
861 * to fetch the status (in GetStatus()) are used if possible.
863 CTGitPath
GetCommonURL(bool bStrict
);
866 * Sets a pointer to a boolean variable which is checked periodically
867 * during the status fetching. As soon as the variable changes to true,
868 * the operations stops.
870 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
873 * Sets the string shown in the control while the status is fetched.
874 * If not set, it defaults to "please wait..."
876 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
877 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
880 * Sets the string shown in the control if no items are shown. This
881 * can happen for example if there's nothing modified and the unversioned
882 * files aren't shown either, so there's nothing to commit.
883 * If not set, it defaults to "file list is empty".
885 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
886 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
889 * Returns the number of selected items
891 LONG
GetSelected(){return m_nSelected
;};
894 * Enables dropping of files on the control.
896 bool EnableFileDrop();
899 * Checks if the path already exists in the list.
901 bool HasPath(const CTGitPath
& path
);
903 * Checks if the path is shown/visible in the list control.
905 bool IsPathShown(const CTGitPath
& path
);
907 * Forces the children to be checked when the parent folder is checked,
908 * and the parent folder to be unchecked if one of its children is unchecked.
910 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
913 * Allows checking the items if change lists are present. If set to false,
914 * items are not checked if at least one changelist is available.
916 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
918 * Returns the currently used show flags passed to the Show() method.
920 DWORD
GetShowFlags() {return m_dwShow
;}
923 CString
GetLastErrorMessage() {return m_sLastError
;}
925 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
927 LONG
GetUnversionedCount() { return m_nShownUnversioned
; }
928 LONG
GetModifiedCount() { return m_nShownModified
; }
929 LONG
GetAddedCount() { return m_nShownAdded
; }
930 LONG
GetDeletedCount() { return m_nShownDeleted
; }
931 LONG
GetConflictedCount() { return m_nShownConflicted
; }
932 LONG
GetFileCount() { return m_nShownFiles
; }
933 LONG
GetSubmoduleCount() { return m_nShownSubmodules
; }
935 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
937 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
939 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
941 bool m_amend
; ///< if true show the changes to the revision before the last commit
943 CString m_sUUID
; ///< the UUID of the associated repository
945 bool m_bIsRevertTheirMy
; ///< at rebase case, Their and My version is revert.
947 CWnd
*m_hwndLogicalParent
;
949 DECLARE_MESSAGE_MAP()
952 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
953 void SetHasCheckboxes(bool bHasCheckboxes
)
955 m_bHasCheckboxes
= bHasCheckboxes
;
956 DWORD exStyle
= GetExtendedStyle();
958 exStyle
|= LVS_EX_CHECKBOXES
;
960 exStyle
&= ~LVS_EX_CHECKBOXES
;
961 SetExtendedStyle(exStyle
);
965 void SaveColumnWidths(bool bSaveToRegistry
= false);
966 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
967 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
968 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
969 void StartDiff(int fileindex
); ///< start the external diff program
970 void StartDiffWC(int fileindex
); ///< start the external diff program
971 void StartDiffTwo(int fileindex
);
979 void OpenFile(CTGitPath
*path
,int mode
);
981 /// Process one line of the command file supplied to GetStatus
982 bool FetchStatusForSingleTarget(GitConfig
& config
, GitStatus
& status
, const CTGitPath
& target
,
983 bool bFetchStatusFromRepository
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
,
984 bool bAllDirect
, git_depth_t depth
= git_depth_infinity
, bool bShowIgnores
= false);
986 /// Create 'status' data for each item in an unversioned folder
987 void AddUnversionedFolder(const CTGitPath
& strFolderName
, const CTGitPath
& strBasePath
, GitConfig
* config
);
989 /// Read the all the other status items which result from a single GetFirstStatus call
990 void ReadRemainingItemsStatus(GitStatus
& status
, const CTGitPath
& strBasePath
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
, GitConfig
* config
, bool bAllDirect
);
992 /// Clear the status vector (contains custodial pointers)
993 void ClearStatusArray();
995 /// Sort predicate function - Compare the paths of two entries without regard to case
996 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
998 /// Predicate used to build a list of only the versioned entries of the FileEntry array
999 //static bool IsEntryVersioned(const FileEntry* pEntry1);
1001 /// Look up the relevant show flags for a particular Git status value
1002 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
1004 /// Adjust the checkbox-state on all descendants of a specific item
1005 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
1007 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
1008 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
1010 /// Enables/Disables group view and adds all groups to the list control.
1011 /// If bForce is true, then group view is enabled and the 'null' group is added.
1012 bool PrepareGroups(bool bForce
= false);
1013 /// Returns the group number to which the group header belongs
1014 /// If the point is not over a group header, -1 is returned
1015 int GetGroupFromPoint(POINT
* ppt
);
1016 /// Returns the number of change lists the selection has
1017 size_t GetNumberOfChangelistsInSelection();
1019 /// Puts the item to the corresponding group
1020 bool SetItemGroup(int item
, int groupindex
);
1022 void CheckEntry(int index
, int nListItems
);
1023 void UncheckEntry(int index
, int nListItems
);
1025 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1027 CWnd
* GetLogicalParent() { return m_hwndLogicalParent
!= NULL
? m_hwndLogicalParent
: this->GetParent(); }
1029 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1030 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1031 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1032 bool CheckMultipleDiffs();
1034 void DeleteSelectedFiles();
1036 virtual void PreSubclassWindow();
1037 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1038 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1039 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1040 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1041 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1042 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1043 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1044 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1045 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1047 void CreateChangeList(const CString
& name
);
1049 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1050 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1051 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1052 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1053 afx_msg UINT
OnGetDlgCode();
1054 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1055 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1056 afx_msg
void OnPaint();
1057 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1058 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1059 afx_msg
void OnDestroy();
1063 void FileSaveAs(CTGitPath
*path
);
1064 int RevertSelectedItemToVersion(bool parent
= false);
1067 bool * m_pbCanceled
;
1068 bool m_bAscending
; ///< sort direction
1069 int m_nSortedColumn
; ///< which column to sort
1070 bool m_bHasCheckboxes
;
1072 bool m_bUnversionedLast
;
1073 bool m_bHasExternalsFromDifferentRepos
;
1074 bool m_bHasExternals
;
1075 BOOL m_bHasUnversionedItems
;
1077 bool m_bHasChangeLists
;
1078 //typedef std::vector<FileEntry*> FileEntryVector;
1079 //FileEntryVector m_arStatusArray;
1080 std::vector
<CTGitPath
*> m_arStatusArray
;
1081 std::vector
<size_t> m_arListArray
;
1082 std::map
<CString
, int> m_changelists
;
1083 bool m_bHasIgnoreGroup
;
1084 //CTGitPathList m_ConflictFileList;
1085 CTGitPathList m_StatusFileList
;
1086 CTGitPathList m_UnRevFileList
;
1087 CTGitPathList m_IgnoreFileList
;
1088 CTGitPathList m_LocalChangesIgnoredFileList
; // assume valid & skip worktree
1089 //CTGitPathList m_StatusUrlList;
1090 CString m_sLastError
;
1092 LONG m_nUnversioned
;
1101 LONG m_nLineDeleted
;
1104 LONG m_nShownUnversioned
;
1105 LONG m_nShownModified
;
1107 LONG m_nShownDeleted
;
1108 LONG m_nShownConflicted
;
1110 LONG m_nShownSubmodules
;
1112 DWORD m_dwDefaultColumns
;
1114 bool m_bShowFolders
;
1115 bool m_bShowIgnores
;
1117 unsigned __int64 m_dwContextMenus
;
1122 bool m_bIgnoreRemoveOnly
;
1123 bool m_bCheckIfGroupsExist
;
1124 bool m_bFileDropsEnabled
;
1130 CWnd
* m_pStatLabel
;
1131 CButton
* m_pSelectButton
;
1132 CButton
* m_pConfirmButton
;
1137 CString m_sNoPropValueText
;
1139 bool m_bCheckChildrenWithParent
;
1140 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1142 ColumnManager m_ColumnManager
;
1144 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember de-/selected items
1145 std::map
<CString
,bool> m_mapDirectFiles
;
1146 CComCriticalSection m_critSec
;
1148 friend class CGitStatusListCtrlDropTarget
;
1152 FILELIST_MODIFY
= 0x1,
1153 FILELIST_UNVER
= 0x2,
1154 FILELIST_IGNORE
=0x4,
1155 FILELIST_LOCALCHANGESIGNORED
= 0x8, // assume valid & skip worktree files
1158 int UpdateFileList(git_revnum_t hash
,CTGitPathList
*List
=NULL
);
1159 int UpdateFileList(int mask
, bool once
=true,CTGitPathList
*List
=NULL
);
1160 int UpdateUnRevFileList(CTGitPathList
&list
);
1161 int UpdateUnRevFileList(CTGitPathList
*List
=NULL
);
1162 int UpdateIgnoreFileList(CTGitPathList
*List
=NULL
);
1163 int UpdateLocalChangesIgnoredFileList(CTGitPathList
* list
= nullptr);
1165 int UpdateWithGitPathList(CTGitPathList
&list
);
1167 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1170 git_revnum_t m_CurrentVersion
;
1171 bool m_bDoNotAutoselectSubmodules
;
1172 std::map
<CString
, CString
> m_restorepaths
;
1176 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1179 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1181 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1182 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1184 CGitStatusListCtrl
* m_pGitStatusListCtrl
;