Hi Joan,
> That's it... Does anyone know how to disable the "File / New" Menu?
a bit more infos won't be too bad. You want to use java? If so, see code
below (just pass the command URL in the first line):
-----%<-----
public void changeMenusTransient(String myCommandURL) {
// Init menu elements
// 1. Getting the menubar
com.sun.star.ui.XUIElement myMenubar = getLayoutManager()
.getElement("private:resource/menubar/menubar");
// 2. Getting the menubar settings
XUIElementSettings myMenuBarSettings = (XUIElementSettings)
UnoRuntime.queryInterface(XUIElementSettings.class, myMenubar);
// 3. Casting the settings into a container to be able to get the
// properties
XIndexContainer myMenuBarContainer = (XIndexContainer)
UnoRuntime.queryInterface(XIndexContainer.class,
myMenuBarSettings.getSettings(true));
try {
// Creating a Vector containing all menus with a "Save" item
Vector foundMenuItems = this.searchXIndexContainerForItem(
myCommandURL,
myMenuBarContainer,
new Vector());
// Remove the menu items
this.removeXIndexContainerItems(foundMenuItems);
// Make changes only transient (temporary).
com.sun.star.beans.XPropertySet xPropSet = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,
myMenubar);
xPropSet.setPropertyValue("Persistent", new Boolean(false));
// Apply settings to the root container (includes all
// subcontainers)
myMenuBarSettings.setSettings(myMenuBarContainer);
}
catch (Exception e) {}
}
-----%<-----
public XLayoutManager getLayoutManager()
{
// Getting the frame the loaded document resides in
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class,
this.xComponent);
XController xController = xModel.getCurrentController();
// Getting the properties of the frame
XPropertySet xps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,
xController.getFrame());
XLayoutManager xLayoutManager = null;
try
{
xLayoutManager = (XLayoutManager)
UnoRuntime.queryInterface(XLayoutManager.class,
xps.getPropertyValue("LayoutManager"));
}
catch (com.sun.star.uno.Exception e)
{
if (debug > 0)
System.out.println("Cannot get Layout Manager.");
if (debug > 1)
System.out.println(e);
}
return xLayoutManager;
}
-----%<-----
private void removeXIndexContainerItems(Vector itemsToRemove) throws
IndexOutOfBoundsException,
WrappedTargetException
{
// Starting with the last Element, because removing changes item
// index
for (int i = itemsToRemove.size() -1; i >= 0; i--)
{
Vector thisVectorItem = (Vector)itemsToRemove.elementAt(i);
XIndexContainer thisMenuContainer = (XIndexContainer)
thisVectorItem.elementAt(0);
Integer menuPosition = (Integer)thisVectorItem.elementAt(1);
// remove the item, but settings must be set to make it
//visible
thisMenuContainer.removeByIndex(menuPosition.intValue());
}
}
-----%<-----
private Vector searchXIndexContainerForItem(String myCommandURL,
XIndexContainer myMenuContainer, Vector foundMenuItems)
throws IllegalArgumentException,
IndexOutOfBoundsException,
WrappedTargetException {
if(myMenuContainer != null) {
for(int g = 0; g < myMenuContainer.getCount(); g++) {
// Getting the properties of the given container
PropertyValue[] gMenuItem = (PropertyValue[])
com.sun.star.uno.AnyConverter.toObject(
PropertyValue[].class,
myMenuContainer.getByIndex(g));
for(int h = 0; h < gMenuItem.length; h++)
{
if(gMenuItem[h].Name.equals("CommandURL"))
{
if(gMenuItem[h].Value.equals(myCommandURL))
{
Vector thisMenuItem = new Vector();
thisMenuItem.addElement(myMenuContainer);
thisMenuItem.addElement(new Integer(g));
foundMenuItems.addElement(thisMenuItem);
break;
}
}
else if(gMenuItem[h].Name.equals(
"ItemDescriptorContainer"))
{
XIndexAccess subMenuAccess = (XIndexAccess)
com.sun.star.uno.AnyConverter.toObject(
XIndexAccess.class,
gMenuItem[h].Value);
XIndexContainer subMenuContainer =
(XIndexContainer)
UnoRuntime.queryInterface(
XIndexContainer.class, subMenuAccess);
if(subMenuAccess != null)
{
searchXIndexContainerForItem(myCommandURL,
subMenuContainer,
foundMenuItems);
}
}
}
}
}
return foundMenuItems;
}
-----%<-----
Greetings, Tobias
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]