/** Copyright 2015 Tony Kuyper  */

function PSActionSetLoader(csInterface,debug) 
{
	this.csInterface = csInterface;
	this.debug = debug;
}

PSActionSetLoader.prototype.loadAction = function(actionPath,actnSet,testAction)
{
	var loadAction = false;
	var extScript = "$._ext_ISACTIONLOADED.run('"+testAction+"', '"+actnSet+"');";
	var csInterface = this.csInterface;
	evalScript(extScript,function(result)
	{
		if(result == "false")
		{
			
			var fullActionPath;
			
			try
			{
				var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION);  
			    fullActionPath = extensionRoot + "/"+actionPath+actnSet;
			}
			catch(e)
			{
				if(this.debug)
					alert("Failed to retrieve extension path from csInterface for action "+actnSet);
					
				return;
			}
			
			extScript = "$._ext_LOADACTION.run('"+fullActionPath+"');";
			evalScript(extScript,function(result)
			{
				if(result != "true")
				{
					if(this.debug)
						alert("Failed to load action "+actnSet);
					
					return;
				}
			});
		}
		else if(result == "true")
			loadAction = false;
		else
		{
			if(this.debug)
				alert("Failed to determine if action is already loaded "+actnSet);
			
			return;
		}
	});
};
