No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsProgsAlternativeEditor.cpp
blobf98af41d2c71686563f4c1b51d8b6a63e8768b6a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
4 // Copyright (C) 2011,2013-2015 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "AppUtils.h"
23 #include "SettingsProgsAlternativeEditor.h"
26 IMPLEMENT_DYNAMIC(CSettingsProgsAlternativeEditor, ISettingsPropPage)
27 CSettingsProgsAlternativeEditor::CSettingsProgsAlternativeEditor()
28 : ISettingsPropPage(CSettingsProgsAlternativeEditor::IDD)
29 , m_iAlternativeEditor(0)
31 m_regAlternativeEditorPath = CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
34 CSettingsProgsAlternativeEditor::~CSettingsProgsAlternativeEditor()
38 void CSettingsProgsAlternativeEditor::DoDataExchange(CDataExchange* pDX)
40 ISettingsPropPage::DoDataExchange(pDX);
41 DDX_Text(pDX, IDC_ALTERNATIVEEDITOR, m_sAlternativeEditorPath);
42 DDX_Radio(pDX, IDC_ALTERNATIVEEDITOR_OFF, m_iAlternativeEditor);
44 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(m_iAlternativeEditor == 1);
45 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(m_iAlternativeEditor == 1);
46 DDX_Control(pDX, IDC_ALTERNATIVEEDITOR, m_cAlternativeEditorEdit);
50 BEGIN_MESSAGE_MAP(CSettingsProgsAlternativeEditor, ISettingsPropPage)
51 ON_BN_CLICKED(IDC_ALTERNATIVEEDITOR_OFF, OnBnClickedAlternativeEditorOff)
52 ON_BN_CLICKED(IDC_ALTERNATIVEEDITOR_ON, OnBnClickedAlternativeEditorOn)
53 ON_BN_CLICKED(IDC_ALTERNATIVEEDITORBROWSE, OnBnClickedAlternativeEditorBrowse)
54 ON_EN_CHANGE(IDC_ALTERNATIVEEDITOR, OnEnChangeAlternativeEditor)
55 END_MESSAGE_MAP()
57 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorOff()
59 m_iAlternativeEditor = 0;
60 SetModified();
61 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(FALSE);
62 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(FALSE);
63 CheckProgComment();
66 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorOn()
68 m_iAlternativeEditor = 1;
69 SetModified();
70 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(TRUE);
71 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(TRUE);
72 GetDlgItem(IDC_ALTERNATIVEEDITOR)->SetFocus();
73 CheckProgComment();
76 void CSettingsProgsAlternativeEditor::OnEnChangeAlternativeEditor()
78 SetModified();
81 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorBrowse()
83 if (CAppUtils::FileOpenSave(m_sAlternativeEditorPath, NULL, IDS_SETTINGS_SELECTDIFFVIEWER, IDS_PROGRAMSFILEFILTER, true, m_hWnd))
85 UpdateData(FALSE);
86 SetModified();
90 BOOL CSettingsProgsAlternativeEditor::OnInitDialog()
92 ISettingsPropPage::OnInitDialog();
94 AdjustControlSize(IDC_ALTERNATIVEEDITOR_OFF);
95 AdjustControlSize(IDC_ALTERNATIVEEDITOR_ON);
97 EnableToolTips();
99 m_sAlternativeEditorPath = m_regAlternativeEditorPath;
100 m_iAlternativeEditor = IsExternal(m_sAlternativeEditorPath);
102 SHAutoComplete(::GetDlgItem(m_hWnd, IDC_ALTERNATIVEEDITOR), SHACF_FILESYSTEM | SHACF_FILESYS_ONLY);
104 m_tooltips.AddTool(IDC_ALTERNATIVEEDITOR, IDS_SETTINGS_ALTERNATIVEEDITOR_TT);
106 UpdateData(FALSE);
107 return TRUE;
110 BOOL CSettingsProgsAlternativeEditor::OnApply()
112 UpdateData();
113 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
114 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
116 m_regAlternativeEditorPath = m_sAlternativeEditorPath;
117 SetModified(FALSE);
118 return ISettingsPropPage::OnApply();
121 void CSettingsProgsAlternativeEditor::CheckProgComment()
123 UpdateData();
124 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
125 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
126 else if (m_iAlternativeEditor == 1)
127 m_sAlternativeEditorPath.TrimLeft('#');
128 UpdateData(FALSE);