| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "UndoActions.hxx" |
| 21 |
#include "ChartModelClone.hxx" |
| 22 |
#include <ChartModel.hxx> |
| 23 |
|
| 24 |
#include <com/sun/star/lang/DisposedException.hpp> |
| 25 |
|
| 26 |
#include <svx/svdundo.hxx> |
| 27 |
|
| 28 |
#include <memory> |
| 29 |
#include <utility> |
| 30 |
|
| 31 |
using namespace ::com::sun::star; |
| 32 |
|
| 33 |
namespace chart::impl |
| 34 |
{ |
| 35 |
using ::com::sun::star::lang::DisposedException; |
| 36 |
|
| 37 |
UndoElement::UndoElement( OUString i_actionString, rtl::Reference<::chart::ChartModel> i_documentModel, std::shared_ptr< ChartModelClone > i_modelClone ) |
| 38 |
:m_sActionString(std::move( i_actionString )) |
| 39 |
,m_xDocumentModel(std::move( i_documentModel )) |
| 40 |
,m_pModelClone(std::move( i_modelClone )) |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
UndoElement::~UndoElement() |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
void UndoElement::disposing(std::unique_lock<std::mutex>&) |
| 49 |
{ |
| 50 |
if ( m_pModelClone ) |
| 51 |
m_pModelClone->dispose(); |
| 52 |
m_pModelClone.reset(); |
| 53 |
m_xDocumentModel.clear(); |
| 54 |
} |
| 55 |
|
| 56 |
OUString SAL_CALL UndoElement::getTitle() |
| 57 |
{ |
| 58 |
return m_sActionString; |
| 59 |
} |
| 60 |
|
| 61 |
void UndoElement::impl_toggleModelState() |
| 62 |
{ |
| 63 |
// get a snapshot of the current state of our model |
| 64 |
auto pNewClone = std::make_shared<ChartModelClone>( m_xDocumentModel, m_pModelClone->getFacet() ); |
| 65 |
// apply the previous snapshot to our model |
| 66 |
m_pModelClone->applyToModel( m_xDocumentModel ); |
| 67 |
// remember the new snapshot, for the next toggle |
| 68 |
m_pModelClone = std::move(pNewClone); |
| 69 |
} |
| 70 |
|
| 71 |
void SAL_CALL UndoElement::undo( ) |
| 72 |
{ |
| 73 |
impl_toggleModelState(); |
| 74 |
} |
| 75 |
|
| 76 |
void SAL_CALL UndoElement::redo( ) |
| 77 |
{ |
| 78 |
impl_toggleModelState(); |
| 79 |
} |
| 80 |
|
| 81 |
// = ShapeUndoElement |
| 82 |
|
| 83 |
ShapeUndoElement::ShapeUndoElement( std::unique_ptr<SdrUndoAction> xSdrUndoAction ) |
| 84 |
:m_xAction( std::move(xSdrUndoAction) ) |
| 85 |
{ |
| 86 |
} |
| 87 |
|
| 88 |
ShapeUndoElement::~ShapeUndoElement() |
| 89 |
{ |
| 90 |
} |
| 91 |
|
| 92 |
OUString SAL_CALL ShapeUndoElement::getTitle() |
| 93 |
{ |
| 94 |
if ( !m_xAction ) |
| 95 |
throw DisposedException( OUString(), *this ); |
| 96 |
return m_xAction->GetComment(); |
| 97 |
} |
| 98 |
|
| 99 |
void SAL_CALL ShapeUndoElement::undo( ) |
| 100 |
{ |
| 101 |
if ( !m_xAction ) |
| 102 |
throw DisposedException( OUString(), *this ); |
| 103 |
m_xAction->Undo(); |
| 104 |
} |
| 105 |
|
| 106 |
void SAL_CALL ShapeUndoElement::redo( ) |
| 107 |
{ |
| 108 |
if ( !m_xAction ) |
| 109 |
throw DisposedException( OUString(), *this ); |
| 110 |
m_xAction->Redo(); |
| 111 |
} |
| 112 |
|
| 113 |
} // namespace chart::impl |
| 114 |
|
| 115 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |