Skip to content

Commit

Permalink
- Template file name+extension now validates through single field only
Browse files Browse the repository at this point in the history
- [Bug] After renaming a project template - closing the project template
through its context menu was not removing the project from sidebar -
fixed

(reference #62)
  • Loading branch information
rat-moonshine committed Nov 29, 2017
1 parent fb8f381 commit d464583
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,14 @@
private function rename():void
{
isProject = setting.customTemplate.fileBridge.isDirectory;
txtRename.prompt = isProject ? "Enter a name" : "Enter a name and extension";
// show the file name cutting down .template word
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;
var lastIndex:int = setting.label.indexOf(".template");
txtRename.text = (lastIndex != -1) ? setting.label.substring(0, lastIndex) : setting.label;
lblName.visible = false;
hgEdit.visible = true;
txtRename.visible = true;
btnsRegular.includeInLayout = btnsRegular.visible = false;
btnsRename.includeInLayout = btnsRename.visible = true;
Expand All @@ -107,13 +101,13 @@
protected function renameDone(event:MouseEvent):void
{
if (StringUtil.trim(txtRename.text).length == 0 || (!isProject && StringUtil.trim(txtRenameExt.text).length == 0))
if (StringUtil.trim(txtRename.text).length == 0 || (!isProject && txtRename.text.split(".").length < 2))
{
Alert.show("Please enter a valid file name and extension.", "Error!");
Alert.show("Please enter a valid file "+ (isProject ? "name." : "name with extension."), "Error!");
return;
}
dispatchEvent(new GeneralEvent(GeneralEvent.DONE, txtRename.text +(isProject ? "" : "."+ txtRenameExt.text)));
dispatchEvent(new GeneralEvent(GeneralEvent.DONE, txtRename.text));
// when done
renameCancel(null);
Expand All @@ -122,7 +116,7 @@
protected function renameCancel(event:MouseEvent):void
{
lblName.visible = true;
hgEdit.visible = false;
txtRename.visible = false;
btnsRegular.includeInLayout = btnsRegular.visible = true;
btnsRename.includeInLayout = btnsRename.visible = false;
}
Expand All @@ -132,26 +126,13 @@

<s:HGroup width="100%" verticalAlign="middle">
<s:Group autoLayout="true" width="100%">
<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:TextInput id="txtRename"
styleName="uiTextSettingsValue"
borderVisible="false" width="100%"
contentBackgroundAlpha="1"
unfocusedTextSelectionColor="#a8c6ee"
focusAlpha="0" paddingLeft="0"
visible="false"/>
<s:Label id="lblName"
styleName="uiTextSettingsValue"
text="{setting.label}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ package actionScripts.ui.renderers
}

//contextMenu.addItem(new ContextMenuItem(null, true));
model.contextMenuCore.addItem(contextMenu, model.contextMenuCore.getContextMenuItem(ConstantsCoreVO.IS_AIR ? SETTINGS : PROJECT_SETUP, redispatch, Event.SELECT));
if (ConstantsCoreVO.IS_AIR && !fw.projectReference.isTemplate)
{
model.contextMenuCore.addItem(contextMenu, model.contextMenuCore.getContextMenuItem(ConstantsCoreVO.IS_AIR ? SETTINGS : PROJECT_SETUP, redispatch, Event.SELECT));
}
model.contextMenuCore.addItem(contextMenu, model.contextMenuCore.getContextMenuItem(CLOSE, redispatch, Event.SELECT));
if (ConstantsCoreVO.IS_AIR)
{
Expand Down
16 changes: 16 additions & 0 deletions ide/MoonshineSharedCore/src/actionScripts/utils/UtilsCore.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ package actionScripts.utils
import flash.system.Capabilities;

import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.CloseEvent;
import mx.events.ToolTipEvent;
import mx.managers.PopUpManager;
import mx.utils.UIDUtil;

import actionScripts.events.ProjectEvent;
import actionScripts.factory.FileLocation;
Expand Down Expand Up @@ -388,6 +390,20 @@ package actionScripts.utils
return wrapper;
}

/**
* Finding fileWrapper by its UDID
*/
public static function findFileWrapperIndexByID(wrapperToSearch:FileWrapper, searchIn:ICollectionView):int
{
var uidToSearch:String = UIDUtil.getUID(wrapperToSearch);
for (var i:String in searchIn)
{
if (UIDUtil.getUID(searchIn[i]) == uidToSearch) return int(i);
}

return -1;
}

/**
* Validate a given path compared with a project's
* default source path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@
case 'remove':
{
project = event.items[0] as ProjectVO;
projectFolders.removeItemAt(projectFolders.getItemIndex(project.projectFolder));
// after a project renaming, and updating its internal fields
// direct search (i.e. getItemIndex) of fileWrapper object in the collection
// returns -1 even the fileWrapper object and object inside the collection has same
// instance id. Thus a different approach it needs to parse by its uid value
var tmpFWIndex:int = UtilsCore.findFileWrapperIndexByID(project.projectFolder, projectFolders);
projectFolders.removeItemAt(tmpFWIndex);
break;
}
case 'add':
Expand Down Expand Up @@ -358,10 +363,7 @@
}
case FTETreeItemRenderer.CLOSE:
{
project = getProjectFromProjectFolder(fileWrapper);
dispatcher.dispatchEvent(
new ProjectEvent(ProjectEvent.REMOVE_PROJECT, project)
);
onFileDeletedOnServer(fileWrapper);
break;
}
case FTETreeItemRenderer.DELETE:
Expand Down Expand Up @@ -545,10 +547,9 @@
setTimeout(function():void
{
var tmpFileW:FileWrapper = UtilsCore.findFileWrapperAgainstProject(i.projectFolder, null, i.projectFolder);
tree.selectedItem = tmpFileW;
tree.selectedItem = i.projectFolder;
var indexToItemRenderer:int = tree.getItemIndex(tmpFileW);
var indexToItemRenderer:int = tree.getItemIndex(i.projectFolder);
tree.callLater(tree.scrollToIndex, [indexToItemRenderer]);
}, 300);
break;
Expand Down

0 comments on commit d464583

Please sign in to comment.