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_COLTEXTSTATUS 0x000000010
37 //#define SVNSLC_COLPROPSTATUS 0x000000020
38 //#define SVNSLC_COLAUTHOR 0x000000040
39 //#define SVNSLC_COLREVISION 0x000000080
40 //#define SVNSLC_COLDATE 0x000000100
41 //#define SVNSLC_COLMODIFICATIONDATE 0x000000200
42 #define GITSLC_COLADD 0x000000010
43 #define GITSLC_COLDEL 0x000000020
44 #define GITSLC_NUMCOLUMNS 6
46 //#define SVNSLC_COLREMOTESTATUS 0x000000010
47 //#define SVNSLC_COLREMOTETEXT 0x000000080
48 //#define SVNSLC_COLREMOTEPROP 0x000000100
49 //#define SVNSLC_COLURL 0x000000200
50 //#define SVNSLC_COLLOCK 0x000000400
51 //#define SVNSLC_COLLOCKCOMMENT 0x000000800
53 //#define SVNSLC_COLREMOTEREVISION 0x000004000
55 //#define SVNSLC_COLSVNNEEDSLOCK 0x000010000
56 //#define SVNSLC_COLCOPYFROM 0x000020000
58 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
59 #define GITSLC_SHOWNORMAL 0x000000000
60 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
61 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
62 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
63 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
64 #define GITSLC_SHOWMISSING 0x00000000
65 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
66 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
67 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
68 #define GITSLC_SHOWOBSTRUCTED 0x00000000
69 #define GITSLC_SHOWEXTERNAL 0x00000000
70 #define GITSLC_SHOWINCOMPLETE 0x00000000
71 #define GITSLC_SHOWINEXTERNALS 0x00000000
72 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
73 #define GITSLC_SHOWLOCKS 0x00000000
74 #define GITSLC_SHOWDIRECTFILES 0x00000000
75 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
76 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
77 #define GITSLC_SHOWSWITCHED 0x00000000
78 #define GITSLC_SHOWINCHANGELIST 0x00000000
80 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
83 #define GITSLC_SHOWVERSIONED (CTGitPath::LOGACTIONS_FORWORD|GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
84 GITSLC_SHOWADDED|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_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
90 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
91 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
92 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
93 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
95 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
96 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
97 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
98 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
100 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
101 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
102 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
103 GITSLC_SHOWINCOMPLETE)
105 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
107 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
108 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
109 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
110 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
111 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
112 #define GITSLC_POPUPDATE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UPDATE)
113 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
114 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
115 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
116 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
117 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
118 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
119 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
120 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
121 #define GITSLC_POPLOCK CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOCK)
122 #define GITSLC_POPUNLOCK CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNLOCK)
123 #define GITSLC_POPUNLOCKFORCE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNLOCKFORCE)
124 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
125 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
126 #define GITSLC_POPPROPERTIES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_PROPERTIES)
127 #define GITSLC_POPREPAIRMOVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REPAIRMOVE)
128 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
129 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
130 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
131 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)
132 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
134 #define GITSLC_IGNORECHANGELIST _T("ignore-on-commit")
136 // This gives up to 64 standard properties and menu entries
137 // plus 192 user-defined properties (should be plenty).
138 // User-defined properties will start at column SVNSLC_NUMCOLUMNS+1
139 // but in the registry, we will record them starting at SVNSLC_USERPROPCOLOFFSET.
141 #define GITSLC_USERPROPCOLOFFSET 0x40
142 #define GITSLC_USERPROPCOLLIMIT 0xff
143 #define GITSLC_MAXCOLUMNCOUNT 0xff
145 #define OVL_RESTORE 1
147 // Supporting extreamly long user props makes no sense here --
148 // especially for binary properties. CString uses a pool allocator
149 // that works for up to 256 chars. Make sure we are well below that.
151 #define GITSLC_MAXUSERPROPLENGTH 0x70
153 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
154 typedef CComCritSecLock
<CComCriticalSection
> Locker
;
156 class CGitStatusListCtrlDropTarget
;
159 * \ingroup TortoiseProc
160 * Helper class for CGitStatusListCtrl that represents
161 * the columns visible and their order as well as
162 * persisting that data in the registry.
164 * It assigns logical index values to the (potential) columns:
165 * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes
166 * GitSLC_USERPROPCOLOFFSET .. GitSLC_MAXCOLUMNCOUNT are user props.
168 * The column vector contains the columns that are actually
169 * available in the control.
171 * Since the set of userprops may change from one WC to another,
172 * we also store the settings (width and order) for those
173 * userprops that are not used in this WC.
175 * A userprop is considered "in use", if the respective column
176 * is not hidden or if at least one item has this property set.
182 /// construction / destruction
184 ColumnManager (CListCtrl
* control
) : control (control
) {};
187 DWORD m_dwDefaultColumns
;
190 void ReadSettings (DWORD defaultColumns
, DWORD hideColumns
, const CString
& containerName
, int ReadSettings
, int *withlist
=NULL
);
191 void WriteSettings() const;
193 /// read column definitions
195 int GetColumnCount() const; ///< total number of columns
196 bool IsVisible (int column
) const;
197 int GetInvisibleCount() const;
198 bool IsRelevant (int column
) const;
199 bool IsUserProp (int column
) const;
200 CString
GetName (int column
) const;
201 int SetNames(UINT
* buff
, int size
);
202 int GetWidth (int column
, bool useDefaults
= false) const;
203 int GetVisibleWidth (int column
, bool useDefaults
) const;
205 /// switch columns on and off
207 void SetVisible (int column
, bool visible
);
209 /// tracking column modifications
211 void ColumnMoved (int column
, int position
);
212 void ColumnResized (int column
);
214 /// call these to update the user-prop list
215 /// (will also auto-insert /-remove new list columns)
217 //void UpdateUserPropList (const std::vector<FileEntry*>& files);
218 //void UpdateRelevance ( const std::vector<FileEntry*>& files
219 // , const std::vector<size_t>& visibleFiles);
221 /// don't clutter the context menu with irrelevant prop info
223 bool AnyUnusedProperties() const;
224 void RemoveUnusedProps();
226 /// bring everything back to its "natural" order
228 void ResetColumns (DWORD defaultColumns
);
230 void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
232 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
233 if ( (header
!= NULL
)
234 && (header
->iItem
>= 0)
235 && (header
->iItem
< GetColumnCount()))
237 ColumnResized (header
->iItem
);
242 void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
244 LPNMHEADER header
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
246 if ( (header
!= NULL
)
247 && (header
->iItem
>= 0)
248 && (header
->iItem
< GetColumnCount())
249 // only allow the reordering if the column was not moved left of the first
250 // visible item - otherwise the 'invisible' columns are not at the far left
251 // anymore and we get all kinds of redrawing problems.
253 && (header
->pitem
->iOrder
> GetInvisibleCount()))
255 ColumnMoved (header
->iItem
, header
->pitem
->iOrder
);
260 void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
262 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
264 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= itemName
.size()))
267 if (IsVisible (phdr
->iItem
))
274 int OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
276 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
278 if ((phdr
->iItem
< 0)||(phdr
->iItem
>= itemName
.size()))
283 // visible columns may be modified
285 if (IsVisible (phdr
->iItem
))
290 // columns already marked as "invisible" internally may be (re-)sized to 0
292 if ( (phdr
->pitem
!= NULL
)
293 && (phdr
->pitem
->mask
== HDI_WIDTH
)
294 && (phdr
->pitem
->cxy
== 0))
299 if ( (phdr
->pitem
!= NULL
)
300 && (phdr
->pitem
->mask
!= HDI_WIDTH
))
308 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
, bool isGroundEnable
=false)
310 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)pWnd
;
311 if ((point
.x
== -1) && (point
.y
== -1))
314 pHeaderCtrl
->GetItemRect(0, &rect
);
315 pHeaderCtrl
->ClientToScreen(&rect
);
316 point
= rect
.CenterPoint();
320 if (popup
.CreatePopupMenu())
322 int columnCount
= GetColumnCount();
325 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
326 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
328 // build control menu
330 //temp.LoadString(IDS_STATUSLIST_SHOWGROUPS);
331 //popup.AppendMenu(isGroundEnable? uCheckedFlags : uUnCheckedFlags, columnCount, temp);
333 if (AnyUnusedProperties())
335 temp
.LoadString(IDS_STATUSLIST_REMOVEUNUSEDPROPS
);
336 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+1, temp
);
339 temp
.LoadString(IDS_STATUSLIST_RESETCOLUMNORDER
);
340 popup
.AppendMenu(uUnCheckedFlags
, columnCount
+2, temp
);
341 popup
.AppendMenu(MF_SEPARATOR
);
346 // user-prop columns:
347 // find relevant ones and sort 'em
349 std::map
<CString
, int> sortedProps
;
350 for (int i
= itemName
.size(); i
< columnCount
; ++i
)
352 sortedProps
[GetName(i
)] = i
;
354 if (!sortedProps
.empty())
356 // add 'em to the menu
358 popup
.AppendMenu(MF_SEPARATOR
);
360 typedef std::map
<CString
, int>::const_iterator CIT
;
361 for ( CIT iter
= sortedProps
.begin(), end
= sortedProps
.end()
365 popup
.AppendMenu ( IsVisible(iter
->second
)
373 // show menu & let user pick an entry
375 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, pWnd
, 0);
376 if ((cmd
>= 1)&&(cmd
< columnCount
))
378 SetVisible (cmd
, !IsVisible(cmd
));
380 else if (cmd
== columnCount
)
382 pWnd
->GetParent()->SendMessage(LVM_ENABLEGROUPVIEW
, !isGroundEnable
, NULL
);
383 //EnableGroupView(!isGroundEnable);
385 else if (cmd
== columnCount
+1)
389 else if (cmd
== columnCount
+2)
391 ResetColumns (m_dwDefaultColumns
);
396 void AddMenuItem(CMenu
*pop
)
398 UINT uCheckedFlags
= MF_STRING
| MF_ENABLED
| MF_CHECKED
;
399 UINT uUnCheckedFlags
= MF_STRING
| MF_ENABLED
;
401 for (int i
= 1; i
< itemName
.size(); ++i
)
404 pop
->AppendMenu ( IsVisible(i
)
413 /// initialization utilities
415 void ParseUserPropSettings ( const CString
& userPropList
416 , const CString
& shownUserProps
);
417 void ParseWidths (const CString
& widths
);
418 void SetStandardColumnVisibility (DWORD visibility
);
419 void ParseColumnOrder (const CString
& widths
);
421 /// map internal column order onto visible column order
422 /// (all invisibles in front)
424 std::vector
<int> GetGridColumnOrder();
425 void ApplyColumnOrder();
427 /// utilities used when writing data to the registry
429 DWORD
GetSelectedStandardColumns() const;
430 CString
GetUserPropList() const;
431 CString
GetShownUserProps() const;
432 CString
GetWidthString() const;
433 CString
GetColumnOrderString() const;
435 /// our parent control and its data
439 /// where to store in the registry
441 CString registryPrefix
;
443 /// all columns in their "natural" order
447 int index
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
450 bool relevant
; ///< set to @a visible, if no *shown* item has that property
453 std::vector
<ColumnInfo
> columns
;
455 /// user-defined properties
459 CString name
; ///< is a user prop when < GitSLC_USERPROPCOLOFFSET
463 std::vector
<UserProp
> userProps
;
465 /// stored result from last UpdateUserPropList() call
467 std::set
<CString
> itemProps
;
469 /// global column ordering including unused user props
471 std::vector
<int> columnOrder
;
473 std::vector
<int> itemName
;
478 * \ingroup TortoiseProc
479 * Simple utility class that defines the sort column order.
485 CSorter ( ColumnManager
* columnManager
489 bool operator() ( const CTGitPath
* entry1
490 , const CTGitPath
* entry2
) const;
492 static int A2L(const CString
&str
)
502 ColumnManager
* columnManager
;
509 * A List control, based on the MFC CListCtrl which shows a list of
510 * files with their Subversion status. The control also provides a context
511 * menu to do some Subversion tasks on the selected files.
513 * This is the main control used in many dialogs to show a list of files to
516 class CGitStatusListCtrl
:
531 IDGITLC_EDITCONFLICT
,
534 IDGITLC_RESOLVECONFLICT
,
538 IDGITLC_UNLOCKFORCE
,
541 IDGITLC_RESOLVETHEIRS
,
542 IDGITLC_RESOLVEMINE
,
549 IDGITLC_REMOVEFROMCS
,
551 IDGITLC_CREATEIGNORECS
,
553 IDGITLC_UNCHECKGROUP
,
554 IDGITLC_ADD_RECURSIVE
,
558 IDGITLC_REVERTTOREV
,
563 IDGITLC_COMPARETWOFILES
,
565 IDGITLC_CREATERESTORE
,
566 IDGITLC_RESTOREPATH
,
567 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
568 // the submenu items get command ID's sequent to this number
571 int GetColumnIndex(int colmask
);
572 static inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
574 * Sent to the parent window (using ::SendMessage) after a context menu
575 * command has finished if the item count has changed.
577 static const UINT GITSLNM_ITEMCOUNTCHANGED
;
579 * Sent to the parent window (using ::SendMessage) when the control needs
580 * to be refreshed. Since this is done usually in the parent window using
581 * a thread, this message is used to tell the parent to do exactly that.
583 static const UINT GITSLNM_NEEDSREFRESH
;
586 * Sent to the parent window (using ::SendMessage) when the user drops
587 * files on the control. The LPARAM is a pointer to a TCHAR string
588 * containing the dropped path.
590 static const UINT GITSLNM_ADDFILE
;
593 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
594 * one or more items in the control. The WPARAM contains the number of
595 * checked items in the control.
597 static const UINT GITSLNM_CHECKCHANGED
;
599 static const UINT GITSLNM_ITEMCHANGED
;
601 CGitStatusListCtrl(void);
602 ~CGitStatusListCtrl(void);
608 * \ingroup TortoiseProc
609 * Helper class for CGitStatusListCtrl which represents
610 * the data for each file shown.
616 FileEntry() : status(git_wc_status_unversioned
)
617 // , copyfrom_rev(GIT_REV_ZERO)
618 , last_commit_date(0)
619 , last_commit_rev(GIT_REV_ZERO
)
620 // , remoterev(GIT_REV_ZERO)
621 , textstatus(git_wc_status_unversioned
)
622 , propstatus(git_wc_status_unversioned
)
623 // , remotestatus(git_wc_status_unversioned)
624 // , remotetextstatus(git_wc_status_unversioned)
625 // , remotepropstatus(git_wc_status_unversioned)
629 , inunversionedfolder(false)
631 , differentrepo(false)
635 , Revision(GIT_REV_ZERO
)
636 , isConflicted(false)
639 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
641 // , depth(git_depth_unknown)
644 const CTGitPath
& GetPath() const
648 const bool IsChecked() const
652 CString
GetRelativeGitPath() const
654 if (path
.IsEquivalentTo(basepath
))
655 return path
.GetGitPathString();
656 return path
.GetGitPathString().Mid(basepath
.GetGitPathString().GetLength()+1);
658 // const bool IsLocked() const
660 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
662 // const bool HasNeedsLock() const
666 const bool IsFolder() const
670 const bool IsInExternal() const
674 const bool IsNested() const
678 const bool IsFromDifferentRepository() const
680 return differentrepo
;
682 CString
GetDisplayName() const
684 CString
const& chopped
= path
.GetDisplayString(&basepath
);
685 if (!chopped
.IsEmpty())
691 // "Display name" must not be empty.
692 return path
.GetFileOrDirectoryName();
695 CString
GetChangeList() const
699 // CString GetURL() const
704 git_wc_status_kind status
; ///< local status
705 git_wc_status_kind textstatus
; ///< local text status
706 git_wc_status_kind propstatus
; ///< local property status
709 CTGitPath path
; ///< full path of the file
710 CTGitPath basepath
; ///< common ancestor path of all files
712 CString changelist
; ///< the name of the changelist the item belongs to
714 CString last_commit_author
; ///< the author which last committed this item
715 CTime last_commit_date
; ///< the date when this item was last committed
716 git_revnum_t last_commit_rev
; ///< the revision where this item was last committed
718 git_revnum_t remoterev
; ///< the revision in HEAD of the repository
719 bool copied
; ///< if the file/folder is added-with-history
720 bool switched
; ///< if the file/folder is switched to another url
721 bool checked
; ///< if the file is checked in the list control
722 bool inunversionedfolder
; ///< if the file is inside an unversioned folder
723 bool inexternal
; ///< if the item is in an external folder
724 bool differentrepo
; ///< if the item is from a different repository than the rest
725 bool direct
; ///< directly included (TRUE) or just a child of a folder
726 bool isfolder
; ///< TRUE if entry refers to a folder
727 bool isNested
; ///< TRUE if the folder from a different repository and/or path
728 bool isConflicted
; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
729 bool needslock
; ///< TRUE if the Git:needs-lock property is set
730 git_revnum_t Revision
; ///< the base revision
731 // PropertyList present_props; ///< cacheable properties present in BASE
732 bool keeplocal
; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
733 git_depth_t depth
; ///< the depth of this entry
734 friend class CGitStatusListCtrl
;
735 friend class CGitStatusListCtrlDropTarget
;
736 friend class CSorter
;
741 * Initializes the control, sets up the columns.
742 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
743 * \param sColumnInfoContainer Name of a registry key
744 * where the position and visibility of each column
745 * is saved and used from. If the registry key
746 * doesn't exist, the default order is used
747 * and dwColumns tells which columns are visible.
748 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
749 * Use the GitSLC_POPxxx defines.
750 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
751 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
753 void Init(DWORD dwColumns
, const CString
& sColumnInfoContainer
, unsigned __int64 dwContextMenus
= ((GITSLC_POPALL
^ GITSLC_POPCOMMIT
) ^ GITSLC_POPRESTORE
), bool bHasCheckboxes
= true, bool bHasWC
= true);
755 * Sets a background image for the list control.
756 * The image is shown in the right bottom corner.
757 * \param nID the resource ID of the bitmap to use as the background
759 bool SetBackgroundImage(UINT nID
);
761 * Makes the 'ignore' context menu only ignore the files and not add the
762 * folder which gets the Git:ignore property changed to the list.
763 * This is needed e.g. for the Add-dialog, where the modified folder
764 * showing up would break the resulting "add" command.
766 void SetIgnoreRemoveOnly(bool bRemoveOnly
= true) {m_bIgnoreRemoveOnly
= bRemoveOnly
;}
768 * The unversioned items are by default shown after all other files in the list.
769 * If that behavior should be changed, set this value to false.
771 void PutUnversionedLast(bool bLast
) {m_bUnversionedLast
= bLast
;}
773 * Fetches the Subversion status of all files and stores the information
774 * about them in an internal array.
775 * \param sFilePath path to a file which contains a list of files and/or folders for which to
776 * fetch the status, separated by newlines.
777 * \param bUpdate TRUE if the remote status is requested too.
778 * \return TRUE on success.
780 BOOL
GetStatus ( const CTGitPathList
* pathList
=NULL
781 , bool bUpdate
= false
782 , bool bShowIgnores
= false
783 , bool bShowUnRev
=false
784 , bool bShowUserProps
= false);
787 * Populates the list control with the previously (with GetStatus) gathered status information.
788 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
789 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
791 void Show(unsigned int dwShow
, unsigned int dwCheck
= 0, bool bShowFolders
= true,BOOL updateStatusList
=FALSE
, bool UseStoredCheckStatus
=false);
792 void Show(unsigned int dwShow
, const CTGitPathList
& checkedList
, bool bShowFolders
= true);
795 * Copies the selected entries in the control to the clipboard. The entries
796 * are separated by newlines.
797 * \param dwCols the columns to copy. Each column is separated by a tab.
799 bool CopySelectedEntriesToClipboard(DWORD dwCols
);
802 * If during the call to GetStatus() some Git:externals are found from different
803 * repositories than the first one checked, then this method returns TRUE.
805 BOOL
HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos
;}
808 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
810 BOOL
HasExternals() const {return m_bHasExternals
;}
813 * If unversioned files are found (but not necessarily shown) TRUE is returned.
815 BOOL
HasUnversionedItems() {return m_bHasUnversionedItems
;}
818 * If there are any locks in the working copy, TRUE is returned
820 BOOL
HasLocks() const {return m_bHasLocks
;}
823 * If there are any change lists defined in the working copy, TRUE is returned
825 BOOL
HasChangeLists() const {return m_bHasChangeLists
;}
828 * Returns the file entry data for the list control index.
830 //CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);
833 * Returns the file entry data for the specified path.
834 * \note The entry might not be shown in the list control.
836 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
839 * Returns the index of the list control entry with the specified path,
840 * or -1 if the path is not in the list control.
842 int GetIndex(const CTGitPath
& path
);
845 * Returns the file entry data for the specified path in the list control.
847 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
850 * Returns a String containing some statistics like number of modified, normal, deleted,...
853 CString
GetStatisticsString(bool simple
=false);
856 * Set a static control which will be updated automatically with
857 * the number of selected and total files shown in the list control.
859 void SetStatLabel(CWnd
* pStatLabel
){m_pStatLabel
= pStatLabel
;};
862 * Set a tri-state checkbox which is updated automatically if the
863 * user checks/unchecks file entries in the list control to indicate
864 * if all files are checked, none are checked or some are checked.
866 void SetSelectButton(CButton
* pButton
) {m_pSelectButton
= pButton
;}
869 * Set a button which is de-/activated automatically. The button is
870 * only set active if at least one item is selected.
872 void SetConfirmButton(CButton
* pButton
) {m_pConfirmButton
= pButton
;}
875 * Select/unselect all entries in the list control.
876 * \param bSelect TRUE to check, FALSE to uncheck.
878 void SelectAll(bool bSelect
, bool bIncludeNoCommits
= false);
880 /** Set a checkbox on an entry in the listbox
881 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
883 void SetEntryCheck(CTGitPath
* pEntry
, int listboxIndex
, bool bCheck
);
885 /** Write a list of the checked items' paths into a path list
887 void WriteCheckedNamesToPathList(CTGitPathList
& pathList
);
889 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
890 * files/folders in the working copy.
891 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
892 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
894 * \remark Since an item can only be checked if it is visible/shown in the list control
895 * bShownOnly is automatically set to true if bCheckedOnly is true
897 void GetMinMaxRevisions(git_revnum_t
& rMin
, git_revnum_t
& rMax
, bool bShownOnly
, bool bCheckedOnly
);
900 * Returns the parent directory of all entries in the control.
901 * if \a bStrict is set to false, then the paths passed to the control
902 * to fetch the status (in GetStatus()) are used if possible.
904 CString
GetCommonDirectory(bool bStrict
);
907 * Returns the parent url of all entries in the control.
908 * if \a bStrict is set to false, then the paths passed to the control
909 * to fetch the status (in GetStatus()) are used if possible.
911 CTGitPath
GetCommonURL(bool bStrict
);
914 * Sets a pointer to a boolean variable which is checked periodically
915 * during the status fetching. As soon as the variable changes to true,
916 * the operations stops.
918 void SetCancelBool(bool * pbCanceled
) {m_pbCanceled
= pbCanceled
;}
921 * Sets the string shown in the control while the status is fetched.
922 * If not set, it defaults to "please wait..."
924 void SetBusyString(const CString
& str
) {m_sBusy
= str
;}
925 void SetBusyString(UINT id
) {m_sBusy
.LoadString(id
);}
928 * Sets the string shown in the control if no items are shown. This
929 * can happen for example if there's nothing modified and the unversioned
930 * files aren't shown either, so there's nothing to commit.
931 * If not set, it defaults to "file list is empty".
933 void SetEmptyString(const CString
& str
) {m_sEmpty
= str
;}
934 void SetEmptyString(UINT id
) {m_sEmpty
.LoadString(id
);}
937 * Returns the number of selected items
939 LONG
GetSelected(){return m_nSelected
;};
942 * Enables dropping of files on the control.
944 bool EnableFileDrop();
947 * Checks if the path already exists in the list.
949 bool HasPath(const CTGitPath
& path
);
951 * Checks if the path is shown/visible in the list control.
953 bool IsPathShown(const CTGitPath
& path
);
955 * Forces the children to be checked when the parent folder is checked,
956 * and the parent folder to be unchecked if one of its children is unchecked.
958 void CheckChildrenWithParent(bool bCheck
) {m_bCheckChildrenWithParent
= bCheck
;}
961 * Allows checking the items if change lists are present. If set to false,
962 * items are not checked if at least one changelist is available.
964 void CheckIfChangelistsArePresent(bool bCheck
) {m_bCheckIfGroupsExist
= bCheck
;}
966 * Returns the currently used show flags passed to the Show() method.
968 DWORD
GetShowFlags() {return m_dwShow
;}
971 CString
GetLastErrorMessage() {return m_sLastError
;}
973 void Block(BOOL block
, BOOL blockUI
) {m_bBlock
= block
; m_bBlockUI
= blockUI
;}
975 LONG m_nTargetCount
; ///< number of targets in the file passed to GetStatus()
977 CString m_sURL
; ///< the URL of the target or "(multiple targets)"
979 GitRev m_HeadRev
; ///< the HEAD revision of the repository if bUpdate was TRUE
981 bool m_amend
; ///< if true show the changes to the revision before the last commit
983 CString m_sUUID
; ///< the UUID of the associated repository
985 bool m_bIsRevertTheirMy
; ///< at rebase case, Their and My version is revert.
987 DECLARE_MESSAGE_MAP()
990 void SetBusy(bool b
) {m_bBusy
= b
; Invalidate();}
993 void SaveColumnWidths(bool bSaveToRegistry
= false);
994 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
995 void RemoveListEntry(int index
); ///< removes an entry from the listcontrol and both arrays
996 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
997 void StartDiff(int fileindex
); ///< start the external diff program
998 void StartDiffWC(int fileindex
); ///< start the external diff program
999 void StartDiffTwo(int fileindex
);
1007 void OpenFile(CTGitPath
*path
,int mode
);
1009 /// fetch all user properties for all items
1010 void FetchUserProperties();
1012 /// Process one line of the command file supplied to GetStatus
1013 bool FetchStatusForSingleTarget(GitConfig
& config
, GitStatus
& status
, const CTGitPath
& target
,
1014 bool bFetchStatusFromRepository
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
,
1015 bool bAllDirect
, git_depth_t depth
= git_depth_infinity
, bool bShowIgnores
= false);
1017 /// Create 'status' data for each item in an unversioned folder
1018 void AddUnversionedFolder(const CTGitPath
& strFolderName
, const CTGitPath
& strBasePath
, GitConfig
* config
);
1020 /// Read the all the other status items which result from a single GetFirstStatus call
1021 void ReadRemainingItemsStatus(GitStatus
& status
, const CTGitPath
& strBasePath
, CStringA
& strCurrentRepositoryUUID
, CTGitPathList
& arExtPaths
, GitConfig
* config
, bool bAllDirect
);
1023 /// Clear the status vector (contains custodial pointers)
1024 void ClearStatusArray();
1026 /// Sort predicate function - Compare the paths of two entries without regard to case
1027 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
1029 /// Predicate used to build a list of only the versioned entries of the FileEntry array
1030 //static bool IsEntryVersioned(const FileEntry* pEntry1);
1032 /// Look up the relevant show flags for a particular Git status value
1033 DWORD
GetShowFlagsFromGitStatus(git_wc_status_kind status
);
1035 /// Build a FileEntry item and add it to the FileEntry array
1036 //const FileEntry* AddNewFileEntry(
1037 // const git_wc_status2_t* pGitStatus, // The return from the Git GetStatus functions
1038 // const CTGitPath& path, // The path of the item we're adding
1039 // const CTGitPath& basePath, // The base directory for this status build
1040 // bool bDirectItem, // Was this item the first found by GetFirstFileStatus or by a subsequent GetNextFileStatus call
1041 // bool bInExternal, // Are we in an 'external' folder
1042 // bool bEntryfromDifferentRepo // if the entry is from a different repository
1045 /// Adjust the checkbox-state on all descendants of a specific item
1046 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
1048 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
1049 void FillListOfSelectedItemPaths(CTGitPathList
& pathList
, bool bNoIgnored
= false);
1051 /// Enables/Disables group view and adds all groups to the list control.
1052 /// If bForce is true, then group view is enabled and the 'null' group is added.
1053 bool PrepareGroups(bool bForce
= false);
1054 /// Returns the group number to which the group header belongs
1055 /// If the point is not over a group header, -1 is returned
1056 int GetGroupFromPoint(POINT
* ppt
);
1057 /// Returns the number of change lists the selection has
1058 size_t GetNumberOfChangelistsInSelection();
1060 /// Puts the item to the corresponding group
1061 bool SetItemGroup(int item
, int groupindex
);
1063 void CheckEntry(int index
, int nListItems
);
1064 void UncheckEntry(int index
, int nListItems
);
1066 /// sends an GitSLNM_CHECKCHANGED notification to the parent
1069 int CellRectFromPoint(CPoint
& point
, RECT
*cellrect
, int *col
) const;
1071 void OnContextMenuList(CWnd
* pWnd
, CPoint point
);
1072 void OnContextMenuGroup(CWnd
* pWnd
, CPoint point
);
1073 void OnContextMenuHeader(CWnd
* pWnd
, CPoint point
);
1075 virtual void PreSubclassWindow();
1076 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
1077 virtual INT_PTR
OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const;
1078 afx_msg
void OnBeginDrag(NMHDR
* pNMHDR
, LRESULT
* pResult
);
1079 afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
*pNMHDR
, LRESULT
*pResult
);
1080 afx_msg
void OnHdnItemclick(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1081 afx_msg
void OnLvnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1082 afx_msg BOOL
OnLvnItemchanged(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1083 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1084 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1085 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
1087 void CreateChangeList(const CString
& name
);
1089 afx_msg
void OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1090 afx_msg
void OnLvnGetInfoTip(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1091 afx_msg
void OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1092 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
1093 afx_msg UINT
OnGetDlgCode();
1094 afx_msg
void OnNMReturn(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1095 afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
1096 afx_msg
void OnPaint();
1097 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1098 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
1099 afx_msg
void OnDestroy();
1102 void FileSaveAs(CTGitPath
*path
);
1103 int RevertSelectedItemToVersion();
1106 bool * m_pbCanceled
;
1107 bool m_bAscending
; ///< sort direction
1108 int m_nSortedColumn
; ///< which column to sort
1109 bool m_bHasCheckboxes
;
1111 bool m_bUnversionedLast
;
1112 bool m_bHasExternalsFromDifferentRepos
;
1113 bool m_bHasExternals
;
1114 BOOL m_bHasUnversionedItems
;
1116 bool m_bHasChangeLists
;
1117 //typedef std::vector<FileEntry*> FileEntryVector;
1118 //FileEntryVector m_arStatusArray;
1119 std::vector
<CTGitPath
*> m_arStatusArray
;
1120 std::vector
<size_t> m_arListArray
;
1121 std::map
<CString
, int> m_changelists
;
1122 bool m_bHasIgnoreGroup
;
1123 //CTGitPathList m_ConflictFileList;
1124 CTGitPathList m_StatusFileList
;
1125 CTGitPathList m_UnRevFileList
;
1126 CTGitPathList m_IgnoreFileList
;
1127 //CTGitPathList m_StatusUrlList;
1128 CString m_sLastError
;
1130 LONG m_nUnversioned
;
1139 LONG m_nLineDeleted
;
1142 DWORD m_dwDefaultColumns
;
1144 bool m_bShowFolders
;
1145 bool m_bShowIgnores
;
1147 unsigned __int64 m_dwContextMenus
;
1152 bool m_bIgnoreRemoveOnly
;
1153 bool m_bCheckIfGroupsExist
;
1154 bool m_bFileDropsEnabled
;
1160 CWnd
* m_pStatLabel
;
1161 CButton
* m_pSelectButton
;
1162 CButton
* m_pConfirmButton
;
1167 CString m_sNoPropValueText
;
1169 bool m_bCheckChildrenWithParent
;
1170 CGitStatusListCtrlDropTarget
* m_pDropTarget
;
1172 ColumnManager m_ColumnManager
;
1174 std::map
<CString
,bool> m_mapFilenameToChecked
; ///< Remember manually de-/selected items
1175 CComCriticalSection m_critSec
;
1177 friend class CGitStatusListCtrlDropTarget
;
1181 FILELIST_MODIFY
= 0x1,
1182 FILELIST_UNVER
= 0x2,
1183 FILELIST_IGNORE
=0x4
1186 int UpdateFileList(git_revnum_t hash
,CTGitPathList
*List
=NULL
);
1187 int UpdateFileList(int mask
, bool once
=true,CTGitPathList
*List
=NULL
);
1188 int UpdateUnRevFileList(CTGitPathList
*List
=NULL
);
1189 int UpdateIgnoreFileList(CTGitPathList
*List
=NULL
);
1191 int UpdateWithGitPathList(CTGitPathList
&list
);
1193 void AddEntry(CTGitPath
* path
, WORD langID
, int ListIndex
);
1196 git_revnum_t m_CurrentVersion
;
1197 bool m_bDoNotAutoselectSubmodules
;
1198 std::map
<CString
, CString
> m_restorepaths
;
1202 class CGitStatusListCtrlDropTarget
: public CIDropTarget
1205 CGitStatusListCtrlDropTarget(CGitStatusListCtrl
* pGitStatusListCtrl
):CIDropTarget(pGitStatusListCtrl
->m_hWnd
){m_pGitStatusListCtrl
= pGitStatusListCtrl
;}
1207 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
, DWORD
* /*pdwEffect*/, POINTL pt
);
1208 virtual HRESULT STDMETHODCALLTYPE
DragOver(DWORD grfKeyState
, POINTL pt
, DWORD __RPC_FAR
*pdwEffect
);
1210 CGitStatusListCtrl
* m_pGitStatusListCtrl
;