Adjust checkbox and radio control widths to required size
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsProgsAlternativeEditor.cpp
blobfc108062cf415d4bfc66daa4f988abe9207e3590
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2007 - TortoiseSVN
4 // Copyright (C) 2011,2013-2014 - 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 "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 AdjustControlSize(IDC_ALTERNATIVEEDITOR_OFF);
97 AdjustControlSize(IDC_ALTERNATIVEEDITOR_ON);
99 EnableToolTips();
101 m_sAlternativeEditorPath = m_regAlternativeEditorPath;
102 m_iAlternativeEditor = IsExternal(m_sAlternativeEditorPath);
104 SHAutoComplete(::GetDlgItem(m_hWnd, IDC_ALTERNATIVEEDITOR), SHACF_FILESYSTEM | SHACF_FILESYS_ONLY);
106 m_tooltips.Create(this);
107 m_tooltips.AddTool(IDC_ALTERNATIVEEDITOR, IDS_SETTINGS_ALTERNATIVEEDITOR_TT);
109 UpdateData(FALSE);
110 return TRUE;
113 BOOL CSettingsProgsAlternativeEditor::PreTranslateMessage(MSG* pMsg)
115 m_tooltips.RelayEvent(pMsg);
116 return ISettingsPropPage::PreTranslateMessage(pMsg);
119 BOOL CSettingsProgsAlternativeEditor::OnApply()
121 UpdateData();
122 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
123 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
125 m_regAlternativeEditorPath = m_sAlternativeEditorPath;
126 SetModified(FALSE);
127 return ISettingsPropPage::OnApply();
130 void CSettingsProgsAlternativeEditor::CheckProgComment()
132 UpdateData();
133 if (m_iAlternativeEditor == 0 && !m_sAlternativeEditorPath.IsEmpty() && m_sAlternativeEditorPath.Left(1) != _T("#"))
134 m_sAlternativeEditorPath = _T("#") + m_sAlternativeEditorPath;
135 else if (m_iAlternativeEditor == 1)
136 m_sAlternativeEditorPath.TrimLeft('#');
137 UpdateData(FALSE);