Re: Importing a view with code

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

Re: Importing a view with code

Keith Alcock
This topic is from mid August 2000 and no longer available on some news
servers, but in case anyone runs into the same problem, it would be good
if it was recorded for DSDN.

The old code that Ian found worked for a long time and I am grateful for
it.  However, there is a problem with the "ri save: vr load."  The
resource gets read in and then saved again to disk.  Normally this
doesn't matter and I believe that the reason for doing this is that an
icon gets changed as a side-effect to the save operation.  There is a
problem, however, if you upgrade your version of Dolphin, or anything
else that changes the versioning of objects that are contained in the
binary stream.  When read in, the objects are automatically updated and
then written back out.  Attempts to read the views back in with an older
version of Dolphin will result in errors and the older version views may
effectively be lost.

(Of course the whole reason for doing this was to be able to but the
views under external version control, so the situation wasn't as bad as
it could have been.)

A version that does not require the save and that seems to work so far
is below.  The last three lines contain the important changes.


loadViewFromFile: aFileName

 | directories parts class viewName viewResource resourceIdentifier
loadedView |
 directories := aFileName subStrings: $\.
 parts := directories last subStrings: $..
 class := Smalltalk at: (parts at: 1).
 viewName := parts at: 2.
 viewResource := ViewResource inSTBFileWithName: aFileName.
 resourceIdentifier := ResourceIdentifier class: class name: viewName.

 resourceIdentifier assign: viewResource.
 loadedView := viewResource load.
 resourceIdentifier resource icon: loadedView icon.

Keith Alcock


Ian Bartholomew wrote:

> Keith,
>
> > The following code nearly gets that far.  The resource browser sees
the

> > new view, but the view composer can't use them quite yet.
> >
> > filename := 'MyShellPresenter.My default view.vu'
> > parts := filename subStrings: $..
> > class := Smalltalk at: (parts at: 1).
> > name := parts at: 2.
> > vr := ViewResource inSTBFileWithName: filename
> > ri := ResourceIdentifier class: class name: name
> >
> > Has anyone done this before or can anyone tell what's missing?
>
> A browse through some old code shows that I once used something like
>
> ri
>    assign: vr;
>    save: vr load
>
> and adding this to your code above does appear to make it all work as
> expected. There may be a better way of doing it though....
>
> Ian