Fetch+Rebase: Don't error out if no remote tracked branch is configured for current...
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blob955534a652f132f5ac4d126f5679ac4f62e5ea69
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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 "Git.h"
23 #include "Colors.h"
24 #include "UnicodeUtils.h"
25 #include "resource.h"
26 #include "../TortoiseShell/resource.h"
27 #include "LoglistCommonResource.h"
28 #include "IconMenu.h"
29 #include "ProgressDlg.h"
30 /**
31 * \ingroup TortoiseProc
32 * Options which can be used to configure the way the dialog box works
34 typedef enum
36 ProgOptNone = 0,
37 /// Don't actually do the merge - just practice it
38 ProgOptDryRun = 0x04,
39 } ProgressOptions;
41 // CGitProgressList
42 struct git_transfer_progress;
43 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
44 #define WM_PROG_CMD_FINISH (WM_APP + 200)
45 #define WM_PROG_CMD_START (WM_APP + 201)
47 class ProgressCommand;
48 class CGitProgressList : public CListCtrl
50 DECLARE_DYNAMIC(CGitProgressList)
52 public:
53 CGitProgressList();
54 virtual ~CGitProgressList();
56 void SetCommand(ProgressCommand* command) { ATLASSERT(command); m_Command = command; }
57 void SetOptions(DWORD opts) {m_options = opts;}
59 /**
60 * If the number of items for which the operation is done on is known
61 * beforehand, that number can be set here. It is then used to show a more
62 * accurate progress bar during the operation.
64 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
65 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
66 bool SetBackgroundImage(UINT nID);
67 bool DidErrorsOccur() {return m_bErrorsOccurred;}
68 bool m_bErrorsOccurred;
69 CWnd *m_pProgressLabelCtrl;
70 CWnd *m_pInfoCtrl;
71 CAnimateCtrl *m_pAnimate;
72 CProgressCtrl *m_pProgControl;
73 ProgressCommand *m_Command;
74 void Cancel();
75 volatile BOOL IsCancelled() {return m_bCancelled;}
76 volatile LONG IsRunning() {return m_bThreadRunning;}
77 CWinThread* m_pThread;
78 CWnd *m_pPostWnd;
79 bool m_bSetTitle;
81 public:
82 typedef std::vector<std::function<void()>> ContextMenuActionList;
83 struct Payload
85 CGitProgressList* list;
86 git_repository* repo;
89 class NotificationData
91 public:
92 NotificationData()
93 : color(::GetSysColor(COLOR_WINDOWTEXT))
94 , bAuxItem(false)
95 {};
97 NotificationData(const CTGitPath &path, UINT actionTextId)
98 : NotificationData()
100 this->path = path;
101 sActionColumnText.LoadString(actionTextId);
104 virtual ~NotificationData() {};
106 virtual void SetColorCode(CColors& /*colors*/) {};
107 virtual void GetContextMenu(CIconMenu& /*popup*/, ContextMenuActionList& /*actions*/) {};
108 virtual void HandleDblClick() const {}
110 // The text we put into the first column (the Git action for normal items, just text for aux items)
111 CString sActionColumnText;
112 CTGitPath path;
113 COLORREF color;
114 bool bAuxItem; // Set if this item is not a true 'Git action'
115 CString sPathColumnText;
118 class WC_File_NotificationData : public NotificationData
120 public:
121 typedef enum
123 git_wc_notify_add,
124 git_wc_notify_resolved,
125 git_wc_notify_revert,
126 git_wc_notify_checkout,
127 } git_wc_notify_action_t;
129 WC_File_NotificationData(const CTGitPath& path, git_wc_notify_action_t action);
130 virtual void SetColorCode(CColors& colors);
132 git_wc_notify_action_t action;
134 virtual void GetContextMenu(CIconMenu& popup, ContextMenuActionList& actions);
135 virtual void HandleDblClick() const;
138 void AddNotify(NotificationData* data, CColors::Colors color = CColors::COLOR_END);
139 int UpdateProgress(const git_transfer_progress* stat);
141 void SetProgressLabelText(const CString& str);
143 protected:
144 DECLARE_MESSAGE_MAP()
146 public:
147 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
149 protected:
150 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
151 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
152 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
153 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
154 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
155 afx_msg void OnTimer(UINT_PTR nIDEvent);
156 afx_msg void OnSize(UINT nType, int cx, int cy);
157 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
158 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
160 void Sort();
161 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
163 static BOOL m_bAscending;
164 static int m_nSortedColumn;
166 private:
167 static UINT ProgressThreadEntry(LPVOID pVoid);
168 UINT ProgressThread();
170 public:
171 void ReportGitError();
172 void ReportUserCanceled();
173 void ReportError(const CString& sError);
174 void ReportWarning(const CString& sWarning);
175 void ReportNotification(const CString& sNotification);
176 void ReportCmd(const CString& sCmd);
177 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
179 private:
180 void AddItemToList();
181 CString BuildInfoString();
184 * Resizes the columns of the progress list so that the headings are visible.
186 void ResizeColumns();
188 /// Predicate function to tell us if a notification data item is auxiliary or not
189 static bool NotificationDataIsAux(const NotificationData* pData);
191 private:
192 typedef std::vector<NotificationData *> NotificationDataVect;
194 NotificationDataVect m_arData;
196 volatile LONG m_bThreadRunning;
198 int m_options; // Use values from the ProgressOptions enum
201 TCHAR m_columnbuf[MAX_PATH];
203 public:
204 volatile BOOL m_bCancelled;
206 private:
207 int iFirstResized;
208 BOOL bSecondResized;
209 int nEnsureVisibleCount;
211 CString m_sTotalBytesTransferred;
212 size_t m_TotalBytesTransferred;
214 CColors m_Colors;
216 bool m_bFinishedItemAdded;
217 bool m_bLastVisible;
219 public:
220 int m_itemCount;
221 int m_itemCountTotal;
223 public:
224 CComPtr<ITaskbarList3> m_pTaskbarList;
225 void Init();
226 void ShowProgressBar();
228 protected:
229 afx_msg void OnClose();
230 virtual BOOL PreTranslateMessage(MSG* pMsg);
231 afx_msg void OnSysColorChange();
232 UINT m_nBackgroundImageID;
235 class ProgressCommand
237 protected:
238 CTGitPathList m_targetPathList;
240 public:
241 PostCmdCallback m_PostCmdCallback;
243 ProgressCommand()
244 : m_PostCmdCallback(nullptr)
247 void SetPathList(CTGitPathList& pathList) { m_targetPathList = pathList; }
248 virtual bool Run(CGitProgressList* list, CString& sWindowTitle, int& m_itemCountTotal, int& m_itemCount) = 0;
249 virtual bool ShowInfo(CString& /*info*/) { return false; }
250 virtual ~ProgressCommand() {}