diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
4 files changed, 155 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/ExtensionModel/GlobalOptionsDialog.addin.xml b/main/src/core/MonoDevelop.Ide/ExtensionModel/GlobalOptionsDialog.addin.xml index 4cac3efd8d..e986a87a30 100644 --- a/main/src/core/MonoDevelop.Ide/ExtensionModel/GlobalOptionsDialog.addin.xml +++ b/main/src/core/MonoDevelop.Ide/ExtensionModel/GlobalOptionsDialog.addin.xml @@ -38,6 +38,7 @@ <Section id = "VersionControl" _label = "Version Control" /> <Section id = "Other" _label = "Other"> + <Section id = "SdkLocations" _label = "SDK Locations" /> <Section id = "MonoDevelopMaintenance" _label = "MonoDevelop Maintenance" class = "MonoDevelop.Ide.Gui.OptionPanels.MaintenanceOptionsPanel" /> </Section> </Extension> diff --git a/main/src/core/MonoDevelop.Ide/Makefile.am b/main/src/core/MonoDevelop.Ide/Makefile.am index cee4550f5d..877e144c51 100644 --- a/main/src/core/MonoDevelop.Ide/Makefile.am +++ b/main/src/core/MonoDevelop.Ide/Makefile.am @@ -487,6 +487,7 @@ FILES = \ MonoDevelop.Ide.Gui.OptionPanels/LoadSavePanel.cs \ MonoDevelop.Ide.Gui.OptionPanels/MaintenanceOptionsPanel.cs \ MonoDevelop.Ide.Gui.OptionPanels/MonoRuntimePanel.cs \ + MonoDevelop.Ide.Gui.OptionPanels/SdkLocationPanel.cs \ MonoDevelop.Ide.Gui.OptionPanels/TasksOptionsPanel.cs \ MonoDevelop.Ide.Gui.OptionPanels/TextStylePolicyPanel.cs \ MonoDevelop.Ide.Gui.Pads.ClassPad/ClassBrowserPad.cs \ diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/SdkLocationPanel.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/SdkLocationPanel.cs new file mode 100644 index 0000000000..93d8623307 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/SdkLocationPanel.cs @@ -0,0 +1,152 @@ +// +// SdkLocationPanel.cs +// +// Author: +// Michael Hutchinson <mhutch@xamarin.com> +// +// Copyright (c) 2011 Xamarin Inc. (http://xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using Gtk; +using MonoDevelop.Components; +using MonoDevelop.Core; +using MonoDevelop.Ide.Gui.Dialogs; + +namespace MonoDevelop.Ide.Gui.OptionPanels +{ + /// <summary> + /// Panel that allows the user to specify the location of an SDK. + /// </summary> + public abstract class SdkLocationPanel : OptionsPanel + { + SdkLocationWidget w; + + public override Widget CreatePanelWidget () + { + return w = new SdkLocationWidget (this); + } + + public override void ApplyChanges () + { + w.ApplyChanges (); + } + + /// <summary> + /// The panel's header label. + /// </summary> + public abstract string Label { get; } + + /// <summary> + /// The default SDK location that wil be used if the value is blank. + /// </summary> + public abstract FilePath DefaultSdkLocation { get; } + + /// <summary> + /// Check whether the SDK exists at a location. + /// </summary> + public abstract bool ValidateSdkLocation (FilePath location); + + /// <summary> + /// Loads the SDK location setting. A null value means that the default should be used. + /// </summary> + public abstract FilePath LoadSdkLocationSetting (); + + /// <summary> + /// Saves the SDK location setting. A null value means that the default should be used. + /// </summary> + public abstract void SaveSdkLocationSetting (FilePath location); + } + + class SdkLocationWidget : VBox + { + FolderEntry locationEntry = new FolderEntry (); + Label messageLabel = new Label (); + Image messageIcon = new Image (); + SdkLocationPanel panel; + + public SdkLocationWidget (SdkLocationPanel panel) : base (false, 12) + { + this.panel = panel; + + this.PackStart (new Label () { + Markup = "<b>" + GLib.Markup.EscapeText (panel.Label) + "</b>", + Xalign = 0f, + }); + var alignment = new Alignment (0f, 0f, 1f, 1f) { LeftPadding = 24 }; + this.PackStart (alignment); + var vbox = new VBox (false , 6); + var locationBox = new HBox (false, 6); + var messageBox = new HBox (false, 6); + alignment.Add (vbox); + vbox.PackStart (messageBox, false, false, 0); + vbox.PackStart (locationBox, false, false, 0); + locationBox.PackStart (new Label (GettextCatalog.GetString ("Location:")), false, false, 0); + locationBox.PackStart (locationEntry, true, true, 0); + messageBox.PackStart (messageIcon, false, false, 0); + messageBox.PackStart (messageLabel, true, true, 0); + messageLabel.Xalign = 0f; + + string location = panel.LoadSdkLocationSetting (); + locationEntry.Path = location ?? ""; + + locationEntry.PathChanged += delegate { + Validate (); + }; + Validate (); + ShowAll (); + } + + void Validate () + { + FilePath location = CleanPath (locationEntry.Path); + if (!location.IsNullOrEmpty) { + if (panel.ValidateSdkLocation (location)) { + messageLabel.Text = GettextCatalog.GetString ("SDK found at specified location."); + messageIcon.Stock = Gtk.Stock.Apply; + } else { + messageLabel.Text = GettextCatalog.GetString ("No SDK found at specified location."); + messageIcon.Stock = Gtk.Stock.Cancel; + } + } else if (panel.ValidateSdkLocation (panel.DefaultSdkLocation)) { + messageLabel.Text = GettextCatalog.GetString ("SDK found at default location."); + messageIcon.Stock = Gtk.Stock.Apply; + } else { + messageLabel.Text = GettextCatalog.GetString ("No SDK found at default location."); + messageIcon.Stock = Gtk.Stock.Cancel; + } + } + + string CleanPath (string path) + { + if (string.IsNullOrEmpty (path)) + return null; + path = System.IO.Path.GetFullPath (path); + if (path == panel.DefaultSdkLocation) + return null; + return path; + } + + public void ApplyChanges () + { + panel.SaveSdkLocationSetting (CleanPath (locationEntry.Path)); + } + } +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj index 5f98f2c5bb..453063d4b1 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj @@ -1456,6 +1456,7 @@ <Compile Include="MonoDevelop.Ide.Updater\IUpdateHandler.cs" /> <Compile Include="MonoDevelop.Ide.Updater\AddinsUpdateHandler.cs" /> <Compile Include="MonoDevelop.Ide.Updater\UpdateCheckHandler.cs" /> + <Compile Include="MonoDevelop.Ide.Gui.OptionPanels\SdkLocationPanel.cs" /> </ItemGroup> <ItemGroup> <None Include="ChangeLog" /> |