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.
25 #include "UnicodeUtils.h"
28 * \ingroup TortoiseProc
29 * Options which can be used to configure the way the dialog box works
34 /// Don't actually do the merge - just practice it
41 git_wc_notify_sendmail
,
42 git_wc_notify_resolved
,
45 git_wc_notify_checkout
,
46 git_wc_notify_update_ref
,
48 }git_wc_notify_action_t
;
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)
58 class CGitProgressList
: public CListCtrl
60 DECLARE_DYNAMIC(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
);
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
;
107 CAnimateCtrl
*m_pAnimate
;
108 CProgressCtrl
*m_pProgControl
;
111 volatile BOOL
IsCancelled() {return m_bCancelled
;}
112 volatile LONG
IsRunning() {return m_bThreadRunning
;}
113 CWinThread
* m_pThread
;
117 class NotificationData
121 : color(::GetSysColor(COLOR_WINDOWTEXT
))
122 , action((git_wc_notify_action_t
)-1)
125 git_wc_notify_action_t action
;
127 // The text we put into the first column (the Git action for normal items, just text for aux items)
128 CString sActionColumnText
;
133 bool bAuxItem
; // Set if this item is not a true 'Git action'
134 CString sPathColumnText
;
139 DECLARE_MESSAGE_MAP()
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
);
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
)
166 progText
= CUnicodeUtils::GetUnicode(CStringA(str
, len
));
167 ((CGitProgressList
*)data
) -> SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
170 static int RemoteCompletionCallback(git_remote_completion_type
/*type*/, void * /*data*/)
174 static int RemoteUpdatetipsCallback(const char *refname
, const git_oid
*a
, const git_oid
*b
, void *data
)
177 str
= CUnicodeUtils::GetUnicode(refname
);
178 ((CGitProgressList
*)data
) -> Notify(git_wc_notify_update_ref
, str
, a
, b
);
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
);
193 static bool SortCompare(const NotificationData
* pElem1
, const NotificationData
* pElem2
);
195 static BOOL m_bAscending
;
196 static int m_nSortedColumn
;
199 static UINT
ProgressThreadEntry(LPVOID pVoid
);
200 UINT
ProgressThread();
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
));
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
);
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
;
249 GitRev m_RevisionEnd
;
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
;
262 bool m_bMergesAddsDeletesOccurred
;
266 int nEnsureVisibleCount
;
268 CString m_sTotalBytesTransferred
;
269 size_t m_TotalBytesTransferred
;
273 bool m_bFinishedItemAdded
;
277 int m_itemCountTotal
;
279 CSendMail
* m_SendMail
;
281 // some strings different methods can use
294 CComPtr
<ITaskbarList3
> m_pTaskbarList
;
296 void ShowProgressBar();
299 afx_msg
void OnClose();
300 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);