1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <dbaccess/dbaundomanager.hxx>
21 #include <dbaccess/dataview.hxx>
22 #include <core_resource.hxx>
23 #include <singledoccontroller.hxx>
24 #include <browserids.hxx>
25 #include <strings.hrc>
27 #include <svl/undo.hxx>
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
;
38 // OSingleDocumentController
39 OSingleDocumentController::OSingleDocumentController( const Reference
< XComponentContext
>& _rxORB
)
40 :OSingleDocumentController_Base( _rxORB
)
41 ,m_pUndoManager(new UndoManager(*this, getMutex()))
45 OSingleDocumentController::~OSingleDocumentController()
49 void SAL_CALL
OSingleDocumentController::disposing()
51 OSingleDocumentController_Base::disposing();
53 m_pUndoManager
->disposing();
56 void OSingleDocumentController::ClearUndoManager()
58 GetUndoManager().Clear();
61 SfxUndoManager
& OSingleDocumentController::GetUndoManager() const
63 return m_pUndoManager
->GetSfxUndoManager();
66 void OSingleDocumentController::addUndoActionAndInvalidate(std::unique_ptr
<SfxUndoAction
> _pAction
)
69 GetUndoManager().AddUndoAction( std::move(_pAction
) );
71 // when we add an undo action the controller was modified
74 // now inform me that or states changed
75 InvalidateFeature( ID_BROWSER_UNDO
);
76 InvalidateFeature( ID_BROWSER_REDO
);
79 Reference
< XUndoManager
> SAL_CALL
OSingleDocumentController::getUndoManager( )
81 // see UndoManager::acquire
82 return m_pUndoManager
.get();
85 FeatureState
OSingleDocumentController::GetState(sal_uInt16 _nId
) const
91 aReturn
.bEnabled
= isEditable() && GetUndoManager().GetUndoActionCount() != 0;
92 if ( aReturn
.bEnabled
)
94 OUString sUndo
= DBA_RES(STR_UNDO_COLON
) + " " +
95 GetUndoManager().GetUndoActionComment();
96 aReturn
.sTitle
= sUndo
;
100 case ID_BROWSER_REDO
:
101 aReturn
.bEnabled
= isEditable() && GetUndoManager().GetRedoActionCount() != 0;
102 if ( aReturn
.bEnabled
)
104 OUString sRedo
= DBA_RES(STR_REDO_COLON
) + " " +
105 GetUndoManager().GetRedoActionComment();
106 aReturn
.sTitle
= sRedo
;
110 case SID_GETUNDOSTRINGS
:
112 size_t nCount(GetUndoManager().GetUndoActionCount());
113 Sequence
<OUString
> aSeq(nCount
);
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;
122 case SID_GETREDOSTRINGS
:
124 size_t nCount(GetUndoManager().GetRedoActionCount());
125 Sequence
<OUString
> aSeq(nCount
);
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;
135 aReturn
= OSingleDocumentController_Base::GetState(_nId
);
139 void OSingleDocumentController::Execute( sal_uInt16 _nId
, const Sequence
< PropertyValue
>& _rArgs
)
143 case ID_BROWSER_UNDO
:
144 case ID_BROWSER_REDO
:
147 if (_rArgs
.hasElements() && _rArgs
[0].Name
!= "KeyModifier")
148 _rArgs
[0].Value
>>= nCount
;
152 if (_nId
== ID_BROWSER_UNDO
)
153 GetUndoManager().Undo();
155 GetUndoManager().Redo();
158 InvalidateFeature( ID_BROWSER_UNDO
);
159 InvalidateFeature( ID_BROWSER_REDO
);
164 OSingleDocumentController_Base::Execute( _nId
, _rArgs
);
167 InvalidateFeature(_nId
);
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */