Browse Source

More fixes to the forms designer view to prevent meaningless NullReferenceExceptions when the DesignSurface cannot be created because of an early exception in LoadDesigner.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2526 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 18 years ago
parent
commit
fa9ae124db
  1. 76
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

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

@ -195,12 +195,14 @@ namespace ICSharpCode.FormsDesigner
// in the PropertyPad, "InvalidOperationException: The container cannot be disposed // in the PropertyPad, "InvalidOperationException: The container cannot be disposed
// at design time" is thrown. // at design time" is thrown.
// This is solved by calling dispose after the double-click event has been processed. // This is solved by calling dispose after the double-click event has been processed.
if (disposing) { if (designSurface != null) {
designSurface.Dispose(); if (disposing) {
} else { designSurface.Dispose();
p.BeginInvoke(new MethodInvoker(designSurface.Dispose)); } else {
p.BeginInvoke(new MethodInvoker(designSurface.Dispose));
}
designSurface = null;
} }
designSurface = null;
} }
PropertyContainer propertyContainer = new PropertyContainer(); PropertyContainer propertyContainer = new PropertyContainer();
@ -213,6 +215,10 @@ namespace ICSharpCode.FormsDesigner
public void ShowHelp() public void ShowHelp()
{ {
if (Host == null) {
return;
}
ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService)); ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService));
if (selectionService != null) { if (selectionService != null) {
Control ctl = selectionService.PrimarySelection as Control; Control ctl = selectionService.PrimarySelection as Control;
@ -396,7 +402,7 @@ namespace ICSharpCode.FormsDesigner
protected void UpdatePropertyPad() protected void UpdatePropertyPad()
{ {
if (IsFormsDesignerVisible) { if (IsFormsDesignerVisible && Host != null) {
propertyContainer.Host = Host; propertyContainer.Host = Host;
propertyContainer.SelectableObjects = Host.Container.Components; propertyContainer.SelectableObjects = Host.Container.Components;
ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService)); ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService));
@ -441,62 +447,54 @@ namespace ICSharpCode.FormsDesigner
#endregion #endregion
#region IClipboardHandler implementation #region IClipboardHandler implementation
bool IsMenuCommandEnabled(CommandID commandID)
{
if (designSurface == null) {
return false;
}
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));
if (menuCommandService == null) {
return false;
}
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(commandID);
if (menuCommand == null) {
return false;
}
//int status = menuCommand.OleStatus;
return menuCommand.Enabled;
}
public bool EnableCut { public bool EnableCut {
get { get {
//ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService)); return IsMenuCommandEnabled(StandardCommands.Cut);
//return selectionService.SelectionCount >= 0 && selectionService.PrimarySelection != host.RootComponent;
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Cut);
if (menuCommand == null) {
return false;
}
int status = menuCommand.OleStatus;
return menuCommand.Enabled;
} }
} }
public bool EnableCopy { public bool EnableCopy {
get { get {
//ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService)); return IsMenuCommandEnabled(StandardCommands.Copy);
//return selectionService.SelectionCount >= 0 && selectionService.PrimarySelection != host.RootComponent;
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Copy);
if (menuCommand == null) {
return false;
}
int status = menuCommand.OleStatus;
return menuCommand.Enabled;
} }
} }
const string ComponentClipboardFormat = "CF_DESIGNERCOMPONENTS"; const string ComponentClipboardFormat = "CF_DESIGNERCOMPONENTS";
public bool EnablePaste { public bool EnablePaste {
get { get {
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); return IsMenuCommandEnabled(StandardCommands.Paste);
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Paste);
if (menuCommand == null) {
return false;
}
int status = menuCommand.OleStatus;
return menuCommand.Enabled;
} }
} }
public bool EnableDelete { public bool EnableDelete {
get { get {
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); return IsMenuCommandEnabled(StandardCommands.Delete);
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Delete);
if (menuCommand == null) {
return false;
}
int status = menuCommand.OleStatus;
return menuCommand.Enabled;
} }
} }
public bool EnableSelectAll { public bool EnableSelectAll {
get { get {
return true; return designSurface != null;
} }
} }

Loading…
Cancel
Save