Dropped unused includes
[TortoiseGit.git] / src / TortoiseProc / GitProgressList.h
blobf1040ae4b453717df8f929eaed88f5db4c6aa921
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 "afxwin.h"
28 #include "Win7.h"
29 #include "UnicodeUtils.h"
30 #include "resource.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 ProgOptRecursive = 0x01,
39 ProgOptNonRecursive = 0x00,
40 /// Don't actually do the merge - just practice it
41 ProgOptDryRun = 0x04,
42 ProgOptIgnoreExternals = 0x08,
43 ProgOptKeeplocks = 0x10,
44 /// for locking this means steal the lock, for unlocking it means breaking the lock
45 ProgOptLockForce = 0x20,
46 ProgOptSwitchAfterCopy = 0x40,
47 ProgOptIncludeIgnored = 0x80,
48 ProgOptIgnoreAncestry = 0x100,
49 ProgOptEolDefault = 0x200,
50 ProgOptEolCRLF = 0x400,
51 ProgOptEolLF = 0x800,
52 ProgOptEolCR = 0x1000,
53 ProgOptSkipConflictCheck = 0x2000,
54 ProgOptRecordOnly = 0x4000
55 } ProgressOptions;
57 typedef enum
59 CLOSE_MANUAL = 0,
60 CLOSE_NOERRORS,
61 CLOSE_NOCONFLICTS,
62 CLOSE_NOMERGES,
63 CLOSE_LOCAL
64 } ProgressCloseOptions;
66 typedef enum
68 git_wc_notify_add,
69 git_wc_notify_sendmail,
70 git_wc_notify_resolved,
71 git_wc_notify_revert,
72 git_wc_notify_fetch,
73 git_wc_notify_checkout,
74 git_wc_notify_update_ref,
76 }git_wc_notify_action_t;
78 // CGitProgressList
79 struct git_transfer_progress;
80 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
81 #define WM_PROG_CMD_FINISH (WM_APP + 200)
82 #define WM_PROG_CMD_START (WM_APP + 201)
84 class CSendMail;
86 class CGitProgressList : public CListCtrl
88 DECLARE_DYNAMIC(CGitProgressList)
90 public:
91 typedef enum
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 } Command;
106 CGitProgressList();
107 virtual ~CGitProgressList();
109 void SetCommand(CGitProgressList::Command cmd) {m_Command = cmd;}
110 void SetOptions(DWORD opts) {m_options = opts;}
111 void SetPathList(const CTGitPathList& pathList) {m_targetPathList = pathList;}
112 void SetUrl(const CString& url) {m_url.SetFromUnknown(url);}
113 void SetSecondUrl(const CString& url) {m_url2.SetFromUnknown(url);}
114 void SetCommitMessage(const CString& msg) {m_sMessage = msg;}
115 void SetIsBare(bool b) { m_bBare = b; }
116 void SetNoCheckout(bool b){ m_bNoCheckout = b; }
117 void SetRefSpec(CString spec){ m_RefSpec = spec; }
118 void SetAutoTag(int tag){ m_AutoTag = tag; }
120 // void SetRevision(const GitRev& rev) {m_Revision = rev;}
121 // void SetRevisionEnd(const GitRev& rev) {m_RevisionEnd = rev;}
123 void SetDiffOptions(const CString& opts) {m_diffoptions = opts;}
124 void SetSendMailOption(CSendMail *sendmail) { m_SendMail = sendmail; }
125 void SetDepth(git_depth_t depth = git_depth_unknown) {m_depth = depth;}
126 void SetPegRevision(GitRev pegrev = GitRev()) {m_pegRev = pegrev;}
127 void SetProjectProperties(ProjectProperties props) {m_ProjectProperties = props;}
128 void SetChangeList(const CString& changelist, bool keepchangelist) {m_changelist = changelist; m_keepchangelist = keepchangelist;}
129 void SetSelectedList(const CTGitPathList& selPaths);
130 // void SetRevisionRanges(const GitRevRangeArray& revArray) {m_revisionArray = revArray;}
131 // void SetBugTraqProvider(const CComPtr<IBugTraqProvider> pBugtraqProvider) { m_BugTraqProvider = pBugtraqProvider;}
133 * If the number of items for which the operation is done on is known
134 * beforehand, that number can be set here. It is then used to show a more
135 * accurate progress bar during the operation.
137 void SetItemCountTotal(long count) { if(count) m_itemCountTotal = count; }
138 void SetItemProgress(long count) { m_itemCount = count;} // do not use SetItemCount here as this overrides the ListBox method
139 bool SetBackgroundImage(UINT nID);
140 bool DidErrorsOccur() {return m_bErrorsOccurred;}
141 bool m_bErrorsOccurred;
142 CWnd *m_pProgressLabelCtrl;
143 CWnd *m_pInfoCtrl;
144 CAnimateCtrl *m_pAnimate;
145 CProgressCtrl *m_pProgControl;
146 Command m_Command;
147 void Cancel();
148 volatile BOOL IsCancelled() {return m_bCancelled;}
149 volatile LONG IsRunning() {return m_bThreadRunning;}
150 CWinThread* m_pThread;
151 bool m_AlwaysConflicted;
152 CWnd *m_pPostWnd;
153 bool m_bSetTitle;
154 private:
155 class NotificationData
157 public:
158 NotificationData()
159 : color(::GetSysColor(COLOR_WINDOWTEXT))
160 , action((git_wc_notify_action_t)-1)
161 , bConflictedActionItem(false)
162 , bAuxItem(false)
164 git_wc_notify_action_t action;
165 #if 0
166 action((git_wc_notify_action_t)-1),
167 kind(git_node_none),
168 content_state(git_wc_notify_state_inapplicable),
169 prop_state(git_wc_notify_state_inapplicable),
170 rev(0),
172 bConflictedActionItem(false),
173 bAuxItem(false)
175 // lock_state(git_wc_notify_lock_state_unchanged)
177 // merge_range.end = 0;
178 // merge_range.start = 0;
180 #endif
181 public:
182 // The text we put into the first column (the Git action for normal items, just text for aux items)
183 CString sActionColumnText;
184 CTGitPath path;
185 CTGitPath basepath;
186 // CString changelistname;
188 // git_node_kind_t kind;
189 // CString mime_type;
190 // git_wc_notify_state_t content_state;
191 // git_wc_notify_state_t prop_state;
192 // git_wc_notify_lock_state_t lock_state;
193 // git_merge_range_t merge_range;
194 git_revnum_t rev;
195 COLORREF color;
196 // CString owner; ///< lock owner
197 bool bConflictedActionItem; // Is this item a conflict?
198 bool bAuxItem; // Set if this item is not a true 'Git action'
199 CString sPathColumnText;
200 CGitHash m_OldHash;
201 CGitHash m_NewHash;
203 protected:
204 DECLARE_MESSAGE_MAP()
206 public:
207 //Need update in the future implement the virtual methods from Git base class
208 virtual BOOL Notify(const CTGitPath& path,
209 git_wc_notify_action_t action
211 git_node_kind_t kind, const CString& mime_type,
212 git_wc_notify_state_t content_state,
213 git_wc_notify_state_t prop_state, LONG rev,
214 const git_lock_t * lock, git_wc_notify_lock_state_t lock_state,
215 const CString& changelistname,
216 git_merge_range_t * range,
217 git_error_t * err, apr_pool_t * pool*/
219 protected:
220 virtual BOOL Notify(const git_wc_notify_action_t action, const git_transfer_progress *stat);
221 virtual BOOL Notify(const git_wc_notify_action_t action, CString str, const git_oid *a, const git_oid *b);
223 void SetWindowTitle(UINT id, const CString& urlorpath, CString& dialogname);
225 // virtual git_wc_conflict_choice_t ConflictResolveCallback(const git_wc_conflict_description_t *description, CString& mergedfile);
227 static int FetchCallback(const git_transfer_progress *stats, void *payload)
229 return !((CGitProgressList*)payload) -> Notify(git_wc_notify_fetch, stats);
232 static void CheckoutCallback(const char *path, size_t cur, size_t tot, void *payload)
234 CTGitPath tpath = CUnicodeUtils::GetUnicode(CStringA(path), CP_UTF8);
235 ((CGitProgressList*)payload) -> m_itemCountTotal = (int)tot;
236 ((CGitProgressList*)payload) -> m_itemCount = (int)cur;
237 ((CGitProgressList*)payload) -> Notify(tpath, git_wc_notify_checkout);
240 static void RemoteProgressCallback(const char *str, int len, void *data)
242 CString progText;
243 progText = CUnicodeUtils::GetUnicode(CStringA(str, len));
244 ((CGitProgressList*)data) -> SetDlgItemText(IDC_PROGRESSLABEL, progText);
246 static int RemoteCompletionCallback(git_remote_completion_type /*type*/, void * /*data*/)
248 return 0;
250 static int RemoteUpdatetipsCallback(const char *refname, const git_oid *a, const git_oid *b, void *data)
252 CString str;
253 str = CUnicodeUtils::GetUnicode(refname);
254 ((CGitProgressList*)data) -> Notify(git_wc_notify_update_ref, str, a, b);
255 return 0;
258 afx_msg void OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
259 afx_msg void OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
260 afx_msg void OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
261 afx_msg void OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
262 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
263 afx_msg void OnTimer(UINT_PTR nIDEvent);
264 afx_msg void OnSize(UINT nType, int cx, int cy);
265 LRESULT OnShowConflictResolver(WPARAM, LPARAM);
266 afx_msg void OnLvnBegindragSvnprogress(NMHDR *pNMHDR, LRESULT *pResult);
268 void Sort();
269 static bool SortCompare(const NotificationData* pElem1, const NotificationData* pElem2);
271 static BOOL m_bAscending;
272 static int m_nSortedColumn;
273 CStringList m_ExtStack;
275 private:
276 static UINT ProgressThreadEntry(LPVOID pVoid);
277 UINT ProgressThread();
279 public:
280 void ReportGitError();
281 void ReportUserCanceled();
282 void ReportError(const CString& sError);
283 void ReportWarning(const CString& sWarning);
284 void ReportNotification(const CString& sNotification);
285 void ReportCmd(const CString& sCmd);
286 void ReportString(CString sMessage, const CString& sMsgKind, COLORREF color = ::GetSysColor(COLOR_WINDOWTEXT));
287 private:
288 void AddItemToList();
289 CString BuildInfoString();
290 CString GetPathFromColumnText(const CString& sColumnText);
293 * Resizes the columns of the progress list so that the headings are visible.
295 void ResizeColumns();
297 /// Predicate function to tell us if a notification data item is auxiliary or not
298 static bool NotificationDataIsAux(const NotificationData* pData);
300 // the commands to execute
301 bool CmdAdd(CString& sWindowTitle, bool& localoperation);
302 bool CmdCheckout(CString& sWindowTitle, bool& localoperation);
303 bool CmdCopy(CString& sWindowTitle, bool& localoperation);
304 bool CmdExport(CString& sWindowTitle, bool& localoperation);
305 bool CmdRename(CString& sWindowTitle, bool& localoperation);
306 bool CmdResolve(CString& sWindowTitle, bool& localoperation);
307 bool CmdRevert(CString& sWindowTitle, bool& localoperation);
308 bool CmdSwitch(CString& sWindowTitle, bool& localoperation);
309 bool CmdSendMail(CString& sWindowTitle, bool& localoperation);
310 bool CmdClone(CString& sWindowTitle, bool& localoperation);
311 bool CmdFetch(CString& sWindowTitle, bool& localoperation);
313 private:
314 typedef std::map<CStringA, git_revnum_t> StringRevMap;
315 typedef std::vector<NotificationData *> NotificationDataVect;
317 CString m_mergedfile;
318 NotificationDataVect m_arData;
320 volatile LONG m_bThreadRunning;
322 ProjectProperties m_ProjectProperties;
324 int m_options; // Use values from the ProgressOptions enum
325 git_depth_t m_depth;
326 CTGitPathList m_targetPathList;
327 CTGitPathList m_selectedPaths;
328 CTGitPath m_url;
329 CTGitPath m_url2;
330 CString m_sMessage;
331 CString m_diffoptions;
332 GitRev m_Revision;
333 GitRev m_RevisionEnd;
334 GitRev m_pegRev;
335 // GitRevRangeArray m_revisionArray;
336 CString m_changelist;
337 bool m_keepchangelist;
339 CTGitPath m_basePath;
340 StringRevMap m_UpdateStartRevMap;
341 StringRevMap m_FinishedRevMap;
343 TCHAR m_columnbuf[MAX_PATH];
345 volatile BOOL m_bCancelled;
346 int m_nConflicts;
347 bool m_bMergesAddsDeletesOccurred;
349 int iFirstResized;
350 BOOL bSecondResized;
351 int nEnsureVisibleCount;
353 CString m_sTotalBytesTransferred;
354 size_t m_TotalBytesTransferred;
356 CColors m_Colors;
358 bool m_bFinishedItemAdded;
359 bool m_bLastVisible;
361 int m_itemCount;
362 int m_itemCountTotal;
364 CSendMail * m_SendMail;
366 /// CComPtr<IBugTraqProvider> m_BugTraqProvider;
368 // some strings different methods can use
369 CString sDryRun;
370 CString sRecordOnly;
372 bool m_bBare;
373 bool m_bNoCheckout;
374 CString m_RefSpec;
375 int m_AutoTag;
376 public:
377 CComPtr<ITaskbarList3> m_pTaskbarList;
378 void Init();
379 afx_msg void OnClose();
380 virtual BOOL PreTranslateMessage(MSG* pMsg);