GitProgressList: Do not show download progress animation for reset
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blob36c6f096a059a783f22be07d2a3404fc8946df53
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 /**
28 * \ingroup TortoiseProc
29 * Options which can be used to configure the way the dialog box works
31 typedef enum
33 ProgOptNone = 0,
34 /// Don't actually do the merge - just practice it
35 ProgOptDryRun = 0x04,
36 } ProgressOptions;
38 typedef enum
40 git_wc_notify_add,
41 git_wc_notify_sendmail,
42 git_wc_notify_resolved,
43 git_wc_notify_revert,
44 git_wc_notify_fetch,
45 git_wc_notify_checkout,
46 git_wc_notify_update_ref,
48 }git_wc_notify_action_t;
50 // CGitProgressList
51 struct git_transfer_progress;
52 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
53 #define WM_PROG_CMD_FINISH (WM_APP + 200)
54 #define WM_PROG_CMD_START (WM_APP + 201)
56 class CSendMail;
58 class CGitProgressList : public CListCtrl
60 DECLARE_DYNAMIC(CGitProgressList)
62 public:
63 typedef enum
65 GitProgress_none,
66 GitProgress_Add,
67 GitProgress_Checkout,
68 GitProgress_Resolve,
69 GitProgress_Revert,
70 GitProgress_SendMail,
71 GitProgress_Clone,
72 GitProgress_Fetch,
73 GitProgress_Reset,
74 } Command;
76 CGitProgressList();
77 virtual ~CGitProgressList();
79 void SetCommand(CGitProgressList::Command cmd) {m_Command = cmd;}
80 void SetOptions(DWORD opts) {m_options = opts;}
81 void SetPathList(const CTGitPathList& pathList) {m_targetPathList = pathList;}
82 void SetUrl(const CString& url) {m_url.SetFromUnknown(url);}
83 void SetSecondUrl(const CString& url) {m_url2.SetFromUnknown(url);}
84 void SetCommitMessage(const CString& msg) {m_sMessage = msg;}
85 void SetIsBare(bool b) { m_bBare = b; }
86 void SetNoCheckout(bool b){ m_bNoCheckout = b; }
87 void SetRefSpec(CString spec){ m_RefSpec = spec; }
88 void SetRemote(const CString& remote) { m_remote = remote; }
89 void SetAutoTag(int tag){ m_AutoTag = tag; }
90 void SetRevision(CString revision){ m_revision = revision; }
91 void SetResetType(int resetType){ m_resetType = resetType; }
93 void SetSendMailOption(CSendMail *sendmail) { m_SendMail = sendmail; }
94 void SetSelectedList(const CTGitPathList& selPaths);
95 /**
96 * If the number of items for which the operation is done on is known
97 * beforehand, that number can be set here. It is then used to show a more
98 * accurate progress bar during the operation.
100 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
101 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
102 bool SetBackgroundImage(UINT nID);
103 bool DidErrorsOccur() {return m_bErrorsOccurred;}
104 bool m_bErrorsOccurred;
105 CWnd *m_pProgressLabelCtrl;
106 CWnd *m_pInfoCtrl;
107 CAnimateCtrl *m_pAnimate;
108 CProgressCtrl *m_pProgControl;
109 Command m_Command;
110 void Cancel();
111 volatile BOOL IsCancelled() {return m_bCancelled;}
112 volatile LONG IsRunning() {return m_bThreadRunning;}
113 CWinThread* m_pThread;
114 CWnd *m_pPostWnd;
115 bool m_bSetTitle;
116 private:
117 class NotificationData
119 public:
120 NotificationData()
121 : color(::GetSysColor(COLOR_WINDOWTEXT))
122 , action((git_wc_notify_action_t)-1)
123 , bAuxItem(false)
125 git_wc_notify_action_t action;
126 public:
127 // The text we put into the first column (the Git action for normal items, just text for aux items)
128 CString sActionColumnText;
129 CTGitPath path;
130 CTGitPath basepath;
131 git_revnum_t rev;
132 COLORREF color;
133 bool bAuxItem; // Set if this item is not a true 'Git action'
134 CString sPathColumnText;
135 CGitHash m_OldHash;
136 CGitHash m_NewHash;
138 protected:
139 DECLARE_MESSAGE_MAP()
141 public:
142 //Need update in the future implement the virtual methods from Git base class
143 virtual BOOL Notify(const CTGitPath& path, git_wc_notify_action_t action);
144 protected:
145 virtual BOOL Notify(const git_wc_notify_action_t action, const git_transfer_progress *stat);
146 virtual BOOL Notify(const git_wc_notify_action_t action, CString str, const git_oid *a, const git_oid *b);
148 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
150 static int FetchCallback(const git_transfer_progress *stats, void *payload)
152 return !((CGitProgressList*)payload) -> Notify(git_wc_notify_fetch, stats);
155 static void CheckoutCallback(const char *path, size_t cur, size_t tot, void *payload)
157 CTGitPath tpath = CUnicodeUtils::GetUnicode(CStringA(path), CP_UTF8);
158 ((CGitProgressList*)payload) -> m_itemCountTotal = (int)tot;
159 ((CGitProgressList*)payload) -> m_itemCount = (int)cur;
160 ((CGitProgressList*)payload) -> Notify(tpath, git_wc_notify_checkout);
163 static int RemoteProgressCallback(const char *str, int len, void *data)
165 CString progText;
166 progText = CUnicodeUtils::GetUnicode(CStringA(str, len));
167 ((CGitProgressList*)data) -> SetDlgItemText(IDC_PROGRESSLABEL, progText);
168 return 0;
170 static int RemoteCompletionCallback(git_remote_completion_type /*type*/, void * /*data*/)
172 return 0;
174 static int RemoteUpdatetipsCallback(const char *refname, const git_oid *a, const git_oid *b, void *data)
176 CString str;
177 str = CUnicodeUtils::GetUnicode(refname);
178 ((CGitProgressList*)data) -> Notify(git_wc_notify_update_ref, str, a, b);
179 return 0;
182 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
183 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
184 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
185 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
186 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
187 afx_msg void OnTimer(UINT_PTR nIDEvent);
188 afx_msg void OnSize(UINT nType, int cx, int cy);
189 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
190 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
192 void Sort();
193 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
195 static BOOL m_bAscending;
196 static int m_nSortedColumn;
198 private:
199 static UINT ProgressThreadEntry(LPVOID pVoid);
200 UINT ProgressThread();
202 public:
203 void ReportGitError();
204 void ReportUserCanceled();
205 void ReportError(const CString& sError);
206 void ReportWarning(const CString& sWarning);
207 void ReportNotification(const CString& sNotification);
208 void ReportCmd(const CString& sCmd);
209 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
211 private:
212 void AddItemToList();
213 CString BuildInfoString();
214 CString GetPathFromColumnText(const CString& sColumnText);
217 * Resizes the columns of the progress list so that the headings are visible.
219 void ResizeColumns();
221 /// Predicate function to tell us if a notification data item is auxiliary or not
222 static bool NotificationDataIsAux(const NotificationData* pData);
224 // the commands to execute
225 bool CmdAdd(CString& sWindowTitle, bool& localoperation);
226 bool CmdCheckout(CString& sWindowTitle, bool& localoperation);
227 bool CmdResolve(CString& sWindowTitle, bool& localoperation);
228 bool CmdRevert(CString& sWindowTitle, bool& localoperation);
229 bool CmdSendMail(CString& sWindowTitle, bool& localoperation);
230 bool CmdClone(CString& sWindowTitle, bool& localoperation);
231 bool CmdFetch(CString& sWindowTitle, bool& localoperation);
232 bool CmdReset(CString& sWindowTitle, bool& localoperation);
234 private:
235 typedef std::map<CStringA, git_revnum_t> StringRevMap;
236 typedef std::vector<NotificationData *> NotificationDataVect;
238 NotificationDataVect m_arData;
240 volatile LONG m_bThreadRunning;
242 int m_options; // Use values from the ProgressOptions enum
243 CTGitPathList m_targetPathList;
244 CTGitPathList m_selectedPaths;
245 CTGitPath m_url;
246 CTGitPath m_url2;
247 CString m_sMessage;
248 GitRev m_Revision;
249 GitRev m_RevisionEnd;
250 GitRev m_pegRev;
251 CString m_changelist;
252 bool m_keepchangelist;
254 CTGitPath m_basePath;
255 StringRevMap m_UpdateStartRevMap;
256 StringRevMap m_FinishedRevMap;
258 TCHAR m_columnbuf[MAX_PATH];
260 volatile BOOL m_bCancelled;
261 int m_nConflicts;
262 bool m_bMergesAddsDeletesOccurred;
264 int iFirstResized;
265 BOOL bSecondResized;
266 int nEnsureVisibleCount;
268 CString m_sTotalBytesTransferred;
269 size_t m_TotalBytesTransferred;
271 CColors m_Colors;
273 bool m_bFinishedItemAdded;
274 bool m_bLastVisible;
276 int m_itemCount;
277 int m_itemCountTotal;
279 CSendMail * m_SendMail;
281 // some strings different methods can use
282 CString sDryRun;
283 CString sRecordOnly;
285 bool m_bBare;
286 bool m_bNoCheckout;
287 CString m_RefSpec;
288 CString m_remote;
289 int m_AutoTag;
290 CString m_revision;
291 int m_resetType;
293 public:
294 CComPtr<ITaskbarList3> m_pTaskbarList;
295 void Init();
296 void ShowProgressBar();
298 protected:
299 afx_msg void OnClose();
300 virtual BOOL PreTranslateMessage(MSG* pMsg);