Fix bugs in Eeschema paste.
1) don't ASSERT; use exceptions (which can be caught) instead. 2) clean up LIB_LOGGER so it's only used during sync 3) fix typos in wxLogMessage() calls so they produce output. 4) throw on unrecognized token in loadContent(). 5) if clipboard can't be pasted as content then paste as text. Fixes: lp:1840172 * https://bugs.launchpad.net/kicad/+bug/1840172
This commit is contained in:
parent
b4c8657904
commit
206b40621e
|
@ -27,7 +27,7 @@
|
|||
|
||||
|
||||
#define THROWERS_WHERE _( "from %s : %s() line:%d" )
|
||||
#define PARSE_PROBLEM _( "%s in input/source\n\"%s\"\nline %d, offset %d" )
|
||||
#define PARSE_PROBLEM _( "%s in \"%s\", line %d, offset %d" )
|
||||
|
||||
|
||||
const wxString IO_ERROR::What() const
|
||||
|
|
|
@ -49,14 +49,16 @@ void LIB_MANAGER::Sync( bool aForce,
|
|||
std::function<void( int, int, const wxString& )> aProgressCallback )
|
||||
{
|
||||
m_logger.Activate();
|
||||
|
||||
int libTableHash = symTable()->GetModifyHash();
|
||||
|
||||
if( aForce || m_syncHash != libTableHash )
|
||||
{
|
||||
getAdapter()->Sync( aForce, aProgressCallback );
|
||||
m_syncHash = libTableHash;
|
||||
int libTableHash = symTable()->GetModifyHash();
|
||||
|
||||
if( aForce || m_syncHash != libTableHash )
|
||||
{
|
||||
getAdapter()->Sync( aForce, aProgressCallback );
|
||||
m_syncHash = libTableHash;
|
||||
}
|
||||
}
|
||||
m_logger.Deactivate();
|
||||
}
|
||||
|
||||
|
||||
|
@ -577,8 +579,8 @@ bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LI
|
|||
if( relPath.IsEmpty() )
|
||||
relPath = aFilePath;
|
||||
|
||||
SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath,
|
||||
SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
|
||||
wxString typeName = SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY );
|
||||
SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
|
||||
aTable->InsertRow( libRow );
|
||||
|
||||
if( aCreate )
|
||||
|
@ -748,13 +750,13 @@ bool LIB_MANAGER::LIB_BUFFER::DeleteBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartB
|
|||
|
||||
|
||||
bool LIB_MANAGER::LIB_BUFFER::SaveBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf,
|
||||
SYMBOL_LIB_TABLE* aLibTable )
|
||||
SYMBOL_LIB_TABLE* aLibTable )
|
||||
{
|
||||
wxCHECK( aPartBuf, false );
|
||||
LIB_PART* part = aPartBuf->GetPart();
|
||||
wxCHECK( part, false );
|
||||
wxCHECK( aLibTable->SaveSymbol( m_libName,
|
||||
new LIB_PART( *part ) ) == SYMBOL_LIB_TABLE::SAVE_OK, false );
|
||||
SYMBOL_LIB_TABLE::SAVE_T result = aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) );
|
||||
wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
|
||||
|
||||
aPartBuf->SetOriginal( new LIB_PART( *part ) );
|
||||
++m_hash;
|
||||
|
@ -763,7 +765,7 @@ bool LIB_MANAGER::LIB_BUFFER::SaveBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf
|
|||
|
||||
|
||||
bool LIB_MANAGER::LIB_BUFFER::SaveBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf,
|
||||
SCH_PLUGIN* aPlugin, bool aBuffer )
|
||||
SCH_PLUGIN* aPlugin, bool aBuffer )
|
||||
{
|
||||
wxCHECK( aPartBuf, false );
|
||||
LIB_PART* part = aPartBuf->GetPart();
|
||||
|
|
|
@ -54,16 +54,27 @@ public:
|
|||
|
||||
~LIB_LOGGER() override
|
||||
{
|
||||
if( m_activated )
|
||||
wxLog::SetActiveTarget( m_previousLogger );
|
||||
Deactivate();
|
||||
}
|
||||
|
||||
void Activate()
|
||||
{
|
||||
m_activated = true;
|
||||
m_previousLogger = wxLog::GetActiveTarget();
|
||||
wxLog::SetActiveTarget( this );
|
||||
Clear();
|
||||
if( !m_activated )
|
||||
{
|
||||
m_previousLogger = wxLog::GetActiveTarget();
|
||||
wxLog::SetActiveTarget( this );
|
||||
m_activated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Deactivate()
|
||||
{
|
||||
if( m_activated )
|
||||
{
|
||||
Flush();
|
||||
m_activated = false;
|
||||
wxLog::SetActiveTarget( m_previousLogger );
|
||||
}
|
||||
}
|
||||
|
||||
void Flush() override
|
||||
|
|
|
@ -600,7 +600,7 @@ void LIB_EDIT_FRAME::DuplicatePart( bool aFromClipboard )
|
|||
}
|
||||
catch( IO_ERROR& e )
|
||||
{
|
||||
wxLogError( wxString::Format( "Malformed clipboard: %s" ), GetChars( e.What() ) );
|
||||
wxLogMessage( "Can not paste: %s", GetChars( e.Problem() ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -787,6 +787,8 @@ void SCH_LEGACY_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
|
|||
aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
|
||||
else if( strCompare( "$EndSCHEMATC", line ) )
|
||||
return;
|
||||
else
|
||||
SCH_PARSE_ERROR( "unrecognized token", aReader, line );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2699,7 +2701,8 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::LoadPart( LINE_READER& aReader, int aMajorVer
|
|||
while( *line == '#' )
|
||||
aReader.ReadLine();
|
||||
|
||||
wxCHECK( strCompare( "DEF", line, &line ), NULL );
|
||||
if( !strCompare( "DEF", line, &line ) )
|
||||
SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
|
||||
|
||||
long num;
|
||||
size_t pos = 4; // "DEF" plus the first space.
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <dialogs/dialog_edit_component_in_lib.h>
|
||||
#include <dialogs/dialog_lib_edit_pin_table.h>
|
||||
#include <sch_legacy_plugin.h>
|
||||
#include <lib_text.h>
|
||||
#include "lib_edit_tool.h"
|
||||
|
||||
|
||||
|
@ -661,8 +662,11 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
catch( IO_ERROR& e )
|
||||
{
|
||||
wxLogError( wxString::Format( "Malformed clipboard: %s" ), GetChars( e.What() ) );
|
||||
return -1;
|
||||
// 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 );
|
||||
newPart->AddDrawItem( newText );
|
||||
}
|
||||
|
||||
if( !newPart )
|
||||
|
|
|
@ -929,6 +929,10 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
SCH_ITEM* last = dlist.GetLast();
|
||||
|
||||
std::string text = m_toolMgr->GetClipboard();
|
||||
|
||||
if( text.empty() )
|
||||
return 0;
|
||||
|
||||
STRING_LINE_READER reader( text, "Clipboard" );
|
||||
SCH_LEGACY_PLUGIN plugin;
|
||||
|
||||
|
@ -938,8 +942,8 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
catch( IO_ERROR& e )
|
||||
{
|
||||
wxLogError( wxString::Format( "Malformed clipboard: %s" ), GetChars( e.What() ) );
|
||||
return 0;
|
||||
// If it wasn't content, then paste as text
|
||||
dlist.Append( new SCH_TEXT( wxPoint( 0, 0 ), text ) );
|
||||
}
|
||||
|
||||
// SCH_LEGACY_PLUGIN added the items to the DLIST, but not to the view or anything
|
||||
|
|
Loading…
Reference in New Issue