1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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
26 #include "TortoiseProc.h"
29 #include "HistoryDlg.h"
33 IMPLEMENT_DYNAMIC(CMergeDlg
, CResizableStandAloneDialog
)
35 CMergeDlg::CMergeDlg(CWnd
* pParent
/*=nullptr*/)
36 : CResizableStandAloneDialog(CMergeDlg::IDD
, pParent
),
39 m_pDefaultText
= MAKEINTRESOURCE(IDS_PROC_AUTOGENERATEDBYGIT
);
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;
52 CMergeDlg::~CMergeDlg()
56 void CMergeDlg::DoDataExchange(CDataExchange
* pDX
)
58 CDialog::DoDataExchange(pDX
);
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
)
77 ON_BN_CLICKED(IDOK
, &CMergeDlg::OnBnClickedOk
)
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
)
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
);
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);
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
);
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();
191 void CMergeDlg::OnCancel()
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
);
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())
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
);
242 if (cmd
== m_nPopupRecentMessage
)
244 CHistoryDlg historyDlg
;
245 historyDlg
.SetHistory(m_History
);
246 if (historyDlg
.DoModal() != IDOK
)
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();
258 void CMergeDlg::OnBnClickedCheckSquash()
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()
268 GetDlgItem(IDC_EDIT_MERGE_LOGNUM
)->EnableWindow(m_bLog
);
271 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
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()
281 GetDlgItem(IDC_EDIT_STRATEGYPARAM
)->EnableWindow(m_StrategyOption
== _T("rename-threshold") || m_StrategyOption
== _T("subtree"));
284 void CMergeDlg::OnBnClickedCheckFFonlyOrNoFF()
288 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(!m_bNoFF
);
289 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(!m_bFFonly
);