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 .
21 #include <macrodlg.hxx>
22 #include <macrodlg.hrc>
23 #include <basidesh.hxx>
24 #include <baside2.hrc>
26 #include <iderdll.hxx>
27 #include <iderdll2.hxx>
29 #include <moduldlg.hxx>
30 #include <basic/basmgr.hxx>
31 #include <basic/sbmeth.hxx>
32 #include <basic/sbmod.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/minfitem.hxx>
36 #include <sfx2/request.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
50 MacroChooser::MacroChooser( vcl::Window
* pParnt
, bool bCreateEntries
)
51 : SfxModalDialog(pParnt
, "BasicMacroDialog", "modules/BasicIDE/ui/basicmacrodialog.ui")
53 // the Sfx doesn't aske the BasicManger whether modified or not
54 // => start saving in case of a change without a into the BasicIDE.
55 , bForceStoreBasic(false)
58 get(m_pMacroNameEdit
, "macronameedit");
59 get(m_pMacroFromTxT
, "macrofromft");
60 get(m_pMacrosSaveInTxt
, "macrotoft");
61 get(m_pBasicBox
, "libraries");
62 get(m_pMacrosInTxt
, "existingmacrosft");
63 m_aMacrosInTxtBaseStr
= m_pMacrosInTxt
->GetText();
64 get(m_pMacroBox
, "macros");
65 get(m_pRunButton
, "run");
66 get(m_pCloseButton
, "close");
67 get(m_pAssignButton
, "assign");
68 get(m_pEditButton
, "edit");
69 get(m_pDelButton
, "delete");
70 get(m_pOrganizeButton
, "organize");
71 get(m_pNewLibButton
, "newlibrary");
72 get(m_pNewModButton
, "newmodule");
74 m_pMacroBox
->SetSelectionMode( SINGLE_SELECTION
);
75 m_pMacroBox
->SetHighlightRange(); // select over the whole width
77 m_pRunButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
78 m_pCloseButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
79 m_pAssignButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
80 m_pEditButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
81 m_pDelButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
82 m_pOrganizeButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
84 // Buttons only for MacroChooser::Recording
85 m_pNewLibButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
86 m_pNewModButton
->SetClickHdl( LINK( this, MacroChooser
, ButtonHdl
) );
87 m_pNewLibButton
->Hide(); // default
88 m_pNewModButton
->Hide(); // default
89 m_pMacrosSaveInTxt
->Hide(); // default
91 m_pMacrosInTxt
->SetStyle( WB_NOMULTILINE
| WB_PATHELLIPSIS
);
93 m_pMacroNameEdit
->SetModifyHdl( LINK( this, MacroChooser
, EditModifyHdl
) );
95 m_pBasicBox
->SetSelectHdl( LINK( this, MacroChooser
, BasicSelectHdl
) );
97 m_pMacroBox
->SetDoubleClickHdl( LINK( this, MacroChooser
, MacroDoubleClickHdl
) );
98 m_pMacroBox
->SetSelectHdl( LINK( this, MacroChooser
, MacroSelectHdl
) );
100 m_pBasicBox
->SetMode( BROWSEMODE_MODULES
);
101 m_pBasicBox
->SetStyle( WB_TABSTOP
| WB_BORDER
|
102 WB_HASLINES
| WB_HASLINESATROOT
|
103 WB_HASBUTTONS
| WB_HASBUTTONSATROOT
|
106 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
107 pDispatcher
->Execute( SID_BASICIDE_STOREALLMODULESOURCES
);
109 if ( bCreateEntries
)
110 m_pBasicBox
->ScanAllEntries();
113 MacroChooser::~MacroChooser()
118 void MacroChooser::dispose()
120 if ( bForceStoreBasic
)
122 SfxGetpApp()->SaveBasicAndDialogContainer();
123 bForceStoreBasic
= false;
125 m_pMacroNameEdit
.clear();
126 m_pMacroFromTxT
.clear();
127 m_pMacrosSaveInTxt
.clear();
129 m_pMacrosInTxt
.clear();
131 m_pRunButton
.clear();
132 m_pCloseButton
.clear();
133 m_pAssignButton
.clear();
134 m_pEditButton
.clear();
135 m_pDelButton
.clear();
136 m_pOrganizeButton
.clear();
137 m_pNewLibButton
.clear();
138 m_pNewModButton
.clear();
139 SfxModalDialog::dispose();
142 void MacroChooser::StoreMacroDescription()
144 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(m_pBasicBox
->FirstSelected());
145 OUString aMethodName
;
146 SvTreeListEntry
* pEntry
= m_pMacroBox
->FirstSelected();
148 aMethodName
= m_pMacroBox
->GetEntryText( pEntry
);
150 aMethodName
= m_pMacroNameEdit
->GetText();
151 if ( !aMethodName
.isEmpty() )
153 aDesc
.SetMethodName( aMethodName
);
154 aDesc
.SetType( OBJ_TYPE_METHOD
);
157 if (ExtraData
* pData
= basctl::GetExtraData())
158 pData
->SetLastEntryDescriptor( aDesc
);
161 void MacroChooser::RestoreMacroDescription()
163 EntryDescriptor aDesc
;
164 if (Shell
* pShell
= GetShell())
166 if (BaseWindow
* pCurWin
= pShell
->GetCurWindow())
167 aDesc
= pCurWin
->CreateEntryDescriptor();
171 if (ExtraData
* pData
= basctl::GetExtraData())
172 aDesc
= pData
->GetLastEntryDescriptor();
175 m_pBasicBox
->SetCurrentEntry( aDesc
);
177 OUString
aLastMacro( aDesc
.GetMethodName() );
178 if ( !aLastMacro
.isEmpty() )
180 // find entry in macro box
181 SvTreeListEntry
* pEntry
= 0;
183 SvTreeListEntry
* pE
= m_pMacroBox
->GetEntry( nPos
);
186 if ( m_pMacroBox
->GetEntryText( pE
) == aLastMacro
)
191 pE
= m_pMacroBox
->GetEntry( ++nPos
);
195 m_pMacroBox
->SetCurEntry( pEntry
);
198 m_pMacroNameEdit
->SetText( aLastMacro
);
199 m_pMacroNameEdit
->SetSelection( Selection( 0, 0 ) );
204 short MacroChooser::Execute()
206 RestoreMacroDescription();
207 m_pRunButton
->GrabFocus();
209 // #104198 Check if "wrong" document is active
210 SvTreeListEntry
* pSelectedEntry
= m_pBasicBox
->GetCurEntry();
211 EntryDescriptor
aDesc( m_pBasicBox
->GetEntryDescriptor( pSelectedEntry
) );
212 const ScriptDocument
& rSelectedDoc( aDesc
.GetDocument() );
214 // App Basic is always ok, so only check if shell was found
215 if( rSelectedDoc
.isDocument() && !rSelectedDoc
.isActive() )
217 // Search for the right entry
218 sal_uLong nRootPos
= 0;
219 SvTreeListEntry
* pRootEntry
= m_pBasicBox
->GetEntry( nRootPos
);
222 EntryDescriptor
aCmpDesc( m_pBasicBox
->GetEntryDescriptor( pRootEntry
) );
223 const ScriptDocument
& rCmpDoc( aCmpDesc
.GetDocument() );
224 if ( rCmpDoc
.isDocument() && rCmpDoc
.isActive() )
226 SvTreeListEntry
* pEntry
= pRootEntry
;
227 SvTreeListEntry
* pLastValid
= pEntry
;
231 pEntry
= m_pBasicBox
->FirstChild( pEntry
);
234 m_pBasicBox
->SetCurEntry( pLastValid
);
236 pRootEntry
= m_pBasicBox
->GetEntry( ++nRootPos
);
243 if ( StarBASIC::IsRunning() )
244 m_pCloseButton
->GrabFocus();
246 vcl::Window
* pPrevDlgParent
= Application::GetDefDialogParent();
247 Application::SetDefDialogParent( this );
248 short nRet
= ModalDialog::Execute();
249 // #57314# If the BasicIDE has been activated, don't reset the DefModalDialogParent to the inactive document.
250 if ( Application::GetDefDialogParent() == this )
251 Application::SetDefDialogParent( pPrevDlgParent
);
256 void MacroChooser::EnableButton( Button
& rButton
, bool bEnable
)
260 if (nMode
== ChooseOnly
|| nMode
== Recording
)
261 rButton
.Enable(&rButton
== m_pRunButton
);
272 SbMethod
* MacroChooser::GetMacro()
274 SbMethod
* pMethod
= 0;
275 SbModule
* pModule
= m_pBasicBox
->FindModule( m_pBasicBox
->GetCurEntry() );
278 SvTreeListEntry
* pEntry
= m_pMacroBox
->FirstSelected();
281 OUString
aMacroName( m_pMacroBox
->GetEntryText( pEntry
) );
282 pMethod
= static_cast<SbMethod
*>(pModule
->GetMethods()->Find( aMacroName
, SbxCLASS_METHOD
));
290 void MacroChooser::DeleteMacro()
292 SbMethod
* pMethod
= GetMacro();
293 DBG_ASSERT( pMethod
, "DeleteMacro: Kein Macro !" );
294 if ( pMethod
&& QueryDelMacro( pMethod
->GetName(), this ) )
296 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
297 pDispatcher
->Execute( SID_BASICIDE_STOREALLMODULESOURCES
);
299 // mark current doc as modified:
300 StarBASIC
* pBasic
= FindBasic(pMethod
);
301 assert(pBasic
&& "Basic?!");
302 BasicManager
* pBasMgr
= FindBasicManager( pBasic
);
303 DBG_ASSERT( pBasMgr
, "BasMgr?" );
304 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
305 if ( aDocument
.isDocument() )
307 aDocument
.setDocumentModified();
308 if (SfxBindings
* pBindings
= GetBindingsPtr())
309 pBindings
->Invalidate( SID_SAVEDOC
);
312 SbModule
* pModule
= pMethod
->GetModule();
313 DBG_ASSERT( pModule
, "DeleteMacro: Kein Modul?!" );
314 OUString
aSource( pModule
->GetSource32() );
315 sal_uInt16 nStart
, nEnd
;
316 pMethod
->GetLineRange( nStart
, nEnd
);
317 pModule
->GetMethods()->Remove( pMethod
);
318 CutLines( aSource
, nStart
-1, nEnd
-nStart
+1, true );
319 pModule
->SetSource32( aSource
);
321 // update module in library
322 OUString aLibName
= pBasic
->GetName();
323 OUString aModName
= pModule
->GetName();
324 OSL_VERIFY( aDocument
.updateModule( aLibName
, aModName
, aSource
) );
326 SvTreeListEntry
* pEntry
= m_pMacroBox
->FirstSelected();
327 DBG_ASSERT( pEntry
, "DeleteMacro: Entry ?!" );
328 m_pMacroBox
->GetModel()->Remove( pEntry
);
329 bForceStoreBasic
= true;
333 SbMethod
* MacroChooser::CreateMacro()
335 SbMethod
* pMethod
= 0;
336 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
337 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
338 ScriptDocument
aDocument( aDesc
.GetDocument() );
339 OSL_ENSURE( aDocument
.isAlive(), "MacroChooser::CreateMacro: no document!" );
340 if ( !aDocument
.isAlive() )
343 OUString
aLibName( aDesc
.GetLibName() );
345 if ( aLibName
.isEmpty() )
346 aLibName
= "Standard" ;
348 aDocument
.getOrCreateLibrary( E_SCRIPTS
, aLibName
);
350 OUString
aOULibName( aLibName
);
351 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
352 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && !xModLibContainer
->isLibraryLoaded( aOULibName
) )
353 xModLibContainer
->loadLibrary( aOULibName
);
354 Reference
< script::XLibraryContainer
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
) );
355 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && !xDlgLibContainer
->isLibraryLoaded( aOULibName
) )
356 xDlgLibContainer
->loadLibrary( aOULibName
);
358 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
359 StarBASIC
* pBasic
= pBasMgr
? pBasMgr
->GetLib( aLibName
) : 0;
362 SbModule
* pModule
= 0;
363 OUString
aModName( aDesc
.GetName() );
364 if ( !aModName
.isEmpty() )
366 // extract the module name from the string like "Sheet1 (Example1)"
367 if( aDesc
.GetLibSubName() == IDE_RESSTR(RID_STR_DOCUMENT_OBJECTS
) )
369 sal_Int32 nIndex
= 0;
370 aModName
= aModName
.getToken( 0, ' ', nIndex
);
372 pModule
= pBasic
->FindModule( aModName
);
374 else if ( pBasic
->GetModules()->Count() )
375 pModule
= static_cast<SbModule
*>(pBasic
->GetModules()->Get( 0 ));
379 pModule
= createModImpl( static_cast<vcl::Window
*>( this ),
380 aDocument
, *m_pBasicBox
, aLibName
, aModName
);
383 OUString aSubName
= m_pMacroNameEdit
->GetText();
384 DBG_ASSERT( !pModule
|| !pModule
->GetMethods()->Find( aSubName
, SbxCLASS_METHOD
), "Macro existiert schon!" );
385 pMethod
= pModule
? basctl::CreateMacro( pModule
, aSubName
) : NULL
;
391 void MacroChooser::SaveSetCurEntry( SvTreeListBox
& rBox
, SvTreeListEntry
* pEntry
)
393 // the edit would be killed by the highlight otherwise:
395 OUString
aSaveText( m_pMacroNameEdit
->GetText() );
396 Selection
aCurSel( m_pMacroNameEdit
->GetSelection() );
398 rBox
.SetCurEntry( pEntry
);
399 m_pMacroNameEdit
->SetText( aSaveText
);
400 m_pMacroNameEdit
->SetSelection( aCurSel
);
403 void MacroChooser::CheckButtons()
405 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
406 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
407 SvTreeListEntry
* pMacroEntry
= m_pMacroBox
->FirstSelected();
408 SbMethod
* pMethod
= GetMacro();
410 // check, if corresponding libraries are readonly
411 bool bReadOnly
= false;
412 sal_uInt16 nDepth
= pCurEntry
? m_pBasicBox
->GetModel()->GetDepth( pCurEntry
) : 0;
413 if ( nDepth
== 1 || nDepth
== 2 )
415 ScriptDocument
aDocument( aDesc
.GetDocument() );
416 OUString
aOULibName( aDesc
.GetLibName() );
417 Reference
< script::XLibraryContainer2
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
418 Reference
< script::XLibraryContainer2
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
419 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryReadOnly( aOULibName
) ) ||
420 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryReadOnly( aOULibName
) ) )
426 if (nMode
!= Recording
)
429 bool bEnable
= pMethod
!= nullptr;
430 if (nMode
!= ChooseOnly
&& StarBASIC::IsRunning())
432 EnableButton(*m_pRunButton
, bEnable
);
435 // organising still possible?
438 EnableButton(*m_pAssignButton
, pMethod
!= nullptr);
441 EnableButton(*m_pEditButton
, pMacroEntry
!= nullptr);
444 EnableButton(*m_pOrganizeButton
, !StarBASIC::IsRunning() && nMode
== All
);
447 bool bProtected
= m_pBasicBox
->IsEntryProtected( pCurEntry
);
448 bool bShare
= ( aDesc
.GetLocation() == LIBRARY_LOCATION_SHARE
);
449 EnableButton(*m_pDelButton
, !StarBASIC::IsRunning() && nMode
== All
&& !bProtected
&& !bReadOnly
&& !bShare
);
450 bool bPrev
= bNewDelIsDel
;
451 bNewDelIsDel
= pMethod
!= nullptr;
452 if (bPrev
!= bNewDelIsDel
&& nMode
== All
)
454 OUString
aBtnText( bNewDelIsDel
? IDEResId(RID_STR_BTNDEL
).toString() : IDEResId(RID_STR_BTNNEW
).toString() );
455 m_pDelButton
->SetText( aBtnText
);
458 if (nMode
== Recording
)
461 m_pRunButton
->Enable(!bProtected
&& !bReadOnly
&& !bShare
);
462 // new library button
463 m_pNewLibButton
->Enable(!bShare
);
465 m_pNewModButton
->Enable(!bProtected
&& !bReadOnly
&& !bShare
);
471 IMPL_LINK_NOARG(MacroChooser
, MacroDoubleClickHdl
)
473 StoreMacroDescription();
474 if (nMode
== Recording
)
476 SbMethod
* pMethod
= GetMacro();
477 if ( pMethod
&& !QueryReplaceMacro( pMethod
->GetName(), this ) )
481 EndDialog(Macro_OkRun
);
485 IMPL_LINK( MacroChooser
, MacroSelectHdl
, SvTreeListBox
*, pBox
)
487 // Is also called if deselected!
488 // Two function calls in every SelectHdl because
489 // there's no separate DeselectHDL.
490 // So find out if select or deselect:
491 if ( pBox
->IsSelected( pBox
->GetHdlEntry() ) )
499 IMPL_LINK( MacroChooser
, BasicSelectHdl
, SvTreeListBox
*, pBox
)
501 // Is also called if deselected!
502 // Two function calls in every SelectHdl because
503 // there's no separate DeselectHDL.
504 // So find out if select or deselect:
505 if ( !pBox
->IsSelected( pBox
->GetHdlEntry() ) )
508 SbModule
* pModule
= m_pBasicBox
->FindModule( m_pBasicBox
->GetCurEntry() );
510 m_pMacroBox
->Clear();
513 OUString aStr
= m_aMacrosInTxtBaseStr
;
515 aStr
+= pModule
->GetName();
517 m_pMacrosInTxt
->SetText( aStr
);
519 // The macros should be called in the same order that they
520 // are written down in the module.
522 map
< sal_uInt16
, SbMethod
* > aMacros
;
523 size_t nMacroCount
= pModule
->GetMethods()->Count();
524 for ( size_t iMeth
= 0; iMeth
< nMacroCount
; iMeth
++ )
526 SbMethod
* pMethod
= static_cast<SbMethod
*>(pModule
->GetMethods()->Get( iMeth
));
527 if( pMethod
->IsHidden() )
529 DBG_ASSERT( pMethod
, "Methode nicht gefunden! (NULL)" );
530 sal_uInt16 nStart
, nEnd
;
531 pMethod
->GetLineRange( nStart
, nEnd
);
532 aMacros
.insert( map
< sal_uInt16
, SbMethod
*>::value_type( nStart
, pMethod
) );
535 m_pMacroBox
->SetUpdateMode(false);
536 for ( map
< sal_uInt16
, SbMethod
* >::iterator it
= aMacros
.begin(); it
!= aMacros
.end(); ++it
)
537 m_pMacroBox
->InsertEntry( (*it
).second
->GetName() );
538 m_pMacroBox
->SetUpdateMode(true);
540 if ( m_pMacroBox
->GetEntryCount() )
542 SvTreeListEntry
* pEntry
= m_pMacroBox
->GetEntry( 0 );
543 DBG_ASSERT( pEntry
, "Entry ?!" );
544 m_pMacroBox
->SetCurEntry( pEntry
);
555 IMPL_LINK( MacroChooser
, EditModifyHdl
, Edit
*, pEdit
)
559 // select the module in which the macro is put at Neu (new),
560 // if BasicManager or Lib is selecting
561 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
564 sal_uInt16 nDepth
= m_pBasicBox
->GetModel()->GetDepth( pCurEntry
);
565 if ( ( nDepth
== 1 ) && ( m_pBasicBox
->IsEntryProtected( pCurEntry
) ) )
567 // then put to the respective Std-Lib...
568 SvTreeListEntry
* pManagerEntry
= m_pBasicBox
->GetModel()->GetParent( pCurEntry
);
569 pCurEntry
= m_pBasicBox
->GetModel()->FirstChild( pManagerEntry
);
573 SvTreeListEntry
* pNewEntry
= pCurEntry
;
574 while ( pCurEntry
&& ( nDepth
< 2 ) )
576 pCurEntry
= m_pBasicBox
->FirstChild( pCurEntry
);
579 pNewEntry
= pCurEntry
;
580 nDepth
= m_pBasicBox
->GetModel()->GetDepth( pCurEntry
);
583 SaveSetCurEntry( *m_pBasicBox
, pNewEntry
);
585 if ( m_pMacroBox
->GetEntryCount() )
587 OUString
aEdtText( m_pMacroNameEdit
->GetText() );
589 for ( sal_uInt16 n
= 0; n
< m_pMacroBox
->GetEntryCount(); n
++ )
591 SvTreeListEntry
* pEntry
= m_pMacroBox
->GetEntry( n
);
592 DBG_ASSERT( pEntry
, "Entry ?!" );
593 if ( m_pMacroBox
->GetEntryText( pEntry
).equalsIgnoreAsciiCase( aEdtText
) )
595 SaveSetCurEntry(*m_pMacroBox
, pEntry
);
602 SvTreeListEntry
* pEntry
= m_pMacroBox
->FirstSelected();
603 // if the entry exists ->Select ->Desription...
605 m_pMacroBox
->Select( pEntry
, false );
616 IMPL_LINK( MacroChooser
, ButtonHdl
, Button
*, pButton
)
618 // apart from New/Record the Description is done by LoseFocus
619 if (pButton
== m_pRunButton
)
621 StoreMacroDescription();
623 // #116444# check security settings before macro execution
626 SbMethod
* pMethod
= GetMacro();
627 SbModule
* pModule
= pMethod
? pMethod
->GetModule() : NULL
;
628 StarBASIC
* pBasic
= pModule
? static_cast<StarBASIC
*>(pModule
->GetParent()) : NULL
;
629 BasicManager
* pBasMgr
= pBasic
? FindBasicManager(pBasic
) : NULL
;
632 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
633 if ( aDocument
.isDocument() && !aDocument
.allowMacros() )
635 ScopedVclPtrInstance
<MessageDialog
>::Create(this, IDEResId(RID_STR_CANNOTRUNMACRO
), VCL_MESSAGE_WARNING
)->Execute();
640 else if (nMode
== Recording
)
642 if ( !IsValidSbxName(m_pMacroNameEdit
->GetText()) )
644 ScopedVclPtrInstance
<MessageDialog
>::Create(this, IDEResId(RID_STR_BADSBXNAME
))->Execute();
645 m_pMacroNameEdit
->SetSelection( Selection( 0, m_pMacroNameEdit
->GetText().getLength() ) );
646 m_pMacroNameEdit
->GrabFocus();
650 SbMethod
* pMethod
= GetMacro();
651 if ( pMethod
&& !QueryReplaceMacro( pMethod
->GetName(), this ) )
655 EndDialog(Macro_OkRun
);
657 else if (pButton
== m_pCloseButton
)
659 StoreMacroDescription();
660 EndDialog(Macro_Close
);
662 else if ((pButton
== m_pEditButton
) || (pButton
== m_pDelButton
))
664 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
665 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
666 ScriptDocument
aDocument( aDesc
.GetDocument() );
667 DBG_ASSERT( aDocument
.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" );
668 if ( !aDocument
.isAlive() )
670 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
671 OUString
aLib( aDesc
.GetLibName() );
672 OUString
aMod( aDesc
.GetName() );
673 // extract the module name from the string like "Sheet1 (Example1)"
674 if( aDesc
.GetLibSubName() == IDE_RESSTR(RID_STR_DOCUMENT_OBJECTS
) )
676 sal_Int32 nIndex
= 0;
677 aMod
= aMod
.getToken( 0, ' ', nIndex
);
679 OUString
aSub( aDesc
.GetMethodName() );
680 SfxMacroInfoItem
aInfoItem( SID_BASICIDE_ARG_MACROINFO
, pBasMgr
, aLib
, aMod
, aSub
, OUString() );
681 if (pButton
== m_pEditButton
)
683 SvTreeListEntry
* pEntry
= m_pMacroBox
->FirstSelected();
685 aInfoItem
.SetMethod( m_pMacroBox
->GetEntryText( pEntry
) );
686 StoreMacroDescription();
687 SfxAllItemSet
aArgs( SfxGetpApp()->GetPool() );
688 SfxRequest
aRequest( SID_BASICIDE_APPEAR
, SfxCallMode::SYNCHRON
, aArgs
);
689 SfxGetpApp()->ExecuteSlot( aRequest
);
691 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
692 pDispatcher
->Execute( SID_BASICIDE_EDITMACRO
, SfxCallMode::ASYNCHRON
, &aInfoItem
, 0L );
693 EndDialog(Macro_Edit
);
700 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
701 pDispatcher
->Execute( SID_BASICIDE_UPDATEMODULESOURCE
,
702 SfxCallMode::SYNCHRON
, &aInfoItem
, 0L );
705 //if ( m_pMacroBox->GetCurEntry() ) // OV-Bug ?
706 // m_pMacroBox->Select( m_pMacroBox->GetCurEntry() );
710 if ( !IsValidSbxName(m_pMacroNameEdit
->GetText()) )
712 ScopedVclPtrInstance
<MessageDialog
>::Create(this, IDEResId(RID_STR_BADSBXNAME
))->Execute();
713 m_pMacroNameEdit
->SetSelection( Selection( 0, m_pMacroNameEdit
->GetText().getLength() ) );
714 m_pMacroNameEdit
->GrabFocus();
717 SbMethod
* pMethod
= CreateMacro();
720 aInfoItem
.SetMethod( pMethod
->GetName() );
721 aInfoItem
.SetModule( pMethod
->GetModule()->GetName() );
722 aInfoItem
.SetLib( pMethod
->GetModule()->GetParent()->GetName() );
723 SfxAllItemSet
aArgs( SfxGetpApp()->GetPool() );
724 SfxRequest
aRequest( SID_BASICIDE_APPEAR
, SfxCallMode::SYNCHRON
, aArgs
);
725 SfxGetpApp()->ExecuteSlot( aRequest
);
727 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
728 pDispatcher
->Execute( SID_BASICIDE_EDITMACRO
, SfxCallMode::ASYNCHRON
, &aInfoItem
, 0L );
729 StoreMacroDescription();
730 EndDialog(Macro_New
);
735 else if (pButton
== m_pAssignButton
)
737 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
738 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
739 ScriptDocument
aDocument( aDesc
.GetDocument() );
740 DBG_ASSERT( aDocument
.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" );
741 if ( !aDocument
.isAlive() )
743 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
744 OUString
aLib( aDesc
.GetLibName() );
745 OUString
aMod( aDesc
.GetName() );
746 OUString
aSub( m_pMacroNameEdit
->GetText() );
747 SbMethod
* pMethod
= GetMacro();
748 DBG_ASSERT( pBasMgr
, "BasMgr?" );
749 DBG_ASSERT( pMethod
, "Method?" );
750 OUString
aComment( GetInfo( pMethod
) );
751 SfxMacroInfoItem
aItem( SID_MACROINFO
, pBasMgr
, aLib
, aMod
, aSub
, aComment
);
752 SfxAllItemSet
Args( SfxGetpApp()->GetPool() );
753 SfxRequest
aRequest( SID_CONFIG
, SfxCallMode::SYNCHRON
, Args
);
754 aRequest
.AppendItem( aItem
);
755 SfxGetpApp()->ExecuteSlot( aRequest
);
757 else if (pButton
== m_pNewLibButton
)
759 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
760 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
761 ScriptDocument
aDocument( aDesc
.GetDocument() );
762 createLibImpl( static_cast<vcl::Window
*>( this ), aDocument
, NULL
, m_pBasicBox
);
764 else if (pButton
== m_pNewModButton
)
766 SvTreeListEntry
* pCurEntry
= m_pBasicBox
->GetCurEntry();
767 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(pCurEntry
);
768 ScriptDocument
aDocument( aDesc
.GetDocument() );
769 OUString
aLibName( aDesc
.GetLibName() );
771 createModImpl( static_cast<vcl::Window
*>( this ), aDocument
,
772 *m_pBasicBox
, aLibName
, aModName
, true );
774 else if (pButton
== m_pOrganizeButton
)
776 StoreMacroDescription();
778 EntryDescriptor aDesc
= m_pBasicBox
->GetEntryDescriptor(m_pBasicBox
->FirstSelected());
779 VclPtrInstance
< OrganizeDialog
> pDlg( this, 0, aDesc
);
780 sal_uInt16 nRet
= pDlg
->Execute();
783 if ( nRet
) // not only closed
785 EndDialog(Macro_Edit
);
789 Shell
* pShell
= GetShell();
790 if ( pShell
&& pShell
->IsAppBasicModified() )
791 bForceStoreBasic
= true;
793 m_pBasicBox
->UpdateEntries();
800 void MacroChooser::UpdateFields()
802 SvTreeListEntry
* pMacroEntry
= m_pMacroBox
->GetCurEntry();
805 m_pMacroNameEdit
->SetText( aEmptyStr
);
807 m_pMacroNameEdit
->SetText( m_pMacroBox
->GetEntryText( pMacroEntry
) );
810 void MacroChooser::SetMode (Mode nM
)
817 m_pRunButton
->SetText(IDEResId(RID_STR_RUN
).toString());
818 EnableButton(*m_pDelButton
, true);
819 EnableButton(*m_pOrganizeButton
, true);
825 m_pRunButton
->SetText(IDEResId(RID_STR_CHOOSE
).toString());
826 EnableButton(*m_pDelButton
, false);
827 EnableButton(*m_pOrganizeButton
, false);
833 m_pRunButton
->SetText(IDEResId(RID_STR_RECORD
).toString());
834 EnableButton(*m_pDelButton
, false);
835 EnableButton(*m_pOrganizeButton
, false);
837 m_pAssignButton
->Hide();
838 m_pEditButton
->Hide();
839 m_pDelButton
->Hide();
840 m_pOrganizeButton
->Hide();
841 m_pMacroFromTxT
->Hide();
843 m_pNewLibButton
->Show();
844 m_pNewModButton
->Show();
845 m_pMacrosSaveInTxt
->Show();
853 OUString
MacroChooser::GetInfo( SbxVariable
* pVar
)
856 SbxInfoRef xInfo
= pVar
->GetInfo();
858 aComment
= xInfo
->GetComment();
863 } // namespace basctl
865 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */