From 182bf6fe95c3133485d4d3910d51d70c952d2fe1 Mon Sep 17 00:00:00 2001 From: devSena Date: Tue, 28 Nov 2017 17:44:44 +0530 Subject: [PATCH] - File/project creation from custom template through File/New now 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) --- .../impls/IContextMenuBridgeImp.as | 5 + .../actionScripts/events/TemplatingEvent.as | 6 +- .../interfaces/IContextMenuBridge.as | 1 + .../plugin/templating/TemplatingPlugin.as | 18 +-- .../settings/renderer/TemplateRenderer.mxml | 64 +++++++---- .../src/actionScripts/ui/menu/MenuPlugin.as | 14 ++- .../ui/renderers/FTETreeItemRenderer.as | 105 +++++++++--------- .../impls/IContextMenuBridgeImp.as | 5 + 8 files changed, 131 insertions(+), 87 deletions(-) diff --git a/ide/MoonshineDESKTOPevolved/src/actionScripts/impls/IContextMenuBridgeImp.as b/ide/MoonshineDESKTOPevolved/src/actionScripts/impls/IContextMenuBridgeImp.as index 92d7bfb26..3c51639f2 100644 --- a/ide/MoonshineDESKTOPevolved/src/actionScripts/impls/IContextMenuBridgeImp.as +++ b/ide/MoonshineDESKTOPevolved/src/actionScripts/impls/IContextMenuBridgeImp.as @@ -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); diff --git a/ide/MoonshineSharedCore/src/actionScripts/events/TemplatingEvent.as b/ide/MoonshineSharedCore/src/actionScripts/events/TemplatingEvent.as index 2f955b38b..bd7377b47 100644 --- a/ide/MoonshineSharedCore/src/actionScripts/events/TemplatingEvent.as +++ b/ide/MoonshineSharedCore/src/actionScripts/events/TemplatingEvent.as @@ -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"; @@ -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); diff --git a/ide/MoonshineSharedCore/src/actionScripts/interfaces/IContextMenuBridge.as b/ide/MoonshineSharedCore/src/actionScripts/interfaces/IContextMenuBridge.as index c212d303c..3ef8bd87d 100644 --- a/ide/MoonshineSharedCore/src/actionScripts/interfaces/IContextMenuBridge.as +++ b/ide/MoonshineSharedCore/src/actionScripts/interfaces/IContextMenuBridge.as @@ -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; } } \ No newline at end of file diff --git a/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/TemplatingPlugin.as b/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/TemplatingPlugin.as index 823e8e7de..acb2308cc 100644 --- a/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/TemplatingPlugin.as +++ b/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/TemplatingPlugin.as @@ -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); @@ -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 @@ -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); } } @@ -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 @@ -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 { @@ -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; @@ -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 diff --git a/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/settings/renderer/TemplateRenderer.mxml b/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/settings/renderer/TemplateRenderer.mxml index 51eb8dfdb..37e43cda3 100644 --- a/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/settings/renderer/TemplateRenderer.mxml +++ b/ide/MoonshineSharedCore/src/actionScripts/plugin/templating/settings/renderer/TemplateRenderer.mxml @@ -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 { @@ -65,7 +62,6 @@ { showReset = true; } - } public function reset():void @@ -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; @@ -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); @@ -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; } @@ -127,15 +132,26 @@ - + + + + +