Skip to content

Commit

Permalink
- File/project creation from custom template through File/New now
Browse files Browse the repository at this point in the history
properly triggers in Mac, too
- Project's context menu generates properly with current file template
list each time
- Renaming project template changes name in sidebar in Mac, too
- File template now has new field for extension input

(reference #62)
  • Loading branch information
rat-moonshine committed Nov 28, 2017
1 parent 38a63e6 commit 182bf6f
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ package actionScripts.impls
else if (menuItem) NativeMenuItem(menuOf).submenu.addItem(menuItem as NativeMenuItem);
}

public function removeAll(menuOf:Object):void
{
if (NativeMenuItem(menuOf).submenu) NativeMenuItem(menuOf).submenu.removeAllItems();
}

public function addItem(menuOf:Object, menuItem:Object):void
{
ContextMenu(menuOf).addItem(menuItem as NativeMenuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package actionScripts.events
{
import flash.events.Event;

import actionScripts.factory.FileLocation;

public class TemplatingEvent extends Event
{
public static const ADDED_NEW_TEMPLATE:String = "ADDED_NEW_TEMPLATE";
Expand All @@ -28,14 +30,16 @@ package actionScripts.events

public var label:String;
public var newLabel:String;
public var newFileTemplate:FileLocation;
public var listener:String;
public var isProject:Boolean;

public function TemplatingEvent(type:String, isProject:Boolean, label:String, listener:String=null, newLabel:String=null)
public function TemplatingEvent(type:String, isProject:Boolean, label:String, listener:String=null, newLabel:String=null, newFileTemplate:FileLocation=null)
{
this.isProject = isProject;
this.label = label;
this.newLabel = newLabel;
this.newFileTemplate = newFileTemplate;
this.listener = listener;

super(type, false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ package actionScripts.interfaces
function getContextMenuItem(title:String, listener:Function = null, forState:String=null, hasSeparatorBefore:Boolean=false):Object;
function subMenu(menuOf:Object, menuItem:Object = null, extendedListner:Function=null):void;
function addItem(menuOf:Object, menuItem:Object):void;
function removeAll(menuOf:Object):void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ package actionScripts.plugin.templating
);

// Update internal template list
readTemplates();
fileTemplates.push(newTemplate);

// send event to get the new item added immediately to File/New menu
var lbl:String = TemplatingHelper.getTemplateLabel(newTemplate);
Expand Down Expand Up @@ -471,7 +471,7 @@ package actionScripts.plugin.templating

NewTemplateRenderer(event.target).dispatchEvent(new Event('refresh'));

readTemplates();
projectTemplates.push(newTemplate);

// send event to get the new item added immediately to File/New menu
// send event to get the new item added immediately to File/New menu
Expand Down Expand Up @@ -615,7 +615,9 @@ package actionScripts.plugin.templating
settingsList.splice(idx, 1);
rdr.dispatchEvent(new Event('refresh'));

readTemplates();
//readTemplates();
if (custom.fileBridge.isDirectory) projectTemplates.splice(projectTemplates.indexOf(custom), 1);
else fileTemplates.splice(fileTemplates.indexOf(custom), 1);
}
}

Expand All @@ -639,9 +641,10 @@ package actionScripts.plugin.templating
return;
}

var isDirectory:Boolean = custom.fileBridge.isDirectory; // detect this before moveTo else it'll always return false to older file instance
custom.fileBridge.moveTo(customNewLocation, true);

if (!custom.fileBridge.isDirectory)
if (!isDirectory)
{
// we need to update file location of the (if any) opened instance
// of the file template
Expand All @@ -666,7 +669,7 @@ package actionScripts.plugin.templating
if (tmpOldIndex != -1) fileTemplates[tmpOldIndex] = customNewLocation;

// updating file/new menu
dispatcher.dispatchEvent(new TemplatingEvent(TemplatingEvent.RENAME_TEMPLATE, false, oldFileName, null, newFileName));
dispatcher.dispatchEvent(new TemplatingEvent(TemplatingEvent.RENAME_TEMPLATE, false, oldFileName, null, newFileName, customNewLocation));
}
else
{
Expand All @@ -681,7 +684,7 @@ package actionScripts.plugin.templating
if (tmpOldIndex != -1) projectTemplates[tmpOldIndex] = customNewLocation;

// updating file/new menu
dispatcher.dispatchEvent(new TemplatingEvent(TemplatingEvent.RENAME_TEMPLATE, true, oldFileName, null, newFileName));
dispatcher.dispatchEvent(new TemplatingEvent(TemplatingEvent.RENAME_TEMPLATE, true, oldFileName, null, newFileName, customNewLocation));
}

rdr.setting.customTemplate = customNewLocation;
Expand Down Expand Up @@ -1076,7 +1079,8 @@ package actionScripts.plugin.templating
if (event.fromTemplate.fileBridge.exists)
{
var content:String = String(event.fromTemplate.fileBridge.read());
var fileToSave:FileLocation = new FileLocation(event.insideLocation.nativePath + event.fromTemplate.fileBridge.separator + event.fileName + ((event.fromTemplate == ConstantsCoreVO.TEMPLATE_XML) ? ".xml" : ""));
var tmpArr:Array = event.fromTemplate.fileBridge.name.split(".");
var fileToSave:FileLocation = new FileLocation(event.insideLocation.nativePath + event.fromTemplate.fileBridge.separator + event.fileName +"."+ tmpArr[tmpArr.length - 2]);
fileToSave.fileBridge.save(content);

// opens the file after writing done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@
public static const EVENT_MODIFY:String = "modify";
public static const EVENT_REMOVE:String = "delete";
[Bindable]
public var setting:TemplateSetting;
[Bindable] public var setting:TemplateSetting;
[Bindable] public var showReset:Boolean;
[Bindable] public var showRemove:Boolean;
[Bindable]
public var showReset:Boolean;
[Bindable]
public var showRemove:Boolean;
[Bindable] private var isProject:Boolean;
private function init():void
{
Expand All @@ -65,7 +62,6 @@
{
showReset = true;
}
}
public function reset():void
Expand All @@ -88,12 +84,21 @@
private function rename():void
{
isProject = setting.customTemplate.fileBridge.isDirectory;
// show the file name cutting down .template word
var lastIndex:int = setting.label.indexOf(".template");
txtRename.text = (lastIndex != -1) ? setting.label.substring(0, lastIndex) : setting.label;
if (!isProject)
{
var tmpSplit:Array = setting.label.split(".");
tmpSplit.pop(); // .pop twice as 1. ".template", 2. extension
txtRenameExt.text = tmpSplit.pop();
txtRename.text = tmpSplit.join(".");
}
else
txtRename.text = setting.label;
lblName.visible = false;
txtRename.visible = true;
hgEdit.visible = true;
btnsRegular.includeInLayout = btnsRegular.visible = false;
btnsRename.includeInLayout = btnsRename.visible = true;
Expand All @@ -102,13 +107,13 @@
protected function renameDone(event:MouseEvent):void
{
if (StringUtil.trim(txtRename.text).length == 0)
if (StringUtil.trim(txtRename.text).length == 0 || (!isProject && StringUtil.trim(txtRenameExt.text).length == 0))
{
Alert.show("Please enter a valid file name.", "Error!");
Alert.show("Please enter a valid file name and extension.", "Error!");
return;
}
dispatchEvent(new GeneralEvent(GeneralEvent.DONE, txtRename.text));
dispatchEvent(new GeneralEvent(GeneralEvent.DONE, txtRename.text +(isProject ? "" : "."+ txtRenameExt.text)));
// when done
renameCancel(null);
Expand All @@ -117,7 +122,7 @@
protected function renameCancel(event:MouseEvent):void
{
lblName.visible = true;
txtRename.visible = false;
hgEdit.visible = false;
btnsRegular.includeInLayout = btnsRegular.visible = true;
btnsRename.includeInLayout = btnsRename.visible = false;
}
Expand All @@ -127,15 +132,26 @@

<s:HGroup width="100%" verticalAlign="middle">
<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:HGroup id="hgEdit"
width="100%" visible="false" verticalAlign="bottom" gap="0">
<s:TextInput id="txtRename"
styleName="uiTextSettingsValue"
borderVisible="false" width="100%"
contentBackgroundAlpha="1"
unfocusedTextSelectionColor="#a8c6ee"
focusAlpha="0" paddingLeft="0"
prompt="Enter a template name"/>
<s:Label text="." paddingBottom="4" visible="{!isProject}" includeInLayout="{!isProject}"/>
<s:TextInput id="txtRenameExt"
styleName="uiTextSettingsValue"
width="80" maxChars="8"
borderVisible="false"
contentBackgroundAlpha="1"
unfocusedTextSelectionColor="#a8c6ee"
focusAlpha="0" paddingLeft="0"
prompt="Extension"
visible="{!isProject}" includeInLayout="{!isProject}"/>
</s:HGroup>
<s:Label id="lblName"
styleName="uiTextSettingsValue"
text="{setting.label}"
Expand Down
14 changes: 10 additions & 4 deletions ide/MoonshineSharedCore/src/actionScripts/ui/menu/MenuPlugin.as
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package actionScripts.ui.menu
import mx.core.FlexGlobals;
import mx.events.MenuEvent;

import actionScripts.events.GeneralEvent;
import actionScripts.events.ProjectEvent;
import actionScripts.events.ShortcutEvent;
import actionScripts.events.TemplatingEvent;
Expand All @@ -38,7 +37,6 @@ package actionScripts.ui.menu
import actionScripts.plugin.settings.vo.ISetting;
import actionScripts.plugin.settings.vo.MultiOptionSetting;
import actionScripts.plugin.settings.vo.NameValuePair;
import actionScripts.plugin.templating.TemplatingHelper;
import actionScripts.plugin.templating.TemplatingPlugin;
import actionScripts.ui.menu.vo.CustomMenu;
import actionScripts.ui.menu.vo.CustomMenuItem;
Expand Down Expand Up @@ -457,9 +455,17 @@ package actionScripts.ui.menu
{
if (subItemsInItemOfTopMenu[i].label == event.label)
{
/*if (buildingNativeMenu) itemsInTopMenu[1].submenu.items[0].submenu.items[0].menu.removeItemAt(i);
else*/ subItemsInItemOfTopMenu[i].label = event.newLabel;
subItemsInItemOfTopMenu[i].label = event.newLabel;
subItemsInItemOfTopMenu[i].data.event = (event.isProject ? "eventNewProjectFromTemplate" : "eventNewFileFromTemplate")+ event.newLabel;
subItemsInItemOfTopMenu[i].data.eventData = event.newFileTemplate;

// in case of mac we need to update windowMenus for latter use
if (buildingNativeMenu)
{
windowMenus[1].items[0].items[i].label = event.newLabel;
windowMenus[1].items[0].items[i].event = (event.isProject ? "eventNewProjectFromTemplate" : "eventNewFileFromTemplate")+ event.newLabel;
windowMenus[1].items[0].items[i].data = event.newFileTemplate;
}
return;
}
}
Expand Down
Loading

0 comments on commit 182bf6f

Please sign in to comment.