/src/libreoffice/chart2/source/controller/main/UndoGuard.hxx
Line | Count | Source |
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 | | #pragma once |
20 | | |
21 | | #include "ChartModelClone.hxx" |
22 | | |
23 | | #include <rtl/ustring.hxx> |
24 | | |
25 | | #include <memory> |
26 | | |
27 | | namespace com::sun::star::document { class XUndoManager; } |
28 | | |
29 | | namespace chart |
30 | | { |
31 | | |
32 | | /** A guard which does nothing, unless you explicitly call commitAction. In particular, in its destructor, it |
33 | | does neither auto-commit nor auto-rollback the model changes. |
34 | | */ |
35 | | class UndoGuard |
36 | | { |
37 | | public: |
38 | | explicit UndoGuard( |
39 | | OUString i_undoMessage, |
40 | | const css::uno::Reference< css::document::XUndoManager > & i_undoManager, |
41 | | const ModelFacet i_facet = E_MODEL |
42 | | ); |
43 | | ~UndoGuard(); |
44 | | |
45 | | void commit(); |
46 | | void rollback(); |
47 | | |
48 | | protected: |
49 | 0 | bool isActionPosted() const { return m_bActionPosted; } |
50 | | |
51 | | private: |
52 | | void discardSnapshot(); |
53 | | |
54 | | private: |
55 | | rtl::Reference<::chart::ChartModel> m_xChartModel; |
56 | | const css::uno::Reference< css::document::XUndoManager > m_xUndoManager; |
57 | | |
58 | | std::shared_ptr< ChartModelClone > m_pDocumentSnapshot; |
59 | | OUString m_aUndoString; |
60 | | bool m_bActionPosted; |
61 | | }; |
62 | | |
63 | | /** A guard which, in its destructor, restores the model state it found in the constructor. If |
64 | | <member>commitAction</member> is called inbetween, the restoration is not performed. |
65 | | */ |
66 | | class UndoLiveUpdateGuard : public UndoGuard |
67 | | { |
68 | | public: |
69 | | explicit UndoLiveUpdateGuard( |
70 | | const OUString& i_undoMessage, |
71 | | const css::uno::Reference< css::document::XUndoManager > & i_undoManager |
72 | | ); |
73 | | ~UndoLiveUpdateGuard(); |
74 | | }; |
75 | | |
76 | | /** Same as UndoLiveUpdateGuard but with additional storage of the chart's data. |
77 | | Only use this if the data has internal data. |
78 | | */ |
79 | | class UndoLiveUpdateGuardWithData : |
80 | | public UndoGuard |
81 | | { |
82 | | public: |
83 | | explicit UndoLiveUpdateGuardWithData( |
84 | | const OUString& i_undoMessage, |
85 | | const css::uno::Reference< css::document::XUndoManager > & i_undoManager |
86 | | ); |
87 | | ~UndoLiveUpdateGuardWithData(); |
88 | | }; |
89 | | |
90 | | class UndoGuardWithSelection : public UndoGuard |
91 | | { |
92 | | public: |
93 | | explicit UndoGuardWithSelection( |
94 | | const OUString& i_undoMessage, |
95 | | const css::uno::Reference< css::document::XUndoManager > & i_undoManager |
96 | | ); |
97 | | virtual ~UndoGuardWithSelection(); |
98 | | }; |
99 | | |
100 | | class HiddenUndoContext |
101 | | { |
102 | | public: |
103 | | explicit HiddenUndoContext( |
104 | | const css::uno::Reference< css::document::XUndoManager > & i_undoManager |
105 | | ); |
106 | | ~HiddenUndoContext(); |
107 | | |
108 | | private: |
109 | | css::uno::Reference< css::document::XUndoManager > m_xUndoManager; |
110 | | }; |
111 | | |
112 | | } |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |