Deduplicate code
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.h
blob95d002f95ed9adf8ddb3dfce9757df9c901be289
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009, 2012-2019 - 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.
20 #pragma once
21 #include "StandAloneDlg.h"
22 #include "HistoryCombo.h"
23 #include "MenuButton.h"
24 #include "registry.h"
25 #include "BranchCombox.h"
26 #include "GitLoglist.h"
27 #include "GitProgressList.h"
28 #include "GitRefCompareList.h"
29 #include "GitTagCompareList.h"
30 #include "SyncTabCtrl.h"
31 #include "GestureEnabledControl.h"
33 // CSyncDlg dialog
34 #define IDC_SYNC_TAB 0x1000000
36 #define IDC_CMD_LOG 0x1
37 #define IDC_IN_LOGLIST 0x2
38 #define IDC_IN_CHANGELIST 0x3
39 #define IDC_IN_CONFLICT 0x4
40 #define IDC_OUT_LOGLIST 0x5
41 #define IDC_OUT_CHANGELIST 0x6
42 #define IDC_CMD_GIT_PROG 0x7
43 #define IDC_REFLIST 0x8
44 #define IDC_TAGCOMPARELIST 0x9
46 #define IDT_INPUT 108
48 class CSyncDlg : public CResizableStandAloneDialog,public CBranchCombox
50 DECLARE_DYNAMIC(CSyncDlg)
52 public:
53 CSyncDlg(CWnd* pParent = nullptr); // standard constructor
54 virtual ~CSyncDlg();
56 // Dialog Data
57 enum { IDD = IDD_SYNC };
59 enum { GIT_COMMAND_PUSH,
60 GIT_COMMAND_PULL,
61 GIT_COMMAND_FETCH,
62 GIT_COMMAND_FETCHANDREBASE,
63 GIT_COMMAND_SUBMODULE,
64 GIT_COMMAND_REMOTE,
65 GIT_COMMAND_STASH
67 protected:
68 virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
69 BRANCH_COMBOX_EVENT_HANDLE();
71 virtual BOOL OnInitDialog() override;
72 afx_msg void OnBnClickedButtonManage();
73 virtual BOOL PreTranslateMessage(MSG* pMsg) override;
74 afx_msg void OnCbnEditchangeComboboxex();
75 afx_msg void OnBnClickedButtonPull();
76 afx_msg void OnBnClickedButtonPush();
77 afx_msg void OnBnClickedButtonApply();
78 afx_msg void OnBnClickedButtonEmail();
79 afx_msg void OnTimer(UINT_PTR nIDEvent);
80 afx_msg void OnDestroy();
81 afx_msg LRESULT OnThemeChanged();
83 afx_msg LRESULT OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam);
84 CComPtr<ITaskbarList3> m_pTaskbarList;
86 int m_CurrentCmd;
88 CRegDWORD m_regPullButton;
89 CRegDWORD m_regPushButton;
90 CRegDWORD m_regSubmoduleButton;
91 CRegDWORD m_regAutoLoadPutty;
93 CSyncTabCtrl m_ctrlTabCtrl;
95 BOOL m_bInited;
97 CGitLogList m_OutLogList;
98 CGitLogList m_InLogList;
99 CGitProgressList m_GitProgressList;
100 std::unique_ptr<ProgressCommand> progressCommand;
102 CGitStatusListCtrl m_OutChangeFileList;
103 CGitStatusListCtrl m_InChangeFileList;
104 CGitStatusListCtrl m_ConflictFileList;
105 ProjectProperties m_ProjectProperties;
107 CGestureEnabledControlTmpl<CRichEditCtrl> m_ctrlCmdOut;
108 CGitRefCompareList m_refList;
109 CGitTagCompareList m_tagCompareList;
111 CTGitPathList m_arOutChangeList;
112 CTGitPathList m_arInChangeList;
114 int m_CmdOutCurrentPos;
116 CWinThread* m_pThread;
118 volatile LONG m_bBlock;
119 CGitGuardedByteArray m_Databuf;
120 int m_BufStart;
122 void ParserCmdOutput(char ch);
124 virtual void LocalBranchChange() override { FetchOutList(); };
125 virtual void RemoteBranchChange() override {};
127 void ShowTab(int windowid)
129 this->m_ctrlTabCtrl.ShowTab(windowid-1);
130 this->m_ctrlTabCtrl.SetActiveTab(windowid-1);
133 void FetchOutList(bool force=false);
135 bool IsURL();
137 virtual void SetRemote(CString remote) override
139 if(!remote.IsEmpty())
141 int index=this->m_ctrlURL.FindStringExact(0,remote);
142 if(index>=0)
144 m_ctrlURL.SetCurSel(index);
145 return;
147 this->m_ctrlURL.AddString(remote);
151 std::vector<CString> m_GitCmdList;
152 STRING_VECTOR m_remotelist;
154 volatile bool m_bAbort;
155 bool m_bDone;
156 ULONGLONG m_startTick;
157 bool m_bWantToExit;
159 int m_GitCmdStatus;
161 CStringA m_LogText;
162 CString m_OutLocalBranch;
163 CString m_OutRemoteBranch;
165 CGitHash m_oldHash;
166 CGitHash m_oldRemoteHash;
167 MAP_HASH_NAME m_oldHashMap;
168 MAP_HASH_NAME m_newHashMap;
170 void ShowProgressCtrl(bool bShow=true);
171 void ShowInputCtrl(bool bShow=true);
172 void SwitchToRun(){ShowProgressCtrl(true);ShowInputCtrl(false);EnableControlButton(false);}
173 void SwitchToInput(){ShowProgressCtrl(false);ShowInputCtrl(true);}
175 LRESULT OnProgressUpdateUI(WPARAM wParam,LPARAM lParam);
176 LRESULT OnProgCmdFinish(WPARAM wParam, LPARAM lParam);
177 void FillNewRefMap();
178 void RunPostAction();
179 void UpdateCombox()
181 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
182 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
183 this->m_ctrlURL.GetWindowText(this->m_strURL);
184 m_strRemoteBranch=m_strRemoteBranch.Trim();
187 void AddDiffFileList(CGitStatusListCtrl *pCtrlList, CTGitPathList *pGitList,
188 CString rev1, CString rev2)
190 g_Git.GetCommitDiffList(rev1,rev2,*pGitList);
191 pCtrlList->m_Rev1=rev1;
192 pCtrlList->m_Rev2=rev2;
193 pCtrlList->SetEmptyString(CString(MAKEINTRESOURCE(IDS_COMPAREREV_NODIFF)));
194 pCtrlList->UpdateWithGitPathList(*pGitList);
195 pCtrlList->Show(GITSLC_SHOWALL);
196 return;
199 void ShowInCommits(const CString& friendname);
200 void PullComplete();
201 void FetchComplete();
202 void StashComplete();
204 DECLARE_MESSAGE_MAP()
206 public:
207 BOOL m_bAutoLoadPuttyKey;
208 BOOL m_bForce;
209 CString m_strURL;
210 int m_seq;
212 protected:
213 static UINT ProgressThreadEntry(LPVOID pVoid) { return reinterpret_cast<CSyncDlg*>(pVoid)->ProgressThread(); };
214 UINT ProgressThread();
216 void StartWorkerThread();
218 CHistoryCombo m_ctrlURL;
219 CButton m_ctrlDumyButton;
220 CMenuButton m_ctrlPull;
221 CMenuButton m_ctrlPush;
222 CStatic m_ctrlStatus;
223 CMenuButton m_ctrlSubmodule;
224 CMenuButton m_ctrlStash;
225 CProgressCtrl m_ctrlProgress;
226 CAnimateCtrl m_ctrlAnimate;
227 CStatic m_ctrlProgLabel;
228 int m_iPullRebase;
230 void EnableControlButton(bool bEnabled=true);
231 afx_msg void OnBnClickedButtonCommit();
233 virtual void OnOK() override;
234 virtual void OnCancel() override;
235 void Refresh();
236 bool AskSetTrackedBranch();
238 afx_msg void OnBnClickedButtonSubmodule();
239 afx_msg void OnBnClickedButtonStash();
240 afx_msg void OnBnClickedCheckForce();
241 afx_msg void OnBnClickedLog();
242 afx_msg void OnEnscrollLog();
243 afx_msg void OnEnLinkLog(NMHDR* pNMHDR, LRESULT* pResult);
245 friend class CSyncTabCtrl;