1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ScriptBinding" script:language="StarBasic">REM ***** BASIC ***** 4*cdf0e10cSrcweir 5*cdf0e10cSrcweirREM ----- Global Variables ----- 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir'bindingDialog can refer to either KeyBinding or MenuBinding dialog 8*cdf0e10cSrcweirprivate languages() as String 9*cdf0e10cSrcweirprivate extensions() as Object 10*cdf0e10cSrcweirprivate locations() as String 11*cdf0e10cSrcweirprivate filesysScripts() as String 12*cdf0e10cSrcweirprivate filesysCount as integer 13*cdf0e10cSrcweirprivate bindingDialog as object 14*cdf0e10cSrcweirprivate helpDialog as object 15*cdf0e10cSrcweir'Couldn't get redim to work, so scriptDisplayList is and array of arrays 16*cdf0e10cSrcweir'where the one and only array in scriptDisplayList is an array 17*cdf0e10cSrcweir'of com.sun.star.beans.PropertyValue, where Name = [logicalName][FunctionName] 18*cdf0e10cSrcweir'and value is ScriptStorage object 19*cdf0e10cSrcweirprivate scriptDisplayList(0) 20*cdf0e10cSrcweirprivate testArray() as String 21*cdf0e10cSrcweir'Array to store lines from the xml file 22*cdf0e10cSrcweirprivate xmlFile() as string 23*cdf0e10cSrcweir'Name of the xml file [writer/calc][menubar/keybindings].xml 24*cdf0e10cSrcweirprivate xmlFileName as string 25*cdf0e10cSrcweir'Number of lines in the xml file 26*cdf0e10cSrcweirprivate numberOfLines as integer 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir'Parallel arrays to store all top-level menu names and line positions 29*cdf0e10cSrcweirprivate menuItems() as string 30*cdf0e10cSrcweirprivate menuItemLinePosition() as integer 31*cdf0e10cSrcweir'Counter for the number of top-level menus 32*cdf0e10cSrcweirprivate menuCount as integer 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir'Parallel arrays to store all sub-menu names and line positions for a particular top-level menu 35*cdf0e10cSrcweirprivate subMenuItems() as string 36*cdf0e10cSrcweirprivate subMenuItemLinePosition() as integer 37*cdf0e10cSrcweir'Counter for the number of sub-menus 38*cdf0e10cSrcweirprivate subMenuCount as integer 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir'Parallel arrays to store all script names and line positions 41*cdf0e10cSrcweirprivate scriptNames() as string 42*cdf0e10cSrcweirprivate scriptLinePosition() as integer 43*cdf0e10cSrcweir'Counter for the number of scripts 44*cdf0e10cSrcweirprivate scriptCount as integer 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir'Array to store all combinations of key bindings 47*cdf0e10cSrcweirprivate allKeyBindings() as string 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir'Array of Arrays 50*cdf0e10cSrcweir'KeyBindArrayOfArrays(0) contains array of "SHIFT + CONTROL + F Keys" data 51*cdf0e10cSrcweir'Similarly 52*cdf0e10cSrcweir'KeyBindArrayOfArrays(1) contains SHIFT + CONTROL + digits 53*cdf0e10cSrcweir'KeyBindArrayOfArrays(2) contains SHIFT + CONTROL + letters 54*cdf0e10cSrcweir'KeyBindArrayOfArrays(3) contains CONTROL + F keys 55*cdf0e10cSrcweir'KeyBindArrayOfArrays(4) contains CONTROL + digits 56*cdf0e10cSrcweir'KeyBindArrayOfArrays(5) contains CONTROL + letters 57*cdf0e10cSrcweir'KeyBindArrayOfArrays(6) contains SHIFT + F keys 58*cdf0e10cSrcweirprivate KeyBindArrayOfArrays(6) 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir'Each PropertyValue represents a key, Name member contains the script (if a binding exists) 61*cdf0e10cSrcweir' the Value contains and integer 62*cdf0e10cSrcweir' 0 means no script bound 63*cdf0e10cSrcweir' 1 script is bound to an office function 64*cdf0e10cSrcweir' >1 line number of entry in xmlfile array 65*cdf0e10cSrcweirprivate keyAllocationMap(6,25) as new com.sun.star.beans.PropertyValue 66*cdf0e10cSrcweir'array to store key group descriptions 67*cdf0e10cSrcweirprivate AllKeyGroupsArray(6) as String 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir'Array of props to store all event bindings for the Applications 71*cdf0e10cSrcweirprivate allEventTypesApp( 14 ) as new com.sun.star.beans.PropertyValue 72*cdf0e10cSrcweir'Array of props to store all event bindings for the Document 73*cdf0e10cSrcweirprivate allEventTypesDoc( 14 ) as new com.sun.star.beans.PropertyValue 74*cdf0e10cSrcweir'Array of props to store all event types (Name) and textual description (Value) 75*cdf0e10cSrcweirprivate allEventTypes( 14 ) as new com.sun.star.beans.PropertyValue 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweirprivate dialogName as String 79*cdf0e10cSrcweirREM ------ Storage Refresh Function ------ 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweirsub RefreshUserScripts() 83*cdf0e10cSrcweir' TDB - change Menu bindings to allow user to refresh all, user, share or document script 84*cdf0e10cSrcweir RefreshAppScripts( "USER" ) 85*cdf0e10cSrcweirend sub 86*cdf0e10cSrcweir 87*cdf0e10cSrcweirsub RefreshAllScripts() 88*cdf0e10cSrcweir RefreshAppScripts( "USER" ) 89*cdf0e10cSrcweir RefreshAppScripts( "SHARE" ) 90*cdf0e10cSrcweir RefreshDocumentScripts 91*cdf0e10cSrcweirend sub 92*cdf0e10cSrcweir 93*cdf0e10cSrcweirsub RefreshAppScripts( appName as String ) 94*cdf0e10cSrcweir On Error Goto ErrorHandler 95*cdf0e10cSrcweir smgr = getProcessServiceManager() 96*cdf0e10cSrcweir context = smgr.getPropertyValue( "DefaultContext" ) 97*cdf0e10cSrcweir scriptstoragemgr = context.getValueByName( "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager" ) 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir scriptstoragemgr.refreshScriptStorage( appName ) 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir Exit sub 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir ErrorHandler: 104*cdf0e10cSrcweir reset 105*cdf0e10cSrcweir MsgBox ("Error: Unable to refresh Java (scripts)" + chr$(10) + chr$(10)+ "Detail: " & error$ + chr$(10) + chr$(10)+ "Action: Please restart Office",0,"Error" ) 106*cdf0e10cSrcweir 107*cdf0e10cSrcweirend sub 108*cdf0e10cSrcweir 109*cdf0e10cSrcweirsub RefreshDocumentScripts() 110*cdf0e10cSrcweir On Error Goto ErrorHandler 111*cdf0e10cSrcweir smgr = getProcessServiceManager() 112*cdf0e10cSrcweir context = smgr.getPropertyValue( "DefaultContext" ) 113*cdf0e10cSrcweir scriptstoragemgr = context.getValueByName( "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager" ) 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir oDocURL = ThisComponent.GetCurrentController.getModel.getURL 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir On Error Goto ErrorHandlerDoc 118*cdf0e10cSrcweir scriptstoragemgr.refreshScriptStorage( oDocURL ) 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir Exit sub 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ErrorHandlerDoc: 123*cdf0e10cSrcweir reset 124*cdf0e10cSrcweir ' Ignore document script errors as it will happen when refreshing an unsaved doc 125*cdf0e10cSrcweir Exit sub 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir ErrorHandler: 128*cdf0e10cSrcweir reset 129*cdf0e10cSrcweir MsgBox ("Error: Unable to refresh Java (scripts)" + chr$(10) + chr$(10)+ "Detail: " & error$ + chr$(10) + chr$(10)+ "Action: Please restart Office",0,"Error" ) 130*cdf0e10cSrcweir 131*cdf0e10cSrcweirend sub 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir 134*cdf0e10cSrcweirREM ----- Launch Functions ----- 135*cdf0e10cSrcweir 136*cdf0e10cSrcweirSub createAndPopulateKeyArrays() 137*cdf0e10cSrcweir 'Create SHIFT + CONTROL + F keys array 138*cdf0e10cSrcweir 'Dim keyGroupProp as new com.sun.star.beans.PropertyValue 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir Dim SCFKey( 11 ) 141*cdf0e10cSrcweir for FKey = 1 to 12 142*cdf0e10cSrcweir SCFKey( FKey - 1 ) = "SHIFT + CONTROL + F" + FKey 143*cdf0e10cSrcweir next FKey 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir KeyBindArrayOfArrays(0) = SCFKey() 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 'Create SHIFT + CONTROL + digits 148*cdf0e10cSrcweir Dim SCDKey( 9 ) 149*cdf0e10cSrcweir for Digit = 0 to 9 150*cdf0e10cSrcweir SCDKey( Digit ) = "SHIFT + CONTROL + " + Digit 151*cdf0e10cSrcweir next Digit 152*cdf0e10cSrcweir KeyBindArrayOfArrays(1) = SCDKey() 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir 'Create SHIFT + CONTROL + letters 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir Dim SCLKey( 25 ) 157*cdf0e10cSrcweir for Alpha = 65 to 90 158*cdf0e10cSrcweir SCLKey( Alpha - 65 ) = "SHIFT + CONTROL + " + chr$( Alpha ) 159*cdf0e10cSrcweir next Alpha 160*cdf0e10cSrcweir KeyBindArrayOfArrays(2) = SCLKey() 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir 'Create CONTROL + F keys 163*cdf0e10cSrcweir Dim CFKey( 11 ) 164*cdf0e10cSrcweir for FKey = 1 to 12 165*cdf0e10cSrcweir CFKey( Fkey - 1 ) = "CONTROL + F" + FKey 166*cdf0e10cSrcweir next FKey 167*cdf0e10cSrcweir KeyBindArrayOfArrays(3) = CFKey() 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 'Create CONTROL + digits 170*cdf0e10cSrcweir Dim CDKey( 9 ) 171*cdf0e10cSrcweir for Digit = 0 to 9 172*cdf0e10cSrcweir CDKey( Digit ) = "CONTROL + " + Digit 173*cdf0e10cSrcweir next Digit 174*cdf0e10cSrcweir KeyBindArrayOfArrays(4) = CDKey() 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir 'Create CONTROL + letters 177*cdf0e10cSrcweir Dim CLKey( 25 ) 178*cdf0e10cSrcweir for Alpha = 65 to 90 179*cdf0e10cSrcweir CLKey( Alpha - 65 ) = "CONTROL + " + chr$( Alpha ) 180*cdf0e10cSrcweir next Alpha 181*cdf0e10cSrcweir KeyBindArrayOfArrays(5) = CLKey() 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 'Create SHIFT + F Keys 184*cdf0e10cSrcweir Dim SFKey( 11 ) 185*cdf0e10cSrcweir for FKey = 1 to 12 186*cdf0e10cSrcweir SFKey( Fkey - 1 ) = "SHIFT + F" + FKey 187*cdf0e10cSrcweir next FKey 188*cdf0e10cSrcweir KeyBindArrayOfArrays(6) = SFKey() 189*cdf0e10cSrcweir 190*cdf0e10cSrcweirEnd Sub 191*cdf0e10cSrcweir 192*cdf0e10cSrcweirSub updateMapWithDisabledKeys() 193*cdf0e10cSrcweir 'disable CONTROL + F1 & 194*cdf0e10cSrcweir keyAllocationMap( 3, 0 ).Value = 1 195*cdf0e10cSrcweir keyAllocationMap( 3, 0 ).Name = "" 196*cdf0e10cSrcweir 'disable CONTROL + F4 & 197*cdf0e10cSrcweir keyAllocationMap( 3, 3 ).Value = 1 198*cdf0e10cSrcweir keyAllocationMap( 3, 3 ).Name = "" 199*cdf0e10cSrcweir 'disable CONTROL + F6 200*cdf0e10cSrcweir keyAllocationMap( 3, 5 ).Value = 1 201*cdf0e10cSrcweir keyAllocationMap( 3, 5 ).Name = "" 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir 'disable SHIFT + F1 & 205*cdf0e10cSrcweir keyAllocationMap( 6, 0 ).Value = 1 206*cdf0e10cSrcweir keyAllocationMap( 6, 0 ).Name = "" 207*cdf0e10cSrcweir 'disable SHIFT + F2 & 208*cdf0e10cSrcweir keyAllocationMap( 6, 1 ).Value = 1 209*cdf0e10cSrcweir keyAllocationMap( 6, 1 ).Name = "" 210*cdf0e10cSrcweir 'disable SHIFT + F6 & 211*cdf0e10cSrcweir keyAllocationMap( 6, 5 ).Value = 1 212*cdf0e10cSrcweir keyAllocationMap( 6, 5 ).Name = "" 213*cdf0e10cSrcweir 214*cdf0e10cSrcweirEnd Sub 215*cdf0e10cSrcweir 216*cdf0e10cSrcweirSub initialiseFileExtensions() 217*cdf0e10cSrcweir ReDim extensions(ubound(languages())+1) as Object 218*cdf0e10cSrcweir oConfigProvider = CreateUnoService( "com.sun.star.configuration.ConfigurationProvider" ) 219*cdf0e10cSrcweir Dim configArgs(1) as new com.sun.star.beans.PropertyValue 220*cdf0e10cSrcweir configargs(0).Name = "nodepath" 221*cdf0e10cSrcweir configArgs(0).Value = "org.openoffice.Office.Scripting/ScriptRuntimes" 222*cdf0e10cSrcweir configargs(1).Name = "lazywrite" 223*cdf0e10cSrcweir configArgs(1).Value = false 224*cdf0e10cSrcweir oConfigAccess = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", configArgs()) 225*cdf0e10cSrcweir for index = 0 to ubound(languages()) 226*cdf0e10cSrcweir if(languages(index) <> "Java") then 227*cdf0e10cSrcweir xPropSet = oConfigAccess.getByName(languages(index)) 228*cdf0e10cSrcweir extns() = xPropSet.getPropertyValue("SupportedFileExtensions") 229*cdf0e10cSrcweir extensions(index) = extns() 230*cdf0e10cSrcweir endif 231*cdf0e10cSrcweir next index 232*cdf0e10cSrcweirend sub 233*cdf0e10cSrcweir 234*cdf0e10cSrcweirSub ExecuteEditDebug() 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir locations = Array ( "User", "Share", "Document", "Filesystem" ) 237*cdf0e10cSrcweir languages = Array ( "BeanShell", "JavaScript" ) 238*cdf0e10cSrcweir dialogName = "EditDebug" 239*cdf0e10cSrcweir initialiseFileExtensions() 240*cdf0e10cSrcweir bindingDialog = LoadDialog( "ScriptBindingLibrary", "EditDebug" ) 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir PopulateLanguageCombo() 243*cdf0e10cSrcweir PopulateLocationCombo() 244*cdf0e10cSrcweir PopulateScriptList( languages(0), locations(0) ) 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir bindingDialog.execute() 247*cdf0e10cSrcweirEnd Sub 248*cdf0e10cSrcweir 249*cdf0e10cSrcweirSub ExecuteKeyBinding() 250*cdf0e10cSrcweir dialogName = "Key" 251*cdf0e10cSrcweir createAndPopulateKeyArrays() 252*cdf0e10cSrcweir updateMapWithDisabledKeys() 253*cdf0e10cSrcweir xmlFileName = GetDocumentType( "Key" ) 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if not (ReadXMLToArray( "Key" )) then 256*cdf0e10cSrcweir Exit Sub 257*cdf0e10cSrcweir endif 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir bindingDialog = LoadDialog( "ScriptBindingLibrary", "KeyBinding" ) 260*cdf0e10cSrcweir PopulateKeyBindingList(0) 261*cdf0e10cSrcweir initialiseNavigationComboArrays() 262*cdf0e10cSrcweir PopulateLanguageCombo() 263*cdf0e10cSrcweir PopulateLocationCombo() 264*cdf0e10cSrcweir PopulateScriptList( languages(0), locations(0) ) 265*cdf0e10cSrcweir PopulateTopLevelKeyBindingList() 266*cdf0e10cSrcweir bindingDialog.execute() 267*cdf0e10cSrcweirend Sub 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir 270*cdf0e10cSrcweirSub initialiseNavigationComboArrays() 271*cdf0e10cSrcweir locations = Array ( "User", "Share", "Document", "Filesystem" ) 272*cdf0e10cSrcweir ReDim languages(0) as String 273*cdf0e10cSrcweir ReDim extensions(0) as Object 274*cdf0e10cSrcweir languages(0) = "Java" 275*cdf0e10cSrcweir REM extensions(0) = "" 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir ' Setup languages array for all supported languages 278*cdf0e10cSrcweir oServiceManager = GetProcessServiceManager() 279*cdf0e10cSrcweir svrArray = oServiceManager.getAvailableServiceNames 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir langCount = 1 282*cdf0e10cSrcweir for index = 0 to ubound(svrArray) 283*cdf0e10cSrcweir iPos = inStr(svrArray(index), "ScriptProviderFor") 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if (iPos > 0) then 286*cdf0e10cSrcweir lang = Mid(svrArray(index), iPos + Len("ScriptProviderFor") 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir if not (lang = "Java") then 289*cdf0e10cSrcweir 'Add to language vector 290*cdf0e10cSrcweir ReDim Preserve languages(langCount) as String 291*cdf0e10cSrcweir languages(langCount) = lang 292*cdf0e10cSrcweir langCount = langCount + 1 293*cdf0e10cSrcweir endif 294*cdf0e10cSrcweir endif 295*cdf0e10cSrcweir next index 296*cdf0e10cSrcweir initialiseFileExtensions() 297*cdf0e10cSrcweirEnd Sub 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir 300*cdf0e10cSrcweirSub ExecuteEventBinding 301*cdf0e10cSrcweir dialogName = "Event" 302*cdf0e10cSrcweir createAllEventTypes() 303*cdf0e10cSrcweir createAllEventBindings() 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir 'Populate application event bindings array (from config xml file) 306*cdf0e10cSrcweir if not (ReadXMLToArray( "Event" )) then 307*cdf0e10cSrcweir Exit Sub 308*cdf0e10cSrcweir endif 309*cdf0e10cSrcweir 'Populate document event bindings array (using Office API calls) 310*cdf0e10cSrcweir ReadEventsFromDoc() 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir bindingDialog = LoadDialog( "ScriptBindingLibrary", "EventsBinding" ) 313*cdf0e10cSrcweir initialiseNavigationComboArrays() 314*cdf0e10cSrcweir PopulateLanguageCombo() 315*cdf0e10cSrcweir PopulateLocationCombo() 316*cdf0e10cSrcweir PopulateScriptList( languages(0), locations(0) ) 317*cdf0e10cSrcweir populateEventList( 0 ) 318*cdf0e10cSrcweir EventListListener() 319*cdf0e10cSrcweir bindingDialog.execute() 320*cdf0e10cSrcweirEnd Sub 321*cdf0e10cSrcweir 322*cdf0e10cSrcweirSub ExecuteMenuBinding() 323*cdf0e10cSrcweir dialogName = "Menu" 324*cdf0e10cSrcweir xmlFileName = GetDocumentType( "Menu" ) 325*cdf0e10cSrcweir if not (ReadXMLToArray( "Menu" )) then 326*cdf0e10cSrcweir Exit Sub 327*cdf0e10cSrcweir endif 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir bindingDialog = LoadDialog( "ScriptBindingLibrary", "MenuBinding" ) 330*cdf0e10cSrcweir initialiseNavigationComboArrays() 331*cdf0e10cSrcweir PopulateLanguageCombo() 332*cdf0e10cSrcweir PopulateLocationCombo() 333*cdf0e10cSrcweir PopulateScriptList( languages(0), locations(0) ) 334*cdf0e10cSrcweir PopulateMenuCombo() 335*cdf0e10cSrcweir PopulateSubMenuList( 1 ) 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir subMenuList = bindingDialog.getControl("SubMenuList") 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir subMenuList.selectItemPos( 0, true ) 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir bindingDialog.execute() 342*cdf0e10cSrcweirend Sub 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir 345*cdf0e10cSrcweirREM ----- Initialising functions ----- 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir 348*cdf0e10cSrcweirfunction LoadDialog( libName as string, dialogName as string ) as object 349*cdf0e10cSrcweir dim library as object 350*cdf0e10cSrcweir dim libDialog as object 351*cdf0e10cSrcweir dim runtimeDialog as object 352*cdf0e10cSrcweir libContainer = DialogLibraries 353*cdf0e10cSrcweir libContainer.LoadLibrary( libName ) 354*cdf0e10cSrcweir library = libContainer.getByName( libname ) 355*cdf0e10cSrcweir libDialog = library.getByName( dialogName ) 356*cdf0e10cSrcweir runtimeDialog = CreateUnoDialog( libDialog ) 357*cdf0e10cSrcweir LoadDialog() = runtimeDialog 358*cdf0e10cSrcweir 359*cdf0e10cSrcweirend function 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir 362*cdf0e10cSrcweirfunction GetDocumentType( bindingType as string ) as string 363*cdf0e10cSrcweir document = StarDesktop.ActiveFrame.Controller.Model 364*cdf0e10cSrcweir Dim errornumber As Integer 365*cdf0e10cSrcweir errornumber = 111 366*cdf0e10cSrcweir Error errornumber 367*cdf0e10cSrcweir if document.SupportsService("com.sun.star.sheet.SpreadsheetDocument") then 368*cdf0e10cSrcweir if bindingType = "Key" then 369*cdf0e10cSrcweir GetDocumentType() = "calckeybinding.xml" 370*cdf0e10cSrcweir else 371*cdf0e10cSrcweir if bindingType = "Menu" then 372*cdf0e10cSrcweir GetDocumentType() = "calcmenubar.xml" 373*cdf0e10cSrcweir end if 374*cdf0e10cSrcweir end if 375*cdf0e10cSrcweir elseif document.SupportsService("com.sun.star.text.TextDocument") then 376*cdf0e10cSrcweir if bindingType = "Key" then 377*cdf0e10cSrcweir GetDocumentType() = "writerkeybinding.xml" 378*cdf0e10cSrcweir else 379*cdf0e10cSrcweir if bindingType = "Menu" then 380*cdf0e10cSrcweir GetDocumentType() = "writermenubar.xml" 381*cdf0e10cSrcweir end if 382*cdf0e10cSrcweir end if 383*cdf0e10cSrcweir elseif document.SupportsService("com.sun.star.presentation.PresentationDocument") then 384*cdf0e10cSrcweir if bindingType = "Key" then 385*cdf0e10cSrcweir GetDocumentType() = "impresskeybinding.xml" 386*cdf0e10cSrcweir else 387*cdf0e10cSrcweir if bindingType = "Menu" then 388*cdf0e10cSrcweir GetDocumentType() = "impressmenubar.xml" 389*cdf0e10cSrcweir end if 390*cdf0e10cSrcweir end if 391*cdf0e10cSrcweir elseif document.SupportsService("com.sun.star.presentation.PresentationDocument") then 392*cdf0e10cSrcweir if bindingType = "Key" then 393*cdf0e10cSrcweir GetDocumentType() = "impresskeybinding.xml" 394*cdf0e10cSrcweir else 395*cdf0e10cSrcweir if bindingType = "Menu" then 396*cdf0e10cSrcweir GetDocumentType() = "impressmenubar.xml" 397*cdf0e10cSrcweir end if 398*cdf0e10cSrcweir end if 399*cdf0e10cSrcweir elseif document.SupportsService("com.sun.star.drawing.DrawingDocument") then 400*cdf0e10cSrcweir if bindingType = "Key" then 401*cdf0e10cSrcweir GetDocumentType() = "drawkeybinding.xml" 402*cdf0e10cSrcweir else 403*cdf0e10cSrcweir if bindingType = "Menu" then 404*cdf0e10cSrcweir GetDocumentType() = "drawmenubar.xml" 405*cdf0e10cSrcweir end if 406*cdf0e10cSrcweir end if 407*cdf0e10cSrcweir else 408*cdf0e10cSrcweir MsgBox ("Error: Couldn't determine configuration file type" + chr$(10) + chr$(10) + "Action: Please reinstall Scripting Framework",0,"Error" ) 409*cdf0e10cSrcweir end if 410*cdf0e10cSrcweirend function 411*cdf0e10cSrcweir 412*cdf0e10cSrcweirfunction lastIndexOf( targetStr as String, substr as String ) as Integer 413*cdf0e10cSrcweir copyStr = targetStr 414*cdf0e10cSrcweir while instr(copyStr, substr) > 0 415*cdf0e10cSrcweir pos = instr(copyStr, substr) 416*cdf0e10cSrcweir tpos = tpos + pos 417*cdf0e10cSrcweir copyStr = mid(copyStr, pos+1, len(copyStr)-pos ) 418*cdf0e10cSrcweir wend 419*cdf0e10cSrcweir lastIndexOf() = tpos 420*cdf0e10cSrcweirend function 421*cdf0e10cSrcweir 422*cdf0e10cSrcweirfunction getScriptURI( selectedScript as String ) as String 423*cdf0e10cSrcweir combo = bindingDialog.getControl( "LocationCombo" ) 424*cdf0e10cSrcweir location = combo.text 425*cdf0e10cSrcweir if ( location = "User" ) then 426*cdf0e10cSrcweir location = "user" 427*cdf0e10cSrcweir elseif ( location = "Share" ) then 428*cdf0e10cSrcweir location = "share" 429*cdf0e10cSrcweir elseif ( location = "Filesystem" ) then 430*cdf0e10cSrcweir location = "filesystem" 431*cdf0e10cSrcweir else 432*cdf0e10cSrcweir location = "document" 433*cdf0e10cSrcweir end if 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if ( location = "filesystem" ) then 438*cdf0e10cSrcweir REM need to build URI here - dcf 439*cdf0e10cSrcweir combo = bindingDialog.getControl( "LanguageCombo" ) 440*cdf0e10cSrcweir language = combo.text 441*cdf0e10cSrcweir url = selectedscript 442*cdf0e10cSrcweir pos = lastIndexOf( url, "/" ) 443*cdf0e10cSrcweir locationPath = mid( url, 1, pos) 444*cdf0e10cSrcweir url = mid( url, pos+1, len( url ) - pos ) 445*cdf0e10cSrcweir functionName = url 446*cdf0e10cSrcweir pos = lastIndexOf( url, "." ) 447*cdf0e10cSrcweir logicalName = mid( url, 1, pos - 1 ) 448*cdf0e10cSrcweir getScriptURI() = "script://" + logicalName + "?language=" _ 449*cdf0e10cSrcweir + language + "&amp;function=" + functionName _ 450*cdf0e10cSrcweir + "&amp;location=filesystem:" + locationPath 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir Dim scriptInfo as Object 453*cdf0e10cSrcweir scripts() = scriptDisplayList(0) 454*cdf0e10cSrcweir for n = LBOUND( scripts() ) to UBOUND( scripts() ) 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir if ( scripts( n ).Name = selectedScript ) then 457*cdf0e10cSrcweir scriptInfo = scripts( n ).Value 458*cdf0e10cSrcweir exit for 459*cdf0e10cSrcweir end if 460*cdf0e10cSrcweir next n 461*cdf0e10cSrcweir getScriptURI() = "script://" + scriptInfo.getLogicalName + "?language=" _ 462*cdf0e10cSrcweir + scriptInfo.getLanguage() + "&amp;function=" + _ 463*cdf0e10cSrcweir scriptInfo.getFunctionName() + "&amp;location=" + location 464*cdf0e10cSrcweir end if 465*cdf0e10cSrcweir 466*cdf0e10cSrcweirend function 467*cdf0e10cSrcweir 468*cdf0e10cSrcweirfunction GetOfficePath() as string 469*cdf0e10cSrcweir REM Error check and prompt user to manually input Office Path 470*cdf0e10cSrcweir settings = CreateUnoService( "com.sun.star.frame.Settings" ) 471*cdf0e10cSrcweir path = settings.getByName( "PathSettings" ) 472*cdf0e10cSrcweir unformattedOfficePath = path.getPropertyValue( "UserPath" ) 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir dim officePath as string 475*cdf0e10cSrcweir const removeFromEnd = "/user" 476*cdf0e10cSrcweir const removeFromEndWindows = "\user" 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir REM If Solaris or Linux 479*cdf0e10cSrcweir if not ( instr( unformattedOfficePath, removeFromEnd ) = 0 ) then 480*cdf0e10cSrcweir endPosition = instr( unformattedOfficePath, removeFromEnd ) 481*cdf0e10cSrcweir officePath = mid( unformattedOfficePath, 1, endPosition ) 482*cdf0e10cSrcweir REM If Windows 483*cdf0e10cSrcweir else if not ( instr( unformattedOfficePath, removeFromEndWindows ) = 0 ) then 484*cdf0e10cSrcweir endPosition = instr( unformattedOfficePath, removeFromEndWindows ) 485*cdf0e10cSrcweir officePath = mid( unformattedOfficePath, 1, endPosition ) 486*cdf0e10cSrcweir while instr( officePath, "\" ) > 0 487*cdf0e10cSrcweir backSlash = instr( officePath, "\" ) 488*cdf0e10cSrcweir startPath = mid( officePath, 1, backSlash - 1 ) 489*cdf0e10cSrcweir endPath = mid( officePath, backslash + 1, len( officePath ) - backSlash ) 490*cdf0e10cSrcweir officePath = startPath + "/" + endPath 491*cdf0e10cSrcweir wend 492*cdf0e10cSrcweir else 493*cdf0e10cSrcweir MsgBox ("Error: Office path not found" + chr$(10) + chr$(10) + "Action: Please reinstall Scripting Framework",0,"Error" ) 494*cdf0e10cSrcweir REM Prompt user 495*cdf0e10cSrcweir end if 496*cdf0e10cSrcweir end if 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir GetOfficePath() = officePath 499*cdf0e10cSrcweirend function 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir 503*cdf0e10cSrcweirREM ----- File I/O functions ----- 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir 506*cdf0e10cSrcweirfunction ReadXMLToArray( bindingType as string ) as boolean 507*cdf0e10cSrcweir On Error Goto ErrorHandler 508*cdf0e10cSrcweir if ( bindingType = "Event" ) then 509*cdf0e10cSrcweir xmlfilename = "eventbindings.xml" 510*cdf0e10cSrcweir endif 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir simplefileaccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 513*cdf0e10cSrcweir filestream = simplefileaccess.openFileRead( "file://" + GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName ) 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir textin = CreateUnoService( "com.sun.star.io.TextInputStream" ) 516*cdf0e10cSrcweir textin.setInputStream( filestream ) 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir redim xmlFile( 400 ) as String 519*cdf0e10cSrcweir redim menuItems( 30 ) as String 520*cdf0e10cSrcweir redim menuItemLinePosition( 30 ) as Integer 521*cdf0e10cSrcweir redim scriptNames( 120 ) as string 522*cdf0e10cSrcweir redim scriptLinePosition( 120) as integer 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir lineCount = 1 525*cdf0e10cSrcweir menuCount = 1 526*cdf0e10cSrcweir scriptCount = 1 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir do while not textin.isEOF() 529*cdf0e10cSrcweir xmlline = textin.readLine() 530*cdf0e10cSrcweir xmlFile( lineCount ) = xmlline 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir const menuItemWhiteSpace = 2 533*cdf0e10cSrcweir const menuXMLTag = "<menu:menu" 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir if bindingType = "Menu" then 536*cdf0e10cSrcweir evaluateForMenu( xmlline, lineCount ) 537*cdf0e10cSrcweir elseif bindingType = "Key" then 538*cdf0e10cSrcweir processKeyXMLLine( lineCount, xmlline ) 539*cdf0e10cSrcweir elseif bindingType = "Event" then 540*cdf0e10cSrcweir evaluateForEvent( xmlline, lineCount ) 541*cdf0e10cSrcweir else 542*cdf0e10cSrcweir MsgBox ("Error: Couldn't determine file type" + chr$(10) + chr$(10) + "Action: Please reinstall Scripting Framework",0,"Error" ) 543*cdf0e10cSrcweir end if 544*cdf0e10cSrcweir lineCount = lineCount + 1 545*cdf0e10cSrcweir loop 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir 'Set global variable numberOfLines (lineCount is one too many at end of the loop) 548*cdf0e10cSrcweir numberOfLines = lineCount - 1 549*cdf0e10cSrcweir 'Set global variable menuCount (it is one too many at end of the loop) 550*cdf0e10cSrcweir menuCount = menuCount - 1 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir filestream.closeInput() 553*cdf0e10cSrcweir ReadXMLToArray( ) = true 554*cdf0e10cSrcweir Exit function 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir ErrorHandler: 557*cdf0e10cSrcweir reset 558*cdf0e10cSrcweir MsgBox ("Error: Unable to read Star Office configuration file - " + xmlFileName + chr$(10) + chr$(10) + "Action: Please reinstall Scripting Framework",0,"Error" ) 559*cdf0e10cSrcweir ReadXMLToArray( ) = false 560*cdf0e10cSrcweirend function 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir 564*cdf0e10cSrcweirsub evaluateForMenu( xmlline as string, lineCount as integer ) 565*cdf0e10cSrcweir const menuItemWhiteSpace = 2 566*cdf0e10cSrcweir const menuXMLTag = "<menu:menu" 567*cdf0e10cSrcweir 'If the xml line is a top-level menu 568*cdf0e10cSrcweir if instr( xmlline, menuXMLTag ) = menuItemWhiteSpace then 569*cdf0e10cSrcweir menuLabel = ExtractLabelFromXMLLine( xmlline ) 570*cdf0e10cSrcweir menuItems( menuCount ) = menuLabel 571*cdf0e10cSrcweir menuItemLinePosition( menuCount ) = lineCount 572*cdf0e10cSrcweir menuCount = menuCount + 1 573*cdf0e10cSrcweir end if 574*cdf0e10cSrcweirend sub 575*cdf0e10cSrcweir 576*cdf0e10cSrcweirsub evaluateForEvent( xmlline as string, lineCount as integer ) 577*cdf0e10cSrcweir dim eventName as String 578*cdf0e10cSrcweir 'if the xml line identifies a script or SB macro 579*cdf0e10cSrcweir dim scriptName as string 580*cdf0e10cSrcweir dim lineNumber as integer 581*cdf0e10cSrcweir if instr( xmlline, "event:language=" + chr$(34) + "Script" ) > 0 then 582*cdf0e10cSrcweir eventName = ExtractEventNameFromXMLLine( xmlline ) 583*cdf0e10cSrcweir scriptName = ExtractEventScriptFromXMLLine( xmlline ) 584*cdf0e10cSrcweir lineNumber = lineCount 585*cdf0e10cSrcweir elseif instr( xmlline, "event:language=" + chr$(34) + "StarBasic" ) > 0 then 586*cdf0e10cSrcweir eventName = ExtractEventNameFromXMLLine( xmlline ) 587*cdf0e10cSrcweir scriptName = "Allocated to Office function" 588*cdf0e10cSrcweir lineNumber = 1 589*cdf0e10cSrcweir end if 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir 'Need to sequence to find the corresponding index for the event type 592*cdf0e10cSrcweir for n = 0 to ubound( allEventTypesApp() ) 593*cdf0e10cSrcweir if ( eventName = allEventTypes( n ).Name ) then 594*cdf0e10cSrcweir allEventTypesApp( n ).Name = scriptName 595*cdf0e10cSrcweir allEventTypesApp( n ).Value = lineNumber 596*cdf0e10cSrcweir end if 597*cdf0e10cSrcweir next n 598*cdf0e10cSrcweirend sub 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir 601*cdf0e10cSrcweirfunction isOKscriptProps( props() as Object, eventName as string ) as Boolean 602*cdf0e10cSrcweir On Error Goto ErrorHandler 603*cdf0e10cSrcweir props = ThisComponent.getEvents().getByName( eventName ) 604*cdf0e10cSrcweir test = ubound( props() ) 605*cdf0e10cSrcweir isOKscriptProps() = true 606*cdf0e10cSrcweir exit function 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir ErrorHandler: 609*cdf0e10cSrcweir isOKscriptProps() = false 610*cdf0e10cSrcweirend function 611*cdf0e10cSrcweir 612*cdf0e10cSrcweirsub ReadEventsFromDoc() 613*cdf0e10cSrcweir On Error Goto ErrorHandler 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir eventSupplier = ThisComponent 616*cdf0e10cSrcweir for n = 0 to ubound( allEventTypes() ) 617*cdf0e10cSrcweir Dim scriptProps() as Object 618*cdf0e10cSrcweir if (isOKscriptProps( scriptProps(), allEventTypes( n ).Name) ) then 619*cdf0e10cSrcweir if ( ubound( scriptProps ) > 0 ) then 620*cdf0e10cSrcweir if ( scriptProps(0).Value = "Script" ) then 621*cdf0e10cSrcweir 'Script binding 622*cdf0e10cSrcweir allEventTypesDoc(n).Name = scriptProps(1).Value 623*cdf0e10cSrcweir allEventTypesDoc(n).value = 2 624*cdf0e10cSrcweir elseif( scriptProps(0).Value = "StarBasic" ) then 625*cdf0e10cSrcweir 'StarBasic macro 626*cdf0e10cSrcweir allEventTypesDoc(n).Name = "Allocated to Office function" 627*cdf0e10cSrcweir allEventTypesDoc(n).value = 1 628*cdf0e10cSrcweir end if 629*cdf0e10cSrcweir end if 630*cdf0e10cSrcweir end if 631*cdf0e10cSrcweir next n 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir exit sub 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir ' eventProps is undefined if there are no event bindings in the doc 636*cdf0e10cSrcweir ErrorHandler: 637*cdf0e10cSrcweir reset 638*cdf0e10cSrcweirend sub 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir 641*cdf0e10cSrcweirsub WriteEventsToDoc() 642*cdf0e10cSrcweir On Error Goto ErrorHandler 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir eventSupplier = ThisComponent 645*cdf0e10cSrcweir for n = 0 to ubound( allEventTypes() ) 646*cdf0e10cSrcweir scriptName = allEventTypesDoc( n ).Name 647*cdf0e10cSrcweir eventName = allEventTypes( n ).Name 648*cdf0e10cSrcweir if( allEventTypesDoc( n ).Value > 1 ) then 'script 649*cdf0e10cSrcweir 'add to doc 650*cdf0e10cSrcweir AddEventToDocViaAPI( scriptName, eventName ) 651*cdf0e10cSrcweir elseif( allEventTypesDoc( n ).Value = 0 ) then 'blank (this will "remove" already blank entries) 652*cdf0e10cSrcweir 'remove from doc 653*cdf0e10cSrcweir RemoveEventFromDocViaAPI( eventName ) 654*cdf0e10cSrcweir endif 655*cdf0e10cSrcweir 'Otherwise it is a StarBasic binding - leave alone 656*cdf0e10cSrcweir next n 657*cdf0e10cSrcweir 'Mark document as modified ( should happen automatically as a result of calling the API ) 658*cdf0e10cSrcweir ThisComponent.CurrentController.getModel().setModified( True ) 659*cdf0e10cSrcweir exit sub 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir ErrorHandler: 662*cdf0e10cSrcweir reset 663*cdf0e10cSrcweir msgbox( "Error calling UNO API for writing event bindings to the document" ) 664*cdf0e10cSrcweirend sub 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir 667*cdf0e10cSrcweirsub RemoveEventFromDocViaAPI( event as string ) 668*cdf0e10cSrcweir dim document as object 669*cdf0e10cSrcweir dim dispatcher as object 670*cdf0e10cSrcweir dim parser as object 671*cdf0e10cSrcweir dim url as new com.sun.star.util.URL 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir document = ThisComponent.CurrentController.Frame 674*cdf0e10cSrcweir parser = createUnoService("com.sun.star.util.URLTransformer") 675*cdf0e10cSrcweir dim args(0) as new com.sun.star.beans.PropertyValue 676*cdf0e10cSrcweir args(0).Name = "" 677*cdf0e10cSrcweir args(0).Value = event 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir url.Complete = "script://_$ScriptFrmwrkHelper.removeEvent?" _ 680*cdf0e10cSrcweir + "language=Java&function=ScriptFrmwrkHelper.removeEvent" _ 681*cdf0e10cSrcweir + "&location=share" 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir parser.parseStrict(url) 684*cdf0e10cSrcweir disp = document.queryDispatch(url,"",0) 685*cdf0e10cSrcweir disp.dispatch(url,args()) 686*cdf0e10cSrcweirend sub 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir 689*cdf0e10cSrcweirsub AddEventToDocViaAPI( scriptName as string, eventName as string ) 690*cdf0e10cSrcweir dim properties( 1 ) as new com.sun.star.beans.PropertyValue 691*cdf0e10cSrcweir properties( 0 ).Name = "EventType" 692*cdf0e10cSrcweir properties( 0 ).Value = "Script" 693*cdf0e10cSrcweir properties( 1 ).Name = "Script" 694*cdf0e10cSrcweir properties( 1 ).Value = scriptName 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir eventSupplier = ThisComponent 697*cdf0e10cSrcweir nameReplace = eventSupplier.getEvents() 698*cdf0e10cSrcweir nameReplace.replaceByName( eventName, properties() ) 699*cdf0e10cSrcweirend sub 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir' returns 0 for Fkey 703*cdf0e10cSrcweir' 1 for digit 704*cdf0e10cSrcweir' 2 for letter 705*cdf0e10cSrcweir 706*cdf0e10cSrcweirfunction getKeyTypeOffset( key as String ) as integer 707*cdf0e10cSrcweir length = Len( key ) 708*cdf0e10cSrcweir if ( length > 1 ) then 709*cdf0e10cSrcweir getKeyTypeOffset() = 0 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir elseif ( key >= "0" AND key <= "9" ) then 712*cdf0e10cSrcweir getKeyTypeOffset() = 1 713*cdf0e10cSrcweir else 714*cdf0e10cSrcweir getKeyTypeOffset() = 2 715*cdf0e10cSrcweir end if 716*cdf0e10cSrcweirend function 717*cdf0e10cSrcweir 718*cdf0e10cSrcweirfunction getKeyGroupIndex( key as String, offset as Integer ) as Integer 719*cdf0e10cSrcweir ' Keys we are interested in are A - Z, F2 - F12, 0 - 9 anything else should 720*cdf0e10cSrcweir ' ensure -1 is returned 721*cdf0e10cSrcweir cutKey = mid( key,2 ) 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir if ( cutKey <> "" ) then 724*cdf0e10cSrcweir acode = asc ( mid( cutKey,1,1) ) 725*cdf0e10cSrcweir if ( acode > 57 ) then 726*cdf0e10cSrcweir getKeyGroupIndex() = -1 727*cdf0e10cSrcweir exit function 728*cdf0e10cSrcweir end if 729*cdf0e10cSrcweir end if 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir select case offset 732*cdf0e10cSrcweir case 0: 733*cdf0e10cSrcweir num = cint( cutKey ) 734*cdf0e10cSrcweir getKeyGroupIndex() = num - 1 735*cdf0e10cSrcweir exit function 736*cdf0e10cSrcweir case 1: 737*cdf0e10cSrcweir num = asc( key ) - 48 738*cdf0e10cSrcweir getKeyGroupIndex() = num 739*cdf0e10cSrcweir exit function 740*cdf0e10cSrcweir case 2: 741*cdf0e10cSrcweir num = asc( key ) - 65 742*cdf0e10cSrcweir getKeyGroupIndex() = num 743*cdf0e10cSrcweir exit function 744*cdf0e10cSrcweir end select 745*cdf0e10cSrcweir getKeyGroupIndex() = -1 746*cdf0e10cSrcweirend function 747*cdf0e10cSrcweir 748*cdf0e10cSrcweirSub processKeyXMLLine( lineCount as Integer, xmlline as String ) 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir if instr( xmlline, "<accel:item" ) > 0 then 751*cdf0e10cSrcweir shift = false 752*cdf0e10cSrcweir control = false 753*cdf0e10cSrcweir if instr( xmlline, "accel:shift="+chr$(34)+"true"+chr$(34) ) > 0 then 754*cdf0e10cSrcweir shift = true 755*cdf0e10cSrcweir end if 756*cdf0e10cSrcweir if instr( xmlFile( lineCount ), "accel:mod1="+chr$(34)+"true"+chr$(34) ) > 0 then 757*cdf0e10cSrcweir control = true 758*cdf0e10cSrcweir end if 759*cdf0e10cSrcweir offsetIntoArrayOfArrays = -1 'default unknown 760*cdf0e10cSrcweir if ( control AND shift ) then 761*cdf0e10cSrcweir offsetIntoArrayOfArrays = 0 762*cdf0e10cSrcweir elseif ( control ) then 763*cdf0e10cSrcweir offsetIntoArrayOfArrays = 3 764*cdf0e10cSrcweir elseif ( shift ) then 765*cdf0e10cSrcweir offsetIntoArrayOfArrays = 6 766*cdf0e10cSrcweir endif 767*cdf0e10cSrcweir ' Calculate which of the 7 key group arrays we need to point to 768*cdf0e10cSrcweir key = ExtractKeyCodeFromXMLLine( xmlline ) 769*cdf0e10cSrcweir keyTypeOffset = getKeyTypeOffset( key ) 770*cdf0e10cSrcweir offsetIntoArrayOfArrays = offsetIntoArrayOfArrays + keyTypeOffset 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir ' Calculate from the key the offset into key group array we need to point to 773*cdf0e10cSrcweir KeyGroupIndex = getKeyGroupIndex( key, keyTypeOffset ) 774*cdf0e10cSrcweir if ( offsetIntoArrayOfArrays = -1 ) then 775*cdf0e10cSrcweir 'Unknown key group, no processing necessary 776*cdf0e10cSrcweir Exit Sub 777*cdf0e10cSrcweir end if 778*cdf0e10cSrcweir if ( KeyGroupIndex > -1 ) then 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir ' Determine if a script framework binding is present or not 781*cdf0e10cSrcweir if instr( xmlline, "script://" ) > 0 then 782*cdf0e10cSrcweir ' its one of ours so update its details 783*cdf0e10cSrcweir scriptName = ExtractScriptIdFromXMLLine( xmlline ) 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = lineCount 786*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName 787*cdf0e10cSrcweir else 788*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = 1 789*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = "" 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir end if 792*cdf0e10cSrcweir end if 793*cdf0e10cSrcweir end if 794*cdf0e10cSrcweirEnd Sub 795*cdf0e10cSrcweir 796*cdf0e10cSrcweirSub WriteXMLFromArray() 797*cdf0e10cSrcweir On Error Goto ErrorHandler 798*cdf0e10cSrcweir cfgFile = GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName 799*cdf0e10cSrcweir updateCfgFile( cfgFile ) 800*cdf0e10cSrcweir 'if ( false ) then' config stuff not in build yet 801*cdf0e10cSrcweir if ( true ) then 802*cdf0e10cSrcweir updateConfig( xmlFileName ) 803*cdf0e10cSrcweir else 804*cdf0e10cSrcweir msgbox ("Office must be restarted before your changes will take effect."+ chr$(10)+"Also close the Office QuickStarter (Windows and Linux)", 48, "Assign Script (Java) To Menu" ) 805*cdf0e10cSrcweir endif 806*cdf0e10cSrcweir Exit Sub 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir ErrorHandler: 809*cdf0e10cSrcweir reset 810*cdf0e10cSrcweir MsgBox ("Error: Unable to write to Star Office configuration file" + chr$(10) + "/" + GetOfficePath() + "user/config/soffice.cfg/" +xmlFileName + chr$(10) + chr$(10) + "Action: Please make sure you have write access to this file",0,"Error" ) 811*cdf0e10cSrcweirend Sub 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir 814*cdf0e10cSrcweirSub UpdateCfgFile ( fileName as String ) 815*cdf0e10cSrcweir dim ScriptProvider as Object 816*cdf0e10cSrcweir dim Script as Object 817*cdf0e10cSrcweir dim args(1) 818*cdf0e10cSrcweir dim displayDialogFlag as boolean 819*cdf0e10cSrcweir displayDialogFlag = false 820*cdf0e10cSrcweir args(0) = ThisComponent 821*cdf0e10cSrcweir args(1) = displayDialogFlag 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir ScriptProvider = createUnoService("drafts.com.sun.star.script.framework.provider.MasterScriptProvider") 824*cdf0e10cSrcweir ScriptProvider.initialize( args() ) 825*cdf0e10cSrcweir Script = ScriptProvider.getScript("script://_$ScriptFrmwrkHelper.updateCfgFile?" _ 826*cdf0e10cSrcweir + "language=Java&function=ScriptFrmwrkHelper.updateCfgFile&location=share") 827*cdf0e10cSrcweir Dim inArgs(2) 828*cdf0e10cSrcweir Dim outArgs() 829*cdf0e10cSrcweir Dim outIndex() 830*cdf0e10cSrcweir dim localNumLines as integer 831*cdf0e10cSrcweir 832*cdf0e10cSrcweir inArgs(0) = xmlFile() 833*cdf0e10cSrcweir inArgs(1) = fileName 834*cdf0e10cSrcweir inArgs(2) = numberOfLines 835*cdf0e10cSrcweir Script.invoke( inArgs(), outIndex(), outArgs() ) 836*cdf0e10cSrcweirEnd Sub 837*cdf0e10cSrcweir 838*cdf0e10cSrcweirsub UpdateConfig( a$ ) 839*cdf0e10cSrcweir dim document as object 840*cdf0e10cSrcweir dim dispatcher as object 841*cdf0e10cSrcweir dim parser as object 842*cdf0e10cSrcweir dim disp as object 843*cdf0e10cSrcweir dim url as new com.sun.star.util.URL 844*cdf0e10cSrcweir document = ThisComponent.CurrentController.Frame 845*cdf0e10cSrcweir parser = createUnoService("com.sun.star.util.URLTransformer") 846*cdf0e10cSrcweir dim args1(0) as new com.sun.star.beans.PropertyValue 847*cdf0e10cSrcweir args1(0).Name = "StreamName" 848*cdf0e10cSrcweir args1(0).Value = a$ 849*cdf0e10cSrcweir url.Complete = ".uno:UpdateConfiguration" 850*cdf0e10cSrcweir parser.parseStrict(url) 851*cdf0e10cSrcweir disp = document.queryDispatch(url,"",0) 852*cdf0e10cSrcweir disp.dispatch(url,args1()) 853*cdf0e10cSrcweir 854*cdf0e10cSrcweirEnd Sub 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir 857*cdf0e10cSrcweirsub AddNewEventBinding( scriptName as string, eventPosition as integer, isApp as boolean ) 858*cdf0e10cSrcweir event = allEventTypes( eventPosition ).Name 859*cdf0e10cSrcweir 'dim scriptProp as new com.sun.star.beans.PropertyValue 860*cdf0e10cSrcweir if isApp then 861*cdf0e10cSrcweir 'scriptProp.Name = scriptName 862*cdf0e10cSrcweir 'scriptProp.Value = numberOfLines 863*cdf0e10cSrcweir allEventTypesApp( eventPosition ).Name = scriptName 864*cdf0e10cSrcweir allEventTypesApp( eventPosition ).Value = numberOfLines 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir newline = " <event:event event:name=" + chr$(34) + event + chr$(34) 867*cdf0e10cSrcweir newline = newline + " event:language=" + chr$(34) + "Script" + chr$(34) + " xlink:href=" + chr$(34) 868*cdf0e10cSrcweir newline = newline + scriptName + chr$(34) + " xlink:type=" + chr$(34) + "simple" + chr$(34) + "/>" 869*cdf0e10cSrcweir xmlFile( numberOfLines ) = newline 870*cdf0e10cSrcweir xmlFile( numberOfLines + 1 ) = "</event:events>" 871*cdf0e10cSrcweir numberOfLines = numberOfLines + 1 872*cdf0e10cSrcweir else 873*cdf0e10cSrcweir 'scriptProp.Name = scriptName 874*cdf0e10cSrcweir 'scriptProp.Value = 2 875*cdf0e10cSrcweir allEventTypesDoc( eventPosition ).Name = scriptName 876*cdf0e10cSrcweir allEventTypesDoc( eventPosition ).Value = 2 877*cdf0e10cSrcweir end if 878*cdf0e10cSrcweirend sub 879*cdf0e10cSrcweir 880*cdf0e10cSrcweirREM ----- Array update functions ----- 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir 883*cdf0e10cSrcweirsub AddNewMenuBinding( newScript as string, newMenuLabel as string, newLinePosition as integer ) 884*cdf0e10cSrcweir dim newXmlFile( 400 ) as string 885*cdf0e10cSrcweir dim newLineInserted as boolean 886*cdf0e10cSrcweir dim lineCounter as integer 887*cdf0e10cSrcweir lineCounter = 1 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir do while lineCounter <= numberOfLines 890*cdf0e10cSrcweir if not newLineInserted then 891*cdf0e10cSrcweir REM If the line number is the position at which to insert the new line 892*cdf0e10cSrcweir if lineCounter = newLinePosition then 893*cdf0e10cSrcweir if( instr( xmlFile( lineCounter ), "<menu:menupopup>" ) > 0 ) then 894*cdf0e10cSrcweir indent = GetMenuWhiteSpace( xmlFile( newLinePosition + 1 ) ) 895*cdf0e10cSrcweir newXmlFile( lineCounter ) = xmlFile( lineCounter ) 896*cdf0e10cSrcweir newXmlFile( lineCounter + 1 ) = ( indent + "<menu:menuitem menu:id="+chr$(34) + newScript + chr$(34)+" menu:helpid="+chr$(34)+"1929"+chr$(34)+" menu:label="+chr$(34)+ newMenuLabel + chr$(34)+"/>" ) 897*cdf0e10cSrcweir else 898*cdf0e10cSrcweir indent = GetMenuWhiteSpace( xmlFile( newLinePosition - 1 ) ) 899*cdf0e10cSrcweir newXmlFile( lineCounter ) = ( indent + "<menu:menuitem menu:id="+chr$(34) + newScript + chr$(34)+" menu:helpid="+chr$(34)+"1929"+chr$(34)+" menu:label="+chr$(34)+ newMenuLabel + chr$(34)+"/>" ) 900*cdf0e10cSrcweir newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter ) 901*cdf0e10cSrcweir end if 902*cdf0e10cSrcweir REM added -1 for debug --> 903*cdf0e10cSrcweir ' indent = GetMenuWhiteSpace( xmlFile( newLinePosition ) ) 904*cdf0e10cSrcweir ' newXmlFile( lineCounter ) = ( indent + "<menu:menuitem menu:id="+chr$(34)+"script://" + newScript + chr$(34)+" menu:helpid="+chr$(34)+"1929"+chr$(34)+" menu:label="+chr$(34)+ newMenuLabel + chr$(34)+"/>" ) 905*cdf0e10cSrcweir ' newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter ) 906*cdf0e10cSrcweir newLineInserted = true 907*cdf0e10cSrcweir else 908*cdf0e10cSrcweir newXmlFile( lineCounter ) = xmlFile( lineCounter ) 909*cdf0e10cSrcweir end if 910*cdf0e10cSrcweir else 911*cdf0e10cSrcweir REM if the new line has been inserted the read from one position behind 912*cdf0e10cSrcweir newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter ) 913*cdf0e10cSrcweir end if 914*cdf0e10cSrcweir lineCounter = lineCounter + 1 915*cdf0e10cSrcweir loop 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir numberOfLines = numberOfLines + 1 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir REM read the new file into the global array 920*cdf0e10cSrcweir for n = 1 to numberOfLines 921*cdf0e10cSrcweir xmlFile( n ) = newXmlFile( n ) 922*cdf0e10cSrcweir next n 923*cdf0e10cSrcweir 924*cdf0e10cSrcweirend sub 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir 927*cdf0e10cSrcweirsub AddNewKeyBinding( scriptName as string, shift as boolean, control as boolean, key as string ) 928*cdf0e10cSrcweir 929*cdf0e10cSrcweir dim keyCombo as string 930*cdf0e10cSrcweir newLine = " <accel:item accel:code="+chr$(34)+"KEY_" + key +chr$(34) 931*cdf0e10cSrcweir if shift then 932*cdf0e10cSrcweir keyCombo = "SHIFT + " 933*cdf0e10cSrcweir newLine = newLine + " accel:shift="+chr$(34)+"true"+chr$(34) 934*cdf0e10cSrcweir end if 935*cdf0e10cSrcweir if control then 936*cdf0e10cSrcweir keyCombo = keyCombo + "CONTROL + " 937*cdf0e10cSrcweir newLine = newLine + " accel:mod1="+chr$(34)+"true"+chr$(34) 938*cdf0e10cSrcweir end if 939*cdf0e10cSrcweir keyCombo = keyCombo + key 940*cdf0e10cSrcweir newLine = newLine + " xlink:href="+chr$(34)+ scriptName +chr$(34) +"/>" 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir if ( control AND shift ) then 943*cdf0e10cSrcweir offsetIntoArrayOfArrays = 0 944*cdf0e10cSrcweir elseif ( control ) then 945*cdf0e10cSrcweir offsetIntoArrayOfArrays = 3 946*cdf0e10cSrcweir elseif ( shift ) then 947*cdf0e10cSrcweir offsetIntoArrayOfArrays = 6 948*cdf0e10cSrcweir endif 949*cdf0e10cSrcweir 950*cdf0e10cSrcweir keyTypeOffset = getKeyTypeOffset( key ) 951*cdf0e10cSrcweir offsetIntoArrayOfArrays = offsetIntoArrayOfArrays + keyTypeOffset 952*cdf0e10cSrcweir ' Calculate from the key the offset into key group array we need to point to 953*cdf0e10cSrcweir KeyGroupIndex = getKeyGroupIndex( key, keyTypeOffset ) 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir ' if key is allready allocated to a script then just reallocate 956*cdf0e10cSrcweir if ( keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value > 1 ) then 957*cdf0e10cSrcweir 958*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName 959*cdf0e10cSrcweir 'replace line in xml file 960*cdf0e10cSrcweir xmlFile( keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value ) = newLine 961*cdf0e10cSrcweir else 962*cdf0e10cSrcweir ' this is a new binding, create a new line in xml file 963*cdf0e10cSrcweir for n = 1 to numberOfLines 964*cdf0e10cSrcweir if n = numberOfLines then 965*cdf0e10cSrcweir xmlFile( n ) = newLine 966*cdf0e10cSrcweir xmlFile( n + 1 ) = "</accel:acceleratorlist>" 967*cdf0e10cSrcweir exit for 968*cdf0e10cSrcweir else 969*cdf0e10cSrcweir xmlFile( n ) = xmlFile( n ) 970*cdf0e10cSrcweir end if 971*cdf0e10cSrcweir next n 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = n 974*cdf0e10cSrcweir keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName 975*cdf0e10cSrcweir numberOfLines = numberOfLines + 1 976*cdf0e10cSrcweir endif 977*cdf0e10cSrcweir 978*cdf0e10cSrcweirend sub 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir 981*cdf0e10cSrcweirSub RemoveBinding( lineToRemove as Integer ) 982*cdf0e10cSrcweir xmlFile( lineToRemove ) = "" 983*cdf0e10cSrcweirend Sub 984*cdf0e10cSrcweir 985*cdf0e10cSrcweirREM Adds or removes the starting xml line positions for each top-level menu after the menu with the added script 986*cdf0e10cSrcweirsub UpdateTopLevelMenus( topLevelMenuPosition as integer, addLine as boolean ) 987*cdf0e10cSrcweir for n = topLevelMenuPosition to 8 988*cdf0e10cSrcweir if addLine then 989*cdf0e10cSrcweir menuItemLinePosition( n ) = menuItemLinePosition( n ) + 1 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir end if 992*cdf0e10cSrcweir next n 993*cdf0e10cSrcweirend sub 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir 996*cdf0e10cSrcweirREM Remove scriptNames and scriptLinePosition entries 997*cdf0e10cSrcweirsub RemoveScriptNameAndPosition( keyComboPosition ) 998*cdf0e10cSrcweir dim updatedScriptNames( 120 ) as string 999*cdf0e10cSrcweir dim updatedScriptLinePosition( 120 ) as integer 1000*cdf0e10cSrcweir dim removedScript as boolean 1001*cdf0e10cSrcweir removedScript = false 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir for n = 1 to scriptCount 1004*cdf0e10cSrcweir if not removedScript then 1005*cdf0e10cSrcweir if not( n = keyComboPosition ) then 1006*cdf0e10cSrcweir updatedScriptNames( n ) = scriptNames( n ) 1007*cdf0e10cSrcweir else 1008*cdf0e10cSrcweir removedScript = true 1009*cdf0e10cSrcweir end if 1010*cdf0e10cSrcweir else 1011*cdf0e10cSrcweir updatedScriptNames( n - 1 ) = scriptNames( n ) 1012*cdf0e10cSrcweir end if 1013*cdf0e10cSrcweir next n 1014*cdf0e10cSrcweir scriptCount = scriptCount - 1 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir for n = 1 to scriptCount 1017*cdf0e10cSrcweir scriptNames( n ) = updatedScriptNames( n ) 1018*cdf0e10cSrcweir next n 1019*cdf0e10cSrcweirend sub 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweirREM ----- Populating Dialog Controls ----- 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweirSub PopulateLanguageCombo() 1026*cdf0e10cSrcweir langCombo = bindingDialog.getControl( "LanguageCombo" ) 1027*cdf0e10cSrcweir langCombo.removeItems( 0, langCombo.getItemCount() ) 1028*cdf0e10cSrcweir for n = LBOUND( languages() ) to UBOUND ( languages() ) 1029*cdf0e10cSrcweir langCombo.addItem( languages( n ), n ) 1030*cdf0e10cSrcweir next n 1031*cdf0e10cSrcweir langCombo.setDropDownLineCount( n ) 1032*cdf0e10cSrcweir langCombo.text = langCombo.getItem( 0 ) 1033*cdf0e10cSrcweirEnd Sub 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweirSub PopulateLocationCombo() 1036*cdf0e10cSrcweir dim ScriptProvider as Object 1037*cdf0e10cSrcweir dim args(1) 1038*cdf0e10cSrcweir dim displayDialogFlag as boolean 1039*cdf0e10cSrcweir displayDialogFlag = false 1040*cdf0e10cSrcweir args(0) = ThisComponent 1041*cdf0e10cSrcweir args(1) = displayDialogFlag 1042*cdf0e10cSrcweir 1043*cdf0e10cSrcweir ScriptProvider = createUnoService("drafts.com.sun.star.script.framework.provider.MasterScriptProvider") 1044*cdf0e10cSrcweir ScriptProvider.initialize( args() ) 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir locCombo = bindingDialog.getControl( "LocationCombo" ) 1047*cdf0e10cSrcweir locCombo.removeItems( 0, locCombo.getItemCount() ) 1048*cdf0e10cSrcweir for n = LBOUND( locations() ) to UBOUND ( locations() ) 1049*cdf0e10cSrcweir locCombo.addItem( locations( n ), n ) 1050*cdf0e10cSrcweir next n 1051*cdf0e10cSrcweir locCombo.setDropDownLineCount( n ) 1052*cdf0e10cSrcweir locCombo.text = locCombo.getItem( 0 ) 1053*cdf0e10cSrcweirEnd Sub 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweirsub PopulateScriptList( lang as String, loc as String ) 1056*cdf0e10cSrcweir Dim detailedView as boolean 1057*cdf0e10cSrcweir detailedView = bindingDialog.Model.detail.state 1058*cdf0e10cSrcweir scriptList = bindingDialog.getControl( "ScriptList" ) 1059*cdf0e10cSrcweir scriptList.removeItems( 0, scriptList.getItemCount() ) 1060*cdf0e10cSrcweir 1061*cdf0e10cSrcweir smgr = getProcessServiceManager() 1062*cdf0e10cSrcweir context = smgr.getPropertyValue( "DefaultContext" ) 1063*cdf0e10cSrcweir scriptstoragemgr = context.getValueByName( "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager" ) 1064*cdf0e10cSrcweir scriptLocationURI = "USER" 1065*cdf0e10cSrcweir if ( loc = "Share" ) then 1066*cdf0e10cSrcweir scriptLocationURI = "SHARE" 1067*cdf0e10cSrcweir elseif ( loc = "Document" )then 1068*cdf0e10cSrcweir document = StarDesktop.ActiveFrame.Controller.Model 1069*cdf0e10cSrcweir scriptLocationURI = document.getURL() 1070*cdf0e10cSrcweir elseif ( loc = "Filesystem" ) then 1071*cdf0e10cSrcweir REM populate the list from the filesysScripts list 1072*cdf0e10cSrcweir if(lang = "Java" ) then 1073*cdf0e10cSrcweir exit sub 1074*cdf0e10cSrcweir endif 1075*cdf0e10cSrcweir length = UBOUND( filesysScripts() ) 1076*cdf0e10cSrcweir if(length = -1) then 1077*cdf0e10cSrcweir exit sub 1078*cdf0e10cSrcweir endif 1079*cdf0e10cSrcweir for langIndex = lbound(languages()) to ubound(languages()) 1080*cdf0e10cSrcweir if ( lang = languages(langIndex)) then 1081*cdf0e10cSrcweir extns = extensions(langIndex) 1082*cdf0e10cSrcweir exit for 1083*cdf0e10cSrcweir endif 1084*cdf0e10cSrcweir next langIndex 1085*cdf0e10cSrcweir dim locnDisplayList( length ) as new com.sun.star.beans.PropertyValue 1086*cdf0e10cSrcweir for index = lbound(filesysScripts()) to ubound(filesysScripts()) 1087*cdf0e10cSrcweir scriptextn = filesysScripts( index ) 1088*cdf0e10cSrcweir pos = lastIndexOf( scriptextn, "." ) 1089*cdf0e10cSrcweir scriptextn = mid( scriptextn, pos + 1, len( scriptextn ) - pos ) 1090*cdf0e10cSrcweir 1091*cdf0e10cSrcweir for extnsIndex = lbound(extns()) to ubound(extns()) 1092*cdf0e10cSrcweir extn = extns(extnsIndex) 1093*cdf0e10cSrcweir if ( scriptextn = extn ) then 1094*cdf0e10cSrcweir if ( detailedView ) then 1095*cdf0e10cSrcweir locnDisplayList( index ).Name = filesysScripts( index ) 1096*cdf0e10cSrcweir locnDisplayList( index ).Value = filesysScripts( index ) 1097*cdf0e10cSrcweir else 1098*cdf0e10cSrcweir REM replace name with simplified view 1099*cdf0e10cSrcweir locnDisplayList( index ).Name = filesysScripts( index ) 1100*cdf0e10cSrcweir locnDisplayList( index ).Value = filesysScripts( index ) 1101*cdf0e10cSrcweir end if 1102*cdf0e10cSrcweir scriptList.addItem( locnDisplayList( index ).Name, index ) 1103*cdf0e10cSrcweir exit for 1104*cdf0e10cSrcweir end if 1105*cdf0e10cSrcweir next extnsIndex 1106*cdf0e10cSrcweir next index 1107*cdf0e10cSrcweir ScriptDisplayList(0) = locnDisplayList() 1108*cdf0e10cSrcweir scriptList.selectItemPos( 0, true ) 1109*cdf0e10cSrcweir 1110*cdf0e10cSrcweir REM !!!!At this point we exit the sub!!!! 1111*cdf0e10cSrcweir exit sub 1112*cdf0e10cSrcweir 1113*cdf0e10cSrcweir endif 1114*cdf0e10cSrcweir 1115*cdf0e10cSrcweir scriptStorageID = scriptstoragemgr.getScriptStorageID( scriptLocationURI ) 1116*cdf0e10cSrcweir dim resultList() as Object 1117*cdf0e10cSrcweir if ( scriptStorageID > -1 ) then 1118*cdf0e10cSrcweir storage = scriptstoragemgr.getScriptStorage( scriptStorageID ) 1119*cdf0e10cSrcweir implementations() = storage.getAllImplementations() 1120*cdf0e10cSrcweir length = UBOUND( implementations() ) 1121*cdf0e10cSrcweir reservedScriptTag = "_$" 1122*cdf0e10cSrcweir if ( length > -1 ) then 1123*cdf0e10cSrcweir dim tempDisplayList( length ) as new com.sun.star.beans.PropertyValue 1124*cdf0e10cSrcweir for n = LBOUND( implementations() ) to UBOUND( implementations() ) 1125*cdf0e10cSrcweir logicalName = implementations( n ).getLogicalName() 1126*cdf0e10cSrcweir firstTwoChars = LEFT( logicalName, 2 ) 1127*cdf0e10cSrcweir 'Only display scripts whose logicalnames don't begin with "_$" 1128*cdf0e10cSrcweir if ( firstTwoChars <> reservedScriptTag ) then 1129*cdf0e10cSrcweir if ( lang = implementations( n ).getLanguage() ) then 1130*cdf0e10cSrcweir if ( detailedView ) then 1131*cdf0e10cSrcweir tempDisplayList( n ).Name = logicalName _ 1132*cdf0e10cSrcweir + " [" + implementations( n ).getFunctionName() + "]" 1133*cdf0e10cSrcweir tempDisplayList( n ).Value = implementations( n ) 1134*cdf0e10cSrcweir else 1135*cdf0e10cSrcweir tempDisplayList( n ).Name = logicalName 1136*cdf0e10cSrcweir tempDisplayList( n ).Value = implementations( n ) 1137*cdf0e10cSrcweir endif 1138*cdf0e10cSrcweir scriptList.addItem( tempDisplayList( n ).Name, n ) 1139*cdf0e10cSrcweir endif 1140*cdf0e10cSrcweir endif 1141*cdf0e10cSrcweir next n 1142*cdf0e10cSrcweir resultList = tempDisplayList() 1143*cdf0e10cSrcweir endif 1144*cdf0e10cSrcweir ScriptDisplayList(0) = resultList() 1145*cdf0e10cSrcweir endif 1146*cdf0e10cSrcweir scriptList.selectItemPos( 0, true ) 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweirend sub 1149*cdf0e10cSrcweir 1150*cdf0e10cSrcweirsub PopulateMenuCombo() 1151*cdf0e10cSrcweir menuComboBox = bindingDialog.getControl( "MenuCombo" ) 1152*cdf0e10cSrcweir menuComboBox.removeItems( 0, menuComboBox.getItemCount() ) 1153*cdf0e10cSrcweir for n = 1 to menuCount 1154*cdf0e10cSrcweir menuComboBox.addItem( menuItems( n ), n - 1 ) 1155*cdf0e10cSrcweir next n 1156*cdf0e10cSrcweir menuComboBox.setDropDownLineCount( 8 ) 1157*cdf0e10cSrcweir menuComboBox.text = menuComboBox.getItem( 0 ) 1158*cdf0e10cSrcweirend sub 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweirsub PopulateSubMenuList( menuItemPosition as integer ) 1162*cdf0e10cSrcweir redim subMenuItems( 100 ) as string 1163*cdf0e10cSrcweir redim subMenuItemLinePosition( 100 ) as integer 1164*cdf0e10cSrcweir dim lineNumber as integer 1165*cdf0e10cSrcweir const menuItemWhiteSpace = 4 1166*cdf0e10cSrcweir const menuXMLTag = "<menu:menu" 1167*cdf0e10cSrcweir subMenuCount = 1 1168*cdf0e10cSrcweir 1169*cdf0e10cSrcweir REM xmlStartLine and xmlEndLine refer to the first and last lines 1170*cdf0e10cSrcweir ' menuItemPosition of a top-level menu ( 1=File to 8=Help ) add one line 1171*cdf0e10cSrcweir xmlStartLine = menuItemLinePosition( menuItemPosition ) + 1 1172*cdf0e10cSrcweir 1173*cdf0e10cSrcweir REM If last menu item is chosen 1174*cdf0e10cSrcweir if menuItemPosition = menuCount then 1175*cdf0e10cSrcweir xmlEndLine = numberOfLines 1176*cdf0e10cSrcweir else 1177*cdf0e10cSrcweir REM Other wise get the line before the next top-level menu begins 1178*cdf0e10cSrcweir xmlEndLine = menuItemLinePosition( menuItemPosition + 1 ) - 1 1179*cdf0e10cSrcweir end if 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir for lineNumber = xmlStartLine to xmlEndLine 1182*cdf0e10cSrcweir REM Insert all sub-menus and sub-popupmenus 1183*cdf0e10cSrcweir if not( instr( xmlFile( lineNumber ), menuXMLTag ) = 0 ) and instr( xmlFile( lineNumber ), "menupopup") = 0 then 1184*cdf0e10cSrcweir subMenuIndent = GetMenuWhiteSpace( xmlFile( lineNumber ) ) 1185*cdf0e10cSrcweir if subMenuIndent = " " then 1186*cdf0e10cSrcweir subMenuIndent = "" 1187*cdf0e10cSrcweir else 1188*cdf0e10cSrcweir subMenuIndent = subMenuIndent + subMenuIndent 1189*cdf0e10cSrcweir end if 1190*cdf0e10cSrcweir if not( instr( xmlFile( lineNumber ), "menuseparator" ) = 0 ) then 1191*cdf0e10cSrcweir subMenuItems( subMenuCount ) = subMenuIndent + "----------------" 1192*cdf0e10cSrcweir else 1193*cdf0e10cSrcweir subMenuName = ExtractLabelFromXMLLine( xmlFile( lineNumber ) ) 1194*cdf0e10cSrcweir REM Add script Name if there is one bound to menu item 1195*cdf0e10cSrcweir if instr( xmlFile( lineNumber ), "script://" ) > 0 then 1196*cdf0e10cSrcweir script = ExtractScriptIdFromXMLLine( xmlFile( lineNumber ) ) 1197*cdf0e10cSrcweir subMenuItems( subMenuCount ) = ( subMenuIndent + subMenuName + " [" + script + "]" ) 1198*cdf0e10cSrcweir else 1199*cdf0e10cSrcweir subMenuItems( subMenuCount ) = subMenuIndent + subMenuName 1200*cdf0e10cSrcweir end if 1201*cdf0e10cSrcweir end if 1202*cdf0e10cSrcweir subMenuItemLinePosition( subMenuCount ) = lineNumber 1203*cdf0e10cSrcweir subMenuCount = subMenuCount + 1 1204*cdf0e10cSrcweir end if 1205*cdf0e10cSrcweir next lineNumber 1206*cdf0e10cSrcweir 1207*cdf0e10cSrcweir subMenuList = bindingDialog.getControl( "SubMenuList" ) 1208*cdf0e10cSrcweir 1209*cdf0e10cSrcweir currentPosition = subMenuList.getSelectedItemPos() 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir subMenuList.removeItems( 0, subMenuList.getItemCount() ) 1212*cdf0e10cSrcweir 'If there are no sub-menus i.e. a dynamically generated menu like Format 1213*cdf0e10cSrcweir 'if subMenuCount = 1 then 1214*cdf0e10cSrcweir if menuItems( menuItemPosition ) = "Format" then 1215*cdf0e10cSrcweir subMenuList.addItem( "Unable to Assign Scripts to this menu", 0 ) 1216*cdf0e10cSrcweir else 1217*cdf0e10cSrcweir for n = 1 to subMenuCount - 1 1218*cdf0e10cSrcweir subMenuList.addItem( subMenuItems( n ), n - 1 ) 1219*cdf0e10cSrcweir next n 1220*cdf0e10cSrcweir end if 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir subMenuList.selectItemPos( currentPosition, true ) 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir SubMenuListListener() 1225*cdf0e10cSrcweir MenuLabelBoxListener() 1226*cdf0e10cSrcweirend sub 1227*cdf0e10cSrcweir 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir 1230*cdf0e10cSrcweirsub PopulateTopLevelKeyBindingList() 1231*cdf0e10cSrcweir 1232*cdf0e10cSrcweir allKeyGroupsArray(0) = "SHIFT + CONTROL + F keys" 1233*cdf0e10cSrcweir allKeyGroupsArray(1) = "SHIFT + CONTROL + digits" ' CURRENTLY DISABLED 1234*cdf0e10cSrcweir allKeyGroupsArray(2) = "SHIFT + CONTROL + letters" 1235*cdf0e10cSrcweir allKeyGroupsArray(3) = "CONTROL + F keys" 1236*cdf0e10cSrcweir allKeyGroupsArray(4) = "CONTROL + digits" 1237*cdf0e10cSrcweir allKeyGroupsArray(5) = "CONTROL + letters" 1238*cdf0e10cSrcweir allKeyGroupsArray(6) = "SHIFT + F keys" 1239*cdf0e10cSrcweir 1240*cdf0e10cSrcweir keyCombo = bindingDialog.getControl( "KeyCombo" ) 1241*cdf0e10cSrcweir keyCombo.removeItems( 0, keyCombo.getItemCount() ) 1242*cdf0e10cSrcweir pos = 0 1243*cdf0e10cSrcweir for n = LBOUND( allKeyGroupsArray() ) to UBOUND( allKeyGroupsArray() ) 1244*cdf0e10cSrcweir ' SHIFT + CONTROL + digits group is disabled at the moment, so skip 1245*cdf0e10cSrcweir ' it 1246*cdf0e10cSrcweir if ( n <> 1 ) then 1247*cdf0e10cSrcweir keyCombo.addItem( allKeyGroupsArray( n ), pos ) 1248*cdf0e10cSrcweir pos = pos +1 1249*cdf0e10cSrcweir endif 1250*cdf0e10cSrcweir next n 1251*cdf0e10cSrcweir keyCombo.text = keyCombo.getItem( 0 ) 1252*cdf0e10cSrcweirend sub 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweirsub PopulateKeyBindingList( keyGroupIndex as Integer ) 1255*cdf0e10cSrcweir keyList = bindingDialog.getControl( "KeyList" ) 1256*cdf0e10cSrcweir selectedPos = keyList.getSelectedItemPos() 1257*cdf0e10cSrcweir keyList.removeItems( 0, keyList.getItemCount() ) 1258*cdf0e10cSrcweir 1259*cdf0e10cSrcweir ShortCutKeyArray() = KeyBindArrayOfArrays( keyGroupIndex ) 1260*cdf0e10cSrcweir 1261*cdf0e10cSrcweir Dim keyProp as new com.sun.star.beans.PropertyValue 1262*cdf0e10cSrcweir for n = lbound( ShortCutKeyArray() ) to ubound( ShortCutKeyArray() ) 1263*cdf0e10cSrcweir keyName = ShortCutKeyArray( n ) 1264*cdf0e10cSrcweir if ( keyAllocationMap( keyGroupIndex, n ).Value = 1 ) then 1265*cdf0e10cSrcweir keyName = keyName + " [Allocated to Office function]" 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir elseif ( keyAllocationMap( keyGroupIndex, n ).Value > 1 ) then 1268*cdf0e10cSrcweir keyName = keyName + " " + keyAllocationMap( keyGroupIndex, n ).Name 1269*cdf0e10cSrcweir endif 1270*cdf0e10cSrcweir keyList.addItem( keyName, n ) 1271*cdf0e10cSrcweir next n 1272*cdf0e10cSrcweir 1273*cdf0e10cSrcweir if ( selectedPos <> -1 )then 1274*cdf0e10cSrcweir keyList.selectItemPos( selectedPos, true ) 1275*cdf0e10cSrcweir else 1276*cdf0e10cSrcweir keyList.selectItemPos( 0, true ) 1277*cdf0e10cSrcweir end if 1278*cdf0e10cSrcweir KeyListListener() 1279*cdf0e10cSrcweirend sub 1280*cdf0e10cSrcweir 1281*cdf0e10cSrcweirsub populateEventList( focusPosition as integer ) 1282*cdf0e10cSrcweir allApps = bindingDialog.getControl( "AllAppsOption" ) 1283*cdf0e10cSrcweir eventList = bindingDialog.getControl( "EventList" ) 1284*cdf0e10cSrcweir eventList.removeItems( 0, eventList.getItemCount() ) 1285*cdf0e10cSrcweir 1286*cdf0e10cSrcweir dim isApp as boolean 1287*cdf0e10cSrcweir if allApps.state = true then ' Application event 1288*cdf0e10cSrcweir isApp = true 1289*cdf0e10cSrcweir else 1290*cdf0e10cSrcweir isApp = false 1291*cdf0e10cSrcweir end if 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir ' use allEventTypes() to fill list box 1294*cdf0e10cSrcweir ' for each element compare with allEventTypesApp 1295*cdf0e10cSrcweir dim scriptName as string 1296*cdf0e10cSrcweir dim lineNumber as integer 1297*cdf0e10cSrcweir for n = 0 to ubound( allEventTypes() ) 1298*cdf0e10cSrcweir ' If the line number is 1 then SB macro 1299*cdf0e10cSrcweir ' more than 1 it is the line number of the script 1300*cdf0e10cSrcweir if isApp and n > 12 then 1301*cdf0e10cSrcweir exit for 1302*cdf0e10cSrcweir endif 1303*cdf0e10cSrcweir if isApp then 1304*cdf0e10cSrcweir lineNumber = allEventTypesApp( n ).Value 1305*cdf0e10cSrcweir scriptName = allEventTypesApp( n ).Name 1306*cdf0e10cSrcweir else 1307*cdf0e10cSrcweir lineNumber = allEventTypesDoc( n ).Value 1308*cdf0e10cSrcweir scriptName = allEventTypesDoc( n ).Name 1309*cdf0e10cSrcweir end if 1310*cdf0e10cSrcweir stringToAdd = "" 1311*cdf0e10cSrcweir if ( lineNumber >= 1 ) then 1312*cdf0e10cSrcweir stringToAdd = " [" + scriptName + "]" 1313*cdf0e10cSrcweir end if 1314*cdf0e10cSrcweir eventList.addItem( allEventTypes( n ).Value + " " + stringToAdd, n ) 1315*cdf0e10cSrcweir next n 1316*cdf0e10cSrcweir 1317*cdf0e10cSrcweir eventList.selectItemPos( focusPosition, true ) 1318*cdf0e10cSrcweirend sub 1319*cdf0e10cSrcweir 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweirsub CreateAllKeyBindings() 1323*cdf0e10cSrcweir reDim allKeyBindings( 105 ) as string 1324*cdf0e10cSrcweir keyBindingPosition = 1 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir for FKey = 2 to 12 1327*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + F" + FKey 1328*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1329*cdf0e10cSrcweir next FKey 1330*cdf0e10cSrcweir for Digit = 0 to 9 1331*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + " + Digit 1332*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1333*cdf0e10cSrcweir next Digit 1334*cdf0e10cSrcweir for Alpha = 65 to 90 1335*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + " + chr$( Alpha ) 1336*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1337*cdf0e10cSrcweir next Alpha 1338*cdf0e10cSrcweir 1339*cdf0e10cSrcweir for FKey = 2 to 12 1340*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "CONTROL + F" + FKey 1341*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1342*cdf0e10cSrcweir next FKey 1343*cdf0e10cSrcweir for Digit = 0 to 9 1344*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "CONTROL + " + Digit 1345*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1346*cdf0e10cSrcweir next Digit 1347*cdf0e10cSrcweir for Alpha = 65 to 90 1348*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "CONTROL + " + chr$( Alpha ) 1349*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1350*cdf0e10cSrcweir next Alpha 1351*cdf0e10cSrcweir 1352*cdf0e10cSrcweir for FKey = 2 to 12 1353*cdf0e10cSrcweir allKeyBindings( keyBindingPosition ) = "SHIFT + F" + FKey 1354*cdf0e10cSrcweir keyBindingPosition = keyBindingPosition + 1 1355*cdf0e10cSrcweir next FKey 1356*cdf0e10cSrcweirend sub 1357*cdf0e10cSrcweir 1358*cdf0e10cSrcweir 1359*cdf0e10cSrcweirsub createAllEventTypes() 1360*cdf0e10cSrcweir allEventTypes( 0 ).Name = "OnStartApp" 1361*cdf0e10cSrcweir allEventTypes( 0 ).Value = "Start Application" 1362*cdf0e10cSrcweir allEventTypes( 1 ).Name = "OnCloseApp" 1363*cdf0e10cSrcweir allEventTypes( 1 ).Value = "Close Application" 1364*cdf0e10cSrcweir allEventTypes( 2 ).Name = "OnNew" 1365*cdf0e10cSrcweir allEventTypes( 2 ).Value = "Create Document" 1366*cdf0e10cSrcweir allEventTypes( 3 ).Name = "OnLoad" 1367*cdf0e10cSrcweir allEventTypes( 3 ).Value = "Open Document" 1368*cdf0e10cSrcweir allEventTypes( 4 ).Name = "OnSaveAs" 1369*cdf0e10cSrcweir allEventTypes( 4 ).Value = "Save Document As" 1370*cdf0e10cSrcweir allEventTypes( 5 ).Name = "OnSaveAsDone" 1371*cdf0e10cSrcweir allEventTypes( 5 ).Value = "Document has been saved as" 1372*cdf0e10cSrcweir allEventTypes( 6 ).Name = "OnSave" 1373*cdf0e10cSrcweir allEventTypes( 6 ).Value = "Save Document" 1374*cdf0e10cSrcweir allEventTypes( 7 ).Name = "OnSaveDone" 1375*cdf0e10cSrcweir allEventTypes( 7 ).Value = "Document has been saved" 1376*cdf0e10cSrcweir allEventTypes( 8 ).Name = "OnPrepareUnload" 1377*cdf0e10cSrcweir allEventTypes( 8 ).Value = "Close Document" 1378*cdf0e10cSrcweir allEventTypes( 9 ).Name = "OnUnload" 1379*cdf0e10cSrcweir allEventTypes( 9 ).Value = "Close Document" 1380*cdf0e10cSrcweir allEventTypes( 10 ).Name = "OnFocus" 1381*cdf0e10cSrcweir allEventTypes( 10 ).Value = "Activate document" 1382*cdf0e10cSrcweir allEventTypes( 11 ).Name = "OnUnfocus" 1383*cdf0e10cSrcweir allEventTypes( 11 ).Value = "DeActivate document" 1384*cdf0e10cSrcweir allEventTypes( 12 ).Name = "OnPrint" 1385*cdf0e10cSrcweir allEventTypes( 12 ).Value = "Print Document" 1386*cdf0e10cSrcweir REM The following are document-only events 1387*cdf0e10cSrcweir allEventTypes( 13 ).Name = "OnMailMerge" 1388*cdf0e10cSrcweir allEventTypes( 13 ).Value = "Print form letters" 1389*cdf0e10cSrcweir allEventTypes( 14 ).Name = "OnPageCountChange" 1390*cdf0e10cSrcweir allEventTypes( 14 ).Value = "Changing the page count" 1391*cdf0e10cSrcweirend sub 1392*cdf0e10cSrcweir 1393*cdf0e10cSrcweir 1394*cdf0e10cSrcweirsub createAllEventBindings() 1395*cdf0e10cSrcweir 'dim props as new com.sun.star.beans.PropertyValue 1396*cdf0e10cSrcweir 'props.Name = "" 'Name = script name 1397*cdf0e10cSrcweir 'props.Value = 0 'Value = 0 for empty, 1 for macro, linenumber for script 1398*cdf0e10cSrcweir 1399*cdf0e10cSrcweir ' Creates all types of event bindings for both Application and Document 1400*cdf0e10cSrcweir ' Initially both arrays have no bindings allocated to the events 1401*cdf0e10cSrcweir ' The value for Doc is only Script/macro name (no need for line number) 1402*cdf0e10cSrcweir for n = 0 to ubound( allEventTypes() ) 1403*cdf0e10cSrcweir allEventTypesApp( n ).Name = "" 1404*cdf0e10cSrcweir allEventTypesApp( n ).Value = 0 1405*cdf0e10cSrcweir allEventTypesDoc( n ).Name = "" 1406*cdf0e10cSrcweir allEventTypesDoc( n ).Value = 0 1407*cdf0e10cSrcweir next n 1408*cdf0e10cSrcweirend sub 1409*cdf0e10cSrcweir 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweirREM ----- Text Handling Functions ----- 1412*cdf0e10cSrcweir 1413*cdf0e10cSrcweir 1414*cdf0e10cSrcweirfunction ExtractLabelFromXMLLine( XMLLine as string ) as string 1415*cdf0e10cSrcweir labelStart = instr( XMLLine, "label="+chr$(34)) + 7 1416*cdf0e10cSrcweir labelEnd = instr( XMLLine, chr$(34)+">" ) 1417*cdf0e10cSrcweir if labelEnd = 0 then 1418*cdf0e10cSrcweir labelEnd = instr( XMLLine, chr$(34)+"/>" ) 1419*cdf0e10cSrcweir end if 1420*cdf0e10cSrcweir labelLength = labelEnd - labelStart 1421*cdf0e10cSrcweir 1422*cdf0e10cSrcweir menuLabelUnformatted = mid( XMLLine, labelStart, labelLength ) 1423*cdf0e10cSrcweir tildePosition = instr( menuLabelUnformatted, "~" ) 1424*cdf0e10cSrcweir select case tildePosition 1425*cdf0e10cSrcweir case 0 1426*cdf0e10cSrcweir menuLabel = menuLabelUnformatted 1427*cdf0e10cSrcweir case 1 1428*cdf0e10cSrcweir menuLabel = right( menuLabelUnformatted, labelLength - 1 ) 1429*cdf0e10cSrcweir case else 1430*cdf0e10cSrcweir menuLabelLeft = left( menuLabelUnformatted, tildePosition - 1 ) 1431*cdf0e10cSrcweir menuLabelRight = right( menuLabelUnformatted, labelLength - tildePosition ) 1432*cdf0e10cSrcweir menuLabel = menuLabelLeft + menuLabelRight 1433*cdf0e10cSrcweir end select 1434*cdf0e10cSrcweir 1435*cdf0e10cSrcweir ExtractLabelFromXMLLine() = menuLabel 1436*cdf0e10cSrcweirend function 1437*cdf0e10cSrcweir 1438*cdf0e10cSrcweir 1439*cdf0e10cSrcweirfunction ExtractScriptIdFromXMLLine( XMLLine as string ) as string 1440*cdf0e10cSrcweir idStart = instr( XMLLine, "script://") + 9 1441*cdf0e10cSrcweir if instr( XMLLine, chr$(34)+" menu:helpid=" ) = 0 then 1442*cdf0e10cSrcweir idEnd = instr( XMLLIne, "?location=" ) 1443*cdf0e10cSrcweir else 1444*cdf0e10cSrcweir idEnd = instr( XMLLine, ""+chr$(34)+" menu:helpid=" ) 1445*cdf0e10cSrcweir end if 1446*cdf0e10cSrcweir idLength = idEnd - idStart 1447*cdf0e10cSrcweir scriptId = mid( XMLLine, idStart, idLength ) 1448*cdf0e10cSrcweir 1449*cdf0e10cSrcweir ExtractScriptIdFromXMLLine() = scriptId 1450*cdf0e10cSrcweirend function 1451*cdf0e10cSrcweir 1452*cdf0e10cSrcweirfunction ExtractEventScriptFromXMLLine( xmlline as string ) 1453*cdf0e10cSrcweir if instr( xmlline, "script://" ) > 0 then 1454*cdf0e10cSrcweir idStart = instr( xmlline, "script://") + 9 1455*cdf0e10cSrcweir idEnd = instr( xmlline, chr$(34)+" xlink:type=" ) 1456*cdf0e10cSrcweir idLength = idEnd - idStart 1457*cdf0e10cSrcweir scriptId = mid( xmlline, idStart, idLength ) 1458*cdf0e10cSrcweir end if 1459*cdf0e10cSrcweir ExtractEventScriptFromXMLLine() = scriptId 1460*cdf0e10cSrcweirend function 1461*cdf0e10cSrcweir 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweirfunction ExtractEventNameFromXMLLine( xmlline as string ) 1464*cdf0e10cSrcweir idStart = instr( xmlline, "event:name=" + chr$(34) ) + 12 1465*cdf0e10cSrcweir idEnd = instr( xmlline, chr$(34)+" event:language" ) 1466*cdf0e10cSrcweir idLength = idEnd - idStart 1467*cdf0e10cSrcweir event = mid( xmlline, idStart, idLength ) 1468*cdf0e10cSrcweir 1469*cdf0e10cSrcweir ExtractEventNameFromXMLLine() = event 1470*cdf0e10cSrcweirend function 1471*cdf0e10cSrcweir 1472*cdf0e10cSrcweirfunction ExtractKeyCodeFromXMLLine( XMLLine as string ) as string 1473*cdf0e10cSrcweir keyStart = instr( XMLLine, "code="+chr$(34)+"KEY_") + 10 1474*cdf0e10cSrcweir keyCode = mid( XMLLine, keyStart, ( len( XMLLine ) - keyStart ) ) 1475*cdf0e10cSrcweir keyEnd = instr( keyCode, chr$(34) ) 1476*cdf0e10cSrcweir keyCode = mid( keyCode, 1, keyEnd - 1 ) 1477*cdf0e10cSrcweir 1478*cdf0e10cSrcweir ExtractKeyCodeFromXMLLine() = keyCode 1479*cdf0e10cSrcweirend function 1480*cdf0e10cSrcweir 1481*cdf0e10cSrcweir 1482*cdf0e10cSrcweirfunction GetMenuWhiteSpace( MenuXMLLine as string ) as string 1483*cdf0e10cSrcweir whiteSpace = "" 1484*cdf0e10cSrcweir numberOfSpaces = instr( MenuXMLLine, "<" ) - 1 1485*cdf0e10cSrcweir for i = 1 to numberOfSpaces 1486*cdf0e10cSrcweir whiteSpace = whiteSpace + " " 1487*cdf0e10cSrcweir next i 1488*cdf0e10cSrcweir 1489*cdf0e10cSrcweir GetMenuWhiteSpace() = whiteSpace 1490*cdf0e10cSrcweirend function 1491*cdf0e10cSrcweir 1492*cdf0e10cSrcweirfunction IsAllocatedMenuItem( script as string ) as boolean 1493*cdf0e10cSrcweir foundMenuItem = false 1494*cdf0e10cSrcweir Allocated = false 1495*cdf0e10cSrcweir count = 0 1496*cdf0e10cSrcweir do 1497*cdf0e10cSrcweir count = count + 1 1498*cdf0e10cSrcweir if strcomp( script, subMenuItems( count ) ) = 0 then 1499*cdf0e10cSrcweir foundMenuItem = true 1500*cdf0e10cSrcweir end if 1501*cdf0e10cSrcweir loop while not( foundMenuItem ) and count < subMenuCount 1502*cdf0e10cSrcweir 1503*cdf0e10cSrcweir linePosition = subMenuItemLinePosition( count ) 1504*cdf0e10cSrcweir 1505*cdf0e10cSrcweir if not( instr( xmlFile( linePosition ), "script://" ) = 0 ) then 1506*cdf0e10cSrcweir Allocated = true 1507*cdf0e10cSrcweir end if 1508*cdf0e10cSrcweir 1509*cdf0e10cSrcweir isAllocatedMenuItem() = Allocated 1510*cdf0e10cSrcweirend Function 1511*cdf0e10cSrcweir 1512*cdf0e10cSrcweir 1513*cdf0e10cSrcweirfunction HasShiftKey( keyCombo ) as boolean 1514*cdf0e10cSrcweir if instr( keyCombo, "SHIFT" ) = 0 then 1515*cdf0e10cSrcweir hasShift = false 1516*cdf0e10cSrcweir else 1517*cdf0e10cSrcweir hasShift = true 1518*cdf0e10cSrcweir end if 1519*cdf0e10cSrcweir 1520*cdf0e10cSrcweir HasShiftKey = hasShift 1521*cdf0e10cSrcweirend function 1522*cdf0e10cSrcweir 1523*cdf0e10cSrcweir 1524*cdf0e10cSrcweirfunction HasControlKey( keyCombo ) as boolean 1525*cdf0e10cSrcweir if instr( keyCombo, "CONTROL" ) = 0 then 1526*cdf0e10cSrcweir hasControl = false 1527*cdf0e10cSrcweir else 1528*cdf0e10cSrcweir hasControl = true 1529*cdf0e10cSrcweir end if 1530*cdf0e10cSrcweir 1531*cdf0e10cSrcweir HasControlKey = hasControl 1532*cdf0e10cSrcweirend function 1533*cdf0e10cSrcweir 1534*cdf0e10cSrcweir 1535*cdf0e10cSrcweirfunction ExtractKeyFromCombo( keyString as string ) as string 1536*cdf0e10cSrcweir while not( instr( keyString, "+" ) = 0 ) 1537*cdf0e10cSrcweir removeTo = instr( keyString, "+ " ) + 2 1538*cdf0e10cSrcweir keyString = mid( keyString, removeTo, ( len( keyString ) - removeTo ) + 1 ) 1539*cdf0e10cSrcweir wend 1540*cdf0e10cSrcweir ExtractKeyFromCombo() = keyString 1541*cdf0e10cSrcweirend function 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir 1544*cdf0e10cSrcweir 1545*cdf0e10cSrcweirREM ------ Event Handling Functions (Listeners) ------ 1546*cdf0e10cSrcweir 1547*cdf0e10cSrcweir 1548*cdf0e10cSrcweirsub KeyListListener() 1549*cdf0e10cSrcweir keyShortCutList = bindingDialog.getControl( "KeyList" ) 1550*cdf0e10cSrcweir selectedShortCut = keyShortCutList.getSelectedItem() 1551*cdf0e10cSrcweir combo = bindingDialog.getControl( "KeyCombo" ) 1552*cdf0e10cSrcweir 1553*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1554*cdf0e10cSrcweir selectedScript = menuScriptList.getSelectedItem() 1555*cdf0e10cSrcweir 1556*cdf0e10cSrcweir keyGroup = combo.text 1557*cdf0e10cSrcweir dim keyGroupIndex as Integer 1558*cdf0e10cSrcweir dim selectedKeyIndex as Integer 1559*cdf0e10cSrcweir for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() ) 1560*cdf0e10cSrcweir if ( allKeyGroupsArray( n ) = keyGroup )then 1561*cdf0e10cSrcweir keyGroupIndex = n 1562*cdf0e10cSrcweir exit for 1563*cdf0e10cSrcweir end if 1564*cdf0e10cSrcweir next n 1565*cdf0e10cSrcweir selectedKeyIndex = keyShortCutList.getSelectedItemPos() 1566*cdf0e10cSrcweir 1567*cdf0e10cSrcweir if keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value > 1 then 1568*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = true 1569*cdf0e10cSrcweir bindingDialog.Model.AddOn.enabled = true 1570*cdf0e10cSrcweir if selectedScript <> "" then 1571*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = true 1572*cdf0e10cSrcweir endif 1573*cdf0e10cSrcweir 1574*cdf0e10cSrcweir else 1575*cdf0e10cSrcweir 1576*cdf0e10cSrcweir if keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value = 1 then 1577*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = false 1578*cdf0e10cSrcweir bindingDialog.Model.AddOn.enabled = false 1579*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = false 1580*cdf0e10cSrcweir else 1581*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = false 1582*cdf0e10cSrcweir bindingDialog.Model.AddOn.enabled = false 1583*cdf0e10cSrcweir if selectedScript <> "" then 1584*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = true 1585*cdf0e10cSrcweir end if 1586*cdf0e10cSrcweir end if 1587*cdf0e10cSrcweir end if 1588*cdf0e10cSrcweirend sub 1589*cdf0e10cSrcweir 1590*cdf0e10cSrcweir 1591*cdf0e10cSrcweirsub SubMenuListListener() 1592*cdf0e10cSrcweir scriptList = bindingDialog.getControl( "ScriptList" ) 1593*cdf0e10cSrcweir subMenuList = bindingDialog.getControl( "SubMenuList" ) 1594*cdf0e10cSrcweir selectedMenuItem = subMenuList.getSelectedItem() 1595*cdf0e10cSrcweir if IsAllocatedMenuItem( selectedMenuItem ) then 1596*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = true 1597*cdf0e10cSrcweir bindingDialog.Model.AddOn.enabled = true 1598*cdf0e10cSrcweir else 1599*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = false 1600*cdf0e10cSrcweir bindingDialog.Model.AddOn.enabled = false 1601*cdf0e10cSrcweir end if 1602*cdf0e10cSrcweirend sub 1603*cdf0e10cSrcweir 1604*cdf0e10cSrcweirREM a keypress listener that in turn fires the MenuCL on a return key even only 1605*cdf0e10cSrcweirsub fireMenuComboListernerOnRet( eventobj as object ) 1606*cdf0e10cSrcweir if (eventobj.KeyCode = 1280 ) then 1607*cdf0e10cSrcweir MenuComboListener() 1608*cdf0e10cSrcweir endif 1609*cdf0e10cSrcweirend sub 1610*cdf0e10cSrcweir 1611*cdf0e10cSrcweir'Populates the SubMenuList with the appropriate menu items from the Top-level menu selected from the combo box 1612*cdf0e10cSrcweirsub MenuComboListener() 1613*cdf0e10cSrcweir combo = bindingDialog.getControl( "MenuCombo" ) 1614*cdf0e10cSrcweir newToplevelMenu = combo.text 1615*cdf0e10cSrcweir counter = 0 1616*cdf0e10cSrcweir do 1617*cdf0e10cSrcweir counter = counter + 1 1618*cdf0e10cSrcweir loop while not( newToplevelMenu = menuItems( counter ) ) 1619*cdf0e10cSrcweir 1620*cdf0e10cSrcweir PopulateSubMenuList( counter ) 1621*cdf0e10cSrcweirend sub 1622*cdf0e10cSrcweir 1623*cdf0e10cSrcweirREM a keypress listener that in turn fires the LLCL on a return key even only 1624*cdf0e10cSrcweirsub fireLangLocComboListernerOnRet( eventobj as object ) 1625*cdf0e10cSrcweir if (eventobj.KeyCode = 1280 ) then 1626*cdf0e10cSrcweir LangLocComboListener() 1627*cdf0e10cSrcweir endif 1628*cdf0e10cSrcweirend sub 1629*cdf0e10cSrcweir 1630*cdf0e10cSrcweirsub LangLocComboListener() 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir combo = bindingDialog.getControl( "LanguageCombo" ) 1633*cdf0e10cSrcweir language = combo.text 1634*cdf0e10cSrcweir combo = bindingDialog.getControl( "LocationCombo" ) 1635*cdf0e10cSrcweir location = combo.text 1636*cdf0e10cSrcweir 1637*cdf0e10cSrcweir PopulateScriptList( language,location ) 1638*cdf0e10cSrcweir 1639*cdf0e10cSrcweir 'Enable/disable Assign button 1640*cdf0e10cSrcweir scriptList = bindingDialog.getControl( "ScriptList" ) 1641*cdf0e10cSrcweir if not (dialogName = "EditDebug") then 1642*cdf0e10cSrcweir if scriptList.getSelectedItem() = "" then 1643*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = false 1644*cdf0e10cSrcweir end if 1645*cdf0e10cSrcweir end if 1646*cdf0e10cSrcweir 1647*cdf0e10cSrcweir if ( location = "Filesystem" ) and ( language <> "Java" ) then 1648*cdf0e10cSrcweir bindingDialog.Model.Browse.enabled = true 1649*cdf0e10cSrcweir if not (dialogName = "EditDebug") then 1650*cdf0e10cSrcweir bindingDialog.Model.fsonly.enabled = true 1651*cdf0e10cSrcweir end if 1652*cdf0e10cSrcweir else 1653*cdf0e10cSrcweir bindingDialog.Model.Browse.enabled = false 1654*cdf0e10cSrcweir if not (dialogName = "EditDebug") then 1655*cdf0e10cSrcweir bindingDialog.Model.fsonly.enabled = false 1656*cdf0e10cSrcweir end if 1657*cdf0e10cSrcweir endif 1658*cdf0e10cSrcweir 1659*cdf0e10cSrcweir ' extra dialog dependant processing 1660*cdf0e10cSrcweir if dialogName = "Menu" then 1661*cdf0e10cSrcweir ' will set New button to false if no text in LableBox 1662*cdf0e10cSrcweir MenuLabelBoxListener() 1663*cdf0e10cSrcweir elseif dialogName = "Key" then 1664*cdf0e10cSrcweir ' will set Assigne button to false if appropriate 1665*cdf0e10cSrcweir KeyListListener() 1666*cdf0e10cSrcweir elseif dialogName = "Event" then 1667*cdf0e10cSrcweir EventListListener() 1668*cdf0e10cSrcweir end if 1669*cdf0e10cSrcweir 1670*cdf0e10cSrcweirend sub 1671*cdf0e10cSrcweir 1672*cdf0e10cSrcweirREM a keypress listener that in turn fires the KeyCL on a return key even only 1673*cdf0e10cSrcweirsub fireKeyComboListernerOnRet( eventobj as object ) 1674*cdf0e10cSrcweir if (eventobj.KeyCode = 1280 ) then 1675*cdf0e10cSrcweir KeyComboListener() 1676*cdf0e10cSrcweir endif 1677*cdf0e10cSrcweirend sub 1678*cdf0e10cSrcweir 1679*cdf0e10cSrcweir'Populates the KeyList with the appropriate key combos from the Top-level key group selected from the combo box 1680*cdf0e10cSrcweirsub KeyComboListener() 1681*cdf0e10cSrcweir combo = bindingDialog.getControl( "KeyCombo" ) 1682*cdf0e10cSrcweir keyGroup = combo.text 1683*cdf0e10cSrcweir for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() ) 1684*cdf0e10cSrcweir if ( allKeyGroupsArray( n ) = keyGroup )then 1685*cdf0e10cSrcweir keyGroupIndex = n 1686*cdf0e10cSrcweir exit for 1687*cdf0e10cSrcweir end if 1688*cdf0e10cSrcweir next n 1689*cdf0e10cSrcweir PopulateKeyBindingList( keyGroupIndex ) 1690*cdf0e10cSrcweirend sub 1691*cdf0e10cSrcweir 1692*cdf0e10cSrcweir 1693*cdf0e10cSrcweirsub MenuLabelBoxListener() 1694*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1695*cdf0e10cSrcweir selectedScript = menuScriptList.getSelectedItem() 1696*cdf0e10cSrcweir 'if the SubMenuList is from a dynamically created menu (e.g. Format) 1697*cdf0e10cSrcweir 'or if the Menu Label text box is empty 1698*cdf0e10cSrcweir subMenuList = bindingDialog.getControl( "SubMenuList" ) 1699*cdf0e10cSrcweir firstItem = subMenuList.getItem( 0 ) 1700*cdf0e10cSrcweir if bindingDialog.Model.MenuLabelBox.text = "" OR firstItem = "Unable to Assign Scripts to this menu" OR selectedScript = "" then 1701*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = false 1702*cdf0e10cSrcweir else 1703*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = true 1704*cdf0e10cSrcweir end if 1705*cdf0e10cSrcweirend sub 1706*cdf0e10cSrcweir 1707*cdf0e10cSrcweirsub AppDocEventListener() 1708*cdf0e10cSrcweir populateEventList( 0 ) 1709*cdf0e10cSrcweir EventListListener() 1710*cdf0e10cSrcweirend sub 1711*cdf0e10cSrcweir 1712*cdf0e10cSrcweir 1713*cdf0e10cSrcweirsub EventListListener() 1714*cdf0e10cSrcweir on error goto ErrorHandler 1715*cdf0e10cSrcweir 1716*cdf0e10cSrcweir eventList = bindingDialog.getControl( "EventList" ) 1717*cdf0e10cSrcweir eventPos = eventList.getSelectedItemPos() 1718*cdf0e10cSrcweir 1719*cdf0e10cSrcweir allApps = bindingDialog.getControl( "AllAppsOption" ) 1720*cdf0e10cSrcweir 1721*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1722*cdf0e10cSrcweir selectedScript = menuScriptList.getSelectedItem() 1723*cdf0e10cSrcweir 1724*cdf0e10cSrcweir dim binding as integer 1725*cdf0e10cSrcweir if allApps.state = true then 1726*cdf0e10cSrcweir binding = allEventTypesApp( eventPos ).Value 1727*cdf0e10cSrcweir else 1728*cdf0e10cSrcweir binding = allEventTypesDoc( eventPos ).Value 1729*cdf0e10cSrcweir endif 1730*cdf0e10cSrcweir 1731*cdf0e10cSrcweir if ( binding > 1 ) then 1732*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = true 1733*cdf0e10cSrcweir else 1734*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = false 1735*cdf0e10cSrcweir end if 1736*cdf0e10cSrcweir 1737*cdf0e10cSrcweir if ( binding = 1 ) then 1738*cdf0e10cSrcweir ' staroffice binding, can't assign 1739*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = false 1740*cdf0e10cSrcweir elseif ( selectedScript <> "" ) then 1741*cdf0e10cSrcweir bindingDialog.Model.NewButton.enabled = true 1742*cdf0e10cSrcweir end if 1743*cdf0e10cSrcweir exit sub 1744*cdf0e10cSrcweir 1745*cdf0e10cSrcweir ErrorHandler: 1746*cdf0e10cSrcweir reset 1747*cdf0e10cSrcweir bindingDialog.Model.Delete.enabled = false 1748*cdf0e10cSrcweir 1749*cdf0e10cSrcweirend sub 1750*cdf0e10cSrcweir 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweirREM ------ Event Handling Functions (Buttons) ------ 1753*cdf0e10cSrcweir 1754*cdf0e10cSrcweirfunction getFilePicker() as Object 1755*cdf0e10cSrcweir REM file dialog 1756*cdf0e10cSrcweir oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" ) 1757*cdf0e10cSrcweir 1758*cdf0e10cSrcweir combo = bindingDialog.getControl( "LanguageCombo" ) 1759*cdf0e10cSrcweir language = combo.text 1760*cdf0e10cSrcweir currentFilter = "" 1761*cdf0e10cSrcweir 1762*cdf0e10cSrcweir for langIndex = 0 to ubound(languages()) 1763*cdf0e10cSrcweir if( languages(langIndex) <> "Java" ) then 1764*cdf0e10cSrcweir filterName = languages(langIndex) + " (" 1765*cdf0e10cSrcweir filterVal="" 1766*cdf0e10cSrcweir extns = extensions(langIndex) 1767*cdf0e10cSrcweir for extnIndex = lbound(extns()) to ubound(extns()) 1768*cdf0e10cSrcweir filterName = filterName + "*." + extns(extnIndex) + "," 1769*cdf0e10cSrcweir filterVal = filterVal + "*." + extns(extnIndex) + "," 1770*cdf0e10cSrcweir next extnIndex 1771*cdf0e10cSrcweir filterName = left(filterName, len(filterName) -1) + ")" 1772*cdf0e10cSrcweir filterVal = left(filterVal, len(filterVal) -1) 1773*cdf0e10cSrcweir if(instr(filterName,language) = 1 ) then 1774*cdf0e10cSrcweir currentFilter = filterName 1775*cdf0e10cSrcweir end if 1776*cdf0e10cSrcweir oFilePicker.AppendFilter(filterName, filterVal) 1777*cdf0e10cSrcweir end if 1778*cdf0e10cSrcweir next langIndex 1779*cdf0e10cSrcweir if(len(currentFilter) > 0 ) then 1780*cdf0e10cSrcweir oFilePicker.SetCurrentFilter( currentFilter ) 1781*cdf0e10cSrcweir end if 1782*cdf0e10cSrcweir 1783*cdf0e10cSrcweir If sFileURL = "" Then 1784*cdf0e10cSrcweir oSettings = CreateUnoService( "com.sun.star.frame.Settings" ) 1785*cdf0e10cSrcweir oPathSettings = oSettings.getByName( "PathSettings" ) 1786*cdf0e10cSrcweir sFileURL = oPathSettings.getPropertyValue( "Work" ) 1787*cdf0e10cSrcweir End If 1788*cdf0e10cSrcweir 1789*cdf0e10cSrcweir REM set display directory 1790*cdf0e10cSrcweir oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 1791*cdf0e10cSrcweir 1792*cdf0e10cSrcweir If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then 1793*cdf0e10cSrcweir oFilePicker.setDisplayDirectory( sFileURL ) 1794*cdf0e10cSrcweir End If 1795*cdf0e10cSrcweir getFilePicker() = oFilePicker 1796*cdf0e10cSrcweirend function 1797*cdf0e10cSrcweir 1798*cdf0e10cSrcweirSub DoBrowseAndEdit() 1799*cdf0e10cSrcweir Dim oFilePicker As Object, oSimpleFileAccess As Object 1800*cdf0e10cSrcweir Dim oSettings As Object, oPathSettings As Object 1801*cdf0e10cSrcweir Dim sFileURL As String 1802*cdf0e10cSrcweir Dim sFiles As Variant 1803*cdf0e10cSrcweir 1804*cdf0e10cSrcweir oFilePicker = getFilePicker() 1805*cdf0e10cSrcweir REM execute file dialog 1806*cdf0e10cSrcweir If oFilePicker.execute() Then 1807*cdf0e10cSrcweir sFiles = oFilePicker.getFiles() 1808*cdf0e10cSrcweir 1809*cdf0e10cSrcweir sFileURL = sFiles(0) 1810*cdf0e10cSrcweir oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 1811*cdf0e10cSrcweir If oSimpleFileAccess.exists( sFileURL ) Then 1812*cdf0e10cSrcweir for langIndex = 0 to ubound(languages()) 1813*cdf0e10cSrcweir If (instr(oFilePicker.GetCurrentFilter, languages(langIndex)) = 1 ) then 1814*cdf0e10cSrcweir RunDebugger(languages(langIndex), sFileURL, "") 1815*cdf0e10cSrcweir End If 1816*cdf0e10cSrcweir next langIndex 1817*cdf0e10cSrcweir End If 1818*cdf0e10cSrcweir bindingDialog.endExecute() 1819*cdf0e10cSrcweir End If 1820*cdf0e10cSrcweirEnd Sub 1821*cdf0e10cSrcweir 1822*cdf0e10cSrcweirSub RunDebugger(lang as String, uri as String, filename as String) 1823*cdf0e10cSrcweir dim document as object 1824*cdf0e10cSrcweir dim dispatcher as object 1825*cdf0e10cSrcweir dim parser as object 1826*cdf0e10cSrcweir dim url as new com.sun.star.util.URL 1827*cdf0e10cSrcweir 1828*cdf0e10cSrcweir document = ThisComponent.CurrentController.Frame 1829*cdf0e10cSrcweir parser = createUnoService("com.sun.star.util.URLTransformer") 1830*cdf0e10cSrcweir dim args(2) as new com.sun.star.beans.PropertyValue 1831*cdf0e10cSrcweir args(0).Name = "language" 1832*cdf0e10cSrcweir args(0).Value = lang 1833*cdf0e10cSrcweir args(1).Name = "uri" 1834*cdf0e10cSrcweir args(1).Value = uri 1835*cdf0e10cSrcweir args(2).Name = "filename" 1836*cdf0e10cSrcweir args(2).Value = filename 1837*cdf0e10cSrcweir 1838*cdf0e10cSrcweir url.Complete = "script://_$DebugRunner.Debug?" _ 1839*cdf0e10cSrcweir + "language=Java&function=DebugRunner.go" _ 1840*cdf0e10cSrcweir + "&location=share" 1841*cdf0e10cSrcweir 1842*cdf0e10cSrcweir parser.parseStrict(url) 1843*cdf0e10cSrcweir disp = document.queryDispatch(url,"",0) 1844*cdf0e10cSrcweir disp.dispatch(url, args()) 1845*cdf0e10cSrcweirEnd Sub 1846*cdf0e10cSrcweir 1847*cdf0e10cSrcweirsub DoEdit() 1848*cdf0e10cSrcweir Dim scriptInfo as Object 1849*cdf0e10cSrcweir 1850*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1851*cdf0e10cSrcweir selectedScript = menuScriptList.getSelectedItem() 1852*cdf0e10cSrcweir 1853*cdf0e10cSrcweir if not (selectedScript = "") then 1854*cdf0e10cSrcweir scripts() = scriptDisplayList(0) 1855*cdf0e10cSrcweir for n = LBOUND( scripts() ) to UBOUND( scripts() ) 1856*cdf0e10cSrcweir if ( scripts( n ).Name = selectedScript ) then 1857*cdf0e10cSrcweir scriptInfo = scripts( n ).Value 1858*cdf0e10cSrcweir exit for 1859*cdf0e10cSrcweir end if 1860*cdf0e10cSrcweir next n 1861*cdf0e10cSrcweir 1862*cdf0e10cSrcweir RunDebugger(scriptInfo.getLanguage, scriptInfo.getParcelURI, scriptInfo.getFunctionName) 1863*cdf0e10cSrcweir bindingDialog.endExecute() 1864*cdf0e10cSrcweir end if 1865*cdf0e10cSrcweirend sub 1866*cdf0e10cSrcweir 1867*cdf0e10cSrcweirsub MenuOKButton() 1868*cdf0e10cSrcweir WriteXMLFromArray() 1869*cdf0e10cSrcweir bindingDialog.endExecute() 1870*cdf0e10cSrcweirend sub 1871*cdf0e10cSrcweir 1872*cdf0e10cSrcweir 1873*cdf0e10cSrcweirsub MenuCancelButton() 1874*cdf0e10cSrcweir bindingDialog.endExecute() 1875*cdf0e10cSrcweirend sub 1876*cdf0e10cSrcweir 1877*cdf0e10cSrcweir 1878*cdf0e10cSrcweirsub MenuHelpButton() 1879*cdf0e10cSrcweir helpDialog = LoadDialog( "ScriptBindingLibrary", "HelpBinding" ) 1880*cdf0e10cSrcweir helpDialog.execute() 1881*cdf0e10cSrcweirend sub 1882*cdf0e10cSrcweir 1883*cdf0e10cSrcweir 1884*cdf0e10cSrcweirsub MenuDeleteButton() 1885*cdf0e10cSrcweir subMenuList = bindingDialog.getControl( "SubMenuList" ) 1886*cdf0e10cSrcweir linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 ) 1887*cdf0e10cSrcweir 1888*cdf0e10cSrcweir RemoveBinding( linePos ) 1889*cdf0e10cSrcweir 1890*cdf0e10cSrcweir REM Update the top-level menu's line positions 1891*cdf0e10cSrcweir combo = bindingDialog.getControl( "MenuCombo" ) 1892*cdf0e10cSrcweir newToplevelMenu = combo.text 1893*cdf0e10cSrcweir counter = 0 1894*cdf0e10cSrcweir do 1895*cdf0e10cSrcweir counter = counter + 1 1896*cdf0e10cSrcweir loop while not( newToplevelMenu = menuItems( counter ) ) 1897*cdf0e10cSrcweir UpdateTopLevelMenus( counter + 1, false ) 1898*cdf0e10cSrcweir 1899*cdf0e10cSrcweir MenuComboListener() 1900*cdf0e10cSrcweir 1901*cdf0e10cSrcweir subMenuList.selectItemPos( subMenuList.getSelectedItemPos(), true ) 1902*cdf0e10cSrcweirend sub 1903*cdf0e10cSrcweir 1904*cdf0e10cSrcweir 1905*cdf0e10cSrcweirsub MenuNewButton() 1906*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1907*cdf0e10cSrcweir selectedScript = menuScriptList.getSelectedItem() 1908*cdf0e10cSrcweir scriptURI = getScriptURI( selectedScript ) 1909*cdf0e10cSrcweir newMenuLabel = bindingDialog.Model.MenuLabelBox.text 1910*cdf0e10cSrcweir 1911*cdf0e10cSrcweir subMenuList = bindingDialog.getControl( "SubMenuList" ) 1912*cdf0e10cSrcweir 1913*cdf0e10cSrcweir REM Update the top-level menu's line positions 1914*cdf0e10cSrcweir combo = bindingDialog.getControl( "MenuCombo" ) 1915*cdf0e10cSrcweir newToplevelMenu = combo.text 1916*cdf0e10cSrcweir counter = 0 1917*cdf0e10cSrcweir do 1918*cdf0e10cSrcweir counter = counter + 1 1919*cdf0e10cSrcweir loop while not( newToplevelMenu = menuItems( counter ) ) 1920*cdf0e10cSrcweir UpdateTopLevelMenus( counter + 1, true ) 1921*cdf0e10cSrcweir 1922*cdf0e10cSrcweir REM New line position is one ahead of the selected sub menu item 1923*cdf0e10cSrcweir linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 ) + 1 1924*cdf0e10cSrcweir 1925*cdf0e10cSrcweir AddNewMenuBinding( scriptURI, newMenuLabel, linePos ) 1926*cdf0e10cSrcweir 1927*cdf0e10cSrcweir MenuComboListener() 1928*cdf0e10cSrcweir subMenuList.selectItemPos( subMenuList.getSelectedItemPos() + 1, true ) 1929*cdf0e10cSrcweir SubMenuListListener() 1930*cdf0e10cSrcweirend sub 1931*cdf0e10cSrcweir 1932*cdf0e10cSrcweirsub BrowseButton() 1933*cdf0e10cSrcweir Dim oFilePicker As Object, oSimpleFileAccess As Object 1934*cdf0e10cSrcweir Dim oSettings As Object, oPathSettings As Object 1935*cdf0e10cSrcweir Dim sFileURL As String 1936*cdf0e10cSrcweir Dim sFiles As Variant 1937*cdf0e10cSrcweir 1938*cdf0e10cSrcweir oFilePicker = getFilePicker() 1939*cdf0e10cSrcweir 1940*cdf0e10cSrcweir REM execute file dialog 1941*cdf0e10cSrcweir If oFilePicker.execute() Then 1942*cdf0e10cSrcweir sFiles = oFilePicker.getFiles() 1943*cdf0e10cSrcweir sFileURL = sFiles(0) 1944*cdf0e10cSrcweir oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 1945*cdf0e10cSrcweir If oSimpleFileAccess.exists( sFileURL ) Then 1946*cdf0e10cSrcweir REM add sFileURL to the list 1947*cdf0e10cSrcweir ReDim preserve filesysScripts(filesysCount) as String 1948*cdf0e10cSrcweir filesysScripts( filesysCount ) = sFileURL 1949*cdf0e10cSrcweir filesysCount=filesysCount+1 1950*cdf0e10cSrcweir ' if user changed filter in file picker then populate 1951*cdf0e10cSrcweir ' language with language associated with that in file picker 1952*cdf0e10cSrcweir sFilter = oFilePicker.getCurrentFilter() 1953*cdf0e10cSrcweir langCombo = bindingDialog.getControl( "LanguageCombo" ) 1954*cdf0e10cSrcweir dim items() as String 1955*cdf0e10cSrcweir items() = langCombo.getItems() 1956*cdf0e10cSrcweir for index = lbound(items()) to ubound(items()) 1957*cdf0e10cSrcweir iPos = inStr(sFilter," ") 1958*cdf0e10cSrcweir Dim theLanguage as String 1959*cdf0e10cSrcweir if( iPos > 0 ) then 1960*cdf0e10cSrcweir theLanguage = Left( sFilter, iPos - 1) 1961*cdf0e10cSrcweir if ( theLanguage = items( index ) ) then 1962*cdf0e10cSrcweir langCombo.text = items( index ) 1963*cdf0e10cSrcweir exit for 1964*cdf0e10cSrcweir end if 1965*cdf0e10cSrcweir end if 1966*cdf0e10cSrcweir next index 1967*cdf0e10cSrcweir End If 1968*cdf0e10cSrcweir End If 1969*cdf0e10cSrcweir LangLocComboListener() 1970*cdf0e10cSrcweirEnd Sub 1971*cdf0e10cSrcweir 1972*cdf0e10cSrcweirsub KeyOKButton() 1973*cdf0e10cSrcweir WriteXMLFromArray() 1974*cdf0e10cSrcweir bindingDialog.endExecute() 1975*cdf0e10cSrcweirend sub 1976*cdf0e10cSrcweir 1977*cdf0e10cSrcweir 1978*cdf0e10cSrcweirsub KeyCancelButton() 1979*cdf0e10cSrcweir bindingDialog.endExecute() 1980*cdf0e10cSrcweirend sub 1981*cdf0e10cSrcweir 1982*cdf0e10cSrcweir 1983*cdf0e10cSrcweirsub KeyHelpButton() 1984*cdf0e10cSrcweir helpDialog = LoadDialog( "ScriptBindingLibrary", "HelpBinding" ) 1985*cdf0e10cSrcweir helpDialog.execute() 1986*cdf0e10cSrcweirend sub 1987*cdf0e10cSrcweir 1988*cdf0e10cSrcweir 1989*cdf0e10cSrcweirsub KeyNewButton() 1990*cdf0e10cSrcweir combo = bindingDialog.getControl( "KeyCombo" ) 1991*cdf0e10cSrcweir keyGroup = combo.text 1992*cdf0e10cSrcweir for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() ) 1993*cdf0e10cSrcweir if ( allKeyGroupsArray( n ) = keyGroup )then 1994*cdf0e10cSrcweir keyGroupIndex = n 1995*cdf0e10cSrcweir exit for 1996*cdf0e10cSrcweir end if 1997*cdf0e10cSrcweir next n 1998*cdf0e10cSrcweir menuScriptList = bindingDialog.getControl( "ScriptList" ) 1999*cdf0e10cSrcweir script = menuScriptList.getSelectedItem() 2000*cdf0e10cSrcweir scriptURI = getScriptURI( script ) 2001*cdf0e10cSrcweir 2002*cdf0e10cSrcweir keyList = bindingDialog.getControl( "KeyList" ) 2003*cdf0e10cSrcweir keyIndex = keyList.getSelectedItemPos() 2004*cdf0e10cSrcweir ShortCutKeyArray() = KeyBindArrayOfArrays( keyGroupIndex ) 2005*cdf0e10cSrcweir keyText = ShortCutKeyArray( keyIndex ) 2006*cdf0e10cSrcweir 2007*cdf0e10cSrcweir AddNewKeyBinding( scriptURI, HasShiftKey( keyText ), HasControlKey( keyText ), ExtractKeyFromCombo( keyText ) ) 2008*cdf0e10cSrcweir 2009*cdf0e10cSrcweir KeyComboListener() 2010*cdf0e10cSrcweirend sub 2011*cdf0e10cSrcweir 2012*cdf0e10cSrcweir 2013*cdf0e10cSrcweirsub KeyDeleteButton() 2014*cdf0e10cSrcweir 2015*cdf0e10cSrcweir keyShortCutList = bindingDialog.getControl( "KeyList" ) 2016*cdf0e10cSrcweir selectedShortCut = keyShortCutList.getSelectedItem() 2017*cdf0e10cSrcweir combo = bindingDialog.getControl( "KeyCombo" ) 2018*cdf0e10cSrcweir 2019*cdf0e10cSrcweir keyGroup = combo.text 2020*cdf0e10cSrcweir dim keyGroupIndex as Integer 2021*cdf0e10cSrcweir dim selectedKeyIndex as Integer 2022*cdf0e10cSrcweir for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() ) 2023*cdf0e10cSrcweir if ( allKeyGroupsArray( n ) = keyGroup )then 2024*cdf0e10cSrcweir keyGroupIndex = n 2025*cdf0e10cSrcweir exit for 2026*cdf0e10cSrcweir end if 2027*cdf0e10cSrcweir next n 2028*cdf0e10cSrcweir selectedKeyIndex = keyShortCutList.getSelectedItemPos() 2029*cdf0e10cSrcweir linePosition = keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value 2030*cdf0e10cSrcweir keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value = 0 2031*cdf0e10cSrcweir keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Name = "" 2032*cdf0e10cSrcweir RemoveBinding( linePosition ) 2033*cdf0e10cSrcweir KeyComboListener() 2034*cdf0e10cSrcweirend sub 2035*cdf0e10cSrcweir 2036*cdf0e10cSrcweir 2037*cdf0e10cSrcweirsub EventNewButton() 2038*cdf0e10cSrcweir eventScriptList = bindingDialog.getControl( "ScriptList" ) 2039*cdf0e10cSrcweir selectedScript = eventScriptList.getSelectedItem() 2040*cdf0e10cSrcweir scriptURI = getScriptURI( selectedScript ) 2041*cdf0e10cSrcweir eventList = bindingDialog.getControl( "EventList" ) 2042*cdf0e10cSrcweir eventPosition = eventList.getSelectedItemPos() 2043*cdf0e10cSrcweir 2044*cdf0e10cSrcweir allApps = bindingDialog.getControl( "AllAppsOption" ) 2045*cdf0e10cSrcweir dim isApp as boolean 2046*cdf0e10cSrcweir if allApps.state = true then 'Application 2047*cdf0e10cSrcweir isApp = true 2048*cdf0e10cSrcweir else 'Document 2049*cdf0e10cSrcweir isApp = false 2050*cdf0e10cSrcweir end if 2051*cdf0e10cSrcweir AddNewEventBinding( scriptURI, eventPosition, isApp ) 2052*cdf0e10cSrcweir 2053*cdf0e10cSrcweir populateEventList( eventPosition ) 2054*cdf0e10cSrcweir EventListListener() 2055*cdf0e10cSrcweirend sub 2056*cdf0e10cSrcweir 2057*cdf0e10cSrcweir 2058*cdf0e10cSrcweirsub EventDeleteButton() 2059*cdf0e10cSrcweir eventList = bindingDialog.getControl( "EventList" ) 2060*cdf0e10cSrcweir REM Check that combo is a script 2061*cdf0e10cSrcweir eventPosition = eventList.getSelectedItemPos() 2062*cdf0e10cSrcweir 2063*cdf0e10cSrcweir allApps = bindingDialog.getControl( "AllAppsOption" ) 2064*cdf0e10cSrcweir if allApps.state = true then 'Application 2065*cdf0e10cSrcweir linePosition = allEventTypesApp( eventPosition ).Value 2066*cdf0e10cSrcweir 'dim eventProp as new com.sun.star.beans.PropertyValue 2067*cdf0e10cSrcweir 'eventProp.Name = "" 2068*cdf0e10cSrcweir 'eventProp.Value = 0 2069*cdf0e10cSrcweir allEventTypesApp( eventPosition ).Name = "" 2070*cdf0e10cSrcweir allEventTypesApp( eventPosition ).Value = 0 2071*cdf0e10cSrcweir RemoveBinding( linePosition ) 2072*cdf0e10cSrcweir else 'Document 2073*cdf0e10cSrcweir 'DeleteEvent( allEventTypes( eventPosition ) ) 2074*cdf0e10cSrcweir allEventTypesDoc( eventPosition ).Name = "" 2075*cdf0e10cSrcweir allEventTypesDoc( eventPosition ).Value = 0 2076*cdf0e10cSrcweir end if 2077*cdf0e10cSrcweir 2078*cdf0e10cSrcweir PopulateEventList( eventPosition ) 2079*cdf0e10cSrcweir EventListListener() 2080*cdf0e10cSrcweirend sub 2081*cdf0e10cSrcweir 2082*cdf0e10cSrcweir 2083*cdf0e10cSrcweirsub EventOKButton 2084*cdf0e10cSrcweir WriteEventsToDoc() 2085*cdf0e10cSrcweir WriteXMLFromArray() 2086*cdf0e10cSrcweir bindingDialog.endExecute() 2087*cdf0e10cSrcweirend sub 2088*cdf0e10cSrcweir 2089*cdf0e10cSrcweir 2090*cdf0e10cSrcweirsub HelpOKButton() 2091*cdf0e10cSrcweir helpDialog.endExecute() 2092*cdf0e10cSrcweirend sub 2093*cdf0e10cSrcweir</script:module> 2094