Added the ability for plugins to add menu items in existing menus

This commit is contained in:
codeimp 2010-08-23 09:58:30 +00:00
parent b2f672c94f
commit 198d9ebfe5
6 changed files with 310 additions and 212 deletions

View file

@ -713,6 +713,7 @@
<DependentUpon>ErrorsForm.cs</DependentUpon>
</Compile>
<Compile Include="Windows\FindReplaceOptions.cs" />
<Compile Include="Windows\MenuSection.cs" />
<Compile Include="Windows\PasteOptionsForm.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -125,6 +125,17 @@ namespace CodeImp.DoomBuilder.Windows
/// <param name="menu">The menu to add to Doom Builder.</param>
void AddMenu(ToolStripMenuItem menu);
/// <summary>
/// This adds a menu or menu item to the Doom Builder menu strip in a specific location.
/// <para>
/// NOTE: When the Tag property of menu items is set with a string, this changes the
/// tag to a fully qualified action name by prefixing it with the assembly name.
/// </para>
/// </summary>
/// <param name="menu">The menu to add to Doom Builder.</param>
/// <param name="section">The location where to insert the menu or item.</param>
void AddMenu(ToolStripMenuItem menu, MenuSection section);
/// <summary>
/// This removes a menu from the Doom Builder menu strip.
/// </summary>

File diff suppressed because it is too large Load diff

View file

@ -1764,25 +1764,58 @@ namespace CodeImp.DoomBuilder.Windows
#region ================== Menus
// This adds a menu to the menus bar
public void AddMenu(ToolStripMenuItem menu)
public void AddMenu(ToolStripMenuItem menu) { AddMenu(menu, MenuSection.Top, General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly())); }
public void AddMenu(ToolStripMenuItem menu, MenuSection section) { AddMenu(menu, section, General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly())); }
private void AddMenu(ToolStripMenuItem menu, MenuSection section, Plugin plugin)
{
// Find the plugin that called this method
Plugin plugin = General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly());
// Fix tags to full action names
RenameTagsToFullActions(menu.DropDownItems, plugin);
ToolStripItemCollection items = new ToolStripItemCollection(this.menumain, new ToolStripItem[0]);
items.Add(menu);
RenameTagsToFullActions(items, plugin);
// Insert the menu before the Tools menu
menumain.Items.Insert(menumain.Items.IndexOf(menutools), menu);
ApplyShortcutKeys(menu.DropDownItems);
// Insert the menu in the right location
switch(section)
{
case MenuSection.FileNewOpenClose: menufile.DropDownItems.Insert(menufile.DropDownItems.IndexOf(seperatorfileopen), menu); break;
case MenuSection.FileSave: menufile.DropDownItems.Insert(menufile.DropDownItems.IndexOf(seperatorfilesave), menu); break;
case MenuSection.FileRecent: menufile.DropDownItems.Insert(menufile.DropDownItems.IndexOf(seperatorfilerecent), menu); break;
case MenuSection.FileExit: menufile.DropDownItems.Insert(menufile.DropDownItems.IndexOf(itemexit), menu); break;
case MenuSection.EditUndoRedo: menuedit.DropDownItems.Insert(menuedit.DropDownItems.IndexOf(seperatoreditundo), menu); break;
case MenuSection.EditCopyPaste: menuedit.DropDownItems.Insert(menuedit.DropDownItems.IndexOf(seperatoreditcopypaste), menu); break;
case MenuSection.EditGeometry: menuedit.DropDownItems.Insert(menuedit.DropDownItems.IndexOf(seperatoreditgeometry), menu); break;
case MenuSection.EditGrid: menuedit.DropDownItems.Insert(menuedit.DropDownItems.IndexOf(seperatoreditgrid), menu); break;
case MenuSection.EditMapOptions: menuedit.DropDownItems.Add(menu); break;
case MenuSection.ViewThings: menuview.DropDownItems.Insert(menuview.DropDownItems.IndexOf(seperatorviewthings), menu); break;
case MenuSection.ViewViews: menuview.DropDownItems.Insert(menuview.DropDownItems.IndexOf(seperatorviewviews), menu); break;
case MenuSection.ViewZoom: menuview.DropDownItems.Insert(menuview.DropDownItems.IndexOf(seperatorviewzoom), menu); break;
case MenuSection.ViewScriptEdit: menuview.DropDownItems.Add(menu); break;
case MenuSection.PrefabsInsert: menuprefabs.DropDownItems.Insert(menuprefabs.DropDownItems.IndexOf(seperatorprefabsinsert), menu); break;
case MenuSection.PrefabsCreate: menuprefabs.DropDownItems.Add(menu); break;
case MenuSection.ToolsResources: menutools.DropDownItems.Insert(menutools.DropDownItems.IndexOf(seperatortoolsresources), menu); break;
case MenuSection.ToolsConfiguration: menutools.DropDownItems.Insert(menutools.DropDownItems.IndexOf(seperatortoolsconfig), menu); break;
case MenuSection.ToolsTesting: menutools.DropDownItems.Add(menu); break;
case MenuSection.HelpManual: menuhelp.DropDownItems.Insert(menuhelp.DropDownItems.IndexOf(seperatorhelpmanual), menu); break;
case MenuSection.HelpAbout: menuhelp.DropDownItems.Add(menu); break;
case MenuSection.Top: menumain.Items.Insert(menumain.Items.IndexOf(menutools), menu); break;
}
ApplyShortcutKeys(items);
}
// Removes a menu
public void RemoveMenu(ToolStripMenuItem menu)
{
// We actually have no idea in which menu this item is,
// so try removing from all menus and the top strip
menufile.DropDownItems.Remove(menu);
menuedit.DropDownItems.Remove(menu);
menuview.DropDownItems.Remove(menu);
menuprefabs.DropDownItems.Remove(menu);
menutools.DropDownItems.Remove(menu);
menuhelp.DropDownItems.Remove(menu);
menumain.Items.Remove(menu);
}
// Public method to apply shortcut keys
internal void ApplyShortcutKeys()
{

View file

@ -117,24 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStripMenuItem1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripMenuItem3.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator9.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator11.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolstripSeperator6.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripSeparator12.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>

View file

@ -0,0 +1,65 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
using CodeImp.DoomBuilder.Map;
using SlimDX.Direct3D9;
using SlimDX;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Imaging;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Editing;
#endregion
namespace CodeImp.DoomBuilder.Windows
{
public enum MenuSection
{
FileNewOpenClose,
FileSave,
FileRecent,
FileExit,
EditUndoRedo,
EditCopyPaste,
EditGeometry,
EditGrid,
EditMapOptions,
ViewThings,
ViewViews,
ViewZoom,
ViewScriptEdit,
PrefabsInsert,
PrefabsCreate,
ToolsResources,
ToolsConfiguration,
ToolsTesting,
HelpManual,
HelpAbout,
Top
}
}