[squeak-dev] The Trunk: Tools-mt.1074.mcz
Marcel Taeumel
marcel.taeumel at hpi.de
Mon Nov 29 16:41:44 UTC 2021
Hi Christoph --
Given that I needed to mimic the flexibility of morph's properties for the sake of robustness, we can add an extra "properties" instVar if necessary. Actually adding instVars for a non-essential extra in the Workspace tool felt overkill. We might want to have this for all kinds of models. Would make extensions easier. So, it's not a "new thing" per se, but an idea present in morphs applied to models.
Why do you see this as a "crazy hack"? It's rather interesting to have a tool that is able to reflect on its internals the same way as it does on external (user specified) information. ;-) Feels like a the textual version of a halo for a command line (or text buffer).
If you think that the risk of a name collision in bindings is too high, we can choose a different prefix or add an extra dictionary instVar. But then we would loose that cool self-reflection feature. :-O
> I only need to print "_fileDirectory" in a workspace and the menu will break.
That's a bug. Why should a read operation change the bindings dictionary? I did not know that. Should be an easy fix. :-)
Best,
Marcel
Am 27.11.2021 21:46:44 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
Hi Marcel,
crazy hack, but it bites with the fact that storing underscore variables in a Workspace is a legal operation. I only need to print "_fileDirectory" in a workspace and the menu will break. Could we please just use a separate dictionary for the properties? :-)
Furthermore, how many different properties can actually be stored in a Workspace? So far I only counted 3 different keys - does this really justify the use of the Variable State pattern?
Best,
Christoph
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Donnerstag, 25. November 2021 11:44:04
An: squeak-dev at lists.squeakfoundation.org; packages at lists.squeakfoundation.org
Betreff: [squeak-dev] The Trunk: Tools-mt.1074.mcz
Marcel Taeumel uploaded a new version of Tools to project The Trunk:
http://source.squeak.org/trunk/Tools-mt.1074.mcz [http://source.squeak.org/trunk/Tools-mt.1074.mcz]
==================== Summary ====================
Name: Tools-mt.1074
Author: mt
Time: 25 November 2021, 11:44:01.944354 am
UUID: 39954290-b416-f242-a5b0-c7aea0e3c6a6
Ancestors: Tools-mt.1073
Adds a property protocol to Workspace to avoid having to go through #containingWindow to store extra stuff, which does not even work for MVC, just for morphs (i.e., SystemWindow, not StandardSystemView). Reuses a workspace's "bindings" with each property being prefixed with a "_" to not interfere with regular bindings.
Note that such extra properties have already been added to #containingWindow in the past.
=============== Diff against Tools-mt.1073 ===============
Item was added:
+ ----- Method: Workspace>>hasProperty: (in category 'binding - properties') -----
+ hasProperty: aSymbol
+
+ | propertyValue |
+ propertyValue := self valueOfProperty: aSymbol.
+ propertyValue ifNil: [^ false].
+ propertyValue == false ifTrue: [^ false].
+ ^ true!
Item was changed:
----- Method: Workspace>>initialize (in category 'initialize-release') -----
initialize
super initialize.
+ bindings := Dictionary new.
- self initializeBindings.
acceptDroppedMorphs := false.
mustDeclareVariables := self class declareVariablesAutomatically not.
environment := Environment current!
Item was removed:
- ----- Method: Workspace>>initializeBindings (in category 'binding') -----
- initializeBindings
-
- bindings := Dictionary new!
Item was added:
+ ----- Method: Workspace>>removeProperty: (in category 'binding - properties') -----
+ removeProperty: aSymbol
+
+ bindings removeKey: ('_', aSymbol) asSymbol ifAbsent: [].!
Item was added:
+ ----- Method: Workspace>>resetBindings (in category 'binding') -----
+ resetBindings
+ "Remove all bindings that are not prefixed with an $_. See #setProperty:toValue:."
+
+ bindings keysAndValuesRemove: [:key :value | key first ~= $_]!
Item was added:
+ ----- Method: Workspace>>setProperty:toValue: (in category 'binding - properties') -----
+ setProperty: aSymbol toValue: anObject
+
+ anObject ifNil: [^ self removeProperty: aSymbol].
+ bindings at: ('_', aSymbol) asSymbol put: anObject.!
Item was added:
+ ----- Method: Workspace>>valueOfProperty: (in category 'binding - properties') -----
+ valueOfProperty: aSymbol
+
+ ^ self valueOfProperty: aSymbol ifAbsent: nil!
Item was added:
+ ----- Method: Workspace>>valueOfProperty:ifAbsent: (in category 'binding - properties') -----
+ valueOfProperty: aSymbol ifAbsent: aBlock
+
+ ^ bindings at: ('_', aSymbol) asSymbol ifAbsent: aBlock!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211129/b1e6501e/attachment.html>
More information about the Squeak-dev
mailing list
|