From 33c515cd081f0a382fce49e304a86eefab5441a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= <tgckpg@gmail.com>
Date: Mon, 22 Feb 2016 09:45:59 +0800
Subject: [PATCH] Early dynamic module loading for SmartInput

---
 .../SmartInput/CandidateAction/Heading.js     | 29 +++++++++++++++++++
 .../Astro/Blog/AstroEdit/SmartInput/_this.js  | 27 +++++++++++++----
 ...g.AstroEdit.SmartInput.ICandidateAction.js |  6 ++++
 3 files changed, 56 insertions(+), 6 deletions(-)
 create mode 100644 botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
 create mode 100644 botanjs/src/externs/Astro.Blog.AstroEdit.SmartInput.ICandidateAction.js

diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
new file mode 100644
index 00000000..aa5f8368
--- /dev/null
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
@@ -0,0 +1,29 @@
+(function ()
+{
+	var ns = __namespace( "Astro.Blog.AstroEdit.SmartInput.CandidateAction" );
+
+	/** @type {System.utils.IKey} */
+	var IKey                              = __import( "System.utils.IKey" );
+	/** @type {System.utils.DataKey} */
+	var DataKey                           = __import( "System.utils.DataKey" );
+	/** @type {Dandelion.IDOMElement} */
+	var IDOMElement                       = __import( "Dandelion.IDOMElement" );
+	/** @type {Dandelion} */
+	var Dand                              = __import( "Dandelion" );
+
+	/** @type {Astro.Blog.AstroEdit.SmartInput.ICandidateAction} */
+	var Heading = function ( visualizer )
+	{
+		this.visualizer = visualizer;
+	};
+
+	Heading.prototype.GetCandidates = function( handler )
+	{
+	};
+
+	Heading.prototype.Process = function( key )
+	{
+	};
+
+	ns[ NS_EXPORT ]( EX_CLASS, "Heading", Heading );
+})();
diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
index 538e933b..19e26a34 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
@@ -11,14 +11,12 @@
 	var Cycle                                   = __import( "System.Cycle" );
 	/** @type {System.Debug} */
 	var debug                                   = __import( "System.Debug" );
+	/** @type {System.Net.ClassLoader} */
+	var Loader                                  = __import( "System.Net.ClassLoader" );
 	/** @type {System.utils} */
 	var utils                                   = __import( "System.utils" );
-	/** @type {System.utils.Perf} */
-	var Perf                                    = __import( "System.utils.Perf" );
 	/** @type {System.utils.DataKey} */
 	var DataKey                                 = __import( "System.utils.DataKey" );
-	/** @type {System.utils.EventKey} */
-	var EventKey                                = __import( "System.utils.EventKey" );
 	/** @type {System.utils.IKey} */
 	var IKey                                    = __import( "System.utils.IKey" );
 	/** @type {Components.MessageBox} */
@@ -26,6 +24,9 @@
 	/** @type {Astro.Blog.Config} */
 	var Config                                  = __import( "Astro.Blog.Config" );
 
+	var moduleNs = "Astro.Blog.AstroEdit.SmartInput.CandidateAction.";
+	var service_uri = Config.get( "ServiceUri" );
+
 	var KeyHandler = function( sender, handler )
 	{
 		return function( e )
@@ -38,6 +39,12 @@
 		};
 	};
 
+	var LoadModule = function( mod, handler )
+	{
+		var ldr = new Loader( service_uri );
+		ldr.load( moduleNs + mod, handler );
+	};
+
 	/** @param {Astro.Blog.AstroEdit.Visualizer} */
 	var SmartInput = function ( visualizer, CandidatesOvd )
 	{
@@ -117,6 +124,14 @@
 			return null;
 		};
 
+		var ModuleLoaded = function( e )
+		{
+			/** @type {Astro.Blog.AstroEdit.SmartInput.ICandidateAction} */
+			var module = new ( __import( e ) )( visualizer );
+
+			// XXX
+		};
+
 		var HandleInput = function( sender, e )
 		{
 			// Don't handle if holding shift or ctrl key
@@ -154,9 +169,9 @@
 					if( selected )
 					{
 						insert = undefined;
-
-
 						sender.BindingBox.close();
+
+						LoadModule( Cands[ selected.getDAttribute( "key" ) ].module, ModuleLoaded );
 					}
 					else
 					{
diff --git a/botanjs/src/externs/Astro.Blog.AstroEdit.SmartInput.ICandidateAction.js b/botanjs/src/externs/Astro.Blog.AstroEdit.SmartInput.ICandidateAction.js
new file mode 100644
index 00000000..1ab9e358
--- /dev/null
+++ b/botanjs/src/externs/Astro.Blog.AstroEdit.SmartInput.ICandidateAction.js
@@ -0,0 +1,6 @@
+/** @constructor */
+Astro.Blog.AstroEdit.SmartInput.ICandidateAction = function(){};
+/** @type {function} */
+Astro.Blog.AstroEdit.SmartInput.ICandidateAction.GetCandidates;
+/** @type {function} */
+Astro.Blog.AstroEdit.SmartInput.ICandidateAction.Process;