From 139d2f96b46276a4ac395fc9060555f6ce3e7504 Mon Sep 17 00:00:00 2001 From: PeterForstmeier Date: Sun, 16 Sep 2012 20:11:01 +0200 Subject: [PATCH] Cpp Binding, cleanup ApplicationOptions --- .../CppBinding/Project/ApplicationOptions.cs | 117 +++++++++--------- .../Project/ApplicationOptions.xaml | 1 + .../ProjectOptions/ApplicationSettings.xaml | 5 +- .../ApplicationSettings.xaml.cs | 1 + 4 files changed, 60 insertions(+), 64 deletions(-) diff --git a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs index 61bfa61ff4..38cf099e5a 100644 --- a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs +++ b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs @@ -31,57 +31,19 @@ namespace ICSharpCode.CppBinding.Project private const string iconsfilter = "${res:SharpDevelop.FileFilter.Icons}|*.ico|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; private const string manifestFilter = "${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.ManifestFiles}|*.manifest|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; private const string win32filter = "Win32 Resource files|*.res|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; - MSBuildBasedProject project; public ApplicationOptions() { InitializeComponent(); + this.DataContext = this; } - #region Initialize - - private void Initialize() - { - - foreach (IClass c in GetPossibleStartupObjects(project)) { - startupObjectComboBox.Items.Add(c.FullyQualifiedName); - } - - //this.outputTypeComboBox.SelectedValue = OutputType.Value.ToString(); - - SetOutputTypeCombo(); - - FillManifestCombo(); - - // embedding manifests requires the project to target MSBuild 3.5 or higher - project_MinimumSolutionVersionChanged(null, null); - // re-evluate 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. - project.MinimumSolutionVersionChanged += project_MinimumSolutionVersionChanged; - - projectFolderTextBox.Text = project.Directory; - projectFileTextBox.Text = Path.GetFileName(project.FileName); - - //OptionBinding - RefreshStartupObjectEnabled(this, EventArgs.Empty); - RefreshOutputNameTextBox(this, null); - - //SetApplicationIcon(); - this.applicationIconTextBox.Text = GetApplicationIconPathFromResourceScripts(); - ApplicationIconTextBox_TextChanged(this,null); - IsDirty = false; - this.applicationIconTextBox.TextChanged += ApplicationIconTextBox_TextChanged; - - this.startupObjectComboBox.SelectionChanged += (s,e) => {IsDirty = true;}; - this.outputTypeComboBox.SelectionChanged += OutputTypeComboBox_SelectionChanged; - } - - + void SetOutputTypeCombo() { - MSBuildItemDefinitionGroup group = new MSBuildItemDefinitionGroup(project, project.ActiveConfiguration, project.ActivePlatform); + MSBuildItemDefinitionGroup group = new MSBuildItemDefinitionGroup(base.Project, base.Project.ActiveConfiguration, base.Project.ActivePlatform); string subsystem = group.GetElementMetadata("Link", "SubSystem"); - string configurationType = project.GetEvaluatedProperty("ConfigurationType"); + string configurationType = base.Project.GetEvaluatedProperty("ConfigurationType"); OutputType validOutputType = ConfigurationTypeToOutputType(configurationType, subsystem); this.outputTypeComboBox.SelectedIndex = Array.IndexOf((OutputType[])Enum.GetValues(typeof(OutputType)), validOutputType); } @@ -91,7 +53,7 @@ namespace ICSharpCode.CppBinding.Project { applicationManifestComboBox.Items.Add(StringParser.Parse("${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.EmbedDefault}")); applicationManifestComboBox.Items.Add(StringParser.Parse("${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.DoNotEmbedManifest}")); - foreach (string fileName in Directory.GetFiles(project.Directory, "*.manifest")) { + foreach (string fileName in Directory.GetFiles(base.Project.Directory, "*.manifest")) { applicationManifestComboBox.Items.Add(Path.GetFileName(fileName)); } applicationManifestComboBox.Items.Add(StringParser.Parse("<${res:Global.CreateButtonText}...>")); @@ -103,12 +65,10 @@ namespace ICSharpCode.CppBinding.Project void project_MinimumSolutionVersionChanged(object sender, EventArgs e) { // embedding manifests requires the project to target MSBuild 3.5 or higher - applicationManifestComboBox.IsEnabled = project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008; + applicationManifestComboBox.IsEnabled = base.Project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008; } - #endregion - #region Properties public ProjectProperty AssemblyName { @@ -149,13 +109,48 @@ namespace ICSharpCode.CppBinding.Project #region overrides - protected override void Load(MSBuildBasedProject project, string configuration, string platform) + protected override void Initialize() { - base.Load(project, configuration, platform); - this.project = project; - Initialize(); + base.Initialize(); + + foreach (IClass c in GetPossibleStartupObjects(base.Project)) { + startupObjectComboBox.Items.Add(c.FullyQualifiedName); + } + + SetOutputTypeCombo(); + + FillManifestCombo(); + + // embedding manifests requires the project to target MSBuild 3.5 or higher + project_MinimumSolutionVersionChanged(null, null); + // re-evluate 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. + base.Project.MinimumSolutionVersionChanged += project_MinimumSolutionVersionChanged; + + projectFolderTextBox.Text = base.Project.Directory; + projectFileTextBox.Text = Path.GetFileName(base.Project.FileName); + + //OptionBinding + RefreshStartupObjectEnabled(this, EventArgs.Empty); + RefreshOutputNameTextBox(this, null); + + //SetApplicationIcon(); + this.applicationIconTextBox.Text = GetApplicationIconPathFromResourceScripts(); + ApplicationIconTextBox_TextChanged(this,null); + + this.applicationIconTextBox.TextChanged += ApplicationIconTextBox_TextChanged; + + this.startupObjectComboBox.SelectionChanged += (s,e) => {IsDirty = true;}; + this.outputTypeComboBox.SelectionChanged += OutputTypeComboBox_SelectionChanged; + IsDirty = false; } + public override void Dispose() + { + base.Project.MinimumSolutionVersionChanged -= project_MinimumSolutionVersionChanged; + base.Dispose(); + } + protected override bool Save(MSBuildBasedProject project, string configuration, string platform) { @@ -180,8 +175,8 @@ namespace ICSharpCode.CppBinding.Project OutputType outputType = values[this.outputTypeComboBox.SelectedIndex]; string subsystem = OutputTypeToSubsystem(outputType); - MSBuildItemDefinitionGroup group = new MSBuildItemDefinitionGroup(project, - project.ActiveConfiguration, project.ActivePlatform); + MSBuildItemDefinitionGroup group = new MSBuildItemDefinitionGroup(base.Project, + base.Project.ActiveConfiguration, base.Project.ActivePlatform); group.SetElementMetadata("Link", "SubSystem", subsystem); return OutputTypeToConfigurationType(outputType); @@ -292,7 +287,7 @@ namespace ICSharpCode.CppBinding.Project string GetApplicationIconPathFromResourceScripts() { foundIconEntry = null; iconResourceScriptPath = null; - IEnumerable resourceScripts = project.Items.Where( + IEnumerable resourceScripts =base.Project .Items.Where( item => item is FileProjectItem && ((FileProjectItem)item).BuildAction == "ResourceCompile"); // search in all resource scripts, but due to limitation in resource compiler, only one of them can contain icons @@ -326,7 +321,7 @@ namespace ICSharpCode.CppBinding.Project } else { - iconResourceScriptPath = AddResourceScriptToProject(project, DEFAULT_RC_NAME); + iconResourceScriptPath = AddResourceScriptToProject(base.Project, DEFAULT_RC_NAME); rc = new ResourceScript(); newIconId = DEFAULT_ICON_ID; } @@ -352,10 +347,10 @@ namespace ICSharpCode.CppBinding.Project void ApplicationIconTextBox_TextChanged(object sender, TextChangedEventArgs e) { - if (project != null) { + if (base.Project != null) { if(FileUtility.IsValidPath(this.applicationIconTextBox.Text)) { - string appIconPath = Path.Combine(project.Directory, this.applicationIconTextBox.Text); + string appIconPath = Path.Combine(base.Project.Directory, this.applicationIconTextBox.Text); Console.WriteLine(appIconPath); var b = File.Exists(appIconPath); if (File.Exists(appIconPath)) { @@ -384,7 +379,6 @@ namespace ICSharpCode.CppBinding.Project } } } - } #endregion @@ -398,6 +392,7 @@ namespace ICSharpCode.CppBinding.Project } else if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 1) { BrowseForManifest(); } + IsDirty = true; } @@ -408,7 +403,7 @@ namespace ICSharpCode.CppBinding.Project void CreateManifest() { - string manifestFile = Path.Combine(project.Directory, "app.manifest"); + string manifestFile = Path.Combine(base.Project.Directory, "app.manifest"); if (!File.Exists(manifestFile)) { string defaultManifest; using (Stream stream = typeof(ApplicationSettings).Assembly.GetManifestResourceStream("Resources.DefaultManifest.manifest")) { @@ -423,10 +418,10 @@ namespace ICSharpCode.CppBinding.Project FileService.FireFileCreated(manifestFile, false); } - if (!project.IsFileInProject(manifestFile)) { - FileProjectItem newItem = new FileProjectItem(project, ItemType.None); + if (!base.Project.IsFileInProject(manifestFile)) { + FileProjectItem newItem = new FileProjectItem(base.Project, ItemType.None); newItem.Include = "app.manifest"; - ProjectService.AddProjectItem(project, newItem); + ProjectService.AddProjectItem(base.Project, newItem); ProjectBrowserPad.RefreshViewAsync(); } diff --git a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.xaml b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.xaml index 7fb93e9907..173375a2ca 100644 --- a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.xaml +++ b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.xaml @@ -97,6 +97,7 @@ diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml index 2fc812be35..f4357b9f35 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml @@ -9,9 +9,8 @@ xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:optionpanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels" xmlns:project="clr-namespace:ICSharpCode.SharpDevelop.Project"> - + + diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs index dc4df00af8..d9b0d17a88 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs @@ -282,6 +282,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels } else if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 1) { BrowseForFile(ApplicationManifest, manifestFilter); } + IsDirty = true; } void CreateManifest()