From 21c216556b0eceef6e9cd198f0060ab74685b574 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 26 May 2019 19:35:20 +0100 Subject: [PATCH] Cut/copy/paste for PlEditor. --- common/page_layout/page_layout_reader.cpp | 2 +- common/page_layout/ws_data_item.cpp | 74 +++++++++---------- common/page_layout/ws_data_model_io.cpp | 9 +++ include/ws_data_model.h | 5 ++ include/ws_draw_item.h | 35 ++++----- include/ws_proxy_undo_item.h | 2 +- pagelayout_editor/hotkeys.cpp | 19 +++-- pagelayout_editor/menubar.cpp | 8 +- pagelayout_editor/tools/pl_edit_tool.cpp | 89 +++++++++++++++++++++-- pagelayout_editor/tools/pl_edit_tool.h | 4 + 10 files changed, 175 insertions(+), 72 deletions(-) diff --git a/common/page_layout/page_layout_reader.cpp b/common/page_layout/page_layout_reader.cpp index 255e81130d..46880983bb 100644 --- a/common/page_layout/page_layout_reader.cpp +++ b/common/page_layout/page_layout_reader.cpp @@ -116,7 +116,7 @@ PAGE_LAYOUT_READER_PARSER::PAGE_LAYOUT_READER_PARSER( const char* aLine, const w void PAGE_LAYOUT_READER_PARSER::Parse( WS_DATA_MODEL* aLayout ) { WS_DATA_ITEM* item; - LOCALE_IO toggle; + LOCALE_IO toggle; for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() ) { diff --git a/common/page_layout/ws_data_item.cpp b/common/page_layout/ws_data_item.cpp index e70853a400..efddf307b0 100644 --- a/common/page_layout/ws_data_item.cpp +++ b/common/page_layout/ws_data_item.cpp @@ -82,10 +82,10 @@ void WS_DATA_ITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aV std::map itemFlags; WS_DRAW_ITEM_BASE* item = nullptr; - for( size_t ii = 0; ii < m_drawItems.size(); ++ii ) + for( size_t i = 0; i < m_drawItems.size(); ++i ) { - item = m_drawItems[ ii ]; - itemFlags[ ii ] = item->GetFlags(); + item = m_drawItems[ i ]; + itemFlags[ i ] = item->GetFlags(); if( aCollector ) aCollector->Remove( item ); @@ -98,17 +98,17 @@ void WS_DATA_ITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aV m_drawItems.clear(); - for( int jj = 0; jj < m_RepeatCount; jj++ ) + for( int j = 0; j < m_RepeatCount; j++ ) { - if( jj && ! IsInsidePage( jj ) ) + if( j && ! IsInsidePage( j ) ) continue; if( m_type == WS_SEGMENT ) - item = new WS_DRAW_ITEM_LINE( this, GetStartPosUi( jj ), GetEndPosUi( jj ), pensize ); + item = new WS_DRAW_ITEM_LINE( this, j, GetStartPosUi( j ), GetEndPosUi( j ), pensize ); else if( m_type == WS_RECT ) - item = new WS_DRAW_ITEM_RECT( this, GetStartPosUi( jj ), GetEndPosUi( jj ), pensize ); + item = new WS_DRAW_ITEM_RECT( this, j, GetStartPosUi( j ), GetEndPosUi( j ), pensize ); - item->SetFlags( itemFlags[ jj ] ); + item->SetFlags( itemFlags[ j ] ); m_drawItems.push_back( item ); if( aCollector ) @@ -155,14 +155,10 @@ void WS_DATA_ITEM::MoveTo( DPOINT aPosition ) MoveStartPointTo( aPosition ); MoveEndPointTo( endpos ); - for( int jj = 0; jj < m_RepeatCount; jj++ ) + for( WS_DRAW_ITEM_BASE* drawItem : m_drawItems ) { - if( jj && !IsInsidePage( jj ) ) - continue; - - WS_DRAW_ITEM_BASE* drawItem = m_drawItems[ jj ]; - drawItem->SetPosition( GetStartPosUi( jj ) ); - drawItem->SetEnd( GetEndPosUi( jj ) ); + drawItem->SetPosition( GetStartPosUi( drawItem->GetIndexInPeer() ) ); + drawItem->SetEnd( GetEndPosUi( drawItem->GetIndexInPeer() ) ); } } @@ -405,10 +401,10 @@ void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX: std::map itemFlags; WS_DRAW_ITEM_BASE* item = nullptr; - for( size_t ii = 0; ii < m_drawItems.size(); ++ii ) + for( size_t i = 0; i < m_drawItems.size(); ++i ) { - item = m_drawItems[ ii ]; - itemFlags[ ii ] = item->GetFlags(); + item = m_drawItems[ i ]; + itemFlags[ i ] = item->GetFlags(); if( aCollector ) aCollector->Remove( item ); @@ -421,17 +417,17 @@ void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX: m_drawItems.clear(); - for( int jj = 0; jj < m_RepeatCount; jj++ ) + for( int j = 0; j < m_RepeatCount; j++ ) { - if( jj && !IsInsidePage( jj ) ) + if( j && !IsInsidePage( j ) ) continue; for( int kk = 0; kk < GetPolyCount(); kk++ ) { const bool fill = true; int pensize = GetPenSizeUi(); - auto poly = new WS_DRAW_ITEM_POLYGON( this, GetStartPosUi( jj ), fill, pensize ); - poly->SetFlags( itemFlags[ jj ] ); + auto poly = new WS_DRAW_ITEM_POLYGON( this, j, GetStartPosUi( j ), fill, pensize ); + poly->SetFlags( itemFlags[ j ] ); m_drawItems.push_back( poly ); if( aCollector ) @@ -445,7 +441,7 @@ void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX: unsigned iend = GetPolyIndexEnd( kk ); while( ist <= iend ) - poly->m_Corners.push_back( GetCornerPositionUi( ist++, jj ) ); + poly->m_Corners.push_back( GetCornerPositionUi( ist++, j ) ); } } } @@ -572,10 +568,10 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE std::map itemFlags; WS_DRAW_ITEM_TEXT* text = nullptr; - for( size_t ii = 0; ii < m_drawItems.size(); ++ii ) + for( size_t i = 0; i < m_drawItems.size(); ++i ) { - text = (WS_DRAW_ITEM_TEXT*) m_drawItems[ ii ]; - itemFlags[ ii ] = text->GetFlags(); + text = (WS_DRAW_ITEM_TEXT*) m_drawItems[ i ]; + itemFlags[ i ] = text->GetFlags(); if( aCollector ) aCollector->Remove( text ); @@ -588,14 +584,14 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE m_drawItems.clear(); - for( int jj = 0; jj < m_RepeatCount; ++jj ) + for( int j = 0; j < m_RepeatCount; ++j ) { - if( jj > 0 && !IsInsidePage( jj ) ) + if( j > 0 && !IsInsidePage( j ) ) continue; - text = new WS_DRAW_ITEM_TEXT( this, m_FullText, GetStartPosUi( jj ), textsize, pensize, + text = new WS_DRAW_ITEM_TEXT( this, j, m_FullText, GetStartPosUi( j ), textsize, pensize, m_Italic, m_Bold ); - text->SetFlags( itemFlags[ jj ] ); + text->SetFlags( itemFlags[ j ] ); m_drawItems.push_back( text ); if( aCollector ) @@ -611,7 +607,7 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE // Increment label for the next text (has no meaning for multiline texts) if( m_RepeatCount > 1 && !multilines ) - IncrementLabel( ( jj + 1 ) * m_IncrementLabel ); + IncrementLabel(( j + 1 ) * m_IncrementLabel ); } } @@ -702,7 +698,7 @@ void WS_DATA_ITEM_TEXT::SetConstrainedTextSize() int linewidth = 0; size_micron.x = KiROUND( m_ConstrainedTextSize.x * FSCALE ); size_micron.y = KiROUND( m_ConstrainedTextSize.y * FSCALE ); - WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, this->m_FullText, wxPoint( 0, 0 ), + WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, 0, this->m_FullText, wxPoint( 0, 0 ), size_micron, linewidth, m_Italic, m_Bold ) ); dummy.SetMultilineAllowed( true ); dummy.SetHorizJustify( m_Hjustify ) ; @@ -728,10 +724,10 @@ void WS_DATA_ITEM_BITMAP::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::V std::map itemFlags; WS_DRAW_ITEM_BASE* item = nullptr; - for( size_t ii = 0; ii < m_drawItems.size(); ++ii ) + for( size_t i = 0; i < m_drawItems.size(); ++i ) { - item = m_drawItems[ ii ]; - itemFlags[ ii ] = item->GetFlags(); + item = m_drawItems[ i ]; + itemFlags[ i ] = item->GetFlags(); if( aCollector ) aCollector->Remove( item ); @@ -744,13 +740,13 @@ void WS_DATA_ITEM_BITMAP::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::V m_drawItems.clear(); - for( int jj = 0; jj < m_RepeatCount; jj++ ) + for( int j = 0; j < m_RepeatCount; j++ ) { - if( jj && !IsInsidePage( jj ) ) + if( j && !IsInsidePage( j ) ) continue; - auto bitmap = new WS_DRAW_ITEM_BITMAP( this, GetStartPosUi( jj ) ); - bitmap->SetFlags( itemFlags[ jj ] ); + auto bitmap = new WS_DRAW_ITEM_BITMAP( this, j, GetStartPosUi( j ) ); + bitmap->SetFlags( itemFlags[ j ] ); m_drawItems.push_back( bitmap ); if( aCollector ) diff --git a/common/page_layout/ws_data_model_io.cpp b/common/page_layout/ws_data_model_io.cpp index 3389fe802f..701b1e0d7a 100644 --- a/common/page_layout/ws_data_model_io.cpp +++ b/common/page_layout/ws_data_model_io.cpp @@ -155,6 +155,15 @@ void WS_DATA_MODEL::SaveInString( wxString& aOutputString ) } +void WS_DATA_MODEL::SaveInString( std::vector aItemsList, wxString& aOutputString ) +{ + WS_DATA_MODEL_STRINGIO writer( aOutputString ); + + for( WS_DATA_ITEM* item : aItemsList ) + writer.Format( this, item, 0 ); +} + + void WS_DATA_MODEL_IO::Format( WS_DATA_MODEL* aModel, WS_DATA_ITEM* aItem, int aNestLevel ) const { switch( aItem->GetType() ) diff --git a/include/ws_data_model.h b/include/ws_data_model.h index 0b1840ae63..173f159f88 100644 --- a/include/ws_data_model.h +++ b/include/ws_data_model.h @@ -123,6 +123,11 @@ public: */ void SaveInString( wxString& aOutputString ); + /** + * Fill the given string with an S-expr serialization of the WS_DATA_ITEMs + */ + void SaveInString( std::vector aItemsList, wxString& aOutputString ); + void Append( WS_DATA_ITEM* aItem ); void Remove( WS_DATA_ITEM* aItem ); diff --git a/include/ws_draw_item.h b/include/ws_draw_item.h index 9c1f976019..46d65e648a 100644 --- a/include/ws_draw_item.h +++ b/include/ws_draw_item.h @@ -49,11 +49,13 @@ class WS_DRAW_ITEM_BASE : public EDA_ITEM // This basic class, not directly { protected: WS_DATA_ITEM* m_peer; // the parent WS_DATA_ITEM item in the WS_DATA_MODEL + int m_index; // the index in the parent's repeat count - WS_DRAW_ITEM_BASE( WS_DATA_ITEM* aPeer, KICAD_T aType ) : + WS_DRAW_ITEM_BASE( WS_DATA_ITEM* aPeer, int aIndex, KICAD_T aType ) : EDA_ITEM( aType ) { m_peer = aPeer; + m_index = aIndex; m_Flags = 0; } @@ -61,6 +63,7 @@ public: virtual ~WS_DRAW_ITEM_BASE() {} WS_DATA_ITEM* GetPeer() const { return m_peer; } + int GetIndexInPeer() const { return m_index; } void ViewGetLayers( int aLayers[], int& aCount ) const override; @@ -104,8 +107,9 @@ class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE int m_penWidth; public: - WS_DRAW_ITEM_LINE( WS_DATA_ITEM* aPeer, wxPoint aStart, wxPoint aEnd, int aPenWidth ) : - WS_DRAW_ITEM_BASE( aPeer, WSG_LINE_T ) + WS_DRAW_ITEM_LINE( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd, + int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_LINE_T ) { m_start = aStart; m_end = aEnd; @@ -150,8 +154,9 @@ public: std::vector m_Corners; public: - WS_DRAW_ITEM_POLYGON( WS_DATA_ITEM* aPeer, wxPoint aPos, bool aFill, int aPenWidth ) : - WS_DRAW_ITEM_BASE( aPeer, WSG_POLY_T ) + WS_DRAW_ITEM_POLYGON( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos, bool aFill, + int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_POLY_T ) { m_penWidth = aPenWidth; m_fill = aFill; @@ -188,8 +193,9 @@ class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_BASE int m_penWidth; public: - WS_DRAW_ITEM_RECT( WS_DATA_ITEM* aPeer, wxPoint aStart, wxPoint aEnd, int aPenWidth ) : - WS_DRAW_ITEM_BASE( aPeer, WSG_RECT_T ) + WS_DRAW_ITEM_RECT( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd, + int aPenWidth ) : + WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_RECT_T ) { m_start = aStart; m_end = aEnd; @@ -227,9 +233,9 @@ public: class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT { public: - WS_DRAW_ITEM_TEXT( WS_DATA_ITEM* aPeer, wxString& aText, wxPoint aPos, wxSize aSize, - int aPenWidth, bool aItalic = false, bool aBold = false ) : - WS_DRAW_ITEM_BASE( aPeer, WSG_TEXT_T), + WS_DRAW_ITEM_TEXT( WS_DATA_ITEM* aPeer, int aIndex, wxString& aText, wxPoint aPos, + wxSize aSize, int aPenWidth, bool aItalic = false, bool aBold = false ) : + WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_TEXT_T), EDA_TEXT( aText ) { SetTextPos( aPos ); @@ -274,17 +280,12 @@ class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE wxPoint m_pos; // position of reference point public: - WS_DRAW_ITEM_BITMAP( WS_DATA_ITEM* aPeer, wxPoint aPos ) : - WS_DRAW_ITEM_BASE( aPeer, WSG_BITMAP_T ) + WS_DRAW_ITEM_BITMAP( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos ) : + WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_BITMAP_T ) { m_pos = aPos; } - WS_DRAW_ITEM_BITMAP() : - WS_DRAW_ITEM_BASE( nullptr, WSG_BITMAP_T ) - { - } - ~WS_DRAW_ITEM_BITMAP() {} virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_BITMAP" ); } diff --git a/include/ws_proxy_undo_item.h b/include/ws_proxy_undo_item.h index 8173d0ce97..a27ca4e89e 100644 --- a/include/ws_proxy_undo_item.h +++ b/include/ws_proxy_undo_item.h @@ -32,7 +32,7 @@ class WS_PROXY_UNDO_ITEM : public EDA_ITEM { public: - explicit WS_PROXY_UNDO_ITEM( const EDA_DRAW_FRAME* aFrame ); + WS_PROXY_UNDO_ITEM( const EDA_DRAW_FRAME* aFrame ); /* * Restores the saved worksheet layout to the global worksheet record, and the saved diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index ece7e0b0f9..9868af5126 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -79,6 +79,11 @@ static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELET // Common: hotkeys_basic.h static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO ); static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO ); + +static EDA_HOTKEY HkCut( _HKI( "Cut" ), HK_CUT, GR_KB_CTRL + 'X' ); +static EDA_HOTKEY HkCopy( _HKI( "Copy" ), HK_COPY, GR_KB_CTRL + 'C' ); +static EDA_HOTKEY HkPaste( _HKI( "Paste" ), HK_PASTE, GR_KB_CTRL + 'V' ); + static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N', (int) wxID_NEW ); static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O', (int) wxID_OPEN ); static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S', (int) wxID_SAVE ); @@ -90,13 +95,13 @@ static EDA_HOTKEY HkPreferences( _HKI( "Preferences" ), HK_PREFERENCES, GR_KB_CT // List of common hotkey descriptors EDA_HOTKEY* s_Common_Hotkey_List[] = { - &HkNew, &HkOpen, &HkSave, &HkSaveAs, &HkPrint, - &HkUndo, &HkRedo, - &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter, - &HkZoomAuto, &HkZoomSelection, &HkResetLocalCoord, - &HkHelp, &HkPreferences, - &HkMouseLeftClick, - &HkMouseLeftDClick, + &HkNew, &HkOpen, &HkSave, &HkSaveAs, &HkPrint, + &HkUndo, &HkRedo, + &HkCut, &HkCopy, &HkPaste, &HkDeleteItem, + &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter, + &HkZoomAuto, &HkZoomSelection, &HkResetLocalCoord, + &HkHelp, &HkPreferences, + &HkMouseLeftClick, &HkMouseLeftDClick, NULL }; diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index c27b7055fa..4cc4f38cb4 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -57,8 +57,6 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() if( openRecentMenu ) Kiface().GetFileHistory().RemoveMenu( openRecentMenu ); - // Recreate all menus: - // // File Menu: // @@ -98,11 +96,17 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() auto enableRedoCondition = [ this ] ( const SELECTION& sel ) { return GetScreen() && GetScreen()->GetRedoCommandCount() != 0; }; + auto idleCondition = [] ( const SELECTION& sel ) { + return !sel.Front() || sel.Front()->GetEditFlags() == 0; + }; editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); editMenu->AddItem( ACTIONS::redo, enableRedoCondition ); editMenu->AddSeparator(); + editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::MoreThan( 0 ) ); + editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::MoreThan( 0 ) ); + editMenu->AddItem( ACTIONS::paste, idleCondition ); editMenu->AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::MoreThan( 0 ) ); // diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 432da00445..1da0b27ac0 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -88,6 +88,9 @@ bool PL_EDIT_TOOL::Init() // CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); + selToolMenu.AddItem( PL_ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( PL_ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( PL_ACTIONS::paste, SELECTION_CONDITIONS::ShowAlways, 200 ); selToolMenu.AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 ); return true; @@ -276,9 +279,7 @@ void PL_EDIT_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ) for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() ) { - // Remove/add is better than update as it handles rtree re-adjustment - getView()->Remove( item ); - getView()->Add( item ); + getView()->Update( item ); item->SetFlags( IS_MOVED ); } } @@ -295,7 +296,7 @@ bool PL_EDIT_TOOL::updateModificationPoint( SELECTION& aSelection ) WS_DRAW_ITEM_BASE* item = static_cast( aSelection.Front() ); aSelection.SetReferencePoint( item->GetPosition() ); } - // ...otherwise modify items with regard to the grid-snapped cursor position + // ...otherwise modify items with regard to the grid-snapped cursor position else { m_cursor = getViewControls()->GetCursorPosition( true ); @@ -398,14 +399,92 @@ int PL_EDIT_TOOL::Redo( const TOOL_EVENT& aEvent ) } +int PL_EDIT_TOOL::Cut( const TOOL_EVENT& aEvent ) +{ + int retVal = Copy( aEvent ); + + if( retVal == 0 ) + retVal = DoDelete( aEvent ); + + return retVal; +} + + +int PL_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent ) +{ + SELECTION& selection = m_selectionTool->RequestSelection(); + std::vector items; + WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance(); + wxString sexpr; + + if( selection.GetSize() == 0 ) + return 0; + + for( EDA_ITEM* item : selection.GetItems() ) + items.push_back( static_cast( item )->GetPeer() ); + + try + { + model.SaveInString( items, sexpr ); + } + catch( const IO_ERROR& ioe ) + { + wxMessageBox( ioe.What(), _( "Error writing objects to clipboard" ) ); + } + + if( m_toolMgr->SaveClipboard( TO_UTF8( sexpr ) ) ) + return 0; + else + return -1; +} + + +int PL_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) +{ + SELECTION& selection = m_selectionTool->GetSelection(); + WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance(); + std::string sexpr = m_toolMgr->GetClipboard(); + + m_selectionTool->ClearSelection(); + + model.SetPageLayout( sexpr.c_str(), true, wxT( "clipboard" ) ); + + // Build out draw items and select the first of each data item + for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() ) + { + if( dataItem->GetDrawItems().empty() ) + { + dataItem->SyncDrawItems( nullptr, getView() ); + dataItem->GetDrawItems().front()->SetSelected(); + } + } + + m_selectionTool->RebuildSelection(); + + if( !selection.Empty() ) + { + WS_DRAW_ITEM_BASE* item = (WS_DRAW_ITEM_BASE*) selection.GetTopLeftItem(); + + selection.SetReferencePoint( item->GetPosition() ); + m_toolMgr->RunAction( PL_ACTIONS::move, false ); + } + + return 0; +} + + void PL_EDIT_TOOL::setTransitions() { Go( &PL_EDIT_TOOL::Main, PL_ACTIONS::move.MakeEvent() ); Go( &PL_EDIT_TOOL::ImportWorksheetContent, PL_ACTIONS::appendImportedWorksheet.MakeEvent() ); - Go( &PL_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() ); Go( &PL_EDIT_TOOL::DeleteItemCursor, PL_ACTIONS::deleteItemCursor.MakeEvent() ); Go( &PL_EDIT_TOOL::Undo, ACTIONS::undo.MakeEvent() ); Go( &PL_EDIT_TOOL::Redo, ACTIONS::redo.MakeEvent() ); + + Go( &PL_EDIT_TOOL::Cut, ACTIONS::cut.MakeEvent() ); + Go( &PL_EDIT_TOOL::Copy, ACTIONS::copy.MakeEvent() ); + Go( &PL_EDIT_TOOL::Paste, ACTIONS::paste.MakeEvent() ); + Go( &PL_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() ); } diff --git a/pagelayout_editor/tools/pl_edit_tool.h b/pagelayout_editor/tools/pl_edit_tool.h index 064866de7c..b74d5238c3 100644 --- a/pagelayout_editor/tools/pl_edit_tool.h +++ b/pagelayout_editor/tools/pl_edit_tool.h @@ -50,6 +50,10 @@ public: int Undo( const TOOL_EVENT& aEvent ); int Redo( const TOOL_EVENT& aEvent ); + int Cut( const TOOL_EVENT& aEvent ); + int Copy( const TOOL_EVENT& aEvent ); + int Paste( const TOOL_EVENT& aEvent ); + int ImportWorksheetContent( const TOOL_EVENT& aEvent ); /**