forked from amazingfate/loongoffice
987 lines
31 KiB
XML
987 lines
31 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ScriptBinding" script:language="StarBasic">REM ***** BASIC *****
|
|
|
|
REM ----- Global Variables -----
|
|
|
|
'bindingDialog can refer to either KeyBinding or MenuBinding dialog
|
|
private bindingDialog as object
|
|
private helpDialog as object
|
|
|
|
'Array to store lines from the xml file
|
|
private xmlFile() as string
|
|
'Name of the xml file [writer/calc][menubar/keybindings].xml
|
|
private xmlFileName as string
|
|
'Number of lines in the xml file
|
|
private numberOfLines as integer
|
|
|
|
'Parallel arrays to store all top-level menu names and line positions
|
|
private menuItems() as string
|
|
private menuItemLinePosition() as integer
|
|
'Counter for the number of top-level menus
|
|
private menuCount as integer
|
|
|
|
'Parallel arrays to store all sub-menu names and line positions for a particular top-level menu
|
|
private subMenuItems() as string
|
|
private subMenuItemLinePosition() as integer
|
|
'Counter for the number of sub-menus
|
|
private subMenuCount as integer
|
|
|
|
'Parallel arrays to store all script names and line positions
|
|
private scriptNames() as string
|
|
private scriptLinePosition() as integer
|
|
'Counter for the number of scripts
|
|
private scriptCount as integer
|
|
|
|
'Array to store all combinations of key bindings
|
|
private allKeyBindings() as string
|
|
|
|
|
|
REM ------ Storage Refresh Function ------
|
|
|
|
|
|
sub RefreshUserScripts()
|
|
smgr = getProcessServiceManager()
|
|
context = smgr.getPropertyValue( "DefaultContext" )
|
|
scriptstoragemgr = context.getValueByName( "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager" )
|
|
|
|
storage = scriptstoragemgr.getScriptStorage( 1 )
|
|
storage.refresh()
|
|
end sub
|
|
|
|
|
|
REM ----- Launch Functions -----
|
|
|
|
Sub ExecuteKeyBinding()
|
|
xmlFileName = GetDocumentType( "Key" )
|
|
|
|
if not (ReadXMLToArray( "Key" )) then
|
|
Exit Sub
|
|
endif
|
|
|
|
bindingDialog = LoadDialog( "ScriptBindingLibrary", "KeyBinding" )
|
|
PopulateScriptList()
|
|
CreateAllKeyBindings()
|
|
PopulateTopLevelKeyBindingList()
|
|
PopulateKeyBindingList( 1, 11 )
|
|
bindingDialog.execute()
|
|
end Sub
|
|
|
|
|
|
Sub ExecuteMenuBinding()
|
|
xmlFileName = GetDocumentType( "Menu" )
|
|
if not (ReadXMLToArray( "Menu" )) then
|
|
Exit Sub
|
|
endif
|
|
|
|
bindingDialog = LoadDialog( "ScriptBindingLibrary", "MenuBinding" )
|
|
PopulateScriptList()
|
|
PopulateMenuCombo()
|
|
PopulateSubMenuList( 1 )
|
|
MenuLabelBoxListener()
|
|
bindingDialog.execute()
|
|
end Sub
|
|
|
|
|
|
REM ----- Initialising functions -----
|
|
|
|
|
|
function LoadDialog( libName as string, dialogName as string ) as object
|
|
dim library as object
|
|
dim libDialog as object
|
|
dim runtimeDialog as object
|
|
|
|
libContainer = DialogLibraries
|
|
libContainer.LoadLibrary( libName )
|
|
library = libContainer.getByName( libname )
|
|
libDialog = library.getByName( dialogName )
|
|
runtimeDialog = CreateUnoDialog( libDialog )
|
|
|
|
LoadDialog() = runtimeDialog
|
|
end function
|
|
|
|
|
|
function GetDocumentType( bindingType as string ) as string
|
|
document = StarDesktop.ActiveFrame.Controller.Model
|
|
Dim errornumber As Integer
|
|
errornumber = 111
|
|
Error errornumber
|
|
if document.SupportsService("com.sun.star.sheet.SpreadsheetDocument") then
|
|
if bindingType = "Key" then
|
|
GetDocumentType() = "calckeybinding.xml"
|
|
else
|
|
if bindingType = "Menu" then
|
|
GetDocumentType() = "calcmenubar.xml"
|
|
end if
|
|
end if
|
|
else
|
|
if document.SupportsService("com.sun.star.text.TextDocument") then
|
|
if bindingType = "Key" then
|
|
GetDocumentType() = "writerkeybinding.xml"
|
|
else
|
|
if bindingType = "Menu" then
|
|
GetDocumentType() = "writermenubar.xml"
|
|
end if
|
|
end if
|
|
else
|
|
msgbox "Couldn't determine file type"
|
|
end if
|
|
end if
|
|
end function
|
|
|
|
|
|
function GetOfficePath() as string
|
|
REM Error check and prompt user to manually input Office Path
|
|
settings = CreateUnoService( "com.sun.star.frame.Settings" )
|
|
path = settings.getByName( "PathSettings" )
|
|
unformattedOfficePath = path.getPropertyValue( "UserPath" )
|
|
|
|
dim officePath as string
|
|
const removeFromEnd = "/user"
|
|
const removeFromEndWindows = "\user"
|
|
|
|
REM If Solaris or Linux
|
|
if not ( instr( unformattedOfficePath, removeFromEnd ) = 0 ) then
|
|
endPosition = instr( unformattedOfficePath, removeFromEnd )
|
|
officePath = mid( unformattedOfficePath, 1, endPosition )
|
|
REM If Windows
|
|
else if not ( instr( unformattedOfficePath, removeFromEndWindows ) = 0 ) then
|
|
endPosition = instr( unformattedOfficePath, removeFromEndWindows )
|
|
officePath = mid( unformattedOfficePath, 1, endPosition )
|
|
while instr( officePath, "\" ) > 0
|
|
backSlash = instr( officePath, "\" )
|
|
startPath = mid( officePath, 1, backSlash - 1 )
|
|
endPath = mid( officePath, backslash + 1, len( officePath ) - backSlash )
|
|
officePath = startPath + "/" + endPath
|
|
wend
|
|
else
|
|
msgbox "Office path not found"
|
|
REM Prompt user
|
|
end if
|
|
end if
|
|
|
|
GetOfficePath() = officePath
|
|
end function
|
|
|
|
|
|
|
|
REM ----- File I/O functions -----
|
|
|
|
|
|
function ReadXMLToArray( bindingType as string ) as boolean
|
|
On Error Goto ErrorHandler
|
|
simplefileaccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
|
|
filestream = simplefileaccess.openFileRead( "file://" + GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName )
|
|
|
|
textin = CreateUnoService( "com.sun.star.io.TextInputStream" )
|
|
textin.setInputStream( filestream )
|
|
|
|
redim xmlFile( 400 ) as String
|
|
redim menuItems( 30 ) as String
|
|
redim menuItemLinePosition( 30 ) as Integer
|
|
redim scriptNames( 120 ) as string
|
|
redim scriptLinePosition( 120) as integer
|
|
|
|
lineCount = 1
|
|
menuCount = 1
|
|
scriptCount = 1
|
|
|
|
do while not textin.isEOF()
|
|
xmlline = textin.readLine()
|
|
xmlFile( lineCount ) = xmlline
|
|
|
|
const menuItemWhiteSpace = 2
|
|
const menuXMLTag = "<menu:menu"
|
|
|
|
'If line read from XML file is a Menu title
|
|
if bindingType = "Menu" then
|
|
'If the xml line is a top-level menu
|
|
if instr( xmlline, menuXMLTag ) = menuItemWhiteSpace then
|
|
menuLabel = ExtractLabelFromXMLLine( xmlline )
|
|
menuItems( menuCount ) = menuLabel
|
|
menuItemLinePosition( menuCount ) = lineCount
|
|
menuCount = menuCount + 1
|
|
end if
|
|
else if bindingType = "Key" then
|
|
'If the xml line is a key binding
|
|
if instr( xmlFile( lineCount ), "<accel:item" ) > 0 then
|
|
scriptName = ""
|
|
if instr( xmlFile( lineCount ), "accel:shift="+chr$(34)+"true"+chr$(34) ) > 0 then
|
|
scriptName = scriptName + "SHIFT + "
|
|
end if
|
|
if instr( xmlFile( lineCount ), "accel:mod1="+chr$(34)+"true"+chr$(34) ) > 0 then
|
|
scriptName = scriptName + "CONTROL + "
|
|
end if
|
|
scriptName = scriptName + ExtractKeyCodeFromXMLLine( xmlline )
|
|
scriptNames( scriptCount ) = scriptName
|
|
' msgbox( "scriptNames( " + scriptCount + " ) " + scriptNames( scriptCount ) )
|
|
scriptLinePosition( scriptCount ) = lineCount
|
|
scriptCount = scriptCount + 1
|
|
end if
|
|
end if
|
|
end if
|
|
|
|
lineCount = lineCount + 1
|
|
loop
|
|
|
|
'Set global variable numberOfLines (lineCount is one too many at end of the loop)
|
|
numberOfLines = lineCount - 1
|
|
'Set global variable scriptCount (it is one too many at end of the loop)
|
|
scriptCount = scriptCount - 1
|
|
'Set global variable menuCount (it is one too many at end of the loop)
|
|
menuCount = menuCount - 1
|
|
|
|
filestream.closeInput()
|
|
ReadXMLToArray( ) = true
|
|
Exit function
|
|
|
|
ErrorHandler:
|
|
reset
|
|
MsgBox ("Error: Unable to read Star Office configuration file - " + xmlFileName + chr$(10) + chr$(10) + "Action: Please reinstall Scripting Framework",0,"Error" )
|
|
ReadXMLToArray( ) = false
|
|
end function
|
|
|
|
|
|
Sub WriteXMLFromArray()
|
|
On Error Goto ErrorHandler
|
|
originalFile = "file:///" + GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName
|
|
backupFile = originalFile + ".tmp"
|
|
|
|
simplefileaccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
|
|
simplefileaccess.move( originalFile, backupFile )
|
|
outfilestream = simplefileaccess.openFileWrite( originalFile )
|
|
|
|
REM Alternative Debug Lines
|
|
'simplefileaccess.kill( "file:///" + GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName + ".temp" )
|
|
'outfilestream = simplefileaccess.openFileWrite( "file:///"+ GetOfficePath() + "user/config/soffice.cfg/" + xmlFileName + ".temp" )
|
|
|
|
textout = CreateUnoService( "com.sun.star.io.TextOutputStream" )
|
|
textout.setOutputStream( outfilestream )
|
|
|
|
for n = 1 to numberOfLines
|
|
'If writing the last line then no new line character added
|
|
if n = numberOfLines then
|
|
textout.writeString( xmlFile(n) )
|
|
else
|
|
textout.writeString( xmlFile(n) + chr$(10) )
|
|
end if
|
|
next n
|
|
|
|
outfilestream.flush()
|
|
outfilestream.closeOutput()
|
|
|
|
if simplefileaccess.exists( backupFile ) then
|
|
simplefileaccess.kill( backupFile)
|
|
endif
|
|
|
|
Exit Sub
|
|
|
|
ErrorHandler:
|
|
reset
|
|
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" )
|
|
if simplefileaccess.exists( backupFile ) then
|
|
simplefileaccess.move( backupFile, originalFile)
|
|
endif
|
|
end Sub
|
|
|
|
|
|
|
|
REM ----- Array update functions -----
|
|
|
|
|
|
sub AddNewMenuBinding( newScript as string, newMenuLabel as string, newLinePosition as integer )
|
|
dim newXmlFile( 400 ) as string
|
|
dim newLineInserted as boolean
|
|
dim lineCounter as integer
|
|
lineCounter = 1
|
|
|
|
do while lineCounter <= numberOfLines
|
|
if not newLineInserted then
|
|
REM If the line number is the position at which to insert the new line
|
|
if lineCounter = newLinePosition then
|
|
if( instr( xmlFile( lineCounter ), "<menu:menupopup>" ) > 0 ) then
|
|
msgbox("It is <menu:menupopup>")
|
|
indent = GetMenuWhiteSpace( xmlFile( newLinePosition + 1 ) )
|
|
newXmlFile( lineCounter ) = xmlFile( lineCounter )
|
|
newXmlFile( lineCounter + 1 ) = ( 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)+"/>" )
|
|
else
|
|
msgbox("It is NOT <menu:menupopup>")
|
|
indent = GetMenuWhiteSpace( xmlFile( newLinePosition - 1 ) )
|
|
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)+"/>" )
|
|
newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
|
|
end if
|
|
REM added -1 for debug -->
|
|
' indent = GetMenuWhiteSpace( xmlFile( newLinePosition ) )
|
|
' 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)+"/>" )
|
|
' newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
|
|
newLineInserted = true
|
|
else
|
|
newXmlFile( lineCounter ) = xmlFile( lineCounter )
|
|
end if
|
|
else
|
|
REM if the new line has been inserted the read from one position behind
|
|
newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
|
|
end if
|
|
lineCounter = lineCounter + 1
|
|
loop
|
|
|
|
numberOfLines = numberOfLines + 1
|
|
|
|
REM read the new file into the global array
|
|
for n = 1 to numberOfLines
|
|
xmlFile( n ) = newXmlFile( n )
|
|
next n
|
|
|
|
end sub
|
|
|
|
|
|
sub AddNewKeyBinding( scriptName as string, shift as boolean, control as boolean, key as string )
|
|
|
|
dim keyCombo as string
|
|
newLine = " <accel:item accel:code="+chr$(34)+"KEY_" + key +chr$(34)
|
|
if shift then
|
|
keyCombo = "SHIFT + "
|
|
newLine = newLine + " accel:shift="+chr$(34)+"true"+chr$(34)
|
|
end if
|
|
if control then
|
|
keyCombo = keyCombo + "CONTROL + "
|
|
newLine = newLine + " accel:mod1="+chr$(34)+"true"+chr$(34)
|
|
end if
|
|
keyCombo = keyCombo + key
|
|
newLine = newLine + " xlink:href="+chr$(34)+"script://" + scriptName
|
|
|
|
REM For this release of the scripting framework only use application binding
|
|
applicationBinding = true
|
|
if applicationBinding then
|
|
newLine = newLine + "?location=application"+chr$(34)+"/>"
|
|
else
|
|
newLine = newLine + "?location=document"+chr$(34)+"/>"
|
|
end if
|
|
|
|
scriptNames( scriptCount ) = keyCombo
|
|
scriptLinePosition( scriptCount ) = numberOfLines
|
|
|
|
scriptCount = scriptCount + 1
|
|
|
|
for n = 1 to numberOfLines
|
|
if n = numberOfLines then
|
|
xmlFile( n ) = newLine
|
|
xmlFile( n + 1 ) = "</accel:acceleratorlist>"
|
|
exit for
|
|
else
|
|
xmlFile( n ) = xmlFile( n )
|
|
end if
|
|
next n
|
|
|
|
numberOfLines = numberOfLines + 1
|
|
|
|
end sub
|
|
|
|
|
|
sub RemoveBinding( removeLinePosition as integer )
|
|
dim newXmlFile( 400 ) as string
|
|
dim lineRemoved as boolean
|
|
lineRemoved = false
|
|
|
|
for n = 1 to numberOfLines
|
|
if not lineRemoved then
|
|
if not( n = removeLinePosition ) then
|
|
newXmlFile( n ) = xmlFile( n )
|
|
else
|
|
newXmlFile( n ) = xmlFile( n + 1 )
|
|
lineRemoved = true
|
|
end if
|
|
else
|
|
newXmlFile( n ) = xmlFile( n + 1 )
|
|
end if
|
|
next n
|
|
|
|
numberOfLines = numberOfLines - 1
|
|
|
|
REM read the new file into the global array
|
|
for n = 1 to numberOfLines
|
|
xmlFile( n ) = newXmlFile( n )
|
|
next n
|
|
end sub
|
|
|
|
|
|
REM Adds or removes the starting xml line positions for each top-level menu after the menu with the added script
|
|
sub UpdateTopLevelMenus( topLevelMenuPosition as integer, addLine as boolean )
|
|
for n = topLevelMenuPosition to 8
|
|
if addLine then
|
|
menuItemLinePosition( n ) = menuItemLinePosition( n ) + 1
|
|
else
|
|
menuItemLinePosition( n ) = menuItemLinePosition( n ) - 1
|
|
end if
|
|
next n
|
|
end sub
|
|
|
|
|
|
REM Remove scriptNames and scriptLinePosition entries
|
|
sub RemoveScriptNameAndPosition( keyComboPosition )
|
|
dim updatedScriptNames( 120 ) as string
|
|
dim updatedScriptLinePosition( 120 ) as integer
|
|
dim removedScript as boolean
|
|
removedScript = false
|
|
|
|
for n = 1 to scriptCount
|
|
if not removedScript then
|
|
if not( n = keyComboPosition ) then
|
|
updatedScriptNames( n ) = scriptNames( n )
|
|
else
|
|
removedScript = true
|
|
end if
|
|
else
|
|
updatedScriptNames( n - 1 ) = scriptNames( n )
|
|
end if
|
|
next n
|
|
scriptCount = scriptCount - 1
|
|
|
|
for n = 1 to scriptCount
|
|
scriptNames( n ) = updatedScriptNames( n )
|
|
next n
|
|
end sub
|
|
|
|
|
|
|
|
REM ----- Populating Dialog Controls -----
|
|
|
|
|
|
sub PopulateScriptList()
|
|
scriptList = bindingDialog.getControl( "ScriptList" )
|
|
scriptList.removeItems( 0, scriptList.getItemCount() )
|
|
|
|
smgr = getProcessServiceManager()
|
|
context = smgr.getPropertyValue( "DefaultContext" )
|
|
scriptstoragemgr = context.getValueByName( "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager" )
|
|
|
|
storage = scriptstoragemgr.getScriptStorage( 1 )
|
|
logicalNames() = storage.getScriptLogicalNames()
|
|
|
|
for n = 1 to ubound( logicalNames() ) + 1
|
|
scriptList.addItem( logicalNames( n - 1 ), n )
|
|
next n
|
|
|
|
scriptList.selectItemPos( 0, true )
|
|
end sub
|
|
|
|
|
|
sub PopulateMenuCombo()
|
|
menuComboBox = bindingDialog.getControl( "MenuCombo" )
|
|
menuComboBox.removeItems( 0, menuComboBox.getItemCount() )
|
|
for n = 1 to menuCount
|
|
menuComboBox.addItem( menuItems( n ), n - 1 )
|
|
next n
|
|
menuComboBox.setDropDownLineCount( 8 )
|
|
menuComboBox.text = menuComboBox.getItem( 0 )
|
|
end sub
|
|
|
|
|
|
sub PopulateSubMenuList( menuItemPosition as integer )
|
|
redim subMenuItems( 100 ) as string
|
|
redim subMenuItemLinePosition( 100 ) as integer
|
|
dim lineNumber as integer
|
|
const menuItemWhiteSpace = 4
|
|
const menuXMLTag = "<menu:menu"
|
|
subMenuCount = 1
|
|
|
|
REM xmlStartLine and xmlEndLine refer to the first and last lines
|
|
' menuItemPosition of a top-level menu ( 1=File to 8=Help ) add one line
|
|
xmlStartLine = menuItemLinePosition( menuItemPosition ) + 1
|
|
|
|
REM If last menu item is chosen
|
|
if menuItemPosition = menuCount then
|
|
xmlEndLine = numberOfLines
|
|
else
|
|
REM Other wise get the line before the next top-level menu begins
|
|
xmlEndLine = menuItemLinePosition( menuItemPosition + 1 ) - 1
|
|
end if
|
|
|
|
for lineNumber = xmlStartLine to xmlEndLine
|
|
REM Insert all sub-menus and sub-popupmenus
|
|
if not( instr( xmlFile( lineNumber ), menuXMLTag ) = 0 ) and instr( xmlFile( lineNumber ), "menupopup") = 0 then
|
|
subMenuIndent = GetMenuWhiteSpace( xmlFile( lineNumber ) )
|
|
if subMenuIndent = " " then
|
|
subMenuIndent = ""
|
|
else
|
|
subMenuIndent = subMenuIndent + subMenuIndent
|
|
end if
|
|
if not( instr( xmlFile( lineNumber ), "menuseparator" ) = 0 ) then
|
|
subMenuItems( subMenuCount ) = subMenuIndent + "----------------"
|
|
else
|
|
subMenuName = ExtractLabelFromXMLLine( xmlFile( lineNumber ) )
|
|
REM Add script Name if there is one bound to menu item
|
|
if instr( xmlFile( lineNumber ), "script://" ) > 0 then
|
|
script = ExtractScriptIdFromXMLLine( xmlFile( lineNumber ) )
|
|
subMenuItems( subMenuCount ) = ( subMenuIndent + subMenuName + " [" + script + "]" )
|
|
else
|
|
subMenuItems( subMenuCount ) = subMenuIndent + subMenuName
|
|
end if
|
|
end if
|
|
subMenuItemLinePosition( subMenuCount ) = lineNumber
|
|
subMenuCount = subMenuCount + 1
|
|
end if
|
|
next lineNumber
|
|
|
|
subMenuList = bindingDialog.getControl( "SubMenuList" )
|
|
|
|
currentPosition = subMenuList.getSelectedItemPos()
|
|
|
|
subMenuList.removeItems( 0, subMenuList.getItemCount() )
|
|
for n = 1 to subMenuCount - 1
|
|
subMenuList.addItem( subMenuItems( n ), n - 1 )
|
|
next n
|
|
|
|
subMenuList.selectItemPos( currentPosition, true )
|
|
|
|
SubMenuListListener()
|
|
end sub
|
|
|
|
|
|
|
|
sub PopulateTopLevelKeyBindingList()
|
|
keyCombo = bindingDialog.getControl( "KeyCombo" )
|
|
keyCombo.removeItems( 0, keyCombo.getItemCount() )
|
|
keyCombo.addItem( "SHIFT + CONTROL + F keys", 0 )
|
|
keyCombo.addItem( "SHIFT + CONTROL + digits", 1 )
|
|
keyCombo.addItem( "SHIFT + CONTROL + letters", 2 )
|
|
keyCombo.addItem( "CONTROL + F keys", 3 )
|
|
keyCombo.addItem( "CONTROL + digits", 4 )
|
|
keyCombo.addItem( "CONTROL + letters", 5 )
|
|
keyCombo.addItem( "SHIFT + F keys", 6 )
|
|
|
|
keyCombo.setDropDownLineCount( 7 )
|
|
keyCombo.text = keyCombo.getItem( 0 )
|
|
end sub
|
|
|
|
|
|
sub PopulateKeyBindingList( startPosition as integer, endPosition as integer )
|
|
dim formattedKeyBinding( 47 ) as string
|
|
counter = 1
|
|
|
|
keyList = bindingDialog.getControl( "KeyList" )
|
|
|
|
for n = startPosition to endPosition
|
|
REM If key combo is a script the value returned is the line position
|
|
if IsAllocatedKeyCombo( allKeyBindings( n ) ) > 1 then
|
|
formattedKeyBinding( counter ) = ( allKeyBindings( n ) + " [Allocated to " + ExtractScriptIdFromXMLLine( xmlFile( isAllocatedKeyCombo( allKeyBindings( n ) ) ) ) + "]" )
|
|
REM If key combo is an Office function 1 is returned
|
|
else if IsAllocatedKeyCombo( allKeyBindings( n ) ) = 1 then
|
|
formattedKeyBinding( counter ) = ( allKeyBindings( n ) + " [Allocated to Office function]" )
|
|
REM If key combo is unallocated 0 is returned
|
|
else
|
|
formattedKeyBinding( counter ) = allKeyBindings( n )
|
|
end if
|
|
end if
|
|
counter = counter + 1
|
|
next n
|
|
|
|
currentPosition = keyList.getSelectedItemPos()
|
|
|
|
keyList.removeItems( 0, keyList.getItemCount() )
|
|
for n = 1 to counter - 1
|
|
keyList.addItem( formattedKeyBinding( n ), n - 1 )
|
|
next n
|
|
|
|
keyList.selectItemPos( currentPosition, true )
|
|
|
|
KeyListListener()
|
|
end sub
|
|
|
|
|
|
|
|
sub CreateAllKeyBindings()
|
|
reDim allKeyBindings( 105 ) as string
|
|
keyBindingPosition = 1
|
|
|
|
for FKey = 2 to 12
|
|
allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + F" + FKey
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next FKey
|
|
for Digit = 0 to 9
|
|
allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + " + Digit
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next Digit
|
|
for Alpha = 65 to 90
|
|
allKeyBindings( keyBindingPosition ) = "SHIFT + CONTROL + " + chr$( Alpha )
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next Alpha
|
|
|
|
for FKey = 2 to 12
|
|
allKeyBindings( keyBindingPosition ) = "CONTROL + F" + FKey
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next FKey
|
|
for Digit = 0 to 9
|
|
allKeyBindings( keyBindingPosition ) = "CONTROL + " + Digit
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next Digit
|
|
for Alpha = 65 to 90
|
|
allKeyBindings( keyBindingPosition ) = "CONTROL + " + chr$( Alpha )
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next Alpha
|
|
|
|
for FKey = 2 to 12
|
|
allKeyBindings( keyBindingPosition ) = "SHIFT + F" + FKey
|
|
keyBindingPosition = keyBindingPosition + 1
|
|
next FKey
|
|
end sub
|
|
|
|
|
|
|
|
REM ----- Text Handling Functions -----
|
|
|
|
|
|
function ExtractLabelFromXMLLine( XMLLine as string ) as string
|
|
labelStart = instr( XMLLine, "label="+chr$(34)) + 7
|
|
labelEnd = instr( XMLLine, chr$(34)+">" )
|
|
if labelEnd = 0 then
|
|
labelEnd = instr( XMLLine, chr$(34)+"/>" )
|
|
end if
|
|
labelLength = labelEnd - labelStart
|
|
|
|
menuLabelUnformatted = mid( XMLLine, labelStart, labelLength )
|
|
tildePosition = instr( menuLabelUnformatted, "~" )
|
|
select case tildePosition
|
|
case 0
|
|
menuLabel = menuLabelUnformatted
|
|
case 1
|
|
menuLabel = right( menuLabelUnformatted, labelLength - 1 )
|
|
case else
|
|
menuLabelLeft = left( menuLabelUnformatted, tildePosition - 1 )
|
|
menuLabelRight = right( menuLabelUnformatted, labelLength - tildePosition )
|
|
menuLabel = menuLabelLeft + menuLabelRight
|
|
end select
|
|
|
|
ExtractLabelFromXMLLine() = menuLabel
|
|
end function
|
|
|
|
|
|
function ExtractScriptIdFromXMLLine( XMLLine as string ) as string
|
|
idStart = instr( XMLLine, "script://") + 9
|
|
if instr( XMLLine, ""+chr$(34)+" menu:helpid=" ) = 0 then
|
|
idEnd = instr( XMLLIne, "?location=" )
|
|
else
|
|
idEnd = instr( XMLLine, ""+chr$(34)+" menu:helpid=" )
|
|
end if
|
|
idLength = idEnd - idStart
|
|
scriptId = mid( XMLLine, idStart, idLength )
|
|
|
|
ExtractScriptIdFromXMLLine() = scriptId
|
|
end function
|
|
|
|
|
|
function ExtractKeyCodeFromXMLLine( XMLLine as string ) as string
|
|
keyStart = instr( XMLLine, "code="+chr$(34)+"KEY_") + 10
|
|
keyCode = mid( XMLLine, keyStart, ( len( XMLLine ) - keyStart ) )
|
|
keyEnd = instr( keyCode, chr$(34) )
|
|
keyCode = mid( keyCode, 1, keyEnd - 1 )
|
|
|
|
ExtractKeyCodeFromXMLLine() = keyCode
|
|
end function
|
|
|
|
|
|
function GetMenuWhiteSpace( MenuXMLLine as string ) as string
|
|
whiteSpace = ""
|
|
numberOfSpaces = instr( MenuXMLLine, "<" ) - 1
|
|
for i = 1 to numberOfSpaces
|
|
whiteSpace = whiteSpace + " "
|
|
next i
|
|
|
|
GetMenuWhiteSpace() = whiteSpace
|
|
end function
|
|
|
|
|
|
function IsAllocatedKeyCombo( script as string ) as integer
|
|
const NotAllocated = 0
|
|
const AllocatedToOfficeFunction = 1
|
|
const AllocatedToScript = 2
|
|
dim Allocation as integer
|
|
|
|
if instr( script, " [Allocated" ) > 0 then
|
|
endPosition = instr( script, " [Allocated" ) - 1
|
|
script = mid( script, 1, endPosition )
|
|
end if
|
|
|
|
Allocation = NotAllocated
|
|
count = 1
|
|
while Allocation = NotAllocated and count < scriptCount
|
|
linePosition = scriptLinePosition( count )
|
|
if strcomp( script, scriptNames( count ) ) = 0 then
|
|
if instr( xmlFile( linePosition ), "script://" ) > 0 then
|
|
Allocation = linePosition
|
|
else
|
|
Allocation = AllocatedToOfficeFunction
|
|
end if
|
|
end if
|
|
count = count + 1
|
|
wend
|
|
msgbox( " IsAllocatedKeyCombo() script: " + script + " Allocation: " + Allocation )
|
|
IsAllocatedKeyCombo() = Allocation
|
|
end Function
|
|
|
|
|
|
function IsAllocatedMenuItem( script as string ) as boolean
|
|
foundMenuItem = false
|
|
Allocated = false
|
|
count = 0
|
|
do
|
|
count = count + 1
|
|
if strcomp( script, subMenuItems( count ) ) = 0 then
|
|
foundMenuItem = true
|
|
end if
|
|
loop while not( foundMenuItem ) and count < subMenuCount
|
|
|
|
linePosition = subMenuItemLinePosition( count )
|
|
|
|
if not( instr( xmlFile( linePosition ), "script://" ) = 0 ) then
|
|
Allocated = true
|
|
end if
|
|
|
|
isAllocatedMenuItem() = Allocated
|
|
end Function
|
|
|
|
|
|
function HasShiftKey( keyCombo ) as boolean
|
|
if instr( keyCombo, "SHIFT" ) = 0 then
|
|
hasShift = false
|
|
else
|
|
hasShift = true
|
|
end if
|
|
|
|
HasShiftKey = hasShift
|
|
end function
|
|
|
|
|
|
function HasControlKey( keyCombo ) as boolean
|
|
if instr( keyCombo, "CONTROL" ) = 0 then
|
|
hasControl = false
|
|
else
|
|
hasControl = true
|
|
end if
|
|
|
|
HasControlKey = hasControl
|
|
end function
|
|
|
|
|
|
function ExtractKeyFromCombo( keyString as string ) as string
|
|
while not( instr( keyString, "+" ) = 0 )
|
|
removeTo = instr( keyString, "+ " ) + 2
|
|
keyString = mid( keyString, removeTo, ( len( keyString ) - removeTo ) + 1 )
|
|
wend
|
|
|
|
ExtractKeyFromCombo() = keyString
|
|
end function
|
|
|
|
|
|
|
|
REM ------ Event Handling Functions (Listeners) ------
|
|
|
|
|
|
sub KeyListListener()
|
|
keyList = bindingDialog.getControl( "KeyList" )
|
|
selectedKeyCombo = keyList.getSelectedItem()
|
|
|
|
if isAllocatedKeyCombo( selectedKeyCombo ) > 1 then
|
|
bindingDialog.Model.Delete.enabled = true
|
|
bindingDialog.Model.NewButton.enabled = false
|
|
else
|
|
if isAllocatedKeyCombo( selectedKeyCombo ) = 1 then
|
|
bindingDialog.Model.Delete.enabled = false
|
|
bindingDialog.Model.NewButton.enabled = false
|
|
else
|
|
bindingDialog.Model.Delete.enabled = false
|
|
bindingDialog.Model.NewButton.enabled = true
|
|
end if
|
|
end if
|
|
end sub
|
|
|
|
|
|
sub SubMenuListListener()
|
|
subMenuList = bindingDialog.getControl( "SubMenuList" )
|
|
selectedMenuItem = subMenuList.getSelectedItem()
|
|
if IsAllocatedMenuItem( selectedMenuItem ) then
|
|
bindingDialog.Model.Delete.enabled = true
|
|
else
|
|
bindingDialog.Model.Delete.enabled = false
|
|
end if
|
|
end sub
|
|
|
|
|
|
'Populates the SubMenuList with the appropriate menu items from the Top-level menu selected from the combo box
|
|
sub MenuComboListener()
|
|
combo = bindingDialog.getControl( "MenuCombo" )
|
|
newToplevelMenu = combo.text
|
|
counter = 0
|
|
do
|
|
counter = counter + 1
|
|
loop while not( newToplevelMenu = menuItems( counter ) )
|
|
|
|
PopulateSubMenuList( counter )
|
|
end sub
|
|
|
|
|
|
'Populates the KeyList with the appropriate key combos from the Top-level key group selected from the combo box
|
|
sub KeyComboListener()
|
|
combo = bindingDialog.getControl( "KeyCombo" )
|
|
itemSelected = combo.text
|
|
|
|
select case itemSelected
|
|
case "SHIFT + CONTROL + F keys"
|
|
PopulateKeyBindingList( 1, 11 )
|
|
case "SHIFT + CONTROL + digits"
|
|
PopulateKeyBindingList( 12, 21 )
|
|
case "SHIFT + CONTROL + letters"
|
|
PopulateKeyBindingList( 22, 47 )
|
|
case "CONTROL + F keys"
|
|
PopulateKeyBindingList( 48, 58 )
|
|
case "CONTROL + digits"
|
|
PopulateKeyBindingList( 59, 68 )
|
|
case "CONTROL + letters"
|
|
PopulateKeyBindingList( 69, 94 )
|
|
case "SHIFT + F keys"
|
|
PopulateKeyBindingList( 95, 105 )
|
|
case else
|
|
msgbox "Error"
|
|
end select
|
|
end sub
|
|
|
|
|
|
sub MenuLabelBoxListener()
|
|
if bindingDialog.Model.MenuLabelBox.text = "" then
|
|
bindingDialog.Model.NewButton.enabled = false
|
|
else
|
|
bindingDialog.Model.NewButton.enabled = true
|
|
end if
|
|
end sub
|
|
|
|
|
|
|
|
REM ------ Event Handling Functions (Buttons) ------
|
|
|
|
|
|
sub MenuOKButton()
|
|
msgbox ("Office must be restarted before your changes will take effect."+ chr$(10)+"Also close the Office QuickStarter (Windows and some Linux)", 48, "Assign Script (Java) To Menu" )
|
|
WriteXMLFromArray()
|
|
bindingDialog.endExecute()
|
|
end sub
|
|
|
|
|
|
sub MenuCancelButton()
|
|
bindingDialog.endExecute()
|
|
end sub
|
|
|
|
|
|
sub MenuHelpButton()
|
|
helpDialog = LoadDialog( "ScriptBindingLibrary", "HelpBinding" )
|
|
helpDialog.execute()
|
|
end sub
|
|
|
|
|
|
sub MenuDeleteButton()
|
|
subMenuList = bindingDialog.getControl( "SubMenuList" )
|
|
linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 )
|
|
|
|
RemoveBinding( linePos )
|
|
|
|
REM Update the top-level menu's line positions
|
|
combo = bindingDialog.getControl( "MenuCombo" )
|
|
newToplevelMenu = combo.text
|
|
counter = 0
|
|
do
|
|
counter = counter + 1
|
|
loop while not( newToplevelMenu = menuItems( counter ) )
|
|
UpdateTopLevelMenus( counter + 1, false )
|
|
|
|
MenuComboListener()
|
|
end sub
|
|
|
|
|
|
sub MenuNewButton()
|
|
menuScriptList = bindingDialog.getControl( "ScriptList" )
|
|
script = menuScriptList.getSelectedItem()
|
|
|
|
newMenuLabel = bindingDialog.Model.MenuLabelBox.text
|
|
|
|
subMenuList = bindingDialog.getControl( "SubMenuList" )
|
|
|
|
REM Update the top-level menu's line positions
|
|
combo = bindingDialog.getControl( "MenuCombo" )
|
|
newToplevelMenu = combo.text
|
|
counter = 0
|
|
do
|
|
counter = counter + 1
|
|
loop while not( newToplevelMenu = menuItems( counter ) )
|
|
UpdateTopLevelMenus( counter + 1, true )
|
|
|
|
REM New line position is one ahead of the selected sub menu item
|
|
linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 ) + 1
|
|
|
|
AddNewMenuBinding( script, newMenuLabel, linePos )
|
|
|
|
MenuComboListener()
|
|
end sub
|
|
|
|
|
|
sub KeyOKButton()
|
|
msgbox ("Office must be restarted before your changes will take effect."+ chr$(10)+"Also close the Office QuickStarter (Windows and some Linux)", 48, "Assign Script (Java) To Key" )
|
|
WriteXMLFromArray()
|
|
bindingDialog.endExecute()
|
|
end sub
|
|
|
|
|
|
sub KeyCancelButton()
|
|
bindingDialog.endExecute()
|
|
end sub
|
|
|
|
|
|
sub KeyHelpButton()
|
|
helpDialog = LoadDialog( "ScriptBindingLibrary", "HelpBinding" )
|
|
helpDialog.execute()
|
|
end sub
|
|
|
|
|
|
sub KeyNewButton()
|
|
menuScriptList = bindingDialog.getControl( "ScriptList" )
|
|
script = menuScriptList.getSelectedItem()
|
|
|
|
keyList = bindingDialog.getControl( "KeyList" )
|
|
keyCombo = keyList.getSelectedItem()
|
|
|
|
AddNewKeyBinding( script, HasShiftKey( keyCombo ), HasControlKey( keyCombo ), ExtractKeyFromCombo( keyCombo ) )
|
|
|
|
KeyComboListener()
|
|
end sub
|
|
|
|
|
|
sub KeyDeleteButton()
|
|
keyList = bindingDialog.getControl( "KeyList" )
|
|
REM Check that combo is a script
|
|
keyCombo = keyList.getSelectedItem()
|
|
|
|
if instr( keyCombo, " [Allocated" ) > 0 then
|
|
endPosition = instr( keyCombo, " [Allocated" ) - 1
|
|
keyCombo = mid( keyCombo, 1, endPosition )
|
|
end if
|
|
|
|
for n = 1 to scriptCount
|
|
if strcomp( keyCombo, scriptNames( n ) ) = 0 then
|
|
keyComboPosition = n
|
|
exit for
|
|
end if
|
|
next n
|
|
|
|
linePosition = scriptLinePosition( keyComboPosition )
|
|
|
|
REM remove scriptNames and scriptLinePosition entries
|
|
RemoveScriptNameAndPosition( keyComboPosition )
|
|
|
|
RemoveBinding( linePosition )
|
|
|
|
script = ExtractScriptIdFromXMLLine( xmlFile( linePosition ) )
|
|
KeyComboListener()
|
|
end sub
|
|
|
|
|
|
sub HelpOKButton()
|
|
helpDialog.endExecute()
|
|
end sub</script:module> |