OK,
I used the newest helper extension
and instaled also the testSideBar.oxt
i endup with a private Deck "MytoolsDeck" who contains 2 panels
"MyPanel1" and "MyPanel2" who are not visible and no content is seen.
When running some API test code (LO 5.1 (Windows)) it crashes when y Xray a panel
Code: Select all
Sub testSidebarApi
controller = thisComponent.currentcontroller
frameIni = thisComponent.currentcontroller.frame
sidebar = thisComponent.currentcontroller.getSidebar()
sidebar.setVisible(true)
frame = sidebar.getFrame()
decks = sidebar.getdecks()
c = decks.count
h = decks.hasElements()
e = decks.getElementNames()
xray e
'a = decks.hasByName("mydeck1")
deck = decks.getByName("MytoolsDeck")
deck.activate(true)
t = deck.getTitle()
'deck.setTitle("new deck title")
' deck.moveFirst()
'deck.moveLast()
' deck.moveUp()
'deck.moveDown()
' index = deck.getOrderIndex()
panels = deck.getPanels()
ep = panels.getElementnames()
xray ep
'ap = panels.hasByName("mypanel1")
panel = panels.getByName("MyPanel1")
xray panel
'panel.setTitle("new panel title")
'panel.collapse()
'panel.expand(true) ' expand and collapse other
' index = panel.getOrderIndex()
' panel.moveLast()
' panel.moveFirst()
' panel.moveDown()
' panel.moveUp()
End Sub
when is use the instructions contained in the "readme" file
and run the basic macro "AddMyDeckWithPanel"
i have the same results: also a empty panel who do crashes LO
it seems that the "Initialize" function is never called ?
Code: Select all
Sub AddMyDeckWithPanel
bAdd = true ' set False to remove the existing settings
' deck settings
sDeckName = "MyNewDeck"
sDeckTitle = "New Deck"
sDeckId = "mydeck1"
sIconURL = "file:///home/asuka/misc/SidebarByMacros/icon2.png" ' 24x24
sHCIconURL = sIconURL
aDeckContextList = Array("Writer, any, visible")
nDeckOrderIndex = 600
' panel settings
sPanelName = "MyPanel"
sPanelTitle = "My Panel"
sPanelId = "mypanel1"
aPanelContextList = Array("Writer, any, visible")
bTitleBarIsOptional = True
nPanelOrderIndex = 600
' resource URL for the panel
sPath = "MyPanel3"
sResourceURL = "private:resource/toolpanel/foo.bar/" & sPath
' macro settings
sMacroFor_Initialize = "Standard.Module1.Initialize"
sMacroLocation = "user"
sMacroLanguage = "Basic"
sMacroQuery = "?location=" & sMacroLocation & "&language=" & sMacroLanguage
if bAdd then
AddDeck(sDeckName, sDeckTitle, sDeckId, _
sIconURL, sHCIconURL, aDeckContextList, nDeckOrderIndex)
AddPanel(sPanelName, sPanelTitle, bTitleBarIsOptional, sPanelId, _
sDeckId, aPanelContextList, sResourceURL, nPanelOrderIndex)
AddSidebarItemForMacro(sResourceURL, _
"vnd.sun.star.script:" & sMacroFor_Initialize & sMacroQuery)
else
RemoveDeck(sDeckName)
RemovePanel(sPanelName)
RemoveSidebarItemForMacro(sResourceURL)
end if
End Sub
' This file contains the macros to add or remove settings of sidebar components.
' See docs.odt for more detail.
Const CONFIG_DECK = "/org.openoffice.Office.UI.Sidebar/Content/DeckList"
Const CONFIG_PANEL = "/org.openoffice.Office.UI.Sidebar/Content/PanelList"
Const CONFIG_CUSTOM = "/mytools.UI.SidebarsByMacros/Content/Imples"
Sub AddSidebarItemForMacro(sResourceURI as string, sURI1 as string)
config = GetConfigurationByName(CONFIG_CUSTOM)
if not config.hasByName(sResourceURI) then
item = config.createInstance()
config.insertByName(sResourceURI, item)
else
item = config.getByName(sResourceURI)
end if
item.Initialize = sURI1
config.commitChanges()
End Sub
Sub RemoveSidebarItemForMacro(sResourceURI as string)
RemoveItemFromConfiguration(CONFIG_CUSTOM, sResourceURI)
End Sub
Sub AddDeck( _
sName As String, sTitle As String, sId As String, _
sIconURL As String, sHighContrastIconURL As String, _
aContextList as Variant, nOrderIndex as integer )
print config_deck
config = GetConfigurationByName(CONFIG_DECK)
if not config.hasByName(sName) then
item = config.createInstance()
config.insertByName(sName, item)
else
item = config.getByName(sName)
end if
item.Title = sTitle
item.Id = sId
item.IconURL = sIconURL
item.HighContrastIconURL = sHighContrastIconURL
item.ContextList = aContextList
item.OrderIndex = nOrderIndex
config.commitChanges()
End Sub
Sub RemoveDeck( sName as string )
RemoveItemFromConfiguration(CONFIG_DECK, sName)
End Sub
Sub AddPanel(_
sName As String, sTitle as String, bTitleBarIsOptional as boolean, _
sId as string, sDeckId as string, aContextList as Variant, _
sImplementationURL as string, nOrderIndex as integer )
print CONFIG_PANEL
config = GetConfigurationByName(CONFIG_PANEL)
if not config.hasByName(sName) then
item = config.createInstance()
config.insertByName(sName, item)
else
item = config.getByName(sName)
end if
item.Title = sTitle
item.TitleBarIsOptional = bTitleBarIsOptional
item.Id = sId
item.DeckId = sDeckId
item.ContextList = aContextList
item.ImplementationURL = sImplementationURL
item.OrderIndex = nOrderIndex
config.commitChanges()
End Sub
Sub RemovePanel( sName as string )
RemoveItemFromConfiguration(CONFIG_PANEL, sName)
End Sub
Function GetConfigurationByName(sNodePath as string)
Dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "nodepath"
args(0).Value = sNodePath
GetConfigurationByName = CreateUnoService("com.sun.star.configuration.ConfigurationProvider")._
createInstanceWithArguments(_
"com.sun.star.configuration.ConfigurationUpdateAccess", args)
End Function
Function RemoveItemFromConfiguration(sNodePath as string, sName as string) As Boolean
bState = False
config = GetConfigurationByName(sNodePath)
if config.hasByName(sName) then
config.removeByName(sName)
config.commitChanges()
bState = True
end if
RemoveItemFromConfiguration = bState
End Function
' Initialize with UIElement and parent window.
' @param oElement instance that implements css.ui.XUIElement,
' XToolPanel and XSidebarPanel.
' Additionally css.container.XNameContainer that
' allows you to set XSidebarPanel.
' @param oParent parent window
' @return panel window
Function Initialize( oElement as Variant, oParent as Variant ) As Variant
print "init"
window = CreateChildWindow("$(user)/basic/Standard/Dialog3.xdl", oParent, True)
window.setPosSize(0, 0, 0, 0, com.sun.star.awt.PosSize.POS)
Initialize = window ' return value
' If you do not need to set complicated resizing, simply you do not need this.
oElement.insertByName("XSidebarPanel", _
CreateUnoListener("XSidebarPanel_", "com.sun.star.ui.XSidebarPanel"))
End Function
Function XSidebarPanel_getHeightForWidth( nWidth as Variant )
ls = CreateUnoStruct("com.sun.star.ui.LayoutSize")
ls.Minimum = 150
ls.Maximum = 150
ls.Preferred = 150
XSidebarPanel_getHeightForWidth = ls
End Function
Function CreateChildWindow( sDialogURL as string, oParent as Variant, Optional bMakeVisible as boolean )
sDialogURI = CreateUnoService("com.sun.star.util.PathSubstitution").substituteVariables(sDialogURL, True)
dp = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
window = dp.createContainerWindow( sDialogURI, "", oParent, Null )
if not IsNull(window) and Not IsMissing(bMakeVisible) and bMakeVisible then window.setVisible(True)
CreateChildWindow = window
End Function