Browse Source

Applied forms designer patch by Christian Hornung: use the MenuCommandService implementation from the .NET framework.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1050 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
0d9ccc034b
  1. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs
  2. 105
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/MenuCommandService.cs

3
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

@ -166,11 +166,10 @@ namespace ICSharpCode.FormsDesigner @@ -166,11 +166,10 @@ namespace ICSharpCode.FormsDesigner
designSurface = new DesignSurface(serviceContainer);
serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormsDesigner.Services.MenuCommandService(p, designSurface, serviceContainer));
serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormsDesigner.Services.MenuCommandService(p, designSurface));
ICSharpCode.FormsDesigner.Services.EventBindingService eventBindingService = new ICSharpCode.FormsDesigner.Services.EventBindingService(designSurface);
serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), eventBindingService);
serviceContainer.AddService(typeof(IDesignerHost), Host); // required for SD2-484
designerResourceService.Host = Host;
DesignerLoader designerLoader = loaderProvider.CreateLoader(generator);

105
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/MenuCommandService.cs

@ -21,93 +21,17 @@ using ICSharpCode.Core; @@ -21,93 +21,17 @@ using ICSharpCode.Core;
namespace ICSharpCode.FormsDesigner.Services
{
class MenuCommandService : IMenuCommandService
class MenuCommandService : System.ComponentModel.Design.MenuCommandService
{
IServiceContainer serviceContainer;
ArrayList commands = new ArrayList();
ArrayList verbs = new ArrayList();
Control panel;
DesignSurface designSurface;
public DesignerVerbCollection Verbs {
get {
DesignerVerbCollection verbCollection = CreateDesignerVerbCollection();
verbCollection.AddRange((DesignerVerb[])verbs.ToArray(typeof(DesignerVerb)));
return verbCollection;
}
}
public MenuCommandService(Control panel, DesignSurface designSurface, IServiceContainer serviceContainer)
{
this.panel = panel;
this.designSurface = designSurface;
this.serviceContainer = serviceContainer;
}
public void AddCommand(System.ComponentModel.Design.MenuCommand command)
{
if (command != null && command.CommandID != null) {
if (!commands.Contains(command)) {
this.commands.Add(command);
}
}
}
public void AddVerb(DesignerVerb verb)
{
if (verb != null) {
this.verbs.Add(verb);
}
}
public void RemoveCommand(System.ComponentModel.Design.MenuCommand command)
{
if (command != null) {
commands.Remove(command.CommandID);
}
}
public void RemoveVerb(DesignerVerb verb)
{
if (verb != null) {
verbs.Remove(verb);
}
}
public bool GlobalInvoke(CommandID commandID)
{
System.ComponentModel.Design.MenuCommand menuCommand = FindCommand(commandID);
if (menuCommand == null) {
return false;
}
menuCommand.Invoke();
return true;
}
public System.ComponentModel.Design.MenuCommand FindCommand(CommandID commandID)
public MenuCommandService(Control panel, IServiceProvider serviceProvider) : base(serviceProvider)
{
// if (StringType.StrCmp(MenuUtilities.GetCommandNameFromCommandID(commandID), "", false) == 0 && StringType.StrCmp(commandID.ToString(), "74d21313-2aee-11d1-8bfb-00a0c90f26f7 : 12288", false) == 0) {
// return MenuUtilities.gPropertyGridResetCommand;
// }
foreach (System.ComponentModel.Design.MenuCommand menuCommand in commands) {
if (menuCommand.CommandID == commandID) {
return menuCommand;
}
}
foreach (DesignerVerb verb in Verbs) {
if (verb.CommandID == commandID) {
return verb;
}
}
return null;
this.panel = panel;
}
public void ShowContextMenu(CommandID menuID, int x, int y)
public override void ShowContextMenu(CommandID menuID, int x, int y)
{
string contextMenuPath = "/SharpDevelop/FormsDesigner/ContextMenus/";
@ -128,26 +52,5 @@ namespace ICSharpCode.FormsDesigner.Services @@ -128,26 +52,5 @@ namespace ICSharpCode.FormsDesigner.Services
MenuService.ShowContextMenu(this, contextMenuPath, panel, p.X, p.Y);
}
public DesignerVerbCollection CreateDesignerVerbCollection()
{
DesignerVerbCollection designerVerbCollection = new DesignerVerbCollection();
ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService));
IDesignerHost host = (IDesignerHost)serviceContainer.GetService(typeof(IDesignerHost));
if (host != null && selectionService != null && selectionService.SelectionCount == 1) {
IComponent selectedComponent = selectionService.PrimarySelection as IComponent;
if (selectedComponent != null) {
IDesigner designer = host.GetDesigner(selectedComponent);
if (designer != null) {
designerVerbCollection.AddRange(designer.Verbs);
}
}
if (selectedComponent == host.RootComponent) {
designerVerbCollection.AddRange((DesignerVerb[])this.verbs.ToArray(typeof(DesignerVerb)));
}
}
return designerVerbCollection;
}
}
}

Loading…
Cancel
Save