Rework Stack (or Card) Script Using Framework Messages

Now I'm going to rework some of your existing application handlers (preOpenStack and resizeStack) to take advantage of framework messages.

Edit Stack Script

Edit Stack Script

The Article Maestro stack defines the preOpenStack and resizeStack handlers in the stack script so I am going to edit that script.

What Is Going On?

What Is Going On?

The preOpenStack message in Article Maestro does a few things.

1) Displays the registration dialog using Zygodact.

2) Performs some operations that should only happen the first time the stack is opened during a session.

Both of these operations can take advantage of framework messages. The registration process is something tied to the application as a whole, not the main application window. I am going to decouple the registration process from the main window by moving this code to the glxapp_initializeApplication message in the application stack script.

The code should only run once can take advantage of the PreOpenWindow message that the framework sends to managed windows. This message has a parameter specifying whether the window is being opened for the first time during a session. The reason this might be important is that on OS X it is common to be able to close the main application but not quit the application. When the user reopens the main window there is no reason to run the initialization code again.

Edit application Stack Script

Edit application Stack Script

I will start by moving the registration code. I edit the script of the application stack.

Locate glxapp_initializeApplication

Locate glxapp_initializeApplication

Now I locate the glxapp_initializeApplication handler in the script.

I cut the registration code from the preOpenStack script in the Article Maestro stack script.

And I paste it into the glxapp_initializeApplication handler. Now the registration dialog will show up when the application launches. If the user doesn't have registration information then the application can quit before loading up the main program window.

Using PreOpenWindow

Using PreOpenWindow

Now I will show you how to take advantage of the PreOpenWindow message that is sent to stacks that are being managed by the framework.

I have moved the remaining code in preOpenStack to PreOpenWindow and wrapped it in an if statement. If the window has not been opened yet then run the initialization code.

Switch resizeStack to ResizeView

Switch resizeStack to ResizeView

The Article Maestro stack script also has a resizeStack handler.

I have switched to using the ResizeView handler that the framework sends. resizeStack is sent when the user resizes a stack window. If your program window has multiple cards then you usually only resize the controls on the visible card. ResizeView is sent when navigating to different cards so that you can make sure your interface always matches the current size of the stack window.

0 Comments

Add your comment

E-Mail me when someone replies to this comment