Fixed issue #2568: Add Fast Forward Only option to the merge dialog (--ff-only)
[TortoiseGit.git] / src / TortoiseProc / MergeDlg.cpp
blob02f079dfb5744d2c38c2e6fea8cd1c31b1fff644
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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 /*=NULL*/)
36 : CResizableStandAloneDialog(CMergeDlg::IDD, pParent),
37 CChooseVersion(this)
39 m_pDefaultText = MAKEINTRESOURCE(IDS_PROC_AUTOGENERATEDBYGIT);
40 m_bSquash=false;
41 m_bNoCommit=false;
42 m_bLog = FALSE;
43 CString mergeLog = g_Git.GetConfigValue(_T("merge.log"));
44 int nLog = _ttoi(mergeLog);
45 m_nLog = nLog > 0 ? nLog : 20;
46 m_nPopupPasteLastMessage = 0;
47 m_nPopupRecentMessage = 0;
48 m_bNoFF = FALSE;
49 m_bFFonly = FALSE;
52 CMergeDlg::~CMergeDlg()
56 void CMergeDlg::DoDataExchange(CDataExchange* pDX)
58 CDialog::DoDataExchange(pDX);
60 CHOOSE_VERSION_DDX;
62 DDX_Check(pDX,IDC_CHECK_NOFF,this->m_bNoFF);
63 DDX_Check(pDX,IDC_CHECK_SQUASH,this->m_bSquash);
64 DDX_Check(pDX,IDC_CHECK_NOCOMMIT,this->m_bNoCommit);
65 DDX_Check(pDX, IDC_CHECK_MERGE_LOG, m_bLog);
66 DDX_Text(pDX, IDC_EDIT_MERGE_LOGNUM, m_nLog);
67 DDX_Text(pDX, IDC_COMBO_MERGESTRATEGY, m_MergeStrategy);
68 DDX_Text(pDX, IDC_COMBO_STRATEGYOPTION, m_StrategyOption);
69 DDX_Text(pDX, IDC_EDIT_STRATEGYPARAM, m_StrategyParam);
70 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
71 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
75 BEGIN_MESSAGE_MAP(CMergeDlg, CResizableStandAloneDialog)
76 CHOOSE_VERSION_EVENT
77 ON_BN_CLICKED(IDOK, &CMergeDlg::OnBnClickedOk)
78 ON_WM_DESTROY()
79 ON_BN_CLICKED(IDC_CHECK_SQUASH, &CMergeDlg::OnBnClickedCheckSquash)
80 ON_BN_CLICKED(IDC_CHECK_MERGE_LOG, &CMergeDlg::OnBnClickedCheckMergeLog)
81 ON_CBN_SELCHANGE(IDC_COMBO_MERGESTRATEGY, &CMergeDlg::OnCbnSelchangeComboMergestrategy)
82 ON_CBN_SELCHANGE(IDC_COMBO_STRATEGYOPTION, &CMergeDlg::OnCbnSelchangeComboStrategyoption)
83 ON_BN_CLICKED(IDC_CHECK_FFONLY, OnBnClickedCheckFFonlyOrNoFF)
84 ON_BN_CLICKED(IDC_CHECK_NOFF, OnBnClickedCheckFFonlyOrNoFF)
85 END_MESSAGE_MAP()
87 void CMergeDlg::ReloadHistoryEntries()
89 m_History.Load(_T("Software\\TortoiseGit\\History\\merge"), _T("logmsgs"));
92 BOOL CMergeDlg::OnInitDialog()
94 CResizableStandAloneDialog::OnInitDialog();
95 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
97 CHOOSE_VERSION_ADDANCHOR;
99 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
100 AddAnchor(IDC_STATIC_MERGE_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
101 AddAnchor(IDC_LOGMESSAGE,TOP_LEFT,BOTTOM_RIGHT);
103 AddAnchor(IDOK,BOTTOM_RIGHT);
104 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
105 AddAnchor(IDHELP, BOTTOM_RIGHT);
107 this->AddOthersToAnchor();
109 AdjustControlSize(IDC_RADIO_BRANCH);
110 AdjustControlSize(IDC_RADIO_TAGS);
111 AdjustControlSize(IDC_RADIO_VERSION);
112 AdjustControlSize(IDC_CHECK_SQUASH);
113 AdjustControlSize(IDC_CHECK_NOFF);
114 AdjustControlSize(IDC_CHECK_NOCOMMIT);
115 AdjustControlSize(IDC_CHECK_MERGE_LOG);
117 CheckRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION,IDC_RADIO_BRANCH);
118 this->SetDefaultChoose(IDC_RADIO_BRANCH);
120 CString sWindowTitle;
121 GetWindowText(sWindowTitle);
122 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
124 m_ProjectProperties.ReadProps();
126 m_cLogMessage.Init(m_ProjectProperties);
127 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
128 m_cLogMessage.RegisterContextMenuHandler(this);
130 m_cLogMessage.SetText(m_pDefaultText);
131 m_cLogMessage.EnableWindow(!m_bSquash);
132 if (m_bSquash)
133 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(COLOR_GRAYTEXT), ::GetSysColor(COLOR_BTNFACE));
135 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
136 ReloadHistoryEntries();
138 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("resolve"));
139 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("recursive"));
140 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("ours"));
141 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("subtree"));
142 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ours"));
143 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("theirs"));
144 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("patience"));
145 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-change"));
146 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-all-space"));
147 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-at-eol"));
148 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("renormalize"));
149 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("no-renormalize"));
150 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("rename-threshold"));
151 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("subtree"));
153 EnableSaveRestore(_T("MergeDlg"));
154 GetDlgItem(IDOK)->SetFocus();
156 InitChooseVersion(true);
158 return FALSE;
161 // CMergeDlg message handlers
164 void CMergeDlg::OnBnClickedOk()
166 this->UpdateData(TRUE);
168 this->UpdateRevsionName();
170 this->m_strLogMesage = m_cLogMessage.GetText() ;
171 if( m_strLogMesage == CString(this->m_pDefaultText) )
173 m_strLogMesage.Empty();
176 if (!m_strLogMesage.IsEmpty() && !m_bNoCommit)
178 ReloadHistoryEntries();
179 m_History.AddEntry(m_strLogMesage);
180 m_History.Save();
183 if (m_MergeStrategy != _T("recursive"))
184 m_StrategyOption.Empty();
185 if (m_StrategyOption != _T("rename-threshold") && m_StrategyOption != _T("subtree"))
186 m_StrategyParam.Empty();
188 OnOK();
191 void CMergeDlg::OnCancel()
193 UpdateData(TRUE);
194 m_strLogMesage = m_cLogMessage.GetText();
195 if (m_strLogMesage != CString(this->m_pDefaultText) && !m_strLogMesage.IsEmpty() && !m_bNoCommit)
197 ReloadHistoryEntries();
198 m_History.AddEntry(m_strLogMesage);
199 m_History.Save();
201 CResizableStandAloneDialog::OnCancel();
204 void CMergeDlg::OnDestroy()
206 WaitForFinishLoading();
207 __super::OnDestroy();
210 // CSciEditContextMenuInterface
211 void CMergeDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
213 ReloadHistoryEntries();
214 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
215 if (m_History.GetCount() > 0)
217 CString sMenuItemText;
218 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
219 m_nPopupPasteLastMessage = nCmd++;
220 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
222 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
223 m_nPopupRecentMessage = nCmd++;
224 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
228 bool CMergeDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
230 if (m_History.IsEmpty())
231 return false;
233 if (cmd == m_nPopupPasteLastMessage)
235 if (pSciEdit->GetText() == CString(m_pDefaultText))
236 pSciEdit->SetText(_T(""));
237 CString logmsg (m_History.GetEntry(0));
238 pSciEdit->InsertText(logmsg);
239 return true;
242 if (cmd == m_nPopupRecentMessage)
244 CHistoryDlg historyDlg;
245 historyDlg.SetHistory(m_History);
246 if (historyDlg.DoModal() != IDOK)
247 return false;
249 if (pSciEdit->GetText() == CString(m_pDefaultText))
250 pSciEdit->SetText(_T(""));
251 m_cLogMessage.InsertText(historyDlg.GetSelectedText(), !m_cLogMessage.GetText().IsEmpty());
252 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
253 return true;
255 return false;
258 void CMergeDlg::OnBnClickedCheckSquash()
260 UpdateData(TRUE);
261 m_cLogMessage.EnableWindow(!m_bSquash);
262 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(m_bSquash ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT), ::GetSysColor(m_bSquash ? COLOR_BTNFACE : COLOR_WINDOW));
265 void CMergeDlg::OnBnClickedCheckMergeLog()
267 UpdateData(TRUE);
268 GetDlgItem(IDC_EDIT_MERGE_LOGNUM)->EnableWindow(m_bLog);
271 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
273 UpdateData(TRUE);
274 GetDlgItem(IDC_COMBO_STRATEGYOPTION)->EnableWindow(m_MergeStrategy == _T("recursive"));
275 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_MergeStrategy == _T("recursive") ? m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree") : FALSE);
278 void CMergeDlg::OnCbnSelchangeComboStrategyoption()
280 UpdateData(TRUE);
281 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree"));
284 void CMergeDlg::OnBnClickedCheckFFonlyOrNoFF()
286 UpdateData();
288 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(!m_bNoFF);
289 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(!m_bFFonly);