PageRenderTime 36ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/NewConfigurationDialog.cs

http://github.com/mono/monodevelop
C# | 197 lines | 141 code | 31 blank | 25 comment | 16 complexity | 62edca0760242ac42defdd67e92077fb MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, CC-BY-SA-3.0, MIT, LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. //
  2. // NewConfigurationDialog.cs
  3. //
  4. // Author:
  5. // Cody Russell <coruss@microsoft.com>
  6. //
  7. // Copyright (c) 2019 Microsoft
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.Collections.Generic;
  28. using MonoDevelop.Projects;
  29. using MonoDevelop.Core;
  30. using Xwt;
  31. using MonoDevelop.Components;
  32. namespace MonoDevelop.Ide.Gui.Dialogs
  33. {
  34. class NewConfigurationDialog : Xwt.Dialog
  35. {
  36. ItemConfigurationCollection<ItemConfiguration> configurations;
  37. ComboBoxEntry comboName;
  38. ComboBoxEntry comboPlatform;
  39. CheckBox createChildrenCheck;
  40. DialogButton okButton;
  41. InformationPopoverWidget popover;
  42. public string ConfigName {
  43. get {
  44. string plat = MultiConfigItemOptionsPanel.GetPlatformId (comboPlatform.TextEntry.Text.Trim ());
  45. if (string.IsNullOrEmpty (plat))
  46. return comboName.TextEntry.Text.Trim ();
  47. else
  48. return comboName.TextEntry.Text.Trim () + "|" + plat;
  49. }
  50. set {
  51. int i = value.LastIndexOf ('|');
  52. if (i == -1) {
  53. comboName.TextEntry.Text = value;
  54. comboPlatform.TextEntry.Text = string.Empty;
  55. } else {
  56. comboName.TextEntry.Text = value.Substring (0, i);
  57. comboPlatform.TextEntry.Text = MultiConfigItemOptionsPanel.GetPlatformName (value.Substring (i + 1));
  58. }
  59. }
  60. }
  61. public bool CreateChildren {
  62. get => createChildrenCheck.Active;
  63. }
  64. public NewConfigurationDialog (ItemConfigurationCollection<ItemConfiguration> configurations)
  65. : this (null, configurations)
  66. {
  67. }
  68. public NewConfigurationDialog (IConfigurationTarget item, ItemConfigurationCollection<ItemConfiguration> configurations)
  69. {
  70. Build ();
  71. this.configurations = configurations;
  72. SetupConfigs (item);
  73. comboName.SetFocus ();
  74. }
  75. void Build ()
  76. {
  77. Padding = 6;
  78. Resizable = false;
  79. Title = GettextCatalog.GetString ("New Configuration");
  80. var mainVBox = new VBox () { Spacing = 6 };
  81. var table = new Table { DefaultColumnSpacing = 6, DefaultRowSpacing = 6 };
  82. var label = new Label { Text = GettextCatalog.GetString ("Name:") };
  83. comboName = new ComboBoxEntry ();
  84. comboName.TextEntry.Changed += ComboTextChanged;
  85. comboName.Accessible.LabelWidget = label;
  86. table.Add (label, 0, 0);
  87. table.Add (comboName, 1, 0);
  88. popover = new InformationPopoverWidget ();
  89. popover.Severity = Tasks.TaskSeverity.Warning;
  90. popover.Accessible.LabelWidget = label;
  91. popover.Visible = false;
  92. popover.CanGetFocus = true;
  93. table.Add (popover, 2, 0);
  94. label = new Label { Text = GettextCatalog.GetString ("Platform:") };
  95. comboPlatform = new ComboBoxEntry ();
  96. comboPlatform.TextEntry.Changed += ComboTextChanged;
  97. comboPlatform.Accessible.LabelWidget = label;
  98. comboPlatform.WidthRequest = 250;
  99. table.Add (label, 0, 1);
  100. table.Add (comboPlatform, 1, 1);
  101. createChildrenCheck = new CheckBox { Label = GettextCatalog.GetString ("Create configurations for all solution items") };
  102. mainVBox.PackStart (table, true, true);
  103. mainVBox.PackStart (createChildrenCheck, true);
  104. var cancelButton = new DialogButton (Command.Cancel);
  105. Buttons.Add (cancelButton);
  106. okButton = new DialogButton (Command.Ok);
  107. Buttons.Add (okButton);
  108. DefaultCommand = okButton.Command;
  109. Content = mainVBox;
  110. ValidateText ();
  111. }
  112. void ComboTextChanged (object sender, EventArgs e)
  113. {
  114. ValidateText ();
  115. }
  116. void ValidateText ()
  117. {
  118. var name = comboName.TextEntry.Text.Trim ();
  119. var isOk = false;
  120. if (name.Length == 0 || name.IndexOf ('|') != -1) {
  121. isOk = false;
  122. popover.Message = GettextCatalog.GetString ("Please enter a valid configuration name.");
  123. popover.Show ();
  124. } else if (configurations[ConfigName] != null) {
  125. isOk = false;
  126. popover.Message = GettextCatalog.GetString ("A configuration with the name '{0}' already exists.", ConfigName);
  127. popover.Show ();
  128. } else {
  129. isOk = true;
  130. popover.Hide ();
  131. }
  132. okButton.Sensitive = isOk;
  133. }
  134. protected override void Dispose (bool disposing)
  135. {
  136. base.Dispose (disposing);
  137. if (disposing) {
  138. comboName.TextEntry.Changed -= ComboTextChanged;
  139. comboPlatform.TextEntry.Changed -= ComboTextChanged;
  140. configurations = null;
  141. comboName = null;
  142. comboPlatform = null;
  143. createChildrenCheck = null;
  144. okButton = null;
  145. popover = null;
  146. }
  147. }
  148. void SetupConfigs (IConfigurationTarget item)
  149. {
  150. var configs = new HashSet<string> ();
  151. var platforms = new HashSet<string> ();
  152. foreach (var conf in configurations) {
  153. if (configs.Add (conf.Name))
  154. comboName.Items.Add (conf.Name);
  155. var plat = MultiConfigItemOptionsPanel.GetPlatformName (conf.Platform);
  156. if (platforms.Add (plat))
  157. comboPlatform.Items.Add (plat);
  158. }
  159. comboPlatform.TextEntry.Text = MultiConfigItemOptionsPanel.GetPlatformName ("");
  160. if (!(item is Solution)) {
  161. createChildrenCheck.Active = false;
  162. createChildrenCheck.Visible = false;
  163. }
  164. }
  165. }
  166. }