Move cut/copy/paste part (in libedit tree) to real clipboard.
Fixes: lp:1821547 * https://bugs.launchpad.net/kicad/+bug/1821547
This commit is contained in:
parent
cf63ae7ae2
commit
b6c0aeb608
|
@ -62,9 +62,6 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME
|
||||||
SYMBOL_TREE_PANE* m_treePane; ///< component search tree widget
|
SYMBOL_TREE_PANE* m_treePane; ///< component search tree widget
|
||||||
LIB_MANAGER* m_libMgr; ///< manager taking care of temporary modificatoins
|
LIB_MANAGER* m_libMgr; ///< manager taking care of temporary modificatoins
|
||||||
|
|
||||||
// Copy/cut/paste buffer to move parts between libraries
|
|
||||||
std::unique_ptr<LIB_PART> m_copiedPart;
|
|
||||||
|
|
||||||
/** Convert of the item currently being drawn. */
|
/** Convert of the item currently being drawn. */
|
||||||
bool m_drawSpecificConvert;
|
bool m_drawSpecificConvert;
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,13 @@
|
||||||
#include <lib_manager.h>
|
#include <lib_manager.h>
|
||||||
#include <symbol_tree_pane.h>
|
#include <symbol_tree_pane.h>
|
||||||
#include <widgets/lib_tree.h>
|
#include <widgets/lib_tree.h>
|
||||||
|
#include <sch_legacy_plugin.h>
|
||||||
#include <dialog_choose_component.h>
|
#include <dialog_choose_component.h>
|
||||||
#include <symbol_tree_model_adapter.h>
|
#include <symbol_tree_model_adapter.h>
|
||||||
|
|
||||||
#include <dialogs/dialog_lib_new_component.h>
|
#include <dialogs/dialog_lib_new_component.h>
|
||||||
#include <dialog_helpers.h>
|
#include <dialog_helpers.h>
|
||||||
|
#include <wx/clipbrd.h>
|
||||||
|
|
||||||
void LIB_EDIT_FRAME::updateTitle()
|
void LIB_EDIT_FRAME::updateTitle()
|
||||||
{
|
{
|
||||||
|
@ -526,7 +527,19 @@ void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent )
|
||||||
if( !part )
|
if( !part )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_copiedPart.reset( new LIB_PART( *part ) );
|
STRING_FORMATTER formatter;
|
||||||
|
SCH_LEGACY_PLUGIN::FormatPart( part, formatter );
|
||||||
|
|
||||||
|
auto clipboard = wxTheClipboard;
|
||||||
|
wxClipboardLocker clipboardLock( clipboard );
|
||||||
|
|
||||||
|
if( !clipboardLock || !clipboard->IsOpened() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto data = new wxTextDataObject( wxString( formatter.GetString().c_str(), wxConvUTF8 ) );
|
||||||
|
clipboard->SetData( data );
|
||||||
|
|
||||||
|
clipboard->Flush();
|
||||||
|
|
||||||
if( aEvent.GetId() == ID_LIBEDIT_CUT_PART )
|
if( aEvent.GetId() == ID_LIBEDIT_CUT_PART )
|
||||||
OnRemovePart( aEvent );
|
OnRemovePart( aEvent );
|
||||||
|
@ -543,22 +556,50 @@ void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LIB_PART* srcPart = nullptr;
|
LIB_PART* srcPart = nullptr;
|
||||||
|
LIB_PART* newPart = nullptr;
|
||||||
|
|
||||||
if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART )
|
if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART )
|
||||||
|
{
|
||||||
srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib );
|
srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib );
|
||||||
|
newPart = new LIB_PART( *srcPart );
|
||||||
|
}
|
||||||
else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART )
|
else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART )
|
||||||
srcPart = m_copiedPart.get();
|
{
|
||||||
|
auto clipboard = wxTheClipboard;
|
||||||
|
wxClipboardLocker clipboardLock( clipboard );
|
||||||
|
|
||||||
|
if( !clipboardLock || ! clipboard->IsSupported( wxDF_TEXT ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
wxTextDataObject data;
|
||||||
|
clipboard->GetData( data );
|
||||||
|
wxString partSource = data.GetText();
|
||||||
|
|
||||||
|
STRING_LINE_READER reader( TO_UTF8( partSource ), "Clipboard" );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader.ReadLine();
|
||||||
|
newPart = SCH_LEGACY_PLUGIN::ParsePart( reader );
|
||||||
|
}
|
||||||
|
catch( IO_ERROR& e )
|
||||||
|
{
|
||||||
|
wxLogError( wxString::Format( "Malformed clipboard: %s" ), GetChars( e.What() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
wxFAIL;
|
wxFAIL;
|
||||||
|
|
||||||
if( !srcPart )
|
if( !newPart )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LIB_PART newPart( *srcPart );
|
fixDuplicateAliases( newPart, lib );
|
||||||
fixDuplicateAliases( &newPart, lib );
|
m_libMgr->UpdatePart( newPart, lib );
|
||||||
m_libMgr->UpdatePart( &newPart, lib );
|
|
||||||
SyncLibraries( false );
|
SyncLibraries( false );
|
||||||
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart->GetName() ) );
|
||||||
|
|
||||||
|
delete newPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2672,6 +2672,9 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::LoadPart( LINE_READER& aReader, int aMajorVer
|
||||||
{
|
{
|
||||||
const char* line = aReader.Line();
|
const char* line = aReader.Line();
|
||||||
|
|
||||||
|
while( *line == '#' )
|
||||||
|
aReader.ReadLine();
|
||||||
|
|
||||||
wxCHECK( strCompare( "DEF", line, &line ), NULL );
|
wxCHECK( strCompare( "DEF", line, &line ), NULL );
|
||||||
|
|
||||||
long num;
|
long num;
|
||||||
|
|
Loading…
Reference in New Issue