瀏覽代碼

Added Dictionary>>keyAtValue: and more Inspector behavior. Still not working

Sebastian Sastre 11 年之前
父節點
當前提交
9a709fba17
共有 6 個文件被更改,包括 267 次插入29 次删除
  1. 59 6
      js/Helios-Inspector.deploy.js
  2. 90 17
      js/Helios-Inspector.js
  3. 30 0
      js/Kernel-Collections.deploy.js
  4. 40 0
      js/Kernel-Collections.js
  5. 36 6
      st/Helios-Inspector.st
  6. 12 0
      st/Kernel-Collections.st

+ 59 - 6
js/Helios-Inspector.deploy.js

@@ -40,9 +40,9 @@ smalltalk.method({
 selector: "ensureModel",
 fn: function (){
 var self=this;
+smalltalk.send(self,"_observeVariables",[]);
 if(($receiver = self["@model"]) == nil || $receiver == undefined){
 smalltalk.send(self,"_model_",[smalltalk.send(self,"_model",[])]);
-smalltalk.send(self,"_observeVariables",[]);
 } else {
 self["@model"];
 };
@@ -269,15 +269,17 @@ smalltalk.method({
 selector: "observeVariables",
 fn: function (){
 var self=this;
-var $1,$2;
+var $1,$2,$3,$4;
 $1=smalltalk.send(smalltalk.send(self,"_variables",[]),"_announcer",[]);
 smalltalk.send($1,"_on_do_",[(smalltalk.HLRefreshRequested || HLRefreshRequested),(function(ann){
 return smalltalk.send(self,"_onRefresh",[]);
 })]);
-smalltalk.send($1,"_on_do_",[(smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),(function(ann){
+$2=smalltalk.send($1,"_yourself",[]);
+$3=smalltalk.send(smalltalk.send(self,"_model",[]),"_announcer",[]);
+smalltalk.send($3,"_on_do_",[(smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),(function(ann){
 return smalltalk.send(self,"_onInstanceVariableSelected",[]);
 })]);
-$2=smalltalk.send($1,"_yourself",[]);
+$4=smalltalk.send($3,"_yourself",[]);
 return self}
 }),
 smalltalk.HLInspector);
@@ -308,7 +310,7 @@ smalltalk.method({
 selector: "onInstanceVariableSelected",
 fn: function (){
 var self=this;
-smalltalk.send(self,"_halt",[]);
+smalltalk.send(self,"_refreshDisplay",[]);
 return self}
 }),
 smalltalk.HLInspector);
@@ -509,7 +511,7 @@ smalltalk.method({
 selector: "renderContentOn:",
 fn: function (html){
 var self=this;
-smalltalk.send(smalltalk.send(html,"_div",[]),"_with_",[smalltalk.send(smalltalk.send(self["@model"],"_selection",[]),"_printString",[])]);
+smalltalk.send(smalltalk.send(html,"_div",[]),"_with_",[smalltalk.send(smalltalk.send(self["@model"],"_selectedInstVarObject",[]),"_printString",[])]);
 return self}
 }),
 smalltalk.HLInspectorDisplay);
@@ -691,6 +693,19 @@ return self}
 }),
 smalltalk.HLInspectorModel);
 
+smalltalk.addMethod(
+"_instVarObjectAt_",
+smalltalk.method({
+selector: "instVarObjectAt:",
+fn: function (anInstVarName){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(self,"_variables",[]),"_at_",[anInstVarName]);
+return $1;
+}
+}),
+smalltalk.HLInspectorModel);
+
 smalltalk.addMethod(
 "_onKeyDown_",
 smalltalk.method({
@@ -719,6 +734,31 @@ return self}
 }),
 smalltalk.HLInspectorModel);
 
+smalltalk.addMethod(
+"_selectedInstVar_",
+smalltalk.method({
+selector: "selectedInstVar:",
+fn: function (anInstVarObject){
+var self=this;
+smalltalk.send(self,"_halt",[]);
+smalltalk.send(self,"_selection_",[smalltalk.send(smalltalk.send(self,"_variables",[]),"_keyAtValue_",[anInstVarObject])]);
+return self}
+}),
+smalltalk.HLInspectorModel);
+
+smalltalk.addMethod(
+"_selectedInstVarObject",
+smalltalk.method({
+selector: "selectedInstVarObject",
+fn: function (){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_instVarObjectAt_",[smalltalk.send(self,"_selection",[])]);
+return $1;
+}
+}),
+smalltalk.HLInspectorModel);
+
 smalltalk.addMethod(
 "_selection",
 smalltalk.method({
@@ -743,6 +783,7 @@ selector: "selection:",
 fn: function (anObject){
 var self=this;
 self["@selection"]=anObject;
+smalltalk.send(smalltalk.send(self,"_announcer",[]),"_announce_",[smalltalk.send((smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),"_on_",[self["@selection"]])]);
 return self}
 }),
 smalltalk.HLInspectorModel);
@@ -913,6 +954,18 @@ return self}
 }),
 smalltalk.HLInspectorVariables);
 
+smalltalk.addMethod(
+"_selectItem_",
+smalltalk.method({
+selector: "selectItem:",
+fn: function (anObject){
+var self=this;
+smalltalk.send(self,"_selectItem_",[anObject],smalltalk.HLNavigationListWidget);
+smalltalk.send(smalltalk.send(self,"_model",[]),"_selectedInstVar_",[anObject]);
+return self}
+}),
+smalltalk.HLInspectorVariables);
+
 smalltalk.addMethod(
 "_selection",
 smalltalk.method({

+ 90 - 17
js/Helios-Inspector.js

@@ -51,16 +51,16 @@ selector: "ensureModel",
 category: 'actions',
 fn: function (){
 var self=this;
+smalltalk.send(self,"_observeVariables",[]);
 if(($receiver = self["@model"]) == nil || $receiver == undefined){
 smalltalk.send(self,"_model_",[smalltalk.send(self,"_model",[])]);
-smalltalk.send(self,"_observeVariables",[]);
 } else {
 self["@model"];
 };
 return self},
 args: [],
-source: "ensureModel\x0a\x09\x22Sends the #model: initialization message if needed.\x22\x0a\x0a\x09model ifNil:[\x0a\x09\x09self model: self model.\x0a\x09\x09self observeVariables]\x0a\x09",
-messageSends: ["ifNil:", "model:", "model", "observeVariables"],
+source: "ensureModel\x0a\x09\x22Sends the #model: initialization message if needed.\x22\x0a\x0a\x09self observeVariables.\x0a        \x0a\x09model ifNil:[\x0a\x09\x09self model: self model]\x0a\x09",
+messageSends: ["observeVariables", "ifNil:", "model:", "model"],
 referencedClasses: []
 }),
 smalltalk.HLInspector);
@@ -360,19 +360,21 @@ selector: "observeVariables",
 category: 'actions',
 fn: function (){
 var self=this;
-var $1,$2;
+var $1,$2,$3,$4;
 $1=smalltalk.send(smalltalk.send(self,"_variables",[]),"_announcer",[]);
 smalltalk.send($1,"_on_do_",[(smalltalk.HLRefreshRequested || HLRefreshRequested),(function(ann){
 return smalltalk.send(self,"_onRefresh",[]);
 })]);
-smalltalk.send($1,"_on_do_",[(smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),(function(ann){
+$2=smalltalk.send($1,"_yourself",[]);
+$3=smalltalk.send(smalltalk.send(self,"_model",[]),"_announcer",[]);
+smalltalk.send($3,"_on_do_",[(smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),(function(ann){
 return smalltalk.send(self,"_onInstanceVariableSelected",[]);
 })]);
-$2=smalltalk.send($1,"_yourself",[]);
+$4=smalltalk.send($3,"_yourself",[]);
 return self},
 args: [],
-source: "observeVariables\x0a\x0a\x09self variables announcer \x0a    \x09on: HLRefreshRequested do:[:ann| self onRefresh];\x0a        on: HLInstanceVariableSelected do:[:ann| self onInstanceVariableSelected];\x0a        yourself ",
-messageSends: ["on:do:", "onRefresh", "announcer", "variables", "onInstanceVariableSelected", "yourself"],
+source: "observeVariables\x0a\x0a\x09self variables announcer \x0a    \x09on: HLRefreshRequested do:[:ann| self onRefresh];\x0a        yourself.\x0a\x0a\x09self model announcer\x0a        on: HLInstanceVariableSelected do:[:ann| self onInstanceVariableSelected];\x0a        yourself.\x0a        ",
+messageSends: ["on:do:", "onRefresh", "announcer", "variables", "yourself", "onInstanceVariableSelected", "model"],
 referencedClasses: ["HLRefreshRequested", "HLInstanceVariableSelected"]
 }),
 smalltalk.HLInspector);
@@ -414,11 +416,11 @@ selector: "onInstanceVariableSelected",
 category: 'reactions',
 fn: function (){
 var self=this;
-smalltalk.send(self,"_halt",[]);
+smalltalk.send(self,"_refreshDisplay",[]);
 return self},
 args: [],
-source: "onInstanceVariableSelected\x0a\x0a\x09self halt.",
-messageSends: ["halt"],
+source: "onInstanceVariableSelected\x0a\x0a\x09self refreshDisplay",
+messageSends: ["refreshDisplay"],
 referencedClasses: []
 }),
 smalltalk.HLInspector);
@@ -700,11 +702,11 @@ selector: "renderContentOn:",
 category: 'rendering',
 fn: function (html){
 var self=this;
-smalltalk.send(smalltalk.send(html,"_div",[]),"_with_",[smalltalk.send(smalltalk.send(self["@model"],"_selection",[]),"_printString",[])]);
+smalltalk.send(smalltalk.send(html,"_div",[]),"_with_",[smalltalk.send(smalltalk.send(self["@model"],"_selectedInstVarObject",[]),"_printString",[])]);
 return self},
 args: ["html"],
-source: "renderContentOn: html\x0a\x09\x0a    html div with: model selection printString\x0a    ",
-messageSends: ["with:", "printString", "selection", "div"],
+source: "renderContentOn: html\x0a\x09\x0a    html div with: model selectedInstVarObject printString\x0a    ",
+messageSends: ["with:", "printString", "selectedInstVarObject", "div"],
 referencedClasses: []
 }),
 smalltalk.HLInspectorDisplay);
@@ -951,6 +953,24 @@ referencedClasses: []
 }),
 smalltalk.HLInspectorModel);
 
+smalltalk.addMethod(
+"_instVarObjectAt_",
+smalltalk.method({
+selector: "instVarObjectAt:",
+category: 'actions',
+fn: function (anInstVarName){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(self,"_variables",[]),"_at_",[anInstVarName]);
+return $1;
+},
+args: ["anInstVarName"],
+source: "instVarObjectAt: anInstVarName\x0a\x0a\x09^ self variables at: anInstVarName",
+messageSends: ["at:", "variables"],
+referencedClasses: []
+}),
+smalltalk.HLInspectorModel);
+
 smalltalk.addMethod(
 "_onKeyDown_",
 smalltalk.method({
@@ -984,6 +1004,41 @@ referencedClasses: []
 }),
 smalltalk.HLInspectorModel);
 
+smalltalk.addMethod(
+"_selectedInstVar_",
+smalltalk.method({
+selector: "selectedInstVar:",
+category: 'actions',
+fn: function (anInstVarObject){
+var self=this;
+smalltalk.send(self,"_halt",[]);
+smalltalk.send(self,"_selection_",[smalltalk.send(smalltalk.send(self,"_variables",[]),"_keyAtValue_",[anInstVarObject])]);
+return self},
+args: ["anInstVarObject"],
+source: "selectedInstVar: anInstVarObject\x0a    self halt.\x0a\x09self selection: (self variables keyAtValue: anInstVarObject)",
+messageSends: ["halt", "selection:", "keyAtValue:", "variables"],
+referencedClasses: []
+}),
+smalltalk.HLInspectorModel);
+
+smalltalk.addMethod(
+"_selectedInstVarObject",
+smalltalk.method({
+selector: "selectedInstVarObject",
+category: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_instVarObjectAt_",[smalltalk.send(self,"_selection",[])]);
+return $1;
+},
+args: [],
+source: "selectedInstVarObject\x0a\x0a\x09^ self instVarObjectAt: self selection\x0a    ",
+messageSends: ["instVarObjectAt:", "selection"],
+referencedClasses: []
+}),
+smalltalk.HLInspectorModel);
+
 smalltalk.addMethod(
 "_selection",
 smalltalk.method({
@@ -1014,11 +1069,12 @@ category: 'accessing',
 fn: function (anObject){
 var self=this;
 self["@selection"]=anObject;
+smalltalk.send(smalltalk.send(self,"_announcer",[]),"_announce_",[smalltalk.send((smalltalk.HLInstanceVariableSelected || HLInstanceVariableSelected),"_on_",[self["@selection"]])]);
 return self},
 args: ["anObject"],
-source: "selection: anObject\x0a\x0a\x09selection := anObject",
-messageSends: [],
-referencedClasses: []
+source: "selection: anObject\x0a\x0a\x09selection := anObject.\x0a\x0a\x09self announcer announce: (HLInstanceVariableSelected on: selection)\x0a    ",
+messageSends: ["announce:", "on:", "announcer"],
+referencedClasses: ["HLInstanceVariableSelected"]
 }),
 smalltalk.HLInspectorModel);
 
@@ -1248,6 +1304,23 @@ referencedClasses: []
 }),
 smalltalk.HLInspectorVariables);
 
+smalltalk.addMethod(
+"_selectItem_",
+smalltalk.method({
+selector: "selectItem:",
+category: 'reactions',
+fn: function (anObject){
+var self=this;
+smalltalk.send(self,"_selectItem_",[anObject],smalltalk.HLNavigationListWidget);
+smalltalk.send(smalltalk.send(self,"_model",[]),"_selectedInstVar_",[anObject]);
+return self},
+args: ["anObject"],
+source: "selectItem: anObject\x0a\x0a\x09super selectItem: anObject.\x0a    \x0a    self model selectedInstVar: anObject",
+messageSends: ["selectItem:", "selectedInstVar:", "model"],
+referencedClasses: []
+}),
+smalltalk.HLInspectorVariables);
+
 smalltalk.addMethod(
 "_selection",
 smalltalk.method({

+ 30 - 0
js/Kernel-Collections.deploy.js

@@ -1314,6 +1314,23 @@ return self}
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+"_keyAtValue_",
+smalltalk.method({
+selector: "keyAtValue:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(smalltalk.send(self,"_associations",[]),"_detect_ifNone_",[(function(k,v){
+return smalltalk.send(v,"__eq_eq",[anObject]);
+}),(function(){
+return smalltalk.send(self,"_error_",["Not found"]);
+})]),"_key",[]);
+return $1;
+}
+}),
+smalltalk.Dictionary);
+
 smalltalk.addMethod(
 "_keys",
 smalltalk.method({
@@ -1349,6 +1366,19 @@ return self}
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+"_valueAt_",
+smalltalk.method({
+selector: "valueAt:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_associationsDo_",[(2)]);
+return $1;
+}
+}),
+smalltalk.Dictionary);
+
 smalltalk.addMethod(
 "_values",
 smalltalk.method({

+ 40 - 0
js/Kernel-Collections.js

@@ -1750,6 +1750,28 @@ referencedClasses: []
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+"_keyAtValue_",
+smalltalk.method({
+selector: "keyAtValue:",
+category: 'accessing',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(smalltalk.send(smalltalk.send(self,"_associations",[]),"_detect_ifNone_",[(function(k,v){
+return smalltalk.send(v,"__eq_eq",[anObject]);
+}),(function(){
+return smalltalk.send(self,"_error_",["Not found"]);
+})]),"_key",[]);
+return $1;
+},
+args: ["anObject"],
+source: "keyAtValue: anObject\x0a\x0a\x09^ (self associations \x0a    \x09detect:[:k :v| v == anObject] \x0a    \x09ifNone:[self error: 'Not found']) key",
+messageSends: ["key", "detect:ifNone:", "==", "error:", "associations"],
+referencedClasses: []
+}),
+smalltalk.Dictionary);
+
 smalltalk.addMethod(
 "_keys",
 smalltalk.method({
@@ -1795,6 +1817,24 @@ referencedClasses: []
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+"_valueAt_",
+smalltalk.method({
+selector: "valueAt:",
+category: 'accessing',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_associationsDo_",[(2)]);
+return $1;
+},
+args: ["anObject"],
+source: "valueAt: anObject\x0a\x0a\x09^ self associationsDo:2",
+messageSends: ["associationsDo:"],
+referencedClasses: []
+}),
+smalltalk.Dictionary);
+
 smalltalk.addMethod(
 "_values",
 smalltalk.method({

+ 36 - 6
st/Helios-Inspector.st

@@ -58,9 +58,10 @@ variables
 ensureModel
 	"Sends the #model: initialization message if needed."
 
+	self observeVariables.
+        
 	model ifNil:[
-		self model: self model.
-		self observeVariables]
+		self model: self model]
 !
 
 inspect: anObject
@@ -97,8 +98,11 @@ observeVariables
 
 	self variables announcer 
     	on: HLRefreshRequested do:[:ann| self onRefresh];
+        yourself.
+
+	self model announcer
         on: HLInstanceVariableSelected do:[:ann| self onInstanceVariableSelected];
-        yourself
+        yourself.
 !
 
 open
@@ -167,7 +171,7 @@ onInspectIt
 
 onInstanceVariableSelected
 
-	self halt.
+	self refreshDisplay
 !
 
 onPrintIt
@@ -227,7 +231,7 @@ model: aModel
 
 renderContentOn: html
 	
-    html div with: model selection printString
+    html div with: model selectedInstVarObject printString
 ! !
 
 Object subclass: #HLInspectorModel
@@ -263,6 +267,11 @@ inspectee: anObject
 	inspectee := anObject
 !
 
+selectedInstVarObject
+
+	^ self instVarObjectAt: self selection
+!
+
 selection
 
 	^ selection ifNil:[self initializeSelection]
@@ -270,7 +279,9 @@ selection
 
 selection: anObject
 
-	selection := anObject
+	selection := anObject.
+
+	self announcer announce: (HLInstanceVariableSelected on: selection)
 !
 
 variables
@@ -306,6 +317,16 @@ inspect: anObject on: anInspector
 	inspectee inspectOn: anInspector
 !
 
+instVarObjectAt: anInstVarName
+
+	^ self variables at: anInstVarName
+!
+
+selectedInstVar: anInstVarObject
+    self halt.
+	self selection: (self variables keyAtValue: anInstVarObject)
+!
+
 subscribe: aWidget
 	aWidget subscribeTo: self announcer
 ! !
@@ -418,6 +439,15 @@ initializeItems
 	^ items := self model variables keys
 ! !
 
+!HLInspectorVariables methodsFor: 'reactions'!
+
+selectItem: anObject
+
+	super selectItem: anObject.
+    
+    self model selectedInstVar: anObject
+! !
+
 !HLInspectorVariables methodsFor: 'rendering'!
 
 renderButtonsOn: html

+ 12 - 0
st/Kernel-Collections.st

@@ -570,10 +570,22 @@ at: aKey put: aValue
 	>
 !
 
+keyAtValue: anObject
+
+	^ (self associations 
+    	detect:[:k :v| v == anObject] 
+    	ifNone:[self error: 'Not found']) key
+!
+
 keys
 	^keys copy
 !
 
+valueAt: anObject
+
+	^ self associationsDo:2
+!
+
 values
 	^values copy
 ! !