29#include <com/sun/star/document/XScriptInvocationContext.hpp>
60 rtl_uString* pScriptURL = aScriptURL.pData;
61 rtl_uString_acquire( pScriptURL );
67 SAL_INFO(
"basctl.basicide",
"in basicide_macro_organizer");
73void Organize(
weld::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& xDocFrame, sal_Int16 tabId)
77 auto xDlg(std::make_shared<OrganizeDialog>(pParent, xDocFrame, tabId));
83 for (
size_t nChar = 0; nChar < rName.size(); nChar++ )
87 ( c >=
'A' && c <=
'Z' ) ||
88 ( c >=
'a' && c <=
'z' ) ||
89 ( c >=
'0' && c <=
'9' && nChar ) ||
101 std::vector<OUString> aLibList;
102 if ( xModLibContainer.is() )
105 aLibList.insert( aLibList.end(), aModLibNames.begin(), aModLibNames.end() );
109 if ( xDlgLibContainer.is() )
112 aLibList.insert( aLibList.end(), aDlgLibNames.begin(), aDlgLibNames.end() );
119 std::sort(aLibList.begin(), aLibList.end(),
120 [&sort](
const OUString& rLHS,
const OUString& rRHS) {
121 return sort.compare(rLHS, rRHS) < 0;
124 std::vector<OUString>::iterator aIterEnd = std::unique( aLibList.begin(), aLibList.end() );
125 aLibList.erase( aIterEnd, aLibList.end() );
133 const OUString& rLibName,
134 const OUString& rOldName,
135 const OUString& rNewName
138 if ( !rDocument.
hasModule( rLibName, rOldName ) )
140 SAL_WARN(
"basctl.basicide",
"basctl::RenameModule: old module name is invalid!" );
144 if ( rDocument.
hasModule( rLibName, rNewName ) )
147 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_SBXNAMEALLREADYUSED2)));
153 if ( rNewName.isEmpty() )
156 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_BADSBXNAME)));
161 if ( !rDocument.
renameModule( rLibName, rOldName, rNewName ) )
172 pWin->SetName( rNewName );
175 pWin->SetSbModule( pWin->GetBasic()->FindModule( rNewName ) );
179 SAL_WARN_IF(
nId == 0 ,
"basctl.basicide",
"No entry in Tabbar!");
192 struct MacroExecutionData
211 MacroExecutionData* i_pData =
static_cast<MacroExecutionData*
>(
p);
214 std::unique_ptr< MacroExecutionData >
pData( i_pData );
216 SAL_WARN_IF( (
pData->xMethod->GetParent()->GetFlags() & SbxFlagBits::ExtSearch) == SbxFlagBits::NONE,
"basctl.basicide",
"No EXTSEARCH!" );
220 std::optional< ::framework::DocumentUndoGuard > pUndoGuard;
221 if (
pData->aDocument.isDocument() )
222 pUndoGuard.emplace(
pData->aDocument.getDocument() );
229 const uno::Reference< frame::XModel >& rxLimitToDocument,
230 const uno::Reference< frame::XFrame >& xDocFrame,
244 if ( !bChooseOnly && rxLimitToDocument.is() )
250 short nRetValue = aChooser.
run();
270 SAL_WARN(
"basctl.basicide",
"basctl::ChooseMacro: No Module found!" );
277 SAL_WARN(
"basctl.basicide",
"basctl::ChooseMacro: No Basic found!" );
284 SAL_WARN(
"basctl.basicide",
"basctl::ChooseMacro: No BasicManager found!" );
297 aLocation =
"document" ;
299 if ( rxLimitToDocument.is() )
301 uno::Reference< frame::XModel > xLimitToDocument( rxLimitToDocument );
303 uno::Reference< document::XEmbeddedScripts > xScripts( rxLimitToDocument, UNO_QUERY );
304 if ( !xScripts.is() )
306 uno::Reference< document::XScriptInvocationContext > xContext( rxLimitToDocument, UNO_QUERY );
308 xScripts = xContext->getScriptContainer();
311 xLimitToDocument.set( xScripts, UNO_QUERY );
312 if ( !xLimitToDocument.is() )
314 SAL_WARN_IF(!xLimitToDocument.is(),
"basctl.basicide",
"basctl::ChooseMacro: a script container which is no document!?" );
315 xLimitToDocument = rxLimitToDocument;
325 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_ERRORCHOOSEMACRO)));
333 aLocation =
"application" ;
339 aScriptURL =
"vnd.sun.star.script:" +
aName +
"?language=Basic&location=" + aLocation;
342 if ( !rxLimitToDocument.is() )
344 MacroExecutionData* pExecData =
new MacroExecutionData;
346 pExecData->xMethod = pMethod;
362 if ( rDocument.
getModule( rLibName, rModName, aOUSource ) )
374 xModule->SetSource32( aOUSource );
375 pMod = xModule.
get();
379 sal_uInt32 nRealCount =
nCount;
380 for ( sal_uInt32
i = 0;
i <
nCount;
i++ )
386 aSeqMethods.realloc( nRealCount );
388 sal_uInt32 iTarget = 0;
389 for ( sal_uInt32
i = 0 ;
i <
nCount; ++
i )
394 SAL_WARN_IF( !pMethod,
"basctl.basicide",
"Method not found! (NULL)" );
395 aSeqMethods.getArray()[ iTarget++ ] = pMethod->
GetName();
404 OUString
const& rLibName,
405 OUString
const& rModName,
406 OUString
const& rMethName
409 bool bHasMethod =
false;
412 if ( rDocument.
hasModule( rLibName, rModName ) && rDocument.
getModule( rLibName, rModName, aOUSource ) )
424 xModule->SetSource32( aOUSource );
425 pMod = xModule.
get();
431 if ( pMethod && !pMethod->
IsHidden() )
static const AllSettings & GetSettings()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
StarBASIC * GetLib(sal_uInt16 nLib) const
const SbxArrayRef & GetMethods() const
const OUString & GetSource32() const
SbxVariable * Find(const OUString &, SbxClassType)
const SbxObject * GetParent() const
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
SbModule * FindModule(std::u16string_view)
virtual void SetPageText(sal_uInt16 nPageId, const OUString &rText)
void MakeVisible(sal_uInt16 nPageId)
sal_uInt16 GetCurPageId() const
virtual short run() override
encapsulates a document which contains Basic scripts and dialogs
bool getModule(const OUString &_rLibName, const OUString &_rModName, OUString &_rModuleSource) const
retrieves a module's source
css::uno::Reference< css::frame::XModel > getDocument() const
returns the UNO component representing the document which the instance operates on
bool isDocument() const
determines whether the ScriptDocument instance operates on a real document, as opposed to the whole a...
BasicManager * getBasicManager() const
returns the BasicManager associated with this instance
static ScriptDocument getDocumentForBasicManager(const BasicManager *_pManager)
returns a (newly created) ScriptDocument instance for the document to which a given BasicManager belo...
bool renameModule(const OUString &_rLibName, const OUString &_rOldName, const OUString &_rNewName) const
renames a module
bool hasModule(const OUString &_rLibName, const OUString &_rModName) const
determines whether a module with the given name exists in the given library
VclPtr< ModulWindow > FindBasWin(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName, bool bCreateIfNotExist=false, bool bFindSuspended=false)
sal_uInt16 GetWindowId(BaseWindow const *pWin) const
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
#define ENSURE_OR_RETURN_VOID(c, m)
#define LINK(Instance, Class, Member)
#define DECL_STATIC_LINK(Class, Member, ArgType, RetType)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::unique_ptr< sal_Int32[]> pData
void RunMethod(SbMethod const *pMethod)
bool HasMethod(ScriptDocument const &rDocument, OUString const &rLibName, OUString const &rModName, OUString const &rMethName)
bool IsValidSbxName(std::u16string_view rName)
IMPL_STATIC_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, BasicDebugFlags)
SAL_DLLPUBLIC_EXPORT rtl_uString * basicide_choose_macro(void *pParent, void *pOnlyInDocument_AsXModel, void *pDocFrame_AsXFrame, sal_Bool bChooseOnly)
ExtraData * GetExtraData()
OUString ChooseMacro(weld::Window *pParent, const uno::Reference< frame::XModel > &rxLimitToDocument, const uno::Reference< frame::XFrame > &xDocFrame, bool bChooseOnly)
void Organize(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &xDocFrame, sal_Int16 tabId)
BasicManager * FindBasicManager(StarBASIC const *pLib)
SAL_DLLPUBLIC_EXPORT void basicide_macro_organizer(void *pParent, void *pDocFrame_AsXFrame, sal_Int16 nTabId)
bool RenameModule(weld::Widget *pErrorParent, const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rOldName, const OUString &rNewName)
renames a module
Sequence< OUString > GetMethodNames(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName)
Sequence< OUString > GetMergedLibraryNames(const Reference< script::XLibraryContainer > &xModLibContainer, const Reference< script::XLibraryContainer > &xDlgLibContainer)
OUString IDEResId(TranslateId aId)
const LanguageTag & getLocale()
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()