Improve line margin icon for moved lines
[TortoiseGit.git] / src / TortoiseProc / ProgressDlg.h
blob14444560aceb9e76a39c86f6a846b3b96b816b98
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - 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"
24 #include "GestureEnabledControl.h"
26 #define MSG_PROGRESSDLG_UPDATE_UI (WM_USER+121)
28 // CProgressDlg dialog
29 #define MSG_PROGRESSDLG_START 0
30 #define MSG_PROGRESSDLG_RUN 50
31 #define MSG_PROGRESSDLG_END 110
32 #define MSG_PROGRESSDLG_FAILED 111
34 typedef enum {
35 AUTOCLOSE_NO,
36 AUTOCLOSE_IF_NO_OPTIONS,
37 AUTOCLOSE_IF_NO_ERRORS,
38 } GitProgressAutoClose;
40 typedef std::function<void()> PostCmdAction;
42 class PostCmd
44 public:
45 PostCmd(UINT icon, UINT msgId, PostCmdAction action)
46 : icon(icon)
47 , action(action)
49 label.LoadString(msgId);
52 PostCmd(UINT msgId, PostCmdAction action)
53 : PostCmd(0, msgId, action)
57 PostCmd(UINT icon, CString label, PostCmdAction action)
58 : icon(icon)
59 , action(action)
60 , label(label)
64 PostCmd(CString label, PostCmdAction action)
65 : PostCmd(0, label, action)
69 UINT icon;
70 CString label;
71 PostCmdAction action;
74 typedef std::vector<PostCmd> PostCmdList;
75 typedef std::function<void(DWORD status, PostCmdList&)> PostCmdCallback;
76 typedef std::function<void(DWORD& exitCode, CString& extraMsg)> PostExecCallback;
78 class CProgressDlg : public CResizableStandAloneDialog
80 DECLARE_DYNAMIC(CProgressDlg)
81 public:
82 CProgressDlg(CWnd* pParent = nullptr); // standard constructor
83 virtual ~CProgressDlg();
85 private:
86 virtual BOOL OnInitDialog();
88 // Dialog Data
89 enum { IDD = IDD_GITPROGRESS };
91 public:
92 CString m_GitCmd;
93 PostCmdCallback m_PostCmdCallback;
94 std::vector<CString> m_GitCmdList;
95 PostExecCallback m_PostExecCallback; // After executing command line, this callback can modify exit code / display extra message
96 STRING_VECTOR m_GitDirList;
97 CString m_PreText; // optional text to show in log window before running command
98 CString m_PreFailText; // optional fail text to show in log window
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 CGestureEnabledControlTmpl<CRichEditCtrl> m_Log;
118 CAnimateCtrl m_Animate;
119 CStatic m_CurrentWork;
120 CWinThread* m_pThread;
122 volatile bool m_bAbort;
123 bool m_bDone;
124 ULONGLONG 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);
134 static const int s_iProgressLinesLimit;
136 LRESULT OnProgressUpdateUI(WPARAM wParam,LPARAM lParam);
138 afx_msg LRESULT OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam);
139 CComPtr<ITaskbarList3> m_pTaskbarList;
141 void OnCancel();
142 afx_msg void OnClose();
144 afx_msg void OnEnscrollLog();
145 afx_msg void OnEnLinkLog(NMHDR* pNMHDR, LRESULT* pResult);
147 CGitGuardedByteArray m_Databuf;
148 virtual CString Convert2UnionCode(char *buff, int size=-1)
150 CString str;
151 CGit::StringAppend(&str, (BYTE*)buff, CP_UTF8, size);
152 return str;
155 int m_BufStart;
157 DECLARE_MESSAGE_MAP()
159 //Share with Sync Dailog
160 static int ParsePercentage(CString &log, int pos);
162 static void ClearESC(CString &str);
164 public:
165 static void ParserCmdOutput(CRichEditCtrl &log,CProgressCtrl &progressctrl,HWND m_hWnd,CComPtr<ITaskbarList3> m_pTaskbarList,
166 CStringA& oneline, char ch, CWnd* CurrentWork = nullptr);
169 *@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
171 static UINT RunCmdList(CWnd* pWnd, STRING_VECTOR& cmdlist, STRING_VECTOR& dirlist, bool bShowCommand, CString* pfilename, volatile bool* bAbort, CGitGuardedByteArray* pdata, CGit* git = &g_Git);
173 static void KillProcessTree(DWORD dwProcessId, unsigned int depth = 0);
175 static void InsertColorText(CRichEditCtrl &edit,CString text,COLORREF rgb);
177 private:
178 afx_msg void OnBnClickedOk();
179 afx_msg void OnBnClickedButton1();
181 virtual BOOL PreTranslateMessage(MSG* pMsg);
183 typedef struct {
184 int id;
185 int cnt;
186 int wmid;
187 } ACCELLERATOR;
188 std::map<TCHAR, ACCELLERATOR> m_accellerators;
189 HACCEL m_hAccel;
190 virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
193 class CCommitProgressDlg:public CProgressDlg
195 public:
196 CCommitProgressDlg(CWnd* pParent = nullptr) : CProgressDlg(pParent)
200 virtual CString Convert2UnionCode(char *buff, int size=-1);