--- Orig/chart2/source/controller/main/ChartController.cxx 2007-08-07 14:16:18.000000000 +0800 +++ new/chart2/source/controller/main/ChartController.cxx 2007-08-15 11:50:42.000000000 +0800 @@ -1239,7 +1239,7 @@ uno::Reference< XDataSeries > xGivenDataSeries( ObjectIdentifier::getDataSeriesForCID( //yyy todo also legendentries and labels? aObjectCID, m_aModel->getModel() ) ); - UndoGuard aUndoGuard( + UndoLiveUpdateGuardWithSelection aUndoGuard( ActionDescriptionProvider::createDescription( (bForward ? ActionDescriptionProvider::MOVE_TOTOP : ActionDescriptionProvider::MOVE_TOBOTTOM), ::rtl::OUString( String( SchResId( STR_OBJECT_DATASERIES )))), @@ -1247,7 +1247,10 @@ bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( m_aModel->getModel() ), xGivenDataSeries, bForward ); if( bChanged ) + { + m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( aObjectCID, bForward ) ); aUndoGuard.commitAction(); + } } // ____ XMultiServiceFactory ____ --- Orig/chart2/source/inc/ObjectIdentifier.hxx 2007-08-07 14:16:22.000000000 +0800 +++ new/chart2/source/inc/ObjectIdentifier.hxx 2007-08-15 11:50:42.000000000 +0800 @@ -268,6 +268,8 @@ , ::com::sun::star::awt::Point& rMaximumPosition ); static TitleHelper::eTitleType getTitleTypeForCID( const ::rtl::OUString& rCID ); + + static ::rtl::OUString getMovedSeriesCID( const ::rtl::OUString& rObjectCID, sal_Bool bForward ); }; //............................................................................. --- Orig/chart2/source/inc/UndoGuard.hxx 2007-08-07 14:16:22.000000000 +0800 +++ new/chart2/source/inc/UndoGuard.hxx 2007-08-15 11:50:42.000000000 +0800 @@ -110,6 +110,16 @@ virtual ~UndoLiveUpdateGuardWithData(); }; +class UndoLiveUpdateGuardWithSelection : public UndoGuard_Base +{ +public: + explicit UndoLiveUpdateGuardWithSelection( const rtl::OUString& rUndoMessage + , UndoManager& rUndoManager + , const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xModel ); + virtual ~UndoLiveUpdateGuardWithSelection(); +}; + } // CHART2_UNDOGUARD_HXX #endif --- Orig/chart2/source/inc/UndoManager.hxx 2007-08-07 14:16:22.000000000 +0800 +++ new/chart2/source/inc/UndoManager.hxx 2007-08-15 11:50:42.000000000 +0800 @@ -108,6 +108,9 @@ /// same as preAction but with cloning the data for the chart in addition to the model void preActionWithData( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xCurrentModel ); + + void preActionWithSelection( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xCurrentModel ); /// give the current model to be put into the redo-stack void undo( const ::com::sun::star::uno::Reference< --- Orig/chart2/source/tools/ImplUndoManager.cxx 2007-08-07 14:16:28.000000000 +0800 +++ new/chart2/source/tools/ImplUndoManager.cxx 2007-08-15 11:50:42.000000000 +0800 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -268,6 +269,74 @@ // ======================================== +// ---------------------------------------- + +UndoElementWithSelection::UndoElementWithSelection( + const OUString & rActionString, + const Reference< frame::XModel > & xModel ) : + UndoElement( rActionString, xModel ) +{ + initialize( xModel ); +} + +UndoElementWithSelection::UndoElementWithSelection( + const Reference< frame::XModel > & xModel ) : + UndoElement( xModel ) +{ + initialize( xModel ); +} + +UndoElementWithSelection::UndoElementWithSelection( + const UndoElementWithSelection & rOther ) : + UndoElement( rOther ) +{ + initialize( rOther.m_xModel ); +} + +UndoElementWithSelection::~UndoElementWithSelection() +{} + +void UndoElementWithSelection::initialize( const Reference< frame::XModel > & xModel ) +{ + try + { + uno::Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY ); + OSL_ASSERT( xSelSupp.is() ); + + if( xSelSupp.is() ) + m_aSelection = xSelSupp->getSelection(); + } + catch ( const uno::Exception & ) + { + } +} + +void UndoElementWithSelection::dispose() +{ + UndoElement::dispose(); + m_aSelection.clear(); +} + +void UndoElementWithSelection::applyDataToModel( + const Reference< frame::XModel > & xInOutModelToChange ) +{ + Reference< view::XSelectionSupplier > xCurrentSelection( xInOutModelToChange->getCurrentController(), uno::UNO_QUERY ); + OSL_ASSERT( xCurrentSelection.is() ); + + if( xCurrentSelection.is() && typelib_TypeClass_VOID != m_aSelection.pType->eTypeClass ) + { + xCurrentSelection->select( m_aSelection ); + } +} + +UndoElement * UndoElementWithSelection::createFromModel( + const Reference< frame::XModel > & xModel ) +{ + return new UndoElementWithSelection( getActionString(), xModel ); +} + +// ======================================== + UndoStack::UndoStack() : m_nSizeLimit( 1000 ) { --- Orig/chart2/source/tools/ImplUndoManager.hxx 2007-08-07 14:16:28.000000000 +0800 +++ new/chart2/source/tools/ImplUndoManager.hxx 2007-08-15 11:50:42.000000000 +0800 @@ -124,6 +124,34 @@ ::com::sun::star::chart2::XInternalDataProvider > m_xData; }; +class UndoElementWithSelection : public UndoElement +{ +public: + UndoElementWithSelection( const ::rtl::OUString & rActionString, + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xModel ); + UndoElementWithSelection( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xModel ); + UndoElementWithSelection( const UndoElementWithSelection & rOther ); + virtual ~UndoElementWithSelection(); + + virtual void dispose(); + virtual UndoElement * createFromModel( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xModel ); + +protected: + virtual void applyDataToModel( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xInOutModelToChange ); + +private: + void initialize( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & xModel ); + + ::com::sun::star::uno::Any m_aSelection; +}; + /** Note that all models that are put into this container are at some point disposed of inside this class. (At least in the destructor). That means the models retrieved here should never be used, but instead their content --- Orig/chart2/source/tools/ObjectIdentifier.cxx 2007-08-07 14:16:30.000000000 +0800 +++ new/chart2/source/tools/ObjectIdentifier.cxx 2007-08-15 11:50:42.000000000 +0800 @@ -1336,6 +1336,23 @@ return eRet; } +//static +OUString ObjectIdentifier::getMovedSeriesCID( const ::rtl::OUString& rObjectCID, sal_Bool bForward ) +{ + sal_Int32 nDiagramIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, C2U("CID/D=") ) ); + sal_Int32 nCooSysIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, C2U("CS=") ) ); + sal_Int32 nChartTypeIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, C2U("CT=") ) ); + sal_Int32 nSeriesIndex = lcl_StringToIndex( lcl_getIndexStringAfterString( rObjectCID, C2U("Series=") ) ); + + if( bForward ) + nSeriesIndex--; + else + nSeriesIndex++; + + OUString aRet = ObjectIdentifier::createParticleForSeries( nDiagramIndex, nCooSysIndex, nChartTypeIndex, nSeriesIndex ); + return ObjectIdentifier::createClassifiedIdentifierForParticle( aRet ); +} +//static //............................................................................. } //namespace chart //............................................................................. --- Orig/chart2/source/tools/UndoGuard.cxx 2007-08-07 14:16:30.000000000 +0800 +++ new/chart2/source/tools/UndoGuard.cxx 2007-08-15 11:50:42.000000000 +0800 @@ -116,4 +116,20 @@ m_rUndoManager.cancelActionUndo( m_xModel ); } +//----------------------------------------------------------------------------- + +UndoLiveUpdateGuardWithSelection::UndoLiveUpdateGuardWithSelection( const rtl::OUString& rUndoString + , UndoManager& rUndoManager + , const uno::Reference< frame::XModel > & xModel ) + : UndoGuard_Base( rUndoString, rUndoManager, xModel ) +{ + m_rUndoManager.preActionWithSelection( m_xModel ); +} + +UndoLiveUpdateGuardWithSelection::~UndoLiveUpdateGuardWithSelection() +{ + if( !m_bActionPosted ) + m_rUndoManager.cancelActionUndo( m_xModel ); +} + } // namespace chart --- Orig/chart2/source/tools/UndoManager.cxx 2007-08-07 14:16:30.000000000 +0800 +++ new/chart2/source/tools/UndoManager.cxx 2007-08-15 11:50:42.000000000 +0800 @@ -220,6 +220,12 @@ m_pLastRemeberedUndoElement = new impl::UndoElementWithData( xCurrentModel ); } +void UndoManager::preActionWithSelection( const Reference< frame::XModel > & xCurrentModel ) +{ + OSL_ENSURE( ! m_pLastRemeberedUndoElement, "Looks like postAction or cancelAction call was missing" ); + m_pLastRemeberedUndoElement = new impl::UndoElementWithSelection( xCurrentModel ); +} + void UndoManager::postAction( const OUString & rUndoString ) { OSL_ENSURE( m_pLastRemeberedUndoElement, "Looks like preAction call was missing" );