I am using c# to develop an addon but the problem comes when I use insertByIndex(int,uno.Any) on XnamContainer it is giving me error "[map_to_uno():any] could not convert type!"
I am using this code
Code: Select all
private String menuBarURL = "private:resource/menubar/menubar";
private String topLevelMenuCmd = ".uno:dct_test";
private String topLevelMenuLabel = "Sun Developer Connection";
private String itemCmd = "macro:///Standard.Module1.myMacro()";
private String itemLabel = "myMacro";
public static string res = "1";
public static XComponent xcomponent;
XComponentLoader componentLoader;
XMultiServiceFactory multiServiceFactory;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap();
multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
get_menu(localContext);
componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
XDesktop desktop = (XDesktop)componentLoader;
xcomponent = desktop.getCurrentComponent();
XFrame xf = desktop.getCurrentFrame();
}
public void get_menu(XComponentContext xContext)
{
XModuleManager modulemanager = (XModuleManager)multiServiceFactory.createInstance("com.sun.star.frame.ModuleManager");
unoidl.com.sun.star.ui.XModuleUIConfigurationManagerSupplier xmucm = (unoidl.com.sun.star.ui.XModuleUIConfigurationManagerSupplier)multiServiceFactory.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
unoidl.com.sun.star.ui.XUIConfigurationManager xui_conf_manager = xmucm.getUIConfigurationManager("com.sun.star.text.TextDocument");
unoidl.com.sun.star.container.XIndexAccess _xindexaccess = xui_conf_manager.getSettings("private:resource/menubar/menubar", true);
XSingleComponentFactory xCfgMgrFactory = (XSingleComponentFactory)_xindexaccess;
PropertyValue[] topLevelMenuProperty = SetTopLevelMenuProperties(topLevelMenuCmd, topLevelMenuLabel, xCfgMgrFactory, xContext);
PropertyValue[] menuItemProperty = SetItemProperty(itemCmd, itemLabel);
uno.Any a=new uno.Any(topLevelMenuProperty.getType());
XIndexContainer _xindexcontainer = (XIndexContainer)xCfgMgrFactory;
_xindexcontainer.insertByIndex(0,a );
xui_conf_manager.replaceSettings(menuBarURL, _xindexaccess);
}
protected PropertyValue[] SetTopLevelMenuProperties(String CommandId, String _label, XSingleComponentFactory xCfgMgrFactory, XComponentContext xContext)
{
PropertyValue[] MenuProperty = new PropertyValue[4];
uno.Any a = new uno.Any(CommandId);
try
{
MenuProperty[0] = new PropertyValue();
MenuProperty[0].Name = "CommandURL";
MenuProperty[0].Value = a;
MenuProperty[1] = new PropertyValue();
MenuProperty[1].Name = "Label";
a = new uno.Any(_label);
MenuProperty[1].Value = a;
MenuProperty[2] = new PropertyValue();
MenuProperty[2].Name = "Type";
a = new uno.Any(0);
MenuProperty[2].Value = a;
MenuProperty[3] = new PropertyValue();
MenuProperty[3].Name = "ItemDescriptorContainer";
a = new uno.Any(xCfgMgrFactory.createInstanceWithContext(xContext).GetType());
MenuProperty[3].Value = a;
}
catch (unoidl.com.sun.star.uno.Exception ex)
{ }
return MenuProperty;
}
protected PropertyValue[] SetItemProperty(String CommandId, String _label)
{
PropertyValue[] itemProperty = new PropertyValue[3];
uno.Any a = new uno.Any(CommandId);
itemProperty[0] = new PropertyValue();
itemProperty[0].Name = "CommandURL";
itemProperty[0].Value = a;
itemProperty[1] = new PropertyValue();
itemProperty[1].Name = "Label";
a = new uno.Any(_label);
itemProperty[1].Value = a;
itemProperty[2] = new PropertyValue();
itemProperty[2].Name = "Type";
a = new uno.Any(0);
itemProperty[2].Value = a;
return itemProperty;
}
}