Dropped unused variables
[TortoiseGit.git] / src / TortoiseProc / MergeDlg.cpp
blob78f86d17f80e8276f2244385dfa21911627b0cb8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2013 - 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"
30 #include "Messagebox.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_bNoFF=false;
41 m_bSquash=false;
42 m_bNoCommit=false;
43 m_bLog = FALSE;
44 CString mergeLog = g_Git.GetConfigValue(_T("merge.log"));
45 int nLog = _ttoi(mergeLog);
46 m_nLog = nLog > 0 ? nLog : 20;
47 m_nPopupPasteLastMessage = 0;
48 m_nPopupRecentMessage = 0;
51 CMergeDlg::~CMergeDlg()
55 void CMergeDlg::DoDataExchange(CDataExchange* pDX)
57 CDialog::DoDataExchange(pDX);
59 CHOOSE_VERSION_DDX;
61 DDX_Check(pDX,IDC_CHECK_NOFF,this->m_bNoFF);
62 DDX_Check(pDX,IDC_CHECK_SQUASH,this->m_bSquash);
63 DDX_Check(pDX,IDC_CHECK_NOCOMMIT,this->m_bNoCommit);
64 DDX_Check(pDX, IDC_CHECK_MERGE_LOG, m_bLog);
65 DDX_Text(pDX, IDC_EDIT_MERGE_LOGNUM, m_nLog);
66 DDX_Text(pDX, IDC_COMBO_MERGESTRATEGY, m_MergeStrategy);
67 DDX_Text(pDX, IDC_COMBO_STRATEGYOPTION, m_StrategyOption);
68 DDX_Text(pDX, IDC_EDIT_STRATEGYPARAM, m_StrategyParam);
69 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
73 BEGIN_MESSAGE_MAP(CMergeDlg, CResizableStandAloneDialog)
74 CHOOSE_VERSION_EVENT
75 ON_BN_CLICKED(IDOK, &CMergeDlg::OnBnClickedOk)
76 ON_WM_DESTROY()
77 ON_BN_CLICKED(IDC_CHECK_MERGE_LOG, &CMergeDlg::OnBnClickedCheckMergeLog)
78 ON_CBN_SELCHANGE(IDC_COMBO_MERGESTRATEGY, &CMergeDlg::OnCbnSelchangeComboMergestrategy)
79 ON_CBN_SELCHANGE(IDC_COMBO_STRATEGYOPTION, &CMergeDlg::OnCbnSelchangeComboStrategyoption)
80 END_MESSAGE_MAP()
83 BOOL CMergeDlg::OnInitDialog()
85 CResizableStandAloneDialog::OnInitDialog();
86 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
88 CHOOSE_VERSION_ADDANCHOR;
90 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
91 AddAnchor(IDC_STATIC_MERGE_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
92 AddAnchor(IDC_LOGMESSAGE,TOP_LEFT,BOTTOM_RIGHT);
94 AddAnchor(IDOK,BOTTOM_RIGHT);
95 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
96 AddAnchor(IDHELP, BOTTOM_RIGHT);
98 this->AddOthersToAnchor();
100 AdjustControlSize(IDC_RADIO_BRANCH);
101 AdjustControlSize(IDC_RADIO_TAGS);
102 AdjustControlSize(IDC_RADIO_VERSION);
103 AdjustControlSize(IDC_CHECK_SQUASH);
104 AdjustControlSize(IDC_CHECK_NOFF);
105 AdjustControlSize(IDC_CHECK_NOCOMMIT);
106 AdjustControlSize(IDC_CHECK_MERGE_LOG);
108 CheckRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION,IDC_RADIO_BRANCH);
109 this->SetDefaultChoose(IDC_RADIO_BRANCH);
111 CString sWindowTitle;
112 GetWindowText(sWindowTitle);
113 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
115 Init(true);
117 m_ProjectProperties.ReadProps(CTGitPath(g_Git.m_CurrentDir));
119 m_cLogMessage.Init(m_ProjectProperties);
120 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
121 m_cLogMessage.RegisterContextMenuHandler(this);
123 m_cLogMessage.SetText(m_pDefaultText);
125 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
126 if (m_History.GetCount() == 0)
127 m_History.Load(_T("Software\\TortoiseGit\\History\\merge"), _T("logmsgs"));
129 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("resolve"));
130 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("recursive"));
131 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("ours"));
132 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("subtree"));
133 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ours"));
134 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("theirs"));
135 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("patience"));
136 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-change"));
137 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-all-space"));
138 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-at-eol"));
139 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("renormalize"));
140 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("no-renormalize"));
141 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("rename-threshold"));
142 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("subtree"));
144 EnableSaveRestore(_T("MergeDlg"));
145 GetDlgItem(IDOK)->SetFocus();
147 return FALSE;
150 // CMergeDlg message handlers
153 void CMergeDlg::OnBnClickedOk()
155 this->UpdateData(TRUE);
157 this->UpdateRevsionName();
159 this->m_strLogMesage = m_cLogMessage.GetText() ;
160 if( m_strLogMesage == CString(this->m_pDefaultText) )
162 m_strLogMesage.Empty();
165 if (!m_strLogMesage.IsEmpty() && !m_bNoCommit)
167 m_History.AddEntry(m_strLogMesage);
168 m_History.Save();
171 if (m_MergeStrategy != _T("recursive"))
172 m_StrategyOption = _T("");
173 if (m_StrategyOption != _T("rename-threshold") && m_StrategyOption != _T("subtree"))
174 m_StrategyParam = _T("");
176 OnOK();
179 void CMergeDlg::OnCancel()
181 UpdateData(TRUE);
182 m_strLogMesage = m_cLogMessage.GetText();
183 if (m_strLogMesage != CString(this->m_pDefaultText) && !m_strLogMesage.IsEmpty() && !m_bNoCommit)
185 m_History.AddEntry(m_strLogMesage);
186 m_History.Save();
188 CResizableStandAloneDialog::OnCancel();
191 void CMergeDlg::OnDestroy()
193 WaitForFinishLoading();
194 __super::OnDestroy();
197 // CSciEditContextMenuInterface
198 void CMergeDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
200 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
201 if (m_History.GetCount() > 0)
203 CString sMenuItemText;
204 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
205 m_nPopupPasteLastMessage = nCmd++;
206 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
208 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
209 m_nPopupRecentMessage = nCmd++;
210 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
214 bool CMergeDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
216 if (m_History.GetCount() == 0)
217 return false;
219 if (cmd == m_nPopupPasteLastMessage)
221 if (pSciEdit->GetText() == CString(m_pDefaultText))
222 pSciEdit->SetText(_T(""));
223 CString logmsg (m_History.GetEntry(0));
224 pSciEdit->InsertText(logmsg);
225 return true;
228 if (cmd == m_nPopupRecentMessage)
230 CHistoryDlg historyDlg;
231 historyDlg.SetHistory(m_History);
232 if (historyDlg.DoModal() != IDOK)
233 return false;
235 if (pSciEdit->GetText() == CString(m_pDefaultText))
236 pSciEdit->SetText(_T(""));
237 m_cLogMessage.InsertText(historyDlg.GetSelectedText(), !m_cLogMessage.GetText().IsEmpty());
238 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
239 return true;
241 return false;
244 void CMergeDlg::OnBnClickedCheckMergeLog()
246 UpdateData(TRUE);
247 GetDlgItem(IDC_EDIT_MERGE_LOGNUM)->EnableWindow(m_bLog);
250 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
252 UpdateData(TRUE);
253 GetDlgItem(IDC_COMBO_STRATEGYOPTION)->EnableWindow(m_MergeStrategy == _T("recursive"));
254 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_MergeStrategy == _T("recursive") ? m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree") : FALSE);
257 void CMergeDlg::OnCbnSelchangeComboStrategyoption()
259 UpdateData(TRUE);
260 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree"));