Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) How to access diagram node context menu by keyboard? (Read 8595 times)
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
How to access diagram node context menu by keyboard?
Mar 30th, 2015 at 3:27pm
Print Post  
We are required to access diagram node context menu by keyboard, e.g, shift+F10. When a diagram node is selected, right click on the node, a context menu will be opened, how can we hook the keyboard for this context menu?

Thanks,
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #1 - Mar 30th, 2015 at 5:37pm
Print Post  
If you have set nodes' ContextMenu property, you could show it from PreviewKeyDown handler like this:

Code
Select All
<diag:Diagram
	PreviewKeyDown="OnDiagramKeyDown"
	...

void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.System && e.SystemKey == Key.F10)
	{
		var node = diagram.ActiveItem as DiagramNode;
		if (node != null && node.ContextMenu != null)
		{
			var menu = node.ContextMenu;
			menu.PlacementTarget = node;
			menu.Placement = PlacementMode.Relative;
			menu.IsOpen = true;
			e.Handled = true;
		}
	}
} 



If you are showing it dynamically from NodeClicked event handler, you could refactor the code to call a common method from both key-down and click handlers:

Code
Select All
void ShowContextMenu(DiagramNode node)
{
	var menu = new ContextMenu();
	var item = new MenuItem();
	item.Header = "Title";
	menu.Items.Add(item);

	menu.PlacementTarget = node;
	menu.Placement = PlacementMode.Relative;
	menu.IsOpen = true;
}

private void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.System && e.SystemKey == Key.F10)
	{
		var node = diagram.ActiveItem as DiagramNode;
		if (node != null)
		{
			ShowContextMenu(node);
			e.Handled = true;
		}
	}
}

private void OnNodeClicked(object sender, NodeEventArgs e)
{
	if (e.MouseButton == MouseButton.Right)
	{
		ShowContextMenu(e.Node);
		return;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #2 - Apr 12th, 2015 at 10:18am
Print Post  
Thanks, This works!
Will Mindfusion consider to add 508 Compliance such as right click or Shift +F10 to open context menu in the future?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #3 - Apr 13th, 2015 at 2:02pm
Print Post  
Do you mean getting some built-in support for all points from Software Applications section of 508 standard (http://www.section508.gov/section-508-standards-guide#Software), or just showing context menu using keyboard shortcut?
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #4 - Apr 17th, 2015 at 2:36am
Print Post  
Yes, that link covers it.
For example, for context menu, shift + F10 or the keyboard button between the Start button and the Ctrl button under Shift and Enter with an context menu icon.
Do you have any plan to cover this in the future natively?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #5 - Apr 17th, 2015 at 3:14pm
Print Post  
We've added built-in binding to ApplicationCommands.ContextMenu in this v3.3 build:

https://mindfusion.eu/_beta/wpfdiag33.zip

That command is executed for both Shift+F10 and the dedicated menu key. It will show Diagram.ActiveItem.ContextMenu if it's not null. If you do not set items' ContextMenu properties but show menus dynamically as in second example above, you will have to add your own binding to the command.

We'll have in mind the other points from 508 for next releases.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #6 - Apr 20th, 2015 at 3:26pm
Print Post  
Thank you!

I will try V3.3 soon.

Question again, I tried the sample code above, it works for Shift+F10 to bring the context menu up, but for Menu key
as: http://en.wikipedia.org/wiki/Menu_key
It won't show up context menu.
I debugged it, the keycode I have for Menu Key is Key.Apps, seems working, but no context menu is showing.

Any idea?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #7 - Apr 20th, 2015 at 4:03pm
Print Post  
You will need to add a test for the Key.Apps key too:

Code
Select All
// PreviewKeyUp="OnDiagramKeyUp" in Xaml
private void OnDiagramKeyUp(object sender, KeyEventArgs e)
{
	if (e.Key == Key.Apps)
	{
		var node = diagram.ActiveItem as DiagramNode;
		if (node != null)
		{
			ShowContextMenu(node);
			e.Handled = true;
		}
	}
}

// PreviewKeyDown="OnDiagramKeyDown" in Xaml
void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.System && e.SystemKey == Key.F10)
	{
		var node = diagram.ActiveItem as DiagramNode;
		if (node != null)
		{
			ShowContextMenu(node);
			e.Handled = true;
		}
	}
} 



I had to move the Key.Apps case to a KeyUp handler because of this problem:
http://stackoverflow.com/questions/4333032/context-menu-disappears-when-opened-w...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #8 - Apr 21st, 2015 at 5:00pm
Print Post  
Thank you!

I tried to test v3.3 with the zip file you sent earlier. I couldn't compile by just replacing the dll due to license issue.
I checked your website for trial version, there is no v3.3 yet for WPF. Where can I get a trial version v3.3? Currently we have v3.0.3.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #9 - Apr 22nd, 2015 at 8:20am
Print Post  
Hi,

v3.3 is now in beta tests (http://mindfusion.eu/Forum/YaBB.pl?num=1427803969). This version no longer requires design-time licensing so you can remove the respective line from licenses.licx if you are getting errors from LC.exe.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #10 - Apr 24th, 2015 at 3:03pm
Print Post  
I finally got my earlier code compiled OK with v3.3.
But when running it, it complains about Mindfusion.Scripting dll. I am using CreateShapeNode from Diagram Factory.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #11 - Apr 25th, 2015 at 10:30am
Print Post  
We've omitted scripting.dll from last beta upload. Now you can find it with new build here:
https://mindfusion.eu/_beta/wpfdiag33.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #12 - Apr 27th, 2015 at 2:17pm
Print Post  
Yes, I used the latest one and got my earlier coded diagram show up correctly. I set item's ContextMenu properties,
with SHIFT+F10,  it shows up correctly.
with the dedicated context menu key as I mentioned earlier in my post, it shows and disappears. I thought it is already built-in.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to access diagram node context menu by keyboard?
Reply #13 - Apr 27th, 2015 at 3:49pm
Print Post  
That looks like a bug in WPF context menus. The keyboard focus is on the context menu when KeyUp event is raised for Apps key. The menu closes even if it was shown from WPF's own ApplicationCommand.ContextMenu, so the decision to close it comes from the framework code. You can work around this by stopping event propagation from PreviewKeyUp:

nodeCtxMenu.PreviewKeyUp += (sender, e) => e.Handled = e.Key == Key.Apps;

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: How to access diagram node context menu by keyboard?
Reply #14 - Apr 28th, 2015 at 1:17pm
Print Post  
Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint