Add option 'Show complete log'
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blob1da203d72997e4ec7d1acabc05acc7f4841bef4e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 "ProjectProperties.h"
23 #include "Git.h"
24 #include "GitStatus.h"
25 #include "Colors.h"
26 //#include "..\IBugTraqProvider\IBugTraqProvider_h.h"
27 #include "Win7.h"
28 #include "UnicodeUtils.h"
29 #include "resource.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 ProgOptRecursive = 0x01,
38 ProgOptNonRecursive = 0x00,
39 /// Don't actually do the merge - just practice it
40 ProgOptDryRun = 0x04,
41 ProgOptIgnoreExternals = 0x08,
42 ProgOptKeeplocks = 0x10,
43 /// for locking this means steal the lock, for unlocking it means breaking the lock
44 ProgOptLockForce = 0x20,
45 ProgOptSwitchAfterCopy = 0x40,
46 ProgOptIncludeIgnored = 0x80,
47 ProgOptIgnoreAncestry = 0x100,
48 ProgOptEolDefault = 0x200,
49 ProgOptEolCRLF = 0x400,
50 ProgOptEolLF = 0x800,
51 ProgOptEolCR = 0x1000,
52 ProgOptSkipConflictCheck = 0x2000,
53 ProgOptRecordOnly = 0x4000
54 } ProgressOptions;
56 typedef enum
58 CLOSE_MANUAL = 0,
59 CLOSE_NOERRORS,
60 CLOSE_NOCONFLICTS,
61 CLOSE_NOMERGES,
62 CLOSE_LOCAL
63 } ProgressCloseOptions;
65 typedef enum
67 git_wc_notify_add,
68 git_wc_notify_sendmail,
69 git_wc_notify_resolved,
70 git_wc_notify_revert,
71 git_wc_notify_fetch,
72 git_wc_notify_checkout,
73 git_wc_notify_update_ref,
75 }git_wc_notify_action_t;
77 // CGitProgressList
78 struct git_transfer_progress;
79 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
80 #define WM_PROG_CMD_FINISH (WM_APP + 200)
81 #define WM_PROG_CMD_START (WM_APP + 201)
83 class CSendMail;
85 class CGitProgressList : public CListCtrl
87 DECLARE_DYNAMIC(CGitProgressList)
89 public:
90 typedef enum
92 GitProgress_none,
93 GitProgress_Add,
94 GitProgress_Checkout,
95 GitProgress_Copy,
96 GitProgress_Export,
97 GitProgress_Rename,
98 GitProgress_Resolve,
99 GitProgress_Revert,
100 GitProgress_Switch,
101 GitProgress_SendMail,
102 GitProgress_Clone,
103 GitProgress_Fetch,
104 GitProgress_Reset,
105 } Command;
107 CGitProgressList();
108 virtual ~CGitProgressList();
110 void SetCommand(CGitProgressList::Command cmd) {m_Command = cmd;}
111 void SetOptions(DWORD opts) {m_options = opts;}
112 void SetPathList(const CTGitPathList& pathList) {m_targetPathList = pathList;}
113 void SetUrl(const CString& url) {m_url.SetFromUnknown(url);}
114 void SetSecondUrl(const CString& url) {m_url2.SetFromUnknown(url);}
115 void SetCommitMessage(const CString& msg) {m_sMessage = msg;}
116 void SetIsBare(bool b) { m_bBare = b; }
117 void SetNoCheckout(bool b){ m_bNoCheckout = b; }
118 void SetRefSpec(CString spec){ m_RefSpec = spec; }
119 void SetRemote(const CString& remote) { m_remote = remote; }
120 void SetAutoTag(int tag){ m_AutoTag = tag; }
121 void SetRevision(CString revision){ m_revision = revision; }
122 void SetResetType(int resetType){ m_resetType = resetType; }
124 // void SetRevision(const GitRev& rev) {m_Revision = rev;}
125 // void SetRevisionEnd(const GitRev& rev) {m_RevisionEnd = rev;}
127 void SetDiffOptions(const CString& opts) {m_diffoptions = opts;}
128 void SetSendMailOption(CSendMail *sendmail) { m_SendMail = sendmail; }
129 void SetPegRevision(GitRev pegrev = GitRev()) {m_pegRev = pegrev;}
130 void SetProjectProperties(ProjectProperties props) {m_ProjectProperties = props;}
131 void SetChangeList(const CString& changelist, bool keepchangelist) {m_changelist = changelist; m_keepchangelist = keepchangelist;}
132 void SetSelectedList(const CTGitPathList& selPaths);
133 // void SetRevisionRanges(const GitRevRangeArray& revArray) {m_revisionArray = revArray;}
134 // void SetBugTraqProvider(const CComPtr<IBugTraqProvider> pBugtraqProvider) { m_BugTraqProvider = pBugtraqProvider;}
136 * If the number of items for which the operation is done on is known
137 * beforehand, that number can be set here. It is then used to show a more
138 * accurate progress bar during the operation.
140 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
141 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
142 bool SetBackgroundImage(UINT nID);
143 bool DidErrorsOccur() {return m_bErrorsOccurred;}
144 bool m_bErrorsOccurred;
145 CWnd *m_pProgressLabelCtrl;
146 CWnd *m_pInfoCtrl;
147 CAnimateCtrl *m_pAnimate;
148 CProgressCtrl *m_pProgControl;
149 Command m_Command;
150 void Cancel();
151 volatile BOOL IsCancelled() {return m_bCancelled;}
152 volatile LONG IsRunning() {return m_bThreadRunning;}
153 CWinThread* m_pThread;
154 bool m_AlwaysConflicted;
155 CWnd *m_pPostWnd;
156 bool m_bSetTitle;
157 private:
158 class NotificationData
160 public:
161 NotificationData()
162 : color(::GetSysColor(COLOR_WINDOWTEXT))
163 , action((git_wc_notify_action_t)-1)
164 , bConflictedActionItem(false)
165 , bAuxItem(false)
167 git_wc_notify_action_t action;
168 #if 0
169 action((git_wc_notify_action_t)-1),
170 kind(git_node_none),
171 content_state(git_wc_notify_state_inapplicable),
172 prop_state(git_wc_notify_state_inapplicable),
173 rev(0),
175 bConflictedActionItem(false),
176 bAuxItem(false)
178 // lock_state(git_wc_notify_lock_state_unchanged)
180 // merge_range.end = 0;
181 // merge_range.start = 0;
183 #endif
184 public:
185 // The text we put into the first column (the Git action for normal items, just text for aux items)
186 CString sActionColumnText;
187 CTGitPath path;
188 CTGitPath basepath;
189 // CString changelistname;
191 // git_node_kind_t kind;
192 // CString mime_type;
193 // git_wc_notify_state_t content_state;
194 // git_wc_notify_state_t prop_state;
195 // git_wc_notify_lock_state_t lock_state;
196 // git_merge_range_t merge_range;
197 git_revnum_t rev;
198 COLORREF color;
199 // CString owner; ///< lock owner
200 bool bConflictedActionItem; // Is this item a conflict?
201 bool bAuxItem; // Set if this item is not a true 'Git action'
202 CString sPathColumnText;
203 CGitHash m_OldHash;
204 CGitHash m_NewHash;
206 protected:
207 DECLARE_MESSAGE_MAP()
209 public:
210 //Need update in the future implement the virtual methods from Git base class
211 virtual BOOL Notify(const CTGitPath& path,
212 git_wc_notify_action_t action
214 git_node_kind_t kind, const CString& mime_type,
215 git_wc_notify_state_t content_state,
216 git_wc_notify_state_t prop_state, LONG rev,
217 const git_lock_t * lock, git_wc_notify_lock_state_t lock_state,
218 const CString& changelistname,
219 git_merge_range_t * range,
220 git_error_t * err, apr_pool_t * pool*/
222 protected:
223 virtual BOOL Notify(const git_wc_notify_action_t action, const git_transfer_progress *stat);
224 virtual BOOL Notify(const git_wc_notify_action_t action, CString str, const git_oid *a, const git_oid *b);
226 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
228 // virtual git_wc_conflict_choice_t ConflictResolveCallback(const git_wc_conflict_description_t *description, CString& mergedfile);
230 static int FetchCallback(const git_transfer_progress *stats, void *payload)
232 return !((CGitProgressList*)payload) -> Notify(git_wc_notify_fetch, stats);
235 static void CheckoutCallback(const char *path, size_t cur, size_t tot, void *payload)
237 CTGitPath tpath = CUnicodeUtils::GetUnicode(CStringA(path), CP_UTF8);
238 ((CGitProgressList*)payload) -> m_itemCountTotal = (int)tot;
239 ((CGitProgressList*)payload) -> m_itemCount = (int)cur;
240 ((CGitProgressList*)payload) -> Notify(tpath, git_wc_notify_checkout);
243 static int RemoteProgressCallback(const char *str, int len, void *data)
245 CString progText;
246 progText = CUnicodeUtils::GetUnicode(CStringA(str, len));
247 ((CGitProgressList*)data) -> SetDlgItemText(IDC_PROGRESSLABEL, progText);
248 return 0;
250 static int RemoteCompletionCallback(git_remote_completion_type /*type*/, void * /*data*/)
252 return 0;
254 static int RemoteUpdatetipsCallback(const char *refname, const git_oid *a, const git_oid *b, void *data)
256 CString str;
257 str = CUnicodeUtils::GetUnicode(refname);
258 ((CGitProgressList*)data) -> Notify(git_wc_notify_update_ref, str, a, b);
259 return 0;
262 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
263 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
264 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
265 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
266 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
267 afx_msg void OnTimer(UINT_PTR nIDEvent);
268 afx_msg void OnSize(UINT nType, int cx, int cy);
269 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
270 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
272 void Sort();
273 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
275 static BOOL m_bAscending;
276 static int m_nSortedColumn;
277 CStringList m_ExtStack;
279 private:
280 static UINT ProgressThreadEntry(LPVOID pVoid);
281 UINT ProgressThread();
283 public:
284 void ReportGitError();
285 void ReportUserCanceled();
286 void ReportError(const CString& sError);
287 void ReportWarning(const CString& sWarning);
288 void ReportNotification(const CString& sNotification);
289 void ReportCmd(const CString& sCmd);
290 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
291 private:
292 void AddItemToList();
293 CString BuildInfoString();
294 CString GetPathFromColumnText(const CString& sColumnText);
297 * Resizes the columns of the progress list so that the headings are visible.
299 void ResizeColumns();
301 /// Predicate function to tell us if a notification data item is auxiliary or not
302 static bool NotificationDataIsAux(const NotificationData* pData);
304 // the commands to execute
305 bool CmdAdd(CString& sWindowTitle, bool& localoperation);
306 bool CmdCheckout(CString& sWindowTitle, bool& localoperation);
307 bool CmdCopy(CString& sWindowTitle, bool& localoperation);
308 bool CmdExport(CString& sWindowTitle, bool& localoperation);
309 bool CmdRename(CString& sWindowTitle, bool& localoperation);
310 bool CmdResolve(CString& sWindowTitle, bool& localoperation);
311 bool CmdRevert(CString& sWindowTitle, bool& localoperation);
312 bool CmdSwitch(CString& sWindowTitle, bool& localoperation);
313 bool CmdSendMail(CString& sWindowTitle, bool& localoperation);
314 bool CmdClone(CString& sWindowTitle, bool& localoperation);
315 bool CmdFetch(CString& sWindowTitle, bool& localoperation);
316 bool CmdReset(CString& sWindowTitle, bool& localoperation);
318 private:
319 typedef std::map<CStringA, git_revnum_t> StringRevMap;
320 typedef std::vector<NotificationData *> NotificationDataVect;
322 CString m_mergedfile;
323 NotificationDataVect m_arData;
325 volatile LONG m_bThreadRunning;
327 ProjectProperties m_ProjectProperties;
329 int m_options; // Use values from the ProgressOptions enum
330 CTGitPathList m_targetPathList;
331 CTGitPathList m_selectedPaths;
332 CTGitPath m_url;
333 CTGitPath m_url2;
334 CString m_sMessage;
335 CString m_diffoptions;
336 GitRev m_Revision;
337 GitRev m_RevisionEnd;
338 GitRev m_pegRev;
339 // GitRevRangeArray m_revisionArray;
340 CString m_changelist;
341 bool m_keepchangelist;
343 CTGitPath m_basePath;
344 StringRevMap m_UpdateStartRevMap;
345 StringRevMap m_FinishedRevMap;
347 TCHAR m_columnbuf[MAX_PATH];
349 volatile BOOL m_bCancelled;
350 int m_nConflicts;
351 bool m_bMergesAddsDeletesOccurred;
353 int iFirstResized;
354 BOOL bSecondResized;
355 int nEnsureVisibleCount;
357 CString m_sTotalBytesTransferred;
358 size_t m_TotalBytesTransferred;
360 CColors m_Colors;
362 bool m_bFinishedItemAdded;
363 bool m_bLastVisible;
365 int m_itemCount;
366 int m_itemCountTotal;
368 CSendMail * m_SendMail;
370 /// CComPtr<IBugTraqProvider> m_BugTraqProvider;
372 // some strings different methods can use
373 CString sDryRun;
374 CString sRecordOnly;
376 bool m_bBare;
377 bool m_bNoCheckout;
378 CString m_RefSpec;
379 CString m_remote;
380 int m_AutoTag;
381 CString m_revision;
382 int m_resetType;
383 public:
384 CComPtr<ITaskbarList3> m_pTaskbarList;
385 void Init();
386 afx_msg void OnClose();
387 virtual BOOL PreTranslateMessage(MSG* pMsg);