KiCad PCB EDA Suite
panel_common_settings.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <pgm_base.h>
25 #include <dialog_shim.h>
26 #include <kiface_i.h>
27 #include <bitmap_types.h>
28 #include <bitmaps.h>
29 #include <wx/graphics.h>
30 #include "panel_common_settings.h"
31 
33  PANEL_COMMON_SETTINGS_BASE( aParent ),
34  m_dialog( aDialog ),
35  m_last_scale( -1 )
36 {
37  m_scaleSlider->SetStep( 25 );
38 
39  m_textEditorBtn->SetBitmap( KiBitmap( folder_xpm ) );
40  m_pdfViewerBtn->SetBitmap( KiBitmap( folder_xpm ) );
41 }
42 
43 
45 {
46  wxConfigBase* commonSettings = Pgm().CommonSettings();
47 
48  int timevalue;
49  wxString msg;
50 
51  commonSettings->Read( AUTOSAVE_INTERVAL_KEY, &timevalue );
52  msg << timevalue / 60;
53  m_SaveTime->SetValue( msg );
54 
55  int fileHistorySize;
56  commonSettings->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
57  m_fileHistorySize->SetValue( fileHistorySize );
58 
59  int antialiasingMode;
60  commonSettings->Read( GAL_ANTIALIASING_MODE_KEY, &antialiasingMode, 0 );
61  m_antialiasing->SetSelection( antialiasingMode );
62 
63  int scale_fourths;
64  commonSettings->Read( ICON_SCALE_KEY, &scale_fourths );
65 
66  if( scale_fourths <= 0 )
67  {
68  m_scaleAuto->SetValue( true );
69  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
70  }
71  else
72  {
73  m_scaleAuto->SetValue( false );
74  m_scaleSlider->SetValue( scale_fourths * 25 );
75  }
76 
77  bool option;
78  commonSettings->Read( USE_ICONS_IN_MENUS_KEY, &option );
79  m_checkBoxIconsInMenus->SetValue( option );
80 
81  commonSettings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
82  m_ZoomCenterOpt->SetValue( !option );
83 
84  commonSettings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
85  m_MousewheelPANOpt->SetValue( option );
86 
87  commonSettings->Read( ENBL_AUTO_PAN_KEY, &option );
88  m_AutoPANOpt->SetValue( option );
89 
90  m_textEditorPath->SetValue( Pgm().GetEditorName( false ) );
91  m_defaultPDFViewer->SetValue( Pgm().UseSystemPdfBrowser() );
92  m_otherPDFViewer->SetValue( !Pgm().UseSystemPdfBrowser() );
93  m_PDFViewerPath->SetValue( Pgm().GetPdfBrowserName() );
94 
95  return true;
96 }
97 
98 
100 {
101  wxConfigBase* commonSettings = Pgm().CommonSettings();
102 
103  commonSettings->Write( AUTOSAVE_INTERVAL_KEY, m_SaveTime->GetValue() * 60 );
104 
105  commonSettings->Write( FILE_HISTORY_SIZE_KEY, m_fileHistorySize->GetValue() );
106 
107  commonSettings->Write( GAL_ANTIALIASING_MODE_KEY, m_antialiasing->GetSelection() );
108 
109  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
110  commonSettings->Write( ICON_SCALE_KEY, scale_fourths );
111 
112  commonSettings->Write( USE_ICONS_IN_MENUS_KEY, m_checkBoxIconsInMenus->GetValue() );
113  commonSettings->Write( ENBL_ZOOM_NO_CENTER_KEY, !m_ZoomCenterOpt->GetValue() );
114  commonSettings->Write( ENBL_MOUSEWHEEL_PAN_KEY, m_MousewheelPANOpt->GetValue() );
115  commonSettings->Write( ENBL_AUTO_PAN_KEY, m_AutoPANOpt->GetValue() );
116 
117  Pgm().SetEditorName( m_textEditorPath->GetValue() );
118 
119  Pgm().SetPdfBrowserName( m_PDFViewerPath->GetValue() );
122 
123  return true;
124 }
125 
126 
127 void PANEL_COMMON_SETTINGS::OnScaleSlider( wxScrollEvent& aEvent )
128 {
129  m_scaleAuto->SetValue( false );
130 }
131 
132 
133 void PANEL_COMMON_SETTINGS::OnScaleAuto( wxCommandEvent& aEvent )
134 {
135  if( m_scaleAuto->GetValue() )
136  {
137  m_last_scale = m_scaleSlider->GetValue();
138  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
139  }
140  else
141  {
142  if( m_last_scale >= 0 )
143  m_scaleSlider->SetValue( m_last_scale );
144  }
145 }
146 
147 
148 void PANEL_COMMON_SETTINGS::OnTextEditorClick( wxCommandEvent& event )
149 {
150  // Ask the user to select a new editor, but suggest the current one as the default.
151  wxString editorname = Pgm().AskUserForPreferredEditor( m_textEditorPath->GetValue() );
152 
153  // If we have a new editor name request it to be copied to m_editor_name and saved
154  // to the preferences file. If the user cancelled the dialog then the previous
155  // value will be retained.
156  if( !editorname.IsEmpty() )
157  m_textEditorPath->SetValue( editorname );
158 }
159 
160 
161 void PANEL_COMMON_SETTINGS::OnPDFViewerClick( wxCommandEvent& event )
162 {
163  wxString mask( wxT( "*" ) );
164 
165 #ifdef __WINDOWS__
166  mask += wxT( ".exe" );
167 #endif
168 
169  wxString wildcard = _( "Executable files (" ) + mask + wxT( ")|" ) + mask;
170 
172  wxFileName fn = Pgm().GetPdfBrowserName();
173 
174  wxFileDialog dlg( this, _( "Select Preferred PDF Browser" ), fn.GetPath(), fn.GetFullPath(),
175  wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
176 
177  if( dlg.ShowModal() == wxID_CANCEL )
178  return;
179 
180  m_otherPDFViewer->SetValue( true );
181  m_PDFViewerPath->SetValue( dlg.GetPath() );
182 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:195
void OnScaleAuto(wxCommandEvent &aEvent) override
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:238
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:219
void OnScaleSlider(wxScrollEvent &aEvent) override
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:89
void OnPDFViewerClick(wxCommandEvent &event) override
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:82
VTBL_ENTRY void WritePdfBrowserInfos()
Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:55
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:240
Class PANEL_COMMON_SETTINGS_BASE.
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:47
bool TransferDataFromWindow() override
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void OnTextEditorClick(wxCommandEvent &event) override
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:50
#define DEFAULT_FILE_HISTORY_SIZE
The default file history size is 9.
Definition: pgm_base.h:58
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:221
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:48
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:51
#define ICON_SCALE_KEY
Definition: pgm_base.h:45
int m_last_scale
saved icon scale when Auto selected
#define AUTOSAVE_INTERVAL_KEY
Definition: pgm_base.h:46
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:53
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
see class PGM_BASE
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
bool TransferDataToWindow() override
PANEL_COMMON_SETTINGS(DIALOG_SHIM *aDialog, wxWindow *aParent)
void SetStep(int aSize)
Set the step size.