diff --git a/common/dialogs/panel_hotkeys_editor.cpp b/common/dialogs/panel_hotkeys_editor.cpp index 8b77a2994f..c5cee0fe43 100644 --- a/common/dialogs/panel_hotkeys_editor.cpp +++ b/common/dialogs/panel_hotkeys_editor.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KICAD, a free EDA CAD application. * - * Copyright (C) 1992-2020 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 Kicad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -188,10 +189,9 @@ void PANEL_HOTKEYS_EDITOR::OnFilterSearch( wxCommandEvent& aEvent ) void PANEL_HOTKEYS_EDITOR::ImportHotKeys() { - wxString ext = DEFAULT_HOTKEY_FILENAME_EXT; - wxString mask = wxT( "*." ) + ext; - wxString filename = EDA_FILE_SELECTOR( _( "Import Hotkeys File:" ), m_frame->GetMruPath(), - wxEmptyString, ext, mask, this, wxFD_OPEN, true ); + wxString filename = wxFileSelector( _( "Import Hotkeys File:" ), m_frame->GetMruPath(), + wxEmptyString, HotkeyFileExtension, + HotkeyFileWildcard(), wxFD_OPEN, this ); if( filename.IsEmpty() ) return; @@ -216,9 +216,9 @@ void PANEL_HOTKEYS_EDITOR::ImportHotKeys() void PANEL_HOTKEYS_EDITOR::dumpHotkeys() { - wxString filename = EDA_FILE_SELECTOR( wxT( "Dump Hotkeys File:" ), m_frame->GetMruPath(), - wxEmptyString, wxT( "txt" ), wxT( "*.txt" ), this, - wxFD_SAVE, true ); + wxString filename = wxFileSelector( wxT( "Hotkeys File" ), m_frame->GetMruPath(), + wxEmptyString, TextFileExtension, TextFileWildcard(), + wxFD_SAVE, this ); if( filename.IsEmpty() ) return; diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index 52fd70b100..0854ff8eff 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -121,40 +121,33 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT /* Compute the full file name */ if( wxIsAbsolutePath( docname ) || aPaths == nullptr ) fullfilename = docname; - /* If the file exists, this is a trivial case: return the filename - * "as this". the name can be an absolute path, or a relative path - * like ./filename or ../ + /* If the file exists, this is a trivial case: return the filename "as this". the name can + * be an absolute path, or a relative path like ./filename or ../. */ else if( wxFileName::FileExists( docname ) ) fullfilename = docname; else fullfilename = aPaths->FindValidPath( docname ); - wxString mask( wxT( "*" ) ), extension; + wxString extension; #ifdef __WINDOWS__ - mask += wxT( ".*" ); extension = wxT( ".*" ); #endif if( wxIsWild( fullfilename ) ) { - fullfilename = EDA_FILE_SELECTOR( _( "Doc Files" ), - wxPathOnly( fullfilename ), - fullfilename, - extension, - mask, - aParent, - wxFD_OPEN, - true, - wxPoint( -1, -1 ) ); + fullfilename = wxFileSelector( _( "Documentation File" ), wxPathOnly( fullfilename ), + fullfilename, extension, wxFileSelectorDefaultWildcardStr, + wxFD_OPEN, aParent ); + if( fullfilename.IsEmpty() ) return false; } if( !wxFileExists( fullfilename ) ) { - msg.Printf( _( "Doc File '%s' not found" ), docname ); + msg.Printf( _( "Documentation file '%s' not found." ), docname ); DisplayError( aParent, msg ); return false; } @@ -197,7 +190,7 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT if( !success ) { - msg.Printf( _( "Unknown MIME type for doc file '%s'" ), fullfilename ); + msg.Printf( _( "Unknown MIME type for documentation file '%s'" ), fullfilename ); DisplayError( aParent, msg ); } diff --git a/common/gestfich.cpp b/common/gestfich.cpp index d61ab4abe6..01f4d857e2 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -49,56 +49,6 @@ void AddDelimiterString( wxString& string ) } -wxString EDA_FILE_SELECTOR( const wxString& aTitle, - const wxString& aPath, - const wxString& aFileName, - const wxString& aExtension, - const wxString& aWildcard, - wxWindow* aParent, - int aStyle, - const bool aKeepWorkingDirectory, - const wxPoint& aPosition, - wxString* aMruPath ) -{ - wxString fullfilename; - wxString curr_cwd = wxGetCwd(); - wxString defaultname = aFileName; - wxString defaultpath = aPath; - wxString dotted_Ext = wxT(".") + aExtension; - -#ifdef __WINDOWS__ - defaultname.Replace( wxT( "/" ), wxT( "\\" ) ); - defaultpath.Replace( wxT( "/" ), wxT( "\\" ) ); -#endif - - if( defaultpath.IsEmpty() ) - { - if( aMruPath == nullptr ) - defaultpath = wxGetCwd(); - else - defaultpath = *aMruPath; - } - - wxSetWorkingDirectory( defaultpath ); - - fullfilename = wxFileSelector( aTitle, defaultpath, defaultname, - dotted_Ext, aWildcard, - aStyle, // open mode wxFD_OPEN, wxFD_SAVE .. - aParent, aPosition.x, aPosition.y ); - - if( aKeepWorkingDirectory ) - wxSetWorkingDirectory( curr_cwd ); - - if( !fullfilename.IsEmpty() && aMruPath ) - { - wxFileName fn = fullfilename; - *aMruPath = fn.GetPath(); - } - - return fullfilename; -} - - wxString FindKicadFile( const wxString& shortname ) { // Test the presence of the file in the directory shortname of diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index 7013679240..8dfd065015 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2010 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,7 @@ struct hotkey_name_descr int m_KeyCode; }; + /* table giving the hotkey name from the hotkey code, for special keys * Note : when modifiers (ATL, SHIFT, CTRL) do not modify * the code of the key, do need to enter the modified key code @@ -120,6 +122,7 @@ static struct hotkey_name_descr hotkeyNameList[] = { wxT( "" ), KEY_NON_FOUND } }; + // name of modifier keys. // Note: the Ctrl key is Cmd key on Mac OS X. // However, in wxWidgets defs, the key WXK_CONTROL is the Cmd key, @@ -326,7 +329,7 @@ void ReadHotKeyConfig( const wxString& aFileName, std::map& aH if( fileName.IsEmpty() ) { wxFileName fn( "user" ); - fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); + fn.SetExt( HotkeyFileExtension ); fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fileName = fn.GetFullPath(); } @@ -362,7 +365,7 @@ int WriteHotKeyConfig( const std::map& aActionMap ) std::map hotkeys; wxFileName fn( "user" ); - fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); + fn.SetExt( HotkeyFileExtension ); fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); // Read the existing config (all hotkeys) @@ -408,7 +411,7 @@ int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map #include #include -#include +#include #include #include #include @@ -427,15 +427,15 @@ int SYMBOL_EDITOR_CONTROL::ExportSymbolAsSVG( const TOOL_EVENT& aEvent ) return 0; } - wxString file_ext = wxT( "svg" ); - wxString mask = wxT( "*." ) + file_ext; + wxString file_ext = SVGFileExtension; wxFileName fn( symbol->GetName() ); - fn.SetExt( file_ext ); + fn.SetExt( SVGFileExtension ); wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() ); - wxString fullFileName = EDA_FILE_SELECTOR( _( "Filename:" ), pro_dir, fn.GetFullName(), - file_ext, mask, m_frame, wxFD_SAVE, true ); + wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(), + SVGFileExtension, SVGFileWildcard(), wxFD_SAVE, + m_frame ); if( !fullFileName.IsEmpty() ) { @@ -443,7 +443,7 @@ int SYMBOL_EDITOR_CONTROL::ExportSymbolAsSVG( const TOOL_EVENT& aEvent ) PAGE_INFO pageTemp = pageSave; wxSize symbolSize = symbol->GetUnitBoundingBox( editFrame->GetUnit(), - editFrame->GetConvert() ).GetSize(); + editFrame->GetConvert() ).GetSize(); // Add a small margin to the plot bounding box pageTemp.SetWidthMils( int( symbolSize.x * 1.2 ) ); diff --git a/include/gestfich.h b/include/gestfich.h index 7ca140f8a1..ed4119946d 100644 --- a/include/gestfich.h +++ b/include/gestfich.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009-2014 Jerry Jacobs - * Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -66,36 +66,6 @@ bool CanPrintFile( const wxString& file ); */ void KiCopyFile( const wxString& aSrcPath, const wxString& aDestPath, wxString& aErrors ); -/** - * A helper function that wraps a call to wxFileSelector. - * - * @param aTitle is a string to display in the dialog title bar. - * @param aPath is a string contain the default path for the path dialog. - * @param aFileName is a string containing the default file name. - * @param aExtension is a string containing the default file extension. - * @param aWildcard is a string containing the default wildcard. - * @param aParent is the parent window of the dialog. - * @param aStyle is the style of the path dialog, wxFD_???. - * @param aKeepWorkingDirectory determines if current working directory should be set to the - * user selected path. - * @param aPosition is the position of the dialog. - * @param aMruPath is a pointer to a string to copy the path selected by the user when - * the OK button is pressed to dismiss the dialog. This can be NULL. - * @return the full path and file name of the selected file or wxEmptyString if the user - * pressed the cancel button to dismiss the dialog. - */ -wxString EDA_FILE_SELECTOR( const wxString& aTitle, - const wxString& aPath, - const wxString& aFileName, - const wxString& aExtension, - const wxString& aWildcard, - wxWindow* aParent, - int aStyle, - const bool aKeepWorkingDirectory, - const wxPoint& aPosition = wxDefaultPosition, - wxString* aMruPath = nullptr ); - - /** * Call the executable file \a ExecFile with the command line parameters \a param. */ diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index 8134be31e2..f0509b50ee 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,7 +27,6 @@ #include #include -#define DEFAULT_HOTKEY_FILENAME_EXT wxT( "hotkeys" ) #define EESCHEMA_HOTKEY_NAME wxT( "Eeschema" ) #define PCBNEW_HOTKEY_NAME wxT( "PcbNew" ) diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 3d7f538ce3..f793fb2d7a 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -126,6 +126,7 @@ extern const std::string GerberFileExtension; extern const std::string GerberJobFileExtension; extern const std::string HtmlFileExtension; extern const std::string EquFileExtension; +extern const std::string HotkeyFileExtension; extern const std::string ArchiveFileExtension; @@ -150,11 +151,13 @@ extern const std::string GedaPcbFootprintLibFileExtension; extern const std::string EagleFootprintLibPathExtension; extern const std::string DrawingSheetFileExtension; extern const std::string SpecctraDsnFileExtension; +extern const std::string SpecctraSessionFileExtension; extern const std::string IpcD356FileExtension; extern const std::string WorkbookFileExtension; extern const std::string PngFileExtension; extern const std::string JpegFileExtension; +extern const std::string TextFileExtension; bool IsProtelExtension( const wxString& ext ); @@ -233,10 +236,12 @@ extern wxString GencadFileWildcard(); extern wxString DxfFileWildcard(); extern wxString GerberJobFileWildcard(); extern wxString SpecctraDsnFileWildcard(); +extern wxString SpecctraSessionFileWildcard(); extern wxString IpcD356FileWildcard(); extern wxString WorkbookFileWildcard(); extern wxString PngFileWildcard(); extern wxString JpegFileWildcard(); +extern wxString HotkeyFileWildcard(); /** * @} diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 6594882a7f..51caae3f77 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -106,9 +106,6 @@ static const wxChar* s_allowedExtensionsToList[] = { * library as required. */ -// File extension definitions. -const wxChar TextFileExtension[] = wxT( "txt" ); - // Gerber file extension wildcard. const wxString GerberFileExtensionWildCard( ".((gbr|gbrjob|(gb|gt)[alops])|pho)" ); @@ -505,6 +502,7 @@ wxTreeItemId PROJECT_TREE_PANE::addItemToProjectTree( const wxString& aName, bool haveFile = dir.GetFirst( &dir_filename ); data->SetPopulated( true ); + #ifndef __WINDOWS__ subdir_populated = aRecurse; #endif @@ -799,12 +797,13 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event ) { popup_menu.AppendSeparator(); AddMenuItem( &popup_menu, ID_PROJECT_PRINT, + #ifdef __APPLE__ - _( "Print..." ), + _( "Print..." ), #else - _( "Print" ), + _( "Print" ), #endif - _( "Print the contents of the file" ), KiBitmap( BITMAPS::print_button ) ); + _( "Print the contents of the file" ), KiBitmap( BITMAPS::print_button ) ); } if( popup_menu.GetMenuItemCount() > 0 ) @@ -969,6 +968,7 @@ void PROJECT_TREE_PANE::onExpand( wxTreeEvent& Event ) } itemData->SetPopulated( true ); // set state to populated + #ifndef __WINDOWS__ subdir_populated = true; #endif @@ -1097,19 +1097,19 @@ void PROJECT_TREE_PANE::onFileSystemEvent( wxFileSystemWatcherEvent& event ) switch( event.GetChangeType() ) { case wxFSW_EVENT_CREATE: - { - wxTreeItemId newitem = addItemToProjectTree( pathModified.GetFullPath(), root_id, - nullptr, true ); + { + wxTreeItemId newitem = + addItemToProjectTree( pathModified.GetFullPath(), root_id, nullptr, true ); - // If we are in the process of renaming a file, select the new one - // This is needed for MSW and OSX, since we don't get RENAME events from them, just a - // pair of DELETE and CREATE events. - if( m_isRenaming && newitem.IsOk() ) - { - m_TreeProject->SelectItem( newitem ); - m_isRenaming = false; - } + // If we are in the process of renaming a file, select the new one + // This is needed for MSW and OSX, since we don't get RENAME events from them, just a + // pair of DELETE and CREATE events. + if( m_isRenaming && newitem.IsOk() ) + { + m_TreeProject->SelectItem( newitem ); + m_isRenaming = false; } + } break; case wxFSW_EVENT_DELETE: @@ -1127,45 +1127,45 @@ void PROJECT_TREE_PANE::onFileSystemEvent( wxFileSystemWatcherEvent& event ) break; case wxFSW_EVENT_RENAME : + { + const wxFileName& newpath = event.GetNewPath(); + wxString newdir = newpath.GetPath(); + wxString newfn = newpath.GetFullPath(); + + while( kid.IsOk() ) { - const wxFileName& newpath = event.GetNewPath(); - wxString newdir = newpath.GetPath(); - wxString newfn = newpath.GetFullPath(); + PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); - while( kid.IsOk() ) + if( itemData && itemData->GetFileName() == fn ) { - PROJECT_TREE_ITEM* itemData = GetItemIdData( kid ); - - if( itemData && itemData->GetFileName() == fn ) - { - m_TreeProject->Delete( kid ); - break; - } - - kid = m_TreeProject->GetNextChild( root_id, cookie ); + m_TreeProject->Delete( kid ); + break; } - // Add the new item only if it is not the current project file (root item). - // Remember: this code is called by a wxFileSystemWatcherEvent event, and not always - // called after an actual file rename, and the cleanup code does not explore the - // root item, because it cannot be renamed by the user. Also, ensure the new file - // actually exists on the file system before it is readded. On Linux, moving a file - // to the trash can cause the same path to be returned in both the old and new paths - // of the event, even though the file isn't there anymore. - PROJECT_TREE_ITEM* rootData = GetItemIdData( root_id ); - - if( newpath.Exists() && ( newfn != rootData->GetFileName() ) ) - { - wxTreeItemId newroot_id = findSubdirTreeItem( newdir ); - wxTreeItemId newitem = addItemToProjectTree( newfn, newroot_id, nullptr, true ); - - // If the item exists, select it - if( newitem.IsOk() ) - m_TreeProject->SelectItem( newitem ); - } - - m_isRenaming = false; + kid = m_TreeProject->GetNextChild( root_id, cookie ); } + + // Add the new item only if it is not the current project file (root item). + // Remember: this code is called by a wxFileSystemWatcherEvent event, and not always + // called after an actual file rename, and the cleanup code does not explore the + // root item, because it cannot be renamed by the user. Also, ensure the new file + // actually exists on the file system before it is readded. On Linux, moving a file + // to the trash can cause the same path to be returned in both the old and new paths + // of the event, even though the file isn't there anymore. + PROJECT_TREE_ITEM* rootData = GetItemIdData( root_id ); + + if( newpath.Exists() && ( newfn != rootData->GetFileName() ) ) + { + wxTreeItemId newroot_id = findSubdirTreeItem( newdir ); + wxTreeItemId newitem = addItemToProjectTree( newfn, newroot_id, nullptr, true ); + + // If the item exists, select it + if( newitem.IsOk() ) + m_TreeProject->SelectItem( newitem ); + } + + m_isRenaming = false; + } break; } diff --git a/pcbnew/microwave/microwave_polygon.cpp b/pcbnew/microwave/microwave_polygon.cpp index effaaf8e66..8d003188a9 100644 --- a/pcbnew/microwave/microwave_polygon.cpp +++ b/pcbnew/microwave/microwave_polygon.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -172,9 +171,8 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event ) wxString fullFileName; wxString mask = wxFileSelectorDefaultWildcardStr; - fullFileName = EDA_FILE_SELECTOR( _( "Read Shape Description File" ), lastpath, - fullFileName, wxEmptyString, mask, this, - wxFD_OPEN, true ); + fullFileName = wxFileSelector( _( "Shape Description File" ), lastpath, + fullFileName, wxEmptyString, mask, wxFD_OPEN, this ); if( fullFileName.IsEmpty() ) return; diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index d2891b76cb..936edb295c 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -375,10 +374,12 @@ int BOARD_EDITOR_CONTROL::ImportSpecctraSession( const TOOL_EVENT& aEvent ) wxString ext; wxFileName::SplitPath( fullFileName, &path, &name, &ext ); - name += wxT( ".ses" ); + name += wxT( "." ) + SpecctraSessionFileExtension; - fullFileName = EDA_FILE_SELECTOR( _( "Merge Specctra Session file:" ), path, name, - wxT( ".ses" ), wxT( "*.ses" ), frame(), wxFD_OPEN, false ); + fullFileName = wxFileSelector( _( "Specctra Session File" ), path, name, + wxT( "." ) + SpecctraSessionFileExtension, + SpecctraSessionFileWildcard(), wxFD_OPEN | wxFD_CHANGE_DIR, + frame() ); if( !fullFileName.IsEmpty() ) getEditFrame()->ImportSpecctraSession( fullFileName ); @@ -400,9 +401,9 @@ int BOARD_EDITOR_CONTROL::ExportSpecctraDSN( const TOOL_EVENT& aEvent ) else fn = fullFileName; - fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN File" ), fn.GetPath(), fn.GetFullName(), - SpecctraDsnFileExtension, SpecctraDsnFileWildcard(), - frame(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, false ); + fullFileName = wxFileSelector( _( "Specctra DSN File" ), fn.GetPath(), fn.GetFullName(), + SpecctraDsnFileExtension, SpecctraDsnFileWildcard(), + wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR, frame() ); if( !fullFileName.IsEmpty() ) {