CommitDlg: Update empty file list message
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blob2f973e07381978f0b7663117b50b1ff075574024
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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 "Win7.h"
25 #include "UnicodeUtils.h"
26 #include "resource.h"
27 #include "../TortoiseShell/resource.h"
28 #include "LoglistCommonResource.h"
29 #include "IconMenu.h"
30 #include "ProgressDlg.h"
31 /**
32 * \ingroup TortoiseProc
33 * Options which can be used to configure the way the dialog box works
35 typedef enum
37 ProgOptNone = 0,
38 /// Don't actually do the merge - just practice it
39 ProgOptDryRun = 0x04,
40 } ProgressOptions;
42 // CGitProgressList
43 struct git_transfer_progress;
44 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
45 #define WM_PROG_CMD_FINISH (WM_APP + 200)
46 #define WM_PROG_CMD_START (WM_APP + 201)
48 class ProgressCommand;
49 class CGitProgressList : public CListCtrl
51 DECLARE_DYNAMIC(CGitProgressList)
53 public:
54 CGitProgressList();
55 virtual ~CGitProgressList();
57 void SetCommand(ProgressCommand* command) { ATLASSERT(command); m_Command = command; }
58 void SetOptions(DWORD opts) {m_options = opts;}
60 /**
61 * If the number of items for which the operation is done on is known
62 * beforehand, that number can be set here. It is then used to show a more
63 * accurate progress bar during the operation.
65 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
66 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
67 bool SetBackgroundImage(UINT nID);
68 bool DidErrorsOccur() {return m_bErrorsOccurred;}
69 bool m_bErrorsOccurred;
70 CWnd *m_pProgressLabelCtrl;
71 CWnd *m_pInfoCtrl;
72 CAnimateCtrl *m_pAnimate;
73 CProgressCtrl *m_pProgControl;
74 ProgressCommand *m_Command;
75 void Cancel();
76 volatile BOOL IsCancelled() {return m_bCancelled;}
77 volatile LONG IsRunning() {return m_bThreadRunning;}
78 CWinThread* m_pThread;
79 CWnd *m_pPostWnd;
80 bool m_bSetTitle;
82 public:
83 typedef std::vector<std::function<void()>> ContextMenuActionList;
84 struct Payload
86 CGitProgressList* list;
87 git_repository* repo;
90 class NotificationData
92 public:
93 NotificationData()
94 : color(::GetSysColor(COLOR_WINDOWTEXT))
95 , bAuxItem(false)
96 {};
98 NotificationData(const CTGitPath &path, UINT actionTextId)
99 : color(::GetSysColor(COLOR_WINDOWTEXT))
100 , bAuxItem(false)
102 this->path = path;
103 sActionColumnText.LoadString(actionTextId);
106 virtual ~NotificationData() {};
108 virtual void SetColorCode(CColors& /*colors*/) {};
109 virtual void GetContextMenu(CIconMenu& /*popup*/, ContextMenuActionList& /*actions*/) {};
110 virtual void HandleDblClick() const {}
112 // The text we put into the first column (the Git action for normal items, just text for aux items)
113 CString sActionColumnText;
114 CTGitPath path;
115 COLORREF color;
116 bool bAuxItem; // Set if this item is not a true 'Git action'
117 CString sPathColumnText;
120 class WC_File_NotificationData : public NotificationData
122 public:
123 typedef enum
125 git_wc_notify_add,
126 git_wc_notify_resolved,
127 git_wc_notify_revert,
128 git_wc_notify_checkout,
129 } git_wc_notify_action_t;
131 WC_File_NotificationData(const CTGitPath& path, git_wc_notify_action_t action);
132 virtual void SetColorCode(CColors& colors);
134 git_wc_notify_action_t action;
136 virtual void GetContextMenu(CIconMenu& popup, ContextMenuActionList& actions);
137 virtual void HandleDblClick() const;
140 void AddNotify(NotificationData* data, CColors::Colors color = CColors::COLOR_END);
141 int UpdateProgress(const git_transfer_progress* stat);
143 void SetProgressLabelText(const CString& str);
145 protected:
146 DECLARE_MESSAGE_MAP()
148 public:
149 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
151 protected:
152 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
153 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
154 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
155 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
156 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
157 afx_msg void OnTimer(UINT_PTR nIDEvent);
158 afx_msg void OnSize(UINT nType, int cx, int cy);
159 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
160 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
162 void Sort();
163 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
165 static BOOL m_bAscending;
166 static int m_nSortedColumn;
168 private:
169 static UINT ProgressThreadEntry(LPVOID pVoid);
170 UINT ProgressThread();
172 public:
173 void ReportGitError();
174 void ReportUserCanceled();
175 void ReportError(const CString& sError);
176 void ReportWarning(const CString& sWarning);
177 void ReportNotification(const CString& sNotification);
178 void ReportCmd(const CString& sCmd);
179 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
181 private:
182 void AddItemToList();
183 CString BuildInfoString();
186 * Resizes the columns of the progress list so that the headings are visible.
188 void ResizeColumns();
190 /// Predicate function to tell us if a notification data item is auxiliary or not
191 static bool NotificationDataIsAux(const NotificationData* pData);
193 private:
194 typedef std::vector<NotificationData *> NotificationDataVect;
196 NotificationDataVect m_arData;
198 volatile LONG m_bThreadRunning;
200 int m_options; // Use values from the ProgressOptions enum
203 TCHAR m_columnbuf[MAX_PATH];
205 public:
206 volatile BOOL m_bCancelled;
208 private:
209 int iFirstResized;
210 BOOL bSecondResized;
211 int nEnsureVisibleCount;
213 CString m_sTotalBytesTransferred;
214 size_t m_TotalBytesTransferred;
216 CColors m_Colors;
218 bool m_bFinishedItemAdded;
219 bool m_bLastVisible;
221 public:
222 int m_itemCount;
223 int m_itemCountTotal;
225 public:
226 CComPtr<ITaskbarList3> m_pTaskbarList;
227 void Init();
228 void ShowProgressBar();
230 protected:
231 afx_msg void OnClose();
232 virtual BOOL PreTranslateMessage(MSG* pMsg);
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() {}