mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 19:21:41 +00:00
Cut/copy/paste for PlEditor.
This commit is contained in:
parent
6936effaa7
commit
21c216556b
common/page_layout
include
pagelayout_editor
@ -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() )
|
||||
{
|
||||
|
@ -82,10 +82,10 @@ void WS_DATA_ITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aV
|
||||
std::map<int, STATUS_FLAGS> 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<int, STATUS_FLAGS> 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<int, STATUS_FLAGS> 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<int, STATUS_FLAGS> 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 )
|
||||
|
@ -155,6 +155,15 @@ void WS_DATA_MODEL::SaveInString( wxString& aOutputString )
|
||||
}
|
||||
|
||||
|
||||
void WS_DATA_MODEL::SaveInString( std::vector<WS_DATA_ITEM*> 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() )
|
||||
|
@ -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<WS_DATA_ITEM*> aItemsList, wxString& aOutputString );
|
||||
|
||||
void Append( WS_DATA_ITEM* aItem );
|
||||
void Remove( WS_DATA_ITEM* aItem );
|
||||
|
||||
|
@ -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 <wxPoint> 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" ); }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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 ) );
|
||||
|
||||
//
|
||||
|
@ -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<WS_DRAW_ITEM_BASE*>( 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<WS_DATA_ITEM*> 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<WS_DRAW_ITEM_BASE*>( 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() );
|
||||
}
|
||||
|
@ -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 );
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user