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