1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
5 // Copyright (C) 2010-2012 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 0x00000000
65 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
66 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
67 #define GITSLC_SHOWSWITCHED 0x00000000
68 #define GITSLC_SHOWINCHANGELIST 0x00000000
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_COMPARETWO)
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)
125 #define GITSLC_IGNORECHANGELIST _T("ignore-on-commit")
127 // This gives up to 64 standard properties and menu entries
128 #define GITSLC_MAXCOLUMNCOUNT 0xff
130 #define OVL_RESTORE 1
132 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
133 typedef CComCritSecLock
<CComCriticalSection
> Locker
;
135 class CGitStatusListCtrlDropTarget
;
138 * \ingroup TortoiseProc
139 * Helper class for CGitStatusListCtrl that represents
140 * the columns visible and their order as well as
141 * persisting that data in the registry.
143 * It assigns logical index values to the (potential) columns:
144 * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes
146 * The column vector contains the columns that are actually
147 * available in the control.
154 /// construction / destruction
156 ColumnManager (CListCtrl
* control
) : control (control
), m_dwDefaultColumns(0) {};
159 DWORD m_dwDefaultColumns
;
162 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int *withlist
=NULL
);
163 void WriteSettings() const;
165 /// read column definitions
167 int GetColumnCount() const; ///< total number of columns
168 bool IsVisible (int column
) const;
169 int GetInvisibleCount() const;
170 bool IsRelevant (int column
) const;
171 CString
GetName (int column
) const;
172 int SetNames(UINT
* buff
, int size
);
173 int GetWidth (int column
, bool useDefaults
= false) const;
174 int GetVisibleWidth (int column
, bool useDefaults
) const;
176 /// switch columns on and off
178 void SetVisible (int column
, bool visible
);
180 /// tracking column modifications
182 void ColumnMoved (int column
, int position
);
183 void ColumnResized (int column
);
185 /// call these to update the user-prop list
186 /// (will also auto-insert /-remove new list columns)
188 /// don't clutter the context menu with irrelevant prop info
190 void RemoveUnusedProps();
192 /// bring everything back to its "natural" order
194 void ResetColumns (DWORD defaultColumns
);
196 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
198 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
199 if ( (header
!= NULL
)
200 && (header
->iItem
>= 0)
201 && (header
->iItem
< GetColumnCount()))
203 ColumnResized (header
->iItem
);
208 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
210 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
212 if ( (header
!= NULL
)
213 && (header
->iItem
>= 0)
214 && (header
->iItem
< GetColumnCount())
215 // only allow the reordering if the column was not moved left of the first
216 // visible item - otherwise the 'invisible' columns are not at the far left
217 // anymore and we get all kinds of redrawing problems.
219 && (header
->pitem
->iOrder
>= GetInvisibleCount()))
221 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
225 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
227 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
229 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= itemName
.size()))
232 if (IsVisible (phdr
->iItem
))
239 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
241 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
243 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= itemName
.size()))
248 // visible columns may be modified
250 if (IsVisible (phdr
->iItem
))
255 // columns already marked as "invisible" internally may be (re-)sized to 0
257 if ( (phdr
->pitem
!= NULL
)
258 && (phdr
->pitem
->mask
== HDI_WIDTH
)
259 && (phdr
->pitem
->cxy
== 0))
264 if ( (phdr
->pitem
!= NULL
)
265 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
273 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
275 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
276 if ((point
.x
== -1) && (point
.y
== -1))
279 pHeaderCtrl
->GetItemRect(0, &rect
);
280 pHeaderCtrl
->ClientToScreen(&rect
);
281 point
= rect
.CenterPoint();
285 if (popup
.CreatePopupMenu())
287 int columnCount
= GetColumnCount();
290 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
291 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
293 // build control menu
295 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
296 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
298 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
299 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
300 popup
.AppendMenu(MF_SEPARATOR
);
305 // user-prop columns:
306 // find relevant ones and sort 'em
308 std::map
<CString
, int> sortedProps
;
309 for (int i
= (int)itemName
.size(); i
< columnCount
; ++i
)
311 sortedProps
[GetName(i
)] = i
;
313 if (!sortedProps
.empty())
315 // add 'em to the menu
317 popup
.AppendMenu(MF_SEPARATOR
);
319 typedef std::map
<CString
, int>::const_iterator CIT
;
320 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
324 popup
.AppendMenu ( IsVisible(iter
->second
)
332 // show menu & let user pick an entry
334 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
335 if ((cmd
>= 1)&&(cmd
< columnCount
))
337 SetVisible (cmd
, !IsVisible(cmd
));
339 else if (cmd
== columnCount
)
341 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
342 //EnableGroupView(!isGroundEnable);
344 else if (cmd
== columnCount
+1)
348 else if (cmd
== columnCount
+2)
350 ResetColumns (m_dwDefaultColumns
);
355 void AddMenuItem(CMenu
*pop
)
357 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
358 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
360 for (int i
= 1; i
< itemName
.size(); ++i
)
363 pop
->AppendMenu ( IsVisible(i
)
372 /// initialization utilities
374 void ParseWidths (const CString
& widths
);
375 void SetStandardColumnVisibility (DWORD visibility
);
376 void ParseColumnOrder (const CString
& widths
);
378 /// map internal column order onto visible column order
379 /// (all invisibles in front)
381 std::vector
<int> GetGridColumnOrder();
382 void ApplyColumnOrder();
384 /// utilities used when writing data to the registry
386 DWORD
GetSelectedStandardColumns() const;
387 CString
GetWidthString() const;
388 CString
GetColumnOrderString() const;
390 /// our parent control and its data
394 /// where to store in the registry
396 CString registryPrefix
;
398 /// all columns in their "natural" order
402 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
405 bool relevant
; ///< set to @a visible, if no *shown* item has that property
408 std::vector
<ColumnInfo
> columns
;
410 /// user-defined properties
412 std::set
<CString
> itemProps
;
414 /// global column ordering including unused user props
416 std::vector
<int> columnOrder
;
418 std::vector
<int> itemName
;
423 * \ingroup TortoiseProc
424 * Simple utility class that defines the sort column order.
430 CSorter ( ColumnManager
* columnManager
434 bool operator() ( const CTGitPath
* entry1
435 , const CTGitPath
* entry2
) const;
437 static int A2L(const CString
&str
)
447 ColumnManager
* columnManager
;
454 * A List control, based on the MFC CListCtrl which shows a list of
455 * files with their Subversion status. The control also provides a context
456 * menu to do some Subversion tasks on the selected files.
458 * This is the main control used in many dialogs to show a list of files to
461 class CGitStatusListCtrl
:
475 IDGITLC_LOGSUBMODULE
,
476 IDGITLC_EDITCONFLICT
,
479 IDGITLC_RESOLVECONFLICT
,
482 IDGITLC_RESOLVETHEIRS
,
483 IDGITLC_RESOLVEMINE
,
488 IDGITLC_REMOVEFROMCS
,
490 IDGITLC_CREATEIGNORECS
,
492 IDGITLC_UNCHECKGROUP
,
496 IDGITLC_REVERTTOREV
,
501 IDGITLC_COMPARETWOFILES
,
503 IDGITLC_CREATERESTORE
,
504 IDGITLC_RESTOREPATH
,
505 IDGITLC_ASSUMEVALID
,
506 IDGITLC_SKIPWORKTREE
,
508 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
509 // the submenu items get command ID's sequent to this number
512 int GetColumnIndex(int colmask
);
513 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
515 * Sent to the parent window (using ::SendMessage) after a context menu
516 * command has finished if the item count has changed.
518 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
520 * Sent to the parent window (using ::SendMessage) when the control needs
521 * to be refreshed. Since this is done usually in the parent window using
522 * a thread, this message is used to tell the parent to do exactly that.
524 static const UINT GITSLNM_NEEDSREFRESH
;
527 * Sent to the parent window (using ::SendMessage) when the user drops
528 * files on the control. The LPARAM is a pointer to a TCHAR string
529 * containing the dropped path.
531 static const UINT GITSLNM_ADDFILE
;
534 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
535 * one or more items in the control. The WPARAM contains the number of
536 * checked items in the control.
538 static const UINT GITSLNM_CHECKCHANGED
;
540 static const UINT GITSLNM_ITEMCHANGED
;
542 CGitStatusListCtrl(void);
543 ~CGitStatusListCtrl(void);
549 * \ingroup TortoiseProc
550 * Helper class for CGitStatusListCtrl which represents
551 * the data for each file shown.
557 FileEntry() : status(git_wc_status_unversioned
)
558 // , copyfrom_rev(GIT_REV_ZERO)
559 , last_commit_date(0)
560 , last_commit_rev(GIT_REV_ZERO
)
561 // , remoterev(GIT_REV_ZERO)
562 , textstatus(git_wc_status_unversioned
)
563 , propstatus(git_wc_status_unversioned
)
564 // , remotestatus(git_wc_status_unversioned)
565 // , remotetextstatus(git_wc_status_unversioned)
566 // , remotepropstatus(git_wc_status_unversioned)
570 , inunversionedfolder(false)
572 , differentrepo(false)
576 , Revision(GIT_REV_ZERO
)
577 , isConflicted(false)
580 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
582 // , depth(git_depth_unknown)
585 const CTGitPath
& GetPath() const
589 const bool IsChecked() const
593 CString
GetRelativeGitPath() const
595 if (path
.IsEquivalentTo(basepath
))
596 return path
.GetGitPathString();
597 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
599 // const bool IsLocked() const
601 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
603 // const bool HasNeedsLock() const
607 const bool IsFolder() const
611 const bool IsInExternal() const
615 const bool IsNested() const
619 const bool IsFromDifferentRepository() const
621 return differentrepo
;
623 CString
GetDisplayName() const
625 CString
const& chopped
= path
.GetDisplayString(&basepath
);
626 if (!chopped
.IsEmpty())
632 // "Display name" must not be empty.
633 return path
.GetFileOrDirectoryName();
636 CString
GetChangeList() const
640 // CString GetURL() const
645 git_wc_status_kind status
; ///< local status
646 git_wc_status_kind textstatus
; ///< local text status
647 git_wc_status_kind propstatus
; ///< local property status
650 CTGitPath path
; ///< full path of the file
651 CTGitPath basepath
; ///< common ancestor path of all files
653 CString changelist
; ///< the name of the changelist the item belongs to
655 CString last_commit_author
; ///< the author which last committed this item
656 CTime last_commit_date
; ///< the date when this item was last committed
657 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
659 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
660 bool copied
; ///< if the file/folder is added-with-history
661 bool switched
; ///< if the file/folder is switched to another url
662 bool checked
; ///< if the file is checked in the list control
663 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
664 bool inexternal
; ///< if the item is in an external folder
665 bool differentrepo
; ///< if the item is from a different repository than the rest
666 bool direct
; ///< directly included (TRUE) or just a child of a folder
667 bool isfolder
; ///< TRUE if entry refers to a folder
668 bool isNested
; ///< TRUE if the folder from a different repository and/or path
669 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
670 bool needslock
; ///< TRUE if the Git:needs-lock property is set
671 git_revnum_t Revision
; ///< the base revision
672 // PropertyList present_props; ///< cacheable properties present in BASE
673 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
674 git_depth_t depth
; ///< the depth of this entry
675 friend class CGitStatusListCtrl
;
676 friend class CGitStatusListCtrlDropTarget
;
677 friend class CSorter
;
682 * Initializes the control, sets up the columns.
683 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
684 * \param sColumnInfoContainer Name of a registry key
685 * where the position and visibility of each column
686 * is saved and used from. If the registry key
687 * doesn't exist, the default order is used
688 * and dwColumns tells which columns are visible.
689 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
690 * Use the GitSLC_POPxxx defines.
691 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
692 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
694 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);
696 * Sets a background image for the list control.
697 * The image is shown in the right bottom corner.
698 * \param nID the resource ID of the bitmap to use as the background
700 bool SetBackgroundImage(UINT nID
);
702 * Makes the 'ignore' context menu only ignore the files and not add the
703 * folder which gets the Git:ignore property changed to the list.
704 * This is needed e.g. for the Add-dialog, where the modified folder
705 * showing up would break the resulting "add" command.
707 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
709 * The unversioned items are by default shown after all other files in the list.
710 * If that behavior should be changed, set this value to false.
712 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
714 * Fetches the Subversion status of all files and stores the information
715 * about them in an internal array.
716 * \param sFilePath path to a file which contains a list of files and/or folders for which to
717 * fetch the status, separated by newlines.
718 * \param bUpdate TRUE if the remote status is requested too.
719 * \return TRUE on success.
721 BOOL
GetStatus ( const CTGitPathList
* pathList
=NULL
722 , bool bUpdate
= false
723 , bool bShowIgnores
= false
724 , bool bShowUnRev
=false);
727 * Populates the list control with the previously (with GetStatus) gathered status information.
728 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
729 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
731 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
732 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
735 * Copies the selected entries in the control to the clipboard. The entries
736 * are separated by newlines.
737 * \param dwCols the columns to copy. Each column is separated by a tab.
739 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
742 * If during the call to GetStatus() some Git:externals are found from different
743 * repositories than the first one checked, then this method returns TRUE.
745 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
748 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
750 BOOL
HasExternals() const {return m_bHasExternals
;}
753 * If unversioned files are found (but not necessarily shown) TRUE is returned.
755 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
758 * If there are any locks in the working copy, TRUE is returned
760 BOOL
HasLocks() const {return m_bHasLocks
;}
763 * If there are any change lists defined in the working copy, TRUE is returned
765 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
768 * Returns the file entry data for the list control index.
770 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
773 * Returns the file entry data for the specified path.
774 * \note The entry might not be shown in the list control.
776 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
779 * Returns the index of the list control entry with the specified path,
780 * or -1 if the path is not in the list control.
782 int GetIndex(const CTGitPath
& path
);
785 * Returns the file entry data for the specified path in the list control.
787 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
790 * Returns a String containing some statistics like number of modified, normal, deleted,...
793 CString
GetStatisticsString(bool simple
=false);
796 * Set a static control which will be updated automatically with
797 * the number of selected and total files shown in the list control.
799 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
802 * Set a tri-state checkbox which is updated automatically if the
803 * user checks/unchecks file entries in the list control to indicate
804 * if all files are checked, none are checked or some are checked.
806 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
809 * Set a button which is de-/activated automatically. The button is
810 * only set active if at least one item is selected.
812 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
815 * Select/unselect all entries in the list control.
816 * \param bSelect TRUE to check, FALSE to uncheck.
818 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
821 * Checks or unchecks all specified items
822 * \param dwCheck GITLC_SHOWxxx defines
823 * \param check if true matching items will be selected, false unchecks matching items
825 void Check(DWORD dwCheck
, bool check
= true);
827 /** Set a checkbox on an entry in the listbox
828 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
830 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
832 /** Write a list of the checked items' paths into a path list
834 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
836 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
837 * files/folders in the working copy.
838 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
839 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
841 * \remark Since an item can only be checked if it is visible/shown in the list control
842 * bShownOnly is automatically set to true if bCheckedOnly is true
844 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
847 * Returns the parent directory of all entries in the control.
848 * if \a bStrict is set to false, then the paths passed to the control
849 * to fetch the status (in GetStatus()) are used if possible.
851 CString
GetCommonDirectory(bool bStrict
);
854 * Returns the parent url of all entries in the control.
855 * if \a bStrict is set to false, then the paths passed to the control
856 * to fetch the status (in GetStatus()) are used if possible.
858 CTGitPath
GetCommonURL(bool bStrict
);
861 * Sets a pointer to a boolean variable which is checked periodically
862 * during the status fetching. As soon as the variable changes to true,
863 * the operations stops.
865 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
868 * Sets the string shown in the control while the status is fetched.
869 * If not set, it defaults to "please wait..."
871 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
872 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
875 * Sets the string shown in the control if no items are shown. This
876 * can happen for example if there's nothing modified and the unversioned
877 * files aren't shown either, so there's nothing to commit.
878 * If not set, it defaults to "file list is empty".
880 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
881 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
884 * Returns the number of selected items
886 LONG
GetSelected(){return m_nSelected
;};
889 * Enables dropping of files on the control.
891 bool EnableFileDrop();
894 * Checks if the path already exists in the list.
896 bool HasPath(const CTGitPath
& path
);
898 * Checks if the path is shown/visible in the list control.
900 bool IsPathShown(const CTGitPath
& path
);
902 * Forces the children to be checked when the parent folder is checked,
903 * and the parent folder to be unchecked if one of its children is unchecked.
905 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
908 * Allows checking the items if change lists are present. If set to false,
909 * items are not checked if at least one changelist is available.
911 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
913 * Returns the currently used show flags passed to the Show() method.
915 DWORD
GetShowFlags() {return m_dwShow
;}
918 CString
GetLastErrorMessage() {return m_sLastError
;}
920 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
922 LONG
GetUnversionedCount() { return m_nShownUnversioned
; }
923 LONG
GetModifiedCount() { return m_nShownModified
; }
924 LONG
GetAddedCount() { return m_nShownAdded
; }
925 LONG
GetDeletedCount() { return m_nShownDeleted
; }
926 LONG
GetConflictedCount() { return m_nShownConflicted
; }
927 LONG
GetFileCount() { return m_nShownFiles
; }
928 LONG
GetSubmoduleCount() { return m_nShownSubmodules
; }
930 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
932 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
934 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
936 bool m_amend
; ///< if true show the changes to the revision before the last commit
938 CString m_sUUID
; ///< the UUID of the associated repository
940 bool m_bIsRevertTheirMy
; ///< at rebase case, Their and My version is revert.
942 CWnd
*m_hwndLogicalParent
;
944 DECLARE_MESSAGE_MAP()
947 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
950 void SaveColumnWidths(bool bSaveToRegistry
= false);
951 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
952 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
953 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
954 void StartDiff(int fileindex
); ///< start the external diff program
955 void StartDiffWC(int fileindex
); ///< start the external diff program
956 void StartDiffTwo(int fileindex
);
964 void OpenFile(CTGitPath
*path
,int mode
);
966 /// Process one line of the command file supplied to GetStatus
967 bool FetchStatusForSingleTarget(GitConfig
& config
, GitStatus
& status
, const CTGitPath
& target
,
968 bool bFetchStatusFromRepository
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
,
969 bool bAllDirect
, git_depth_t depth
= git_depth_infinity
, bool bShowIgnores
= false);
971 /// Create 'status' data for each item in an unversioned folder
972 void AddUnversionedFolder(const CTGitPath
& strFolderName
, const CTGitPath
& strBasePath
, GitConfig
* config
);
974 /// Read the all the other status items which result from a single GetFirstStatus call
975 void ReadRemainingItemsStatus(GitStatus
& status
, const CTGitPath
& strBasePath
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
, GitConfig
* config
, bool bAllDirect
);
977 /// Clear the status vector (contains custodial pointers)
978 void ClearStatusArray();
980 /// Sort predicate function - Compare the paths of two entries without regard to case
981 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
983 /// Predicate used to build a list of only the versioned entries of the FileEntry array
984 //static bool IsEntryVersioned(const FileEntry* pEntry1);
986 /// Look up the relevant show flags for a particular Git status value
987 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
989 /// Adjust the checkbox-state on all descendants of a specific item
990 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
992 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
993 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
995 /// Enables/Disables group view and adds all groups to the list control.
996 /// If bForce is true, then group view is enabled and the 'null' group is added.
997 bool PrepareGroups(bool bForce
= false);
998 /// Returns the group number to which the group header belongs
999 /// If the point is not over a group header, -1 is returned
1000 int GetGroupFromPoint(POINT
* ppt
);
1001 /// Returns the number of change lists the selection has
1002 size_t GetNumberOfChangelistsInSelection();
1004 /// Puts the item to the corresponding group
1005 bool SetItemGroup(int item
, int groupindex
);
1007 void CheckEntry(int index
, int nListItems
);
1008 void UncheckEntry(int index
, int nListItems
);
1010 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1012 CWnd
* GetLogicalParent() { return m_hwndLogicalParent
!= NULL
? m_hwndLogicalParent
: this->GetParent(); }
1014 int CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const;
1016 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1017 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1018 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1020 virtual void PreSubclassWindow();
1021 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1022 virtual INT_PTR
OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const;
1023 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1024 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1025 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1026 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1027 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1028 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1029 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1030 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1032 void CreateChangeList(const CString
& name
);
1034 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1035 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1036 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1037 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1038 afx_msg UINT
OnGetDlgCode();
1039 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1040 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1041 afx_msg
void OnPaint();
1042 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1043 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1044 afx_msg
void OnDestroy();
1048 void FileSaveAs(CTGitPath
*path
);
1049 int RevertSelectedItemToVersion();
1052 bool * m_pbCanceled
;
1053 bool m_bAscending
; ///< sort direction
1054 int m_nSortedColumn
; ///< which column to sort
1055 bool m_bHasCheckboxes
;
1057 bool m_bUnversionedLast
;
1058 bool m_bHasExternalsFromDifferentRepos
;
1059 bool m_bHasExternals
;
1060 BOOL m_bHasUnversionedItems
;
1062 bool m_bHasChangeLists
;
1063 //typedef std::vector<FileEntry*> FileEntryVector;
1064 //FileEntryVector m_arStatusArray;
1065 std::vector
<CTGitPath
*> m_arStatusArray
;
1066 std::vector
<size_t> m_arListArray
;
1067 std::map
<CString
, int> m_changelists
;
1068 bool m_bHasIgnoreGroup
;
1069 //CTGitPathList m_ConflictFileList;
1070 CTGitPathList m_StatusFileList
;
1071 CTGitPathList m_UnRevFileList
;
1072 CTGitPathList m_IgnoreFileList
;
1073 //CTGitPathList m_StatusUrlList;
1074 CString m_sLastError
;
1076 LONG m_nUnversioned
;
1085 LONG m_nLineDeleted
;
1088 LONG m_nShownUnversioned
;
1089 LONG m_nShownModified
;
1091 LONG m_nShownDeleted
;
1092 LONG m_nShownConflicted
;
1094 LONG m_nShownSubmodules
;
1096 DWORD m_dwDefaultColumns
;
1098 bool m_bShowFolders
;
1099 bool m_bShowIgnores
;
1101 unsigned __int64 m_dwContextMenus
;
1106 bool m_bIgnoreRemoveOnly
;
1107 bool m_bCheckIfGroupsExist
;
1108 bool m_bFileDropsEnabled
;
1114 CWnd
* m_pStatLabel
;
1115 CButton
* m_pSelectButton
;
1116 CButton
* m_pConfirmButton
;
1121 CString m_sNoPropValueText
;
1123 bool m_bCheckChildrenWithParent
;
1124 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1126 ColumnManager m_ColumnManager
;
1128 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember de-/selected items
1129 CComCriticalSection m_critSec
;
1131 friend class CGitStatusListCtrlDropTarget
;
1135 FILELIST_MODIFY
= 0x1,
1136 FILELIST_UNVER
= 0x2,
1137 FILELIST_IGNORE
=0x4
1140 int UpdateFileList(git_revnum_t hash
,CTGitPathList
*List
=NULL
);
1141 int UpdateFileList(int mask
, bool once
=true,CTGitPathList
*List
=NULL
);
1142 int UpdateUnRevFileList(CTGitPathList
&list
);
1143 int UpdateUnRevFileList(CTGitPathList
*List
=NULL
);
1144 int UpdateIgnoreFileList(CTGitPathList
*List
=NULL
);
1146 int UpdateWithGitPathList(CTGitPathList
&list
);
1148 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1151 git_revnum_t m_CurrentVersion
;
1152 bool m_bDoNotAutoselectSubmodules
;
1153 std::map
<CString
, CString
> m_restorepaths
;
1157 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1160 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1162 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1163 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1165 CGitStatusListCtrl
* m_pGitStatusListCtrl
;