Ariel Constenla-Haile wrote:
Hello Alexander,

On Monday 12 October 2009, 01:50, Alexander Anisimov wrote:
Hello Ariel,

I have one more question. I think it last question.

Now I know how to operate with toolbar items. But I need to know how to
 hide or show some toolbar and then save it in document storage.

do you want to save the visibility state inside the document?
AFAIK this isn't possible.

I'm just an API client, so the following is just "guessing" (Carsten Diesner usually reads this mailing list, sure the mail subject catches his attention; he could give you a better advice, as he developed the code).

* as far as I could see, the window state configuration is stored globally; even if the doc has its own UI elements, as long as they are persistent, their window state is stored globally, per module
Hi Ariel and Alexander,

The visibility state cannot be stored in the document. This was a design decision by the UX team several years ago. The visibility state should always follow the user settings. That means if the user sets a toolbar to invisible it's a violation of user experience to make it visible again.


Sub Hide_Standard_Toolbar()

  Dim oDoc As Object
  Dim oFrame
  Dim element
  Dim layoutmanager

  oDoc = ThisComponent

  Dim oUIConfigurationManager as Object
  oUIConfigurationManager = oDoc.getUIConfigurationManager()

  oFrame = oDoc.getCurrentController().getFrame()
  layoutmanager = oFrame.LayoutManager

  element =
layoutmanager.getElement("private:resource/toolbar/standardbar")
  element.ConfigurationSource = oUIConfigurationManager
This might work but normally it's not something you want to do. You change the configuration source of an active user interface element. The layout manager can destroy and create the elements whenever the user interface context changes. So your solution would only work temporary. Please use the way Ariel describes below.

* does this switch the storage? I mean, if the toolbar wasn't stored in the document, changing the configuration source copies the module toolbar into the document storage? I didn't try if this works.

  element.Persistent = true

* you should do the opposite: setting this to true stores the window state at the module level cf. http://svn.services.openoffice.org/opengrok/xref/DEV300_m61/framework/source/layoutmanager/layoutmanager.cxx#1545
spec. 1573

I'd try the following:

* do not access the toolbar by the LayoutManager and then change the ConfigurationSource. Use the way you already learn by getting it from the configuration manager (first try to see if the document already has a customized version in its storage; if not, get it from the module ui config. manager, and copy it in the document ui config. manager). You can make a helper method getToolbar(sResourceURL) for this. This way you make sure that you're always working with the toolbar at document level, not module.
Ariel is right that this is the way to go. Please always uses the ui configuration manager whenever you want to make persistent changes to the content of a user interface element. Non-persistent changes can be done by using the layout manager to retrieve the ui element.


* now fool the LayoutManager to set it not visible without storing the window state information:

        Dim oLayoutManager as Object
oLayoutManager = oDoc.getCurrentController().getFrame().getPropertyValue("LayoutManager")
        Dim oUIElement as Object
        oUIElement = oLayoutManager.getElement(OOO_WRITER_STANDARD_TOOLBAR)
        'Fool the LayoutManager
        oUIElement.Persistent = False
        oLayoutManager.hideElement(OOO_WRITER_STANDARD_TOOLBAR)
        'Set it Persistent again
        oUIElement.Persistent = True

I've updated the doc with a new sub http://arielch.fedorapeople.org/docs/com.sun.star.ui.XUIConfigirationManager.odt

I didn't test much, but that trick seems to work.
This is definitely a trick and I cannot promise that it will work in the future. "Persistent" is a property which influences the persistence of the content of a ui element. It's not designed to influence other attributes (like visibility), although the current implementation respects it.

Regards,
Carsten

--
Carsten Driesner (cd) - Project Lead OpenOffice.org Framework
Framework wiki: http://wiki.services.openoffice.org/wiki/Framework
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to