Browse Source

Fixed ObjectDisposedException on MSBuildBasedProject in OptionPanels.ApplicationSettings.<LoadPanelContents>b__1:

- close project options view when the project is removed from the solution
- use an event on MSBuildBasedProject to detect a changed tools version, instead of querying it whenever the option page becomes visible
4.0
Daniel Grunwald 15 years ago
parent
commit
d77090270c
  1. 17
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs
  2. 9
      src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs
  3. 4
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  4. 16
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

17
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs

@ -75,11 +75,10 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
applicationManifestComboBox.TextChanged += delegate { helper.IsDirty = true; }; applicationManifestComboBox.TextChanged += delegate { helper.IsDirty = true; };
// embedding manifests requires the project to target MSBuild 3.5 or higher // embedding manifests requires the project to target MSBuild 3.5 or higher
project_MinimumSolutionVersionChanged(null, null);
// re-evaluate if the project has the minimum version whenever this options page gets visible // re-evaluate if the project has the minimum version whenever this options page gets visible
// because the "convert project" button on the compiling tab page might have updated the MSBuild version. // because the "convert project" button on the compiling tab page might have updated the MSBuild version.
applicationManifestComboBox.VisibleChanged += delegate { project.MinimumSolutionVersionChanged += project_MinimumSolutionVersionChanged;
applicationManifestComboBox.Enabled = project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008;
};
Get<TextBox>("projectFolder").Text = project.Directory; Get<TextBox>("projectFolder").Text = project.Directory;
Get<TextBox>("projectFile").Text = Path.GetFileName(project.FileName); Get<TextBox>("projectFile").Text = Path.GetFileName(project.FileName);
@ -93,6 +92,18 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
helper.AddConfigurationSelector(this); helper.AddConfigurationSelector(this);
} }
void project_MinimumSolutionVersionChanged(object sender, EventArgs e)
{
// embedding manifests requires the project to target MSBuild 3.5 or higher
applicationManifestComboBox.Enabled = project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008;
}
protected override void Dispose(bool disposing)
{
project.MinimumSolutionVersionChanged -= project_MinimumSolutionVersionChanged;
base.Dispose(disposing);
}
void ApplicationManifestComboBox_SelectedIndexChanged(object sender, EventArgs e) void ApplicationManifestComboBox_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 2) { if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 2) {

9
src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs

@ -39,6 +39,14 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
tabControl.IsDirtyChanged += delegate { RaiseIsDirtyChanged(); }; tabControl.IsDirtyChanged += delegate { RaiseIsDirtyChanged(); };
tabControl.AddOptionPanels(node.BuildChildItems<IOptionPanelDescriptor>(project)); tabControl.AddOptionPanels(node.BuildChildItems<IOptionPanelDescriptor>(project));
ProjectService.ProjectRemoved += ProjectService_ProjectRemoved;
}
void ProjectService_ProjectRemoved(object sender, ProjectEventArgs e)
{
if (e.Project == project && this.WorkbenchWindow != null)
WorkbenchWindow.CloseWindow(true);
} }
public override bool IsDirty { public override bool IsDirty {
@ -67,6 +75,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
public override void Dispose() public override void Dispose()
{ {
ProjectService.ProjectRemoved -= ProjectService_ProjectRemoved;
foreach (IDisposable op in tabControl.OptionPanels.OfType<IDisposable>()) { foreach (IDisposable op in tabControl.OptionPanels.OfType<IDisposable>()) {
op.Dispose(); op.Dispose();
} }

4
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -114,6 +114,8 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
public event EventHandler MinimumSolutionVersionChanged;
protected void SetToolsVersion(string newToolsVersion) protected void SetToolsVersion(string newToolsVersion)
{ {
PerformUpdateOnProjectFile( PerformUpdateOnProjectFile(
@ -121,6 +123,8 @@ namespace ICSharpCode.SharpDevelop.Project
projectFile.ToolsVersion = newToolsVersion; projectFile.ToolsVersion = newToolsVersion;
userProjectFile.ToolsVersion = newToolsVersion; userProjectFile.ToolsVersion = newToolsVersion;
}); });
if (MinimumSolutionVersionChanged != null)
MinimumSolutionVersionChanged(this, EventArgs.Empty);
} }
public void PerformUpdateOnProjectFile(Action action) public void PerformUpdateOnProjectFile(Action action)

16
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -628,6 +628,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (project != null) { if (project != null) {
OpenSolution.RemoveProjectConfigurations(project.IdGuid); OpenSolution.RemoveProjectConfigurations(project.IdGuid);
ParserService.RemoveProjectContentForRemovedProject(project); ParserService.RemoveProjectContentForRemovedProject(project);
OnProjectRemoved(new ProjectEventArgs(project));
project.Dispose(); project.Dispose();
} }
if (folder is ISolutionFolderContainer) { if (folder is ISolutionFolderContainer) {
@ -661,6 +662,12 @@ namespace ICSharpCode.SharpDevelop.Project
ProjectAdded(null, e); ProjectAdded(null, e);
} }
} }
static void OnProjectRemoved(ProjectEventArgs e)
{
if (ProjectRemoved != null) {
ProjectRemoved(null, e);
}
}
internal static void OnProjectCreated(ProjectEventArgs e) internal static void OnProjectCreated(ProjectEventArgs e)
{ {
if (ProjectCreated != null) { if (ProjectCreated != null) {
@ -682,6 +689,15 @@ namespace ICSharpCode.SharpDevelop.Project
/// Is raised when a new or existing project is added to the solution. /// Is raised when a new or existing project is added to the solution.
/// </summary> /// </summary>
public static event ProjectEventHandler ProjectAdded; public static event ProjectEventHandler ProjectAdded;
/// <summary>
/// Is raised when a project is removed from the solution.
/// </summary>
public static event ProjectEventHandler ProjectRemoved;
/// <summary>
/// Is raised when a solution folder is removed from the solution.
/// This might remove multiple projects from the solution.
/// </summary>
public static event SolutionFolderEventHandler SolutionFolderRemoved; public static event SolutionFolderEventHandler SolutionFolderRemoved;
public static event EventHandler<BuildEventArgs> BuildStarted; public static event EventHandler<BuildEventArgs> BuildStarted;

Loading…
Cancel
Save