Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: eddiemoore/StructureCreator-AIR
base: 3433766bf3
...
head fork: eddiemoore/StructureCreator-AIR
compare: 552a06b567
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
5 .actionScriptProperties
@@ -10,8 +10,6 @@
</excludedEntries>
</libraryPathEntry>
<libraryPathEntry kind="1" linkType="1" path="libs"/>
- <libraryPathEntry kind="3" linkType="1" path="D:/Work/as3/robotlegs-framework-v1.5.2/bin/robotlegs-framework-v1.5.2.swc" useDefaultLinkType="false"/>
- <libraryPathEntry kind="3" linkType="1" path="D:/Work/as3/robotlegs-framework-v1.5.2/libs/SwiftSuspenders-v1.6.0.swc" useDefaultLinkType="false"/>
</libraryPath>
<sourceAttachmentPath/>
</compiler>
@@ -26,9 +24,8 @@
<flashCatalyst validateFlashCatalystCompatibility="false"/>
<buildTargets>
<buildTarget buildTargetName="default">
- <airSettings airCertificatePath="" airTimestamp="true" anePathSet="true" version="1">
+ <airSettings airCertificatePath="" airTimestamp="true" version="1">
<airExcludes/>
- <anePaths/>
</airSettings>
<actionScriptSettings version="1"/>
</buildTarget>
View
BIN  bin-debug/StructureCreator.swf
Binary file not shown
View
BIN  libs/SwiftSuspenders-v1.6.0.swc
Binary file not shown
View
BIN  libs/robotlegs-framework-v1.5.2.swc
Binary file not shown
View
4 src/com/structurecreator/MainContext.as
@@ -5,7 +5,9 @@ package com.structurecreator
import com.structurecreator.model.ProjectFolderModel;
import com.structurecreator.model.SchemaModel;
import com.structurecreator.model.StructureCreatorModel;
+ import com.structurecreator.model.files.FileCreatorModel;
import com.structurecreator.model.schemas.XMLSchema;
+ import com.structurecreator.services.FileCreateService;
import com.structurecreator.view.CreateButton;
import com.structurecreator.view.CreateButtonMediator;
import com.structurecreator.view.CustomVariablesMediator;
@@ -39,6 +41,8 @@ package com.structurecreator
injector.mapSingleton(StructureCreatorModel);
injector.mapSingleton(CustomVariableModel);
+ injector.mapClass(FileCreateService, FileCreateService);
+
mediatorMap.mapView(ProjectFolderView, ProjectFolderMediator);
mediatorMap.mapView(SchemaSelectView, SchemaSelectMediator);
mediatorMap.mapView(CreateButton, CreateButtonMediator);
View
20 src/com/structurecreator/model/CustomVariableModel.as
@@ -19,6 +19,26 @@ package com.structurecreator.model
return _customVars;
}
+ public function updateVariableById(id:uint, variable:String='', value:String=''):void
+ {
+ customVars[id].variable = variable;
+ customVars[id].value = value;
+ trace(customVars[id].variable, customVars[id].value);
+ }
+
+ public function updateVariablesInStr(str:String=''):String
+ {
+ var vo:CustomVariableVO;
+ var reg:RegExp;
+ for (var i:int =0; i < customVars.length; i++)
+ {
+ vo = customVars[i];
+ reg = new RegExp('%' + vo.variable + '%', 'g');
+ str = str.replace(reg, vo.value);
+ }
+ return str;
+ }
+
public function addCustomVariable():void
{
trace("Add a custom variable");
View
11 src/com/structurecreator/model/files/FileCreatorModel.as
@@ -6,6 +6,7 @@ package com.structurecreator.model.files
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
+ import flash.events.TimerEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
@@ -13,6 +14,7 @@ package com.structurecreator.model.files
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.utils.ByteArray;
+ import flash.utils.Timer;
public class FileCreatorModel extends EventDispatcher
{
@@ -168,7 +170,14 @@ package com.structurecreator.model.files
_loader = null;
_urlLoader = null;
- //setTimeout(function() { dispatchEvent(new FileEvent(FileEvent.FILE_CREATED)); }, 100);
+ var t:Timer = new Timer(100,1);
+ t.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ t.start();
+ //dispatchEvent(new FileEvent(FileEvent.FILE_CREATED));
+ }
+
+ protected function onTimerComplete(event:TimerEvent):void
+ {
dispatchEvent(new FileEvent(FileEvent.FILE_CREATED));
}
}
View
30 src/com/structurecreator/model/schemas/XMLSchema.as
@@ -3,9 +3,12 @@ package com.structurecreator.model.schemas
import com.structurecreator.events.FileEvent;
import com.structurecreator.events.StructureCreatorEvent;
- import com.structurecreator.model.files.FileCreatorModel;
+ import com.structurecreator.model.CustomVariableModel;
+ //import com.structurecreator.model.files.FileCreatorModel;
+ import com.structurecreator.services.FileCreateService;
import flash.events.Event;
+ import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.filesystem.File;
@@ -23,7 +26,12 @@ package com.structurecreator.model.schemas
private var _totalFiles:int;
private var _foldersCreated:int;
private var _filesCreated:int;
- private var _customVars:Array;
+
+ [Inject]
+ public var customVarsModel:CustomVariableModel;
+
+ [Inject]
+ public var fileCreatorService:FileCreateService;
public function XMLSchema()
{
@@ -80,7 +88,7 @@ package com.structurecreator.model.schemas
//FILES
var file:File;
var url:String;
- var fc:FileCreatorModel;
+ //var fc:FileCreatorModel;
for (var j:int = 0; j < xml.file.length(); j++)
@@ -89,8 +97,8 @@ package com.structurecreator.model.schemas
url = xml.file[j].@url;
trace("URL = ", url);
- fc = new FileCreatorModel(_directory + currPath, xml.file[j].@name, url, xml.file[j].text());
- fc.addEventListener(FileEvent.FILE_CREATED, fc_fileCreated);
+ fileCreatorService.init(_directory + currPath, xml.file[j].@name, url, xml.file[j].text());
+ eventDispatcher.addEventListener(FileEvent.FILE_CREATED, onFileCreated);
}
//FOLDERS
@@ -101,7 +109,7 @@ package com.structurecreator.model.schemas
trace("create folder : " + xml.folder[i].@name);
dir = new File();
dir.url = _directory + currPath;
- newname = xml.folder[i].@name; //CustomVariables.getInstance().updateVars(xml.folder[i].@name);
+ newname = customVarsModel.updateVariablesInStr(xml.folder[i].@name);
dir = dir.resolvePath(newname);
dir.createDirectory();
@@ -111,20 +119,23 @@ package com.structurecreator.model.schemas
}
_foldersCreated += 1;
}
-
+ trace("Files : " + _filesCreated + '/' + _totalFiles);
+ trace("Folders : " + _foldersCreated + '/' + _totalFolders);
if (_filesCreated >= _totalFiles && _foldersCreated >= _totalFolders)
{
- trace("DONE!!!");
+ trace("Created Everything");
+ eventDispatcher.dispatchEvent(new StructureCreatorEvent(StructureCreatorEvent.CREATION_COMPLETE));
cleanUp();
}
}
- private function fc_fileCreated(e:FileEvent):void
+ private function onFileCreated(e:FileEvent):void
{
_filesCreated += 1;
trace(_filesCreated, '/', _totalFiles);
if (_filesCreated >= _totalFiles && _foldersCreated >= _totalFolders)
{
+ trace("Created Everything");
eventDispatcher.dispatchEvent(new StructureCreatorEvent(StructureCreatorEvent.CREATION_COMPLETE));
cleanUp();
}
@@ -132,7 +143,6 @@ package com.structurecreator.model.schemas
private function cleanUp():void
{
- _customVars = null;
_xmlLoader = null;
}
View
195 src/com/structurecreator/services/FileCreateService.as
@@ -0,0 +1,195 @@
+package com.structurecreator.services
+{
+ import com.structurecreator.events.FileEvent;
+ import com.structurecreator.model.CustomVariableModel;
+ import com.structurecreator.model.files.FileTypes;
+
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.events.ProgressEvent;
+ import flash.events.TimerEvent;
+ import flash.filesystem.File;
+ import flash.filesystem.FileMode;
+ import flash.filesystem.FileStream;
+ import flash.net.URLLoader;
+ import flash.net.URLRequest;
+ import flash.net.URLStream;
+ import flash.utils.ByteArray;
+ import flash.utils.Timer;
+
+ import org.robotlegs.mvcs.Actor;
+
+ public class FileCreateService extends Actor
+ {
+ private var _dir:String;
+ private var _url:String;
+ private var _name:String;
+ private var _file_content:String;
+ private var _byte_content:ByteArray;
+
+ private var _loader:URLStream;
+ private var _urlLoader:URLLoader;
+ private var _file_ext:String;
+
+ [Inject]
+ public var customVarsModel:CustomVariableModel;
+
+ public function FileCreateService()
+ {
+ super();
+ }
+
+ public function init(dir:String, name:String = '', url:String = '', file_content:String = ''):void
+ {
+ _dir = dir;
+ _url = url;
+
+ _name = customVarsModel.updateVariablesInStr(name);
+ _file_content = file_content;
+
+ _file_ext = (_name.substr(_name.lastIndexOf('.') + 1) as String).toLowerCase();
+
+ if (_url == '')
+ {
+ //Text file from content in XML
+ createTextFile();
+ }
+ else if (FileTypes.NON_TEXT_EXT_ARRAY.indexOf(_file_ext) > -1)
+ {
+ loadByteFile();
+ }
+ else
+ {
+ //Text file from URL
+ loadTextFileContent();
+ }
+ }
+
+ private function loadByteFile():void
+ {
+ _loader = new URLStream();
+ _byte_content = new ByteArray();
+ //_byte_content.endian = Endian.BIG_ENDIAN;
+ _loader.addEventListener(Event.COMPLETE, byteFileLoaded);
+ _loader.addEventListener(IOErrorEvent.IO_ERROR, byteFileIOError);
+ _loader.load(new URLRequest(_url));
+ }
+
+ private function byteFileIOError(e:IOErrorEvent):void
+ {
+ trace("CANNOT LOAD " + _name);
+ }
+
+ private function byteFileLoaded(e:Event):void
+ {
+ _loader.removeEventListener(Event.COMPLETE, byteFileLoaded);
+ _loader.removeEventListener(IOErrorEvent.IO_ERROR, byteFileIOError);
+ trace("File contents LOADED for " + _name);
+
+ _loader.readBytes(_byte_content, 0, _loader.bytesAvailable);
+ createByteFile();
+ }
+
+ private function createByteFile():void
+ {
+ var file:File = new File();
+ file.url = _dir;
+ file = file.resolvePath(_name);
+
+ trace('the file ext : ' + _file_ext);
+ switch (_file_ext)
+ {
+ case 'docx':
+ case 'pptx':
+ case 'xlsx':
+ //trace("WRITE A MICROSOFT FILE : " + _file_ext);
+ //var mx:MicrosoftXModel = new MicrosoftXModel(file, _byte_content);
+ //mx.addEventListener(FileEvent.FILE_CREATED, mx_fileCreated);
+ break;
+
+ default:
+ var fs:FileStream = new FileStream();
+ fs.open(file, FileMode.WRITE);
+ fs.writeBytes(_byte_content);
+ fs.close();
+
+ complete();
+ break;
+ }
+ }
+
+ private function mx_fileCreated(e:FileEvent):void
+ {
+ //(e.currentTarget as MicrosoftX).removeEventListener(FileEvent.FILE_CREATED, mx_fileCreated);
+ complete();
+ }
+
+ /**
+ * Text Based File
+ */
+ private function loadTextFileContent():void
+ {
+ trace("Load file contents for " + _name);
+ _urlLoader = new URLLoader();
+ _urlLoader.addEventListener(Event.COMPLETE, textFileLoaded);
+ _urlLoader.addEventListener(ProgressEvent.PROGRESS, urlLoader_progress);
+ _urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
+ _urlLoader.load(new URLRequest(_url));
+ }
+
+ private function urlLoader_progress(e:ProgressEvent):void
+ {
+ trace(e.bytesLoaded / e.bytesTotal);
+ }
+
+ private function onIOError(e:IOErrorEvent):void
+ {
+ trace("Error loading text file");
+ //TODO add to log file
+ complete();
+ }
+
+ private function textFileLoaded(e:Event):void
+ {
+ _urlLoader.removeEventListener(Event.COMPLETE, textFileLoaded);
+ _urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
+ trace("File contents LOADED for " + _name);
+ _file_content = e.currentTarget.data as String;
+ createTextFile();
+ }
+
+ private function createTextFile():void
+ {
+ _file_content = customVarsModel.updateVariablesInStr(_file_content);
+
+ var file:File = new File();
+ file.url = _dir;
+ file = file.resolvePath(_name);
+
+ var fs:FileStream = new FileStream();
+ fs.open(file, FileMode.WRITE);
+ //fs.writeUTFBytes(CustomVariables.getInstance().updateVars(_file_content));
+ fs.writeUTFBytes(_file_content);
+ fs.close();
+
+ complete();
+ }
+
+ private function complete():void
+ {
+ trace(_name, 'created');
+ _loader = null;
+ _urlLoader = null;
+
+ var t:Timer = new Timer(100,1);
+ t.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ t.start();
+ //dispatchEvent(new FileEvent(FileEvent.FILE_CREATED));
+ }
+
+ protected function onTimerComplete(event:TimerEvent):void
+ {
+ eventDispatcher.dispatchEvent(new FileEvent(FileEvent.FILE_CREATED));
+ }
+ }
+}
View
3  src/com/structurecreator/view/CustomVariablesMediator.as
@@ -30,9 +30,8 @@ package com.structurecreator.view
private function onCustomVarAdded(e:CustomVarsEvent):void
{
- trace("Added Custom Variable");
+ //trace("Added Custom Variable");
var cvb:CustomVariableBarView = new CustomVariableBarView();
- trace(model.customVars.length, cvb.height);
cvb.y = model.customVars.length * cvb.height;
view.customVarsHolder.addElement(cvb);
}
View
12 src/com/structurecreator/view/customvars/CustomVariableBarMediator.as
@@ -2,6 +2,7 @@ package com.structurecreator.view.customvars
{
import com.structurecreator.model.CustomVariableModel;
+ import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import org.robotlegs.mvcs.Mediator;
@@ -14,18 +15,23 @@ package com.structurecreator.view.customvars
[Inject]
public var model:CustomVariableModel;
+ private var _id:uint;
+
public function CustomVariableBarMediator()
{
}
override public function onRegister():void
{
- view.variableTI.addEventListener(KeyboardEvent.KEY_UP, onKeyUp)
+ _id = model.customVars.length - 1;
+ view.variableTI.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
+ view.valueTI.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
}
- protected function onKeyUp(event:KeyboardEvent):void
+ protected function onFocusOut(event:FocusEvent):void
{
- trace("Update custom var VO");
+ //trace("Update custom var VO");
+ model.updateVariableById(_id, view.variableTI.text, view.valueTI.text);
}
}
}

No commit comments for this range

Something went wrong with that request. Please try again.