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