33#include <com/sun/star/script/XLibraryContainer2.hpp>
40#include <sfx2/sfxsids.hrc>
45#include <osl/diagnose.h>
54 :
SfxDialogController(pParnt,
"modules/BasicIDE/ui/basicmacrodialog.ui",
"BasicMacroDialog")
55 , m_xDocumentFrame(xDocFrame)
58 , bForceStoreBasic(false)
60 , m_xMacroNameEdit(m_xBuilder->weld_entry(
"macronameedit"))
61 , m_xMacroFromTxT(m_xBuilder->weld_label(
"macrofromft"))
62 , m_xMacrosSaveInTxt(m_xBuilder->weld_label(
"macrotoft"))
64 , m_xBasicBoxIter(m_xBasicBox->make_iterator())
65 , m_xMacrosInTxt(m_xBuilder->weld_label(
"existingmacrosft"))
66 , m_xMacroBox(m_xBuilder->weld_tree_view(
"macros"))
67 , m_xMacroBoxIter(m_xMacroBox->make_iterator())
68 , m_xRunButton(m_xBuilder->weld_button(
"ok"))
69 , m_xCloseButton(m_xBuilder->weld_button(
"close"))
70 , m_xAssignButton(m_xBuilder->weld_button(
"assign"))
71 , m_xEditButton(m_xBuilder->weld_button(
"edit"))
72 , m_xDelButton(m_xBuilder->weld_button(
"delete"))
73 , m_xNewButton(m_xBuilder->weld_button(
"new"))
74 , m_xOrganizeButton(m_xBuilder->weld_button(
"organize"))
75 , m_xNewLibButton(m_xBuilder->weld_button(
"newlibrary"))
76 , m_xNewModButton(m_xBuilder->weld_button(
"newmodule"))
109 pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
128 OUString aMethodName;
133 if ( !aMethodName.isEmpty() )
140 pData->SetLastEntryDescriptor( aDesc );
151 if (
BaseWindow* pCurWin = pShell->GetCurWindow())
152 aDesc = pCurWin->CreateEntryDescriptor();
157 aDesc =
pData->GetLastEntryDescriptor();
164 if (!aLastMacro.isEmpty())
198 std::unique_ptr<weld::TreeIter> xEntry(
m_xBasicBox->make_iterator());
200 std::unique_ptr<weld::TreeIter> xLastValid(
m_xBasicBox->make_iterator());
201 bool bValidEntryIter =
true;
205 bValidEntryIter =
m_xBasicBox->iter_children(*xEntry);
207 while (bValidEntryIter);
223 return SfxDialogController::run();
249 return pModule->
FindMethod(aMacroName, SbxClassType::Method);
255 DBG_ASSERT( pMethod,
"DeleteMacro: No Macro !" );
260 pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
264 assert(pBasic &&
"Basic?!");
272 pBindings->Invalidate( SID_SAVEDOC );
276 assert(pModule &&
"DeleteMacro: No Module?!");
278 sal_uInt16 nStart, nEnd;
281 CutLines( aSource, nStart-1, nEnd-nStart+1 );
285 OUString aLibName = pBasic->
GetName();
286 OUString aModName = pModule->
GetName();
287 OSL_VERIFY(
aDocument.updateModule( aLibName, aModName, aSource ) );
290 DBG_ASSERT(bSelected,
"DeleteMacro: Entry ?!");
300 SAL_WARN(
"basctl.basicide",
"neither cursor set nor root entry to use as fallback");
305 OSL_ENSURE(
aDocument.isAlive(),
"MacroChooser::CreateMacro: no document!" );
311 if ( aLibName.isEmpty() )
312 aLibName =
"Standard" ;
316 OUString aOULibName( aLibName );
318 if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
319 xModLibContainer->loadLibrary( aOULibName );
321 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
322 xDlgLibContainer->loadLibrary( aOULibName );
329 OUString aModName( aDesc.
GetName() );
330 if ( !aModName.isEmpty() )
335 aModName = aModName.getToken( 0,
' ' );
351 DBG_ASSERT( !pModule || !pModule->
FindMethod( aSubName, SbxClassType::Method ),
"Macro exists already!" );
363 int nStartPos, nEndPos;
376 const bool bMacroEntry =
m_xMacroBox->get_selected(
nullptr);
382 if ( nDepth == 1 || nDepth == 2 )
385 const OUString& aOULibName( aDesc.
GetLibName() );
388 if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
389 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
398 bool bEnable = pMethod !=
nullptr;
455 std::unique_ptr<weld::MessageDialog> xError(
457 VclButtonsType::Ok,
IDEResId(RID_STR_CANNOTRUNMACRO)));
462 StoreMacroDescription();
463 if (nMode == Recording)
482 if (m_xBasicBox->get_cursor(m_xBasicBoxIter.get()))
483 pModule = m_xBasicBox->FindModule(m_xBasicBoxIter.get());
484 m_xMacroBox->clear();
487 m_xMacrosInTxt->set_label(m_aMacrosInTxtBaseStr +
" " + pModule->
GetName());
489 m_xMacroBox->freeze();
491 sal_uInt32 nMacroCount = pModule->
GetMethods()->Count();
492 for ( sal_uInt32 iMeth = 0; iMeth < nMacroCount; iMeth++ )
495 assert(pMethod &&
"Method not found!");
498 m_xMacroBox->append_text(pMethod->
GetName());
503 if (m_xMacroBox->get_iter_first(*m_xMacroBoxIter))
504 m_xMacroBox->set_cursor(*m_xMacroBoxIter);
515 if (m_xBasicBox->get_cursor(m_xBasicBoxIter.get()))
517 sal_uInt16 nDepth = m_xBasicBox->get_iter_depth(*m_xBasicBoxIter);
518 if (nDepth == 1 && m_xBasicBox->IsEntryProtected(m_xBasicBoxIter.get()))
521 m_xBasicBox->iter_parent(*m_xBasicBoxIter);
522 m_xBasicBox->iter_children(*m_xBasicBoxIter);
526 std::unique_ptr<weld::TreeIter> xNewEntry(m_xBasicBox->make_iterator());
527 m_xBasicBox->copy_iterator(*m_xBasicBoxIter, *xNewEntry);
528 bool bCurEntry =
true;
531 bCurEntry = m_xBasicBox->iter_children(*m_xBasicBoxIter);
534 m_xBasicBox->copy_iterator(*m_xBasicBoxIter, *xNewEntry);
535 nDepth = m_xBasicBox->get_iter_depth(*m_xBasicBoxIter);
538 while (bCurEntry && (nDepth < 2));
539 SaveSetCurEntry(m_xBasicBox->get_widget(), *xNewEntry);
541 auto nCount = m_xMacroBox->n_children();
544 OUString aEdtText(m_xMacroNameEdit->get_text());
546 bool bValidIter = m_xMacroBox->get_iter_first(*m_xMacroBoxIter);
549 if (m_xMacroBox->get_text(*m_xMacroBoxIter).equalsIgnoreAsciiCase(aEdtText))
551 SaveSetCurEntry(*m_xMacroBox, *m_xMacroBoxIter);
555 bValidIter = m_xMacroBox->iter_next_sibling(*m_xMacroBoxIter);
559 bValidIter = m_xMacroBox->get_selected(m_xMacroBoxIter.get());
562 m_xMacroBox->unselect(*m_xMacroBoxIter);
573 if (&rButton == m_xRunButton.get())
575 StoreMacroDescription();
590 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_CANNOTRUNMACRO)));
596 else if (nMode == Recording )
601 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_BADSBXNAME)));
603 m_xMacroNameEdit->select_region(0, -1);
604 m_xMacroNameEdit->grab_focus();
615 else if (&rButton == m_xCloseButton.get())
617 StoreMacroDescription();
620 else if (&rButton == m_xEditButton.get() || &rButton == m_xDelButton.get() || &rButton == m_xNewButton.get())
622 if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter))
624 SAL_WARN(
"basctl.basicide",
"neither cursor set nor root entry to use as fallback");
627 EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get());
634 OUString aMod( aDesc.
GetName() );
638 aMod = aMod.getToken( 0,
' ' );
641 SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLib, aMod, aSub, OUString() );
642 if (&rButton == m_xEditButton.get())
644 if (m_xMacroBox->get_selected(m_xMacroBoxIter.get()))
645 aInfoItem.SetMethod(m_xMacroBox->get_text(*m_xMacroBoxIter));
646 StoreMacroDescription();
650 SfxRequest aRequest( SID_BASICIDE_APPEAR, SfxCallMode::SYNCHRON, aArgs );
655 pDispatcher->ExecuteList(SID_BASICIDE_EDITMACRO,
656 SfxCallMode::ASYNCHRON, { &aInfoItem });
662 if (&rButton == m_xDelButton.get())
667 pDispatcher->ExecuteList( SID_BASICIDE_UPDATEMODULESOURCE,
668 SfxCallMode::SYNCHRON, { &aInfoItem });
680 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_BADSBXNAME)));
682 m_xMacroNameEdit->select_region(0, -1);
683 m_xMacroNameEdit->grab_focus();
689 aInfoItem.SetMethod( pMethod->
GetName() );
693 SfxRequest aRequest( SID_BASICIDE_APPEAR, SfxCallMode::SYNCHRON, aArgs );
698 pDispatcher->ExecuteList(SID_BASICIDE_EDITMACRO,
699 SfxCallMode::ASYNCHRON, { &aInfoItem });
701 StoreMacroDescription();
707 else if (&rButton == m_xAssignButton.get())
709 if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter))
711 SAL_WARN(
"basctl.basicide",
"neither cursor set nor root entry to use as fallback");
714 EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get());
721 const OUString& aMod( aDesc.
GetName() );
722 OUString aSub( m_xMacroNameEdit->get_text() );
726 OUString aComment(
GetInfo( pMethod ) );
727 SfxMacroInfoItem aItem( SID_MACROINFO, pBasMgr, aLib, aMod, aSub, aComment );
731 if (m_xDocumentFrame.is())
734 SfxRequest aRequest(SID_CONFIGACCEL, SfxCallMode::SYNCHRON, Args, aInternalSet);
738 else if (&rButton == m_xNewLibButton.get())
740 if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter))
742 SAL_WARN(
"basctl.basicide",
"neither cursor set nor root entry to use as fallback");
745 EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get());
749 else if (&rButton == m_xNewModButton.get())
751 if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter))
753 SAL_WARN(
"basctl.basicide",
"neither cursor set nor root entry to use as fallback");
756 EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get());
758 const OUString& aLibName( aDesc.
GetLibName() );
761 else if (&rButton == m_xOrganizeButton.get())
763 StoreMacroDescription();
765 m_xBasicBox->get_selected(m_xBasicBoxIter.get());
766 auto xDlg(std::make_shared<OrganizeDialog>(
m_xDialog.get(),
nullptr, 0));
776 bForceStoreBasic =
true;
778 m_xBasicBox->UpdateEntries();
785 if (rCEvt.GetCommand() != CommandEventId::ContextMenu || !m_xMacroBox->n_children())
789 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(
"sortmenu"));
790 std::unique_ptr<weld::Menu> xDropMenu(xBuilder->weld_menu(
"sortsubmenu"));
791 xDropMenu->set_active(
"alphabetically", m_xMacroBox->get_sort_order());
792 xDropMenu->set_active(
"properorder", !m_xMacroBox->get_sort_order());
794 OUString sCommand(xPopup->popup_at_rect(m_xMacroBox.get(),
tools::Rectangle(rCEvt.GetMousePosPixel(),
Size(1,1))));
795 if (sCommand ==
"alphabetically")
797 m_xMacroBox->make_sorted();
799 else if (sCommand ==
"properorder")
801 m_xMacroBox->make_unsorted();
802 BasicSelectHdl(m_xBasicBox->get_widget());
804 else if (!sCommand.isEmpty())
806 SAL_WARN(
"basctl.basicide",
"Unknown context menu action: " << sCommand );
814 auto nMacroEntry =
m_xMacroBox->get_selected_index();
816 if (nMacroEntry != -1)
872 aComment = xInfo->GetComment();
SfxApplication * SfxGetpApp()
Reference< XExecutableDialog > m_xDialog
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
StarBASIC * GetLib(sal_uInt16 nLib) const
void GetLineRange(sal_uInt16 &, sal_uInt16 &)
const SbxArrayRef & GetMethods() const
SbMethod * FindMethod(const OUString &, SbxClassType)
const OUString & GetSource32() const
void SetSource32(const OUString &r)
const SbxObject * GetParent() const
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
virtual SbxInfo * GetInfo()
void SaveBasicAndDialogContainer() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void AppendItem(const SfxPoolItem &)
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
SbModule * FindModule(std::u16string_view)
const OUString & GetMethodName() const
LibraryLocation GetLocation() const
ScriptDocument const & GetDocument() const
void SetType(EntryType eType)
void SetMethodName(const OUString &aMethodName)
const OUString & GetLibName() const
const OUString & GetName() const
const OUString & GetLibSubName() const
OUString m_aMacrosInTxtBaseStr
std::unique_ptr< weld::TreeIter > m_xBasicBoxIter
virtual ~MacroChooser() override
void EnableButton(weld::Button &rButton, bool bEnable)
void SaveSetCurEntry(weld::TreeView &rBox, const weld::TreeIter &rEntry)
std::unique_ptr< weld::Button > m_xAssignButton
std::unique_ptr< weld::Button > m_xRunButton
std::unique_ptr< weld::Label > m_xMacrosInTxt
void StoreMacroDescription()
std::unique_ptr< weld::Button > m_xDelButton
std::unique_ptr< weld::TreeView > m_xMacroBox
std::unique_ptr< SbTreeListBox > m_xBasicBox
virtual short run() override
std::unique_ptr< weld::Entry > m_xMacroNameEdit
std::unique_ptr< weld::Button > m_xCloseButton
void RestoreMacroDescription()
std::unique_ptr< weld::TreeIter > m_xMacroBoxIter
std::unique_ptr< weld::Label > m_xMacroFromTxT
std::unique_ptr< weld::Button > m_xEditButton
std::unique_ptr< weld::Button > m_xNewModButton
std::unique_ptr< weld::Button > m_xNewLibButton
static OUString GetInfo(SbxVariable *pVar)
std::unique_ptr< weld::Button > m_xOrganizeButton
std::unique_ptr< weld::Button > m_xNewButton
MacroChooser(weld::Window *pParent, const ::css::uno::Reference< ::css::frame::XFrame > &xDocFrame)
std::unique_ptr< weld::Label > m_xMacrosSaveInTxt
encapsulates a document which contains Basic scripts and dialogs
bool allowMacros() const
determines whether macro execution for this document is allowed
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 isAlive() const
determines whether the document instance is alive
bool isActive() const
determines whether the document is currently the one-and-only application-wide active document
bool IsAppBasicModified() const
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
virtual void set_cursor(int pos)=0
#define DBG_ASSERT(sCon, aError)
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
SfxBindings * GetBindingsPtr()
bool QueryReplaceMacro(std::u16string_view rName, weld::Widget *pParent)
bool IsValidSbxName(std::u16string_view rName)
void createLibImpl(weld::Window *pWin, const ScriptDocument &rDocument, weld::TreeView *pLibBox, SbTreeListBox *pBasicBox)
ExtraData * GetExtraData()
SbMethod * CreateMacro(SbModule *pModule, const OUString &rMacroName)
SbModule * createModImpl(weld::Window *pWin, const ScriptDocument &rDocument, SbTreeListBox &rBasicBox, const OUString &rLibName, const OUString &_aModName, bool bMain)
SfxDispatcher * GetDispatcher()
BasicManager * FindBasicManager(StarBASIC const *pLib)
IMPL_LINK(AccessibleDialogWindow, WindowEventListener, VclWindowEvent &, rEvent, void)
StarBASIC * FindBasic(const SbxVariable *pVar)
bool QueryDelMacro(std::u16string_view rName, weld::Widget *pParent)
IMPL_LINK_NOARG(EditorWindow, SetSourceInBasicHdl, void *, void)
OUString IDEResId(TranslateId aId)
void CutLines(OUString &rStr, sal_Int32 nStartLine, sal_Int32 nLines)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)