OO & Abstract classes.

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

myranalis

OO & Abstract classes.

Post by myranalis »

Morning all. I've finished my first application and thought I'd try to get fancy and save myself some of the repetative code for future projects by creating a base class I can inherit from. My working code is below - I've culled alot of the irrelevant stuff out.

I've run into a problem though, in that my dialog doesn't show.
And it doesn't help that the debugger doesn't seem to step into the sub class's functions. Is anyone able to point me in the right direction here?

Thanks

Main.jsx
Code: Select all#include "MyDialog.jsx"
#include "AbstractApplicationBase.jsx"

//inherit frrom base class
MyApp.prototype = new AbstractApplicationBase("My App");

//constructor
function MyApp() {};

showDialog = function() {
   
   var form = new MyDialog();
   return form.run();
};
   

runApplication = function() {
   //todo implement this
};
   
   
readParameters = function() {
   return true;
   //todo implement this
};
   
MyApp.prototype.$LaunchCriteria = isCS3Plus;
MyApp.prototype.$ShowDialog = showDialog;
MyApp.prototype.$RunApplication = runApplication;
MyApp.prototype.$ReadParameters = readParameters;

var tmp = new MyApp;
tmp.Run();

AbstractApplicationBase.jsx
Code: Select allfunction AbstractApplicationBase(applicationName) {
   this.APP_NAME = applicationName;
}

//MustOverride functions
AbstractApplicationBase.prototype.$LaunchCriteria = function(){};
AbstractApplicationBase.prototype.$ShowDialog = function(){};
AbstractApplicationBase.prototype.$RunApplication = function(){};
AbstractApplicationBase.prototype.$ReadParameters = function(){};

//public properties
AbstractApplicationBase.prototype.LOGGER = undefined;
AbstractApplicationBase.prototype.USER_DIRECTORY= undefined;
AbstractApplicationBase.prototype.SCRIPT_DIRECTORY= undefined;

//Public methods
AbstractApplicationBase.prototype.Run = function(){
   app.bringToFront();

   if (this.$LaunchCriteria)
   {
      try {
         this._main();
      }
      catch(e) {
         if (e.number != 8007) { // don't report error on user cancel
            showError(e);
         }
      }
   }
};


AbstractApplicationBase.prototype._main = function() {
   
   //default to logging
   this.LOGGING = true;
   this.USER_FOLDER = decodeURI(Folder(Folder.userData)) + "/" + this.APP_NAME.stripSpaces();
      
   if (!this.$ReadParameters)
      return;
      
   this.LOGGER = new solib.Log(this.USER_FOLDER +"/" + this.APP_NAME.stripSpaces() + ".log" , true );
   this.LOGGER.setDebug(this.LOGGING);
      
   if (this.$ShowDialog) {   
      this.$RunApplication;
   }
}

String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

MyDialog.jsx
Code: Select all//Constructor
function MyDialog()
{
   this.windowRef = null;
}

MyDialog.prototype.run = function()
{
   $.writeln ("inside dialog.run");
   var win = new Window("dialog", "MyDialog" ); 
   this.windowRef = win;
   
   // Display the window
   win.show();
   
   return true;      
}