Fetch+Rebase: Don't error out if no remote tracked branch is configured for current...
[TortoiseGit.git] / src / TortoiseProc / ProgressDlg.h
blob8db0a7928d9942d35d2dd49260dfad8348f97d1a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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 : PostCmd(0, msgId, action)
56 PostCmd(UINT icon, CString label, PostCmdAction action)
57 : icon(icon)
58 , action(action)
59 , label(label)
63 PostCmd(CString label, PostCmdAction action)
64 : PostCmd(0, label, action)
68 UINT icon;
69 CString label;
70 PostCmdAction action;
73 typedef std::vector<PostCmd> PostCmdList;
74 typedef std::function<void(DWORD status, PostCmdList&)> PostCmdCallback;
75 typedef std::function<void(DWORD& exitCode, CString& extraMsg)> PostExecCallback;
77 class CProgressDlg : public CResizableStandAloneDialog
79 DECLARE_DYNAMIC(CProgressDlg)
80 public:
81 CProgressDlg(CWnd* pParent = nullptr); // standard constructor
82 virtual ~CProgressDlg();
84 private:
85 virtual BOOL OnInitDialog();
87 // Dialog Data
88 enum { IDD = IDD_GITPROGRESS };
90 public:
91 CString m_GitCmd;
92 PostCmdCallback m_PostCmdCallback;
93 std::vector<CString> m_GitCmdList;
94 PostExecCallback m_PostExecCallback; // After executing command line, this callback can modify exit code / display extra message
95 STRING_VECTOR m_GitDirList;
96 CString m_PreText; // optional text to show in log window before running command
97 CString m_PreFailText; // optional fail text to show in log window
98 bool m_bShowCommand; // whether to display the command in the log window (default true)
99 CString m_LogFile;
100 bool m_bBufferAll; // Buffer All to improve speed when there are many file add at commit
101 GitProgressAutoClose m_AutoClose;
102 CGit * m_Git;
104 DWORD m_GitStatus;
105 CString m_LogText;
107 CString GetLogText() const { CString text; m_Log.GetWindowText(text); return text; }
109 private:
110 PostCmdList m_PostCmdList;
111 void WriteLog() const;
112 CMenuButton m_ctrlPostCmd;
114 CProgressCtrl m_Progress;
116 CRichEditCtrl m_Log;
117 CAnimateCtrl m_Animate;
118 CStatic m_CurrentWork;
119 CWinThread* m_pThread;
121 volatile bool m_bAbort;
122 bool m_bDone;
123 ULONGLONG m_startTick;
125 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
126 static UINT ProgressThreadEntry(LPVOID pVoid);
127 UINT ProgressThread();
129 CStringA m_LogTextA;
131 void ParserCmdOutput(char ch);
132 void RemoveLastLine(CString &str);
133 static const int s_iProgressLinesLimit;
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 afx_msg void OnEnscrollLog();
144 afx_msg void OnEnLinkLog(NMHDR* pNMHDR, LRESULT* pResult);
146 CGitGuardedByteArray m_Databuf;
147 virtual CString Convert2UnionCode(char *buff, int size=-1)
149 CString str;
150 CGit::StringAppend(&str, (BYTE*)buff, CP_UTF8, size);
151 return str;
154 int m_BufStart;
156 DECLARE_MESSAGE_MAP()
158 //Share with Sync Dailog
159 static int ParsePercentage(CString &log, int pos);
161 static void ClearESC(CString &str);
163 public:
164 static void ParserCmdOutput(CRichEditCtrl &log,CProgressCtrl &progressctrl,HWND m_hWnd,CComPtr<ITaskbarList3> m_pTaskbarList,
165 CStringA& oneline, char ch, CWnd* CurrentWork = nullptr);
168 *@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
170 static UINT RunCmdList(CWnd* pWnd, STRING_VECTOR& cmdlist, STRING_VECTOR& dirlist, bool bShowCommand, CString* pfilename, volatile bool* bAbort, CGitGuardedByteArray* pdata, CGit* git = &g_Git);
172 static void KillProcessTree(DWORD dwProcessId, unsigned int depth = 0);
174 static void InsertColorText(CRichEditCtrl &edit,CString text,COLORREF rgb);
176 private:
177 afx_msg void OnBnClickedOk();
178 afx_msg void OnBnClickedButton1();
180 virtual BOOL PreTranslateMessage(MSG* pMsg);
182 typedef struct {
183 int id;
184 int cnt;
185 int wmid;
186 } ACCELLERATOR;
187 std::map<TCHAR, ACCELLERATOR> m_accellerators;
188 HACCEL m_hAccel;
189 virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
192 class CCommitProgressDlg:public CProgressDlg
194 public:
195 CCommitProgressDlg(CWnd* pParent = nullptr) : CProgressDlg(pParent)
199 virtual CString Convert2UnionCode(char *buff, int size=-1);