LibreOffice Module dbaccess (master) 1
singledoccontroller.cxx
Go to the documentation of this file.
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
21#include <dbaccess/dataview.hxx>
22#include <core_resource.hxx>
24#include <browserids.hxx>
25#include <strings.hrc>
26
27#include <svl/undo.hxx>
28
29namespace dbaui
30{
31
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::XComponentContext;
35 using ::com::sun::star::document::XUndoManager;
36 using ::com::sun::star::beans::PropertyValue;
37
38 // OSingleDocumentController
41 ,m_pUndoManager(new UndoManager(*this, getMutex()))
42 {
43 }
44
46 {
47 }
48
50 {
51 OSingleDocumentController_Base::disposing();
53 m_pUndoManager->disposing();
54 }
55
57 {
59 }
60
62 {
63 return m_pUndoManager->GetSfxUndoManager();
64 }
65
66 void OSingleDocumentController::addUndoActionAndInvalidate(std::unique_ptr<SfxUndoAction> _pAction)
67 {
68 // add undo action
69 GetUndoManager().AddUndoAction( std::move(_pAction) );
70
71 // when we add an undo action the controller was modified
72 setModified( true );
73
74 // now inform me that or states changed
75 InvalidateFeature( ID_BROWSER_UNDO );
76 InvalidateFeature( ID_BROWSER_REDO );
77 }
78
80 {
81 // see UndoManager::acquire
82 return m_pUndoManager.get();
83 }
84
86 {
87 FeatureState aReturn;
88 switch ( _nId )
89 {
90 case ID_BROWSER_UNDO:
91 aReturn.bEnabled = isEditable() && GetUndoManager().GetUndoActionCount() != 0;
92 if ( aReturn.bEnabled )
93 {
94 OUString sUndo = DBA_RES(STR_UNDO_COLON) + " " +
96 aReturn.sTitle = sUndo;
97 }
98 break;
99
100 case ID_BROWSER_REDO:
101 aReturn.bEnabled = isEditable() && GetUndoManager().GetRedoActionCount() != 0;
102 if ( aReturn.bEnabled )
103 {
104 OUString sRedo = DBA_RES(STR_REDO_COLON) + " " +
106 aReturn.sTitle = sRedo;
107 }
108 break;
109
110 case SID_GETUNDOSTRINGS:
111 {
112 size_t nCount(GetUndoManager().GetUndoActionCount());
114 auto aSeqRange = asNonConstRange(aSeq);
115 for (size_t n = 0; n < nCount; ++n)
116 aSeqRange[n] = GetUndoManager().GetUndoActionComment(n);
117 aReturn.aValue <<= aSeq;
118 aReturn.bEnabled = true;
119 break;
120 }
121
122 case SID_GETREDOSTRINGS:
123 {
124 size_t nCount(GetUndoManager().GetRedoActionCount());
126 auto aSeqRange = asNonConstRange(aSeq);
127 for (size_t n = 0; n < nCount; ++n)
128 aSeqRange[n] = GetUndoManager().GetRedoActionComment(n);
129 aReturn.aValue <<= aSeq;
130 aReturn.bEnabled = true;
131 break;
132 }
133
134 default:
135 aReturn = OSingleDocumentController_Base::GetState(_nId);
136 }
137 return aReturn;
138 }
140 {
141 switch ( _nId )
142 {
143 case ID_BROWSER_UNDO:
144 case ID_BROWSER_REDO:
145 {
146 sal_Int16 nCount(1);
147 if (_rArgs.hasElements() && _rArgs[0].Name != "KeyModifier")
148 _rArgs[0].Value >>= nCount;
149
150 while (nCount--)
151 {
152 if (_nId == ID_BROWSER_UNDO)
154 else
156 }
157
158 InvalidateFeature( ID_BROWSER_UNDO );
159 InvalidateFeature( ID_BROWSER_REDO );
160 break;
161 }
162
163 default:
164 OSingleDocumentController_Base::Execute( _nId, _rArgs );
165 break;
166 }
167 InvalidateFeature(_nId);
168 }
169
170} // namespace dbaui
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ID_BROWSER_UNDO
Definition: browserids.hxx:35
#define ID_BROWSER_REDO
Definition: browserids.hxx:31
virtual bool Undo()
virtual void Clear()
OUString GetRedoActionComment(size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
OUString GetUndoActionComment(size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
virtual bool Redo()
virtual size_t GetRedoActionCount(bool const i_currentLevel=CurrentLevel) const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
virtual size_t GetUndoActionCount(bool const i_currentLevel=CurrentLevel) const
virtual void SAL_CALL disposing() override
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
std::unique_ptr< UndoManager > m_pUndoManager
OSingleDocumentController(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual css::uno::Reference< css::document::XUndoManager > SAL_CALL getUndoManager() override
SfxUndoManager & GetUndoManager() const
need for undo's and redo's
void addUndoActionAndInvalidate(std::unique_ptr< SfxUndoAction > pAction)
addUndoActionAndInvalidate adds an undo action to the undoManager, additionally invalidates the UNDO ...
virtual FeatureState GetState(sal_uInt16 nId) const override
void ClearUndoManager()
complete clears the Undo/Redo stacks
#define DBA_RES(id)
int nCount
sal_Int64 n
Sequence< sal_Int8 > aSeq
::cppu::ImplInheritanceHelper< DBSubComponentController, css::document::XUndoManagerSupplier > OSingleDocumentController_Base
::osl::Mutex & getMutex()
describes the state of a feature
std::optional< OUString > sTitle