LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basctl / source / basicide / scriptdocument.cxx
blobfcef9e78802b6010a0e67e582f801f22ea1cfa52
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
21 #include <scriptdocument.hxx>
22 #include <basobj.hxx>
23 #include <strings.hrc>
24 #include <iderid.hxx>
25 #include <dlgeddef.hxx>
26 #include <doceventnotifier.hxx>
27 #include "documentenumeration.hxx"
29 #include <com/sun/star/ucb/ContentCreationException.hpp>
30 #include <com/sun/star/uri/UriReferenceFactory.hpp>
31 #include <com/sun/star/util/theMacroExpander.hpp>
32 #include <com/sun/star/frame/XStorable.hpp>
33 #include <com/sun/star/frame/FrameSearchFlag.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/awt/XWindow2.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/document/XEmbeddedScripts.hpp>
38 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
39 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
40 #include <com/sun/star/script/ModuleInfo.hpp>
41 #include <com/sun/star/script/ModuleType.hpp>
43 #include <sfx2/app.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/docfile.hxx>
48 #include <basic/basicmanagerrepository.hxx>
50 #include <xmlscript/xmldlg_imexp.hxx>
52 #include <i18nlangtag/languagetag.hxx>
54 #include <tools/diagnose_ex.h>
55 #include <tools/debug.hxx>
57 #include <comphelper/documentinfo.hxx>
58 #include <comphelper/processfactory.hxx>
59 #include <comphelper/propertysequence.hxx>
60 #include <comphelper/string.hxx>
62 #include <vcl/svapp.hxx>
63 #include <vcl/settings.hxx>
65 #include <osl/file.hxx>
66 #include <rtl/uri.hxx>
67 #include <set>
70 namespace basctl
72 using ::com::sun::star::uno::Sequence;
73 using ::com::sun::star::uno::Reference;
74 using ::com::sun::star::frame::XModel;
75 using ::com::sun::star::beans::XPropertySet;
76 using ::com::sun::star::script::XLibraryContainer;
77 using ::com::sun::star::uno::UNO_QUERY_THROW;
78 using ::com::sun::star::uno::UNO_SET_THROW;
79 using ::com::sun::star::uno::Exception;
80 using ::com::sun::star::container::XNameContainer;
81 using ::com::sun::star::container::NoSuchElementException;
82 using ::com::sun::star::uno::UNO_QUERY;
83 using ::com::sun::star::task::XStatusIndicator;
84 using ::com::sun::star::uno::Any;
85 using ::com::sun::star::script::XLibraryContainer2;
86 using ::com::sun::star::uri::UriReferenceFactory;
87 using ::com::sun::star::uri::XUriReferenceFactory;
88 using ::com::sun::star::uri::XUriReference;
89 using ::com::sun::star::uno::XComponentContext;
90 using ::com::sun::star::util::XMacroExpander;
91 using ::com::sun::star::util::theMacroExpander;
92 using ::com::sun::star::io::XInputStreamProvider;
93 using ::com::sun::star::uno::Any;
94 using ::com::sun::star::io::XInputStream;
95 using ::com::sun::star::frame::XStorable;
96 using ::com::sun::star::util::XModifiable;
97 using ::com::sun::star::frame::XController;
98 using ::com::sun::star::frame::XFrame;
99 using ::com::sun::star::util::URL;
100 using ::com::sun::star::frame::XDispatchProvider;
101 using ::com::sun::star::frame::XDispatch;
102 using ::com::sun::star::beans::PropertyValue;
103 using ::com::sun::star::awt::XWindow2;
104 using ::com::sun::star::document::XEmbeddedScripts;
105 using ::com::sun::star::script::ModuleInfo;
106 using ::com::sun::star::script::vba::XVBACompatibility;
107 using ::com::sun::star::script::vba::XVBAModuleInfo;
109 namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
112 namespace
114 class FilterDocuments : public docs::IDocumentDescriptorFilter
116 public:
117 explicit FilterDocuments(bool _bFilterInvisible)
118 : m_bFilterInvisible(_bFilterInvisible)
122 virtual ~FilterDocuments() {}
124 virtual bool includeDocument( const docs::DocumentDescriptor& _rDocument ) const override;
126 private:
127 static bool impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument );
129 private:
130 bool m_bFilterInvisible;
133 bool FilterDocuments::impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument )
137 for (auto const& controller : _rDocument.aControllers)
139 Reference< XFrame > xFrame( controller->getFrame(), UNO_SET_THROW );
140 Reference< XWindow2 > xContainer( xFrame->getContainerWindow(), UNO_QUERY_THROW );
141 if ( xContainer->isVisible() )
142 return true;
145 catch( const Exception& )
147 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
149 return false;
152 bool FilterDocuments::includeDocument( const docs::DocumentDescriptor& _rDocument ) const
154 Reference< XEmbeddedScripts > xScripts( _rDocument.xModel, UNO_QUERY );
155 if ( !xScripts.is() )
156 return false;
157 return !m_bFilterInvisible || impl_isDocumentVisible_nothrow( _rDocument );
160 void lcl_getAllModels_throw( docs::Documents& _out_rModels, bool _bVisibleOnly )
162 _out_rModels.clear();
164 FilterDocuments aFilter( _bVisibleOnly );
165 docs::DocumentEnumeration aEnum(
166 comphelper::getProcessComponentContext(), &aFilter );
168 aEnum.getDocuments( _out_rModels );
172 class ScriptDocument::Impl : public DocumentEventListener
174 private:
175 bool m_bIsApplication;
176 bool m_bValid;
177 bool m_bDocumentClosed;
178 Reference< XModel > m_xDocument;
179 Reference< XModifiable > m_xDocModify;
180 Reference< XEmbeddedScripts > m_xScriptAccess;
181 std::unique_ptr< DocumentEventNotifier > m_pDocListener;
183 public:
184 Impl ();
185 explicit Impl(Reference<XModel> const& rxDocument);
186 virtual ~Impl() override;
188 /** determines whether the instance refers to a valid "document" with script and
189 dialog libraries
191 bool isValid() const { return m_bValid; }
192 /** determines whether the instance refers to a non-closed document
194 bool isAlive() const { return m_bValid && ( m_bIsApplication || !m_bDocumentClosed ); }
195 /// determines whether the "document" refers to the application in real
196 bool isApplication() const { return m_bValid && m_bIsApplication; }
197 /// determines whether the document refers to a real document (instead of the application)
198 bool isDocument() const { return m_bValid && !m_bIsApplication; }
200 /** invalidates the instance
202 void invalidate();
204 const Reference< XModel >&
205 getDocumentRef() const { return m_xDocument; }
207 /// returns a library container belonging to the document
208 Reference< XLibraryContainer >
209 getLibraryContainer( LibraryContainerType _eType ) const;
211 /// determines whether a given library is part of the shared installation
212 bool isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType );
214 /** returns the current frame of the document
216 To be called for documents only, not for the application.
218 If <FALSE/> is returned, an assertion will be raised in non-product builds.
220 bool getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const;
222 // versions with the same signature/semantics as in ScriptDocument itself
223 bool isReadOnly() const;
224 bool isInVBAMode() const;
225 BasicManager*
226 getBasicManager() const;
227 Reference< XModel >
228 getDocument() const;
229 void setDocumentModified() const;
230 bool isDocumentModified() const;
231 void saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const;
233 OUString getTitle() const;
234 OUString getURL() const;
236 bool allowMacros() const;
238 Reference< XNameContainer >
239 getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const;
240 bool hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
241 Reference< XNameContainer >
242 getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
244 void loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary );
246 bool removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName );
247 bool hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const;
248 bool getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog );
249 bool renameModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel );
250 bool createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const;
251 bool insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rObjectName, const OUString& _rModName, const Any& _rElement ) const;
252 bool updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const;
253 bool createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const;
255 protected:
256 // DocumentEventListener
257 virtual void onDocumentCreated( const ScriptDocument& _rDocument ) override;
258 virtual void onDocumentOpened( const ScriptDocument& _rDocument ) override;
259 virtual void onDocumentSave( const ScriptDocument& _rDocument ) override;
260 virtual void onDocumentSaveDone( const ScriptDocument& _rDocument ) override;
261 virtual void onDocumentSaveAs( const ScriptDocument& _rDocument ) override;
262 virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument ) override;
263 virtual void onDocumentClosed( const ScriptDocument& _rDocument ) override;
264 virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument ) override;
265 virtual void onDocumentModeChanged( const ScriptDocument& _rDocument ) override;
267 private:
268 bool impl_initDocument_nothrow( const Reference< XModel >& _rxModel );
272 ScriptDocument::Impl::Impl()
273 :m_bIsApplication( true )
274 ,m_bValid( true )
275 ,m_bDocumentClosed( false )
279 ScriptDocument::Impl::Impl( const Reference< XModel >& _rxDocument )
280 :m_bIsApplication( false )
281 ,m_bValid( false )
282 ,m_bDocumentClosed( false )
284 if ( _rxDocument.is() )
285 impl_initDocument_nothrow( _rxDocument );
288 ScriptDocument::Impl::~Impl()
290 invalidate();
293 void ScriptDocument::Impl::invalidate()
295 m_bIsApplication = false;
296 m_bValid = false;
297 m_bDocumentClosed = false;
299 m_xDocument.clear();
300 m_xDocModify.clear();
301 m_xScriptAccess.clear();
303 if (m_pDocListener)
304 m_pDocListener->dispose();
307 bool ScriptDocument::Impl::impl_initDocument_nothrow( const Reference< XModel >& _rxModel )
311 m_xDocument.set ( _rxModel, UNO_SET_THROW );
312 m_xDocModify.set ( _rxModel, UNO_QUERY_THROW );
313 m_xScriptAccess.set ( _rxModel, UNO_QUERY );
315 m_bValid = m_xScriptAccess.is();
317 if ( m_bValid )
318 m_pDocListener.reset( new DocumentEventNotifier( *this, _rxModel ) );
320 catch( const Exception& )
322 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
323 m_bValid = false;
326 if ( !m_bValid )
328 invalidate();
331 return m_bValid;
334 Reference< XLibraryContainer > ScriptDocument::Impl::getLibraryContainer( LibraryContainerType _eType ) const
336 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibraryContainer: invalid!" );
338 Reference< XLibraryContainer > xContainer;
339 if ( !isValid() )
340 return xContainer;
344 if ( isApplication() )
345 xContainer.set( _eType == E_SCRIPTS ? SfxGetpApp()->GetBasicContainer() : SfxGetpApp()->GetDialogContainer(), UNO_QUERY_THROW );
346 else
348 xContainer.set(
349 _eType == E_SCRIPTS ? m_xScriptAccess->getBasicLibraries() : m_xScriptAccess->getDialogLibraries(),
350 UNO_QUERY_THROW );
353 catch( const Exception& )
355 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
357 return xContainer;
360 bool ScriptDocument::Impl::isReadOnly() const
362 OSL_ENSURE( isValid(), "ScriptDocument::Impl::isReadOnly: invalid state!" );
363 OSL_ENSURE( !isApplication(), "ScriptDocument::Impl::isReadOnly: not allowed to be called for the application!" );
365 bool bIsReadOnly = true;
366 if ( isValid() && !isApplication() )
370 // note that XStorable is required by the OfficeDocument service
371 Reference< XStorable > xDocStorable( m_xDocument, UNO_QUERY_THROW );
372 bIsReadOnly = xDocStorable->isReadonly();
374 catch( const Exception& )
376 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
379 return bIsReadOnly;
382 bool ScriptDocument::Impl::isInVBAMode() const
384 bool bResult = false;
385 if ( !isApplication() )
387 Reference< XVBACompatibility > xVBACompat( getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
388 if ( xVBACompat.is() )
389 bResult = xVBACompat->getVBACompatibilityMode();
391 return bResult;
394 BasicManager* ScriptDocument::Impl::getBasicManager() const
398 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getBasicManager: invalid state!" );
399 if ( !isValid() )
400 return nullptr;
402 if ( isApplication() )
403 return SfxApplication::GetBasicManager();
405 return ::basic::BasicManagerRepository::getDocumentBasicManager( m_xDocument );
407 catch (const css::ucb::ContentCreationException&)
409 TOOLS_WARN_EXCEPTION( "basctl.basicide", "ScriptDocument::getBasicManager" );
411 return nullptr;
414 Reference< XModel > ScriptDocument::Impl::getDocument() const
416 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getDocument: invalid state!" );
417 OSL_ENSURE( isDocument(), "ScriptDocument::Impl::getDocument: for documents only!" );
418 if ( !isValid() || !isDocument() )
419 return nullptr;
421 return m_xDocument;
425 Reference< XNameContainer > ScriptDocument::Impl::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
427 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibrary: invalid state!" );
429 Reference< XNameContainer > xContainer;
432 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
433 if ( isValid() && xLibContainer.is() )
434 xContainer.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
436 if ( !xContainer.is() )
437 throw NoSuchElementException();
439 // load library
440 if ( _bLoadLibrary && !xLibContainer->isLibraryLoaded( _rLibName ) )
441 xLibContainer->loadLibrary( _rLibName );
443 catch( const NoSuchElementException& )
445 throw; // allowed to leave
447 catch( const Exception& )
449 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
452 return xContainer;
456 bool ScriptDocument::Impl::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
458 bool bHas = false;
461 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
462 bHas = xLibContainer.is() && xLibContainer->hasByName( _rLibName );
464 catch( const Exception& )
466 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
468 return bHas;
472 Reference< XNameContainer > ScriptDocument::Impl::getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
474 Reference< XNameContainer > xLibrary;
477 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ), UNO_SET_THROW );
478 if ( xLibContainer->hasByName( _rLibName ) )
479 xLibrary.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
480 else
481 xLibrary.set( xLibContainer->createLibrary( _rLibName ), UNO_SET_THROW );
483 if ( !xLibContainer->isLibraryLoaded( _rLibName ) )
484 xLibContainer->loadLibrary( _rLibName );
486 catch( const Exception& )
488 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
490 return xLibrary;
494 void ScriptDocument::Impl::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
498 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ) );
499 if ( xLibContainer.is() && xLibContainer->hasByName( _rLibrary ) && !xLibContainer->isLibraryLoaded( _rLibrary ) )
500 xLibContainer->loadLibrary( _rLibrary );
502 catch( const Exception& )
504 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
509 bool ScriptDocument::Impl::removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName )
511 OSL_ENSURE( isValid(), "ScriptDocument::Impl::removeModuleOrDialog: invalid!" );
512 if ( isValid() )
516 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
517 if ( xLib.is() )
519 xLib->removeByName( _rModuleName );
520 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
521 if(xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo(_rModuleName))
522 xVBAModuleInfo->removeModuleInfo(_rModuleName);
523 return true;
526 catch( const Exception& )
528 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
531 return false;
535 bool ScriptDocument::Impl::hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const
537 OSL_ENSURE( isValid(), "ScriptDocument::Impl::hasModuleOrDialog: invalid!" );
538 if ( !isValid() )
539 return false;
543 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
544 if ( xLib.is() )
545 return xLib->hasByName( _rModName );
547 catch( const Exception& )
549 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
551 return false;
555 bool ScriptDocument::Impl::getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog )
557 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getModuleOrDialog: invalid!" );
558 if ( !isValid() )
559 return false;
561 _out_rModuleOrDialog.clear();
564 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_SET_THROW );
565 if ( xLib->hasByName( _rObjectName ) )
567 _out_rModuleOrDialog = xLib->getByName( _rObjectName );
568 return true;
571 catch( const Exception& )
573 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
575 return false;
579 bool ScriptDocument::Impl::renameModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName,
580 const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel )
582 OSL_ENSURE( isValid(), "ScriptDocument::Impl::renameModuleOrDialog: invalid!" );
583 if ( !isValid() )
584 return false;
588 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_SET_THROW );
590 // get element
591 Any aElement( xLib->getByName( _rOldName ) );
593 // remove element from container
594 xLib->removeByName( _rOldName );
596 // if it's a dialog, import and export, to reflect the new name
597 if ( _eType == E_DIALOGS )
599 // create dialog model
600 Reference< XComponentContext > aContext(
601 comphelper::getProcessComponentContext() );
602 Reference< XNameContainer > xDialogModel;
603 if ( _rxExistingDialogModel.is() )
604 xDialogModel = _rxExistingDialogModel;
605 else
606 xDialogModel.set(
607 ( aContext->getServiceManager()->
608 createInstanceWithContext(
609 "com.sun.star.awt.UnoControlDialogModel",
610 aContext ) ),
611 UNO_QUERY_THROW );
613 // import dialog model
614 Reference< XInputStreamProvider > xISP( aElement, UNO_QUERY_THROW );
615 if ( !_rxExistingDialogModel.is() )
617 Reference< XInputStream > xInput( xISP->createInputStream(), UNO_SET_THROW );
618 ::xmlscript::importDialogModel( xInput, xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
621 // set new name as property
622 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
623 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rNewName ) );
625 // export dialog model
626 xISP = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
627 aElement <<= xISP;
630 // insert element by new name in container
631 if ( _eType == E_SCRIPTS )
633 Reference< XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY );
634 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( _rOldName ) )
636 ModuleInfo sModuleInfo = xVBAModuleInfo->getModuleInfo( _rOldName );
637 xVBAModuleInfo->removeModuleInfo( _rOldName );
638 xVBAModuleInfo->insertModuleInfo( _rNewName, sModuleInfo );
641 xLib->insertByName( _rNewName, aElement );
642 return true;
644 catch( const Exception& )
646 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
648 return false;
652 bool ScriptDocument::Impl::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
654 _out_rNewModuleCode.clear();
657 Reference< XNameContainer > xLib( getLibrary( E_SCRIPTS, _rLibName, true ) );
658 if ( !xLib.is() || xLib->hasByName( _rModName ) )
659 return false;
661 // create new module
662 _out_rNewModuleCode = "REM ***** BASIC *****\n\n" ;
663 if ( _bCreateMain )
664 _out_rNewModuleCode += "Sub Main\n\nEnd Sub\n" ;
666 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
667 if (xVBAModuleInfo.is())
669 css::script::ModuleInfo aModuleInfo;
670 aModuleInfo.ModuleType = css::script::ModuleType::NORMAL;
671 xVBAModuleInfo->insertModuleInfo(_rModName, aModuleInfo);
674 // insert module into library
675 xLib->insertByName( _rModName, Any( _out_rNewModuleCode ) );
677 catch( const Exception& )
679 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
680 return false;
683 return true;
687 bool ScriptDocument::Impl::insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, const Any& _rElement ) const
691 Reference< XNameContainer > xLib( getOrCreateLibrary( _eType, _rLibName ), UNO_SET_THROW );
692 if ( xLib->hasByName( _rObjectName ) )
693 return false;
695 xLib->insertByName( _rObjectName, _rElement );
696 return true;
698 catch( const Exception& )
700 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
702 return false;
706 bool ScriptDocument::Impl::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
710 Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_SET_THROW );
711 if ( !xLib->hasByName( _rModName ) )
712 return false;
713 xLib->replaceByName( _rModName, Any( _rModuleCode ) );
714 return true;
716 catch( const Exception& )
718 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
720 return false;
724 bool ScriptDocument::Impl::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
728 Reference< XNameContainer > xLib( getLibrary( E_DIALOGS, _rLibName, true ), UNO_SET_THROW );
730 // create dialog
731 _out_rDialogProvider.clear();
732 if ( xLib->hasByName( _rDialogName ) )
733 return false;
735 // create new dialog model
736 Reference< XComponentContext > aContext(
737 comphelper::getProcessComponentContext() );
738 Reference< XNameContainer > xDialogModel(
739 aContext->getServiceManager()->createInstanceWithContext(
740 "com.sun.star.awt.UnoControlDialogModel", aContext ),
741 UNO_QUERY_THROW );
743 // set name property
744 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
745 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rDialogName ) );
747 // export dialog model
748 _out_rDialogProvider = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
750 // insert dialog into library
751 xLib->insertByName( _rDialogName, Any( _out_rDialogProvider ) );
753 catch( const Exception& )
755 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
758 return _out_rDialogProvider.is();
762 void ScriptDocument::Impl::setDocumentModified() const
764 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::setDocumentModified: only to be called for real documents!" );
765 if ( isValid() && isDocument() )
769 m_xDocModify->setModified( true );
771 catch( const Exception& )
773 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
779 bool ScriptDocument::Impl::isDocumentModified() const
781 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::isDocumentModified: only to be called for real documents!" );
782 bool bIsModified = false;
783 if ( isValid() && isDocument() )
787 bIsModified = m_xDocModify->isModified();
789 catch( const Exception& )
791 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
794 return bIsModified;
798 void ScriptDocument::Impl::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const
800 Reference< XFrame > xFrame;
801 if ( !getCurrentFrame( xFrame ) )
802 return;
804 Sequence< PropertyValue > aArgs;
805 if ( _rxStatusIndicator.is() )
807 aArgs = ::comphelper::InitPropertySequence({
808 { "StatusIndicator", Any(_rxStatusIndicator) }
814 URL aURL;
815 aURL.Complete = ".uno:Save" ;
816 aURL.Main = aURL.Complete;
817 aURL.Protocol = ".uno:" ;
818 aURL.Path = "Save" ;
820 Reference< XDispatchProvider > xDispProv( xFrame, UNO_QUERY_THROW );
821 Reference< XDispatch > xDispatch(
822 xDispProv->queryDispatch( aURL, "_self", FrameSearchFlag::AUTO ),
823 UNO_SET_THROW );
825 xDispatch->dispatch( aURL, aArgs );
827 catch( const Exception& )
829 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
834 OUString ScriptDocument::Impl::getTitle() const
836 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getTitle: for documents only!" );
838 OUString sTitle;
839 if ( isValid() && isDocument() )
841 sTitle = ::comphelper::DocumentInfo::getDocumentTitle( m_xDocument );
843 return sTitle;
847 OUString ScriptDocument::Impl::getURL() const
849 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getURL: for documents only!" );
851 OUString sURL;
852 if ( isValid() && isDocument() )
856 sURL = m_xDocument->getURL();
858 catch( const Exception& )
860 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
863 return sURL;
867 bool ScriptDocument::Impl::allowMacros() const
869 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::allowMacros: for documents only!" );
870 bool bAllow = false;
871 if ( isValid() && isDocument() )
875 bAllow = m_xScriptAccess->getAllowMacroExecution();
877 catch( const Exception& )
879 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
882 return bAllow;
886 bool ScriptDocument::Impl::getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const
888 _out_rxFrame.clear();
889 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getCurrentFrame: documents only!" );
890 if ( !isValid() || !isDocument() )
891 return false;
895 Reference< XModel > xDocument( m_xDocument, UNO_SET_THROW );
896 Reference< XController > xController( xDocument->getCurrentController(), UNO_SET_THROW );
897 _out_rxFrame.set( xController->getFrame(), UNO_SET_THROW );
899 catch( const Exception& )
901 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
904 return _out_rxFrame.is();
908 bool ScriptDocument::Impl::isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType )
910 bool bIsShared = false;
913 Reference< XLibraryContainer2 > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW );
915 if ( !xLibContainer->hasByName( _rLibName ) || !xLibContainer->isLibraryLink( _rLibName ) )
916 return false;
917 OUString aFileURL;
918 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
919 Reference< XUriReferenceFactory > xUriFac = UriReferenceFactory::create(xContext);
921 OUString aLinkURL( xLibContainer->getLibraryLinkURL( _rLibName ) );
922 Reference< XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_SET_THROW );
924 OUString aScheme = xUriRef->getScheme();
925 if ( aScheme.equalsIgnoreAsciiCase("file") )
927 aFileURL = aLinkURL;
929 else if ( aScheme.equalsIgnoreAsciiCase("vnd.sun.star.pkg") )
931 OUString aAuthority = xUriRef->getAuthority();
932 if ( aAuthority.matchIgnoreAsciiCase("vnd.sun.star.expand:") )
934 OUString aDecodedURL( aAuthority.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) );
935 aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
936 Reference< XMacroExpander > xMacroExpander = theMacroExpander::get(xContext);
937 aFileURL = xMacroExpander->expandMacros( aDecodedURL );
941 if ( !aFileURL.isEmpty() )
943 ::osl::DirectoryItem aFileItem;
944 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileURL );
945 OSL_VERIFY( ::osl::DirectoryItem::get( aFileURL, aFileItem ) == ::osl::FileBase::E_None );
946 OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None );
947 OUString aCanonicalFileURL( aFileStatus.getFileURL() );
949 if( aCanonicalFileURL.indexOf( "share/basic" ) >= 0 ||
950 aCanonicalFileURL.indexOf( "share/uno_packages" ) >= 0 ||
951 aCanonicalFileURL.indexOf( "share/extensions" ) >= 0 )
952 bIsShared = true;
955 catch( const Exception& )
957 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
960 return bIsShared;
964 void ScriptDocument::Impl::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
966 // not interested in
969 void ScriptDocument::Impl::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
971 // not interested in
974 void ScriptDocument::Impl::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
976 // not interested in
979 void ScriptDocument::Impl::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
981 // not interested in
984 void ScriptDocument::Impl::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
986 // not interested in
989 void ScriptDocument::Impl::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
991 // not interested in
994 void ScriptDocument::Impl::onDocumentClosed( const ScriptDocument& _rDocument )
996 DBG_TESTSOLARMUTEX();
997 OSL_PRECOND( isValid(), "ScriptDocument::Impl::onDocumentClosed: should not be listening if I'm not valid!" );
999 bool bMyDocument = m_xDocument == _rDocument.getDocument();
1000 OSL_PRECOND( bMyDocument, "ScriptDocument::Impl::onDocumentClosed: didn't want to know *this*!" );
1001 if ( bMyDocument )
1003 m_bDocumentClosed = true;
1008 void ScriptDocument::Impl::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
1010 // not interested in
1013 void ScriptDocument::Impl::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ )
1015 // not interested in
1019 ScriptDocument::ScriptDocument()
1020 :m_pImpl(std::make_shared<Impl>())
1024 ScriptDocument::ScriptDocument( ScriptDocument::SpecialDocument _eType )
1025 :m_pImpl( std::make_shared<Impl>( Reference< XModel >() ) )
1027 OSL_ENSURE( _eType == NoDocument, "ScriptDocument::ScriptDocument: unknown SpecialDocument type!" );
1031 ScriptDocument::ScriptDocument( const Reference< XModel >& _rxDocument )
1032 :m_pImpl( std::make_shared<Impl>( _rxDocument ) )
1034 OSL_ENSURE( _rxDocument.is(), "ScriptDocument::ScriptDocument: document must not be NULL!" );
1035 // a NULL document results in an uninitialized instance, and for this
1036 // purpose, there is a dedicated constructor
1040 const ScriptDocument& ScriptDocument::getApplicationScriptDocument()
1042 static ScriptDocument s_aApplicationScripts;
1043 return s_aApplicationScripts;
1047 ScriptDocument ScriptDocument::getDocumentForBasicManager( const BasicManager* _pManager )
1049 if ( _pManager == SfxApplication::GetBasicManager() )
1050 return getApplicationScriptDocument();
1052 docs::Documents aDocuments;
1053 lcl_getAllModels_throw( aDocuments, false );
1055 for (auto const& doc : aDocuments)
1057 const BasicManager* pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( doc.xModel );
1058 if ( ( pDocBasicManager != SfxApplication::GetBasicManager() )
1059 && ( pDocBasicManager == _pManager )
1062 return ScriptDocument( doc.xModel );
1066 OSL_FAIL( "ScriptDocument::getDocumentForBasicManager: did not find a document for this manager!" );
1067 return ScriptDocument( NoDocument );
1071 ScriptDocument ScriptDocument::getDocumentWithURLOrCaption( std::u16string_view _rUrlOrCaption )
1073 ScriptDocument aDocument( getApplicationScriptDocument() );
1074 if ( _rUrlOrCaption.empty() )
1075 return aDocument;
1077 docs::Documents aDocuments;
1078 lcl_getAllModels_throw( aDocuments, false );
1080 for (auto const& doc : aDocuments)
1082 const ScriptDocument aCheck( doc.xModel );
1083 if ( _rUrlOrCaption == aCheck.getTitle()
1084 || _rUrlOrCaption == aCheck.m_pImpl->getURL()
1087 aDocument = aCheck;
1088 break;
1092 return aDocument;
1095 ScriptDocuments ScriptDocument::getAllScriptDocuments( ScriptDocument::ScriptDocumentList _eListType )
1097 ScriptDocuments aScriptDocs;
1099 // include application?
1100 if ( _eListType == AllWithApplication )
1101 aScriptDocs.push_back( getApplicationScriptDocument() );
1103 // obtain documents
1106 docs::Documents aDocuments;
1107 lcl_getAllModels_throw( aDocuments, true /* exclude invisible */ );
1109 for (auto const& doc : aDocuments)
1111 // exclude documents without script/library containers
1112 ScriptDocument aDoc( doc.xModel );
1113 if ( !aDoc.isValid() )
1114 continue;
1116 aScriptDocs.push_back( aDoc );
1119 catch( const Exception& )
1121 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1124 // sort document list by doc title?
1125 if ( _eListType == DocumentsSorted )
1127 auto const sort = comphelper::string::NaturalStringSorter(
1128 comphelper::getProcessComponentContext(),
1129 Application::GetSettings().GetUILanguageTag().getLocale());
1130 std::sort(aScriptDocs.begin(), aScriptDocs.end(),
1131 [&sort](const ScriptDocument& rLHS, const ScriptDocument& rRHS) {
1132 return sort.compare(rLHS.getTitle(), rRHS.getTitle()) < 0;
1136 return aScriptDocs;
1140 bool ScriptDocument::operator==( const ScriptDocument& _rhs ) const
1142 return m_pImpl->getDocumentRef() == _rhs.m_pImpl->getDocumentRef();
1146 sal_Int32 ScriptDocument::hashCode() const
1148 return sal::static_int_cast<sal_Int32>(reinterpret_cast< sal_IntPtr >( m_pImpl->getDocumentRef().get() ));
1152 bool ScriptDocument::isValid() const
1154 return m_pImpl->isValid();
1158 bool ScriptDocument::isAlive() const
1160 return m_pImpl->isAlive();
1164 Reference< XLibraryContainer > ScriptDocument::getLibraryContainer( LibraryContainerType _eType ) const
1166 return m_pImpl->getLibraryContainer( _eType );
1170 Reference< XNameContainer > ScriptDocument::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
1172 return m_pImpl->getLibrary( _eType, _rLibName, _bLoadLibrary );
1176 bool ScriptDocument::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
1178 return m_pImpl->hasLibrary( _eType, _rLibName );
1182 Reference< XNameContainer > ScriptDocument::getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
1184 return m_pImpl->getOrCreateLibrary( _eType, _rLibName );
1188 void ScriptDocument::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
1190 m_pImpl->loadLibraryIfExists( _eType, _rLibrary );
1194 Sequence< OUString > ScriptDocument::getObjectNames( LibraryContainerType _eType, const OUString& _rLibName ) const
1196 Sequence< OUString > aModuleNames;
1200 if ( hasLibrary( _eType, _rLibName ) )
1202 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, false ) );
1203 if ( xLib.is() )
1204 aModuleNames = xLib->getElementNames();
1207 catch( const Exception& )
1209 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1212 // sort
1213 auto const sort = comphelper::string::NaturalStringSorter(
1214 comphelper::getProcessComponentContext(),
1215 Application::GetSettings().GetUILanguageTag().getLocale());
1216 auto [begin, end] = asNonConstRange(aModuleNames);
1217 std::sort(begin, end,
1218 [&sort](const OUString& rLHS, const OUString& rRHS) {
1219 return sort.compare(rLHS, rRHS) < 0;
1221 return aModuleNames;
1225 OUString ScriptDocument::createObjectName( LibraryContainerType _eType, const OUString& _rLibName ) const
1227 OUString aObjectName;
1229 OUString aBaseName = _eType == E_SCRIPTS ? OUString("Module") : OUString("Dialog");
1231 const Sequence< OUString > aUsedNames( getObjectNames( _eType, _rLibName ) );
1232 std::set< OUString > aUsedNamesCheck( aUsedNames.begin(), aUsedNames.end() );
1234 bool bValid = false;
1235 sal_Int32 i = 1;
1236 while ( !bValid )
1238 aObjectName = aBaseName
1239 + OUString::number( i );
1241 if ( aUsedNamesCheck.find( aObjectName ) == aUsedNamesCheck.end() )
1242 bValid = true;
1244 ++i;
1247 return aObjectName;
1251 Sequence< OUString > ScriptDocument::getLibraryNames() const
1253 return GetMergedLibraryNames( getLibraryContainer( E_SCRIPTS ), getLibraryContainer( E_DIALOGS ) );
1257 bool ScriptDocument::isReadOnly() const
1259 return m_pImpl->isReadOnly();
1263 bool ScriptDocument::isApplication() const
1265 return m_pImpl->isApplication();
1268 bool ScriptDocument::isInVBAMode() const
1270 return m_pImpl->isInVBAMode();
1274 BasicManager* ScriptDocument::getBasicManager() const
1276 return m_pImpl->getBasicManager();
1280 Reference< XModel > ScriptDocument::getDocument() const
1282 return m_pImpl->getDocument();
1286 Reference< XModel > ScriptDocument::getDocumentOrNull() const
1288 if ( isDocument() )
1289 return m_pImpl->getDocument();
1290 return nullptr;
1294 bool ScriptDocument::removeModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1296 return m_pImpl->removeModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1300 bool ScriptDocument::hasModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1302 return m_pImpl->hasModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1306 bool ScriptDocument::getModule( const OUString& _rLibName, const OUString& _rModName, OUString& _out_rModuleSource ) const
1308 Any aCode;
1309 if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
1310 return false;
1311 OSL_VERIFY( aCode >>= _out_rModuleSource );
1312 return true;
1316 bool ScriptDocument::renameModule( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName ) const
1318 return m_pImpl->renameModuleOrDialog( E_SCRIPTS, _rLibName, _rOldName, _rNewName, nullptr );
1322 bool ScriptDocument::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
1324 if ( !m_pImpl->createModule( _rLibName, _rModName, _bCreateMain, _out_rNewModuleCode ) )
1325 return false;
1327 // doc shell modified
1328 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1329 return true;
1333 bool ScriptDocument::insertModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1335 return m_pImpl->insertModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, Any( _rModuleCode ) );
1339 bool ScriptDocument::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1341 return m_pImpl->updateModule( _rLibName, _rModName, _rModuleCode );
1345 bool ScriptDocument::removeDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1347 return m_pImpl->removeModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1351 bool ScriptDocument::hasDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1353 return m_pImpl->hasModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1357 bool ScriptDocument::getDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1359 Any aCode;
1360 if ( !m_pImpl->getModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, aCode ) )
1361 return false;
1362 OSL_VERIFY( aCode >>= _out_rDialogProvider );
1363 return _out_rDialogProvider.is();
1367 bool ScriptDocument::renameDialog( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ) const
1369 return m_pImpl->renameModuleOrDialog( E_DIALOGS, _rLibName, _rOldName, _rNewName, _rxExistingDialogModel );
1373 bool ScriptDocument::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1375 if ( !m_pImpl->createDialog( _rLibName, _rDialogName, _out_rDialogProvider ) )
1376 return false;
1378 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1379 return true;
1383 bool ScriptDocument::insertDialog( const OUString& _rLibName, const OUString& _rDialogName, const Reference< XInputStreamProvider >& _rxDialogProvider ) const
1385 return m_pImpl->insertModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, Any( _rxDialogProvider ) );
1389 void ScriptDocument::setDocumentModified() const
1391 m_pImpl->setDocumentModified();
1395 bool ScriptDocument::isDocumentModified() const
1397 return m_pImpl->isDocumentModified();
1401 void ScriptDocument::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const
1403 m_pImpl->saveDocument( _rxStatusIndicator );
1407 LibraryLocation ScriptDocument::getLibraryLocation( const OUString& _rLibName ) const
1409 LibraryLocation eLocation = LIBRARY_LOCATION_UNKNOWN;
1410 if ( !_rLibName.isEmpty() )
1412 if ( isDocument() )
1414 eLocation = LIBRARY_LOCATION_DOCUMENT;
1416 else
1418 if ( ( hasLibrary( E_SCRIPTS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_SCRIPTS ) )
1419 || ( hasLibrary( E_DIALOGS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_DIALOGS ) )
1422 eLocation = LIBRARY_LOCATION_USER;
1424 else
1426 eLocation = LIBRARY_LOCATION_SHARE;
1431 return eLocation;
1435 OUString ScriptDocument::getTitle( LibraryLocation _eLocation, LibraryType _eType ) const
1437 OUString aTitle;
1439 switch ( _eLocation )
1441 case LIBRARY_LOCATION_USER:
1443 switch ( _eType )
1445 case LibraryType::Module: aTitle = IDEResId(RID_STR_USERMACROS); break;
1446 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_USERDIALOGS); break;
1447 case LibraryType::All: aTitle = IDEResId(RID_STR_USERMACROSDIALOGS); break;
1448 default:
1449 break;
1452 break;
1453 case LIBRARY_LOCATION_SHARE:
1455 switch ( _eType )
1457 case LibraryType::Module: aTitle = IDEResId(RID_STR_SHAREMACROS); break;
1458 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_SHAREDIALOGS); break;
1459 case LibraryType::All: aTitle = IDEResId(RID_STR_SHAREMACROSDIALOGS); break;
1460 default:
1461 break;
1464 break;
1465 case LIBRARY_LOCATION_DOCUMENT:
1466 aTitle = getTitle();
1467 break;
1468 default:
1469 break;
1472 return aTitle;
1476 OUString ScriptDocument::getTitle() const
1478 return m_pImpl->getTitle();
1482 bool ScriptDocument::isActive() const
1484 bool bIsActive( false );
1487 Reference< XFrame > xFrame;
1488 if ( m_pImpl->getCurrentFrame( xFrame ) )
1489 bIsActive = xFrame->isActive();
1491 catch( const Exception& )
1493 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1495 return bIsActive;
1499 bool ScriptDocument::allowMacros() const
1501 return m_pImpl->allowMacros();
1504 } // namespace basctl
1506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */