Browse Source

General asset renaming

Josh Engebretson 10 years ago
parent
commit
0986372185

+ 15 - 0
Resources/EditorData/AtomicEditor/editor/ui/renameasset.tb.txt

@@ -0,0 +1,15 @@
+TBLayout: axis: y, distribution: gravity, position: left
+	TBLayout: gravity: left right, distribution-position: right bottom
+		TBTextField: text: "Current Name:"
+		TBTextField: id: current_name
+			lp: min-width: 180
+	TBSeparator: gravity: left right, skin: AESeparator
+	TBLayout: gravity: left right, distribution-position: right bottom
+		TBTextField: text: "New Name:"
+		TBEditField: id: new_name, autofocus: 1
+			lp: min-width: 180
+	TBSeparator: gravity: left right, skin: AESeparator
+	TBLayout: 
+		TBButton: text: Rename, id: rename
+		TBButton: text: Cancel, id: cancel
+		

+ 6 - 0
Script/AtomicEditor/ui/frames/menus/ProjectFrameMenu.ts

@@ -39,6 +39,11 @@ class ProjectFrameMenus extends Atomic.ScriptObject {
                 path = this.contentFolder;
                 path = this.contentFolder;
             }
             }
 
 
+            if (refid == "rename_asset") {
+                EditorUI.getModelOps().showRenameAsset(asset);
+                return true;
+            }
+
             if (refid == "delete_asset") {
             if (refid == "delete_asset") {
                 EditorUI.getModelOps().showResourceDelete(asset);
                 EditorUI.getModelOps().showResourceDelete(asset);
                 return true;
                 return true;
@@ -127,6 +132,7 @@ export = ProjectFrameMenus;
 var StringID = strings.StringID;
 var StringID = strings.StringID;
 
 
 var assetGeneralContextItems = {
 var assetGeneralContextItems = {
+    "Rename": ["rename_asset", undefined, ""],
     "Reveal in Finder": ["reveal_folder", undefined, ""],
     "Reveal in Finder": ["reveal_folder", undefined, ""],
     "-1": null,
     "-1": null,
     "Delete": ["delete_asset", undefined, ""]
     "Delete": ["delete_asset", undefined, ""]

+ 11 - 0
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -107,6 +107,17 @@ class ModalOps extends Atomic.ScriptObject {
 
 
     }
     }
 
 
+    showRenameAsset(asset: ToolCore.Asset) {
+
+        if (this.show()) {
+
+            this.opWindow = new UIResourceOps.RenameAsset(asset);
+
+        }
+
+    }
+
+
     showResourceSelection(windowText: string, importerType: string, callback: (asset: ToolCore.Asset, args: any) => void, args: any = undefined) {
     showResourceSelection(windowText: string, importerType: string, callback: (asset: ToolCore.Asset, args: any) => void, args: any = undefined) {
 
 
         if (this.show()) {
         if (this.show()) {

+ 62 - 10
Script/AtomicEditor/ui/modal/UIResourceOps.ts

@@ -18,7 +18,7 @@ export class ResourceDelete extends ModalWindow {
 
 
         this.asset = asset;
         this.asset = asset;
         this.init("Delete Resource", "AtomicEditor/editor/ui/resourcedelete.tb.txt");
         this.init("Delete Resource", "AtomicEditor/editor/ui/resourcedelete.tb.txt");
-        var message = <Atomic.UIEditField> this.getWidget("message");
+        var message = <Atomic.UIEditField>this.getWidget("message");
 
 
         var text = "Are you sure you want to delete resource:\n\n";
         var text = "Are you sure you want to delete resource:\n\n";
         text += asset.path;
         text += asset.path;
@@ -70,7 +70,7 @@ export class CreateFolder extends ModalWindow {
 
 
         this.resourcePath = resourcePath;
         this.resourcePath = resourcePath;
         this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
         this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
-        this.nameField = <Atomic.UIEditField> this.getWidget("folder_name");
+        this.nameField = <Atomic.UIEditField>this.getWidget("folder_name");
     }
     }
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
@@ -117,7 +117,7 @@ export class CreateComponent extends ModalWindow {
 
 
         this.resourcePath = resourcePath;
         this.resourcePath = resourcePath;
         this.init("New Component", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
         this.init("New Component", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
-        this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
+        this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
     }
     }
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
@@ -138,7 +138,7 @@ export class CreateComponent extends ModalWindow {
 
 
                     this.hide();
                     this.hide();
 
 
-                    this.sendEvent(EditorEvents.EditResource, { path:outputFile});
+                    this.sendEvent(EditorEvents.EditResource, { path: outputFile });
 
 
                 }
                 }
 
 
@@ -170,7 +170,7 @@ export class CreateScript extends ModalWindow {
 
 
         this.resourcePath = resourcePath;
         this.resourcePath = resourcePath;
         this.init("New Script", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
         this.init("New Script", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
-        this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
+        this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
     }
     }
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
@@ -191,7 +191,7 @@ export class CreateScript extends ModalWindow {
 
 
                     this.hide();
                     this.hide();
 
 
-                    this.sendEvent(EditorEvents.EditResource, { path:outputFile});
+                    this.sendEvent(EditorEvents.EditResource, { path: outputFile });
 
 
                 }
                 }
 
 
@@ -223,7 +223,7 @@ export class CreateScene extends ModalWindow {
 
 
         this.resourcePath = resourcePath;
         this.resourcePath = resourcePath;
         this.init("New Scene", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
         this.init("New Scene", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
-        this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
+        this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
     }
     }
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
@@ -243,7 +243,7 @@ export class CreateScene extends ModalWindow {
 
 
                     this.hide();
                     this.hide();
 
 
-                    this.sendEvent(EditorEvents.EditResource, { path:outputFile});
+                    this.sendEvent(EditorEvents.EditResource, { path: outputFile });
 
 
                 }
                 }
 
 
@@ -275,7 +275,7 @@ export class CreateMaterial extends ModalWindow {
 
 
         this.resourcePath = resourcePath;
         this.resourcePath = resourcePath;
         this.init("New Material", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
         this.init("New Material", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
-        this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
+        this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
     }
     }
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
@@ -295,7 +295,7 @@ export class CreateMaterial extends ModalWindow {
 
 
                     this.hide();
                     this.hide();
 
 
-                    this.sendEvent(EditorEvents.EditResource, { path:outputFile});
+                    this.sendEvent(EditorEvents.EditResource, { path: outputFile });
 
 
                 }
                 }
 
 
@@ -318,3 +318,55 @@ export class CreateMaterial extends ModalWindow {
     nameField: Atomic.UIEditField;
     nameField: Atomic.UIEditField;
 
 
 }
 }
+
+export class RenameAsset extends ModalWindow {
+
+    constructor(asset: ToolCore.Asset) {
+
+        super();
+
+        this.asset = asset;
+        this.init("Rename Resource", "AtomicEditor/editor/ui/renameasset.tb.txt");
+
+        var currentName = <Atomic.UITextField>this.getWidget("current_name");
+        this.nameEdit = <Atomic.UIEditField>this.getWidget("new_name");
+
+        currentName.text = asset.name;
+        this.nameEdit.text = asset.name;
+
+        this.resizeToFitContent();
+        this.center();
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "rename") {
+
+                this.hide();
+
+                if (this.asset.name != this.nameEdit.text)
+                    this.asset.rename(this.nameEdit.text);
+
+                return true;
+            }
+
+            if (id == "cancel") {
+
+                this.hide();
+
+                return true;
+            }
+
+        }
+
+    }
+
+    nameEdit: Atomic.UIEditField;
+    asset: ToolCore.Asset;
+
+}