/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/CodeGenerationPanel.cs

https://github.com/directhex/monodevelop · C# · 85 lines · 49 code · 11 blank · 25 comment · 0 complexity · 5e9eb26bfe14c2f42ea9dcf09a3cfb27 MD5 · raw file

  1. //
  2. // CodeGenerationPanel.cs
  3. //
  4. // Author:
  5. // Mike Krüger <mikkrg@microsoft.com>
  6. //
  7. // Copyright (c) 2018 Microsoft Corporation. All rights reserved.
  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 Microsoft.CodeAnalysis;
  27. using Microsoft.CodeAnalysis.Editing;
  28. using MonoDevelop.Components;
  29. using MonoDevelop.Core;
  30. using MonoDevelop.Ide.Gui.Dialogs;
  31. using Xwt;
  32. namespace MonoDevelop.Refactoring
  33. {
  34. class CodeGenerationPanel : OptionsPanel
  35. {
  36. CodeGenerationPanelWidget widget;
  37. public override Control CreatePanelWidget ()
  38. {
  39. widget = new CodeGenerationPanelWidget (LanguageNames.CSharp);
  40. return (Gtk.Widget)Toolkit.CurrentEngine.GetNativeWidget (widget);
  41. }
  42. public override void ApplyChanges ()
  43. {
  44. widget.ApplyChanges ();
  45. }
  46. class CodeGenerationPanelWidget : Xwt.VBox
  47. {
  48. string languageName;
  49. CheckBox placeSystemNamespaceFirst;
  50. CheckBox separateImportDirectiveGroups;
  51. ConfigurationProperty<bool> placeSystemNamespaceFirstProp;
  52. ConfigurationProperty<bool> separateImportDirectiveGroupsProp;
  53. public CodeGenerationPanelWidget (string languageName)
  54. {
  55. this.languageName = languageName;
  56. placeSystemNamespaceFirstProp = Ide.IdeApp.Preferences.Roslyn.For (languageName).PlaceSystemNamespaceFirst;
  57. separateImportDirectiveGroupsProp = Ide.IdeApp.Preferences.Roslyn.For (languageName).PlaceSystemNamespaceFirst;
  58. var hBox = new HBox ();
  59. hBox.PackStart (new Label { Markup = GettextCatalog.GetString ("Organize Usings") });
  60. hBox.PackStart (new HSeparator (), true, true);
  61. this.PackStart (hBox);
  62. this.PackStart (placeSystemNamespaceFirst = new CheckBox (GettextCatalog.GetString ("Place 'System' directives first when sorting usings")));
  63. this.PackStart (separateImportDirectiveGroups = new CheckBox (GettextCatalog.GetString ("Separate using groups when sorting")));
  64. placeSystemNamespaceFirst.Active = placeSystemNamespaceFirstProp.Value;
  65. separateImportDirectiveGroups.Active = separateImportDirectiveGroupsProp.Value;
  66. }
  67. public void ApplyChanges ()
  68. {
  69. placeSystemNamespaceFirstProp.Value = placeSystemNamespaceFirst.Active;
  70. separateImportDirectiveGroupsProp.Value = separateImportDirectiveGroups.Active;
  71. }
  72. }
  73. }
  74. }