diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-07-06 23:26:09 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-07-07 02:22:13 +0400 |
commit | 09ee9363f2587d5ba3883f0b62edef2e9687b3a5 (patch) | |
tree | 13e6aac8dde9913dd315ed95c6d2094d005cb4ff /main | |
parent | 2acda47691d4be41cdcae69a7e15e9dac1b20c41 (diff) |
[MacDev] Configurable SDK path & detect Xcode 4
Diffstat (limited to 'main')
18 files changed, 430 insertions, 15 deletions
diff --git a/main/src/addins/MacPlatform/MacInterop/Cocoa.cs b/main/src/addins/MacPlatform/MacInterop/Cocoa.cs new file mode 100644 index 0000000000..2d08a5f56d --- /dev/null +++ b/main/src/addins/MacPlatform/MacInterop/Cocoa.cs @@ -0,0 +1,47 @@ +// +// Cocoa.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; + +namespace MonoDevelop.MacInterop +{ + public static class Cocoa + { + static bool inited; + static object lockObj = new object (); + + public static void InitMonoMac () + { + if (inited) + return; + lock (lockObj) { + if (inited) + return; + MonoMac.AppKit.NSApplication.Init (); + inited = true; + } + } + } +}
\ No newline at end of file diff --git a/main/src/addins/MacPlatform/MacInterop/GtkQuartz.cs b/main/src/addins/MacPlatform/MacInterop/GtkQuartz.cs index 1d4c020783..fbdcad9574 100644 --- a/main/src/addins/MacPlatform/MacInterop/GtkQuartz.cs +++ b/main/src/addins/MacPlatform/MacInterop/GtkQuartz.cs @@ -28,9 +28,9 @@ using System; using System.Runtime.InteropServices; using MonoMac.AppKit; -namespace MonoDevelop.Platform.Mac +namespace MonoDevelop.MacInterop { - static class GtkQuartz + public static class GtkQuartz { //this may be needed to work around focusing issues in GTK/Cocoa interop public static void FocusWindow (Gtk.Window widget) diff --git a/main/src/addins/MacPlatform/MacPlatform.addin.xml b/main/src/addins/MacPlatform/MacPlatform.addin.xml index 26b9653db6..c4d592cfc7 100644 --- a/main/src/addins/MacPlatform/MacPlatform.addin.xml +++ b/main/src/addins/MacPlatform/MacPlatform.addin.xml @@ -10,6 +10,8 @@ version = "2.6"> <Runtime> + <Import assembly="MonoMac.dll" /> + <ScanExclude path="MonoMac.dll" /> </Runtime> <Dependencies> diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 42874e01a1..c7c0982a54 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -68,8 +68,7 @@ namespace MonoDevelop.Platform.Mac //make sure the menu app name is correct even when running Mono 2.6 preview, or not running from the .app Carbon.SetProcessName ("MonoDevelop"); - timer.Trace ("Initializing NSApplication"); - MonoMac.AppKit.NSApplication.Init (); + MonoDevelop.MacInterop.Cocoa.InitMonoMac (); timer.Trace ("Installing App Event Handlers"); GlobalSetup (); diff --git a/main/src/addins/MacPlatform/MacPlatform.csproj b/main/src/addins/MacPlatform/MacPlatform.csproj index 3211da8a98..7e17277e4d 100644 --- a/main/src/addins/MacPlatform/MacPlatform.csproj +++ b/main/src/addins/MacPlatform/MacPlatform.csproj @@ -89,6 +89,7 @@ <Compile Include="MacInterop\LaunchServices.cs" /> <Compile Include="MacInterop\ProcessManager.cs" /> <Compile Include="MacInterop\Keychain.cs" /> + <Compile Include="MacInterop\Cocoa.cs" /> </ItemGroup> <ItemGroup> <None Include="ChangeLog" /> diff --git a/main/src/addins/MacPlatform/Makefile.am b/main/src/addins/MacPlatform/Makefile.am index 41039edf19..ffcb8cf831 100644 --- a/main/src/addins/MacPlatform/Makefile.am +++ b/main/src/addins/MacPlatform/Makefile.am @@ -37,6 +37,7 @@ FILES = \ MacInterop/AppleScript.cs \ MacInterop/ApplicationEvents.cs \ MacInterop/Carbon.cs \ + MacInterop/Cocoa.cs \ MacInterop/ComponentManager.cs \ MacInterop/CoreFoundation.cs \ MacInterop/GtkQuartz.cs \ diff --git a/main/src/addins/MonoDevelop.MacDev/AppleSdkSettings.cs b/main/src/addins/MonoDevelop.MacDev/AppleSdkSettings.cs new file mode 100644 index 0000000000..354bbda5e2 --- /dev/null +++ b/main/src/addins/MonoDevelop.MacDev/AppleSdkSettings.cs @@ -0,0 +1,141 @@ +// +// AppleSdkSettings.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 MonoDevelop.Core; +using MonoMac.Foundation; +using System.IO; + +namespace MonoDevelop.MacDev +{ + public static class AppleSdkSettings + { + const string SDK_KEY = "MonoDevelop.MacDev.AppleSdkRoot"; + internal const string DefaultRoot = "/Developer"; + static DateTime lastWritten; + + static string GetEnvLocation () + { + return Environment.GetEnvironmentVariable ("MD_APPLE_SDK_ROOT"); + } + + internal static bool ValidateSdkLocation (FilePath location) + { + return System.IO.File.Exists (location.Combine ("Library", "version.plist")); + } + + internal static void SetConfiguredSdkLocation (FilePath location) + { + if (location.IsNullOrEmpty || location == DefaultRoot) + location = null; + if (location == PropertyService.Get<string> (SDK_KEY)) + return; + PropertyService.Set (SDK_KEY, location); + if (GetEnvLocation () != null) { + Init (); + Changed (); + } + } + + internal static FilePath GetConfiguredSdkLocation () + { + return PropertyService.Get<string> (SDK_KEY, null); + } + + static void SetInvalid () + { + IsValid = false; + DTXcode = null; + IsXcode4 = false; + lastWritten = DateTime.MinValue; + } + + static AppleSdkSettings () + { + MonoDevelop.MacInterop.Cocoa.InitMonoMac (); + Init (); + } + + static void Init () + { + SetInvalid (); + + DeveloperRoot = Environment.GetEnvironmentVariable ("MD_APPLE_SDK_ROOT"); + if (DeveloperRoot.IsNullOrEmpty) { + DeveloperRoot = GetConfiguredSdkLocation (); + if (DeveloperRoot.IsNullOrEmpty) + DeveloperRoot = "/Developer"; + } + + if (!ValidateSdkLocation (DeveloperRoot)) + return; + + try { + var plist = XcodePath.Combine ("Contents", "Info.plist"); + if (!File.Exists (plist)) + return; + lastWritten = File.GetLastWriteTime (plist); + + using (var pool = new NSAutoreleasePool ()) { + var dict = NSDictionary.FromFile (plist); + var val = (NSString) dict.ObjectForKey (new NSString ("DTXcode")); + DTXcode = val.ToString (); + } + IsXcode4 = int.Parse (DTXcode) >= 0400; + IsValid = true; + } catch (Exception ex) { + LoggingService.LogError ("Error loading Xcode information for prefix '" + DeveloperRoot + "'", ex); + SetInvalid (); + } + } + + public static FilePath DeveloperRoot { get; private set; } + + public static FilePath XcodePath { + get { + return DeveloperRoot.Combine ("Applications", "Xcode.app"); + } + } + + public static void CheckChanged () + { + var plist = XcodePath.Combine ("Contents", "Info.plist"); + DateTime w = DateTime.MinValue; + if (File.Exists (plist)) + w = File.GetLastWriteTime (plist); + if (w != lastWritten) { + Init (); + Changed (); + } + } + + public static bool IsValid { get; private set; } + public static string DTXcode { get; private set; } + public static bool IsXcode4 { get; private set; } + + public static event Action Changed; + } +} diff --git a/main/src/addins/MonoDevelop.MacDev/AppleSdkSettingsPanel.cs b/main/src/addins/MonoDevelop.MacDev/AppleSdkSettingsPanel.cs new file mode 100644 index 0000000000..3e511bfba7 --- /dev/null +++ b/main/src/addins/MonoDevelop.MacDev/AppleSdkSettingsPanel.cs @@ -0,0 +1,59 @@ +// +// AppleSdkSettingsPanel.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 MonoDevelop.Core; +using MonoDevelop.Ide.Gui.OptionPanels; +using MonoMac.Foundation; + +namespace MonoDevelop.MacDev +{ + class AppleSdkSettingsPanel : SdkLocationPanel + { + public override string Label { + get { return GettextCatalog.GetString ("Apple SDK"); } + } + + public override FilePath DefaultSdkLocation { + get { return AppleSdkSettings.DefaultRoot; } + } + + public override bool ValidateSdkLocation (FilePath location) + { + return AppleSdkSettings.ValidateSdkLocation (location); + } + + public override FilePath LoadSdkLocationSetting () + { + return AppleSdkSettings.GetConfiguredSdkLocation (); + } + + public override void SaveSdkLocationSetting (FilePath location) + { + AppleSdkSettings.SetConfiguredSdkLocation (location); + } + } +}
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.MacDev/Makefile.am b/main/src/addins/MonoDevelop.MacDev/Makefile.am index 746781e821..886786e177 100644 --- a/main/src/addins/MonoDevelop.MacDev/Makefile.am +++ b/main/src/addins/MonoDevelop.MacDev/Makefile.am @@ -20,6 +20,8 @@ REFS = \ -r:System.Xml.Linq FILES = \ + AppleSdkSettings.cs \ + AppleSdkSettingsPanel.cs \ AssemblyInfo.cs \ MacBuildUtilities.cs \ MonoDevelop.MacDev.InterfaceBuilder/Collections.cs \ diff --git a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.addin.xml b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.addin.xml index 7828bbd91e..0969a88109 100644 --- a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.addin.xml +++ b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.addin.xml @@ -116,4 +116,7 @@ <CommandItem id = "MonoDevelop.Ide.Commands.EditCommands.Delete" /> </Extension> + <Extension path = "/MonoDevelop/Ide/GlobalOptionsDialog/Other/SdkLocations"> + <Panel id = "AppleSdkSettings" class="MonoDevelop.MacDev.AppleSdkSettingsPanel"/> + </Extension> </Addin>
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj index b86dc66ce6..57b6460133 100644 --- a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj +++ b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj @@ -123,6 +123,8 @@ <Compile Include="XcodeSyncing\XcodeSyncedItem.cs" /> <Compile Include="XcodeSyncing\XcodeSyncBackContext.cs" /> <Compile Include="XcodeSyncing\XcodeSyncContext.cs" /> + <Compile Include="AppleSdkSettingsPanel.cs" /> + <Compile Include="AppleSdkSettings.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.MacDev.addin.xml"> diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeInterfaceBuilderDisplayBinding.cs b/main/src/addins/MonoDevelop.MacDev/XcodeInterfaceBuilderDisplayBinding.cs index f660d9feb1..3e8b26e899 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeInterfaceBuilderDisplayBinding.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeInterfaceBuilderDisplayBinding.cs @@ -42,6 +42,9 @@ namespace MonoDevelop.MacDev public bool CanHandle (FilePath fileName, string mimeType, Project ownerProject) { + if (!AppleSdkSettings.IsXcode4) + return false; + if (ownerProject == null || !(ownerProject is IXcodeTrackedProject)) return false; if (mimeType == "application/vnd.apple-interface-builder") @@ -56,11 +59,10 @@ namespace MonoDevelop.MacDev class XcodeInterfaceBuilderDesktopApplication : DesktopApplication { - public const string XCODE_LOCATION = "/Developer/Applications/Xcode.app"; - IXcodeTrackedProject project; - public XcodeInterfaceBuilderDesktopApplication (IXcodeTrackedProject project) : base (XCODE_LOCATION, "Xcode Interface Builder", true) + public XcodeInterfaceBuilderDesktopApplication (IXcodeTrackedProject project) + : base (AppleSdkSettings.XcodePath, "Xcode Interface Builder", true) { this.project = project; } diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs index 5c03b2b715..b873188469 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs @@ -43,7 +43,6 @@ namespace MonoDevelop.MacDev.XcodeSyncing { class XcodeMonitor { - string xcodePath = XcodeInterfaceBuilderDesktopApplication.XCODE_LOCATION; FilePath originalProjectDir; int nextHackDir = 0; string name; @@ -184,14 +183,14 @@ namespace MonoDevelop.MacDev.XcodeSyncing public bool CheckRunning () { var appPathKey = new NSString ("NSApplicationPath"); - var appPathVal = new NSString (xcodePath); + var appPathVal = new NSString (AppleSdkSettings.XcodePath); return NSWorkspace.SharedWorkspace.LaunchedApplications.Any (app => appPathVal.Equals (app[appPathKey])); } public void SaveProject () { XC4Debug.Log ("Saving Xcode project"); - AppleScript.Run (XCODE_SAVE_IN_PATH, xcodePath, projectDir); + AppleScript.Run (XCODE_SAVE_IN_PATH, AppleSdkSettings.XcodePath, projectDir); } public void OpenProject () @@ -200,7 +199,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing pendingProjectWrite.Generate (projectDir); pendingProjectWrite = null; } - if (!NSWorkspace.SharedWorkspace.OpenFile (xcproj, xcodePath)) + if (!NSWorkspace.SharedWorkspace.OpenFile (xcproj, AppleSdkSettings.XcodePath)) throw new Exception ("Failed to open Xcode project"); } @@ -208,7 +207,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing { XC4Debug.Log ("Opening file in Xcode: {0}", relativeName); OpenProject (); - NSWorkspace.SharedWorkspace.OpenFile (projectDir.Combine (relativeName), xcodePath); + NSWorkspace.SharedWorkspace.OpenFile (projectDir.Combine (relativeName), AppleSdkSettings.XcodePath); } public void DeleteProjectDirectory () @@ -238,19 +237,19 @@ namespace MonoDevelop.MacDev.XcodeSyncing { if (!CheckRunning ()) return false; - return AppleScript.Run (XCODE_CHECK_PROJECT_OPEN, xcodePath, xcproj) == "true"; + return AppleScript.Run (XCODE_CHECK_PROJECT_OPEN, AppleSdkSettings.XcodePath, xcproj) == "true"; } public bool CloseProject () { - var success = AppleScript.Run (XCODE_CLOSE_IN_PATH, xcodePath, projectDir) == "true"; + var success = AppleScript.Run (XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, projectDir) == "true"; XC4Debug.Log ("Closing project: {0}", success); return success; } public bool CloseFile (string fileName) { - var success = AppleScript.Run (XCODE_CLOSE_IN_PATH, xcodePath, fileName) == "true"; + var success = AppleScript.Run (XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, fileName) == "true"; XC4Debug.Log ("Closing file {0}: {1}", fileName, success); return success; } diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs index fd1a4106aa..a26b82f2ee 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs @@ -58,6 +58,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing { this.dnp = dnp; this.infoService = infoService; + AppleSdkSettings.Changed += DisableSyncing; } void EnableSyncing () @@ -363,6 +364,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing return; disposed = true; DisableSyncing (); + AppleSdkSettings.Changed -= DisableSyncing; } } 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" /> |