Cleaning up menu code and starting to implement CommandPlaceholders

This commit is contained in:
Michael Becker 2015-09-28 16:41:31 -04:00
parent 8eca41cbae
commit 3e5b26ea48
5 changed files with 66 additions and 45 deletions

View File

@ -99,12 +99,12 @@
</Command>
<Command ID="FileRecentFiles">
<Items>
<CommandPlaceholder ID="RecentFiles" />
<CommandPlaceholder PlaceholderID="RecentFiles" />
</Items>
</Command>
<Command ID="FileRecentProjects">
<Items>
<CommandPlaceholder ID="RecentProjects" />
<CommandPlaceholder PlaceholderID="RecentProjects" />
</Items>
</Command>
<Command ID="FileRestart" />
@ -285,7 +285,7 @@
<Command ID="ToolsSessionManager" />
<Command ID="ToolsExternalTools">
<Items>
<CommandPlaceholder ID="ExternalTools" />
<CommandPlaceholder PlaceholderID="ExternalTools" />
<Separator />
<CommandReference CommandID="ToolsExternalToolsCustomize" />
</Items>

View File

@ -273,6 +273,10 @@ namespace UniversalEditor.Engines.WindowsForms
}
tsi = tsmi;
}
else if (item is CommandPlaceholderCommandItem)
{
throw new NotImplementedException();
}
else if (item is SeparatorCommandItem)
{
tsi = new ToolStripSeparator();
@ -588,6 +592,14 @@ namespace UniversalEditor.Engines.WindowsForms
smi.NativeControls.Add(tsmi);
}
else if (item is PlaceholderMenuItem)
{
ActionMenuItem[] amis = Engine.CurrentEngine.CreateMenuItemsFromPlaceholder(item as PlaceholderMenuItem);
foreach (ActionMenuItem ami in amis)
{
RecursiveLoadCustomMenuItems(ami, tsiParent);
}
}
}
private ToolStripMenuItem GetToolStripMenuItemFromUniversalMenuItem(ActionMenuItem ami)

View File

@ -18,6 +18,16 @@ namespace UniversalEditor.UserInterface
mvarCommandID = commandID;
}
}
public class CommandPlaceholderCommandItem : CommandItem
{
private string mvarPlaceholderID = String.Empty;
public string PlaceholderID { get { return mvarPlaceholderID; } set { mvarPlaceholderID = value; } }
public CommandPlaceholderCommandItem(string placeholderID)
{
mvarPlaceholderID = placeholderID;
}
}
public class SeparatorCommandItem : CommandItem
{
}

View File

@ -640,7 +640,7 @@ namespace UniversalEditor.UserInterface
MarkupTagElement tag = (el as MarkupTagElement);
if (tag == null) continue;
InitializeMainMenuItem(tag, cmd);
InitializeCommandBarItem(tag, cmd, null);
}
}
@ -658,7 +658,7 @@ namespace UniversalEditor.UserInterface
{
MarkupTagElement tagItem = (elItem as MarkupTagElement);
if (tagItem == null) continue;
InitializeMainMenuItem(tagItem, null);
InitializeCommandBarItem(tagItem, null, null);
}
}
@ -923,30 +923,15 @@ namespace UniversalEditor.UserInterface
{
MarkupTagElement tagItem = (elItem as MarkupTagElement);
if (tagItem == null) continue;
switch (tagItem.FullName)
{
case "CommandReference":
{
MarkupAttribute attCommandID = tagItem.Attributes["CommandID"];
if (attCommandID != null)
{
cb.Items.Add(new CommandReferenceCommandItem(attCommandID.Value));
}
break;
}
case "Separator":
{
cb.Items.Add(new SeparatorCommandItem());
break;
}
}
InitializeCommandBarItem(tagItem, null, cb);
}
}
mvarCommandBars.Add(cb);
}
private void InitializeCommandBarItem(MarkupTagElement tag, CommandBar parent)
private void InitializeCommandBarItem(MarkupTagElement tag, Command parent, CommandBar parentCommandBar)
{
CommandItem item = null;
switch (tag.FullName)
@ -960,29 +945,12 @@ namespace UniversalEditor.UserInterface
}
break;
}
case "Separator":
case "CommandPlaceholder":
{
item = new SeparatorCommandItem();
break;
}
}
if (item != null)
{
parent.Items.Add(item);
}
}
private void InitializeMainMenuItem(MarkupTagElement tag, Command parent)
{
CommandItem item = null;
switch (tag.FullName)
{
case "CommandReference":
{
MarkupAttribute attCommandID = tag.Attributes["CommandID"];
if (attCommandID != null)
MarkupAttribute attPlaceholderID = tag.Attributes["PlaceholderID"];
if (attPlaceholderID != null)
{
item = new CommandReferenceCommandItem(attCommandID.Value);
item = new CommandPlaceholderCommandItem(attPlaceholderID.Value);
}
break;
}
@ -997,7 +965,14 @@ namespace UniversalEditor.UserInterface
{
if (parent == null)
{
mvarMainMenu.Items.Add(item);
if (parentCommandBar != null)
{
parentCommandBar.Items.Add(item);
}
else
{
mvarMainMenu.Items.Add(item);
}
}
else
{
@ -1321,5 +1296,18 @@ namespace UniversalEditor.UserInterface
return false;
}
public abstract bool ShowCustomOptionDialog(ref CustomOption.CustomOptionCollection customOptions, string title = null, EventHandler aboutButtonClicked = null);
public virtual ActionMenuItem[] CreateMenuItemsFromPlaceholder(PlaceholderMenuItem pmi)
{
List<ActionMenuItem> list = new List<ActionMenuItem>();
switch (pmi.PlaceholderID)
{
case "RecentFiles":
{
break;
}
}
return list.ToArray();
}
}
}

View File

@ -143,6 +143,7 @@ namespace UniversalEditor.UserInterface
}
}
}
public class ActionMenuItem : MenuItem
{
private string mvarTitle = String.Empty;
@ -180,4 +181,14 @@ namespace UniversalEditor.UserInterface
{
}
public class PlaceholderMenuItem : MenuItem
{
private string mvarPlaceholderID = String.Empty;
public string PlaceholderID { get { return mvarPlaceholderID; } set { mvarPlaceholderID = value; } }
public PlaceholderMenuItem(string placeholderID)
{
mvarPlaceholderID = placeholderID;
}
}
}