Browse Source

Editor work

Josh Engebretson 10 years ago
parent
commit
0882470fbb

+ 81 - 40
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/ResourceFrame.ts

@@ -5,85 +5,126 @@ var UI = Atomic.UI;
 
 class ResourceFrame extends ScriptWidget {
 
-    tabcontainer:Atomic.UITabContainer;
-    resourceLayout:Atomic.UILayout;
-    resourceViewContainer:Atomic.UILayout;
+    tabcontainer: Atomic.UITabContainer;
+    resourceLayout: Atomic.UILayout;
+    resourceViewContainer: Atomic.UILayout;
 
-    editors: { [path: string] : Editor.ResourceEditor; } = {};
+    editors: { [path: string]: Editor.ResourceEditor; } = {};
 
-    show(value:boolean) {
+    show(value: boolean) {
 
-      if (value) {
+        if (value) {
 
-      }
+        }
 
     }
 
     handleEditResource(data) {
 
-      var path = data.path;
+        var path = data.path;
 
-      if (this.editors[path]) {
+        if (this.editors[path]) {
 
-        return;
+            return;
 
-      }
+        }
 
-      var ext = Atomic.getExtension(data.path);
+        var ext = Atomic.getExtension(data.path);
 
-      var editor:Editor.ResourceEditor = null;
+        var editor: Editor.ResourceEditor = null;
 
-      if (ext == ".js")
-      {
-          editor = new Editor.JSResourceEditor(path, this.tabcontainer);
-      }
+        if (ext == ".js") {
+            editor = new Editor.JSResourceEditor(path, this.tabcontainer);
+        }
 
-      if (editor)
-      {
-          this.editors[path] = editor;
-          this.tabcontainer.currentPage = this.tabcontainer.numPages - 1;
-          editor.setFocus();
-      }
+        if (editor) {
+            this.editors[path] = editor;
+            this.tabcontainer.currentPage = this.tabcontainer.numPages - 1;
+            editor.setFocus();
+        }
 
 
     }
 
+    navigateToResource(fullpath: string, lineNumber = -1, tokenPos: number = -1) {
+
+        if (!this.editors[fullpath]) {
+            return;
+        }
+
+        var editor = this.editors[fullpath];
+        var root = this.tabcontainer.contentRoot;
+
+        var i = 0;
+
+        for (var child = root.firstChild; child; child = child.next, i++) {
+            if (editor.rootContentWidget == child) {
+                break;
+            }
+        }
+
+        if (i < this.tabcontainer.numPages) {
+
+            this.tabcontainer.currentPage = i;
+
+            editor.setFocus();
+
+            // this cast could be better
+            var ext = Atomic.getExtension(fullpath);
+
+            if (ext == ".js" && lineNumber != -1) {
+                (<Editor.JSResourceEditor>editor).gotoLineNumber(lineNumber);
+            }
+            else if (ext == ".js" && tokenPos != -1) {
+                (<Editor.JSResourceEditor>editor).gotoTokenPos(tokenPos);
+            }
+
+        }
+
+    }
+
     handleCloseResourceEditor(data) {
 
-      var editor = <Editor.ResourceEditor> data.editor;
-      var navigate = <boolean> data.navigateToAvailableResource;
+        var editor = <Editor.ResourceEditor> data.editor;
+        var navigate = <boolean> data.navigateToAvailableResource;
 
-      // remove from lookup
-      this.editors[editor.fullPath] = undefined;
+        // remove from lookup
+        this.editors[editor.fullPath] = undefined;
 
-      var root = this.tabcontainer.contentRoot;
+        var root = this.tabcontainer.contentRoot;
 
-      var found = false;
+        var found = false;
 
-      var i = 0;
-      for (var child = root.firstChild; child; child = child.next, i++)
-      {
-            if (child == editor.rootContentWidget)
-            {
+        var i = 0;
+
+        for (var child = root.firstChild; child; child = child.next, i++) {
+            if (child == editor.rootContentWidget) {
                 found = true;
                 root.removeChild(child);
                 break;
             }
 
-      }
+        }
+
+        assert(found);
+
+        this.tabcontainer.currentPage = -1;
 
-      this.tabcontainer.currentPage = -1;
+        if (navigate) {
 
-      if (navigate) {
+            var keys = Object.keys(this.editors);
 
-        print("NAVIGATE!");
+            if (keys.length) {
 
-      }
+                this.navigateToResource(keys[keys.length - 1]);
+
+            }
 
+        }
 
     }
 
-    constructor(parent:Atomic.UIWidget) {
+    constructor(parent: Atomic.UIWidget) {
 
         super();
 

+ 17 - 15
Source/Atomic/UI/UI.cpp

@@ -457,13 +457,6 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
     // switch this to use a factory?
 
     // this is order dependent as we're using IsOfType which also works if a base class
-    if (widget->IsOfType<TBLayout>())
-    {
-        UILayout* layout = new UILayout(context_, false);
-        layout->SetWidget(widget);
-        widgetWrap_[widget] = layout;
-        return layout;
-    }
 
     if (widget->IsOfType<TBButton>())
     {
@@ -524,14 +517,6 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
         return nwidget;
     }
 
-    if (widget->IsOfType<TBWidget>())
-    {
-        UIWidget* nwidget = new UIWidget(context_, false);
-        nwidget->SetWidget(widget);
-        widgetWrap_[widget] = nwidget;
-        return nwidget;
-    }
-
     if (widget->IsOfType<TBSelectList>())
     {
         UISelectList* nwidget = new UISelectList(context_, false);
@@ -556,6 +541,23 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
         return nwidget;
     }
 
+    if (widget->IsOfType<TBLayout>())
+    {
+        UILayout* layout = new UILayout(context_, false);
+        layout->SetWidget(widget);
+        widgetWrap_[widget] = layout;
+        return layout;
+    }
+
+    if (widget->IsOfType<TBWidget>())
+    {
+        UIWidget* nwidget = new UIWidget(context_, false);
+        nwidget->SetWidget(widget);
+        widgetWrap_[widget] = nwidget;
+        return nwidget;
+    }
+
+
     return 0;
 }