Add new settings dialog "Dialogs 3"
[TortoiseGit.git] / src / TortoiseProc / Settings / SetDialogs3.cpp
blobf2738b64fede45ccee1600f76446c0a08858ded8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 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.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "SetMainPage.h"
22 #include "ProjectProperties.h"
23 #include "SetDialogs3.h"
25 CComboBox CSetDialogs3::m_langCombo;
27 IMPLEMENT_DYNAMIC(CSetDialogs3, ISettingsPropPage)
28 CSetDialogs3::CSetDialogs3()
29 : ISettingsPropPage(CSetDialogs3::IDD)
30 , m_bNeedSave(false)
34 CSetDialogs3::~CSetDialogs3()
38 void CSetDialogs3::DoDataExchange(CDataExchange* pDX)
40 ISettingsPropPage::DoDataExchange(pDX);
41 DDX_Control(pDX, IDC_LANGCOMBO, m_langCombo);
42 DDX_Text(pDX, IDC_LOGMINSIZE, m_LogMinSize);
43 DDX_Text(pDX, IDC_BORDER, m_Border);
44 DDX_Control(pDX, IDC_WARN_NO_SIGNED_OFF_BY, m_cWarnNoSignedOffBy);
45 GITSETTINGS_DDX
48 BEGIN_MESSAGE_MAP(CSetDialogs3, ISettingsPropPage)
49 GITSETTINGS_RADIO_EVENT
50 ON_CBN_SELCHANGE(IDC_LANGCOMBO, &OnChange)
51 ON_CBN_SELCHANGE(IDC_WARN_NO_SIGNED_OFF_BY, &OnChange)
52 ON_EN_CHANGE(IDC_LOGMINSIZE, &OnChange)
53 ON_EN_CHANGE(IDC_BORDER, &OnChange)
54 END_MESSAGE_MAP()
56 // CSetDialogs2 message handlers
57 BOOL CSetDialogs3::OnInitDialog()
59 ISettingsPropPage::OnInitDialog();
61 AddTrueFalseToComboBox(m_cWarnNoSignedOffBy);
63 m_langCombo.AddString(_T(""));
64 m_langCombo.SetItemData(0, 0);
65 m_langCombo.AddString(_T("(disable)"));
66 m_langCombo.SetItemData(1, (DWORD_PTR)-1);
67 // fill the combo box with all available languages
68 EnumSystemLocales(EnumLocalesProc, LCID_SUPPORTED);
70 m_tooltips.Create(this);
72 InitGitSettings(this, true, &m_tooltips);
74 UpdateData(FALSE);
75 return TRUE;
78 static void SelectLanguage(CComboBox &combobox, LONG langueage)
80 for (int i = 0; i < combobox.GetCount(); ++i)
82 if (combobox.GetItemData(i) == langueage)
84 combobox.SetCurSel(i);
85 break;
90 void CSetDialogs3::LoadDataImpl(git_config * config)
93 CString value;
94 GetConfigValue(config, PROJECTPROPNAME_PROJECTLANGUAGE, value);
95 if (value == _T("-1"))
96 m_langCombo.SetCurSel(1);
97 else if (!value.IsEmpty())
99 LPTSTR strEnd;
100 long longValue = _tcstol(value, &strEnd, 0);
101 if (longValue == 0)
103 if (m_iConfigSource == 0)
104 SelectLanguage(m_langCombo, CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033));
105 else
106 m_langCombo.SetCurSel(0);
108 else
109 SelectLanguage(m_langCombo, longValue);
110 } else if (m_iConfigSource == 0)
111 SelectLanguage(m_langCombo, CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033));
112 else
113 m_langCombo.SetCurSel(0);
117 m_LogMinSize = _T("");
118 CString value;
119 GetConfigValue(config, PROJECTPROPNAME_LOGMINSIZE, value);
120 if (!value.IsEmpty() || m_iConfigSource == 0)
122 int nMinLogSize = _ttoi(value);
123 m_LogMinSize.Format(L"%d", nMinLogSize);
128 m_Border = _T("");
129 CString value;
130 GetConfigValue(config, PROJECTPROPNAME_LOGWIDTHLINE, value);
131 if (!value.IsEmpty() || m_iConfigSource == 0)
133 int nLogWidthMarker = _ttoi(value);
134 m_Border.Format(L"%d", nLogWidthMarker);
138 GetBoolConfigValueComboBox(config, PROJECTPROPNAME_WARNNOSIGNEDOFFBY, m_cWarnNoSignedOffBy);
140 m_bNeedSave = false;
141 SetModified(FALSE);
142 UpdateData(FALSE);
145 BOOL CSetDialogs3::SafeDataImpl(git_config * config)
147 if (m_langCombo.GetCurSel() == 1)
149 if (!Save(config, PROJECTPROPNAME_PROJECTLANGUAGE, L"-1"))
150 return FALSE;
152 else
154 CString value;
155 char numBuf[20];
156 sprintf_s(numBuf, "%ld", m_langCombo.GetItemData(m_langCombo.GetCurSel()));
157 if (!Save(config, PROJECTPROPNAME_PROJECTLANGUAGE, (CString)numBuf, true))
158 return FALSE;
161 if (!Save(config, PROJECTPROPNAME_LOGMINSIZE, m_LogMinSize, true))
162 return FALSE;
164 if (!Save(config, PROJECTPROPNAME_LOGWIDTHLINE, m_Border, true))
165 return FALSE;
168 CString value;
169 m_cWarnNoSignedOffBy.GetWindowText(value);
170 if (!Save(config, PROJECTPROPNAME_WARNNOSIGNEDOFFBY, value))
171 return FALSE;
174 return TRUE;
177 BOOL CSetDialogs3::PreTranslateMessage(MSG* pMsg)
179 m_tooltips.RelayEvent(pMsg);
180 return ISettingsPropPage::PreTranslateMessage(pMsg);
183 void CSetDialogs3::OnChange()
185 m_bNeedSave = true;
186 SetModified();
189 BOOL CSetDialogs3::OnApply()
191 if (!m_bNeedSave)
192 return TRUE;
193 UpdateData();
194 if (!SafeData())
195 return FALSE;
196 m_bNeedSave = false;
197 SetModified(FALSE);
198 return ISettingsPropPage::OnApply();
201 BOOL CSetDialogs3::EnumLocalesProc(LPTSTR lpLocaleString)
203 DWORD langID = _tcstol(lpLocaleString, NULL, 16);
205 TCHAR buf[MAX_PATH] = {0};
206 GetLocaleInfo(langID, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
207 CString sLang = buf;
208 GetLocaleInfo(langID, LOCALE_SNATIVECTRYNAME, buf, _countof(buf));
209 if (buf[0])
211 sLang += _T(" (");
212 sLang += buf;
213 sLang += _T(")");
216 int index = m_langCombo.AddString(sLang);
217 m_langCombo.SetItemData(index, langID);
219 return TRUE;