SyncDlg: Disallow in/out changes to include local context menu
[TortoiseGit.git] / src / TortoiseProc / MergeDlg.cpp
blob29c15113a77bd37960e74adb5f9183ee4ed18a1d
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.
20 // MergeDlg.cpp : implementation file
23 #include "stdafx.h"
25 #include "Git.h"
26 #include "TortoiseProc.h"
27 #include "MergeDlg.h"
28 #include "AppUtils.h"
29 #include "HistoryDlg.h"
31 // CMergeDlg dialog
33 IMPLEMENT_DYNAMIC(CMergeDlg, CResizableStandAloneDialog)
35 CMergeDlg::CMergeDlg(CWnd* pParent /*=nullptr*/)
36 : CResizableStandAloneDialog(CMergeDlg::IDD, pParent)
37 , CChooseVersion(this)
38 , m_pDefaultText(MAKEINTRESOURCE(IDS_PROC_AUTOGENERATEDBYGIT))
39 , m_bSquash(BST_UNCHECKED)
40 , m_bNoCommit(BST_UNCHECKED)
41 , m_bLog(BST_UNCHECKED)
42 , m_nPopupPasteLastMessage(0)
43 , m_nPopupRecentMessage(0)
44 , m_bNoFF(BST_UNCHECKED)
45 , m_bFFonly(BST_UNCHECKED)
47 CString mergeLog = g_Git.GetConfigValue(L"merge.log");
48 int nLog = _wtoi(mergeLog);
49 m_nLog = nLog > 0 ? nLog : 20;
50 m_bSkipCurrentBranch = true;
53 CMergeDlg::~CMergeDlg()
57 void CMergeDlg::DoDataExchange(CDataExchange* pDX)
59 CDialog::DoDataExchange(pDX);
61 CHOOSE_VERSION_DDX;
63 DDX_Check(pDX,IDC_CHECK_NOFF,this->m_bNoFF);
64 DDX_Check(pDX,IDC_CHECK_SQUASH,this->m_bSquash);
65 DDX_Check(pDX,IDC_CHECK_NOCOMMIT,this->m_bNoCommit);
66 DDX_Check(pDX, IDC_CHECK_MERGE_LOG, m_bLog);
67 DDX_Text(pDX, IDC_EDIT_MERGE_LOGNUM, m_nLog);
68 DDX_Text(pDX, IDC_COMBO_MERGESTRATEGY, m_MergeStrategy);
69 DDX_Text(pDX, IDC_COMBO_STRATEGYOPTION, m_StrategyOption);
70 DDX_Text(pDX, IDC_EDIT_STRATEGYPARAM, m_StrategyParam);
71 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
72 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
76 BEGIN_MESSAGE_MAP(CMergeDlg, CResizableStandAloneDialog)
77 CHOOSE_VERSION_EVENT
78 ON_BN_CLICKED(IDOK, &CMergeDlg::OnBnClickedOk)
79 ON_WM_DESTROY()
80 ON_BN_CLICKED(IDC_CHECK_SQUASH, &CMergeDlg::OnBnClickedCheckSquash)
81 ON_BN_CLICKED(IDC_CHECK_MERGE_LOG, &CMergeDlg::OnBnClickedCheckMergeLog)
82 ON_CBN_SELCHANGE(IDC_COMBO_MERGESTRATEGY, &CMergeDlg::OnCbnSelchangeComboMergestrategy)
83 ON_CBN_SELCHANGE(IDC_COMBO_STRATEGYOPTION, &CMergeDlg::OnCbnSelchangeComboStrategyoption)
84 ON_BN_CLICKED(IDC_CHECK_FFONLY, OnBnClickedCheckFFonlyOrNoFF)
85 ON_BN_CLICKED(IDC_CHECK_NOFF, OnBnClickedCheckFFonlyOrNoFF)
86 ON_WM_SYSCOLORCHANGE()
87 END_MESSAGE_MAP()
89 void CMergeDlg::ReloadHistoryEntries()
91 m_History.Load(L"Software\\TortoiseGit\\History\\merge", L"logmsgs");
94 BOOL CMergeDlg::OnInitDialog()
96 CResizableStandAloneDialog::OnInitDialog();
97 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
99 CHOOSE_VERSION_ADDANCHOR;
101 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
102 AddAnchor(IDC_STATIC_MERGE_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
103 AddAnchor(IDC_LOGMESSAGE,TOP_LEFT,BOTTOM_RIGHT);
105 AddAnchor(IDOK,BOTTOM_RIGHT);
106 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
107 AddAnchor(IDHELP, BOTTOM_RIGHT);
109 this->AddOthersToAnchor();
111 AdjustControlSize(IDC_RADIO_BRANCH);
112 AdjustControlSize(IDC_RADIO_TAGS);
113 AdjustControlSize(IDC_RADIO_VERSION);
114 AdjustControlSize(IDC_CHECK_SQUASH);
115 AdjustControlSize(IDC_CHECK_NOFF);
116 AdjustControlSize(IDC_CHECK_NOCOMMIT);
117 AdjustControlSize(IDC_CHECK_MERGE_LOG);
119 CheckRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION,IDC_RADIO_BRANCH);
120 this->SetDefaultChoose(IDC_RADIO_BRANCH);
122 CString sWindowTitle;
123 GetWindowText(sWindowTitle);
124 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
126 m_ProjectProperties.ReadProps();
128 m_cLogMessage.Init(m_ProjectProperties);
129 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
130 m_cLogMessage.RegisterContextMenuHandler(this);
132 m_cLogMessage.SetText(m_pDefaultText);
133 m_cLogMessage.EnableWindow(!m_bSquash);
134 if (m_bSquash)
135 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(COLOR_GRAYTEXT), ::GetSysColor(COLOR_BTNFACE));
137 m_History.SetMaxHistoryItems((LONG)CRegDWORD(L"Software\\TortoiseGit\\MaxHistoryItems", 25));
138 ReloadHistoryEntries();
140 ((CComboBox*)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"resolve");
141 ((CComboBox*)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"recursive");
142 ((CComboBox*)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"ours");
143 ((CComboBox*)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"subtree");
144 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ours");
145 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"theirs");
146 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"patience");
147 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-space-change");
148 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-all-space");
149 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-space-at-eol");
150 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"renormalize");
151 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"no-renormalize");
152 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"rename-threshold");
153 ((CComboBox*)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"subtree");
155 EnableSaveRestore(L"MergeDlg");
156 GetDlgItem(IDOK)->SetFocus();
158 if (m_initialRefName.IsEmpty())
160 CString currentBranch;
161 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, currentBranch))
162 currentBranch.Empty();
164 CString pr, pb;
165 g_Git.GetRemotePushBranch(currentBranch, pr, pb);
166 if (!pr.IsEmpty() && !pb.IsEmpty())
167 m_initialRefName = L"remotes/" + pr + L'/' + pb;
170 InitChooseVersion(true);
172 return FALSE;
175 // CMergeDlg message handlers
178 void CMergeDlg::OnBnClickedOk()
180 this->UpdateData(TRUE);
182 this->UpdateRevsionName();
184 if (GetCheckedRadioButton(IDC_RADIO_HEAD, IDC_RADIO_VERSION) == IDC_RADIO_BRANCH && m_ChooseVersioinBranch.GetCurSel() == -1)
186 CMessageBox::Show(GetSafeHwnd(), IDS_B_T_NOTEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION);
187 return;
190 this->m_strLogMesage = m_cLogMessage.GetText() ;
191 if( m_strLogMesage == CString(this->m_pDefaultText) )
193 m_strLogMesage.Empty();
196 if (!m_strLogMesage.IsEmpty() && !m_bNoCommit)
198 ReloadHistoryEntries();
199 m_History.AddEntry(m_strLogMesage);
200 m_History.Save();
203 if (m_MergeStrategy != L"recursive")
204 m_StrategyOption.Empty();
205 if (m_StrategyOption != L"rename-threshold" && m_StrategyOption != L"subtree")
206 m_StrategyParam.Empty();
208 OnOK();
211 void CMergeDlg::OnCancel()
213 UpdateData(TRUE);
214 m_strLogMesage = m_cLogMessage.GetText();
215 if (m_strLogMesage != CString(this->m_pDefaultText) && !m_strLogMesage.IsEmpty() && !m_bNoCommit)
217 ReloadHistoryEntries();
218 m_History.AddEntry(m_strLogMesage);
219 m_History.Save();
221 CResizableStandAloneDialog::OnCancel();
224 void CMergeDlg::OnDestroy()
226 WaitForFinishLoading();
227 __super::OnDestroy();
230 // CSciEditContextMenuInterface
231 void CMergeDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
233 ReloadHistoryEntries();
234 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
235 if (m_History.GetCount() > 0)
237 CString sMenuItemText;
238 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
239 m_nPopupPasteLastMessage = nCmd++;
240 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
242 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
243 m_nPopupRecentMessage = nCmd++;
244 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
248 bool CMergeDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
250 if (m_History.IsEmpty())
251 return false;
253 if (cmd == m_nPopupPasteLastMessage)
255 if (pSciEdit->GetText() == CString(m_pDefaultText))
256 pSciEdit->SetText(L"");
257 CString logmsg (m_History.GetEntry(0));
258 pSciEdit->InsertText(logmsg);
259 return true;
262 if (cmd == m_nPopupRecentMessage)
264 CHistoryDlg historyDlg;
265 historyDlg.SetHistory(m_History);
266 if (historyDlg.DoModal() != IDOK)
267 return false;
269 if (pSciEdit->GetText() == CString(m_pDefaultText))
270 pSciEdit->SetText(L"");
271 m_cLogMessage.InsertText(historyDlg.GetSelectedText(), !m_cLogMessage.GetText().IsEmpty());
272 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
273 return true;
275 return false;
278 void CMergeDlg::OnBnClickedCheckSquash()
280 UpdateData(TRUE);
281 m_cLogMessage.EnableWindow(!m_bSquash);
282 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(m_bSquash ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT), ::GetSysColor(m_bSquash ? COLOR_BTNFACE : COLOR_WINDOW));
283 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(!m_bSquash);
286 void CMergeDlg::OnBnClickedCheckMergeLog()
288 UpdateData(TRUE);
289 GetDlgItem(IDC_EDIT_MERGE_LOGNUM)->EnableWindow(m_bLog);
292 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
294 UpdateData(TRUE);
295 GetDlgItem(IDC_COMBO_STRATEGYOPTION)->EnableWindow(m_MergeStrategy == L"recursive");
296 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_MergeStrategy == L"recursive" ? m_StrategyOption == L"rename-threshold" || m_StrategyOption == L"subtree" : FALSE);
299 void CMergeDlg::OnCbnSelchangeComboStrategyoption()
301 UpdateData(TRUE);
302 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_StrategyOption == L"rename-threshold" || m_StrategyOption == L"subtree");
305 void CMergeDlg::OnBnClickedCheckFFonlyOrNoFF()
307 UpdateData();
309 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(!m_bNoFF);
310 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(!m_bFFonly);
311 GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(!m_bNoFF);
314 void CMergeDlg::OnSysColorChange()
316 __super::OnSysColorChange();
317 m_cLogMessage.SetColors(true);
318 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
319 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(m_bSquash ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT), ::GetSysColor(m_bSquash ? COLOR_BTNFACE : COLOR_WINDOW));