git fetch show progress
[TortoiseGit.git] / src / TortoiseProc / ProgressDlg.h
blob5a452c97b8744838ab0fe76859c84016aa11e177
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #include "StandAloneDlg.h"
22 #include "Git.h"
23 #include "MenuButton.h"
25 #define MSG_PROGRESSDLG_UPDATE_UI (WM_USER+121)
27 // CProgressDlg dialog
28 #define MSG_PROGRESSDLG_START 0
29 #define MSG_PROGRESSDLG_RUN 50
30 #define MSG_PROGRESSDLG_END 110
31 #define MSG_PROGRESSDLG_FAILED 111
33 typedef enum {
34 AUTOCLOSE_NO,
35 AUTOCLOSE_IF_NO_OPTIONS,
36 AUTOCLOSE_IF_NO_ERRORS,
37 } GitProgressAutoClose;
39 typedef std::function<void()> PostCmdAction;
41 class PostCmd
43 public:
44 PostCmd(UINT icon, UINT msgId, PostCmdAction action)
45 : icon(icon)
46 , action(action)
48 label.LoadString(msgId);
51 PostCmd(UINT msgId, PostCmdAction action)
52 : icon(0)
53 , action(action)
55 label.LoadString(msgId);
58 PostCmd(UINT icon, CString label, PostCmdAction action)
59 : icon(icon)
60 , action(action)
61 , label(label)
65 PostCmd(CString label, PostCmdAction action)
66 : icon(0)
67 , action(action)
68 , label(label)
72 UINT icon;
73 CString label;
74 PostCmdAction action;
77 typedef std::vector<PostCmd> PostCmdList;
78 typedef std::function<void(DWORD status, PostCmdList&)> PostCmdCallback;
80 class CProgressDlg : public CResizableStandAloneDialog
82 DECLARE_DYNAMIC(CProgressDlg)
83 public:
84 CProgressDlg(CWnd* pParent = NULL); // standard constructor
85 virtual ~CProgressDlg();
87 private:
88 virtual BOOL OnInitDialog();
90 // Dialog Data
91 enum { IDD = IDD_GITPROGRESS };
93 public:
94 CString m_GitCmd;
95 PostCmdCallback m_PostCmdCallback;
96 std::vector<CString> m_GitCmdList;
97 STRING_VECTOR m_GitDirList;
98 CString m_PreText; // optional text to show in log window before running command
99 bool m_bShowCommand; // whether to display the command in the log window (default true)
100 CString m_LogFile;
101 bool m_bBufferAll; // Buffer All to improve speed when there are many file add at commit
102 GitProgressAutoClose m_AutoClose;
103 CGit * m_Git;
105 DWORD m_GitStatus;
106 CString m_LogText;
108 CString GetLogText() const { CString text; m_Log.GetWindowText(text); return text; }
110 private:
111 PostCmdList m_PostCmdList;
112 void WriteLog() const;
113 CMenuButton m_ctrlPostCmd;
115 CProgressCtrl m_Progress;
117 CRichEditCtrl m_Log;
118 CAnimateCtrl m_Animate;
119 CStatic m_CurrentWork;
120 CWinThread* m_pThread;
122 bool m_bAbort;
123 bool m_bDone;
124 DWORD m_startTick;
126 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
127 static UINT ProgressThreadEntry(LPVOID pVoid);
128 UINT ProgressThread();
130 CStringA m_LogTextA;
132 void ParserCmdOutput(char ch);
133 void RemoveLastLine(CString &str);
135 LRESULT OnProgressUpdateUI(WPARAM wParam,LPARAM lParam);
137 afx_msg LRESULT OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam);
138 CComPtr<ITaskbarList3> m_pTaskbarList;
140 void OnCancel();
141 afx_msg void OnClose();
143 CGitByteArray m_Databuf;
144 virtual CString Convert2UnionCode(char *buff, int size=-1)
146 CString str;
147 g_Git.StringAppend(&str, (BYTE*)buff, CP_UTF8, size);
148 return str;
151 int m_BufStart;
153 DECLARE_MESSAGE_MAP()
155 //Share with Sync Dailog
156 static int FindPercentage(CString &log);
158 static void ClearESC(CString &str);
160 public:
161 static void ParserCmdOutput(CRichEditCtrl &log,CProgressCtrl &progressctrl,HWND m_hWnd,CComPtr<ITaskbarList3> m_pTaskbarList,
162 CStringA &oneline, char ch,CWnd *CurrentWork=NULL);
165 *@param dirlist if empty, the current directory of param git is used; otherwise each entry in param cmdlist uses the corresponding entry in param dirlist
167 static UINT RunCmdList(CWnd *pWnd, STRING_VECTOR &cmdlist, STRING_VECTOR &dirlist, bool bShowCommand, CString *pfilename, bool *bAbort, CGitByteArray *pdata, CGit *git = &g_Git);
169 static void KillProcessTree(DWORD dwProcessId, unsigned int depth = 0);
171 static void InsertColorText(CRichEditCtrl &edit,CString text,COLORREF rgb);
173 private:
174 afx_msg void OnBnClickedOk();
175 afx_msg void OnBnClickedButton1();
177 virtual BOOL PreTranslateMessage(MSG* pMsg);
180 class CCommitProgressDlg:public CProgressDlg
182 public:
183 CCommitProgressDlg(CWnd* pParent = NULL):CProgressDlg(pParent)
187 virtual CString Convert2UnionCode(char *buff, int size=-1);