'encoding UTF-8 Do not remove or change this line!
'**************************************************************
'
' Licensed to the Apache Software Foundation (ASF) under one
' or more contributor license agreements. See the NOTICE file
' distributed with this work for additional information
' regarding copyright ownership. The ASF licenses this file
' to you under the Apache License, Version 2.0 (the
' "License"); you may not use this file except in compliance
' with the License. You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing,
' software distributed under the License is distributed on an
' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
' KIND, either express or implied. See the License for the
' specific language governing permissions and limitations
' under the License.
'
'**************************************************************
' **
' ** short description : tools for tools/macro test
' **
'\******************************************************************************
function hSelectTheLastModule( bEditEnabled as Boolean ) as string
'///
Select the last (editable) module in the macro seletor treelist
use "global\tools\includes\optional\t_treelist_tools.inc"
const CFN = "hSelectTheLastModule()::"
dim bCloseDialog as boolean : bCloseDialog = FALSE
dim iNodeCount as integer
dim iCurrentNode as integer
hSelectTheLastModule() = ""
kontext "Makro"
if ( not Makro.exists() ) then ToolsMacro_uno : bCloseDialog = TRUE
kontext "Makro"
iNodeCount = hSelectTheLastNode( MakroAus )
if ( bEditEnabled ) then
for iCurrentNode = iNodeCount to 1 step -1
if ( Bearbeiten.isEnabled() ) then
printlog( CFN & "Editable module found at pos: " & iCurrentNode )
exit for
endif
next iCurrentNode
else
printlog( CFN & "Module selected at pos: " & iNodeCount )
endif
if ( iCurrentNode > 1 ) then hSelectTheLastModule = MakroAus.getSelText()
end function
'*******************************************************************************
function hCreateModuleForDoc( optional cName as string ) as boolean
'///Create a new Basic module for the current document
'///Starting point: Basic Macro Organizer is visible and has focus
const CFN = "hCreateModuleForDoc::"
const DEFAULT_WAIT = 2
const RETVAL_FAILURE = 0
if ( isMissing( cName ) ) then cName = "TTModule"
kontext "Makro"
if ( Makro.exists() ) then
if ( hSelectTheLastNode( MakroAus ) > RETVAL_FAILURE ) then
kontext "Makro"
if ( hClickButton( Neu ) ) then
Kontext "NeuesModul"
if ( NeuesModul.exists( DEFAULT_WAIT ) ) then
Modulname.SetText( cName )
hCloseDialog( NeuesModul, "ok" )
kontext "BasicIDE"
if ( BasicIde.exists( DEFAULT_WAIT ) ) then
hCreateModuleForDoc() = true
else
printlog( CFN & "BASIC IDE is not open" )
hCreateModuleForDoc() = false
endif
else
warnlog( CFN & "Dialog did not open" )
hCreateModuleForDoc() = false
endif
else
warnlog( CFN & "Failed to click button" )
hCreateModuleForDoc() = false
endif
else
warnlog( CFN & "Failed to select the last node" )
hCreateModuleForDoc() = false
endif
else
warnlog( CFN & "Macro organizer is not open" )
hCreateModuleForDoc() = false
endif
end function
'*******************************************************************************
function hOpenBasicObjectOrganizer( iTabPage as integer ) as boolean
'///Open the Basic Library/Module/Dialog Organizer
'///Starting point: Basic IDE is open and has focus
'///
const CFN = "hOpenBasicObjectOrganizer::"
' This function opens a specified tab on the BASIC Organizer from the
' BASIC-IDE
' NOTE: This is the organizer for libraries, modules and dialogs,
' not the one to run or assign macros!
'///+- Open the context menu of the tabbar
kontext "basicide"
Tabbar.OpenContextMenu()
'///+- Select the last entry of the context menu (dynamic menu!)
if ( hMenuItemGetCount() = 2 ) then
printlog( " * short context menu (no edit-window)" )
hMenuSelectNr( 2 )
else
printlog( " * long context menu (edit-window/dialog visible)" )
hMenuSelectNr( 5 )
endif
WaitSlot()
'///+- On the basic object organizer switch to the Modules tab
if ( hSelectBasicObjectOrganizerTab( 1 ) ) then
printlog( CFN & "Requested page is open" )
hOpenBasicObjectOrganizer() = true
else
warnlog( CFN & "Failed to open requested Tabpage" )
hOpenBasicObjectOrganizer() = false
endif
'///+- Return TRUE on success, FALSE on failure
'///
end function
'*******************************************************************************
function hSelectBasicObjectOrganizerTab( iTabPage as integer ) as boolean
const CFN = "hSelectBasicObjectOrganizerTab::"
'///Switch between tab pages in the Basic Object Organizer
'///Starting point: Masic Object Organizer is visible and has focus
'///
'///+- 1 = Modules
'///+- 2 = Dialogs
'///+- 3 = Libraries
'///
'///Description:
'///
'///+- Switch between tabpages 1, 2 or 3
select case iTabPage
case 1 :
kontext
Active.SetPage TabModule
kontext "tabmodule"
if ( TabModule.exists() ) then
printlog( CFN & "Modules-Tab is open"
hSelectBasicObjectOrganizerTab() = true
exit function
endif
case 2 :
kontext
Active.setPage TabDialogs
kontext "tabdialogs"
if ( TabDialogs.exists() ) then
printlog( CFN & "Dialogs-Tab is open"
hSelectBasicObjectOrganizerTab() = true
exit function
endif
case 3 :
kontext
Active.setPage TabBibliotheken
kontext "tabbibliotheken"
if ( TabBibliotheken.exists() ) then
printlog( CFN & "Libraries-Tab is open"
hSelectBasicObjectOrganizerTab() = true
exit function
endif
end select
'///+- Return TRUE on success, FALSE on failure
'///
hSelectBasicObjectOrganizerTab() = false
end function
'*******************************************************************************
function hDeleteLibrary( iLocation as integer, cLibName as string ) as boolean
'///Delete a library by name via Macro Object Organizer
'///Starting point: Plain document
'///
const CFN = "hDeleteLibrary::"
const ITABPOS = 3
dim iObjectCount as integer
dim iCurrentObject as integer
dim cCurrentObjectName as string
'///+- Open Macro Organizer
ToolsMacro_uno
'///+- Click Manage-button
Kontext "Makro"
hClickButton( Verwalten )
'///+- Go to the Libraries Tab on the Macro Object Organizer
hSelectBasicObjectOrganizerTab( ITABPOS )
'///+- Select the root node in the libraries treelist
' Needs to be specified to avoid touching the wrong library (e.g. a protected one)
kontext "TabBibliotheken"
Bibliothek.select( iLocation )
iObjectCount = Bibliotheksliste.getItemCount()
'///+- Find the requested item in the treelist
for iCurrentObject = 1 to iObjectCount
Bibliotheksliste.select( iCurrentObject )
cCurrentObjectName = Bibliotheksliste.getSelText()
if ( cCurrentObjectName = cLibName ) then
'///+- Click Delete
hClickButton( Loeschen )
exit for
endif
next iCurrentObject
'///+- Confirm to delete library
Kontext "Active"
if ( Active.exists( 1 ) ) then
active.yes()
else
warnlog( CFN & "No confirmation for delete" )
endif
'///+- Verify that there is one item less in the treelist (object has been deleted)
kontext "TabBibliotheken"
if ( Bibliotheksliste.getItemCount() = ( iObjectCount - 1 ) ) then
printlog( CFN & "Library has been deleted" )
hDeleteLibrary() = true
else
printlog( CFN & "Library has not been deleted" )
hDeleteLibrary() = false
endif
'///+- Cancel Macro Object Organizer
hCloseDialog( TabBibliotheken, "cancel" )
'///+- Cancel Basic Macro Organizer
Kontext "Makro"
hCloseDialog( Makro, "cancel" )
'///+- Return TRUE on success, FALSE on failure
'///
end function
'*******************************************************************************
function hNameBasicModule( cName as string ) as boolean
'///Name a Basic Module
'///Starting point: Clicked "New..." button in Basic Macro organizer.
'///+ On success the kontext will be on the Basic IDE. In case of
'///+ failure we remain on the naming dialog so that the function can be
'///+ triggered again.
'///Input:
'///
'///+- Name of the module (string)
'///
'///Returns:
'///
'///+- Errorcondition (Boolean)
'///
'///+- TRUE if name is valid, module has been created
'///+- FALSE if name is invalid or naming dialog does not exist
'///
'///
'///Description:
'///
const CFN = "hNameBasicModule::"
'///+- Verify that the naming dialog is open
kontext "NeuesModul"
if ( not NeuesModul.exists() ) then
hNameBasicModule() = false
exit function
endif
'///+- Insert the name into the EntryField
Modulname.SetText( cName )
'///+- Accept the name with OK
hCloseDialog( NeuesModul, "ok" )
'///+- If there is no warning, the name should be valid.
kontext "BasicIDE"
if ( BasicIde.exists( 2 ) ) then
hNameBasicModule() = true
printlog( CFN & "Name accepted, Basic-Ide is open" )
else
hNameBasicModule() = false
'///+- Look for invalid name warning, close it
kontext "active"
if ( active.exists() ) then
printlog( CFN & "Msgbox: " & active.exists() )
hCloseDialog( active, "ok" )
endif
'///+- If the name is invalid, get back to the naming-dialog
kontext "NeuesModul"
if ( NeuesModul.exists() ) then
printlog( CFN & "Name not accepted, focus on naming-dialog" )
else
warnlog( CFN & "Naming failed but we are not on the naming dialog" )
endif
endif
'///
end function