Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / Git / GitStatusListCtrl.h
blobe175550b130c5c6dbd2da24b1e2b17cecb33d82e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018 - 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 "Colors.h"
24 #include "ResizableColumnsListCtrl.h"
25 #include "DragDropImpl.h"
26 #include "ReaderWriterLock.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_SHOWDIRECTFILES 0x04000000
62 #define GITSLC_SHOWDIRECTFOLDER 0x00000000
63 #define GITSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x00000000
64 #define GITSLC_SHOWSWITCHED 0x00000000
65 #define GITSLC_SHOWINCHANGELIST 0x00000000
66 #define GITSLC_SHOWASSUMEVALID CTGitPath::LOGACTIONS_ASSUMEVALID
67 #define GITSLC_SHOWSKIPWORKTREE CTGitPath::LOGACTIONS_SKIPWORKTREE
69 #define GITSLC_SHOWDIRECTS (GITSLC_SHOWDIRECTFILES | GITSLC_SHOWDIRECTFOLDER)
71 #define GITSLC_SHOWFILES 0x01000000
72 #define GITSLC_SHOWSUBMODULES 0x02000000
73 #define GITSLC_SHOWEVERYTHING 0xffffffff
75 #define GITSLC_SHOWVERSIONED (GITSLC_SHOWNORMAL|GITSLC_SHOWMODIFIED|\
76 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
77 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
78 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
79 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
81 #define GITSLC_SHOWVERSIONEDBUTNORMAL (GITSLC_SHOWMODIFIED|GITSLC_SHOWADDED|\
82 GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
83 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
84 GITSLC_SHOWEXTERNAL|GITSLC_SHOWINCOMPLETE|GITSLC_SHOWINEXTERNALS|\
85 GITSLC_SHOWEXTERNALFROMDIFFERENTREPO)
87 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (GITSLC_SHOWMODIFIED|\
88 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
89 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
90 GITSLC_SHOWINCOMPLETE|GITSLC_SHOWEXTERNAL|GITSLC_SHOWINEXTERNALS)
92 #define GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (GITSLC_SHOWMODIFIED|\
93 GITSLC_SHOWADDED|GITSLC_SHOWREMOVED|GITSLC_SHOWCONFLICTED|GITSLC_SHOWMISSING|\
94 GITSLC_SHOWREPLACED|GITSLC_SHOWMERGED|GITSLC_SHOWIGNORED|GITSLC_SHOWOBSTRUCTED|\
95 GITSLC_SHOWINCOMPLETE)
97 #define GITSLC_SHOWALL (GITSLC_SHOWVERSIONED|GITSLC_SHOWUNVERSIONED)
99 #define GITSLC_POPALL 0xFFFFFFFFFFFFFFFF
100 #define GITSLC_POPCOMPAREWITHBASE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARE)
101 #define GITSLC_POPCOMPARE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPAREWC)
102 #define GITSLC_POPGNUDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF1)
103 #define GITSLC_POPREVERT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_REVERT)
104 #define GITSLC_POPSHOWLOG CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOG)
105 #define GITSLC_POPSHOWLOGSUBMODULE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGSUBMODULE)
106 #define GITSLC_POPSHOWLOGOLDNAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_LOGOLDNAME)
107 #define GITSLC_POPOPEN CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_OPEN)
108 #define GITSLC_POPDELETE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_DELETE)
109 #define GITSLC_POPADD CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ADD)
110 #define GITSLC_POPIGNORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_IGNORE)
111 #define GITSLC_POPCONFLICT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EDITCONFLICT)
112 #define GITSLC_POPRESOLVE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_RESOLVECONFLICT)
113 #define GITSLC_POPEXPLORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPLORE)
114 #define GITSLC_POPCOMMIT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMMIT)
115 #define GITSLC_POPCHANGELISTS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_CHECKGROUP)
116 #define GITSLC_POPBLAME CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_BLAME)
117 #define GITSLC_POPSAVEAS CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SAVEAS)
118 #define GITSLC_POPCOMPARETWOFILES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOFILES)
119 #define GITSLC_POPRESTORE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_POPRESTORE)
120 #define GITSLC_POPASSUMEVALID CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_ASSUMEVALID)
121 #define GITSLC_POPSKIPWORKTREE CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_SKIPWORKTREE)
122 #define GITSLC_POPEXPORT CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_EXPORT)
123 #define GITLC_POPUNSETIGNORELOCALCHANGES CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_UNSETIGNORELOCALCHANGES)
124 #define GITSLC_PREPAREDIFF CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_PREPAREDIFF)
126 #define GITSLC_IGNORECHANGELIST L"ignore-on-commit"
128 #define OVL_RESTORE 1
130 typedef int (__cdecl *GENERICCOMPAREFN)(const void * elem1, const void * elem2);
132 class CGitStatusListCtrlDropTarget;
135 * \ingroup TortoiseProc
136 * Simple utility class that defines the sort column order.
138 class CSorter
140 public:
142 CSorter ( ColumnManager* columnManager
143 , int sortedColumn
144 , bool ascending);
146 bool operator() ( const CTGitPath* entry1
147 , const CTGitPath* entry2) const;
149 static int A2L(const CString &str)
151 if (str == L"-")
152 return -1;
154 return _wtol(str);
157 private:
159 ColumnManager* columnManager;
160 int sortedColumn;
161 bool ascending;
162 bool s_bSortLogical;
166 * \ingroup SVN
167 * A List control, based on the MFC CListCtrl which shows a list of
168 * files with their git status. The control also provides a context
169 * menu to do some git tasks on the selected files.
171 * This is the main control used in many dialogs to show a list of files to
172 * work on.
174 class CGitStatusListCtrl :
175 public CResizableColumnsListCtrl<CListCtrl>
177 public:
178 enum
180 IDGITLC_REVERT = 1,
181 /** Compare with base version. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
182 IDGITLC_COMPARE,
183 IDGITLC_OPEN,
184 IDGITLC_DELETE,
185 IDGITLC_IGNORE,
186 /** Compare with base version and generate unified diff. when current version is zero (i.e. working tree changes), compare working tree and HEAD */
187 IDGITLC_GNUDIFF1 ,
188 IDGITLC_LOG ,
189 IDGITLC_LOGOLDNAME,
190 IDGITLC_LOGSUBMODULE,
191 IDGITLC_EDITCONFLICT ,
192 IDGITLC_IGNOREMASK ,
193 IDGITLC_IGNOREFOLDER ,
194 IDGITLC_ADD ,
195 IDGITLC_RESOLVECONFLICT ,
196 IDGITLC_OPENWITH ,
197 IDGITLC_EXPLORE ,
198 IDGITLC_RESOLVETHEIRS ,
199 IDGITLC_RESOLVEMINE ,
200 IDGITLC_REMOVE ,
201 IDGITLC_COMMIT ,
202 IDGITLC_COPYRELPATHS ,
203 IDGITLC_COPYEXT ,
204 IDGITLC_REMOVEFROMCS ,
205 IDGITLC_CREATECS ,
206 IDGITLC_CREATEIGNORECS ,
207 IDGITLC_CHECKGROUP ,
208 IDGITLC_UNCHECKGROUP ,
209 /** Compare current version and working tree */
210 IDGITLC_COMPAREWC ,
211 IDGITLC_BLAME ,
212 IDGITLC_SAVEAS ,
213 IDGITLC_REVERTTOREV ,
214 IDGITLC_REVERTTOPARENT ,
215 IDGITLC_VIEWREV ,
216 IDGITLC_FINDENTRY ,
217 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
218 IDGITLC_COMPARETWOREVISIONS,
219 /** used in sync dlg, compare in/out file changes; in combination with m_Rev1 and m_Rev2 */
220 IDGITLC_GNUDIFF2REVISIONS,
221 /** Compare two selected files */
222 IDGITLC_COMPARETWOFILES ,
223 IDGITLC_POPRESTORE ,
224 IDGITLC_CREATERESTORE ,
225 IDGITLC_RESTOREPATH ,
226 IDGITLC_ASSUMEVALID ,
227 IDGITLC_SKIPWORKTREE ,
228 IDGITLC_EXPORT ,
229 IDGITLC_UNSETIGNORELOCALCHANGES,
230 IDGITLC_PREPAREDIFF ,
231 IDGITLC_PREPAREDIFF_COMPARE,
232 IDGITLC_COPYCOL ,
233 IDGITLC_COPYFULL ,
234 IDGITLC_COPYFILENAMES ,
235 // the IDSVNLC_MOVETOCS *must* be the last index, because it contains a dynamic submenu where
236 // the submenu items get command ID's sequent to this number
237 IDGITLC_MOVETOCS ,
239 static_assert(IDGITLC_MOVETOCS < 64, "IDs must be <64 in order to be usable in a bitfield");
240 int GetColumnIndex(int colmask);
241 static inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}
243 * Sent to the parent window (using ::SendMessage) after a context menu
244 * command has finished if the item count has changed.
246 static const UINT GITSLNM_ITEMCOUNTCHANGED;
248 * Sent to the parent window (using ::SendMessage) when the control needs
249 * to be refreshed. Since this is done usually in the parent window using
250 * a thread, this message is used to tell the parent to do exactly that.
252 static const UINT GITSLNM_NEEDSREFRESH;
255 * Sent to the parent window (using ::SendMessage) when the user drops
256 * files on the control. The LPARAM is a pointer to a TCHAR string
257 * containing the dropped path.
259 static const UINT GITSLNM_ADDFILE;
262 * Sent to the parent window (using ::SendMessage) when the user checks/unchecks
263 * one or more items in the control. The WPARAM contains the number of
264 * checked items in the control.
266 static const UINT GITSLNM_CHECKCHANGED;
268 static const UINT GITSLNM_ITEMCHANGED;
270 CGitStatusListCtrl(void);
271 ~CGitStatusListCtrl(void);
273 HWND GetParentHWND();
275 CString m_Rev1;
276 CString m_Rev2;
279 * \ingroup TortoiseProc
280 * Helper class for CGitStatusListCtrl which represents
281 * the data for each file shown.
283 #if 0
284 class FileEntry
286 public:
287 FileEntry() : status(git_wc_status_unversioned)
288 // , copyfrom_rev(GIT_REV_ZERO)
289 , last_commit_date(0)
290 , last_commit_rev(GIT_REV_ZERO)
291 // , remoterev(GIT_REV_ZERO)
292 , textstatus(git_wc_status_unversioned)
293 , propstatus(git_wc_status_unversioned)
294 // , remotestatus(git_wc_status_unversioned)
295 // , remotetextstatus(git_wc_status_unversioned)
296 // , remotepropstatus(git_wc_status_unversioned)
297 , copied(false)
298 , switched(false)
299 , checked(false)
300 , inunversionedfolder(false)
301 , inexternal(false)
302 , differentrepo(false)
303 , direct(false)
304 , isfolder(false)
305 , isNested(false)
306 , Revision(GIT_REV_ZERO)
307 , isConflicted(false)
308 // , present_props()
309 /// , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)
310 // , depth(git_depth_unknown)
313 const CTGitPath& GetPath() const
315 return path;
317 const bool IsChecked() const
319 return checked;
321 CString GetRelativeGitPath() const
323 if (path.IsEquivalentTo(basepath))
324 return path.GetGitPathString();
325 return path.GetGitPathString().Mid(basepath.GetGitPathString().GetLength()+1);
327 const bool IsFolder() const
329 return isfolder;
331 const bool IsInExternal() const
333 return inexternal;
335 const bool IsNested() const
337 return isNested;
339 const bool IsFromDifferentRepository() const
341 return differentrepo;
343 CString GetDisplayName() const
345 CString const& chopped = path.GetDisplayString(&basepath);
346 if (!chopped.IsEmpty())
348 return chopped;
350 else
352 // "Display name" must not be empty.
353 return path.GetFileOrDirectoryName();
356 CString GetChangeList() const
358 return changelist;
360 // CString GetURL() const
361 // {
362 // return url;
363 // }
364 public:
365 git_wc_status_kind status; ///< local status
366 git_wc_status_kind textstatus; ///< local text status
367 git_wc_status_kind propstatus; ///< local property status
369 private:
370 CTGitPath path; ///< full path of the file
371 CTGitPath basepath; ///< common ancestor path of all files
373 CString changelist; ///< the name of the changelist the item belongs to
375 CString last_commit_author; ///< the author which last committed this item
376 CTime last_commit_date; ///< the date when this item was last committed
377 git_revnum_t last_commit_rev; ///< the revision where this item was last committed
379 git_revnum_t remoterev; ///< the revision in HEAD of the repository
380 bool copied; ///< if the file/folder is added-with-history
381 bool switched; ///< if the file/folder is switched to another url
382 bool checked; ///< if the file is checked in the list control
383 bool inunversionedfolder; ///< if the file is inside an unversioned folder
384 bool inexternal; ///< if the item is in an external folder
385 bool differentrepo; ///< if the item is from a different repository than the rest
386 bool direct; ///< directly included (TRUE) or just a child of a folder
387 bool isfolder; ///< TRUE if entry refers to a folder
388 bool isNested; ///< TRUE if the folder from a different repository and/or path
389 bool isConflicted; ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set
390 git_revnum_t Revision; ///< the base revision
391 // PropertyList present_props; ///< cacheable properties present in BASE
392 git_depth_t depth; ///< the depth of this entry
393 friend class CGitStatusListCtrl;
394 friend class CGitStatusListCtrlDropTarget;
395 friend class CSorter;
397 #endif
400 * Initializes the control, sets up the columns.
401 * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.
402 * \param sColumnInfoContainer Name of a registry key
403 * where the position and visibility of each column
404 * is saved and used from. If the registry key
405 * doesn't exist, the default order is used
406 * and dwColumns tells which columns are visible.
407 * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.
408 * Use the GitSLC_POPxxx defines.
409 * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.
410 * \param bHasWC TRUE if the reporisty is not a bare repository (hides wc related items on the contextmenu)
412 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);
414 * Sets a background image for the list control.
415 * The image is shown in the right bottom corner.
416 * \param nID the resource ID of the bitmap to use as the background
418 bool SetBackgroundImage(UINT nID);
419 private:
420 UINT m_nBackgroundImageID;
421 public:
423 * Makes the 'ignore' context menu only ignore the files and not add the
424 * folder which gets the Git:ignore property changed to the list.
425 * This is needed e.g. for the Add-dialog, where the modified folder
426 * showing up would break the resulting "add" command.
428 void SetIgnoreRemoveOnly(bool bRemoveOnly = true) {m_bIgnoreRemoveOnly = bRemoveOnly;}
430 * The unversioned items are by default shown after all other files in the list.
431 * If that behavior should be changed, set this value to false.
433 void PutUnversionedLast(bool bLast) {m_bUnversionedLast = bLast;}
435 * Fetches the git status of all files and stores the information
436 * about them in an internal array.
437 * \param sFilePath path to a file which contains a list of files and/or folders for which to
438 * fetch the status, separated by newlines.
439 * \param bUpdate TRUE if the remote status is requested too.
440 * \return TRUE on success.
442 BOOL GetStatus (const CTGitPathList* pathList = nullptr
443 , bool bUpdate = false
444 , bool bShowIgnores = false
445 , bool bShowUnRev = false
446 , bool bShowLocalChangesIgnored = false);
449 * Populates the list control with the previously (with GetStatus) gathered status information.
450 * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.
451 * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'
453 void Show(unsigned int dwShow, unsigned int dwCheck = 0, bool bShowFolders = true,BOOL updateStatusList=FALSE, bool UseStoredCheckStatus=false);
456 * Copies the selected entries in the control to the clipboard. The entries
457 * are separated by newlines.
458 * \param dwCols the columns to copy. Each column is separated by a tab.
460 bool CopySelectedEntriesToClipboard(DWORD dwCols, int cmd);
463 * If during the call to GetStatus() some Git:externals are found from different
464 * repositories than the first one checked, then this method returns TRUE.
466 BOOL HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos;}
469 * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.
471 BOOL HasExternals() const {return m_bHasExternals;}
474 * If unversioned files are found (but not necessarily shown) TRUE is returned.
476 BOOL HasUnversionedItems() {return m_bHasUnversionedItems;}
479 * If there are any change lists defined in the working copy, TRUE is returned
481 BOOL HasChangeLists() const {return m_bHasChangeLists;}
484 * Returns the file entry data for the list control index.
486 CTGitPath* GetListEntry(int index);
489 * Returns the file entry data for the specified path.
490 * \note The entry might not be shown in the list control.
492 //CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);
495 * Returns the file entry data for the specified path in the list control.
497 //CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);
500 * Returns a String containing some statistics like number of modified, normal, deleted,...
501 * files.
503 CString GetStatisticsString(bool simple=false);
506 * Set a static control which will be updated automatically with
507 * the number of selected and total files shown in the list control.
509 void SetStatLabel(CWnd * pStatLabel){m_pStatLabel = pStatLabel;};
512 * Set a tri-state checkbox which is updated automatically if the
513 * user checks/unchecks file entries in the list control to indicate
514 * if all files are checked, none are checked or some are checked.
516 void SetSelectButton(CButton * pButton) {m_pSelectButton = pButton;}
519 * Set a button which is de-/activated automatically. The button is
520 * only set active if at least one item is selected.
522 void SetConfirmButton(CButton * pButton) {m_pConfirmButton = pButton;}
525 * Select/unselect all entries in the list control.
526 * \param bSelect TRUE to check, FALSE to uncheck.
528 void SelectAll(bool bSelect, bool bIncludeNoCommits = false);
531 * Checks or unchecks all specified items
532 * \param dwCheck GITLC_SHOWxxx defines
533 * \param check if true matching items will be selected, false unchecks matching items
535 void Check(DWORD dwCheck, bool check = true);
537 /** Set a checkbox on an entry in the listbox
538 * Keeps the listctrl checked state and the FileEntry's checked flag in sync
540 void SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck);
542 void ResetChecked(const CTGitPath& entry);
544 /** Write a list of the checked items' paths into a path list
546 void WriteCheckedNamesToPathList(CTGitPathList& pathList);
549 * Returns the parent directory of all entries in the control.
550 * if \a bStrict is set to false, then the paths passed to the control
551 * to fetch the status (in GetStatus()) are used if possible.
553 CString GetCommonDirectory(bool bStrict);
556 * Sets a pointer to a boolean variable which is checked periodically
557 * during the status fetching. As soon as the variable changes to true,
558 * the operations stops.
560 void SetCancelBool(bool * pbCanceled) {m_pbCanceled = pbCanceled;}
563 * Sets the string shown in the control while the status is fetched.
564 * If not set, it defaults to "please wait..."
566 void SetBusyString(const CString& str) {m_sBusy = str;}
567 void SetBusyString(UINT id) {m_sBusy.LoadString(id);}
570 * Sets the string shown in the control if no items are shown. This
571 * can happen for example if there's nothing modified and the unversioned
572 * files aren't shown either, so there's nothing to commit.
573 * If not set, it defaults to "file list is empty".
575 void SetEmptyString(const CString& str) {m_sEmpty = str;}
576 void SetEmptyString(UINT id) {m_sEmpty.LoadString(id);}
579 * Returns the number of selected items
581 LONG GetSelected(){return m_nSelected;};
584 * Enables dropping of files on the control.
586 bool EnableFileDrop();
589 * Checks if the path already exists in the list.
591 bool HasPath(const CTGitPath& path);
594 * Forces the children to be checked when the parent folder is checked,
595 * and the parent folder to be unchecked if one of its children is unchecked.
597 void CheckChildrenWithParent(bool bCheck) {m_bCheckChildrenWithParent = bCheck;}
600 * Allows checking the items if change lists are present. If set to false,
601 * items are not checked if at least one changelist is available.
603 void CheckIfChangelistsArePresent(bool bCheck) {m_bCheckIfGroupsExist = bCheck;}
605 * Returns the currently used show flags passed to the Show() method.
607 DWORD GetShowFlags() {return m_dwShow;}
609 public:
610 CString GetLastErrorMessage() {return m_sLastError;}
612 void BusyCursor(bool bBusy) { m_bWaitCursor = bBusy; }
614 LONG GetUnversionedCount() { return m_nShownUnversioned; }
615 LONG GetModifiedCount() { return m_nShownModified; }
616 LONG GetAddedCount() { return m_nShownAdded; }
617 LONG GetDeletedCount() { return m_nShownDeleted; }
618 LONG GetConflictedCount() { return m_nShownConflicted; }
619 LONG GetFileCount() { return m_nShownFiles; }
620 LONG GetSubmoduleCount() { return m_nShownSubmodules; }
622 CAutoReadLock AcquireReadLock() { return CAutoReadLock(m_guard); }
623 CAutoReadWeakLock AcquireReadWeakLock(DWORD timeout) { return CAutoReadWeakLock(m_guard, timeout); }
625 LONG m_nTargetCount; ///< number of targets in the file passed to GetStatus()
627 CString m_sURL; ///< the URL of the target or "(multiple targets)"
629 bool m_amend; ///< if true show the changes to the revision before the last commit
631 CString m_sUUID; ///< the UUID of the associated repository
633 CString m_sDisplayedBranch; ///< When on LogDialog, what is the current displayed branch
635 CWnd *m_hwndLogicalParent;
637 DECLARE_MESSAGE_MAP()
639 public:
640 void SetBusy(bool b) {m_bBusy = b; Invalidate();}
641 bool IsBusy() const { return m_bBusy; }
642 void SetHasCheckboxes(bool bHasCheckboxes)
644 m_bHasCheckboxes = bHasCheckboxes;
645 DWORD exStyle = GetExtendedStyle();
646 if (bHasCheckboxes)
647 exStyle |= LVS_EX_CHECKBOXES;
648 else
649 exStyle &= ~LVS_EX_CHECKBOXES;
650 SetExtendedStyle(exStyle);
653 private:
654 CString GetCellText(int listIndex, int column); ///< get the text for a certain grid cell
655 //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control
656 void RemoveListEntry(int index); ///< removes an entry from the listcontrol and both arrays
657 void BuildStatistics(); ///< build the statistics and correct the case of files/folders
658 void StartDiff(int fileindex); ///< start the external diff program
659 void StartDiffWC(int fileindex); ///< start the external diff program
660 void StartDiffTwo(int fileindex);
662 void SetGitIndexFlagsForSelectedFiles(UINT message, BOOL assumevalid, BOOL skipworktree);
664 CString m_sMarkForDiffFilename;
665 CString m_sMarkForDiffVersion;
667 /* while rebasing, Their and My versios are swapped. */
668 bool m_bIsRevertTheirMy;
670 enum
672 ALTERNATIVEEDITOR,
673 OPEN,
674 OPEN_WITH,
676 void OpenFile(CTGitPath *path,int mode);
678 /// Clear the status vector (contains custodial pointers)
679 void ClearStatusArray();
681 /// Sort predicate function - Compare the paths of two entries without regard to case
682 //static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);
684 /// Predicate used to build a list of only the versioned entries of the FileEntry array
685 //static bool IsEntryVersioned(const FileEntry* pEntry1);
687 /// Look up the relevant show flags for a particular Git status value
688 DWORD GetShowFlagsFromGitStatus(git_wc_status_kind status);
690 /// Adjust the checkbox-state on all descendants of a specific item
691 //void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);
693 /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)
694 void FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored = false);
696 /// Enables/Disables group view and adds all groups to the list control.
697 /// If bForce is true, then group view is enabled and the 'null' group is added.
698 bool PrepareGroups(bool bForce = false);
699 /// Returns the group number to which the group header belongs
700 /// If the point is not over a group header, -1 is returned
701 int GetGroupFromPoint(POINT * ppt);
702 /// Returns the number of change lists the selection has
703 size_t GetNumberOfChangelistsInSelection();
705 /// Puts the item to the corresponding group
706 bool SetItemGroup(int item, int groupindex);
708 void CheckEntry(int index, int nListItems);
709 void UncheckEntry(int index, int nListItems);
711 /// sends an GitSLNM_CHECKCHANGED notification to the parent
712 void NotifyCheck();
713 CWnd* GetLogicalParent() { return m_hwndLogicalParent ? m_hwndLogicalParent : this->GetParent(); }
715 void OnContextMenuList(CWnd * pWnd, CPoint point);
716 void OnContextMenuGroup(CWnd * pWnd, CPoint point);
717 bool CheckMultipleDiffs();
719 void DeleteSelectedFiles();
721 virtual void PreSubclassWindow() override;
722 virtual BOOL PreTranslateMessage(MSG* pMsg) override;
723 virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult) override;
724 virtual ULONG GetGestureStatus(CPoint ptTouch) override;
725 afx_msg void OnSysColorChange();
726 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
727 afx_msg void OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult);
728 afx_msg BOOL OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
729 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
731 afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);
732 afx_msg void OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult);
733 afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
734 afx_msg void OnLvnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult);
735 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
736 afx_msg UINT OnGetDlgCode();
737 afx_msg void OnNMReturn(NMHDR *pNMHDR, LRESULT *pResult);
738 afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
739 afx_msg void OnPaint();
741 void FilesExport();
742 void FileSaveAs(CTGitPath *path);
743 int RevertSelectedItemToVersion(bool parent = false);
745 private:
746 bool * m_pbCanceled;
747 bool m_bAscending; ///< sort direction
748 int m_nSortedColumn; ///< which column to sort
749 bool m_bHasCheckboxes;
750 bool m_bHasWC;
751 bool m_bUnversionedLast;
752 bool m_bHasExternalsFromDifferentRepos;
753 bool m_bHasExternals;
754 BOOL m_bHasUnversionedItems;
755 bool m_bHasChangeLists;
756 //typedef std::vector<FileEntry*> FileEntryVector;
757 //FileEntryVector m_arStatusArray;
758 std::vector<const CTGitPath*> m_arStatusArray;
759 std::vector<size_t> m_arListArray;
760 std::map<CString, int> m_changelists;
761 bool m_bHasIgnoreGroup;
762 CTGitPathList m_StatusFileList;
763 CTGitPathList m_UnRevFileList;
764 CTGitPathList m_IgnoreFileList;
765 CTGitPathList m_LocalChangesIgnoredFileList; // assume valid & skip worktree
766 CString m_sLastError;
768 LONG m_nUnversioned;
769 LONG m_nNormal;
770 LONG m_nModified;
771 LONG m_nAdded;
772 LONG m_nDeleted;
773 LONG m_nConflicted;
774 LONG m_nTotal;
775 LONG m_nSelected;
776 LONG m_nLineAdded;
777 LONG m_nLineDeleted;
778 LONG m_nRenamed;
780 LONG m_nShownUnversioned;
781 LONG m_nShownModified;
782 LONG m_nShownAdded;
783 LONG m_nShownDeleted;
784 LONG m_nShownConflicted;
785 LONG m_nShownFiles;
786 LONG m_nShownSubmodules;
788 DWORD m_dwDefaultColumns;
789 DWORD m_dwShow;
790 bool m_bShowFolders;
791 bool m_bShowIgnores;
792 bool m_bUpdate;
793 unsigned __int64 m_dwContextMenus;
794 bool m_bBusy;
795 bool m_bWaitCursor;
796 bool m_bEmpty;
797 bool m_bIgnoreRemoveOnly;
798 bool m_bCheckIfGroupsExist;
799 bool m_bFileDropsEnabled;
800 bool m_bOwnDrag;
802 int m_nIconFolder;
803 int m_nRestoreOvl;
805 CWnd * m_pStatLabel;
806 CButton * m_pSelectButton;
807 CButton * m_pConfirmButton;
808 CColors m_Colors;
810 CString m_sEmpty;
811 CString m_sBusy;
813 bool m_bCheckChildrenWithParent;
814 std::unique_ptr<CGitStatusListCtrlDropTarget> m_pDropTarget;
815 volatile LONG m_nBlockItemChangeHandler;
816 std::map<CString,bool> m_mapFilenameToChecked; ///< Remember de-/selected items
817 std::set<CString> m_setDirectFiles;
818 CComCriticalSection m_critSec;
820 friend class CGitStatusListCtrlDropTarget;
821 public:
822 enum
824 FILELIST_MODIFY= 0x1,
825 FILELIST_UNVER = 0x2,
826 FILELIST_IGNORE =0x4,
827 FILELIST_LOCALCHANGESIGNORED = 0x8, // assume valid & skip worktree files
829 private:
830 int UpdateFileList(const CTGitPathList* list = nullptr);
831 public:
832 int UpdateFileList(int mask, bool once = true, const CTGitPathList* list = nullptr);
833 int UpdateUnRevFileList(CTGitPathList &list);
834 int UpdateUnRevFileList(const CTGitPathList* list = nullptr);
835 int UpdateIgnoreFileList(const CTGitPathList* list = nullptr);
836 int UpdateLocalChangesIgnoredFileList(const CTGitPathList* list = nullptr);
838 int UpdateWithGitPathList(CTGitPathList &list);
840 void AddEntry(size_t arStatusArrayIndex, CTGitPath* path, WORD langID, int ListIndex);
841 void Clear();
842 int m_FileLoaded;
843 CString m_CurrentVersion;
844 bool m_bDoNotAutoselectSubmodules;
845 bool m_bNoAutoselectMissing;
846 std::map<CString, CString> m_restorepaths;
847 mutable CReaderWriterLock m_guard;
849 HMENU m_hShellMenu;
850 LPCONTEXTMENU m_pContextMenu;
852 void StoreScrollPos();
854 private:
855 void RestoreScrollPos();
856 struct ScrollPos
858 bool enabled = false;
859 int nTopIndex;
860 int selMark;
861 int nSelectedEntry;
862 } m_sScrollPos;
865 class CGitStatusListCtrlDropTarget : public CIDropTarget
867 public:
868 CGitStatusListCtrlDropTarget(CGitStatusListCtrl* pGitStatusListCtrl) : CIDropTarget(pGitStatusListCtrl->m_hWnd) { m_pGitStatusListCtrl = pGitStatusListCtrl; }
870 virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect, POINTL pt) override;
871 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR* pdwEffect) override;
872 private:
873 CGitStatusListCtrl* m_pGitStatusListCtrl;
876 class ScopedInDecrement
878 public:
879 ScopedInDecrement(volatile LONG& counter) : m_counter(counter) { InterlockedIncrement(&m_counter); }
880 ~ScopedInDecrement() { InterlockedDecrement(&m_counter); }
882 ScopedInDecrement(const ScopedInDecrement&) = delete;
883 void operator=(const ScopedInDecrement&) = delete;
885 private:
886 volatile LONG& m_counter;