Re: The Trunk: Morphic-mt.895.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Morphic-mt.895.mcz

Nicolas Cellier


2015-04-17 15:58 GMT+02:00 <[hidden email]>:
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.895.mcz

==================== Summary ====================

Name: Morphic-mt.895
Author: mt
Time: 17 April 2015, 3:58:36.602 pm
UUID: 955fb45c-fbb5-d545-8e18-2f22524bcd24
Ancestors: Morphic-mt.894

Added the missing hooks so that text models can not only handle printing but also debugging, exploring, inspecting, and even evaluation.

This avoids having to subclass PluggableTextMorph, TextMorph, and TextEditor for achieving the same variation point.

=============== Diff against Morphic-mt.894 ===============

Item was changed:
  ----- Method: TextEditor>>debugIt (in category 'do-its') -----
  debugIt

+       | receiver context |
-       | method receiver context |
-       (model respondsTo: #doItReceiver)
-               ifTrue:
-                       [receiver := model doItReceiver.
-                       context := model doItContext]
-               ifFalse:
-                       [receiver := context := nil].
        self lineSelectAndEmptyCheck: [^self].
+
+       (model respondsTo: #debugIt:)
+               ifTrue: [^ model perform: #debugIt: with: self selection].
+
+       receiver := (model respondsTo: #doItReceiver)
+               ifTrue: [model doItReceiver]
+               ifFalse: [nil].
+
+       context := (model respondsTo: #doItContext)
+               ifTrue: [model doItContext]
+               ifFalse: [nil].
+
+       (self compileSelectionFor: receiver in: context) ifNotNil: [:method |
+               self debug: method receiver: receiver in: context].!
-       method := self compileSelectionFor: receiver in: context.
-       method notNil ifTrue:
-               [self debug: method receiver: receiver in: context].!

Item was changed:
  ----- Method: TextEditor>>evaluateSelectionAndDo: (in category 'do-its') -----
  evaluateSelectionAndDo: aBlock
        "Treat the current selection as an expression; evaluate it and invoke aBlock with the result."
        | result rcvr ctxt |
        self lineSelectAndEmptyCheck: [^ nil].

+       (model respondsTo: #evaluate:) ifTrue: [
+               ^ aBlock value: (model perform: #evaluate: with: self selection)].
+

In one image with Tweak loaded (http://squeaksource.com/TweakCore)
this change had the effect loosing the ability to do it/print it/inspect it

For example, typing one of most basic Smalltalk expression
  3+4 ->  a Text for '3+4'

This is because the Scripting package installs Object>>evaluate: aBlock ^aBlock value

What are these hooks usefull for? They do not seem in usage currently in the image.

Nicolas

 
        (model respondsTo: #doItReceiver)
                ifTrue: [ rcvr := model doItReceiver.
                                ctxt := model doItContext]
                ifFalse: [rcvr := ctxt := nil].
        result := [
                rcvr class evaluatorClass new
                        evaluate: self selectionAsStream
                        in: ctxt
                        to: rcvr
                        notifying: self
                        ifFail: [morph flash. ^ nil]
                        logged: true.
        ]
                on: OutOfScopeNotification
                do: [ :ex | ex resume: true].

        (model respondsTo: #evaluated:result:) ifTrue: [
                model perform: #evaluated:result: with: self selection with: result].

        ^aBlock value: result!

Item was changed:
  ----- Method: TextEditor>>exploreIt (in category 'do-its') -----
  exploreIt
+
+        self evaluateSelectionAndDo: [:result |
+               (model respondsTo: #exploreIt:result:)
+                       ifTrue: [model
+                               perform: #exploreIt:result:
+                               with: self selection
+                               with: result]
+                       ifFalse: [result explore]].!
-       self evaluateSelectionAndDo: [:result | result explore]!

Item was changed:
  ----- Method: TextEditor>>inspectIt (in category 'do-its') -----
  inspectIt
+
+        self evaluateSelectionAndDo: [:result |
+               (model respondsTo: #inspectIt:result:)
+                       ifTrue: [model
+                               perform: #inspectIt:result:
+                               with: self selection
+                               with: result]
+                       ifFalse: [result inspect]].!
-        self evaluateSelectionAndDo: [:result | result inspect]!





Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Morphic-mt.895.mcz

marcel.taeumel (old)
Hi,

you're right. #evaluate: is too generic if the text editor knows that it actually is an expression. I updated it: http://forum.world.st/The-Trunk-Morphic-mt-953-mcz-td4823480.html

I also added some tests for TextEditor that capture the usage of those hooks.

There are other strange things in TextEditor (e.g. #browseItHere) that indicate that those and similar model callbacks where missing. One goal should be to make the interface of text editors tool-agnostic.

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Morphic-mt.895.mcz

Nicolas Cellier
Thanks Marcel, that was fast!
sometimes I wonder if the fix will not be in the trunk before i ever complain ;)
Most often it is already in the trunk :)

2015-05-01 11:41 GMT+02:00 Marcel Taeumel <[hidden email]>:
Hi,

you're right. #evaluate: is too generic if the text editor knows that it
actually is an expression. I updated it:
http://forum.world.st/The-Trunk-Morphic-mt-953-mcz-td4823480.html

I also added some tests for TextEditor that capture the usage of those
hooks.

There are other strange things in TextEditor (e.g. #browseItHere) that
indicate that those and similar model callbacks where missing. One goal
should be to make the interface of text editors tool-agnostic.

Best,
Marcel



--
View this message in context: http://forum.world.st/Re-The-Trunk-Morphic-mt-895-mcz-tp4823399p4823484.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.