Skip to content

Commit

Permalink
Initial name change commit (reference #62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rat-moonshine committed Nov 17, 2017
1 parent 6543af6 commit ec10e37
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ package actionScripts.plugin.templating

import actionScripts.events.AddTabEvent;
import actionScripts.events.EditorPluginEvent;
import actionScripts.events.GeneralEvent;
import actionScripts.events.GlobalEventDispatcher;
import actionScripts.events.NewFileEvent;
import actionScripts.events.NewProjectEvent;
Expand Down Expand Up @@ -337,6 +338,7 @@ package actionScripts.plugin.templating
setting.renderer.addEventListener(TemplateRenderer.EVENT_MODIFY, handleTemplateModify, false, 0, true);
setting.renderer.addEventListener(TemplateRenderer.EVENT_RESET, handleTemplateReset, false, 0, true);
setting.renderer.addEventListener(TemplateRenderer.EVENT_REMOVE, handleTemplateReset, false, 0, true);
setting.renderer.addEventListener(GeneralEvent.DONE, onRenameDone, false, 0, true);

return setting;
}
Expand All @@ -345,14 +347,15 @@ package actionScripts.plugin.templating
protected function handleFileTemplateCreate(event:Event):void
{
// Create new file
var newTemplate:FileLocation = this.customTemplatesDir.resolvePath("files/New file template.txt");
var newTemplate:FileLocation = this.customTemplatesDir.resolvePath("files/New file template.txt.template");
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, false, 0, true);
t.renderer.addEventListener(TemplateRenderer.EVENT_REMOVE, handleTemplateReset, false, 0, true);
t.renderer.addEventListener(TemplateRenderer.EVENT_RESET, handleTemplateReset, false, 0, true);
t.renderer.addEventListener(GeneralEvent.DONE, onRenameDone, false, 0, true);
var newPos:int = this.settingsList.indexOf(newFileTemplateSetting);
settingsList.splice(newPos, 0, t);

Expand Down Expand Up @@ -473,10 +476,25 @@ package actionScripts.plugin.templating
settingsList.splice(idx, 1);
rdr.dispatchEvent(new Event('refresh'));

readTemplates();
readTemplates();
}
}

protected function onRenameDone(event:GeneralEvent):void
{
// Resetting a template just removes it from app-storage
var rdr:TemplateRenderer = TemplateRenderer(event.target);
var original:FileLocation = rdr.setting.originalTemplate;
var custom:FileLocation = rdr.setting.customTemplate;
var newFileName:String = event.value as String;

if (custom.fileBridge.exists)
{
custom.fileBridge.moveTo(custom.fileBridge.parent.resolvePath(newFileName +".template"), true);
rdr.setting.customTemplate = custom.fileBridge.parent.resolvePath(newFileName +".template");

}
}

protected function handleCreateFileTemplate(event:TemplateEvent):void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<![CDATA[
import flash.events.Event;
import mx.controls.Alert;
import mx.utils.StringUtil;
import actionScripts.events.GeneralEvent;
import actionScripts.plugin.templating.settings.TemplateSetting;
public static const EVENT_RESET:String = "reset";
Expand Down Expand Up @@ -82,33 +86,96 @@
showReset = true;
}
private function rename():void
{
// show the file name cutting down .template word
var lastIndex:int = setting.label.indexOf(".template");
txtRename.text = setting.label.substring(0, lastIndex);
lblName.visible = false;
txtRename.visible = true;
btnsRegular.includeInLayout = btnsRegular.visible = false;
btnsRename.includeInLayout = btnsRename.visible = true;
txtRename.callLater(txtRename.setFocus);
}
protected function renameDone(event:MouseEvent):void
{
if (StringUtil.trim(txtRename.text).length == 0)
{
Alert.show("Please enter a valid file name.", "Error!");
return;
}
dispatchEvent(new GeneralEvent(GeneralEvent.DONE, txtRename.text));
// when done
renameCancel(null);
}
protected function renameCancel(event:MouseEvent):void
{
lblName.visible = true;
txtRename.visible = false;
btnsRegular.includeInLayout = btnsRegular.visible = true;
btnsRename.includeInLayout = btnsRename.visible = false;
}
]]>
</fx:Script>

<s:HGroup width="100%" verticalAlign="middle">
<s:Label styleName="uiTextSettingsValue"
text="{setting.label}" />
<s:Group autoLayout="true" width="100%">
<s:TextInput id="txtRename"
styleName="uiTextSettingsValue"
width="100%"
borderVisible="false"
contentBackgroundAlpha="1"
unfocusedTextSelectionColor="#a8c6ee"
focusAlpha="0" paddingLeft="0"
prompt="Enter a template name"
visible="false"/>
<s:Label id="lblName"
styleName="uiTextSettingsValue"
text="{setting.label}"
verticalCenter="0"/>
</s:Group>

<mx:Spacer width="100%"/>

<s:Button
label="Remove"
styleName="lightButton"
visible="{showRemove}"
click="remove()"
/>
<s:Button
label="Reset"
styleName="lightButton"
visible="{showReset &amp;&amp; !showRemove}"
includeInLayout="{showReset &amp;&amp; !showRemove}"
click="reset()" />
<s:Button
label="Modify"
styleName="lightButton"
click="modify()" />

<mx:Spacer width="100"/>

<s:HGroup id="btnsRename"
includeInLayout="false" visible="false">
<s:Button
label="Done"
styleName="lightButton"
click="renameDone(event)"/>
<s:Button
label="Cancel"
styleName="lightButton"
click="renameCancel(event)"/>
</s:HGroup>
<s:HGroup id="btnsRegular" verticalAlign="middle">
<s:Image source="@Embed('/elements/images/icoRecycle.png')"
buttonMode="true" visible="{showRemove}"
click="remove()"/>
<s:Button
label="Reset"
styleName="lightButton"
visible="{showReset &amp;&amp; !showRemove}"
includeInLayout="{showReset &amp;&amp; !showRemove}"
click="reset()" />
<s:Button
label="Rename"
styleName="lightButton"
visible="{showRemove}" includeInLayout="{showRemove}"
click="rename()"
/>
<s:Button
label="Modify"
styleName="lightButton"
click="modify()" />
</s:HGroup>
</s:HGroup>

</s:VGroup>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ec10e37

Please sign in to comment.