diff options
Diffstat (limited to 'main/src/tools/ExtensionTools/Application.cs')
-rw-r--r-- | main/src/tools/ExtensionTools/Application.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/main/src/tools/ExtensionTools/Application.cs b/main/src/tools/ExtensionTools/Application.cs new file mode 100644 index 0000000000..7403015edb --- /dev/null +++ b/main/src/tools/ExtensionTools/Application.cs @@ -0,0 +1,97 @@ +// +// MyClass.cs +// +// Author: +// Marius Ungureanu <maungu@microsoft.com> +// +// Copyright (c) 2018 Microsoft Inc. +// +// 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 System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Mono.Addins; +using MonoDevelop.Core; +using Xwt; + +namespace MonoDevelop.ExtensionTools +{ + public class Application: IApplication + { + // HACK: Make this proper + internal static LazyNotebook MainNotebook; + + public Task<int> Run (string[] arguments) + { + Xwt.Application.Initialize (ToolkitType.Gtk); +#if MAC + var dir = Path.GetDirectoryName (typeof (Application).Assembly.Location); + if (ObjCRuntime.Dlfcn.dlopen (Path.Combine (dir, "libxammac.dylib"), 0) == IntPtr.Zero) { + LoggingService.LogFatalError ("Unable to load libxammac"); + return Task.FromResult (1); + } +#endif + LoggingService.LogInfo ("Initialized toolkit"); + + Xwt.Toolkit.NativeEngine.Invoke (() => { + using (CreateWindow ()) { + LoggingService.LogInfo ("Showing main window"); + Xwt.Application.Run (); + } + }); + + return Task.FromResult (0); + } + + static Window CreateWindow () + { + var window = new Window { + Content = CreateWindowContent (), + Width = 800, + Height = 800, + }; + + window.Closed += (_, __) => Xwt.Application.Exit (); + window.Show (); + + return window; + } + + static Widget CreateWindowContent () + { + var nb = MainNotebook = new LazyNotebook (); + + foreach (var (widgetFunc, title) in GetTabs ()) { + nb.Add (widgetFunc, title); + } + + return nb; + } + + static IEnumerable<(Func<Widget> widgetFunc, string title)> GetTabs () + { + yield return (() => new AddinListWidget (), "List"); + yield return (() => new AddinDependencyTreeWidget (), "Dependency Tree"); + yield return (() => new ExtensionPointsWidget (), "Extension Points"); + } + } +} |