Browse Source

- more consistency in Helios
- HLListWidget now selects the first item when focused

Nicolas Petton 11 years ago
parent
commit
7de4a20e58

+ 0 - 12
js/Helios-Browser.deploy.js

@@ -1286,18 +1286,6 @@ fn: function (aBoolean) {
 }),
 smalltalk.HLBrowserModel);
 
-smalltalk.addMethod(
-"_subscribe_",
-smalltalk.method({
-selector: "subscribe:",
-fn: function (aWidget) {
-    var self = this;
-    smalltalk.send(aWidget, "_subscribeTo_", [smalltalk.send(self, "_announcer", [])]);
-    return self;
-}
-}),
-smalltalk.HLBrowserModel);
-
 
 smalltalk.addMethod(
 "_on_",

+ 1 - 18
js/Helios-Browser.js

@@ -1367,7 +1367,7 @@ smalltalk.addMethod(
 "_announcer",
 smalltalk.method({
 selector: "announcer",
-category: 'announcements',
+category: 'accessing',
 fn: function () {
     var self = this;
     var $1;
@@ -1706,23 +1706,6 @@ referencedClasses: ["HLShowInstanceToggled"]
 }),
 smalltalk.HLBrowserModel);
 
-smalltalk.addMethod(
-"_subscribe_",
-smalltalk.method({
-selector: "subscribe:",
-category: 'announcements',
-fn: function (aWidget) {
-    var self = this;
-    smalltalk.send(aWidget, "_subscribeTo_", [smalltalk.send(self, "_announcer", [])]);
-    return self;
-},
-args: ["aWidget"],
-source: "subscribe: aWidget\x0a\x09aWidget subscribeTo: self announcer",
-messageSends: ["subscribeTo:", "announcer"],
-referencedClasses: []
-}),
-smalltalk.HLBrowserModel);
-
 
 smalltalk.addMethod(
 "_on_",

+ 40 - 6
js/Helios-Core.deploy.js

@@ -192,12 +192,14 @@ smalltalk.addMethod(
 "_renderOn_",
 smalltalk.method({
 selector: "renderOn:",
-fn: function (html) {
-    var self = this;
-    smalltalk.send(self, "_registerBindings", []);
-    self['@wrapper'] = smalltalk.send(smalltalk.send(html, "_div", []), "_with_", [function () {return smalltalk.send(self, "_renderContentOn_", [html]);}]);
-    return self;
-}
+fn: function (html){
+var self=this;
+smalltalk.send(self,"_registerBindings",[]);
+self["@wrapper"]=smalltalk.send(html,"_div",[]);
+smalltalk.send((function(renderer){
+return smalltalk.send(self,"_renderContentOn_",[renderer]);
+}),"_appendToJQuery_",[smalltalk.send(self["@wrapper"],"_asJQuery",[])]);
+return self}
 }),
 smalltalk.HLWidget);
 
@@ -361,6 +363,17 @@ smalltalk.HLFocusableWidget);
 
 
 smalltalk.addClass('HLListWidget', smalltalk.HLFocusableWidget, ['items', 'selectedItem'], 'Helios-Core');
+smalltalk.addMethod(
+"_activateFirstListItem",
+smalltalk.method({
+selector: "activateFirstListItem",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_activateListItem_",[smalltalk.send(window,"_jQuery_",[smalltalk.send(smalltalk.send(smalltalk.send(self["@wrapper"],"_asJQuery",[]),"_find_",["li"]),"_get_",[(0)])])]);
+return self}
+}),
+smalltalk.HLListWidget);
+
 smalltalk.addMethod(
 "_activateListItem_",
 smalltalk.method({
@@ -422,6 +435,27 @@ fn: function () {
 }),
 smalltalk.HLListWidget);
 
+smalltalk.addMethod(
+"_focus",
+smalltalk.method({
+selector: "focus",
+fn: function (){
+var self=this;
+var $1,$2;
+smalltalk.send(self,"_focus",[],smalltalk.HLFocusableWidget);
+$1=smalltalk.send(smalltalk.send(self,"_items",[]),"_isEmpty",[]);
+if(! smalltalk.assert($1)){
+$2=smalltalk.send(self,"_selectedItem",[]);
+if(($receiver = $2) == nil || $receiver == undefined){
+smalltalk.send(self,"_activateFirstListItem",[]);
+} else {
+$2;
+};
+};
+return self}
+}),
+smalltalk.HLListWidget);
+
 smalltalk.addMethod(
 "_iconForItem_",
 smalltalk.method({

+ 52 - 8
js/Helios-Core.js

@@ -263,15 +263,17 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "renderOn:",
 category: 'rendering',
-fn: function (html) {
-    var self = this;
-    smalltalk.send(self, "_registerBindings", []);
-    self['@wrapper'] = smalltalk.send(smalltalk.send(html, "_div", []), "_with_", [function () {return smalltalk.send(self, "_renderContentOn_", [html]);}]);
-    return self;
-},
+fn: function (html){
+var self=this;
+smalltalk.send(self,"_registerBindings",[]);
+self["@wrapper"]=smalltalk.send(html,"_div",[]);
+smalltalk.send((function(renderer){
+return smalltalk.send(self,"_renderContentOn_",[renderer]);
+}),"_appendToJQuery_",[smalltalk.send(self["@wrapper"],"_asJQuery",[])]);
+return self},
 args: ["html"],
-source: "renderOn: html\x0a    self registerBindings.\x0a\x0a\x09wrapper := html div with: [\x0a    \x09self renderContentOn: html ]",
-messageSends: ["registerBindings", "with:", "renderContentOn:", "div"],
+source: "renderOn: html\x0a    self registerBindings.\x0a\x0a\x09wrapper := html div.\x0a    [ :renderer | self renderContentOn: renderer ] appendToJQuery: wrapper asJQuery",
+messageSends: ["registerBindings", "div", "appendToJQuery:", "asJQuery", "renderContentOn:"],
 referencedClasses: []
 }),
 smalltalk.HLWidget);
@@ -496,6 +498,22 @@ smalltalk.HLFocusableWidget);
 
 
 smalltalk.addClass('HLListWidget', smalltalk.HLFocusableWidget, ['items', 'selectedItem'], 'Helios-Core');
+smalltalk.addMethod(
+"_activateFirstListItem",
+smalltalk.method({
+selector: "activateFirstListItem",
+category: 'actions',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_activateListItem_",[smalltalk.send(window,"_jQuery_",[smalltalk.send(smalltalk.send(smalltalk.send(self["@wrapper"],"_asJQuery",[]),"_find_",["li"]),"_get_",[(0)])])]);
+return self},
+args: [],
+source: "activateFirstListItem\x0a\x09self activateListItem: (window jQuery: ((wrapper asJQuery find: 'li') get: 0))",
+messageSends: ["activateListItem:", "jQuery:", "get:", "find:", "asJQuery"],
+referencedClasses: []
+}),
+smalltalk.HLListWidget);
+
 smalltalk.addMethod(
 "_activateListItem_",
 smalltalk.method({
@@ -572,6 +590,32 @@ referencedClasses: []
 }),
 smalltalk.HLListWidget);
 
+smalltalk.addMethod(
+"_focus",
+smalltalk.method({
+selector: "focus",
+category: 'actions',
+fn: function (){
+var self=this;
+var $1,$2;
+smalltalk.send(self,"_focus",[],smalltalk.HLFocusableWidget);
+$1=smalltalk.send(smalltalk.send(self,"_items",[]),"_isEmpty",[]);
+if(! smalltalk.assert($1)){
+$2=smalltalk.send(self,"_selectedItem",[]);
+if(($receiver = $2) == nil || $receiver == undefined){
+smalltalk.send(self,"_activateFirstListItem",[]);
+} else {
+$2;
+};
+};
+return self},
+args: [],
+source: "focus\x0a\x09super focus.\x0a    self items isEmpty ifFalse: [ \x0a\x09\x09self selectedItem ifNil: [ self activateFirstListItem ] ]",
+messageSends: ["focus", "ifFalse:", "ifNil:", "activateFirstListItem", "selectedItem", "isEmpty", "items"],
+referencedClasses: []
+}),
+smalltalk.HLListWidget);
+
 smalltalk.addMethod(
 "_iconForItem_",
 smalltalk.method({

+ 21 - 77
js/Helios-Workspace.deploy.js

@@ -153,7 +153,7 @@ smalltalk.method({
 selector: "clear",
 fn: function () {
     var self = this;
-    smalltalk.send(self, "_val_", [""]);
+    smalltalk.send(self, "_contents_", [""]);
     return self;
 }
 }),
@@ -163,11 +163,11 @@ smalltalk.addMethod(
 "_contents",
 smalltalk.method({
 selector: "contents",
-fn: function () {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@editor'], "_getValue", []);
-    return $1;
+fn: function (){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@editor"],"_getValue",[]);
+return $1;
 }
 }),
 smalltalk.HLCodeWidget);
@@ -176,12 +176,10 @@ smalltalk.addMethod(
 "_contents_",
 smalltalk.method({
 selector: "contents:",
-fn: function (aString) {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@editor'], "_setValue_", [aString]);
-    return $1;
-}
+fn: function (aString){
+var self=this;
+smalltalk.send(self["@editor"],"_setValue_",[aString]);
+return self}
 }),
 smalltalk.HLCodeWidget);
 
@@ -293,7 +291,7 @@ fn: function () {
     var self = this;
     var $1;
     if (($receiver = self['@model']) == nil || $receiver == undefined) {
-        self['@model'] = smalltalk.send(smalltalk.HLCodeModel || HLCodeModel, "_new", []);
+        smalltalk.send(self, "_model_", [smalltalk.send(smalltalk.HLCodeModel || HLCodeModel, "_new", [])]);
         $1 = self['@model'];
     } else {
         $1 = self['@model'];
@@ -307,11 +305,10 @@ smalltalk.addMethod(
 "_model_",
 smalltalk.method({
 selector: "model:",
-fn: function (aModel) {
-    var self = this;
-    self['@model'] = aModel;
-    return self;
-}
+fn: function (aModel){
+var self=this;
+self["@model"]=aModel;
+return self}
 }),
 smalltalk.HLCodeWidget);
 
@@ -458,28 +455,12 @@ smalltalk.addMethod(
 "_renderContentOn_",
 smalltalk.method({
 selector: "renderContentOn:",
-fn: function (html) {
-    var self = this;
-    self['@code'] = smalltalk.send(html, "_textarea", []);
-    smalltalk.send(self, "_setEditorOn_", [smalltalk.send(self['@code'], "_element", [])]);
-    smalltalk.send(self, "_observeWrapper", []);
-    return self;
-}
-}),
-smalltalk.HLCodeWidget);
-
-smalltalk.addMethod(
-"_renderOn_",
-smalltalk.method({
-selector: "renderOn:",
-fn: function (html) {
-    var self = this;
-    self['@wrapper'] = smalltalk.send(smalltalk.send(html, "_div", []), "_class_", ["code"]);
-    smalltalk.send(self, "_observeWrapper", []);
-    smalltalk.send(self['@wrapper'], "_with_", [function () {self['@code'] = smalltalk.send(html, "_textarea", []);return self['@code'];}]);
-    smalltalk.send(self, "_setEditorOn_", [smalltalk.send(self['@code'], "_element", [])]);
-    return self;
-}
+fn: function (html){
+var self=this;
+self["@code"]=smalltalk.send(html,"_textarea",[]);
+smalltalk.send(self,"_setEditorOn_",[smalltalk.send(self["@code"],"_element",[])]);
+smalltalk.send(self,"_observeWrapper",[]);
+return self}
 }),
 smalltalk.HLCodeWidget);
 
@@ -558,31 +539,6 @@ fn: function (aTextarea) {
 }),
 smalltalk.HLCodeWidget);
 
-smalltalk.addMethod(
-"_val",
-smalltalk.method({
-selector: "val",
-fn: function () {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@code'], "_getValue", []);
-    return $1;
-}
-}),
-smalltalk.HLCodeWidget);
-
-smalltalk.addMethod(
-"_val_",
-smalltalk.method({
-selector: "val:",
-fn: function (aString) {
-    var self = this;
-    smalltalk.send(self['@code'], "_setValue_", [aString]);
-    return self;
-}
-}),
-smalltalk.HLCodeWidget);
-
 
 
 smalltalk.addClass('HLWorkspace', smalltalk.HLWidget, ['model', 'codeWidget'], 'Helios-Workspace');
@@ -823,18 +779,6 @@ fn: function (anEvent) {
 }),
 smalltalk.HLWorkspaceModel);
 
-smalltalk.addMethod(
-"_subscribe_",
-smalltalk.method({
-selector: "subscribe:",
-fn: function (aWidget) {
-    var self = this;
-    smalltalk.send(aWidget, "_subscribeTo_", [smalltalk.send(self, "_announcer", [])]);
-    return self;
-}
-}),
-smalltalk.HLWorkspaceModel);
-
 
 smalltalk.addMethod(
 "_on_",

+ 26 - 102
js/Helios-Workspace.js

@@ -204,12 +204,12 @@ selector: "clear",
 category: 'actions',
 fn: function () {
     var self = this;
-    smalltalk.send(self, "_val_", [""]);
+    smalltalk.send(self, "_contents_", [""]);
     return self;
 },
 args: [],
-source: "clear\x0a      self val: ''",
-messageSends: ["val:"],
+source: "clear\x0a      self contents: ''",
+messageSends: ["contents:"],
 referencedClasses: []
 }),
 smalltalk.HLCodeWidget);
@@ -219,11 +219,11 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "contents",
 category: 'accessing',
-fn: function () {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@editor'], "_getValue", []);
-    return $1;
+fn: function (){
+var self=this;
+var $1;
+$1=smalltalk.send(self["@editor"],"_getValue",[]);
+return $1;
 },
 args: [],
 source: "contents\x0a\x09^ editor getValue",
@@ -237,14 +237,12 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "contents:",
 category: 'accessing',
-fn: function (aString) {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@editor'], "_setValue_", [aString]);
-    return $1;
-},
+fn: function (aString){
+var self=this;
+smalltalk.send(self["@editor"],"_setValue_",[aString]);
+return self},
 args: ["aString"],
-source: "contents: aString\x0a\x09^ editor setValue: aString",
+source: "contents: aString\x0a\x09editor setValue: aString",
 messageSends: ["setValue:"],
 referencedClasses: []
 }),
@@ -394,7 +392,7 @@ fn: function () {
     var self = this;
     var $1;
     if (($receiver = self['@model']) == nil || $receiver == undefined) {
-        self['@model'] = smalltalk.send(smalltalk.HLCodeModel || HLCodeModel, "_new", []);
+        smalltalk.send(self, "_model_", [smalltalk.send(smalltalk.HLCodeModel || HLCodeModel, "_new", [])]);
         $1 = self['@model'];
     } else {
         $1 = self['@model'];
@@ -402,8 +400,8 @@ fn: function () {
     return $1;
 },
 args: [],
-source: "model\x0a\x09^ model ifNil: [ model := HLCodeModel new ]",
-messageSends: ["ifNil:", "new"],
+source: "model\x0a\x09^ model ifNil: [ \x0a    \x09self model: HLCodeModel new.\x0a\x09\x09model ]",
+messageSends: ["ifNil:", "model:", "new"],
 referencedClasses: ["HLCodeModel"]
 }),
 smalltalk.HLCodeWidget);
@@ -413,11 +411,10 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "model:",
 category: 'accessing',
-fn: function (aModel) {
-    var self = this;
-    self['@model'] = aModel;
-    return self;
-},
+fn: function (aModel){
+var self=this;
+self["@model"]=aModel;
+return self},
 args: ["aModel"],
 source: "model: aModel\x0a\x09model := aModel",
 messageSends: [],
@@ -614,13 +611,12 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "renderContentOn:",
 category: 'rendering',
-fn: function (html) {
-    var self = this;
-    self['@code'] = smalltalk.send(html, "_textarea", []);
-    smalltalk.send(self, "_setEditorOn_", [smalltalk.send(self['@code'], "_element", [])]);
-    smalltalk.send(self, "_observeWrapper", []);
-    return self;
-},
+fn: function (html){
+var self=this;
+self["@code"]=smalltalk.send(html,"_textarea",[]);
+smalltalk.send(self,"_setEditorOn_",[smalltalk.send(self["@code"],"_element",[])]);
+smalltalk.send(self,"_observeWrapper",[]);
+return self},
 args: ["html"],
 source: "renderContentOn: html\x0a    code := html textarea.\x0a    self setEditorOn: code element.\x0a    \x0a    self observeWrapper",
 messageSends: ["textarea", "setEditorOn:", "element", "observeWrapper"],
@@ -628,26 +624,6 @@ referencedClasses: []
 }),
 smalltalk.HLCodeWidget);
 
-smalltalk.addMethod(
-"_renderOn_",
-smalltalk.method({
-selector: "renderOn:",
-category: 'rendering',
-fn: function (html) {
-    var self = this;
-    self['@wrapper'] = smalltalk.send(smalltalk.send(html, "_div", []), "_class_", ["code"]);
-    smalltalk.send(self, "_observeWrapper", []);
-    smalltalk.send(self['@wrapper'], "_with_", [function () {self['@code'] = smalltalk.send(html, "_textarea", []);return self['@code'];}]);
-    smalltalk.send(self, "_setEditorOn_", [smalltalk.send(self['@code'], "_element", [])]);
-    return self;
-},
-args: ["html"],
-source: "renderOn: html\x0a    wrapper := html div class: 'code'.\x0a    self observeWrapper.\x0a    wrapper with: [code := html textarea].\x0a    self setEditorOn: code element.\x0a    \x0a",
-messageSends: ["class:", "div", "observeWrapper", "with:", "textarea", "setEditorOn:", "element"],
-referencedClasses: []
-}),
-smalltalk.HLCodeWidget);
-
 smalltalk.addMethod(
 "_selection",
 smalltalk.method({
@@ -753,41 +729,6 @@ referencedClasses: []
 }),
 smalltalk.HLCodeWidget);
 
-smalltalk.addMethod(
-"_val",
-smalltalk.method({
-selector: "val",
-category: 'accessing',
-fn: function () {
-    var self = this;
-    var $1;
-    $1 = smalltalk.send(self['@code'], "_getValue", []);
-    return $1;
-},
-args: [],
-source: "val\x0a\x09^ code getValue",
-messageSends: ["getValue"],
-referencedClasses: []
-}),
-smalltalk.HLCodeWidget);
-
-smalltalk.addMethod(
-"_val_",
-smalltalk.method({
-selector: "val:",
-category: 'accessing',
-fn: function (aString) {
-    var self = this;
-    smalltalk.send(self['@code'], "_setValue_", [aString]);
-    return self;
-},
-args: ["aString"],
-source: "val: aString\x0a    code setValue: aString",
-messageSends: ["setValue:"],
-referencedClasses: []
-}),
-smalltalk.HLCodeWidget);
-
 
 
 smalltalk.addClass('HLWorkspace', smalltalk.HLWidget, ['model', 'codeWidget'], 'Helios-Workspace');
@@ -1108,23 +1049,6 @@ referencedClasses: []
 }),
 smalltalk.HLWorkspaceModel);
 
-smalltalk.addMethod(
-"_subscribe_",
-smalltalk.method({
-selector: "subscribe:",
-category: 'actions',
-fn: function (aWidget) {
-    var self = this;
-    smalltalk.send(aWidget, "_subscribeTo_", [smalltalk.send(self, "_announcer", [])]);
-    return self;
-},
-args: ["aWidget"],
-source: "subscribe: aWidget\x0a\x09aWidget subscribeTo: self announcer",
-messageSends: ["subscribeTo:", "announcer"],
-referencedClasses: []
-}),
-smalltalk.HLWorkspaceModel);
-
 
 smalltalk.addMethod(
 "_on_",

+ 4 - 10
st/Helios-Browser.st

@@ -528,6 +528,10 @@ allProtocol
 	^ '-- All --'
 !
 
+announcer
+	^ announcer ifNil: [ announcer := Announcer new ]
+!
+
 environment
 	^ environment ifNil: [ HLManager current environment ]
 !
@@ -620,16 +624,6 @@ showInstance: aBoolean
     self announcer announce: HLShowInstanceToggled new
 ! !
 
-!HLBrowserModel methodsFor: 'announcements'!
-
-announcer
-	^ announcer ifNil: [ announcer := Announcer new ]
-!
-
-subscribe: aWidget
-	aWidget subscribeTo: self announcer
-! !
-
 !HLBrowserModel class methodsFor: 'actions'!
 
 on: anEnvironment

+ 12 - 2
st/Helios-Core.st

@@ -79,8 +79,8 @@ renderContentOn: html
 renderOn: html
     self registerBindings.
 
-	wrapper := html div with: [
-    	self renderContentOn: html ]
+	wrapper := html div.
+    [ :renderer | self renderContentOn: renderer ] appendToJQuery: wrapper asJQuery
 ! !
 
 !HLWidget methodsFor: 'updating'!
@@ -197,6 +197,10 @@ selectedItem: anObject
 
 !HLListWidget methodsFor: 'actions'!
 
+activateFirstListItem
+	self activateListItem: (window jQuery: ((wrapper asJQuery find: 'li') get: 0))
+!
+
 activateListItem: aListItem
 	| parent position |
     
@@ -218,6 +222,12 @@ activateListItem: aListItem
    self selectItem: (self items at: (aListItem attr: 'list-data') asNumber)
 !
 
+focus
+	super focus.
+    self items isEmpty ifFalse: [ 
+		self selectedItem ifNil: [ self activateFirstListItem ] ]
+!
+
 selectItem: anObject
 	self selectedItem: anObject
 ! !

+ 5 - 24
st/Helios-Workspace.st

@@ -66,7 +66,7 @@ contents
 !
 
 contents: aString
-	^ editor setValue: aString
+	editor setValue: aString
 !
 
 currentLine
@@ -80,7 +80,9 @@ currentLineOrSelection
 !
 
 model
-	^ model ifNil: [ model := HLCodeModel new ]
+	^ model ifNil: [ 
+    	self model: HLCodeModel new.
+		model ]
 !
 
 model: aModel
@@ -113,20 +115,12 @@ selectionStart
 
 selectionStart: anInteger
    code element selectionStart: anInteger
-!
-
-val
-	^ code getValue
-!
-
-val: aString
-    code setValue: aString
 ! !
 
 !HLCodeWidget methodsFor: 'actions'!
 
 clear
-      self val: ''
+      self contents: ''
 !
 
 doIt
@@ -250,13 +244,6 @@ renderContentOn: html
     self setEditorOn: code element.
     
     self observeWrapper
-!
-
-renderOn: html
-    wrapper := html div class: 'code'.
-    self observeWrapper.
-    wrapper with: [code := html textarea].
-    self setEditorOn: code element.
 ! !
 
 HLWidget subclass: #HLWorkspace
@@ -346,12 +333,6 @@ environment: anEnvironment
 	environment := anEnvironment
 ! !
 
-!HLWorkspaceModel methodsFor: 'actions'!
-
-subscribe: aWidget
-	aWidget subscribeTo: self announcer
-! !
-
 !HLWorkspaceModel methodsFor: 'reactions'!
 
 onKeyDown: anEvent