Browse Source

ResourceOps: Folder Creation

Josh Engebretson 10 years ago
parent
commit
69ec23c38f

+ 3 - 2
Script/AtomicEditor/editor/Editor.ts

@@ -27,11 +27,12 @@ class Editor extends Atomic.ScriptObject {
 
 
         this.assetImport = new AssetImport();
         this.assetImport = new AssetImport();
 
 
-        this.parseArguments();
-
         this.subscribeToEvent(EditorEvents.LoadProject, (data) => this.handleEditorLoadProject(data));
         this.subscribeToEvent(EditorEvents.LoadProject, (data) => this.handleEditorLoadProject(data));
         this.subscribeToEvent(EditorEvents.Quit, (data) => this.handleEditorEventQuit(data));
         this.subscribeToEvent(EditorEvents.Quit, (data) => this.handleEditorEventQuit(data));
 
 
+        this.parseArguments();
+
+
     }
     }
 
 
     handleEditorLoadProject(event: EditorEvents.LoadProjectEvent): boolean {
     handleEditorLoadProject(event: EditorEvents.LoadProjectEvent): boolean {

+ 8 - 0
Script/AtomicEditor/editor/EditorEvents.ts

@@ -1,6 +1,14 @@
 
 
 export const Quit = "EditorEventQuit";
 export const Quit = "EditorEventQuit";
 
 
+export const ModalError = "ModalError";
+export interface ModalErrorEvent {
+
+  title: string;
+  message: string;
+
+}
+
 export const LoadProject = "EditorLoadProject";
 export const LoadProject = "EditorLoadProject";
 export interface LoadProjectEvent {
 export interface LoadProjectEvent {
 
 

+ 32 - 0
Script/AtomicEditor/resources/ResourceOps.ts

@@ -0,0 +1,32 @@
+import EditorEvents = require("../editor/EditorEvents");
+
+class ResourceOps extends Atomic.ScriptObject {
+
+
+}
+
+var resourceOps = new ResourceOps();
+
+export function CreateNewFolder(resourcePath: string, reportError: boolean = true): boolean {
+
+    var title = "New Folder Error";
+
+    var fs = Atomic.getFileSystem();
+
+    if (fs.dirExists(resourcePath) || fs.fileExists(resourcePath)) {
+        if (reportError)
+            resourceOps.sendEvent(EditorEvents.ModalError, { title: title, message: "Already exists: " + resourcePath });
+        return false;
+
+    }
+
+    if (!fs.createDir(resourcePath)) {
+        if (reportError)
+            resourceOps.sendEvent(EditorEvents.ModalError, { title: title, message: "Could not create " + resourcePath });
+
+        return false;
+    }
+
+    return true;
+
+}

+ 3 - 1
Script/AtomicEditor/tsconfig.json

@@ -16,6 +16,7 @@
         "./editor/EditorEvents.ts",
         "./editor/EditorEvents.ts",
         "./editor/EditorLicense.ts",
         "./editor/EditorLicense.ts",
         "./main.ts",
         "./main.ts",
+        "./resources/ResourceOps.ts",
         "./ui/EditorStrings.ts",
         "./ui/EditorStrings.ts",
         "./ui/EditorUI.ts",
         "./ui/EditorUI.ts",
         "./ui/HierarchyFrame.ts",
         "./ui/HierarchyFrame.ts",
@@ -49,6 +50,7 @@
         "./ui/modal/ModalOps.ts",
         "./ui/modal/ModalOps.ts",
         "./ui/modal/ModalWindow.ts",
         "./ui/modal/ModalWindow.ts",
         "./ui/modal/NewProject.ts",
         "./ui/modal/NewProject.ts",
-        "./ui/modal/ProgressModal.ts"
+        "./ui/modal/ProgressModal.ts",
+        "./ui/modal/UIResourceOps.ts"
     ]
     ]
 }
 }

+ 5 - 0
Script/AtomicEditor/ui/EditorUI.ts

@@ -1,4 +1,5 @@
 
 
+import EditorEvents = require("../editor/EditorEvents");
 import MainFrame = require("../ui/MainFrame");
 import MainFrame = require("../ui/MainFrame");
 import ModalOps = require("./modal/ModalOps");
 import ModalOps = require("./modal/ModalOps");
 
 
@@ -47,6 +48,10 @@ class EditorUI extends Atomic.ScriptObject {
 
 
     this.modalOps = new ModalOps();
     this.modalOps = new ModalOps();
 
 
+    this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
+      this.showModalError(event.title, event.message);
+    })
+
   }
   }
 
 
   showModalError(windowText:string, message:string)
   showModalError(windowText:string, message:string)

+ 8 - 1
Script/AtomicEditor/ui/ProjectFrame.ts

@@ -10,6 +10,7 @@ class ProjectFrame extends ScriptWidget {
 
 
     folderList: Atomic.UIListView;
     folderList: Atomic.UIListView;
     menu: ProjectFrameMenu;
     menu: ProjectFrameMenu;
+    currentFolder: ToolCore.Asset;
 
 
     constructor(parent: Atomic.UIWidget) {
     constructor(parent: Atomic.UIWidget) {
 
 
@@ -45,7 +46,11 @@ class ProjectFrame extends ScriptWidget {
 
 
             var id = data.target.id;
             var id = data.target.id;
 
 
-            if (this.menu.handlePopupMenu(data.target, data.refid))
+            var system = ToolCore.getToolSystem();
+            var project = system.project;
+
+
+            if (this.menu.handlePopupMenu(data.target, data.refid, this.currentFolder ? this.currentFolder.path : project.resourcePath))
                 return true;
                 return true;
 
 
             // create
             // create
@@ -187,6 +192,8 @@ class ProjectFrame extends ScriptWidget {
 
 
     private refreshContent(folder: ToolCore.Asset) {
     private refreshContent(folder: ToolCore.Asset) {
 
 
+        this.currentFolder = folder;
+
         var db = ToolCore.getAssetDatabase();
         var db = ToolCore.getAssetDatabase();
 
 
         var container: Atomic.UILayout = <Atomic.UILayout> this.getWidget("contentcontainer");
         var container: Atomic.UILayout = <Atomic.UILayout> this.getWidget("contentcontainer");

+ 3 - 1
Script/AtomicEditor/ui/ProjectFrameMenu.ts

@@ -14,7 +14,7 @@ class ProjectFrameMenus extends Atomic.ScriptObject {
 
 
     }
     }
 
 
-    handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
+    handlePopupMenu(target: Atomic.UIWidget, refid: string, currentContentFolder:string): boolean {
 
 
         if (!target || !refid) return;
         if (!target || !refid) return;
 
 
@@ -22,6 +22,8 @@ class ProjectFrameMenus extends Atomic.ScriptObject {
 
 
             if (refid == "create_folder") {
             if (refid == "create_folder") {
 
 
+                EditorUI.getModelOps().showCreateFolder(currentContentFolder);
+
                 return true;
                 return true;
 
 
             }
             }

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

@@ -7,6 +7,8 @@ import EULAWindow = require("../license/EULAWindow");
 import ActivationWindow = require("../license/ActivationWindow");
 import ActivationWindow = require("../license/ActivationWindow");
 import ActivationSuccessWindow = require("../license/ActivationSuccessWindow");
 import ActivationSuccessWindow = require("../license/ActivationSuccessWindow");
 
 
+import UIResourceOps = require("./UIResourceOps");
+
 class ModalOps extends Atomic.ScriptObject {
 class ModalOps extends Atomic.ScriptObject {
 
 
     constructor() {
     constructor() {
@@ -27,6 +29,16 @@ class ModalOps extends Atomic.ScriptObject {
 
 
     }
     }
 
 
+    showCreateFolder(resourcePath:string) {
+
+      if (this.show()) {
+
+          this.opWindow = new UIResourceOps.CreateFolder(resourcePath);
+
+      }
+
+    }
+
     showNewProject() {
     showNewProject() {
 
 
         if (this.show()) {
         if (this.show()) {

+ 51 - 0
Script/AtomicEditor/ui/modal/UIResourceOps.ts

@@ -0,0 +1,51 @@
+import EditorEvents = require("../../editor/EditorEvents");
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("./ModalWindow");
+import ResourceOps = require("../../resources/ResourceOps");
+
+export class CreateFolder extends ModalWindow {
+
+    constructor(resourcePath: string) {
+
+        super();
+
+        this.resourcePath = resourcePath;
+        this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
+        this.nameField = <Atomic.UIEditField> this.getWidget("folder_name");
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "create") {
+
+              var resourcePath = Atomic.addTrailingSlash(this.resourcePath) + this.nameField.text;
+
+              if (ResourceOps.CreateNewFolder(resourcePath)) {
+
+                this.hide();
+
+              }
+
+              return true;
+
+            }
+
+            if (id == "cancel") {
+
+                this.hide();
+
+                return true;
+            }
+
+        }
+
+    }
+
+    resourcePath:string;
+    nameField: Atomic.UIEditField;
+
+}