FILE_NAME_CHAR_VALIDATOR::FILE_NAME_CHAR_VALIDATOR( wxString* aValue ) : wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) { // The Windows (DOS) file system forbidden characters already include the forbidden // file name characters for both Posix and OSX systems. The characters \/:*?|"<> are // illegal and filtered by the validator. wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS ); wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); wxArrayString illegalCharList; for( unsigned i = 0; i < illegalChars.size(); i++ ) illegalCharList.Add( wxString( illegalChars[i] ) ); SetExcludes( illegalCharList ); }
FILE_NAME_WITH_PATH_CHAR_VALIDATOR::FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue ) : wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) { // The Windows (DOS) file system forbidden characters already include the forbidden // file name characters for both Posix and OSX systems. The characters *?|"<> are // illegal and filtered by the validator, but /\: are valid (\ and : only on Windows. wxString illegalChars = wxFileName::GetForbiddenChars(wxPATH_DOS ); wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); wxArrayString illegalCharList; for( unsigned i = 0; i < illegalChars.size(); i++ ) { if( illegalChars[i] == '/' ) continue; #if defined (__WINDOWS__) if( illegalChars[i] == '\\' || illegalChars[i] == ':' ) continue; #endif illegalCharList.Add( wxString( illegalChars[i] ) ); } SetExcludes( illegalCharList ); }
bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule ) { if( aModule == NULL ) return false; FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); SetMsgPanel( aModule ); wxString libraryName = aModule->GetFPID().GetLibNickname(); wxString footprintName = aModule->GetFPID().GetLibItemName(); bool updateValue = ( aModule->GetValue() == footprintName ); wxArrayString headers; std::vector<wxArrayString> itemsToDisplay; std::vector<wxString> nicknames = tbl->GetLogicalLibs(); headers.Add( _( "Nickname" ) ); headers.Add( _( "Description" ) ); for( unsigned i = 0; i < nicknames.size(); i++ ) { wxArrayString item; item.Add( nicknames[i] ); item.Add( tbl->GetDescription( nicknames[i] ) ); itemsToDisplay.push_back( item ); } EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName, nullptr, nullptr, /* sort */ false, /* show headers */ false ); dlg.SetListLabel( _( "Save in library:" ) ); dlg.SetOKLabel( _( "Save" ) ); wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL ); wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ), wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName, wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) ); nameTextCtrl->SetValidator( nameValidator ); wxSizer* mainSizer = dlg.GetSizer(); mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 ); // Move nameTextCtrl to the head of the tab-order if( dlg.GetChildren().DeleteObject( nameTextCtrl ) ) dlg.GetChildren().Insert( nameTextCtrl ); dlg.SetInitialFocus( nameTextCtrl ); dlg.Layout(); mainSizer->Fit( &dlg ); if( dlg.ShowModal() != wxID_OK ) return false; // canceled by user libraryName = dlg.GetTextSelection(); if( libraryName.IsEmpty() ) { DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) ); return false; } footprintName = nameTextCtrl->GetValue(); footprintName.Trim( true ); footprintName.Trim( false ); if( footprintName.IsEmpty() ) { DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) ); return false; } aModule->SetFPID( LIB_ID( libraryName, footprintName ) ); if( updateValue ) aModule->SetValue( footprintName ); // Legacy libraries are readable, but modifying legacy format is not allowed // So prompt the user if he try to add/replace a footprint in a legacy lib wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI(); IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname ); if( piType == IO_MGR::LEGACY ) { DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT ); return false; } bool module_exists = tbl->FootprintExists( libraryName, footprintName ); if( module_exists ) { wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ), footprintName, libraryName ); KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); chkdlg.SetOKLabel( _( "Overwrite" ) ); if( chkdlg.ShowModal() == wxID_CANCEL ) return false; } if( !saveFootprintInLibrary( aModule, libraryName ) ) return false; // Once saved-as a board footprint is no longer a board footprint aModule->SetLink( 0 ); wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) : _( "Component \"%s\" added in \"%s\"" ); wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() ); SetStatusText( msg ); updateTitle(); return true; }