Browse Source

Improvements for the nw app. Helios can now browse a remote page

Nicolas Petton 10 years ago
parent
commit
47a29bae56
6 changed files with 213 additions and 0 deletions
  1. 41 0
      helios.html
  2. BIN
      helios.nw
  3. BIN
      images/helios-app.png
  4. 1 0
      package.json
  5. 123 0
      src/Helios-Core.js
  6. 48 0
      src/Helios-Core.st

+ 41 - 0
helios.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Helios IDE</title>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+    <meta name="author" content="Nicolas Petton" />
+    <link type="image/x-icon" rel="shortcut icon" href="/favicon.ico"/>
+  </head>
+  <body id="helios">
+    <div id="helper">Loading Helios...</div>
+
+	<script type="text/javascript">
+    window.requireNode = window.require;
+    window.require = undefined; 
+	</script>
+
+    <div id="includes">
+      <script type='text/javascript' src='support/requirejs/require.min.js'></script>
+      <script type='text/javascript' src='support/amber.js'></script>
+      <script type='text/javascript'>
+
+          require(
+                  ["helios/all"],
+                  function (smalltalk) {
+          window.require = window.requireNode;
+                      window.onbeforeunload = function() {
+                          return 'Do you want to close Amber? All uncommitted changes will be lost.';
+                      };
+
+          smalltalk.initialize({'transport.defaultAmdNamespace': "amber_core"});
+	  smalltalk.globals.HLManager._setup();
+          smalltalk.globals.HLManager._current()._setTheme_('niflheim');
+          smalltalk.globals.HLManager._current()._setEditorTheme_('niflheim');
+          smalltalk.globals.HLRemoteConnector._connect();
+                  }
+          );
+
+      </script>
+    </div>
+  </body>
+</html>

BIN
amber.nw → helios.nw


BIN
images/helios-app.png


+ 1 - 0
package.json

@@ -2,6 +2,7 @@
 	"name": "amber",
 	"main": "helios.html",
 	"window": {
+		"icon": "images/helios-app.png",
 		"toolbar": false,
 		"width": 800,
 		"height": 600

+ 123 - 0
src/Helios-Core.js

@@ -5721,6 +5721,129 @@ referencedClasses: []
 globals.HLProgressBarWidget.klass);
 
 
+smalltalk.addClass('HLRemoteConnector', globals.HLWidget, [], 'Helios-Core');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "connect",
+protocol: 'connecting',
+fn: function (){
+var self=this;
+function $HLManager(){return globals.HLManager||(typeof HLManager=="undefined"?nil:HLManager)}
+return smalltalk.withContext(function($ctx1) { 
+_st(_st($HLManager())._current())._request_value_do_("Connect Helios to","http://localhost:4000",(function(url){
+return smalltalk.withContext(function($ctx2) {
+return self._connectTo_(url);
+}, function($ctx2) {$ctx2.fillBlock({url:url},$ctx1,1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"connect",{},globals.HLRemoteConnector)})},
+args: [],
+source: "connect\x0a\x09HLManager current\x0a\x09\x09request: 'Connect Helios to'\x0a\x09\x09value: 'http://localhost:4000'\x0a\x09\x09do: [ :url | self connectTo: url ]",
+messageSends: ["request:value:do:", "current", "connectTo:"],
+referencedClasses: ["HLManager"]
+}),
+globals.HLRemoteConnector);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "connectTo:",
+protocol: 'connecting',
+fn: function (aLocation){
+var self=this;
+var target;
+function $HLManager(){return globals.HLManager||(typeof HLManager=="undefined"?nil:HLManager)}
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2,$3,$4,$receiver;
+target=self._openLocation_(aLocation);
+_st(target)._on_do_("loaded",(function(){
+var win;
+return smalltalk.withContext(function($ctx2) {
+win=_st(target)._at_("window");
+$ctx2.sendIdx["at:"]=1;
+win;
+return _st((function(){
+var globals,environment;
+return smalltalk.withContext(function($ctx3) {
+$1=_st(win)._at_("requirejs");
+$ctx3.sendIdx["at:"]=2;
+globals=_st($1)._value_("amber_vm/globals");
+globals;
+$2=globals;
+if(($receiver = $2) == nil || $receiver == null){
+self._error_("Unable to connect to ".__comma(aLocation));
+} else {
+$2;
+};
+environment=_st(_st(globals)._at_("Environment"))._new();
+environment;
+$3=_st($HLManager())._current();
+_st($3)._environment_(environment);
+$4=_st($3)._registerServices();
+return $4;
+}, function($ctx3) {$ctx3.fillBlock({globals:globals,environment:environment},$ctx2,2)})}))._valueWithTimeout_((3000));
+}, function($ctx2) {$ctx2.fillBlock({win:win},$ctx1,1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"connectTo:",{aLocation:aLocation,target:target},globals.HLRemoteConnector)})},
+args: ["aLocation"],
+source: "connectTo: aLocation\x0a\x09| target |\x0a\x09\x0a\x09target := self openLocation: aLocation.\x0a\x09target on: 'loaded' do: [\x0a\x09\x09| win |\x0a\x09\x09win := target at: 'window'.\x0a\x09\x09\x0a\x09\x09[\x0a\x09\x09\x09| globals environment |\x0a\x09\x09\x09globals := (win at: 'requirejs') value: 'amber_vm/globals'.\x0a\x09\x09\x09globals ifNil: [ self error: 'Unable to connect to ', aLocation ].\x0a\x09\x0a\x09\x09\x09environment := (globals at: 'Environment') new.\x0a\x09\x09\x09HLManager current \x0a\x09\x09\x09\x09environment: environment;\x0a\x09\x09\x09\x09registerServices ] valueWithTimeout: 3000 ]",
+messageSends: ["openLocation:", "on:do:", "at:", "valueWithTimeout:", "value:", "ifNil:", "error:", ",", "new", "environment:", "current", "registerServices"],
+referencedClasses: ["HLManager"]
+}),
+globals.HLRemoteConnector);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "openLocation:",
+protocol: 'connecting',
+fn: function (aLocation){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+
+		return require('nw.gui').Window.open(aLocation);
+	;
+return self}, function($ctx1) {$ctx1.fill(self,"openLocation:",{aLocation:aLocation},globals.HLRemoteConnector)})},
+args: ["aLocation"],
+source: "openLocation: aLocation\x0a\x09<\x0a\x09\x09return require('nw.gui').Window.open(aLocation);\x0a\x09>",
+messageSends: [],
+referencedClasses: []
+}),
+globals.HLRemoteConnector);
+
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "connect",
+protocol: 'connecting',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self._new())._connect();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"connect",{},globals.HLRemoteConnector.klass)})},
+args: [],
+source: "connect\x0a\x09^ self new connect",
+messageSends: ["connect", "new"],
+referencedClasses: []
+}),
+globals.HLRemoteConnector.klass);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "connectTo:",
+protocol: 'connecting',
+fn: function (anUrl){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self._new())._connectTo_(anUrl);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"connectTo:",{anUrl:anUrl},globals.HLRemoteConnector.klass)})},
+args: ["anUrl"],
+source: "connectTo: anUrl\x0a\x09^ self new connectTo: anUrl",
+messageSends: ["connectTo:", "new"],
+referencedClasses: []
+}),
+globals.HLRemoteConnector.klass);
+
+
 smalltalk.addClass('HLTabWidget', globals.HLWidget, ['widget', 'label', 'root'], 'Helios-Core');
 globals.HLTabWidget.comment="I am a widget specialized into building another widget as an Helios tab.\x0a\x0aI should not be used directly, `HLWidget class >> #openAsTab` should be used instead.\x0a\x0a## Example\x0a\x0a    HLWorkspace openAsTab";
 smalltalk.addMethod(

+ 48 - 0
src/Helios-Core.st

@@ -1939,6 +1939,54 @@ default
 	^ default ifNil: [ default := self new ]
 ! !
 
+HLWidget subclass: #HLRemoteConnector
+	instanceVariableNames: ''
+	package: 'Helios-Core'!
+
+!HLRemoteConnector methodsFor: 'connecting'!
+
+connect
+	HLManager current
+		request: 'Connect Helios to'
+		value: 'http://localhost:4000'
+		do: [ :url | self connectTo: url ]
+!
+
+connectTo: aLocation
+	| target |
+	
+	target := self openLocation: aLocation.
+	target on: 'loaded' do: [
+		| win |
+		win := target at: 'window'.
+		
+		[
+			| globals environment |
+			globals := (win at: 'requirejs') value: 'amber_vm/globals'.
+			globals ifNil: [ self error: 'Unable to connect to ', aLocation ].
+	
+			environment := (globals at: 'Environment') new.
+			HLManager current 
+				environment: environment;
+				registerServices ] valueWithTimeout: 3000 ]
+!
+
+openLocation: aLocation
+	<
+		return require('nw.gui').Window.open(aLocation);
+	>
+! !
+
+!HLRemoteConnector class methodsFor: 'connecting'!
+
+connect
+	^ self new connect
+!
+
+connectTo: anUrl
+	^ self new connectTo: anUrl
+! !
+
 HLWidget subclass: #HLTabWidget
 	instanceVariableNames: 'widget label root'
 	package: 'Helios-Core'!