Call GatherData after we loaded the conditions we want to show
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blob6888a82de5593ec6859e05c56a89cf78881f49e8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - TortoiseGit
4 // Copyright (C) 2003-2008 - 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 "Colors.h"
23 #include "UnicodeUtils.h"
24 #include "resource.h"
25 #include "../TortoiseShell/resource.h"
26 #include "LoglistCommonResource.h"
27 #include "IconMenu.h"
28 #include "ProgressDlg.h"
29 /**
30 * \ingroup TortoiseProc
31 * Options which can be used to configure the way the dialog box works
33 typedef enum
35 ProgOptNone = 0,
36 /// Don't actually do the merge - just practice it
37 ProgOptDryRun = 0x04,
38 } ProgressOptions;
40 // CGitProgressList
41 struct git_transfer_progress;
42 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
43 #define WM_PROG_CMD_FINISH (WM_APP + 200)
44 #define WM_PROG_CMD_START (WM_APP + 201)
46 class ProgressCommand;
47 class CGitProgressList : public CListCtrl
49 DECLARE_DYNAMIC(CGitProgressList)
51 public:
52 CGitProgressList();
53 virtual ~CGitProgressList();
55 void SetCommand(ProgressCommand* command) { ATLASSERT(command); m_Command = command; }
56 void SetOptions(DWORD opts) {m_options = opts;}
58 /**
59 * If the number of items for which the operation is done on is known
60 * beforehand, that number can be set here. It is then used to show a more
61 * accurate progress bar during the operation.
63 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
64 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
65 bool SetBackgroundImage(UINT nID);
66 bool DidErrorsOccur() {return m_bErrorsOccurred;}
67 bool m_bErrorsOccurred;
68 CWnd *m_pProgressLabelCtrl;
69 CWnd *m_pInfoCtrl;
70 CAnimateCtrl *m_pAnimate;
71 CProgressCtrl *m_pProgControl;
72 ProgressCommand *m_Command;
73 void Cancel();
74 volatile BOOL IsCancelled() {return m_bCancelled;}
75 volatile LONG IsRunning() {return m_bThreadRunning;}
76 CWinThread* m_pThread;
77 CWnd *m_pPostWnd;
78 bool m_bSetTitle;
80 public:
81 typedef std::vector<std::function<void()>> ContextMenuActionList;
82 struct Payload
84 CGitProgressList* list;
85 git_repository* repo;
88 class NotificationData
90 public:
91 NotificationData()
92 : color(::GetSysColor(COLOR_WINDOWTEXT))
93 , bAuxItem(false)
94 {};
96 NotificationData(const CTGitPath &path, UINT actionTextId)
97 : NotificationData()
99 this->path = path;
100 sActionColumnText.LoadString(actionTextId);
103 virtual ~NotificationData() {};
105 virtual void SetColorCode(CColors& /*colors*/) {};
106 virtual void GetContextMenu(CIconMenu& /*popup*/, ContextMenuActionList& /*actions*/) {};
107 virtual void HandleDblClick() const {}
109 // The text we put into the first column (the Git action for normal items, just text for aux items)
110 CString sActionColumnText;
111 CTGitPath path;
112 COLORREF color;
113 bool bAuxItem; // Set if this item is not a true 'Git action'
114 CString sPathColumnText;
117 class WC_File_NotificationData : public NotificationData
119 public:
120 typedef enum
122 git_wc_notify_add,
123 git_wc_notify_resolved,
124 git_wc_notify_revert,
125 git_wc_notify_checkout,
126 } git_wc_notify_action_t;
128 WC_File_NotificationData(const CTGitPath& path, git_wc_notify_action_t action);
129 virtual void SetColorCode(CColors& colors);
131 git_wc_notify_action_t action;
133 virtual void GetContextMenu(CIconMenu& popup, ContextMenuActionList& actions);
134 virtual void HandleDblClick() const;
137 void AddNotify(NotificationData* data, CColors::Colors color = CColors::COLOR_END);
138 int UpdateProgress(const git_transfer_progress* stat);
140 void SetProgressLabelText(const CString& str);
142 protected:
143 DECLARE_MESSAGE_MAP()
145 public:
146 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
148 protected:
149 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
150 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
151 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
152 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
153 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
154 afx_msg void OnTimer(UINT_PTR nIDEvent);
155 afx_msg void OnSize(UINT nType, int cx, int cy);
156 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
157 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
159 void Sort();
160 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
162 static BOOL m_bAscending;
163 static int m_nSortedColumn;
165 private:
166 static UINT ProgressThreadEntry(LPVOID pVoid);
167 UINT ProgressThread();
169 public:
170 void ReportGitError();
171 void ReportUserCanceled();
172 void ReportError(const CString& sError);
173 void ReportWarning(const CString& sWarning);
174 void ReportNotification(const CString& sNotification);
175 void ReportCmd(const CString& sCmd);
176 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
178 private:
179 void AddItemToList();
180 CString BuildInfoString();
183 * Resizes the columns of the progress list so that the headings are visible.
185 void ResizeColumns();
187 /// Predicate function to tell us if a notification data item is auxiliary or not
188 static bool NotificationDataIsAux(const NotificationData* pData);
190 private:
191 typedef std::vector<NotificationData *> NotificationDataVect;
193 NotificationDataVect m_arData;
195 volatile LONG m_bThreadRunning;
197 int m_options; // Use values from the ProgressOptions enum
200 TCHAR m_columnbuf[MAX_PATH];
202 public:
203 volatile BOOL m_bCancelled;
205 private:
206 int iFirstResized;
207 BOOL bSecondResized;
208 int nEnsureVisibleCount;
210 CString m_sTotalBytesTransferred;
211 size_t m_TotalBytesTransferred;
213 CColors m_Colors;
215 bool m_bFinishedItemAdded;
216 bool m_bLastVisible;
218 public:
219 int m_itemCount;
220 int m_itemCountTotal;
222 public:
223 CComPtr<ITaskbarList3> m_pTaskbarList;
224 void Init();
225 void ShowProgressBar();
227 protected:
228 afx_msg void OnClose();
229 virtual BOOL PreTranslateMessage(MSG* pMsg);
230 afx_msg void OnSysColorChange();
231 UINT m_nBackgroundImageID;
234 class ProgressCommand
236 protected:
237 CTGitPathList m_targetPathList;
239 public:
240 PostCmdCallback m_PostCmdCallback;
242 ProgressCommand()
243 : m_PostCmdCallback(nullptr)
246 void SetPathList(CTGitPathList& pathList) { m_targetPathList = pathList; }
247 virtual bool Run(CGitProgressList* list, CString& sWindowTitle, int& m_itemCountTotal, int& m_itemCount) = 0;
248 virtual bool ShowInfo(CString& /*info*/) { return false; }
249 virtual ~ProgressCommand() {}