PageRenderTime 26ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/icsharpcode/SharpDevelop
C# | 270 lines | 226 code | 27 blank | 17 comment | 24 complexity | 7623998a028c46b812b910a38c4946f7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, CPL-1.0, LGPL-2.1
  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Windows.Forms;
  23. using ICSharpCode.Core;
  24. using ICSharpCode.SharpDevelop.Project;
  25. using ICSharpCode.SharpDevelop.Project.Converter;
  26. using StringPair = System.Collections.Generic.KeyValuePair<string, string>;
  27. namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
  28. {
  29. [Obsolete("XML Forms are obsolete")]
  30. public class AbstractBuildOptions : AbstractXmlFormsProjectOptionPanel
  31. {
  32. protected void InitBaseIntermediateOutputPath()
  33. {
  34. helper.BindString(Get<TextBox>("baseIntermediateOutputPath"),
  35. "BaseIntermediateOutputPath",
  36. TextBoxEditMode.EditRawProperty,
  37. delegate { return @"obj\"; }
  38. ).CreateLocationButton("baseIntermediateOutputPathTextBox");
  39. ConnectBrowseFolder("baseIntermediateOutputPathBrowseButton", "baseIntermediateOutputPathTextBox",
  40. "${res:Dialog.Options.PrjOptions.Configuration.FolderBrowserDescription}",
  41. TextBoxEditMode.EditRawProperty);
  42. }
  43. protected void InitIntermediateOutputPath()
  44. {
  45. ConfigurationGuiBinding binding = helper.BindString(
  46. Get<TextBox>("intermediateOutputPath"),
  47. "IntermediateOutputPath",
  48. TextBoxEditMode.EditRawProperty,
  49. delegate {
  50. return Path.Combine(helper.GetProperty("BaseIntermediateOutputPath", @"obj\", true),
  51. helper.Configuration);
  52. }
  53. );
  54. binding.DefaultLocation = PropertyStorageLocations.ConfigurationSpecific;
  55. binding.CreateLocationButton("intermediateOutputPathTextBox");
  56. ConnectBrowseFolder("intermediateOutputPathBrowseButton",
  57. "intermediateOutputPathTextBox",
  58. "${res:Dialog.Options.PrjOptions.Configuration.FolderBrowserDescription}",
  59. TextBoxEditMode.EditRawProperty);
  60. }
  61. protected void InitOutputPath()
  62. {
  63. helper.BindString("outputPathTextBox", "OutputPath", TextBoxEditMode.EditRawProperty)
  64. .CreateLocationButton("outputPathTextBox");
  65. ConnectBrowseFolder("outputPathBrowseButton", "outputPathTextBox", "${res:Dialog.Options.PrjOptions.Configuration.FolderBrowserDescription}", TextBoxEditMode.EditRawProperty);
  66. }
  67. protected void InitXmlDoc()
  68. {
  69. ConfigurationGuiBinding b;
  70. b = helper.BindString("xmlDocumentationTextBox", "DocumentationFile", TextBoxEditMode.EditRawProperty);
  71. b.CreateLocationButton("xmlDocumentationCheckBox");
  72. helper.Loaded += XmlDocHelperLoaded;
  73. XmlDocHelperLoaded(null, null);
  74. }
  75. void XmlDocHelperLoaded(object sender, EventArgs e)
  76. {
  77. Get<CheckBox>("xmlDocumentation").CheckedChanged -= UpdateXmlEnabled;
  78. Get<CheckBox>("xmlDocumentation").Checked = Get<TextBox>("xmlDocumentation").Text.Length > 0;
  79. Get<CheckBox>("xmlDocumentation").CheckedChanged += UpdateXmlEnabled;
  80. Get<TextBox>("xmlDocumentation").Enabled = Get<CheckBox>("xmlDocumentation").Checked;
  81. }
  82. void UpdateXmlEnabled(object sender, EventArgs e)
  83. {
  84. Get<TextBox>("xmlDocumentation").Enabled = Get<CheckBox>("xmlDocumentation").Checked;
  85. if (Get<CheckBox>("xmlDocumentation").Checked) {
  86. if (Get<TextBox>("xmlDocumentation").Text.Length == 0) {
  87. Get<TextBox>("xmlDocumentation").Text = MSBuildInternals.Escape(
  88. Path.ChangeExtension(FileUtility.GetRelativePath(baseDirectory, project.OutputAssemblyFullPath),
  89. ".xml"));
  90. }
  91. } else {
  92. Get<TextBox>("xmlDocumentation").Text = "";
  93. }
  94. }
  95. protected void InitWarnings()
  96. {
  97. ConfigurationGuiBinding b;
  98. b = helper.BindStringEnum("warningLevelComboBox", "WarningLevel",
  99. "4",
  100. new StringPair("0", "0"),
  101. new StringPair("1", "1"),
  102. new StringPair("2", "2"),
  103. new StringPair("3", "3"),
  104. new StringPair("4", "4"));
  105. ChooseStorageLocationButton locationButton = b.CreateLocationButtonInPanel("warningsGroupBox");
  106. b = helper.BindString("suppressWarningsTextBox", "NoWarn", TextBoxEditMode.EditEvaluatedProperty);
  107. b.RegisterLocationButton(locationButton);
  108. b = new WarningsAsErrorsBinding(this);
  109. helper.AddBinding("TreatWarningsAsErrors", b);
  110. locationButton = b.CreateLocationButtonInPanel("treatWarningsAsErrorsGroupBox");
  111. b = helper.BindString("specificWarningsTextBox", "WarningsAsErrors", TextBoxEditMode.EditEvaluatedProperty); // must be saved AFTER TreatWarningsAsErrors
  112. b.RegisterLocationButton(locationButton);
  113. EventHandler setDirty = delegate {
  114. helper.IsDirty = true;
  115. };
  116. Get<RadioButton>("none").CheckedChanged += setDirty;
  117. Get<RadioButton>("specificWarnings").CheckedChanged += setDirty;
  118. Get<RadioButton>("all").CheckedChanged += setDirty;
  119. Get<RadioButton>("specificWarnings").CheckedChanged += new EventHandler(UpdateWarningChecked);
  120. UpdateWarningChecked(this, EventArgs.Empty);
  121. }
  122. void UpdateWarningChecked(object sender, EventArgs e)
  123. {
  124. Get<TextBox>("specificWarnings").Enabled = Get<RadioButton>("specificWarnings").Checked;
  125. }
  126. protected class WarningsAsErrorsBinding : ConfigurationGuiBinding
  127. {
  128. RadioButton none, specific, all;
  129. Control specificWarningsTextBox;
  130. public WarningsAsErrorsBinding(AbstractXmlFormsProjectOptionPanel panel)
  131. {
  132. this.none = panel.Get<RadioButton>("none");
  133. this.specific = panel.Get<RadioButton>("specificWarnings");
  134. this.all = panel.Get<RadioButton>("all");
  135. specificWarningsTextBox = panel.ControlDictionary["specificWarningsTextBox"];
  136. }
  137. public override void Load()
  138. {
  139. if (bool.Parse(Get("false"))) {
  140. all.Checked = true;
  141. } else {
  142. if (this.Helper.GetProperty("WarningsAsErrors", "", true).Length > 0) {
  143. specific.Checked = true;
  144. } else {
  145. none.Checked = true;
  146. }
  147. }
  148. }
  149. public override bool Save()
  150. {
  151. if (none.Checked) {
  152. specificWarningsTextBox.Text = "";
  153. }
  154. if (all.Checked) {
  155. Set("true");
  156. } else {
  157. Set("false");
  158. }
  159. return true;
  160. }
  161. }
  162. ConfigurationGuiBinding debugInfoBinding;
  163. protected ChooseStorageLocationButton advancedLocationButton;
  164. protected void InitDebugInfo()
  165. {
  166. debugInfoBinding = helper.BindEnum<DebugSymbolType>("debugInfoComboBox", "DebugType");
  167. debugInfoBinding.CreateLocationButton("debugInfoLabel");
  168. DebugSymbolsLoaded(null, null);
  169. helper.Loaded += DebugSymbolsLoaded;
  170. helper.Saved += DebugSymbolsSave;
  171. }
  172. protected void InitAdvanced()
  173. {
  174. ConfigurationGuiBinding b;
  175. b = helper.BindBoolean("registerCOMInteropCheckBox", "RegisterForComInterop", false);
  176. b.DefaultLocation = PropertyStorageLocations.PlatformSpecific;
  177. advancedLocationButton = b.CreateLocationButtonInPanel("platformSpecificOptionsPanel");
  178. b = helper.BindStringEnum("generateSerializationAssemblyComboBox", "GenerateSerializationAssemblies",
  179. "Auto",
  180. new StringPair("Off", "${res:Dialog.ProjectOptions.Build.Off}"),
  181. new StringPair("On", "${res:Dialog.ProjectOptions.Build.On}"),
  182. new StringPair("Auto", "${res:Dialog.ProjectOptions.Build.Auto}"));
  183. b.DefaultLocation = PropertyStorageLocations.PlatformSpecific;
  184. b.RegisterLocationButton(advancedLocationButton);
  185. b = helper.BindHexadecimal(Get<TextBox>("dllBaseAddress"), "BaseAddress", 0x400000);
  186. b.DefaultLocation = PropertyStorageLocations.PlatformSpecific;
  187. b.RegisterLocationButton(advancedLocationButton);
  188. b = CreatePlatformTarget();
  189. b.RegisterLocationButton(advancedLocationButton);
  190. }
  191. protected ConfigurationGuiBinding CreatePlatformTarget()
  192. {
  193. ConfigurationGuiBinding b;
  194. b = helper.BindStringEnum("targetCpuComboBox", "PlatformTarget",
  195. "AnyCPU",
  196. new StringPair("AnyCPU", "${res:Dialog.ProjectOptions.Build.TargetCPU.Any}"),
  197. new StringPair("x86", "${res:Dialog.ProjectOptions.Build.TargetCPU.x86}"),
  198. new StringPair("x64", "${res:Dialog.ProjectOptions.Build.TargetCPU.x64}"),
  199. new StringPair("Itanium", "${res:Dialog.ProjectOptions.Build.TargetCPU.Itanium}"));
  200. b.DefaultLocation = PropertyStorageLocations.PlatformSpecific;
  201. return b;
  202. }
  203. void DebugSymbolsLoaded(object sender, EventArgs e)
  204. {
  205. PropertyStorageLocations location;
  206. helper.GetProperty("DebugType", "", true, out location);
  207. if (location == PropertyStorageLocations.Unknown) {
  208. bool debug = helper.GetProperty("DebugSymbols", false, true, out location);
  209. if (location != PropertyStorageLocations.Unknown) {
  210. debugInfoBinding.Location = location;
  211. helper.SetProperty("DebugType", debug ? DebugSymbolType.Full : DebugSymbolType.None, true, location);
  212. debugInfoBinding.Load();
  213. }
  214. }
  215. }
  216. void DebugSymbolsSave(object sender, EventArgs e)
  217. {
  218. if ((DebugSymbolType)Get<ComboBox>("debugInfo").SelectedIndex == DebugSymbolType.Full) {
  219. helper.SetProperty("DebugSymbols", "true", true, debugInfoBinding.Location);
  220. } else {
  221. helper.SetProperty("DebugSymbols", "false", true, debugInfoBinding.Location);
  222. }
  223. }
  224. protected void InitTargetFramework()
  225. {
  226. Button projectUpdateButton = ControlDictionary["projectUpdateButton"] as Button;
  227. if (projectUpdateButton != null) {
  228. projectUpdateButton.Click += delegate {
  229. UpgradeViewContent.Show(project.ParentSolution).Select(project as IUpgradableProject);
  230. };
  231. }
  232. ComboBox targetFrameworkComboBox = ControlDictionary["targetFrameworkComboBox"] as ComboBox;
  233. if (targetFrameworkComboBox != null) {
  234. targetFrameworkComboBox.Enabled = false;
  235. TargetFramework fx = ((IUpgradableProject)project).CurrentTargetFramework;
  236. if (fx != null) {
  237. targetFrameworkComboBox.Items.Add(fx.DisplayName);
  238. targetFrameworkComboBox.SelectedIndex = 0;
  239. }
  240. }
  241. }
  242. }
  243. }