CommandHandler

Topics: CAB & Smart Client Software Factory
Oct 17, 2006 at 9:54 PM
originally posted by: cpearson

Hi

I have a some menu items created in the Shell application. I have called the AddInvoker for each of the menu items. Using the visualization tool, the RootWorkItem.Commands appears to be correct.

In my Module, I have a WorkItem which needs to process the event handler of a clicked menu item created in the Shell.

In the Module, I have something like:

CommandHandler("Delete")
public void OnDelete(object sender, EventArgs e) {
...
}

This method on the Module NEVER seems to get called, I can set the menu item to be disable and visible, but not execute the command action.

However, if I add the CommandHandler("Delete") method in the Shell application the method gets invoked.

What is the best way to modules process 'generic' menu items for there own use?

Craig
Oct 17, 2006 at 11:53 PM
originally posted by: pyhavaim

Make sure that you have this metod in a public class, not private!
Oct 18, 2006 at 6:11 PM
originally posted by: cpearson

The class and the method are public.

I also tried using the following:

UIProject
Shell.cs

public partial class ShellForm : Form {

EventPublication("event://Delete", PublicationScope.Global)
event EventHandler Delete;

CommandHandler("Delete")
public void OnEditDelete(object sender, EventArgs e) {
if (Delete != null) {
Delete(sender, e);
}
}
}


ModuleProject
Module.cs

public class Module: ModuleInit {
InjectionConstructor
public Module(ServiceDependency WorkItem workItem) {
m_workItem = workItem;
}

EventSubscription("event://Delete", ThreadOption.UserInterface)
public void OnDelete(object sender, EventArgs e) {
System.Windows.Forms.MessageBox.Show("Delete");
}
}

Using the pub.sub model didn't work either. The Delete(sender, e); line is never executed because Delete eventhandler is always null.

Also, I am using 3rd party tool,menu and status bar controls, which are registered as follows:

IUIElementAdapterFactoryCatalog catelog = RootWorkItem.Services.Get<IUIElementAdapterFactoryCatalog>();
catelog.RegisterFactory(new ToolBarUIAdapterFactory());

ICommandAdapterMapService mapService = RootWorkItem.Services.Get<ICommandAdapterMapService>();
mapService.Register(typeof(ToolbarItemBase), typeof(ToolBarItemCommandAdapter));

RootWorkItem.UIExtensionSites.RegisterSite("MainMenu", Shell.MenuBar);
RootWorkItem.UIExtensionSites.RegisterSite("MainStatus", Shell.StatusBar);
RootWorkItem.UIExtensionSites.RegisterSite("MainToolbar", Shell.ToolBar)

This seems to work all ok. Any other suggestions?

Craig
Oct 19, 2006 at 6:04 AM
originally posted by: matiaswoloski

Hi Craig

EventPublication("event://Delete", PublicationScope.Global)
event EventHandler Delete;

By default if you don't have access modifiers they will be "private". So change it to

EventPublication("event://Delete", PublicationScope.Global)
public event EventHandler Delete;

Also, I recommend you to use the Add Event Publication/Subscription recipe of the Smart Client Software Factory.
It will avoid any human error ;)

Matias
http://staff.southworks.net/blogs/matiaswoloski
Oct 21, 2006 at 2:23 PM
originally posted by: cpearson

that worked, thanks

Is using the pub/sub event model the best approach for this type of interaction between common menu/tool bar items in the shell and modules?
Oct 29, 2006 at 3:41 AM
originally posted by: tecnocrata

Hi Matias
I have a question
Isn't need a line line: WorkkItem.Commands"Delete".AdInvoke(button,"Click"); ???

Thanks
Oct 29, 2006 at 4:57 AM
originally posted by: matiaswoloski

Yes you will need it to associate the click of the button with the Delete command.
Oct 31, 2006 at 4:15 AM
originally posted by: tecnocrata

Hi Matias Again

I Have probles trying to bind a method like this:

CommandHandler("Delete")
public void OnShowMessage(object sender, SelectEventArgs e)
{
//....
}

This event isn't //public void OnShowMessage(object sender, EventArgs e)
Why I get a error: Error Binding Method?
Oct 31, 2006 at 6:43 AM
originally posted by: matiaswoloski

Check this out: http://www.cabpedia.com/index.php?title=CommandHandler

Matias