diff --git a/common/class_undoredo_container.cpp b/common/class_undoredo_container.cpp index 5d51e2216c..e56d765139 100644 --- a/common/class_undoredo_container.cpp +++ b/common/class_undoredo_container.cpp @@ -102,7 +102,7 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() { case UR_UNSPECIFIED: if( show_error_message ) - wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) ); + wxMessageBox( wxT( "ClearListAndDeleteItems() error: UR_UNSPECIFIED command type" ) ); show_error_message = false; break; diff --git a/common/page_layout/page_layout_reader.cpp b/common/page_layout/page_layout_reader.cpp index 6d55ce10dc..d87fa8fccf 100644 --- a/common/page_layout/page_layout_reader.cpp +++ b/common/page_layout/page_layout_reader.cpp @@ -638,6 +638,28 @@ void WORKSHEET_LAYOUT::SetDefaultLayout() } } +/** + * Populates the list from a S expr description stored in a string + * @param aPageLayout = the S expr string + */ +void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append ) +{ + if( ! Append ) + ClearList(); + + PAGE_LAYOUT_READER_PARSER lp_parser( aPageLayout, wxT( "Sexpr_string" ) ); + + try + { + lp_parser.Parse( this ); + SetDefaultDescrFlag( true ); + } + catch( IO_ERROR ioe ) + { + wxLogMessage( ioe.errorText ); + } +} + #include // SetLayout() try to load a custom layout file, diff --git a/include/base_struct.h b/include/base_struct.h index 40eb7fcaff..0b3e15a899 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -134,6 +134,11 @@ enum KICAD_T { */ TYPE_GERBER_DRAW_ITEM, + /* + * for Pl_Editor, in undo/redo commands + */ + TYPE_PL_EDITOR_LAYOUT, + // End value MAX_STRUCT_TYPE_ID }; diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index 2e0ffaac94..753887f72d 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -531,11 +531,17 @@ public: void ClearList(); /** - * Function Save: + * Save the description in a file * @param aFullFileName the filename of the file to created */ void Save( const wxString& aFullFileName ); + /** + * Save the description in a buffer + * @param aOutputString = a wxString to store the S expr string + */ + void SaveInString( wxString& aOutputString ); + /** * Add an item to the list of items */ @@ -591,6 +597,12 @@ public: void SetPageLayout( const wxString& aFullFileName = wxEmptyString, bool Append = false ); + /** + * Populates the list from a S expr description stored in a string + * @param aPageLayout = the S expr string + */ + void SetPageLayout( const char* aPageLayout, bool Append = false ); + /** * @return a short filename from a full filename: * if the path is the current path, or if the path diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index 90e0cfce6f..eecc08abd6 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -33,6 +33,7 @@ set(PL_EDITOR_SRCS pl_editor.cpp pl_editor_config.cpp pl_editor_frame.cpp + pl_editor_undo_redo.cpp properties_frame.cpp hotkeys.cpp menubar.cpp diff --git a/pagelayout_editor/class_pl_editor_screen.cpp b/pagelayout_editor/class_pl_editor_screen.cpp index 7c4ed73698..65df628ffb 100644 --- a/pagelayout_editor/class_pl_editor_screen.cpp +++ b/pagelayout_editor/class_pl_editor_screen.cpp @@ -86,9 +86,27 @@ int PL_EDITOR_SCREEN::MilsToIuScalar() /* Virtual function needed by classes derived from BASE_SCREEN * this is a virtual pure function in BASE_SCREEN - * do nothing in GerbView - * could be removed later */ -void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int ) +void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, + int aItemCount ) { + if( aItemCount == 0 ) + return; + + unsigned icnt = aList.m_CommandsList.size(); + + if( aItemCount > 0 ) + icnt = aItemCount; + + for( unsigned ii = 0; ii < icnt; ii++ ) + { + if( aList.m_CommandsList.size() == 0 ) + break; + + PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; + aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); + + curr_cmd->ClearListAndDeleteItems(); + delete curr_cmd; // Delete command + } } diff --git a/pagelayout_editor/design_tree_frame.cpp b/pagelayout_editor/design_tree_frame.cpp index 86873e09e9..74fb9c1b28 100644 --- a/pagelayout_editor/design_tree_frame.cpp +++ b/pagelayout_editor/design_tree_frame.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -172,6 +173,8 @@ wxSize DESIGN_TREE_FRAME::GetMinSize() const void DESIGN_TREE_FRAME::ReCreateDesignTree() { + wxWindowUpdateLocker dummy(this); // Avoid flicker when rebuilding the tree + DeleteAllItems(); const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); diff --git a/pagelayout_editor/dialogs/properties_frame_base.cpp b/pagelayout_editor/dialogs/properties_frame_base.cpp index ccf1dab360..bd12ffdd3f 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.cpp +++ b/pagelayout_editor/dialogs/properties_frame_base.cpp @@ -68,8 +68,8 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c m_staticTextText->Wrap( -1 ); m_SizerTextOptions->Add( m_staticTextText, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_textCtrlText = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - m_SizerTextOptions->Add( m_textCtrlText, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + m_textCtrlText = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); + m_SizerTextOptions->Add( m_textCtrlText, 1, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); wxBoxSizer* bSizerFontOpt; bSizerFontOpt = new wxBoxSizer( wxVERTICAL ); @@ -515,6 +515,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneralOpts->Add( bSizerGeneralOpts1, 0, 0, 5 ); + m_buttonDefault = new wxButton( m_swGeneralOpts, wxID_ANY, _("Set to Default"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGeneralOpts->Add( m_buttonDefault, 0, wxALL|wxEXPAND, 5 ); + m_staticline9 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); bSizerGeneralOpts->Add( m_staticline9, 0, wxEXPAND | wxALL, 5 ); @@ -592,16 +595,10 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c bSizerGeneralOpts->Add( bSizerGeneraMargins, 0, 0, 5 ); - m_staticline10 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bSizerGeneralOpts->Add( m_staticline10, 0, wxEXPAND | wxALL, 5 ); - m_buttonGeneralOptsOK = new wxButton( m_swGeneralOpts, wxID_ANY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonGeneralOptsOK->SetDefault(); bSizerGeneralOpts->Add( m_buttonGeneralOptsOK, 0, wxALL|wxEXPAND, 5 ); - m_buttonDefault = new wxButton( m_swGeneralOpts, wxID_ANY, _("Set to Default"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizerGeneralOpts->Add( m_buttonDefault, 0, wxALL|wxEXPAND, 5 ); - m_swGeneralOpts->SetSizer( bSizerGeneralOpts ); m_swGeneralOpts->Layout(); @@ -616,15 +613,15 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c // Connect Events m_buttonOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); - m_buttonGeneralOptsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); m_buttonDefault->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this ); + m_buttonGeneralOptsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); } PANEL_PROPERTIES_BASE::~PANEL_PROPERTIES_BASE() { // Disconnect Events m_buttonOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); - m_buttonGeneralOptsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); m_buttonDefault->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this ); + m_buttonGeneralOptsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); } diff --git a/pagelayout_editor/dialogs/properties_frame_base.fbp b/pagelayout_editor/dialogs/properties_frame_base.fbp index 8247da5d23..7e6b956090 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.fbp +++ b/pagelayout_editor/dialogs/properties_frame_base.fbp @@ -40,7 +40,7 @@ PANEL_PROPERTIES_BASE - 315,739 + 315,782 @@ -802,7 +802,7 @@ 5 wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND - 0 + 1 1 1 @@ -849,7 +849,7 @@ Resizable 1 - + wxTE_MULTILINE 0 @@ -6373,6 +6373,94 @@ + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Set to Default + + 0 + + + 0 + + 1 + m_buttonDefault + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnSetDefaultValues + + + + + + + + + + + + + + + + + + + + + + + + + 5 wxEXPAND | wxALL @@ -7310,87 +7398,6 @@ - - 5 - wxEXPAND | wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_staticline10 - 1 - - - protected - 1 - - Resizable - 1 - - wxLI_HORIZONTAL - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 wxALL|wxEXPAND @@ -7479,94 +7486,6 @@ - - 5 - wxALL|wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Set to Default - - 0 - - - 0 - - 1 - m_buttonDefault - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnSetDefaultValues - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pagelayout_editor/dialogs/properties_frame_base.h b/pagelayout_editor/dialogs/properties_frame_base.h index 6615712902..922ae56df1 100644 --- a/pagelayout_editor/dialogs/properties_frame_base.h +++ b/pagelayout_editor/dialogs/properties_frame_base.h @@ -113,6 +113,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel wxTextCtrl* m_textCtrlDefaultLineWidth; wxStaticText* m_staticText22; wxTextCtrl* m_textCtrlDefaultTextThickness; + wxButton* m_buttonDefault; wxStaticLine* m_staticline9; wxStaticText* m_staticTextMargins; wxStaticText* m_staticTextLeftMargin; @@ -123,9 +124,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel wxTextCtrl* m_textCtrlTopMargin; wxStaticText* m_staticTextBottomMargin; wxTextCtrl* m_textCtrlDefaultBottomMargin; - wxStaticLine* m_staticline10; wxButton* m_buttonGeneralOptsOK; - wxButton* m_buttonDefault; // Virtual event handlers, overide them in your derived class virtual void OnAcceptPrms( wxCommandEvent& event ) { event.Skip(); } @@ -134,7 +133,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel public: - PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 315,739 ), long style = wxTAB_TRAVERSAL ); + PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 315,782 ), long style = wxTAB_TRAVERSAL ); ~PANEL_PROPERTIES_BASE(); }; diff --git a/pagelayout_editor/events_functions.cpp b/pagelayout_editor/events_functions.cpp index d76f73edfe..bf65fd48f9 100644 --- a/pagelayout_editor/events_functions.cpp +++ b/pagelayout_editor/events_functions.cpp @@ -61,8 +61,8 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) EVT_MENU( wxID_ABOUT, EDA_DRAW_FRAME::GetKicadAbout ) EVT_TOOL( wxID_CUT, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( wxID_UNDO, PL_EDITOR_FRAME::Process_Special_Functions ) - EVT_TOOL( wxID_REDO, PL_EDITOR_FRAME::Process_Special_Functions ) + EVT_TOOL( wxID_UNDO, PL_EDITOR_FRAME::GetLayoutFromUndoList ) + EVT_TOOL( wxID_REDO, PL_EDITOR_FRAME::GetLayoutFromRedoList ) EVT_TOOL( wxID_PRINT, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( wxID_PREVIEW, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( ID_SHEET_SET, PL_EDITOR_FRAME::Process_Special_Functions ) @@ -99,7 +99,6 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) { case ID_NO_TOOL_SELECTED: SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); - break; case ID_SELECT_PAGE_NUMBER: m_canvas->Refresh(); @@ -129,6 +128,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) if( item == NULL ) break; + SaveCopyInUndoList(); idx = pglayout.GetItemIndex( item ); pglayout.Remove( item ); RebuildDesignTree(); @@ -147,10 +147,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_ITEM_ADD_LINE: + SaveCopyInUndoList(); idx = m_treePagelayout->GetSelectedItemIndex(); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx ); if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) { + RemoveLastCommandInUndoList(); pglayout.Remove( item ); RebuildDesignTree(); item = NULL; @@ -159,10 +161,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_ITEM_ADD_RECT: + SaveCopyInUndoList(); idx = m_treePagelayout->GetSelectedItemIndex(); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx ); if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) { + RemoveLastCommandInUndoList(); pglayout.Remove( item ); RebuildDesignTree(); item = NULL; @@ -171,10 +175,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_ITEM_ADD_TEXT: + SaveCopyInUndoList(); idx = m_treePagelayout->GetSelectedItemIndex(); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx ); if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) { + RemoveLastCommandInUndoList(); pglayout.Remove( item ); RebuildDesignTree(); item = NULL; @@ -189,8 +195,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_ITEM_PLACE: item = GetScreen()->GetCurItem(); - m_canvas->SetMouseCapture( NULL, NULL ); - GetScreen()->SetCurItem( NULL ); + PlaceItem( item ); break; case ID_POPUP_ITEM_PLACE_CANCEL: @@ -245,19 +250,19 @@ static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositio WORKSHEET_DATAITEM *item = screen->GetCurItem(); wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) ); - - wxPoint newpos = screen->GetCrossHairPosition() + wxPoint position = screen->GetCrossHairPosition() - ( initialCursorPosition - initialPositionUi ); if( (item->GetFlags() & LOCATE_STARTPOINT) ) - item->MoveStartPointToUi( newpos ); + item->MoveStartPointToUi( position ); else if( (item->GetFlags() & LOCATE_ENDPOINT) ) - item->MoveEndPointToUi( newpos ); + item->MoveEndPointToUi( position ); else - item->MoveToUi( newpos ); + item->MoveToUi( position ); // Draw the item item at it's new position. - aPanel->Refresh(); + if( aPanel ) + aPanel->Refresh(); } static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) @@ -312,6 +317,38 @@ void PL_EDITOR_FRAME::MoveItem( WORKSHEET_DATAITEM* aItem ) GetScreen()->SetCurItem( aItem ); } +/** +* Save in Undo list the layout, and place an item being moved. +* @param aItem is the item moved +*/ +void PL_EDITOR_FRAME::PlaceItem( WORKSHEET_DATAITEM* aItem ) +{ + DPOINT currStartPos = aItem->GetStartPos(); + DPOINT currEndPos = aItem->GetEndPos(); + + // Save the curren layout before changes + if( (aItem->GetFlags() & LOCATE_STARTPOINT) ) + { + aItem->MoveStartPointTo( initialPosition ); + } + else if( (aItem->GetFlags() & LOCATE_ENDPOINT) ) + { + aItem->MoveEndPointTo( initialPosition ); + } + else + aItem->MoveTo( initialPosition ); + + SaveCopyInUndoList(); + + // Re-place the item + aItem->MoveStartPointTo( currStartPos ); + aItem->MoveEndPointTo( currEndPos ); + + m_canvas->SetMouseCapture( NULL, NULL ); + GetScreen()->SetCurItem( NULL ); +} + + /* called when the user select one of the 4 page corner as corner * reference (or the left top paper corner) */ diff --git a/pagelayout_editor/files.cpp b/pagelayout_editor/files.cpp index 7c5f2c9de4..0f7ca6c27b 100644 --- a/pagelayout_editor/files.cpp +++ b/pagelayout_editor/files.cpp @@ -233,6 +233,7 @@ bool PL_EDITOR_FRAME::InsertPageLayoutDescrFile( const wxString& aFullFileName ) if( wxFileExists( aFullFileName ) ) { const bool append = true; + SaveCopyInUndoList(); WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName, append ); return true; } diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index 6bc2aa4cc9..a0ba6da265 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -75,8 +75,8 @@ static EDA_HOTKEY HkDeleteItem( wxT( "Move Item" ), HK_DELETE_ITEM, WXK_DELET ID_POPUP_ITEM_DELETE ); // Undo Redo -//static EDA_HOTKEY HkUndo( wxT( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO ); -//static EDA_HOTKEY HkRedo( wxT( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO ); +static EDA_HOTKEY HkUndo( wxT( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO ); +static EDA_HOTKEY HkRedo( wxT( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO ); // List of common hotkey descriptors EDA_HOTKEY* s_Common_Hotkey_List[] = @@ -84,13 +84,15 @@ EDA_HOTKEY* s_Common_Hotkey_List[] = &HkHelp, &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter, &HkZoomAuto, &HkResetLocalCoord, + &HkUndo, &HkRedo, NULL }; EDA_HOTKEY* s_PlEditor_Hotkey_List[] = { &HkMoveItem, &HkMoveStartPoint, - &HkMoveEndPoint, &HkDeleteItem + &HkMoveEndPoint, &HkDeleteItem, + NULL }; // list of sections and corresponding hotkey list for Pl_Editor @@ -144,6 +146,14 @@ void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, DisplayHotkeyList( this, s_PlEditor_Hokeys_Descr ); break; + case HK_UNDO: + case HK_REDO: + if( busy ) + break; + cmd.SetId( HK_Descr->m_IdMenuEvent ); + GetEventHandler()->ProcessEvent( cmd ); + break; + case HK_ZOOM_IN: cmd.SetId( ID_POPUP_ZOOM_IN ); GetEventHandler()->ProcessEvent( cmd ); diff --git a/pagelayout_editor/onleftclick.cpp b/pagelayout_editor/onleftclick.cpp index 1f3ba01981..6f8ba57e94 100644 --- a/pagelayout_editor/onleftclick.cpp +++ b/pagelayout_editor/onleftclick.cpp @@ -49,9 +49,8 @@ void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( item ) // An item is currently in edit: place it { + PlaceItem( item ); m_propertiesPagelayout->CopyPrmsFromItemToPanel( item ); - m_canvas->SetMouseCapture( NULL, NULL ); - GetScreen()->SetCurItem( NULL ); m_canvas->Refresh(); return; } diff --git a/pagelayout_editor/page_layout_writer.cpp b/pagelayout_editor/page_layout_writer.cpp index cd57401ac3..4e888c3fe1 100644 --- a/pagelayout_editor/page_layout_writer.cpp +++ b/pagelayout_editor/page_layout_writer.cpp @@ -137,8 +137,8 @@ public: } }; -/** - * Function Save: aFullFileName = the filename of the file to created +/* + * Save the description in a file */ void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName ) { @@ -146,6 +146,14 @@ void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName ) writer.Format( this ); } +/* Save the description in a buffer + */ +void WORKSHEET_LAYOUT::SaveInString( wxString& aOutputString ) +{ + WORKSHEET_LAYOUT_STRINGIO writer( aOutputString ); + writer.Format( this ); +} + void WORKSHEET_LAYOUT_IO::Format( WORKSHEET_DATAITEM* aItem, int aNestLevel ) const throw( IO_ERROR ) diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index c2c1407871..5d8b36f052 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -408,31 +408,22 @@ void PL_EDITOR_FRAME::UpdateStatusBar() double dXpos = To_User_Unit( g_UserUnit, coord.x*Xsign ); double dYpos = To_User_Unit( g_UserUnit, coord.y*Ysign ); - wxString pagesizeformatter; - wxString absformatter; - wxString locformatter; + wxString pagesizeformatter = wxT( "Page size: width %.4g height %.4g" ); + wxString absformatter = wxT( "X %.4g Y %.4g" ); + wxString locformatter = wxT( "dx %.4g dy %.4g" ); switch( g_UserUnit ) { case INCHES: // Should not be used in page layout editor SetStatusText( _("inches"), 5 ); - pagesizeformatter = wxT( "Page size: width %4g height %4g" ); - absformatter = wxT( "X %.4g Y %.4g" ); - locformatter = wxT( "dx %.4g dy %.4g" ); break; case MILLIMETRES: SetStatusText( _("mm"), 5 ); - pagesizeformatter = wxT( "Page size: width %3g height %3g" ); - absformatter = wxT( "X %.3g Y %.3g" ); - locformatter = wxT( "dx %.3g dy %.3g" ); break; case UNSCALED_UNITS: SetStatusText( wxEmptyString, 5 ); - pagesizeformatter = wxT( "Page size: width %g height %g" ); - absformatter = wxT( "X %g Y %g" ); - locformatter = wxT( "dx %g dy %g" ); break; } @@ -687,6 +678,7 @@ WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition ) */ void PL_EDITOR_FRAME::OnNewPageLayout() { + GetScreen()->ClearUndoRedoList(); GetScreen()->ClrModify(); m_propertiesPagelayout->CopyPrmsFromGeneralToPanel(); RebuildDesignTree(); diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 22b8c70f0c..8b1e85c72f 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -326,6 +326,12 @@ public: */ void MoveItem( WORKSHEET_DATAITEM* aItem ); + /** + * Save in Undo list the layout, and place an item being moved. + * @param aItem is the item moved + */ + void PlaceItem( WORKSHEET_DATAITEM* aItem ); + /** * Must be called after a change * in order to set the "modify" flag of the current screen @@ -335,6 +341,29 @@ public: GetScreen()->SetModify(); } + /** + * Save a copy of the description (in a S expr string) + * for Undo/redo commands + */ + void SaveCopyInUndoList(); + + /** Redo the last edition: + * - Place the current edited layout in undo list + * - Get the previous version of the current edited layput + */ + void GetLayoutFromRedoList( wxCommandEvent& event ); + + /** Undo the last edition: + * - Place the current layout in Redo list + * - Get the previous version of the current edited layout + */ + void GetLayoutFromUndoList( wxCommandEvent& event ); + + /** + * Remove the last command in Undo List. + * Used to clean the Undo stack after a cancel command + */ + void RemoveLastCommandInUndoList(); DECLARE_EVENT_TABLE() }; diff --git a/pagelayout_editor/properties_frame.cpp b/pagelayout_editor/properties_frame.cpp index d9db9c4475..db700d1d4e 100644 --- a/pagelayout_editor/properties_frame.cpp +++ b/pagelayout_editor/properties_frame.cpp @@ -194,7 +194,9 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) m_SizerTextIncrementLabel->Show( true ); WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem; - m_textCtrlText->SetValue( item->m_TextBase ); + wxString text = item->m_TextBase; + text.Replace(wxT("\\n"), wxT("\n") ); + m_textCtrlText->SetValue( text ); msg.Printf( wxT("%d"), item->m_IncrementLabel ); m_textCtrlTextIncrement->SetValue( msg ); @@ -279,6 +281,8 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) // Event function called by clicking on the OK button void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event ) { + m_parent->SaveCopyInUndoList(); + WORKSHEET_DATAITEM* item = m_parent->GetSelectedItem(); if( item ) CopyPrmsFromPanelToItem( item ); @@ -388,6 +392,7 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem; item->m_TextBase = m_textCtrlText->GetValue(); + item->m_TextBase.Replace( wxT("\n"), wxT("\\n") ); msg = m_textCtrlTextIncrement->GetValue(); msg.ToLong( &itmp );