Browse Source

Fixed exception during shutdown that caused SharpDevelop to not save any settings.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0wpf@3480 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
4cf6263988
  1. 2
      src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs
  2. 4
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  3. 39
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs

2
src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.SharpDevelop.Gui
errorTextBox.Background = SystemColors.WindowBrush; errorTextBox.Background = SystemColors.WindowBrush;
} }
errorTextBox.Text = ex.ToString(); errorTextBox.Text = ex.ToString();
contentControl.Content = errorTextBox; contentControl.SetContent(errorTextBox);
} }
Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>(); Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>();

4
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -235,7 +235,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (!page.IsFocused) page.Focus(); if (!page.IsFocused) page.Focus();
}; };
viewTabControl.TabStripPlacement = Dock.Bottom; viewTabControl.TabStripPlacement = Dock.Bottom;
this.Content = viewTabControl; this.SetContent(viewTabControl);
viewTabControl.SelectionChanged += delegate { viewTabControl.SelectionChanged += delegate {
UpdateActiveViewContent(); UpdateActiveViewContent();
@ -248,7 +248,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.Content = null; this.Content = null;
if (viewTabControl != null) { if (viewTabControl != null) {
foreach (TabItem page in viewTabControl.Items) { foreach (TabItem page in viewTabControl.Items) {
page.Content = null; page.SetContent(null);
} }
viewTabControl = null; viewTabControl = null;
} }

39
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -121,23 +121,50 @@ namespace ICSharpCode.SharpDevelop
/// If the content is a Windows-Forms control, it is wrapped in a WindowsFormsHost. /// If the content is a Windows-Forms control, it is wrapped in a WindowsFormsHost.
/// If the content control already contains a WindowsFormsHost with that content, /// If the content control already contains a WindowsFormsHost with that content,
/// the old WindowsFormsHost is kept. /// the old WindowsFormsHost is kept.
/// When a WindowsFormsHost is replaced with another content, the host is disposed (but the control
/// inside the host isn't)
/// </summary> /// </summary>
public static void SetContent(this ContentControl contentControl, object content) public static void SetContent(this ContentControl contentControl, object content)
{ {
if (contentControl == null) if (contentControl == null)
throw new ArgumentNullException("contentControl"); throw new ArgumentNullException("contentControl");
var host = contentControl.Content as SDWindowsFormsHost;
if (host != null) {
if (host.Child == content)
return;
host.Dispose();
}
if (content is WinForms.Control) { if (content is WinForms.Control) {
var host = contentControl.Content as WinForms.Integration.WindowsFormsHost; contentControl.Content = new SDWindowsFormsHost((WinForms.Control)content);
if (host == null || host.Child != content) {
contentControl.Content = new WinForms.Integration.WindowsFormsHost {
Child = (System.Windows.Forms.Control)content
};
}
} else if (content is string) { } else if (content is string) {
contentControl.Content = new TextBlock(new Run(content.ToString())) { TextWrapping = TextWrapping.Wrap }; contentControl.Content = new TextBlock(new Run(content.ToString())) { TextWrapping = TextWrapping.Wrap };
} else { } else {
contentControl.Content = content; contentControl.Content = content;
} }
} }
class SDWindowsFormsHost : WinForms.Integration.WindowsFormsHost
{
public SDWindowsFormsHost(WinForms.Control child)
{
this.Child = child;
child.Disposed += child_Disposed;
}
void child_Disposed(object sender, EventArgs e)
{
Dispose();
}
protected override void Dispose(bool disposing)
{
if (disposing && Child != null) {
Child.Disposed -= child_Disposed;
// prevent child from being disposed
Child = null;
}
base.Dispose(disposing);
}
}
} }
} }

Loading…
Cancel
Save