From a06686abe21bf925b3f30b7c905fa6e9ce6deee4 Mon Sep 17 00:00:00 2001 From: Oystein Bjorke Date: Sun, 12 Oct 2014 11:29:15 +0200 Subject: [PATCH] Add ExampleBrowser for Mac --- .../Xamarin.Mac/ExampleBrowser/AppDelegate.cs | 88 ++++++++ .../ExampleBrowser/AppDelegate.designer.cs | 7 + .../ExampleBrowser/ExampleBrowser.csproj | 108 ++++++++++ .../Xamarin.Mac/ExampleBrowser/Info.plist | 34 ++++ .../Xamarin.Mac/ExampleBrowser/Main.cs | 18 ++ .../Xamarin.Mac/ExampleBrowser/PlotWindow.cs | 24 +++ .../ExampleBrowser/PlotWindow.designer.cs | 7 + .../Xamarin.Mac/ExampleBrowser/PlotWindow.xib | 189 ++++++++++++++++++ .../ExampleBrowser/PlotWindowController.cs | 52 +++++ .../PlotWindowController.designer.cs | 7 + .../Xamarin.Mac/SimpleDemo/AppDelegate.cs | 2 +- Source/OxyPlot.Xamarin.Mac.sln | 21 +- 12 files changed, 555 insertions(+), 2 deletions(-) create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.designer.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/ExampleBrowser.csproj create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/Info.plist create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/Main.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.designer.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.xib create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.cs create mode 100644 Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.designer.cs diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.cs new file mode 100644 index 0000000..065a8c2 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.cs @@ -0,0 +1,88 @@ +using System; + +using Foundation; +using AppKit; +using System.Collections.Generic; +using System.Linq; + +namespace ExampleBrowser +{ + using ExampleLibrary; + + public partial class AppDelegate : NSApplicationDelegate + { + PlotWindowController plotWindowController; + ExampleInfo currentExample; + + public AppDelegate () + { + } + + List exampleList; + + public override void FinishedLaunching (NSObject notification) + { + plotWindowController = new PlotWindowController (); + + var menu = new NSMenu (); + + var appMenu = new NSMenu (); + appMenu.AddItem (new NSMenuItem ("Next example", "n", (s, e) => this.NextExample (1))); + appMenu.AddItem (new NSMenuItem ("Previous example", "p", (s, e) => this.NextExample (-1))); + appMenu.AddItem (NSMenuItem.SeparatorItem); + appMenu.AddItem (new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu))); + menu.AddItem (new NSMenuItem { Submenu = appMenu }); + + var fileMenu = new NSMenu ("File"); + fileMenu.AddItem (new NSMenuItem ("Export", "e")); + menu.AddItem (new NSMenuItem { Submenu = fileMenu }); + + var editMenu = new NSMenu ("Edit"); + editMenu.AddItem (new NSMenuItem ("Copy", "c")); + menu.AddItem (new NSMenuItem { Submenu = editMenu }); + + var examplesMenu = new NSMenu ("Examples"); + exampleList = Examples.GetList (); + + var categories = exampleList.Select (e => e.Category).Distinct ().OrderBy (c => c).ToArray (); + var categoryMenus = new Dictionary (); + foreach (var category in categories) { + var categoryMenu = new NSMenu (category); + examplesMenu.AddItem (new NSMenuItem (category) { Submenu = categoryMenu }); + categoryMenus.Add (category, categoryMenu); + } + + foreach (var example in exampleList) { + var item = new NSMenuItem (example.Title, (s, e) => this.SetExample (example)); + var categoryMenu = categoryMenus [example.Category]; + categoryMenu.AddItem (item); + } + menu.AddItem (new NSMenuItem { Submenu = examplesMenu }); + this.SetExample (exampleList.First ()); + + plotWindowController.Window.MakeKeyAndOrderFront (this); + NSApplication.SharedApplication.MainMenu = menu; + } + + public void SetExample (ExampleInfo example) + { + this.plotWindowController.SetExample (example); + this.currentExample = example; + } + + public void NextExample (int delta) + { + var index = this.exampleList.IndexOf (this.currentExample); + index += delta; + if (index < 0) + index = this.exampleList.Count - 1; + if (index >= this.exampleList.Count) + index = 0; + this.SetExample (this.exampleList [index]); + } + + public void Export () + { + } + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.designer.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.designer.cs new file mode 100644 index 0000000..d97fcb0 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/AppDelegate.designer.cs @@ -0,0 +1,7 @@ +namespace ExampleBrowser +{ + [global::Foundation.Register ("AppDelegate")] + public partial class AppDelegate + { + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/ExampleBrowser.csproj b/Source/Examples/Xamarin.Mac/ExampleBrowser/ExampleBrowser.csproj new file mode 100644 index 0000000..b378875 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/ExampleBrowser.csproj @@ -0,0 +1,108 @@ + + + + Debug + AnyCPU + {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 8.0.30703 + 2.0 + {A354B462-B05D-4D1B-B844-C122511AE0BE} + Exe + ExampleBrowser + Resources + ExampleBrowser + Xamarin.Mac + v2.0 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + false + false + Mac Developer + false + false + + + full + true + bin\Release + prompt + 4 + false + SdkOnly + false + true + false + Developer ID Application + true + true + + + full + true + bin\AppStore + prompt + 4 + false + SdkOnly + false + true + 3rd Party Mac Developer Installer + true + 3rd Party Mac Developer Application + true + true + + + + + + + + + + + + + + + + + AppDelegate.cs + + + + PlotWindow.cs + + + + PlotWindowController.cs + + + + + + {FACB89E5-53A5-4748-9F5B-E0714EBB37B2} + ExampleLibrary + + + {7A0B35C0-DD17-4964-8E9A-44D6CECDC692} + OxyPlot + + + {7DC4B440-5328-4929-BF32-56A1209ED4DD} + OxyPlot.Xamarin.Mac + + + + + + \ No newline at end of file diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/Info.plist b/Source/Examples/Xamarin.Mac/ExampleBrowser/Info.plist new file mode 100644 index 0000000..c489a33 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDisplayName + ExampleBrowser + CFBundleDevelopmentRegion + en + CFBundleIconFile + + CFBundleIdentifier + com..ExampleBrowser + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ExampleBrowser + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.8 + NSHumanReadableCopyright + + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/Main.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/Main.cs new file mode 100644 index 0000000..7a798b6 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/Main.cs @@ -0,0 +1,18 @@ +using System; + +using AppKit; + +namespace ExampleBrowser +{ + static class MainClass + { + static void Main (string[] args) + { + NSApplication.Init (); + + var application = NSApplication.SharedApplication; + application.Delegate = new AppDelegate (); + application.Run (); + } + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.cs new file mode 100644 index 0000000..1fe4a43 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.cs @@ -0,0 +1,24 @@ +using System; + +using Foundation; +using AppKit; + +namespace ExampleBrowser +{ + public partial class PlotWindow : NSWindow + { + public PlotWindow (IntPtr handle) : base (handle) + { + } + + [Export ("initWithCoder:")] + public PlotWindow (NSCoder coder) : base (coder) + { + } + + public override void AwakeFromNib () + { + base.AwakeFromNib (); + } + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.designer.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.designer.cs new file mode 100644 index 0000000..4d3c5c2 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.designer.cs @@ -0,0 +1,7 @@ +namespace ExampleBrowser +{ + [global::Foundation.Register ("PlotWindow")] + public partial class PlotWindow + { + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.xib b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.xib new file mode 100644 index 0000000..1c108b8 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindow.xib @@ -0,0 +1,189 @@ + + + + 1060 + 10D573 + 762 + 1038.29 + 460.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 762 + + + YES + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + YES + + + + YES + + PlotWindowController + + + FirstResponder + + + NSApplication + + + 15 + 2 + {{131, 74}, {606, 354}} + 611844096 + Window + PlotWindow + + {1.79769e+308, 1.79769e+308} + + + 256 + {606, 354} + + + {{0, 0}, {1280, 778}} + {1.79769e+308, 1.79769e+308} + + + + + YES + + + window + + + + 6 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 2 + + + YES + + + + + + 3 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 2.IBEditorWindowLastContentRect + 2.IBPluginDependency + 2.IBWindowTemplateEditedContentRect + 2.NSWindowTemplate.visibleAtLaunch + 3.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{319, 371}, {606, 354}} + com.apple.InterfaceBuilder.CocoaPlugin + {{319, 371}, {606, 354}} + + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 6 + + + + YES + + PlotWindow + NSWindow + + IBUserSource + + + + + PlotWindowController + NSWindowController + + IBUserSource + + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + + 3 + + diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.cs new file mode 100644 index 0000000..75218e0 --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.cs @@ -0,0 +1,52 @@ +using System; + +using Foundation; +using AppKit; + +namespace ExampleBrowser +{ + using ExampleLibrary; + using OxyPlot; + using OxyPlot.Xamarin.Mac; + + public partial class PlotWindowController : NSWindowController + { + private PlotView plotView; + + public PlotWindowController (IntPtr handle) : base (handle) + { + } + + [Export ("initWithCoder:")] + public PlotWindowController (NSCoder coder) : base (coder) + { + } + + public PlotWindowController () : base ("PlotWindow") + { + } + + public override void AwakeFromNib () + { + base.AwakeFromNib (); + } + + public new PlotWindow Window { + get { return (PlotWindow)base.Window; } + } + + public override void WindowDidLoad () + { + base.WindowDidLoad (); + plotView = new PlotView (this.Window.Frame); + Window.ContentView = plotView; + } + + public void SetExample(ExampleInfo example){ + this.Window.Title = example.Title; + plotView.Model = example.PlotModel; + plotView.Controller = example.PlotController; + plotView.InvalidatePlot (true); + } + } +} diff --git a/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.designer.cs b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.designer.cs new file mode 100644 index 0000000..3c7cace --- /dev/null +++ b/Source/Examples/Xamarin.Mac/ExampleBrowser/PlotWindowController.designer.cs @@ -0,0 +1,7 @@ +namespace ExampleBrowser +{ + [global::Foundation.Register ("PlotWindowController")] + public partial class PlotWindowController + { + } +} diff --git a/Source/Examples/Xamarin.Mac/SimpleDemo/AppDelegate.cs b/Source/Examples/Xamarin.Mac/SimpleDemo/AppDelegate.cs index 0aa419d..61ecf9b 100644 --- a/Source/Examples/Xamarin.Mac/SimpleDemo/AppDelegate.cs +++ b/Source/Examples/Xamarin.Mac/SimpleDemo/AppDelegate.cs @@ -21,7 +21,7 @@ namespace SimpleDemo menu.AddItem (menuItem); var appMenu = new NSMenu (); - var quitItem = new NSMenuItem ("Quit " + NSProcessInfo.ProcessInfo.ProcessName, "q", (s, e) => NSApplication.SharedApplication.Terminate (menu)); + var quitItem = new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu)); appMenu.AddItem (quitItem); menuItem.Submenu = appMenu; diff --git a/Source/OxyPlot.Xamarin.Mac.sln b/Source/OxyPlot.Xamarin.Mac.sln index c6e6b64..4d81629 100644 --- a/Source/OxyPlot.Xamarin.Mac.sln +++ b/Source/OxyPlot.Xamarin.Mac.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleLibrary", "Examples\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDemo", "Examples\Xamarin.Mac\SimpleDemo\SimpleDemo.csproj", "{AC685CC2-AE9B-4C9A-8A70-B71D25D2DB90}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleBrowser", "Examples\Xamarin.Mac\ExampleBrowser\ExampleBrowser.csproj", "{A354B462-B05D-4D1B-B844-C122511AE0BE}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OxyPlot.Xamarin.Mac", "OxyPlot.Xamarin.Mac\OxyPlot.Xamarin.Mac.csproj", "{7DC4B440-5328-4929-BF32-56A1209ED4DD}" EndProject Global @@ -55,6 +57,22 @@ Global {7DC4B440-5328-4929-BF32-56A1209ED4DD}.Release|iPhone.Build.0 = Release|Any CPU {7DC4B440-5328-4929-BF32-56A1209ED4DD}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {7DC4B440-5328-4929-BF32-56A1209ED4DD}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.AppStore|iPhone.ActiveCfg = AppStore|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.AppStore|iPhone.Build.0 = AppStore|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|iPhone.Build.0 = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|Any CPU.Build.0 = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|iPhone.ActiveCfg = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|iPhone.Build.0 = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {A354B462-B05D-4D1B-B844-C122511AE0BE}.Release|iPhoneSimulator.Build.0 = Release|Any CPU {AC685CC2-AE9B-4C9A-8A70-B71D25D2DB90}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU {AC685CC2-AE9B-4C9A-8A70-B71D25D2DB90}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU {AC685CC2-AE9B-4C9A-8A70-B71D25D2DB90}.AppStore|iPhone.ActiveCfg = AppStore|Any CPU @@ -91,9 +109,10 @@ Global GlobalSection(NestedProjects) = preSolution {FACB89E5-53A5-4748-9F5B-E0714EBB37B2} = {0AB67A65-9645-4DF6-98A2-D5734D212E7C} {AC685CC2-AE9B-4C9A-8A70-B71D25D2DB90} = {0AB67A65-9645-4DF6-98A2-D5734D212E7C} + {A354B462-B05D-4D1B-B844-C122511AE0BE} = {0AB67A65-9645-4DF6-98A2-D5734D212E7C} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Examples\Xamarin.Mac\SimpleDemo\SimpleDemo.csproj + StartupItem = Examples\Xamarin.Mac\ExampleBrowser\ExampleBrowser.csproj EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE