1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_basic_organizer_tools.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 07:57:24 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 ' ** owner : joerg.skottke@sun.com
36 ' ** short description : tools for tools/macro test
38 '\******************************************************************************
40 function hSelectTheLastModule( bEditEnabled as Boolean ) as string
42 '///<h3>Select the last (editable) module in the macro seletor treelist</li>
44 use "global\tools\includes\optional\t_treelist_tools.inc"
46 const CFN = "hSelectTheLastModule()::"
48 dim bCloseDialog as boolean : bCloseDialog = FALSE
49 dim iNodeCount as integer
50 dim iCurrentNode as integer
52 hSelectTheLastModule() = ""
55 if ( not Makro.exists() ) then ToolsMacro_uno : bCloseDialog = TRUE
58 iNodeCount = hSelectTheLastNode( MakroAus )
60 if ( bEditEnabled ) then
61 for iCurrentNode = iNodeCount to 1 step -1
62 if ( Bearbeiten.isEnabled() ) then
63 printlog( CFN & "Editable module found at pos: " & iCurrentNode )
68 printlog( CFN & "Module selected at pos: " & iNodeCount )
71 if ( iCurrentNode > 1 ) then hSelectTheLastModule = MakroAus.getSelText()
75 '*******************************************************************************
77 function hCreateModuleForDoc( optional cName as string ) as boolean
79 use "global\tools\includes\optional\t_treelist_tools.inc"
80 use "global\tools\includes\optional\t_stringtools.inc"
82 '///<h3>Create a new Basic module for the current document</h3>
83 '///<i>Starting point: Basic Macro Organizer is visible and has focus</i>
86 const CFN = "hCreateModuleForDoc::"
88 dim iWait as integer ' how long we had to wait for the IDE to open
90 dim brc as boolean ' boolean returncode, a temporary variable
94 ' make sure that we have a name for the module
95 if ( isMissing( cName ) ) Then
99 '///+<li>Select the last module (it should belong to the current document)</li>
101 iPos = hSelectTheLastNode( MakroAus )
103 '///+<li>Click the New-Button, name the module</li>
104 if ( Neu.isEnabled() ) then
105 'printlog( CFN & "New-button is enabled" )
107 warnlog( CFN & "New-button is disabled" )
108 hCreateModuleForDoc() = false
114 '///+<li>If the module already exists we end up on the Deletion dialog</li>
116 if ( Active.exists() ) then
117 cMsg = active.getText()
118 cMsg = hRemoveLineBreaks( cMsg )
119 printlog( "Module seems to exist, deleting Main: " & cMsg )
124 if ( NeuesModul.exists() ) then
125 Modulname.SetText( cName )
128 warnlog( CFN & "Failed create a new module, aborting" )
129 hCreateModuleForDoc() = false
135 '///+<li>Wait for the BASIC_IDE to open, verify</li>
136 ' BasicIDE is bad for "Kontexting", using the default toolbar instead
138 if ( MacroBar.exists( 3 ) ) then
139 printlog( CFN & "Exit: New module: " & cName & ". IDE is open" )
142 warnlog( CFN & "Exit: Failed to create the Module" )
146 hCreateModuleForDoc() = brc
147 '///+<li>Return TRUE on success, FALSE on failure</li>
152 '*******************************************************************************
154 function hOpenBasicObjectOrganizer( iTabPage as integer ) as boolean
156 '///<h3>Open the Basic Library/Module/Dialog Organizer</h3>
157 '///<i>Starting point: Basic IDE is open and has focus</i>
160 const CFN = "hOpenBasicObjectOrganizer::"
162 ' This function opens a specified tab on the BASIC Organizer from the
164 ' NOTE: This is the organizer for libraries, modules and dialogs,
165 ' not the one to run or assign macros!
167 dim iMenuSize as integer
170 '///+<li>Open the context menu of the tabbar</li>
172 Tabbar.OpenContextMenu
174 '///+<li>Select the last entry of the context menu (dynamic menu!)</li>
175 iMenuSize = hMenuItemgetCount()
176 if ( iMenuSize = 2 ) then
177 printlog( " * short context menu (no edit-window)" )
180 printlog( " * long context menu (edit-window/dialog visible)" )
186 '///+<li>On the basic object organizer switch to the Modules tab</li>
187 brc = hSelectBasicObjectOrganizerTab( 1 )
189 warnlog( CFN & "Failed to open requested Tabpage" )
190 hOpenBasicObjectOrganizer() = false
192 printlog( CFN & "Requested page is open" )
193 hOpenBasicObjectOrganizer = true
195 '///+<li>Return TRUE on success, FALSE on failure</li>
201 '*******************************************************************************
203 function hOpenBasicOrganizerFromDoc() as boolean
205 '///<h3>Open the Basic Macro Organizer from a plain document</h3>
206 '///<i>Starting point: Plain document</i>
209 const CFN = "hOpenBasicOrganizerFromDoc::"
211 '///+<li>Use the slot ToolsMacro_uno to open the Basic Macro organizer</li>
214 '///+<li>Verify that the dialog is open</li>
216 if ( not Makro.exists() ) then
217 warnlog( CFN & "Could not open Macro Organizer" )
218 hOpenBasicOrganizerFromDoc() = false
222 call dialogtest( Makro )
224 '///+<li>Return TRUE on success, FALSE on failure</li>
225 printlog( CFN & "Basic Organizer is open" )
226 hOpenBasicOrganizerFromDoc() = true
232 '*******************************************************************************
234 function hSelectBasicObjectOrganizerTab( iTabPage as integer ) as boolean
236 const CFN = "hSelectBasicObjectOrganizerTab::"
238 '///<h3>Switch between tab pages in the Basic Object Organizer</h3>
239 '///<i>Starting point: Masic Object Organizer is visible and has focus</i>
241 '///+<li>1 = Modules</li>
242 '///+<li>2 = Dialogs</li>
243 '///+<li>3 = Libraries</li>
248 '///+<li>Verify function parameters</li>
249 if ( ( iTabPage < 1 ) or ( iTabPage > 3 ) ) then
250 warnlog( CFN & "Illegal argument passed to function: " & iTabPage )
251 hSelectBasicObjectOrganizerTab() = false
255 '///+<li>Switch between tabpages 1, 2 or 3</li>
259 Active.SetPage TabModule
261 if ( TabModule.exists() ) then
262 printlog( CFN & "Modules-Tab is open"
263 hSelectBasicObjectOrganizerTab() = true
269 Active.setPage TabDialogs
271 if ( TabDialogs.exists() ) then
272 printlog( CFN & "Dialogs-Tab is open"
273 hSelectBasicObjectOrganizerTab() = true
278 Active.setPage TabBibliotheken
279 kontext "tabbibliotheken"
280 if ( TabBibliotheken.exists() ) then
281 printlog( CFN & "Libraries-Tab is open"
282 hSelectBasicObjectOrganizerTab() = true
287 '///+<li>Return TRUE on success, FALSE on failure</li>
289 hSelectBasicObjectOrganizerTab() = false
293 '*******************************************************************************
295 function hDeleteLibrary( iLocation as integer, cLibName as string ) as boolean
297 '///<h3>Delete a library by name via Macro Object Organizer</h3>
298 '///<i>Starting point: Plain document</i>
301 const CFN = "hDeleteLibrary::"
304 '///+<li>Verify function parameters</li>
305 if ( ( iLocation < 1 ) or ( iLocation > 3 ) ) then
306 warnlog( CFN & "Invalid parameter passed to function" )
307 hDeleteLibrary() = false
310 dim iObjectCount as integer
311 dim iCurrentObject as integer
312 dim cCurrentObjectName as string
314 '///+<li>Open Macro Organizer</li>
315 hOpenBasicOrganizerFromDoc()
317 '///+<li>Click Manage-button</li>
321 '///+<li>Go to the Libraries Tab on the Macro Object Organizer</li>
322 hSelectBasicObjectOrganizerTab( ITABPOS )
324 '///+<li>Select the root node in the libraries treelist</li>
325 ' Needs to be specified to avoid touching the wrong library (e.g. a protected one)
326 kontext "TabBibliotheken"
327 Bibliothek.select( iLocation )
328 iObjectCount = Bibliotheksliste.getItemCount()
330 '///+<li>Find the requested item in the treelist</li>
331 for iCurrentObject = 1 to iObjectCount
333 Bibliotheksliste.select( iCurrentObject )
334 cCurrentObjectName = Bibliotheksliste.getSelText()
335 if ( cCurrentObjectName = cLibName ) then
337 '///+<li>Click Delete</li>
344 '///+<li>Confirm to delete library</li>
346 if ( Active.exists() ) then
349 warnlog( CFN & "No confirmation for delete" )
352 '///+<li>Verify that there is one item less in the treelist (object has been deleted)</li>
353 kontext "TabBibliotheken"
354 if ( Bibliotheksliste.getItemCount() = ( iObjectCount - 1 ) ) then
355 printlog( CFN & "Library has been deleted" )
356 hDeleteLibrary() = true
358 printlog( CFN & "Library has not been deleted" )
359 hDeleteLibrary() = false
362 '///+<li>Cancel Macro Object Organizer</li>
363 TabBibliotheken.cancel()
365 '///+<li>Cancel Basic Macro Organizer</li>
368 '///+<li>Return TRUE on success, FALSE on failure</li>
373 '*******************************************************************************
375 function hIsMacroEditButtonEnabled() as boolean
377 '///<h3>Test whether the "Edit..." button is enabled or not</h3>
378 '///<i>Starting point: Basic Macro Organizer</i>
381 const CFN = "hIsMacroEditButtonEnabled::"
384 '///+<li>Check that the macro dialog is open</li>
386 if ( not Makro.exists() ) then
387 warnlog( "Macro organizer is not open, aborting function" )
388 hIsMacroEditButtonEnabled() = false
392 '///+<li>Verify that the Edit...-Button exists and is enabled</li>
393 if ( bearbeiten.exists() ) then
394 if ( bearbeiten.isEnabled() ) then
395 printlog( CFN & "Button exists and is enabled" )
398 printlog( CFN & "Button exists but is disabled" )
402 warnlog( CFN & "Button does not exist" )
406 '///+<li>Return TRUE if button exists and is enabled</li>
408 hIsMacroEditButtonEnabled() = brc
412 '*******************************************************************************
414 function hIsMacroNewButtonEnabled() as boolean
416 '///<h3>Find out whether the "New..." button is enabled or not</h3>
417 '///<i>Starting point: Basic Macro Organizer</i>
420 const CFN = "hIsMacroNewButtonEnabled::"
423 '///+<li>Check that the macro dialog is open</li>
425 if ( not Makro.exists() ) then
426 warnlog( "Macro organizer is not open, aborting function" )
427 hIsMacroNewButtonEnabled() = false
431 '///+<li>Verify that the New...-Button exists and is enabled</li>
432 if ( neu.exists() ) then
433 if ( neu.isEnabled() ) then
434 printlog( CFN & "Button exists and is enabled" )
437 printlog( CFN & "Button exists but is disabled" )
441 warnlog( CFN & "Button does not exist" )
445 '///+<li>Return TRUE if button exists and is enabled</li>
447 hIsMacroNewButtonEnabled() = brc
451 '*******************************************************************************
453 function hNameBasicModule( cName as string ) as boolean
455 '///<h3>Name a Basic Module</h3>
456 '///<i>Starting point: Clicked "New..." button in Basic Macro organizer.<br>
457 '///+ On success the kontext will be on the Basic IDE. In case of
458 '///+ failure we remain on the naming dialog so that the function can be
459 '///+ triggered again.</i><br>
462 '///+<li>Name of the module (string)</li>
466 '///+<li>Errorcondition (Boolean)</li>
468 '///+<li>TRUE if name is valid, module has been created</li>
469 '///+<li>FALSE if name is invalid or naming dialog does not exist</li>
472 '///<u>Description</u>:
475 use "global\tools\includes\optional\t_stringtools.inc"
477 const CFN = "hNameBasicModule::"
482 '///+<li>Verify that the naming dialog is open</li>
484 if ( not NeuesModul.exists() ) then
485 hNameBasicModule() = false
489 '///+<li>Insert the name into the EntryField</li>
490 Modulname.SetText( cName )
492 '///+<li>Accept the name with OK</li>
495 '///+<li>If there is no warning, the name should be valid.</li>
497 if ( BasicIde.exists( 2 ) ) then
499 printlog( CFN & "Name accepted, Basic-Ide is open" )
502 '///+<li>Look for invalid name warning, close it</li>
504 if ( active.exists() ) then
505 cMsg = active.getText()
506 cMsg = hRemoveLineBreaks( cMsg
507 printlog( CFN & "Msgbox: " & cMsg )
511 '///+<li>If the name is invalid, get back to the naming-dialog</li>
513 if ( NeuesModul.exists() ) then
514 printlog( CFN & "Name not accepted, focus on naming-dialog" )
516 warnlog( CFN & "Naming failed but we are not on the naming dialog" )
520 hNameBasicModule() = brc