Dealing with issues regarding a gui editor for a class

Let’s say one has a data class MyCircle and a gui Class MyCircleGui which displays controls for this class. The gui is constructed by calling aMyCircle.edit; MyCircle {

…

edit { ^MyCircleGui(this) }

}

Now, if I call .edit again on a MyCircle I don’t want it to construct a new gui window if there is one already open: one must keep track of which windows are open. One solution to this problem is to have an IdentityDictionary as a class variable where one adds the window of a MyCircleGui when the class is created and delete it when the window is closed.

MyCircle {

classvar <>instances;


 * new{ |aMyCircle|

instances = instances ?? {IdentityDictionary.new};

if(instances.keys.includes(aMyCircle).not){

var view,window,flow;

window = Window(…)

// add guis to window here.

window.front;

window.onClose_{instances.removeAt(aMyCircle)}; instances.put(aMyCircle,window);

}

{ instances[aMyCircle].front }

}


 * closeAll{

instances.do{ |window| if(window.isClosed.not){window.close} }

}

…

edit { ^MyCircleGui(this) }

}

This takes care of the open windows, and if one wants to close all the current open windows one can just call MyCircleGui.closeAll.