Use new constants everywhere
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsProgsAlternativeEditor.cpp
blob0cc00e64d9a4591fe9b3960b7e28df58531f5402
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
4 // Copyright (C) 2011 - Sven Strickroth <email@cs-ware.de>
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 "StringUtils.h"
24 #include ".\settingsprogsalternativeeditor.h"
27 IMPLEMENT_DYNAMIC(CSettingsProgsAlternativeEditor, ISettingsPropPage)
28 CSettingsProgsAlternativeEditor::CSettingsProgsAlternativeEditor()
29 : ISettingsPropPage(CSettingsProgsAlternativeEditor::IDD)
30 , m_sAlternativeEditorPath(_T(""))
31 , m_iAlternativeEditor(0)
33 m_regAlternativeEditorPath = CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
36 CSettingsProgsAlternativeEditor::~CSettingsProgsAlternativeEditor()
40 void CSettingsProgsAlternativeEditor::DoDataExchange(CDataExchange* pDX)
42 ISettingsPropPage::DoDataExchange(pDX);
43 DDX_Text(pDX, IDC_ALTERNATIVEEDITOR, m_sAlternativeEditorPath);
44 DDX_Radio(pDX, IDC_ALTERNATIVEEDITOR_OFF, m_iAlternativeEditor);
46 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(m_iAlternativeEditor == 1);
47 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(m_iAlternativeEditor == 1);
48 DDX_Control(pDX, IDC_ALTERNATIVEEDITOR, m_cAlternativeEditorEdit);
52 BEGIN_MESSAGE_MAP(CSettingsProgsAlternativeEditor, ISettingsPropPage)
53 ON_BN_CLICKED(IDC_ALTERNATIVEEDITOR_OFF, OnBnClickedAlternativeEditorOff)
54 ON_BN_CLICKED(IDC_ALTERNATIVEEDITOR_ON, OnBnClickedAlternativeEditorOn)
55 ON_BN_CLICKED(IDC_ALTERNATIVEEDITORBROWSE, OnBnClickedAlternativeEditorBrowse)
56 ON_EN_CHANGE(IDC_ALTERNATIVEEDITOR, OnEnChangeAlternativeEditor)
57 END_MESSAGE_MAP()
59 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorOff()
61 m_iAlternativeEditor = 0;
62 SetModified();
63 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(FALSE);
64 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(FALSE);
65 CheckProgComment();
68 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorOn()
70 m_iAlternativeEditor = 1;
71 SetModified();
72 GetDlgItem(IDC_ALTERNATIVEEDITOR)->EnableWindow(TRUE);
73 GetDlgItem(IDC_ALTERNATIVEEDITORBROWSE)->EnableWindow(TRUE);
74 GetDlgItem(IDC_ALTERNATIVEEDITOR)->SetFocus();
75 CheckProgComment();
78 void CSettingsProgsAlternativeEditor::OnEnChangeAlternativeEditor()
80 SetModified();
83 void CSettingsProgsAlternativeEditor::OnBnClickedAlternativeEditorBrowse()
85 if (CAppUtils::FileOpenSave(m_sAlternativeEditorPath, NULL, IDS_SETTINGS_SELECTDIFFVIEWER, IDS_PROGRAMSFILEFILTER, true, m_hWnd))
87 UpdateData(FALSE);
88 SetModified();
92 BOOL CSettingsProgsAlternativeEditor::OnInitDialog()
94 ISettingsPropPage::OnInitDialog();
96 EnableToolTips();
98 m_sAlternativeEditorPath = m_regAlternativeEditorPath;
99 m_iAlternativeEditor = IsExternal(m_sAlternativeEditorPath);
101 SHAutoComplete(::GetDlgItem(m_hWnd, IDC_ALTERNATIVEEDITOR), SHACF_FILESYSTEM | SHACF_FILESYS_ONLY);
103 m_tooltips.Create(this);
104 m_tooltips.AddTool(IDC_ALTERNATIVEEDITOR, IDS_SETTINGS_ALTERNATIVEEDITOR_TT);
106 UpdateData(FALSE);
107 return TRUE;
110 BOOL CSettingsProgsAlternativeEditor::PreTranslateMessage(MSG* pMsg)
112 m_tooltips.RelayEvent(pMsg);
113 return ISettingsPropPage::PreTranslateMessage(pMsg);
116 BOOL CSettingsProgsAlternativeEditor::OnApply()
118 UpdateData();
119 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
120 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
122 m_regAlternativeEditorPath = m_sAlternativeEditorPath;
123 SetModified(FALSE);
124 return ISettingsPropPage::OnApply();
127 void CSettingsProgsAlternativeEditor::CheckProgComment()
129 UpdateData();
130 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
131 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
132 else if (m_iAlternativeEditor == 1)
133 m_sAlternativeEditorPath.TrimLeft('#');
134 UpdateData(FALSE);