First Enhancement to File List

continued


When starting to copy the file and it's contents between the systems in this manual fashion, it seems like the first thing we'll need is the proper file name for the destination file. When we select the source file in the File List and examine the list menu we find a menu item named "copy name to clipboard". Let's try that.

If you open up a new Workspace (Use the World-->open..-->workspace menus) the contents of the clipboard can easily be examined by direct pasting. This is what I get:

steve@192.168.2.2/develop/squeak/3.5 tutorial/importer-support.released.cs
It's the whole path name. Too much information. We can imagine why having the full path would be useful, but it's not what we need. Let's see if we can figure out how to add a new menu item for just the file name portion getting copied.

At this point I recommend that we create a new project just to hold any code changes we develop to support enhancements to FileList.

Close the open FileLists. We can get them back later. From the World menu, select "open..." and then "morphic project". A new morphic project view will be created. It's name will be "unnamed1" again because we renamed the previous one with that name. Using the halo menu for that morph, move it to another location on the desktop. Give it a new name. I used "FileList-mods". Add a drop shadow for cosmetics. You should have this on your desktop:


Enter that project by clicking on the morph. Once inside you can use the menus World-->appearance...-->desktop color... to pick a new color.

Our strategy will be to modify the menu and write the supporting method, while the remote FileList browser is open. Use the World-->open.. menu and open up a "browser". The first list pane in the browser contains system categories. We can use that to help up find our class. Use the menu in that pane and perform a "find class...". When the prompter opens, type FileList and accept. Since there are several classes that have "FileList" in them, just select the one that is the exact class name match. You can also tell the "find" command you used to take the literal match of what you type by adding a period on the end. Like this: FileList. Only the exact match will be used by the Browser.


I selected the "file list menu" method category and found a method named #fileListMenu:.

The source for that menu shows there's a check made to see if a file is selected. In our case it is, so we should look at the #fileSelectedMenu: next. From there I eventually decided upon the #itemsForAnyFile method.

With Squeak 3.5 the technique of hard coding behavior in FileList methods was changed. The issue was that whenever someone wrote a new enhancement for File List and wanted to support a new file type, methods had to be manually edited. You searched through hard coded menu lists and inserted your new entry. Furthermore, installing a change set from someone else that worked on this same method, but for yet another new behavior, would over write the previous version. Hence the addition of a registry. We are going to add a new menu item but it will be on FileList itself. When creating new FileList services that are provided by other classes, the benefit of a registry technique will be more obvious. The tutorial will not have quite the same level of work required.

In the Squeak 3.2 version of this tutorial a discussion was added about setting better text pane colors. There was a large String in the earlier version of this method. For the #itemsForAnyFile method we have now, the parameter "5" (sent when sizing the new OrderedCollection) is difficult to see because of it's color. So we still have a valid reason to make the colors modification later. Since the "5" is too hard to read here, I selected the "colorPrint" button on the browser and chose "source" for viewing option. We'll fix that colors problem later.

We need to make some progress on writing a new method that will copy only just the file name to the clipboard. Begin by looking over the #seviceCopyName method. I wrote a new method called #serviceCopyJustFileName.
    

Not sure what it will do just yet. But this is a start. Let's go back to our #itemsForAnyFile method and add in our service.


And true to Smalltalk coding form, if you go back to the FileList and examine the menu where we have a file selected on the remote system, there's now a new menu item that says "copy just file name to clipboard"; exactly as we wrote the code.

If you try the new menu item it will do the same thing as the other menu item did, of course. We haven't written the new method behavior yet. So let's go do it.

Here's the existing #copyName method. It should give us pretty good clues concerning what we want to do for a new #copyJustFileName method.


That led me to the #fullName method. Note, I had to change my method category list to "-- all --", which allows me to see all methods on this class, regardless of category.

Looks like we have a "fileName" instance variable. That sounds promising. We should investigate if this is what we want.

We can operate on a Morphic object directly and learn more about the value this instance variable holds. Just for experimentation, open up a new FileList. Select any local file, just to load this instance variable. I picked a relatively small text file.


Activate the "halos" on this FileList. Along the right hand side halos, there's a grey one that looks like a tool or wrench. When you move your mouse over it, it produces a pop-up balloon that says "debug".

Click once on it and a menu like this will be presented:

When you select the "inspect model" menu item an Inspector will open on the FileList model object. Click on the instance variable we are interested in, fileName, and you will see that this is exactly what we need.

Close both the Inspector window and the FileList.

Let's go write our new method, using the #copyName method as a guide.

We need to go back and ensure our new #copyJustFileName method is called by our service.

Continue to the next page of first FileList enhancement.

Back to the beginning of this example.