menu items in UIExtensionSites How do you modify

Topics: CAB & Smart Client Software Factory
Jul 21, 2006 at 6:23 AM
originally posted by: creimers

The default ShellLayoutView creates a MenuStrip with a &File menu item. Under that item is the E&xit item. I have created a Business Modual in which I'd like to extend the File menu. Basically, I need to be able to access the root item (&File) in order to add sub items. I have tried several different approaches with no luck. I tried to Access the root file item by:

inside the ModuleController - My bussiness modual
private void ExtendMenu ( )

MenuStrip = WorkItem.Workspaces.UIExtensionSitesUIExtensionSiteNames.MainMenu
AddMenuItem( MenuStrip, Properties.Resources.OpenMenu, CommandNames.Open, 0 );

...

private void AddMenuItem ( ToolStripMenuItem parent, string text, string command, Keys shortcutKeys )

This approach always give me an error the you can't convert a UIExtnsionSite to a menustrip. I've tried to cast with no luck. My question is; How do I access objects contianed within the UIExtensionSite?

In my implementation I find it nice to inherit from the base Layout at least for menus.

thanks
chad
Jul 21, 2006 at 6:59 AM
originally posted by: ForumUserRCC

Create a reference in Shell.cs (like the reference that is created for MainMenu) for the File menu item.

internal ToolStripMenuItem FileMenuItem
{
get { return _menuFile; }
}


Then, Register it as a UIExtensionSite in the ShellApplication.cs file - similar to the UIExtensionSite created for MainMenu.

RootWorkItem.UIExtensionSites.RegisterSite(UIExtensionSiteNames.FileMenu, this.Shell.FileMenuItem);


Now in your module, in its ExtendMenu method, add your code to add your menu items.
ex.
ToolStripMenuItem newMenuItem = new ToolStripMenuItem();
newMenuItem.Name = "menuNewItem";
newMenuItem.Text = "My New Item";
WorkItem.RootWorkItem.UIExtensionSitesUIExtensionSiteNames.FileMenu.Add(newMenuItem);

In my sample above, I also assumed you would add a value for the extension site in the UIExtensionSiteNames class.

That should get you started -
Jul 21, 2006 at 8:52 AM
originally posted by: creimers

Thanks for the quik response.

I guess I'm a bit confused.

Infrastructure.Layout project
Within the ShellLayoutView.cs the MainMenuStrip is created. The ShellLayoutView.Designer.cs creates the File menu item and the Exit Item. The object is regestered in the ShellLayoutViewPresenter::OnViewset via the code like you provided. I created a business modual which uses the shellLayout. I have two views created within the business modual which live within the shellLayout ( LeftWorkspace and RightWorkspace) What I'm trying to do is modify the fileitem that was created inside the ShellLayoutView. I could add a reference to the Infrastructure.Library in the ModuleController then access the internal MenuStrip MainMenuStrip property but I'd have to change the code from internal to public. I don't like that approach.

Is there a way to modify menus that have been previously created in the Infrastrcture.Layout::ShellLayoutView.cs with in a BussinessModual::ModuleControler?

I can Add items easily. I need to be able to extend menu items created in the base layout.

I was hoping there was a method to Get() the MenuStrip or a MenuItem that has been created previosly?

thanks
Jul 22, 2006 at 1:17 PM
originally posted by: sandpa

I had the same issue. I have one module that extends a menu on the MainMenuStrip from the shell. But during normal operation it also needs to enable/disable individual menu items depending on what views are being displayed etc.
The way I did it was to add the toolstripmenuitem to the Items collection for the current WorkItem ( if you were creating the item in the shell it would be the RootWorkItem )
Then in the module ( from the Module Controller or any presenter ) you can access the rootWorkItem's Item collection and retrieve a reference to the toolstripmenuitem and modify it the way you want. For this you would need to create an id for each toolstripmenuitem you are adding to the WorkItem.Item collection so that you can retrieve it later. you can declare the Ids in a new class as constants and put the class in a place where it can be seen by the code that is adding the toolstripmenuitems.

I know this works but it does expose the menu items to subsequent modules due to the WorkItem heirarchy. If there is an easier and more elegant way to do this then I would be happy to follow it. The first time I heard about SCSF was only 4 days ago so i might have overlooked an easier way of doing this.