Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortherzok <marius.ungureanu@xamarin.com>2018-10-19 17:04:17 +0300
committertherzok <marius.ungureanu@xamarin.com>2019-01-29 14:30:34 +0300
commita73e621b1c1cdb5946f43ad9aeeb1d768ac89dba (patch)
tree68a29fa7e12ef0841af513b6525c07202ed6b7a7 /main/src/tools
parent27e6a6d6e6e1a174914cdbc10f27188f72086579 (diff)
Make tab content lazily constructed
Diffstat (limited to 'main/src/tools')
-rw-r--r--main/src/tools/ExtensionTools/Application.cs16
-rw-r--r--main/src/tools/ExtensionTools/ExtensionTools.csproj1
-rw-r--r--main/src/tools/ExtensionTools/LazyNotebook.cs71
3 files changed, 84 insertions, 4 deletions
diff --git a/main/src/tools/ExtensionTools/Application.cs b/main/src/tools/ExtensionTools/Application.cs
index 23b7cf73b1..5d86c23fda 100644
--- a/main/src/tools/ExtensionTools/Application.cs
+++ b/main/src/tools/ExtensionTools/Application.cs
@@ -24,6 +24,7 @@
// 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;
@@ -74,13 +75,20 @@ namespace MonoDevelop.ExtensionTools
static Widget CreateWindowContent ()
{
- var nb = new Notebook ();
+ var nb = new LazyNotebook ();
- nb.Add (new AddinListWidget (), "List");
- nb.Add (new AddinDependencyTreeWidget (), "Dependency Tree");
- nb.Add (new ExtensionPointsWidget (), "Extension Points");
+ 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");
+ }
}
}
diff --git a/main/src/tools/ExtensionTools/ExtensionTools.csproj b/main/src/tools/ExtensionTools/ExtensionTools.csproj
index 7cc890870f..f263e9b78c 100644
--- a/main/src/tools/ExtensionTools/ExtensionTools.csproj
+++ b/main/src/tools/ExtensionTools/ExtensionTools.csproj
@@ -28,6 +28,7 @@
<Compile Include="AddinListWidget.cs" />
<Compile Include="AddinRegistryExtensions.cs" />
<Compile Include="ExtensionPointsWidget.cs" />
+ <Compile Include="LazyNotebook.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj">
diff --git a/main/src/tools/ExtensionTools/LazyNotebook.cs b/main/src/tools/ExtensionTools/LazyNotebook.cs
new file mode 100644
index 0000000000..2f8c98e05b
--- /dev/null
+++ b/main/src/tools/ExtensionTools/LazyNotebook.cs
@@ -0,0 +1,71 @@
+//
+// LazyNotebook.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 Xwt;
+
+namespace MonoDevelop.ExtensionTools
+{
+ class LazyNotebook : Notebook
+ {
+ public void Add (Func<Widget> createWidget, string label)
+ {
+ var createWidgetChain = OnAdd (createWidget);
+ var widget = new LazyWidget (createWidgetChain);
+ Add (widget, label);
+ }
+
+ protected override void OnCurrentTabChanged (EventArgs e)
+ {
+ base.OnCurrentTabChanged (e);
+ Xwt.Application.TimeoutInvoke (0, () => {
+ Toolkit.NativeEngine.Invoke (() => {
+ var tab = Tabs [CurrentTabIndex];
+ var lazy = (LazyWidget)tab.Child;
+ lazy.CreateContent ();
+ });
+ return false;
+ });
+ }
+
+ protected virtual Func<Widget> OnAdd (Func<Widget> createWidget) => createWidget;
+
+ class LazyWidget : Widget
+ {
+ readonly Func<Widget> createWidget;
+
+ public LazyWidget (Func<Widget> createWidget)
+ {
+ this.createWidget = createWidget;
+ }
+
+ public void CreateContent ()
+ {
+ if (Content == null)
+ Content = createWidget ();
+ }
+ }
+ }
+}