diff options
author | David Karlaš <david.karlas@xamarin.com> | 2014-07-10 17:27:25 +0400 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2014-07-10 17:27:25 +0400 |
commit | f87fc8908efac535706a068760a183e8d2fc894d (patch) | |
tree | 044abbffc85b72fb222d9902e71f0de8b39fcb7f | |
parent | b2d52c547ea4cd0ba2c2878a58bb17c485e4e6a0 (diff) |
[Debugger] Location Preview and Android location converter
4 files changed, 152 insertions, 0 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Converters/LocationConverters.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Converters/LocationConverters.cs new file mode 100644 index 0000000000..6021b707f4 --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Converters/LocationConverters.cs @@ -0,0 +1,60 @@ +// +// LocationConverters.cs +// +// Author: +// David Karlaš <david.karlas@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.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 Mono.Debugging.Client; + +namespace MonoDevelop.Debugger.Converters +{ + public class GpsLocation + { + public double Latitude { get; set; } + + public double Longitude { get; set; } + } + + public class LocationConverters : DebugValueConverter<GpsLocation> + { + #region implemented abstract members of DebugValueConverter + + public override bool CanGetValue (ObjectValue val) + { + return val.TypeName == "Android.Locations.Location"; + } + + public override GpsLocation GetValue (ObjectValue val) + { + var ops = DebuggingService.DebuggerSession.EvaluationOptions.Clone (); + ops.AllowTargetInvoke = true; + return new GpsLocation () { + Latitude = (double)val.GetChild ("Latitude", ops).GetRawValue (ops), + Longitude = (double)val.GetChild ("Longitude", ops).GetRawValue (ops) + }; + } + + #endregion + } +} + diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs new file mode 100644 index 0000000000..c31bb74260 --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs @@ -0,0 +1,88 @@ +// +// LocationPreviewVisualizer.cs +// +// Author: +// David Karlaš <david.karlas@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.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.Components; +using Mono.Debugging.Client; +using MonoDevelop.Debugger.Converters; +using System.Net; +using System.Globalization; +using System.IO; +using System.Threading; +using MonoDevelop.Core; +using MonoDevelop.Ide; +using Gtk; + +namespace MonoDevelop.Debugger.PreviewVisualizers +{ + public class LocationPreviewVisualizer : PreviewVisualizer + { + #region implemented abstract members of PreviewVisualizer + + public override bool CanVisualize (ObjectValue val) + { + return DebuggingService.HasGetConverter<GpsLocation> (val); + } + + public override Control GetVisualizerWidget (ObjectValue val) + { + var location = DebuggingService.GetGetConverter<GpsLocation> (val).GetValue (val); + var mainBox = new Gtk.VBox (); + mainBox.PackStart (new Label (GettextCatalog.GetString ("Loading..."))); + using (var stream = new MemoryStream ()) { + var cancelSource = new CancellationTokenSource (); + var timer = new Timer (delegate { + cancelSource.Cancel (); + }, null, 4000, System.Threading.Timeout.Infinite); + WebRequestHelper.GetResponseAsync ( + () => (HttpWebRequest)WebRequest.Create ("http://maps.googleapis.com/maps/api/staticmap?&size=500x300&zoom=15&markers=color:blue%7C" + + location.Longitude.ToString (CultureInfo.InvariantCulture.NumberFormat) + "," + + location.Latitude.ToString (CultureInfo.InvariantCulture.NumberFormat)), + null, + cancelSource.Token).ContinueWith ((System.Threading.Tasks.Task<HttpWebResponse> arg) => { + Application.Invoke (delegate { + mainBox.Remove (mainBox.Children [0]); + if (arg.Exception == null) { + var imageView = new ImageView (Xwt.Drawing.Image.FromStream (arg.Result.GetResponseStream ())); + imageView.Show (); + mainBox.PackStart (imageView); + PreviewWindowManager.RepositionWindow (); + } else { + mainBox.PackStart (new GenericPreviewVisualizer ().GetVisualizerWidget (val)); + PreviewWindowManager.RepositionWindow (); + DebuggingService.DebuggerSession.LogWriter (true, "Failed to load map preview: " + arg.Exception.InnerException); + arg.Exception.Handle ((e) => true); + } + }); + }); + } + mainBox.ShowAll (); + return mainBox; + } + + #endregion + } +} + diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml index 2ef998b319..a5ff9df10e 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml @@ -54,6 +54,7 @@ <Type class="MonoDevelop.Debugger.Converters.SizesConverters" /> <Type class="MonoDevelop.Debugger.Converters.RectanglesConverters" /> <Type class="MonoDevelop.Debugger.Converters.ImageConverter" /> + <Type class="MonoDevelop.Debugger.Converters.LocationConverters" /> </Extension> <Extension path="/MonoDevelop/Debugging/InlineVisualizers"> @@ -64,6 +65,7 @@ <Type class="MonoDevelop.Debugger.PreviewVisualizers.SizeAndRectanglePreviewVisualizer" /> <Type class="MonoDevelop.Debugger.PreviewVisualizers.ColorPreviewVisualizer" /> <Type class="MonoDevelop.Debugger.PreviewVisualizers.ImagePreviewVisualizer" /> + <Type class="MonoDevelop.Debugger.PreviewVisualizers.LocationPreviewVisualizer" /> </Extension> <Extension path = "/MonoDevelop/Ide/StartupHandlers"> diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj index a0ab115069..13b4235bb9 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj @@ -165,6 +165,8 @@ <Compile Include="MonoDevelop.Debugger.PreviewVisualizers\ImagePreviewVisualizer.cs" /> <Compile Include="MonoDevelop.Debugger.Converters\ImageConverter.cs" /> <Compile Include="MonoDevelop.Debugger.PreviewVisualizers\GenericPreviewVisualizer.cs" /> + <Compile Include="MonoDevelop.Debugger.Converters\LocationConverters.cs" /> + <Compile Include="MonoDevelop.Debugger.PreviewVisualizers\LocationPreviewVisualizer.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.Debugger.addin.xml"> |