Skip to content

Commit

Permalink
Template changes now properly resets (reference #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
rat-moonshine committed Oct 23, 2017
1 parent 5ef147c commit 51f4334
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package actionScripts.plugin.actionscript.as3project.save
override public function get author():String { return "Moonshine Project Team"; }
override public function get description():String { return "General options to Moonshine"; }

public var resetLabel:String = "Reset Everything";
public var resetLabel:String = "Reset to Default";

private var _workspacePath:String;
private var _isSaveFiles:Boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package actionScripts.plugin.templating
import flash.display.DisplayObject;
import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
Expand All @@ -31,6 +32,7 @@ package actionScripts.plugin.templating

import actionScripts.events.AddTabEvent;
import actionScripts.events.EditorPluginEvent;
import actionScripts.events.GlobalEventDispatcher;
import actionScripts.events.NewFileEvent;
import actionScripts.events.NewProjectEvent;
import actionScripts.events.OpenFileEvent;
Expand Down Expand Up @@ -61,7 +63,7 @@ package actionScripts.plugin.templating
import components.popup.NewASFilePopup;
import components.popup.NewCSSFilePopup;
import components.popup.NewFilePopup;
import components.popup.NewMXMLFilePopup;
import components.popup.NewMXMLFilePopup;

/*
Templating plugin
Expand Down Expand Up @@ -130,11 +132,19 @@ package actionScripts.plugin.templating

override public function resetSettings():void
{
for each (var i:ISetting in settingsList)
{
if (i is TemplateSetting) TemplateSetting(i).resetTemplate();
}

readTemplates();
}

protected function readTemplates():void
{
fileTemplates = [];
projectTemplates = [];

// Find default templates
var files:FileLocation = templatesDir.resolvePath("files");
var list:Array = files.fileBridge.getDirectoryListing();
Expand Down Expand Up @@ -336,23 +346,23 @@ package actionScripts.plugin.templating
{
// Create new file
var newTemplate:FileLocation = this.customTemplatesDir.resolvePath("files/New file template.txt");
newTemplate.fileBridge.createFile();
newTemplate.fileBridge.save("");

// Add setting for it so we can remove it
var t:TemplateSetting = new TemplateSetting(null, newTemplate, newTemplate.fileBridge.name);
t.renderer.addEventListener(TemplateRenderer.EVENT_MODIFY, handleTemplateModify);
t.renderer.addEventListener(TemplateRenderer.EVENT_REMOVE, handleTemplateReset);
t.renderer.addEventListener(TemplateRenderer.EVENT_MODIFY, handleTemplateModify, false, 0, true);
t.renderer.addEventListener(TemplateRenderer.EVENT_REMOVE, handleTemplateReset, false, 0, true);
t.renderer.addEventListener(TemplateRenderer.EVENT_RESET, handleTemplateReset, false, 0, true);
var newPos:int = this.settingsList.indexOf(newFileTemplateSetting);
settingsList.splice(newPos, 0, t);

// Force settings view to redraw
NewTemplateRenderer(event.target).dispatchEvent(new Event('refresh'));

// Add to project view so user can rename it
dispatcher.dispatchEvent(
new ProjectEvent(ProjectEvent.ADD_PROJECT, new ProjectVO(newTemplate))
GlobalEventDispatcher.getInstance().dispatchEvent(
new OpenFileEvent(OpenFileEvent.OPEN_FILE, newTemplate)
);


// Update internal template list
readTemplates();
Expand Down Expand Up @@ -384,29 +394,37 @@ package actionScripts.plugin.templating
var original:FileLocation = rdr.setting.originalTemplate;
var custom:FileLocation = rdr.setting.customTemplate;

var p:ProjectVO;
var p:AS3ProjectVO;

if (!original || !original.fileBridge.exists)
if ((!original || !original.fileBridge.exists) && custom.fileBridge.isDirectory)
{
p = new ProjectVO(custom)
p = new AS3ProjectVO(custom)
}
else if (!custom.fileBridge.exists)
else if (!custom.fileBridge.exists && (original && original.fileBridge.exists && original.fileBridge.isDirectory))
{
// Copy to app-storage so we can edit
original.fileBridge.copyTo(custom);
p = new ProjectVO(original);
p = new AS3ProjectVO(custom);
}
else if (!custom.fileBridge.exists && original && original.fileBridge.exists && !original.fileBridge.isDirectory)
{
original.fileBridge.copyTo(custom);
}
else if (custom && custom.fileBridge.exists && custom.fileBridge.isDirectory)
{
p = new AS3ProjectVO(custom);
}

// If project or custom, show in Project View so user can rename it
if (custom.fileBridge.isDirectory || !original || !original.fileBridge.exists)
if (p)
{
dispatcher.dispatchEvent(
new ProjectEvent(ProjectEvent.ADD_PROJECT, p)
);
}

// If not a project, open the template for editing
if (!custom.fileBridge.isDirectory)
else if (!custom.fileBridge.isDirectory)
{
dispatcher.dispatchEvent(
new OpenFileEvent(OpenFileEvent.OPEN_FILE, custom)
Expand Down Expand Up @@ -443,8 +461,11 @@ package actionScripts.plugin.templating
var original:FileLocation = rdr.setting.originalTemplate;
var custom:FileLocation = rdr.setting.customTemplate;

if (custom.fileBridge.isDirectory) custom.fileBridge.deleteDirectory(true);
else custom.fileBridge.deleteFile();
if (custom.fileBridge.exists)
{
if (custom.fileBridge.isDirectory) custom.fileBridge.deleteDirectory(true);
else custom.fileBridge.deleteFile();
}

if (!original)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ package actionScripts.plugin.templating.settings
rdr.setting = this;
return rdr;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,12 @@ package actionScripts.plugin.templating.settings
return rdr;
}

public function resetTemplate():void
{
if (rdr)
{
rdr.reset();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@
}
private function reset():void
public function reset():void
{
dispatchEvent(new Event(EVENT_RESET));
showReset = false;
}
public function remove():void
{
dispatchEvent(new Event(EVENT_REMOVE));
showReset = false;
}
private function modify():void
{
dispatchEvent(new Event(EVENT_MODIFY));
showReset = true;
}
private function remove():void
{
dispatchEvent(new Event(EVENT_REMOVE));
showReset = false;
}
]]>
</fx:Script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@
tmpMove.play();
isNoSDKMessageShown = false;
}
else if (isNoSDKMessageShown)
{
grpNoSDKMess.y = this.height - grpNoSDKMess.height;
}
function onEffectEnds(effEvent:EffectEvent):void
{
Expand Down Expand Up @@ -573,6 +577,23 @@
clipAndEnableScrolling="false" />
</s:layout>
</s:DataGroup>
<s:Label
text="FEEDBACK"
color="0XD6D6D6"
paddingTop="3"
paddingLeft="3"
paddingRight="3"
paddingBottom="0"
fontFamily="DejaVuSerif"
fontStyle="italic"
fontSize="18"
/>
<s:HGroup autoLayout="true" verticalAlign="middle">
<s:Button label="This is great!"
styleName="lightButton"/>
<s:Button label="I'm having some problems"
styleName="lightButton"/>
</s:HGroup>
</s:VGroup>

<s:VGroup id="vgProjects"
Expand Down

0 comments on commit 51f4334

Please sign in to comment.