Add icon for fetch post action reset
[TortoiseGit.git] / src / TortoiseProc / MergeDlg.cpp
blob4eed41e609624b4d8cd36566bad9111008bbeb7c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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_SQUASH, &CMergeDlg::OnBnClickedCheckSquash)
78 ON_BN_CLICKED(IDC_CHECK_MERGE_LOG, &CMergeDlg::OnBnClickedCheckMergeLog)
79 ON_CBN_SELCHANGE(IDC_COMBO_MERGESTRATEGY, &CMergeDlg::OnCbnSelchangeComboMergestrategy)
80 ON_CBN_SELCHANGE(IDC_COMBO_STRATEGYOPTION, &CMergeDlg::OnCbnSelchangeComboStrategyoption)
81 END_MESSAGE_MAP()
84 BOOL CMergeDlg::OnInitDialog()
86 CResizableStandAloneDialog::OnInitDialog();
87 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
89 CHOOSE_VERSION_ADDANCHOR;
91 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
92 AddAnchor(IDC_STATIC_MERGE_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
93 AddAnchor(IDC_LOGMESSAGE,TOP_LEFT,BOTTOM_RIGHT);
95 AddAnchor(IDOK,BOTTOM_RIGHT);
96 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
97 AddAnchor(IDHELP, BOTTOM_RIGHT);
99 this->AddOthersToAnchor();
101 AdjustControlSize(IDC_RADIO_BRANCH);
102 AdjustControlSize(IDC_RADIO_TAGS);
103 AdjustControlSize(IDC_RADIO_VERSION);
104 AdjustControlSize(IDC_CHECK_SQUASH);
105 AdjustControlSize(IDC_CHECK_NOFF);
106 AdjustControlSize(IDC_CHECK_NOCOMMIT);
107 AdjustControlSize(IDC_CHECK_MERGE_LOG);
109 CheckRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION,IDC_RADIO_BRANCH);
110 this->SetDefaultChoose(IDC_RADIO_BRANCH);
112 CString sWindowTitle;
113 GetWindowText(sWindowTitle);
114 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
116 m_ProjectProperties.ReadProps();
118 m_cLogMessage.Init(m_ProjectProperties);
119 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
120 m_cLogMessage.RegisterContextMenuHandler(this);
122 m_cLogMessage.SetText(m_pDefaultText);
123 m_cLogMessage.EnableWindow(!m_bSquash);
124 if (m_bSquash)
125 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(COLOR_GRAYTEXT), ::GetSysColor(COLOR_BTNFACE));
127 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
128 if (m_History.IsEmpty())
129 m_History.Load(_T("Software\\TortoiseGit\\History\\merge"), _T("logmsgs"));
131 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("resolve"));
132 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("recursive"));
133 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("ours"));
134 ((CComboBox *)GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(_T("subtree"));
135 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ours"));
136 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("theirs"));
137 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("patience"));
138 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-change"));
139 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-all-space"));
140 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("ignore-space-at-eol"));
141 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("renormalize"));
142 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("no-renormalize"));
143 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("rename-threshold"));
144 ((CComboBox *)GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(_T("subtree"));
146 EnableSaveRestore(_T("MergeDlg"));
147 GetDlgItem(IDOK)->SetFocus();
149 InitChooseVersion(true);
151 return FALSE;
154 // CMergeDlg message handlers
157 void CMergeDlg::OnBnClickedOk()
159 this->UpdateData(TRUE);
161 this->UpdateRevsionName();
163 this->m_strLogMesage = m_cLogMessage.GetText() ;
164 if( m_strLogMesage == CString(this->m_pDefaultText) )
166 m_strLogMesage.Empty();
169 if (!m_strLogMesage.IsEmpty() && !m_bNoCommit)
171 m_History.AddEntry(m_strLogMesage);
172 m_History.Save();
175 if (m_MergeStrategy != _T("recursive"))
176 m_StrategyOption = _T("");
177 if (m_StrategyOption != _T("rename-threshold") && m_StrategyOption != _T("subtree"))
178 m_StrategyParam = _T("");
180 OnOK();
183 void CMergeDlg::OnCancel()
185 UpdateData(TRUE);
186 m_strLogMesage = m_cLogMessage.GetText();
187 if (m_strLogMesage != CString(this->m_pDefaultText) && !m_strLogMesage.IsEmpty() && !m_bNoCommit)
189 m_History.AddEntry(m_strLogMesage);
190 m_History.Save();
192 CResizableStandAloneDialog::OnCancel();
195 void CMergeDlg::OnDestroy()
197 WaitForFinishLoading();
198 __super::OnDestroy();
201 // CSciEditContextMenuInterface
202 void CMergeDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
204 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
205 if (m_History.GetCount() > 0)
207 CString sMenuItemText;
208 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
209 m_nPopupPasteLastMessage = nCmd++;
210 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
212 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
213 m_nPopupRecentMessage = nCmd++;
214 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
218 bool CMergeDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
220 if (m_History.IsEmpty())
221 return false;
223 if (cmd == m_nPopupPasteLastMessage)
225 if (pSciEdit->GetText() == CString(m_pDefaultText))
226 pSciEdit->SetText(_T(""));
227 CString logmsg (m_History.GetEntry(0));
228 pSciEdit->InsertText(logmsg);
229 return true;
232 if (cmd == m_nPopupRecentMessage)
234 CHistoryDlg historyDlg;
235 historyDlg.SetHistory(m_History);
236 if (historyDlg.DoModal() != IDOK)
237 return false;
239 if (pSciEdit->GetText() == CString(m_pDefaultText))
240 pSciEdit->SetText(_T(""));
241 m_cLogMessage.InsertText(historyDlg.GetSelectedText(), !m_cLogMessage.GetText().IsEmpty());
242 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
243 return true;
245 return false;
248 void CMergeDlg::OnBnClickedCheckSquash()
250 UpdateData(TRUE);
251 m_cLogMessage.EnableWindow(!m_bSquash);
252 m_cLogMessage.SetAStyle(STYLE_DEFAULT, ::GetSysColor(m_bSquash ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT), ::GetSysColor(m_bSquash ? COLOR_BTNFACE : COLOR_WINDOW));
255 void CMergeDlg::OnBnClickedCheckMergeLog()
257 UpdateData(TRUE);
258 GetDlgItem(IDC_EDIT_MERGE_LOGNUM)->EnableWindow(m_bLog);
261 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
263 UpdateData(TRUE);
264 GetDlgItem(IDC_COMBO_STRATEGYOPTION)->EnableWindow(m_MergeStrategy == _T("recursive"));
265 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_MergeStrategy == _T("recursive") ? m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree") : FALSE);
268 void CMergeDlg::OnCbnSelchangeComboStrategyoption()
270 UpdateData(TRUE);
271 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_StrategyOption == _T("rename-threshold") || m_StrategyOption == _T("subtree"));