Command Design pattern - extension.

G

Gobi

Hi,

I have few UI elements shown in a main frame. When selecting a UI element I
want to show a context menu. Used a command pattern for it with the UI
element publishing it's commands and it works fine.

Now when two or more UI elements are selected and we want to show the
context menu, we need a subset of these menus

1) only menus common to both
2) some menus can be common to both but doesn't make sense to show for
multiple selection(e.g. When two are selected we should NOT show rename,
though both of them have rename)

I'm looking at the same functionality of Visual studio, where we get
different context menus when we select one project in the visual studio vs
when we select multiple project in visual studio.


Is there a pattern for the same.


Thanks a lot for your time.

Regards,
Gobi.
 
P

Pavel Minaev

Hi,

I have few UI elements shown in a main frame. When selecting a UI elementI
want to show a context menu. Used a command pattern for it with the UI
element publishing it's commands and it works fine.

Now when two or more UI elements are selected and we want to show the
context menu, we need a subset of these menus

1) only menus common to both
2) some menus can be common to both but doesn't make sense to show for
multiple selection(e.g. When two are selected we should NOT show rename,
though both of them have rename)

I'm looking at the same functionality of Visual studio, where we get
different context menus when we select one project in the visual studio vs
when we select multiple project in visual studio.

Is there a pattern for the same.

Doing #1 is fairly straightforward - just intersect the command lists
of all selected items.

Doing #2 is probably less so, but the most generic way I can think of
handling this is to add a "CanExecute" method to your ICommand (or
whatever it is called), which is invoked with sequence of selected
elements passed as an argument. Then you can return false from that
method on RenameCommand if there's more than one element, for example.
And use that when building the context menu.
 
G

Gobi

Thanks Pavel. I would try to come up with a good design to support it and
post if I find/do something generic
Hi,

I have few UI elements shown in a main frame. When selecting a UI element
I
want to show a context menu. Used a command pattern for it with the UI
element publishing it's commands and it works fine.

Now when two or more UI elements are selected and we want to show the
context menu, we need a subset of these menus

1) only menus common to both
2) some menus can be common to both but doesn't make sense to show for
multiple selection(e.g. When two are selected we should NOT show rename,
though both of them have rename)

I'm looking at the same functionality of Visual studio, where we get
different context menus when we select one project in the visual studio vs
when we select multiple project in visual studio.

Is there a pattern for the same.

Doing #1 is fairly straightforward - just intersect the command lists
of all selected items.

Doing #2 is probably less so, but the most generic way I can think of
handling this is to add a "CanExecute" method to your ICommand (or
whatever it is called), which is invoked with sequence of selected
elements passed as an argument. Then you can return false from that
method on RenameCommand if there's more than one element, for example.
And use that when building the context menu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top