Fix Preferred Editor dialog (lp: 1558353)
The functions involved in the problem were PGM_BASE::GetEditorName and EDA_BASE_FRAME::OnSelectPreferredEditor: 1) OnSelectPreferredEditor showed a dialog to allow the user selecting the editor, but before that called GetEditorName to get the name of the current editor (to show as a default in the choose file dialog). 2) The problem was when there was no editor, GetEditorName showed its own dialog. 3) So the user was seeing first the dialog from (2) and then the dialog from (1). 4) As GetEditorName is used in many other places the solution I did was to add to it an optional parameter that tells it what to do if no editor is set. To avoid modifying other code that relies on the current behaviour, this parameter has a default value that causes to show the dialog. But now when OnSelectPreferredEditor calls it, it passes the parameter that causes it to return an empty string if no editor was set. 5) Also, I found a second bug while doing it which allowed in the first dialog to select an unexistent file (the dialog was missing the wxFD_FILE_MUST_EXIST flag). 6) Lastly, to avoid having duplicated code (the one that showed the same dialog and that configured the wildcard was in two methods) I created a single function that now both functions call: PGM_BASE::AskUserForPreferredEditor. This way we also will have consistency in the behaviour of both dialogs and there is a single place where it needs to be modified.
This commit is contained in:
+10
-18
@@ -441,26 +441,18 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
|
||||
|
||||
void EDA_BASE_FRAME::OnSelectPreferredEditor( wxCommandEvent& event )
|
||||
{
|
||||
wxFileName fn = Pgm().GetEditorName();
|
||||
wxString wildcard( wxT( "*" ) );
|
||||
// Ask for the current editor and instruct GetEditorName() to not show
|
||||
// unless we pass false as argument.
|
||||
wxString editorname = Pgm().GetEditorName( false );
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
wildcard += wxT( ".exe" );
|
||||
#endif
|
||||
// Ask the user to select a new editor, but suggest the current one as the default.
|
||||
editorname = Pgm().AskUserForPreferredEditor( editorname );
|
||||
|
||||
wildcard.Printf( _( "Executable file (%s)|%s" ),
|
||||
GetChars( wildcard ), GetChars( wildcard ) );
|
||||
|
||||
wxFileDialog dlg( this, _( "Select Preferred Editor" ), fn.GetPath(),
|
||||
fn.GetFullName(), wildcard,
|
||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return;
|
||||
|
||||
wxString editor = dlg.GetPath();
|
||||
|
||||
Pgm().SetEditorName( editor );
|
||||
// If we have a new editor name request it to be copied to m_editor_name and saved
|
||||
// to the preferences file. If the user cancelled the dialog then the previous
|
||||
// value will be retained.
|
||||
if( !editorname.IsEmpty() )
|
||||
Pgm().SetEditorName( editorname );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user