It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming JavaScript Forum

Abstract classes.

Abstract classes.

Postby myranalis on Fri Oct 09, 2009 6:28 am

Morning all. I've finished my first script for photoshop 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.

My problem is 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. As far as I can tell $ShowDialog contains the write function. I'm wondering if it is unhappy that the dialog is defined in an included file??

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 all
function 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;       
}
myranalis
 
Posts: 1
Joined: Fri Oct 09, 2009 5:37 am

Who is online

Users browsing this forum: No registered users and 8 guests