Browse files

Custom Variables are saves in a Vector of VOs. Updates variables for …

…folder names
  • Loading branch information...
1 parent 9eea011 commit 634493c50e955c479750b9f914f28648e9affc19 @eddiemoore committed Feb 15, 2012
View
BIN bin-debug/StructureCreator.swf
Binary file not shown.
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,13 +6,15 @@ 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;
import flash.net.URLLoader;
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
20 src/com/structurecreator/model/schemas/XMLSchema.as
@@ -3,9 +3,11 @@ package com.structurecreator.model.schemas
import com.structurecreator.events.FileEvent;
import com.structurecreator.events.StructureCreatorEvent;
+ import com.structurecreator.model.CustomVariableModel;
import com.structurecreator.model.files.FileCreatorModel;
import flash.events.Event;
+ import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.filesystem.File;
@@ -23,7 +25,9 @@ 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;
public function XMLSchema()
{
@@ -90,7 +94,7 @@ package com.structurecreator.model.schemas
trace("URL = ", url);
fc = new FileCreatorModel(_directory + currPath, xml.file[j].@name, url, xml.file[j].text());
- fc.addEventListener(FileEvent.FILE_CREATED, fc_fileCreated);
+ fc.addEventListener(FileEvent.FILE_CREATED, onFileCreated);
}
//FOLDERS
@@ -101,7 +105,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,28 +115,30 @@ 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();
}
}
private function cleanUp():void
{
- _customVars = null;
_xmlLoader = null;
}
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);
}
}
}

0 comments on commit 634493c

Please sign in to comment.