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_Data
39 struct OSingleDocumentController_Data
41 // no Reference! see UndoManager::acquire
42 std::unique_ptr
<UndoManager
> m_pUndoManager
;
44 OSingleDocumentController_Data( ::cppu::OWeakObject
& i_parent
, ::osl::Mutex
& i_mutex
)
45 : m_pUndoManager(new UndoManager(i_parent
, i_mutex
))
50 // OSingleDocumentController
51 OSingleDocumentController::OSingleDocumentController( const Reference
< XComponentContext
>& _rxORB
)
52 :OSingleDocumentController_Base( _rxORB
)
53 ,m_pData( new OSingleDocumentController_Data( *this, getMutex() ) )
57 OSingleDocumentController::~OSingleDocumentController()
61 void SAL_CALL
OSingleDocumentController::disposing()
63 OSingleDocumentController_Base::disposing();
65 m_pData
->m_pUndoManager
->disposing();
68 void OSingleDocumentController::ClearUndoManager()
70 GetUndoManager().Clear();
73 SfxUndoManager
& OSingleDocumentController::GetUndoManager() const
75 return m_pData
->m_pUndoManager
->GetSfxUndoManager();
78 void OSingleDocumentController::addUndoActionAndInvalidate(std::unique_ptr
<SfxUndoAction
> _pAction
)
81 GetUndoManager().AddUndoAction( std::move(_pAction
) );
83 // when we add an undo action the controller was modified
86 // now inform me that or states changed
87 InvalidateFeature( ID_BROWSER_UNDO
);
88 InvalidateFeature( ID_BROWSER_REDO
);
91 Reference
< XUndoManager
> SAL_CALL
OSingleDocumentController::getUndoManager( )
93 // see UndoManager::acquire
94 return m_pData
->m_pUndoManager
.get();
97 FeatureState
OSingleDocumentController::GetState(sal_uInt16 _nId
) const
102 case ID_BROWSER_UNDO
:
103 aReturn
.bEnabled
= isEditable() && GetUndoManager().GetUndoActionCount() != 0;
104 if ( aReturn
.bEnabled
)
106 OUString sUndo
= DBA_RES(STR_UNDO_COLON
) + " " +
107 GetUndoManager().GetUndoActionComment();
108 aReturn
.sTitle
= sUndo
;
112 case ID_BROWSER_REDO
:
113 aReturn
.bEnabled
= isEditable() && GetUndoManager().GetRedoActionCount() != 0;
114 if ( aReturn
.bEnabled
)
116 OUString sRedo
= DBA_RES(STR_REDO_COLON
) + " " +
117 GetUndoManager().GetRedoActionComment();
118 aReturn
.sTitle
= sRedo
;
122 case SID_GETUNDOSTRINGS
:
124 size_t nCount(GetUndoManager().GetUndoActionCount());
125 Sequence
<OUString
> aSeq(nCount
);
126 for (size_t n
= 0; n
< nCount
; ++n
)
127 aSeq
[n
] = GetUndoManager().GetUndoActionComment(n
);
128 aReturn
.aValue
<<= aSeq
;
129 aReturn
.bEnabled
= true;
133 case SID_GETREDOSTRINGS
:
135 size_t nCount(GetUndoManager().GetRedoActionCount());
136 Sequence
<OUString
> aSeq(nCount
);
137 for (size_t n
= 0; n
< nCount
; ++n
)
138 aSeq
[n
] = GetUndoManager().GetRedoActionComment(n
);
139 aReturn
.aValue
<<= aSeq
;
140 aReturn
.bEnabled
= true;
145 aReturn
= OSingleDocumentController_Base::GetState(_nId
);
149 void OSingleDocumentController::Execute( sal_uInt16 _nId
, const Sequence
< PropertyValue
>& _rArgs
)
153 case ID_BROWSER_UNDO
:
154 case ID_BROWSER_REDO
:
157 if (_rArgs
.hasElements() && _rArgs
[0].Name
!= "KeyModifier")
158 _rArgs
[0].Value
>>= nCount
;
162 if (_nId
== ID_BROWSER_UNDO
)
163 GetUndoManager().Undo();
165 GetUndoManager().Redo();
168 InvalidateFeature( ID_BROWSER_UNDO
);
169 InvalidateFeature( ID_BROWSER_REDO
);
174 OSingleDocumentController_Base::Execute( _nId
, _rArgs
);
177 InvalidateFeature(_nId
);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */