Use set instead of map<T, bool>
[TortoiseGit.git] / src / Git / GitStatusListCtrl.h
blobcb7f6ad40c43056882043dd91bac8565c85be213
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "TGitPath.h"
22 #include "GitStatus.h"
23 #include "GitRev.h"
24 #include "Colors.h"
25 #include "ResizableColumnsListCtrl.h"
26 #include "DragDropImpl.h"
28 #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)
30 // these defines must be in the order the columns are inserted!
31 #define GITSLC_COLFILENAME 0x000000002
32 #define GITSLC_COLEXT 0x000000004
33 #define GITSLC_COLSTATUS 0x000000008
34 //#define SVNSLC_COLAUTHOR 0x000000040
35 //#define SVNSLC_COLREVISION 0x000000080
36 //#define SVNSLC_COLDATE 0x000000100
37 #define GITSLC_COLADD 0x000000010
38 #define GITSLC_COLDEL 0x000000020
39 #define GITSLC_COLMODIFICATIONDATE 0x000000040
40 #define GITSLC_COLSIZE 0x000000080
41 #define GITSLC_NUMCOLUMNS 8
43 //#define SVNSLC_COLURL 0x000000200
44 //#define SVNSLC_COLCOPYFROM 0x000020000
46 #define GITSLC_SHOWUNVERSIONED CTGitPath::LOGACTIONS_UNVER
47 #define GITSLC_SHOWNORMAL 0x00000000
48 #define GITSLC_SHOWMODIFIED (CTGitPath::LOGACTIONS_MODIFIED)
49 #define GITSLC_SHOWADDED (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY)
50 #define GITSLC_SHOWREMOVED CTGitPath::LOGACTIONS_DELETED
51 #define GITSLC_SHOWCONFLICTED CTGitPath::LOGACTIONS_UNMERGED
52 #define GITSLC_SHOWMISSING 0x00000000
53 #define GITSLC_SHOWREPLACED CTGitPath::LOGACTIONS_REPLACED
54 #define GITSLC_SHOWMERGED CTGitPath::LOGACTIONS_MERGED
55 #define GITSLC_SHOWIGNORED CTGitPath::LOGACTIONS_IGNORE
56 #define GITSLC_SHOWOBSTRUCTED 0x00000000
57 #define GITSLC_SHOWEXTERNAL 0x00000000
58 #define GITSLC_SHOWINCOMPLETE 0x00000000
59 #define GITSLC_SHOWINEXTERNALS 0x00000000
60 #define GITSLC_SHOWREMOVEDANDPRESENT 0x00000000
61 #define GITSLC_SHOWLOCKS 0x00000000
62 #define GITSLC_SHOWDIRECTFILES 0x04000000
63 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
64 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
65 #define GITSLC_SHOWSWITCHED 0x00000000
66 #define GITSLC_SHOWINCHANGELIST 0x00000000
67 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
68 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
70 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
72 #define GITSLC_SHOWFILES 0x01000000
73 #define GITSLC_SHOWSUBMODULES 0x02000000
74 #define GITSLC_SHOWEVERYTHING 0xffffffff
76 #define GITSLC_SHOWVERSIONED (GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
77 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
78 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
79 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
80 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
82 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
83 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
84 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
85 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
86 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
88 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
89 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
90 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
91 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
93 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
94 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
95 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
96 GITSLC_SHOWINCOMPLETE)
98 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
100 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
101 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
102 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
103 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
104 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
105 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
106 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
107 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
108 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
109 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
110 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
111 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
112 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
113 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
114 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
115 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
116 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
117 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
118 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
119 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOFILES)
120 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
121 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
122 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
123 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
124 #define GITLC_POPUNSETIGNORELOCALCHANGES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNSETIGNORELOCALCHANGES)
125 #define GITSLC_PREPAREDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_PREPAREDIFF)
127 #define GITSLC_IGNORECHANGELIST L"ignore-on-commit"
129 #define OVL_RESTORE 1
131 typedef int (__cdecl *GENERICCOMPAREFN)(const void * elem1, const void * elem2);
132 typedef CComCritSecLock<CComCriticalSection> Locker;
134 class CGitStatusListCtrlDropTarget;
137 * \ingroup TortoiseProc
138 * Simple utility class that defines the sort column order.
140 class CSorter
142 public:
144 CSorter ( ColumnManager* columnManager
145 , int sortedColumn
146 , bool ascending);
148 bool operator() ( const CTGitPath* entry1
149 , const CTGitPath* entry2) const;
151 static int A2L(const CString &str)
153 if (str == L"-")
154 return -1;
156 return _wtol(str);
159 private:
161 ColumnManager* columnManager;
162 int sortedColumn;
163 bool ascending;
167 * \ingroup SVN
168 * A List control, based on the MFC CListCtrl which shows a list of
169 * files with their git status. The control also provides a context
170 * menu to do some git tasks on the selected files.
172 * This is the main control used in many dialogs to show a list of files to
173 * work on.
175 class CGitStatusListCtrl :
176 public CResizableColumnsListCtrl<CListCtrl>
178 public:
179 enum
181 IDGITLC_REVERT = 1,
182 /** Compare with base version. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
183 IDGITLC_COMPARE,
184 IDGITLC_OPEN,
185 IDGITLC_DELETE,
186 IDGITLC_IGNORE,
187 /** Compare with base version and generate unified diff. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
188 IDGITLC_GNUDIFF1 ,
189 IDGITLC_LOG ,
190 IDGITLC_LOGOLDNAME,
191 IDGITLC_LOGSUBMODULE,
192 IDGITLC_EDITCONFLICT ,
193 IDGITLC_IGNOREMASK ,
194 IDGITLC_IGNOREFOLDER ,
195 IDGITLC_ADD ,
196 IDGITLC_RESOLVECONFLICT ,
197 IDGITLC_OPENWITH ,
198 IDGITLC_EXPLORE ,
199 IDGITLC_RESOLVETHEIRS ,
200 IDGITLC_RESOLVEMINE ,
201 IDGITLC_REMOVE ,
202 IDGITLC_COMMIT ,
203 IDGITLC_COPY ,
204 IDGITLC_COPYEXT ,
205 IDGITLC_REMOVEFROMCS ,
206 IDGITLC_CREATECS ,
207 IDGITLC_CREATEIGNORECS ,
208 IDGITLC_CHECKGROUP ,
209 IDGITLC_UNCHECKGROUP ,
210 /** Compare current version and working tree */
211 IDGITLC_COMPAREWC ,
212 IDGITLC_BLAME ,
213 IDGITLC_SAVEAS ,
214 IDGITLC_REVERTTOREV ,
215 IDGITLC_REVERTTOPARENT ,
216 IDGITLC_VIEWREV ,
217 IDGITLC_FINDENTRY ,
218 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
219 IDGITLC_COMPARETWOREVISIONS,
220 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
221 IDGITLC_GNUDIFF2REVISIONS,
222 /** Compare two selected files */
223 IDGITLC_COMPARETWOFILES ,
224 IDGITLC_POPRESTORE ,
225 IDGITLC_CREATERESTORE ,
226 IDGITLC_RESTOREPATH ,
227 IDGITLC_ASSUMEVALID ,
228 IDGITLC_SKIPWORKTREE ,
229 IDGITLC_EXPORT ,
230 IDGITLC_UNSETIGNORELOCALCHANGES,
231 IDGITLC_PREPAREDIFF ,
232 IDGITLC_PREPAREDIFF_COMPARE,
233 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
234 // the submenu items get command ID's sequent to this number
235 IDGITLC_MOVETOCS ,
237 int GetColumnIndex(int colmask);
238 static inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}
240 * Sent to the parent window (using ::SendMessage) after a context menu
241 * command has finished if the item count has changed.
243 static const UINT GITSLNM_ITEMCOUNTCHANGED;
245 * Sent to the parent window (using ::SendMessage) when the control needs
246 * to be refreshed. Since this is done usually in the parent window using
247 * a thread, this message is used to tell the parent to do exactly that.
249 static const UINT GITSLNM_NEEDSREFRESH;
252 * Sent to the parent window (using ::SendMessage) when the user drops
253 * files on the control. The LPARAM is a pointer to a TCHAR string
254 * containing the dropped path.
256 static const UINT GITSLNM_ADDFILE;
259 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
260 * one or more items in the control. The WPARAM contains the number of
261 * checked items in the control.
263 static const UINT GITSLNM_CHECKCHANGED;
265 static const UINT GITSLNM_ITEMCHANGED;
267 CGitStatusListCtrl(void);
268 ~CGitStatusListCtrl(void);
270 CString m_Rev1;
271 CString m_Rev2;
274 * \ingroup TortoiseProc
275 * Helper class for CGitStatusListCtrl which represents
276 * the data for each file shown.
278 #if 0
279 class FileEntry
281 public:
282 FileEntry() : status(git_wc_status_unversioned)
283 // , copyfrom_rev(GIT_REV_ZERO)
284 , last_commit_date(0)
285 , last_commit_rev(GIT_REV_ZERO)
286 // , remoterev(GIT_REV_ZERO)
287 , textstatus(git_wc_status_unversioned)
288 , propstatus(git_wc_status_unversioned)
289 // , remotestatus(git_wc_status_unversioned)
290 // , remotetextstatus(git_wc_status_unversioned)
291 // , remotepropstatus(git_wc_status_unversioned)
292 , copied(false)
293 , switched(false)
294 , checked(false)
295 , inunversionedfolder(false)
296 , inexternal(false)
297 , differentrepo(false)
298 , direct(false)
299 , isfolder(false)
300 , isNested(false)
301 , Revision(GIT_REV_ZERO)
302 , isConflicted(false)
303 // , present_props()
304 , needslock(false)
305 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
306 , keeplocal(false)
307 // , depth(git_depth_unknown)
310 const CTGitPath& GetPath() const
312 return path;
314 const bool IsChecked() const
316 return checked;
318 CString GetRelativeGitPath() const
320 if (path.IsEquivalentTo(basepath))
321 return path.GetGitPathString();
322 return path.GetGitPathString().Mid(basepath.GetGitPathString().GetLength()+1);
324 // const bool IsLocked() const
325 // {
326 // return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());
327 // }
328 // const bool HasNeedsLock() const
329 // {
330 // return needslock;
331 // }
332 const bool IsFolder() const
334 return isfolder;
336 const bool IsInExternal() const
338 return inexternal;
340 const bool IsNested() const
342 return isNested;
344 const bool IsFromDifferentRepository() const
346 return differentrepo;
348 CString GetDisplayName() const
350 CString const& chopped = path.GetDisplayString(&basepath);
351 if (!chopped.IsEmpty())
353 return chopped;
355 else
357 // "Display name" must not be empty.
358 return path.GetFileOrDirectoryName();
361 CString GetChangeList() const
363 return changelist;
365 // CString GetURL() const
366 // {
367 // return url;
368 // }
369 public:
370 git_wc_status_kind status; ///< local status
371 git_wc_status_kind textstatus; ///< local text status
372 git_wc_status_kind propstatus; ///< local property status
374 private:
375 CTGitPath path; ///< full path of the file
376 CTGitPath basepath; ///< common ancestor path of all files
378 CString changelist; ///< the name of the changelist the item belongs to
380 CString last_commit_author; ///< the author which last committed this item
381 CTime last_commit_date; ///< the date when this item was last committed
382 git_revnum_t last_commit_rev; ///< the revision where this item was last committed
384 git_revnum_t remoterev; ///< the revision in HEAD of the repository
385 bool copied; ///< if the file/folder is added-with-history
386 bool switched; ///< if the file/folder is switched to another url
387 bool checked; ///< if the file is checked in the list control
388 bool inunversionedfolder; ///< if the file is inside an unversioned folder
389 bool inexternal; ///< if the item is in an external folder
390 bool differentrepo; ///< if the item is from a different repository than the rest
391 bool direct; ///< directly included (TRUE) or just a child of a folder
392 bool isfolder; ///< TRUE if entry refers to a folder
393 bool isNested; ///< TRUE if the folder from a different repository and/or path
394 bool isConflicted; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
395 bool needslock; ///< TRUE if the Git:needs-lock property is set
396 git_revnum_t Revision; ///< the base revision
397 // PropertyList present_props; ///< cacheable properties present in BASE
398 bool keeplocal; ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed
399 git_depth_t depth; ///< the depth of this entry
400 friend class CGitStatusListCtrl;
401 friend class CGitStatusListCtrlDropTarget;
402 friend class CSorter;
404 #endif
407 * Initializes the control, sets up the columns.
408 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
409 * \param sColumnInfoContainer Name of a registry key
410 * where the position and visibility of each column
411 * is saved and used from. If the registry key
412 * doesn't exist, the default order is used
413 * and dwColumns tells which columns are visible.
414 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
415 * Use the GitSLC_POPxxx defines.
416 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
417 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
419 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);
421 * Sets a background image for the list control.
422 * The image is shown in the right bottom corner.
423 * \param nID the resource ID of the bitmap to use as the background
425 bool SetBackgroundImage(UINT nID);
426 private:
427 UINT m_nBackgroundImageID;
428 public:
430 * Makes the 'ignore' context menu only ignore the files and not add the
431 * folder which gets the Git:ignore property changed to the list.
432 * This is needed e.g. for the Add-dialog, where the modified folder
433 * showing up would break the resulting "add" command.
435 void SetIgnoreRemoveOnly(bool bRemoveOnly = true) {m_bIgnoreRemoveOnly = bRemoveOnly;}
437 * The unversioned items are by default shown after all other files in the list.
438 * If that behavior should be changed, set this value to false.
440 void PutUnversionedLast(bool bLast) {m_bUnversionedLast = bLast;}
442 * Fetches the git status of all files and stores the information
443 * about them in an internal array.
444 * \param sFilePath path to a file which contains a list of files and/or folders for which to
445 * fetch the status, separated by newlines.
446 * \param bUpdate TRUE if the remote status is requested too.
447 * \return TRUE on success.
449 BOOL GetStatus (const CTGitPathList* pathList = nullptr
450 , bool bUpdate = false
451 , bool bShowIgnores = false
452 , bool bShowUnRev = false
453 , bool bShowLocalChangesIgnored = false);
456 * Populates the list control with the previously (with GetStatus) gathered status information.
457 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
458 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
460 void Show(unsigned int dwShow, unsigned int dwCheck = 0, bool bShowFolders = true,BOOL updateStatusList=FALSE, bool UseStoredCheckStatus=false);
461 void Show(unsigned int dwShow, const CTGitPathList& checkedList, bool bShowFolders = true);
464 * Copies the selected entries in the control to the clipboard. The entries
465 * are separated by newlines.
466 * \param dwCols the columns to copy. Each column is separated by a tab.
468 bool CopySelectedEntriesToClipboard(DWORD dwCols);
471 * If during the call to GetStatus() some Git:externals are found from different
472 * repositories than the first one checked, then this method returns TRUE.
474 BOOL HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos;}
477 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
479 BOOL HasExternals() const {return m_bHasExternals;}
482 * If unversioned files are found (but not necessarily shown) TRUE is returned.
484 BOOL HasUnversionedItems() {return m_bHasUnversionedItems;}
487 * If there are any locks in the working copy, TRUE is returned
489 BOOL HasLocks() const {return m_bHasLocks;}
492 * If there are any change lists defined in the working copy, TRUE is returned
494 BOOL HasChangeLists() const {return m_bHasChangeLists;}
497 * Returns the file entry data for the list control index.
499 CTGitPath* GetListEntry(int index);
502 * Returns the file entry data for the specified path.
503 * \note The entry might not be shown in the list control.
505 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
508 * Returns the index of the list control entry with the specified path,
509 * or -1 if the path is not in the list control.
511 int GetIndex(const CTGitPath& path);
514 * Returns the file entry data for the specified path in the list control.
516 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
519 * Returns a String containing some statistics like number of modified, normal, deleted,...
520 * files.
522 CString GetStatisticsString(bool simple=false);
525 * Set a static control which will be updated automatically with
526 * the number of selected and total files shown in the list control.
528 void SetStatLabel(CWnd * pStatLabel){m_pStatLabel = pStatLabel;};
531 * Set a tri-state checkbox which is updated automatically if the
532 * user checks/unchecks file entries in the list control to indicate
533 * if all files are checked, none are checked or some are checked.
535 void SetSelectButton(CButton * pButton) {m_pSelectButton = pButton;}
538 * Set a button which is de-/activated automatically. The button is
539 * only set active if at least one item is selected.
541 void SetConfirmButton(CButton * pButton) {m_pConfirmButton = pButton;}
544 * Select/unselect all entries in the list control.
545 * \param bSelect TRUE to check, FALSE to uncheck.
547 void SelectAll(bool bSelect, bool bIncludeNoCommits = false);
550 * Checks or unchecks all specified items
551 * \param dwCheck GITLC_SHOWxxx defines
552 * \param check if true matching items will be selected, false unchecks matching items
554 void Check(DWORD dwCheck, bool check = true);
556 /** Set a checkbox on an entry in the listbox
557 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
559 void SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck);
561 void ResetChecked(const CTGitPath& entry);
563 /** Write a list of the checked items' paths into a path list
565 void WriteCheckedNamesToPathList(CTGitPathList& pathList);
567 /** fills in \a lMin and \a lMax with the lowest/highest revision of all
568 * files/folders in the working copy.
569 * \param bShownOnly if true, the min/max revisions are calculated only for shown items
570 * \param bCheckedOnly if true, the min/max revisions are calculated only for items
571 * which are checked.
572 * \remark Since an item can only be checked if it is visible/shown in the list control
573 * bShownOnly is automatically set to true if bCheckedOnly is true
575 void GetMinMaxRevisions(git_revnum_t& rMin, git_revnum_t& rMax, bool bShownOnly, bool bCheckedOnly);
578 * Returns the parent directory of all entries in the control.
579 * if \a bStrict is set to false, then the paths passed to the control
580 * to fetch the status (in GetStatus()) are used if possible.
582 CString GetCommonDirectory(bool bStrict);
585 * Returns the parent url of all entries in the control.
586 * if \a bStrict is set to false, then the paths passed to the control
587 * to fetch the status (in GetStatus()) are used if possible.
589 CTGitPath GetCommonURL(bool bStrict);
592 * Sets a pointer to a boolean variable which is checked periodically
593 * during the status fetching. As soon as the variable changes to true,
594 * the operations stops.
596 void SetCancelBool(bool * pbCanceled) {m_pbCanceled = pbCanceled;}
599 * Sets the string shown in the control while the status is fetched.
600 * If not set, it defaults to "please wait..."
602 void SetBusyString(const CString& str) {m_sBusy = str;}
603 void SetBusyString(UINT id) {m_sBusy.LoadString(id);}
606 * Sets the string shown in the control if no items are shown. This
607 * can happen for example if there's nothing modified and the unversioned
608 * files aren't shown either, so there's nothing to commit.
609 * If not set, it defaults to "file list is empty".
611 void SetEmptyString(const CString& str) {m_sEmpty = str;}
612 void SetEmptyString(UINT id) {m_sEmpty.LoadString(id);}
615 * Returns the number of selected items
617 LONG GetSelected(){return m_nSelected;};
620 * Enables dropping of files on the control.
622 bool EnableFileDrop();
625 * Checks if the path already exists in the list.
627 bool HasPath(const CTGitPath& path);
629 * Checks if the path is shown/visible in the list control.
631 bool IsPathShown(const CTGitPath& path);
633 * Forces the children to be checked when the parent folder is checked,
634 * and the parent folder to be unchecked if one of its children is unchecked.
636 void CheckChildrenWithParent(bool bCheck) {m_bCheckChildrenWithParent = bCheck;}
639 * Allows checking the items if change lists are present. If set to false,
640 * items are not checked if at least one changelist is available.
642 void CheckIfChangelistsArePresent(bool bCheck) {m_bCheckIfGroupsExist = bCheck;}
644 * Returns the currently used show flags passed to the Show() method.
646 DWORD GetShowFlags() {return m_dwShow;}
648 public:
649 CString GetLastErrorMessage() {return m_sLastError;}
651 void Block(BOOL block, BOOL blockUI) {m_bBlock = block; m_bBlockUI = blockUI;}
653 LONG GetUnversionedCount() { return m_nShownUnversioned; }
654 LONG GetModifiedCount() { return m_nShownModified; }
655 LONG GetAddedCount() { return m_nShownAdded; }
656 LONG GetDeletedCount() { return m_nShownDeleted; }
657 LONG GetConflictedCount() { return m_nShownConflicted; }
658 LONG GetFileCount() { return m_nShownFiles; }
659 LONG GetSubmoduleCount() { return m_nShownSubmodules; }
661 LONG m_nTargetCount; ///< number of targets in the file passed to GetStatus()
663 CString m_sURL; ///< the URL of the target or "(multiple targets)"
665 GitRev m_HeadRev; ///< the HEAD revision of the repository if bUpdate was TRUE
667 bool m_amend; ///< if true show the changes to the revision before the last commit
669 CString m_sUUID; ///< the UUID of the associated repository
671 CString m_sDisplayedBranch; ///< When on LogDialog, what is the current displayed branch
673 CWnd *m_hwndLogicalParent;
675 DECLARE_MESSAGE_MAP()
677 public:
678 void SetBusy(bool b) {m_bBusy = b; Invalidate();}
679 bool IsBusy() const { return m_bBusy; }
680 void SetHasCheckboxes(bool bHasCheckboxes)
682 m_bHasCheckboxes = bHasCheckboxes;
683 DWORD exStyle = GetExtendedStyle();
684 if (bHasCheckboxes)
685 exStyle |= LVS_EX_CHECKBOXES;
686 else
687 exStyle &= ~LVS_EX_CHECKBOXES;
688 SetExtendedStyle(exStyle);
691 private:
692 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
693 void RemoveListEntry(int index); ///< removes an entry from the listcontrol and both arrays
694 bool BuildStatistics(); ///< build the statistics and correct the case of files/folders
695 void StartDiff(int fileindex); ///< start the external diff program
696 void StartDiffWC(int fileindex); ///< start the external diff program
697 void StartDiffTwo(int fileindex);
699 void SetGitIndexFlagsForSelectedFiles(UINT message, BOOL assumevalid, BOOL skipworktree);
701 CString m_sMarkForDiffFilename;
702 CString m_sMarkForDiffVersion;
704 /* while rebasing, Their and My versios are swapped. */
705 bool m_bIsRevertTheirMy;
707 enum
709 ALTERNATIVEEDITOR,
710 OPEN,
711 OPEN_WITH,
713 void OpenFile(CTGitPath *path,int mode);
715 /// Clear the status vector (contains custodial pointers)
716 void ClearStatusArray();
718 /// Sort predicate function - Compare the paths of two entries without regard to case
719 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
721 /// Predicate used to build a list of only the versioned entries of the FileEntry array
722 //static bool IsEntryVersioned(const FileEntry* pEntry1);
724 /// Look up the relevant show flags for a particular Git status value
725 DWORD GetShowFlagsFromGitStatus(git_wc_status_kind status);
727 /// Adjust the checkbox-state on all descendants of a specific item
728 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
730 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
731 void FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored = false);
733 /// Enables/Disables group view and adds all groups to the list control.
734 /// If bForce is true, then group view is enabled and the 'null' group is added.
735 bool PrepareGroups(bool bForce = false);
736 /// Returns the group number to which the group header belongs
737 /// If the point is not over a group header, -1 is returned
738 int GetGroupFromPoint(POINT * ppt);
739 /// Returns the number of change lists the selection has
740 size_t GetNumberOfChangelistsInSelection();
742 /// Puts the item to the corresponding group
743 bool SetItemGroup(int item, int groupindex);
745 void CheckEntry(int index, int nListItems);
746 void UncheckEntry(int index, int nListItems);
748 /// sends an GitSLNM_CHECKCHANGED notification to the parent
749 void NotifyCheck();
750 CWnd* GetLogicalParent() { return m_hwndLogicalParent ? m_hwndLogicalParent : this->GetParent(); }
752 void OnContextMenuList(CWnd * pWnd, CPoint point);
753 void OnContextMenuGroup(CWnd * pWnd, CPoint point);
754 bool CheckMultipleDiffs();
756 void DeleteSelectedFiles();
758 virtual void PreSubclassWindow();
759 virtual BOOL PreTranslateMessage(MSG* pMsg);
760 virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
761 afx_msg void OnSysColorChange();
762 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
763 afx_msg BOOL OnToolTipText(UINT id, NMHDR *pNMHDR, LRESULT *pResult);
764 afx_msg void OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult);
765 afx_msg void OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
766 afx_msg BOOL OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
767 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
769 void CreateChangeList(const CString& name);
771 afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);
772 afx_msg void OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult);
773 afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
774 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
775 afx_msg UINT OnGetDlgCode();
776 afx_msg void OnNMReturn(NMHDR *pNMHDR, LRESULT *pResult);
777 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
778 afx_msg void OnPaint();
780 void FilesExport();
781 void FileSaveAs(CTGitPath *path);
782 int RevertSelectedItemToVersion(bool parent = false);
784 private:
785 bool * m_pbCanceled;
786 bool m_bAscending; ///< sort direction
787 int m_nSortedColumn; ///< which column to sort
788 bool m_bHasCheckboxes;
789 bool m_bHasWC;
790 bool m_bUnversionedLast;
791 bool m_bHasExternalsFromDifferentRepos;
792 bool m_bHasExternals;
793 BOOL m_bHasUnversionedItems;
794 bool m_bHasLocks;
795 bool m_bHasChangeLists;
796 //typedef std::vector<FileEntry*> FileEntryVector;
797 //FileEntryVector m_arStatusArray;
798 std::vector<const CTGitPath*> m_arStatusArray;
799 std::vector<size_t> m_arListArray;
800 std::map<CString, int> m_changelists;
801 bool m_bHasIgnoreGroup;
802 //CTGitPathList m_ConflictFileList;
803 CTGitPathList m_StatusFileList;
804 CTGitPathList m_UnRevFileList;
805 CTGitPathList m_IgnoreFileList;
806 CTGitPathList m_LocalChangesIgnoredFileList; // assume valid & skip worktree
807 //CTGitPathList m_StatusUrlList;
808 CString m_sLastError;
810 LONG m_nUnversioned;
811 LONG m_nNormal;
812 LONG m_nModified;
813 LONG m_nAdded;
814 LONG m_nDeleted;
815 LONG m_nConflicted;
816 LONG m_nTotal;
817 LONG m_nSelected;
818 LONG m_nLineAdded;
819 LONG m_nLineDeleted;
820 LONG m_nRenamed;
822 LONG m_nShownUnversioned;
823 LONG m_nShownModified;
824 LONG m_nShownAdded;
825 LONG m_nShownDeleted;
826 LONG m_nShownConflicted;
827 LONG m_nShownFiles;
828 LONG m_nShownSubmodules;
830 DWORD m_dwDefaultColumns;
831 DWORD m_dwShow;
832 bool m_bShowFolders;
833 bool m_bShowIgnores;
834 bool m_bUpdate;
835 unsigned __int64 m_dwContextMenus;
836 BOOL m_bBlock;
837 BOOL m_bBlockUI;
838 bool m_bBusy;
839 bool m_bEmpty;
840 bool m_bIgnoreRemoveOnly;
841 bool m_bCheckIfGroupsExist;
842 bool m_bFileDropsEnabled;
843 bool m_bOwnDrag;
845 int m_nIconFolder;
846 int m_nRestoreOvl;
848 CWnd * m_pStatLabel;
849 CButton * m_pSelectButton;
850 CButton * m_pConfirmButton;
851 CColors m_Colors;
853 CString m_sEmpty;
854 CString m_sBusy;
856 bool m_bCheckChildrenWithParent;
857 std::unique_ptr<CGitStatusListCtrlDropTarget> m_pDropTarget;
859 std::map<CString,bool> m_mapFilenameToChecked; ///< Remember de-/selected items
860 std::set<CString> m_setDirectFiles;
861 CComCriticalSection m_critSec;
863 friend class CGitStatusListCtrlDropTarget;
864 public:
865 enum
867 FILELIST_MODIFY= 0x1,
868 FILELIST_UNVER = 0x2,
869 FILELIST_IGNORE =0x4,
870 FILELIST_LOCALCHANGESIGNORED = 0x8, // assume valid & skip worktree files
872 private:
873 int UpdateFileList(const CTGitPathList* list = nullptr);
874 public:
875 int UpdateFileList(int mask, bool once = true, const CTGitPathList* list = nullptr);
876 int UpdateUnRevFileList(CTGitPathList &list);
877 int UpdateUnRevFileList(const CTGitPathList* list = nullptr);
878 int UpdateIgnoreFileList(const CTGitPathList* list = nullptr);
879 int UpdateLocalChangesIgnoredFileList(const CTGitPathList* list = nullptr);
881 int UpdateWithGitPathList(CTGitPathList &list);
883 void AddEntry(CTGitPath* path, WORD langID, int ListIndex);
884 void Clear();
885 int m_FileLoaded;
886 git_revnum_t m_CurrentVersion;
887 bool m_bDoNotAutoselectSubmodules;
888 bool m_bNoAutoselectMissing;
889 std::map<CString, CString> m_restorepaths;
891 HMENU m_hShellMenu;
892 LPCONTEXTMENU m_pContextMenu;
894 void StoreScrollPos();
896 private:
897 void RestoreScrollPos();
898 struct ScrollPos
900 bool enabled = false;
901 int nTopIndex;
902 int selMark;
903 int nSelectedEntry;
904 } m_sScrollPos;
907 class CGitStatusListCtrlDropTarget : public CIDropTarget
909 public:
910 CGitStatusListCtrlDropTarget(CGitStatusListCtrl* pGitStatusListCtrl) : CIDropTarget(pGitStatusListCtrl->m_hWnd) { m_pGitStatusListCtrl = pGitStatusListCtrl; }
912 virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect, POINTL pt);
913 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR* pdwEffect);
914 private:
915 CGitStatusListCtrl* m_pGitStatusListCtrl;