Group: Forum Members
Last Active: 14 Years Ago
Posts: 9,
Visits: 1
|
I've been able to create a new command and add that command to an existing toolbar or a new toolbar by implementing my own overrides of NDiagramToolbarsBuilder, but I don't see a simple way / similar to add to the existing menus. Can I get a reference to the "File" or "View" menu to add my own commands in, or what is the easiest way to do this?
Thanks, Herb.
|
Group: Forum Members
Last Active: 14 Years Ago
Posts: 9,
Visits: 1
|
I may have found a way - might not be the easiest.
I've made a new class inheriting from NDiagramMainMenuBuilder and making up the list of commands from it from scratch, adding my own in where I need them, and removing ones where I don't want them.
Unfortunately, the base properties (FileCommandIds, EditCommandIds, etc) that return the command ids all throw an exception:
System.InvalidCastException was unhandled Message="At least one element in the source array could not be cast down to the destination array type." Source="mscorlib" StackTrace: at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at System.Collections.ArrayList.ToArray(Type type) at Nevron.Diagram.WinForm.Commands.NDiagramMainMenuBuilder.get_FileCommandIds()
For now, I've gone through all the values in the DiagramCommand enumeration and have overridden all of NDiagramMainMenuBuilder, as I needed to get these properties.
That said, if there's a better way to customize the menu than this, I'd love to hear it.
Thanks, Herb.
|
Group: Forum Members
Last Active: 14 Years Ago
Posts: 9,
Visits: 1
|
An aside - the same exception occurs when attempting to get any of the arrays of command ids from the NDiagramToolbarsBuilder
System.InvalidCastException was unhandled Message="At least one element in the source array could not be cast down to the destination array type." Source="mscorlib" StackTrace: at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at System.Collections.ArrayList.ToArray(Type type) at Nevron.Diagram.WinForm.Commands.NDiagramToolbarsBuilder.get_ViewCommandIds()
Further experimentation shows that the property BeginGroupCommandIds works on both, suggesting that construction of the apparent underlying ArrayList is different for these than the other ArrayLists (or that the values BeginGroupCommandIds are stored as an int[] to begin with).
It's a mild inconvenience, to say the least.
Herb.
|
Group: Forum Members
Last Active: 2 Months Ago
Posts: 35,
Visits: 15
|
Hi Herb,
Yes - the best way to completely override the main menu and the toolbars building process is to override the BuildMainMenu and BuildToolbars methods of the NDiagramMainMenuBuilder and NDiagramToolbarsBuilder classes respectively, or to simply set new command id arrays to the respective command sections.
Unfortunately we have confirmed the bug in the getter implementation not only for the NDiagramMainMenuBuilder but for the NDiagramToolbarsBuilder too. The bug is now fixed and will appear in the next service pack or volume release - apologies for the inconvenience.
Best regards, Ivo
|
Group: Forum Members
Last Active: 11 Years Ago
Posts: 12,
Visits: 1
|
I'm working my way through Nevron and based on these posts/the UI documentation this is what I came up with to add a menu item. It adds an import item to the top level menu, with one subitem called TT.
public static void AddMenusToNevronDefaultMenu(NDiagramCommandBarsManager manager, Blah context) { NControlHelper.BeginUpdate(manager.ParentControl);
manager.MainMenuBuilder = new OgmaticMainMenuBuilder(context); manager.Recreate();
NControlHelper.EndUpdate(manager.ParentControl, true); } }
public class OgmaticMainMenuBuilder : NDiagramMainMenuBuilder { private readonly Blah context; private ArrayList customCommandIds; public OgmaticMainMenuBuilder(Blah context) { this.context = context; }
public override NMenuBar BuildMainMenu() { var menuBar = base.BuildMainMenu(); NCommandCollection commands = menuBar.Commands;
var importCommand = new NCommand(); importCommand.Properties.Text = "Import"; commands.Insert(2, importCommand);
var importTTCommand = new NCommand(); importTTCommand .Click += new CommandEventHandler(OnImportCommand); importTTCommand .Properties.Text = "TT";
importCommand.Commands.Add(importTTCommand );
return menuBar; }
private void OnImportCommand(object sender, CommandEventArgs e) { ImportDialog import = new ImportDialog(); import.Changed = false; import.ShowDialog(); if (import.Changed) { DiagramGenerator.GenerateTTDiagram(import.CurrentModel, context); } } }
Notes: ======
The NDiagramCommand has a similar intent to NCommand - but they are not compatable. I found it a little confusing.
Help: ===== Is there a better way to do this? Am I missing an obvious API? Examples would help for us Nevron Nubes.
|
Group: Forum Members
Last Active: 14 Years Ago
Posts: 9,
Visits: 1
|
I tend to make classes that inherit from NDiagramCommand or NDiagramButtonCommand - the latter is preferred, since the mechanics are nicer, and it goes on a toolbar as well as a menu.
Eg:
class SelectNoneCommand : NDiagramButtonCommand {
public SelectNoneCommand() : base( (int)DiagramCommandRange.Edit, (int)ASGDiagramCommands.Deselect, "Select None", "Deselect all elements", new NShortcut( System.Windows.Forms.Keys.N, System.Windows.Forms.Keys.Control ) ) { }
public override bool Enabled { get { return WindowController.Default.ElementsSelected > 0; } }
public override void Execute() { // Tell the view to deselect all objects } }
Then tell the NDiagramCommandBarsManager.Commander.Commands to add a new instance: cmds.Add( new SelectNoneCommand() );
Finally, add it to the menu - the MenuBuilder class has a CreateCommand method that will create the NCommand from the Id and GroupId that you used when you made the NDiagramButtonCommand.
You can insert the new NCommand where needed.
Alternatively - you can recreate the NDiagramMainMenuBuilder to have static lists of Command IDs for each of your menus (including the Nevron commands) and just create all the NCommands in a loop. The code is pretty simple, and I suspect that Nevron support would help you with it if need be. It's the route we took, because it was much easier to maintain than trying to insert menu items in the order we wanted.
Much shorter version: Create the NDiagramXXXCommand that you want, then use the CommandBuilder to make the underlying NCommand the menus or toolbars need. Much easer and cleaner.
Hope this helps. Herb.
|