Eeschema: fix a Unicode/UTF8 management when pasting items from Clipboard.

Copy to clipboard save items (using S expr description) using wide strings
(not UTF8 encoding).
But Paste from clipboard was not converting the wide string to UTF8 string
when getting the stored data to send it as std::string to the S expr reader.

Fixes #6449
https://gitlab.com/kicad/code/kicad/issues/6449
This commit is contained in:
jean-pierre charras 2020-11-21 10:59:25 +01:00
parent ff3bd7e72a
commit 64636601b8
5 changed files with 19 additions and 12 deletions

View File

@ -971,11 +971,13 @@ void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu,
}
bool TOOL_MANAGER::SaveClipboard( const std::string& aText )
bool TOOL_MANAGER::SaveClipboard( const std::string& aTextUTF8 )
{
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject( wxString( aText.c_str(), wxConvUTF8 ) ) );
// Store the UTF8 string as unicode string in clipboard:
wxTheClipboard->SetData( new wxTextDataObject( wxString( aTextUTF8.c_str(),
wxConvUTF8 ) ) );
wxTheClipboard->Close();
return true;
@ -985,7 +987,7 @@ bool TOOL_MANAGER::SaveClipboard( const std::string& aText )
}
std::string TOOL_MANAGER::GetClipboard() const
std::string TOOL_MANAGER::GetClipboardUTF8() const
{
std::string result;
@ -997,7 +999,9 @@ std::string TOOL_MANAGER::GetClipboard() const
wxTextDataObject data;
wxTheClipboard->GetData( data );
result = data.GetText().mb_str();
// The clipboard is expected containing a unicode string, so return it
// as UTF8 string
result = data.GetText().utf8_str();
}
wxTheClipboard->Close();

View File

@ -668,8 +668,8 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
if( !part || part->IsAlias() )
return 0;
std::string text = m_toolMgr->GetClipboard();
STRING_LINE_READER reader( text, "Clipboard" );
std::string text_utf8 = m_toolMgr->GetClipboardUTF8();
STRING_LINE_READER reader( text_utf8, "Clipboard" );
LIB_PART* newPart;
try
@ -681,7 +681,7 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
// If it's not a part then paste as text
newPart = new LIB_PART( "dummy_part" );
LIB_TEXT* newText = new LIB_TEXT( newPart );
newText->SetText( text );
newText->SetText( wxString::FromUTF8( text_utf8 ) );
newPart->AddDrawItem( newText );
}

View File

@ -1353,7 +1353,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
}
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
std::string text = m_toolMgr->GetClipboard();
std::string text = m_toolMgr->GetClipboardUTF8();
if( text.empty() )
return 0;

View File

@ -381,16 +381,19 @@ public:
/**
* Stores an information to the system clipboard.
* @param aText is the information to be stored.
* @param aText is the information to be stored, expected UTF8 encoding.
* the text will be stored as Unicode string (not stored as UTF8 string)
* @return False if error occurred.
*/
bool SaveClipboard( const std::string& aText );
bool SaveClipboard( const std::string& aTextUTF8 );
/**
* Returns the information currently stored in the system clipboard. If data stored in the
* clipboard is in non-text format, empty string is returned.
* Note also the clipboard is expected containing unicode chars, not only ASCII7 chars.
* The returned string is UTF8 encoded
*/
std::string GetClipboard() const;
std::string GetClipboardUTF8() const;
/**
* Returns the view controls settings for the current tool or the general settings if there is

View File

@ -477,7 +477,7 @@ int PL_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
{
PL_SELECTION& selection = m_selectionTool->GetSelection();
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
std::string sexpr = m_toolMgr->GetClipboard();
std::string sexpr = m_toolMgr->GetClipboardUTF8();
m_selectionTool->ClearSelection();