From b636aaddf6ab81346afe2b239ff17081e59bf976 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 29 Apr 2018 15:45:11 +0200 Subject: [PATCH] Eeschema: fix incorrect UI messages in dialogs due to using UTF8 strings instead of wxStrings (unicode) to build them. (Added a explicit to build a Unicode string in UI messages to avoid mistakes) --- .../dialogs/dialog_edit_components_libid.cpp | 2 +- .../dialogs/dialog_fields_editor_global.cpp | 4 +++- eeschema/libarch.cpp | 8 +++---- eeschema/libedit.cpp | 3 ++- include/lib_id.h | 21 +++++++++++++++++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp index f6f95d996b..ccbef8466d 100644 --- a/eeschema/dialogs/dialog_edit_components_libid.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid.cpp @@ -66,7 +66,7 @@ public: // Returns a string like mylib:symbol_name from the LIB_ID of the component wxString GetStringLibId() { - return wxString( m_Component->GetLibId().Format().c_str() ); + return m_Component->GetLibId().GetUniStringLibId(); } // Returns a string containing the reference of the component diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 0c8f08ddc4..d26ad52f09 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -409,11 +409,13 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent // Now that the fields are loaded we can set the initial location of the splitter // based on the list width. Again, SetWidth( wxCOL_WIDTH_AUTOSIZE ) fails us on GTK. int nameColWidth = 0; - for( unsigned int row = 0; row < m_fieldsCtrl->GetItemCount(); ++row ) + + for( int row = 0; row < m_fieldsCtrl->GetItemCount(); ++row ) { const wxString& fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN ); nameColWidth = std::max( nameColWidth, GetTextSize( fieldName, m_fieldsCtrl ).x ); } + m_fieldsCtrl->GetColumn( FIELD_NAME_COLUMN )->SetWidth( nameColWidth ); m_splitter1->SetSashPosition( nameColWidth + m_showColWidth + m_groupByColWidth + 40 ); diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index a62c38d798..0e0c207b3f 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -99,8 +99,8 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) catch( const IO_ERROR& ) { // Queue up error messages for later. - tmp.Printf( _( "Failed to add symbol %s to library file." ), - component->GetLibId().GetLibItemName().wx_str(), aFileName ); + tmp.Printf( _( "Failed to add symbol \"%s\" to library file \"%s\"." ), + component->GetLibId().GetUniStringLibItemName(), aFileName ); // Don't bail out here. Attempt to add as many of the symbols to the library // as possible. @@ -114,7 +114,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) { // Use the full LIB_ID as the symbol name to prevent symbol name collisions. wxString oldName = part->GetName(); - part->SetName( component->GetLibId().Format() ); + part->SetName( component->GetLibId().GetUniStringLibId() ); // AddPart() does first clone the part before adding. archLib->AddPart( part ); @@ -123,7 +123,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) else { tmp.Printf( _( "Symbol %s not found in any library or cache." ), - component->GetLibId().Format().wx_str() ); + component->GetLibId().GetUniStringLibId() ); } if( !tmp.empty() ) diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 287f4f7f25..be3a9074da 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -373,7 +373,8 @@ void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent ) if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() ) && !IsOK( this, _( wxString::Format( "Component %s has been modified\n" - "Do you want to remove it from the library?", libId.GetLibItemName().c_str() ) ) ) ) + "Do you want to remove it from the library?", + libId.GetUniStringLibItemName() ) ) ) ) { return; } diff --git a/include/lib_id.h b/include/lib_id.h index c7e5a49e07..f4c2277f62 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -113,10 +113,17 @@ public: int SetLibNickname( const UTF8& aNickname ); /** - * @return the library item name, i.e. footprintName. + * @return the library item name, i.e. footprintName, in UTF8. */ const UTF8& GetLibItemName() const { return item_name; } + /** + * @return the library item name, i.e. footprintName in a wxString (UTF16 or 32). + * useful to display messages in dialogs + * Equivalent to item_name.wx_str(), but more explicit when building a Unicode string in messages. + */ + const wxString GetUniStringLibItemName() const { return item_name.wx_str(); } + /** * Override the library item name portion of the LIB_ID to @a aLibItemName * @@ -133,10 +140,20 @@ public: UTF8 GetLibItemNameAndRev() const; /** - * @return the fully formatted text of the LIB_ID. + * @return the fully formatted text of the LIB_ID in a UTF8 string. */ UTF8 Format() const; + /** + * @return the fully formatted text of the LIB_ID in a wxString (UTF16 or UTF32), + * suitable to display the LIB_ID in dialogs. + * Equivalent to Format().wx_str(), but more explicit when building a Unicode string in messages. + */ + wxString GetUniStringLibId() const + { + return Format().wx_str(); + } + /** * @return a string in the proper format as an LIB_ID for a combination of * aLibNickname, aLibItemName, and aRevision.