/[pcsx2_0.9.7]/trunk/pcsx2/gui/Panels/DirPickerPanel.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/Panels/DirPickerPanel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 7925 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "ConfigurationPanels.h"
18 #include "Dialogs/ModalPopups.h"
19
20 #include <wx/stdpaths.h>
21 #include <wx/file.h>
22 #include <wx/dir.h>
23 #include <wx/filepicker.h>
24
25 using namespace pxSizerFlags;
26
27 static wxString GetNormalizedConfigFolder( FoldersEnum_t folderId )
28 {
29 return Path::Normalize( g_Conf->Folders.IsDefault( folderId ) ? PathDefs::Get(folderId) : g_Conf->Folders[folderId] );
30 }
31
32 // Pass me TRUE if the default path is to be used, and the DirPickerCtrl disabled from use.
33 void Panels::DirPickerPanel::UpdateCheckStatus( bool someNoteworthyBoolean )
34 {
35 m_pickerCtrl->Enable( !someNoteworthyBoolean );
36 if( someNoteworthyBoolean )
37 {
38 wxString normalized( Path::Normalize( PathDefs::Get( m_FolderId ) ) );
39 m_pickerCtrl->SetPath( normalized );
40
41 wxFileDirPickerEvent event( m_pickerCtrl->GetEventType(), m_pickerCtrl, m_pickerCtrl->GetId(), normalized );
42 m_pickerCtrl->GetEventHandler()->ProcessEvent(event);
43 }
44 }
45
46 void Panels::DirPickerPanel::UseDefaultPath_Click( wxCommandEvent &evt )
47 {
48 evt.Skip();
49 pxAssert( (m_pickerCtrl != NULL) && (m_checkCtrl != NULL) );
50 UpdateCheckStatus( m_checkCtrl ? m_checkCtrl->IsChecked() : false );
51 }
52
53 void Panels::DirPickerPanel::Explore_Click( wxCommandEvent &evt )
54 {
55 wxString path( m_pickerCtrl->GetPath() );
56 if( !wxDirExists(path) )
57 {
58 wxDialogWithHelpers createPathDlg( NULL, _("Path does not exist") );
59 createPathDlg.SetMinWidth( 600 );
60
61 createPathDlg += createPathDlg.Text( path ) | StdCenter();
62
63 createPathDlg += createPathDlg.Heading( pxE( "!Notice:DirPicker:CreatePath",
64 L"The specified path/directory does not exist. Would you like to create it?" )
65 );
66
67 wxWindowID result = pxIssueConfirmation( createPathDlg,
68 MsgButtons().Custom(_("Create"), "create").Cancel(),
69 L"DirPicker:CreateOnExplore"
70 );
71
72 if( result == wxID_CANCEL ) return;
73 wxDirName(path).Mkdir();
74 }
75
76 pxExplore( path );
77 }
78
79 // ------------------------------------------------------------------------
80 // If initPath is NULL, then it's assumed the default folder is to be used, which is
81 // obtained from invoking the specified getDefault() function.
82 //
83 Panels::DirPickerPanel::DirPickerPanel( wxWindow* parent, FoldersEnum_t folderid, const wxString& label, const wxString& dialogLabel )
84 : BaseApplicableConfigPanel( parent, wxVERTICAL, label )
85 {
86 Init( folderid, dialogLabel, false );
87 }
88
89 Panels::DirPickerPanel::DirPickerPanel( wxWindow* parent, FoldersEnum_t folderid, const wxString& dialogLabel )
90 : BaseApplicableConfigPanel( parent, wxVERTICAL )
91 {
92 Init( folderid, dialogLabel, true );
93 }
94
95 void Panels::DirPickerPanel::Init( FoldersEnum_t folderid, const wxString& dialogLabel, bool isCompact )
96 {
97 m_FolderId = folderid;
98 m_pickerCtrl = NULL;
99 m_checkCtrl = NULL;
100
101 // Force the Dir Picker to use a text control. This isn't standard on Linux/GTK but it's much
102 // more usable, so to hell with standards.
103
104 wxString normalized( GetNormalizedConfigFolder( m_FolderId ) );
105
106 if( wxFile::Exists( normalized ) )
107 {
108 // The default path is invalid... What should we do here? hmm..
109 }
110
111 //if( !wxDir::Exists( normalized ) )
112 // wxMkdir( normalized );
113
114 if( !isCompact )
115 {
116 m_checkCtrl = new pxCheckBox( this, _("Use default setting") );
117
118 pxSetToolTip( m_checkCtrl, pxEt( "!ContextTip:DirPicker:UseDefault",
119 L"When checked this folder will automatically reflect the default associated with PCSX2's current usermode setting. " )
120 );
121
122 Connect( m_checkCtrl->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DirPickerPanel::UseDefaultPath_Click ) );
123 }
124
125 m_pickerCtrl = new wxDirPickerCtrl( this, wxID_ANY, wxEmptyString, dialogLabel,
126 wxDefaultPosition, wxDefaultSize, wxDIRP_USE_TEXTCTRL | wxDIRP_DIR_MUST_EXIST
127 );
128
129 #ifndef __WXGTK__
130 // GTK+ : The wx implementation of Explore isn't reliable, so let's not even put the
131 // button on the dialogs for now.
132
133 wxButton* b_explore( new wxButton( this, wxID_ANY, _("Open in Explorer") ) );
134 pxSetToolTip( b_explore, _("Open an explorer window to this folder.") );
135 Connect( b_explore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DirPickerPanel::Explore_Click ) );
136 #endif
137
138 if( isCompact )
139 {
140 wxFlexGridSizer& s_compact( *new wxFlexGridSizer( 2, 0, 4 ) );
141 s_compact.AddGrowableCol( 0 );
142 s_compact += m_pickerCtrl | pxExpand;
143 #ifndef __WXGTK__
144 s_compact += b_explore;
145 #endif
146 *this += s_compact | pxExpand; //.Border(wxLEFT | wxRIGHT | wxTOP, 5);
147 }
148 else
149 {
150 wxBoxSizer& s_lower( *new wxBoxSizer( wxHORIZONTAL ) );
151
152 s_lower += m_checkCtrl | pxMiddle;
153 #ifndef __WXGTK__
154 s_lower += pxStretchSpacer(1);
155 s_lower += b_explore;
156 #endif
157
158 *this += m_pickerCtrl | pxExpand.Border(wxLEFT | wxRIGHT | wxTOP, StdPadding);
159 *this += s_lower | pxExpand.Border(wxLEFT | wxRIGHT, StdPadding);
160 }
161
162 // wx warns when paths don't exist, but this is typically normal when the wizard
163 // creates its child controls. So let's ignore them.
164 wxDoNotLogInThisScope please;
165 AppStatusEvent_OnSettingsApplied(); // forces default settings based on g_Conf
166 }
167
168 Panels::DirPickerPanel& Panels::DirPickerPanel::SetStaticDesc( const wxString& msg )
169 {
170 GetSizer()->Insert( 0, &Heading( msg ), pxExpand );
171 return *this;
172 }
173
174 Panels::DirPickerPanel& Panels::DirPickerPanel::SetToolTip( const wxString& tip )
175 {
176 pxSetToolTip( this, tip );
177 return *this;
178 }
179
180 wxWindowID Panels::DirPickerPanel::GetId() const
181 {
182 return m_pickerCtrl->GetId();
183 }
184
185 void Panels::DirPickerPanel::Reset()
186 {
187 const bool isDefault = g_Conf->Folders.IsDefault( m_FolderId );
188
189 if( m_checkCtrl )
190 m_checkCtrl->SetValue( isDefault );
191
192 if( m_pickerCtrl )
193 {
194 // Important! The dirpicker panel stuff, due to however it's put together
195 // needs to check the enable status of this panel before setting the child
196 // panel's enable status.
197
198 m_pickerCtrl->Enable( IsEnabled() ? ( m_checkCtrl ? !isDefault : true ) : false );
199 m_pickerCtrl->SetPath( GetNormalizedConfigFolder( m_FolderId ) );
200 }
201 }
202
203 bool Panels::DirPickerPanel::Enable( bool enable )
204 {
205 m_pickerCtrl->Enable( enable ? (!m_checkCtrl || m_checkCtrl->GetValue()) : false );
206 return _parent::Enable( enable );
207 }
208
209
210 void Panels::DirPickerPanel::AppStatusEvent_OnSettingsApplied()
211 {
212 Reset();
213 }
214
215 void Panels::DirPickerPanel::Apply()
216 {
217 if( !m_pickerCtrl ) return;
218
219 const wxString path( m_pickerCtrl->GetPath() );
220
221 if( !wxDir::Exists( path ) )
222 {
223 wxDialogWithHelpers dialog( NULL, _("Create folder?") );
224 dialog += dialog.Heading(AddAppName(_("A configured folder does not exist. Should %s try to create it?")));
225 dialog += 12;
226 dialog += dialog.Heading( path );
227
228 if( wxID_CANCEL == pxIssueConfirmation( dialog, MsgButtons().Custom(_("Create"), "create").Cancel(), L"CreateNewFolder" ) )
229 throw Exception::CannotApplySettings( this );
230 }
231
232 wxDirName(path).Mkdir();
233 g_Conf->Folders.Set( m_FolderId, m_pickerCtrl->GetPath(), m_checkCtrl ? m_checkCtrl->GetValue() : false );
234 }
235
236 wxDirName Panels::DirPickerPanel::GetPath() const
237 {
238 // The (x) ? y : z construct doesn't like y and z to be different types in gcc.
239 if (m_pickerCtrl)
240 return wxDirName(m_pickerCtrl->GetPath());
241 else
242 return wxDirName(wxEmptyString);
243 }
244
245 void Panels::DirPickerPanel::SetPath( const wxString& newPath )
246 {
247 m_pickerCtrl->SetPath( newPath );
248 }

  ViewVC Help
Powered by ViewVC 1.1.22