Make bugtraq settings dialog hierarchy aware
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsBugtraqConfig.cpp
blobe58a604fa251fba2088ad4307a2841ce797f5e22
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-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 // settings\SettingsBugtraqConfig.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SettingsBugtraqConfig.h"
25 #include "ProjectProperties.h"
26 #include "Git.h"
27 // CSettingsBugtraqConfig dialog
29 IMPLEMENT_DYNAMIC(CSettingsBugtraqConfig, ISettingsPropPage)
31 CSettingsBugtraqConfig::CSettingsBugtraqConfig(CString cmdPath)
32 : ISettingsPropPage(CSettingsBugtraqConfig::IDD)
33 , m_URL(_T(""))
34 , m_Message(_T(""))
35 , m_Label(_T(""))
36 , m_Logregex(_T(""))
37 , m_bNeedSave(false)
41 CSettingsBugtraqConfig::~CSettingsBugtraqConfig()
45 void CSettingsBugtraqConfig::DoDataExchange(CDataExchange* pDX)
47 CPropertyPage::DoDataExchange(pDX);
48 DDX_Text(pDX, IDC_BUGTRAQ_URL, m_URL);
49 DDX_Control(pDX, IDC_BUGTRAQ_WARNINGIFNOISSUE, m_cWarningifnoissue);
50 DDX_Text(pDX, IDC_BUGTRAQ_MESSAGE, m_Message);
51 DDX_Control(pDX, IDC_BUGTRAQ_APPEND, m_cAppend);
52 DDX_Text(pDX, IDC_BUGTRAQ_LABEL, m_Label);
53 DDX_Control(pDX, IDC_BUGTRAQ_NUMBER, m_cNumber);
54 DDX_Text(pDX, IDC_BUGTRAQ_LOGREGEX, m_Logregex);
55 DDX_Control(pDX, IDC_BUGTRAQ_LOGREGEX, m_BugtraqRegex1);
56 GITSETTINGS_DDX
59 BEGIN_MESSAGE_MAP(CSettingsBugtraqConfig, ISettingsPropPage)
60 GITSETTINGS_RADIO_EVENT
61 ON_EN_CHANGE(IDC_BUGTRAQ_URL, &CSettingsBugtraqConfig::OnChange)
62 ON_CBN_SELCHANGE(IDC_BUGTRAQ_WARNINGIFNOISSUE, &CSettingsBugtraqConfig::OnChange)
63 ON_EN_CHANGE(IDC_BUGTRAQ_MESSAGE, &CSettingsBugtraqConfig::OnChange)
64 ON_CBN_SELCHANGE(IDC_BUGTRAQ_APPEND, &CSettingsBugtraqConfig::OnChange)
65 ON_EN_CHANGE(IDC_BUGTRAQ_LABEL, &CSettingsBugtraqConfig::OnChange)
66 ON_CBN_SELCHANGE(IDC_BUGTRAQ_NUMBER, &CSettingsBugtraqConfig::OnChange)
67 ON_EN_CHANGE(IDC_BUGTRAQ_LOGREGEX, &CSettingsBugtraqConfig::OnChange)
68 END_MESSAGE_MAP()
70 BOOL CSettingsBugtraqConfig::OnInitDialog()
72 ISettingsPropPage::OnInitDialog();
74 AddTrueFalseToComboBox(m_cWarningifnoissue);
75 AddTrueFalseToComboBox(m_cAppend);
76 AddTrueFalseToComboBox(m_cNumber);
78 InitGitSettings(this, true);
80 this->UpdateData(FALSE);
81 return TRUE;
84 void CSettingsBugtraqConfig::OnChange()
86 m_bNeedSave = true;
87 SetModified();
90 void CSettingsBugtraqConfig::LoadDataImpl(git_config * config)
92 if (m_iConfigSource == 0)
94 // use project properties here, so that we correctly get the default values
95 ProjectProperties props;
96 props.ReadProps(g_Git.m_CurrentDir);
97 m_URL = props.sUrl;
98 m_Logregex = props.sCheckRe + _T("\n") + props.sBugIDRe;
99 m_Label = props.sLabel;
100 m_Message = props.sMessage;
102 if (props.bAppend)
103 m_cAppend.SetCurSel(1);
104 else
105 m_cAppend.SetCurSel(2);
107 if (props.bNumber)
108 m_cNumber.SetCurSel(1);
109 else
110 m_cNumber.SetCurSel(2);
112 if (props.bWarnIfNoIssue)
113 m_cWarningifnoissue.SetCurSel(1);
114 else
115 m_cWarningifnoissue.SetCurSel(2);
117 else
119 GetConfigValue(config, BUGTRAQPROPNAME_URL, m_URL);
120 GetConfigValue(config, BUGTRAQPROPNAME_MESSAGE, m_Message);
121 GetConfigValue(config, BUGTRAQPROPNAME_LABEL, m_Label);
122 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_NUMBER, m_cNumber);
123 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_APPEND, m_cAppend);
124 GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_WARNIFNOISSUE, m_cWarningifnoissue);
125 GetConfigValue(config, BUGTRAQPROPNAME_LOGREGEX, m_Logregex);
128 m_Logregex.Trim();
129 m_Logregex.Replace(_T("\n"), _T("\r\n"));
131 m_bNeedSave = false;
132 SetModified(FALSE);
133 UpdateData(FALSE);
136 BOOL CSettingsBugtraqConfig::SafeDataImpl(git_config * config)
138 if (!Save(config, BUGTRAQPROPNAME_URL, m_URL))
139 return FALSE;
141 if (!Save(config, BUGTRAQPROPNAME_MESSAGE, m_Message))
142 return FALSE;
144 if (!Save(config, BUGTRAQPROPNAME_LABEL, m_Label))
145 return FALSE;
148 CString value;
149 m_cAppend.GetWindowText(value);
150 if (!Save(config, BUGTRAQPROPNAME_APPEND, value))
151 return FALSE;
154 CString value;
155 m_cNumber.GetWindowText(value);
156 if (!Save(config, BUGTRAQPROPNAME_NUMBER, value))
157 return FALSE;
160 CString value;
161 m_cWarningifnoissue.GetWindowText(value);
162 if (!Save(config, BUGTRAQPROPNAME_WARNIFNOISSUE, value))
163 return FALSE;
166 CString value(m_Logregex);
167 value.Replace(_T("\r\n"),_T("\n"));
168 if (!Save(config, BUGTRAQPROPNAME_LOGREGEX, value))
169 return FALSE;
172 return TRUE;
175 BOOL CSettingsBugtraqConfig::OnApply()
177 if (!m_bNeedSave)
178 return TRUE;
179 UpdateData();
180 if (!SafeData())
181 return FALSE;
182 m_bNeedSave = false;
183 SetModified(FALSE);
184 return TRUE;