/// <summary>
 /// Stores the settings.
 /// </summary>
 protected void StoreSettings()
 {
     if (XCfgMgr == null)
     {
         return;
     }
     if (XCfgMgr.hasSettings(RecourceUrl))
     {
         XCfgMgr.replaceSettings(RecourceUrl, Settings);
     }
     else
     {
         XCfgMgr.insertSettings(RecourceUrl, Settings);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToolBar"/> class.
        /// </summary>
        /// <param name="xMsf">the XMultiComponentFactory.</param>
        /// <param name="name">The UIName Parameter of the ToolBar.</param>
        /// <param name="documentModluleIdentifier">The document modlule identifier for the ToolBar.
        /// E.g. "com.sun.star.text.TextDocument" to add the ToolBar to all text documents</param>
        public ToolBar(string name, string documentModluleIdentifier, XMultiComponentFactory xMsf = null)
        {
            if (name.Trim().Length < 1)
            {
                throw new NullReferenceException("Name for ToolBar creation is empty");
            }

            XMcf        = xMsf ?? OO.GetMultiComponentFactory();
            Name        = name;
            RecourceUrl = GetToolBarUrl(name);

            // Retrieve the module configuration manager supplier to  get
            // the configuration setting from the module
            _xModCfgMgrSupplier =
                (XModuleUIConfigurationManagerSupplier)
                XMcf.createInstanceWithContext(OO.Services.UI_MOD_UI_CONF_MGR_SUPPLIER, OO.GetContext());

            // Retrieve the module configuration manager
            XCfgMgr =
                _xModCfgMgrSupplier.getUIConfigurationManager(documentModluleIdentifier);

            if (XCfgMgr.hasSettings(RecourceUrl) == false)
            {
                // Creates a copy of the user interface configuration manager
                Settings = XCfgMgr.createSettings();

                // Defines the name of the toolbar
                var xToolbarProperties = (XPropertySet)Settings;
                xToolbarProperties.setPropertyValue("UIName", Any.Get(name));

                // Makes the toolbar to the UI manager available
                try
                {
                    XCfgMgr.insertSettings(RecourceUrl, Settings);
                }
                catch (ElementExistException)
                {
                    Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
                }
            }
            else
            {
                Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
            }
        }