Browse Source

Working on VS integration

Josh Engebretson 9 years ago
parent
commit
99cebb3f6c

+ 3 - 0
Script/AtomicEditor/ui/ResourceEditorProvider.ts

@@ -29,6 +29,7 @@ import TypescriptResourceEditorBuilder from "./resourceEditors/TypescriptResourc
 import CSharpResourceEditorBuilder from "./resourceEditors/CSharpResourceEditorBuilder";
 import XMLResourceEditorBuilder from "./resourceEditors/XMLResourceEditorBuilder";
 import ShaderResourceEditorBuilder from "./resourceEditors/ShaderResourceEditorBuilder";
+import VisualStudioResourceEditorBuilder from "./resourceEditors/VisualStudioResourceEditorBuilder";
 
 export default class ResourceEditorProvider {
     private standardEditorRegistry: Editor.Extensions.ResourceEditorBuilder[] = [];
@@ -108,5 +109,7 @@ export default class ResourceEditorProvider {
 
         // this overrides the test resource editor so need to put it in the custom bucket
         this.registerCustomEditor(new TurboBadgerResourceEditorBuilder());
+
+        this.registerCustomEditor(new VisualStudioResourceEditorBuilder());
     }
 }

+ 5 - 0
Script/AtomicEditor/ui/resourceEditors/CSharpResourceEditorBuilder.ts

@@ -29,6 +29,11 @@ export default class CSharpResourceEditorBuilder extends AbstractTextResourceEdi
     }
 
     canHandleResource(resourcePath: string) : boolean {
+
+        /// Handled externally by VS, TODO: make this a preference
+        if (ToolCore.netProjectSystem.visualStudioAvailable)
+            return false;
+
         var ext = Atomic.getExtension(resourcePath).toLowerCase();
         return ext == ".cs";
     }

+ 46 - 0
Script/AtomicEditor/ui/resourceEditors/VisualStudioResourceEditorBuilder.ts

@@ -0,0 +1,46 @@
+//
+// Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+import {AbstractTextResourceEditorBuilder} from "./AbstractTextResourceEditorBuilder";
+
+export default class VisualStudioResourceEditorBuilder extends AbstractTextResourceEditorBuilder {
+
+    constructor() {
+        super();
+    }
+
+    getEditor(resourceFrame: Atomic.UIWidget, resourcePath: string, tabContainer: Atomic.UITabContainer): Editor.ResourceEditor {
+
+        ToolCore.netProjectSystem.openSourceFile(resourcePath);
+        return null;
+    }
+
+    canHandleResource(resourcePath: string) : boolean {
+
+        /// Handled externally by VS, TODO: make this a preference
+        if (!ToolCore.netProjectSystem.visualStudioAvailable)
+            return false;
+
+        var ext = Atomic.getExtension(resourcePath).toLowerCase();
+        return ext == ".cs";
+    }
+}

+ 1 - 0
Script/TypeScript/AtomicWork.d.ts

@@ -377,6 +377,7 @@ declare module ToolCore {
     export var assetDatabase: AssetDatabase;
     export var licenseSystem: LicenseSystem;
     export var buildSystem: BuildSystem;
+    export var netProjectSystem: NETProjectSystem;
 
     export function getToolEnvironment(): ToolEnvironment;
     export function getToolSystem(): ToolSystem;

+ 1 - 0
Script/tsconfig.json

@@ -104,6 +104,7 @@
         "./AtomicEditor/ui/resourceEditors/TextFileResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TurboBadgerResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TypescriptResourceEditorBuilder.ts",
+        "./AtomicEditor/ui/resourceEditors/VisualStudioResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/XMLResourceEditorBuilder.ts",
         "./AtomicEditor/ui/ScriptWidget.ts",
         "./AtomicEditor/ui/Shortcuts.ts",

+ 46 - 1
Source/ToolCore/NETTools/NETProjectSystem.cpp

@@ -33,6 +33,8 @@
 #include "../Project/Project.h"
 #include "../Project/ProjectEvents.h"
 
+#include "../Subprocess/SubprocessSystem.h"
+
 #include "NETProjectGen.h"
 #include "NETBuildSystem.h"
 #include "NETProjectSystem.h"
@@ -60,6 +62,49 @@ namespace ToolCore
         projectAssemblyDirty_ = false;
     }
 
+    void NETProjectSystem::OpenSourceFile(const String& sourceFilePath)
+    {
+        if (!visualStudioPath_.Length())
+            return;
+
+        StringVector args;
+
+        if (vsSubprocess_.Expired())
+        {
+            SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
+            vsSubprocess_ = 0;
+
+            args.Push(solutionPath_);
+            args.Push(sourceFilePath);
+
+            try
+            {
+                vsSubprocess_ = subs->Launch(visualStudioPath_, args);
+            }
+            catch (Poco::SystemException)
+            {
+                vsSubprocess_ = 0;
+            }
+
+        }
+        else
+        {
+            try
+            {
+                std::vector<std::string> args;
+                args.push_back("/edit");
+                args.push_back(sourceFilePath.CString());
+                Poco::Process::launch(visualStudioPath_.CString(), args);
+
+            }
+            catch (Poco::SystemException)
+            {
+            }
+
+        }
+
+    }
+
     void NETProjectSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
     {
         using namespace Update;
@@ -191,7 +236,7 @@ namespace ToolCore
         FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
         // Query for Visual Studio 2015 path
-        String visualStudioPath_ = Poco::Environment::get("VS140COMNTOOLS").c_str();
+        visualStudioPath_ = Poco::Environment::get("VS140COMNTOOLS").c_str();
 
         if (visualStudioPath_.Length())
         {

+ 6 - 0
Source/ToolCore/NETTools/NETProjectSystem.h

@@ -30,6 +30,7 @@ namespace ToolCore
 {
 
     class Project;
+    class Subprocess;
 
     // AtomicProject.dll state (this shouldn't be in resources too)
 
@@ -53,6 +54,8 @@ namespace ToolCore
 
         bool GetVisualStudioAvailable() const { return visualStudioPath_.Length() != 0; }
 
+        void OpenSourceFile(const String& sourceFilePath);
+
     private:
 
         void HandleUpdate(StringHash eventType, VariantMap& eventData);
@@ -79,6 +82,9 @@ namespace ToolCore
         bool solutionDirty_;
         bool  projectAssemblyDirty_;
 
+        // Visual Studio subprocess
+        WeakPtr<Subprocess> vsSubprocess_;
+
     };
 
 }

+ 5 - 0
Source/ToolCoreJS/ToolCoreJS.cpp

@@ -30,6 +30,8 @@
 #include <ToolCore/License/LicenseSystem.h>
 #include <ToolCore/Build/BuildSystem.h>
 
+#include <ToolCore/NETTools/NETProjectSystem.h>
+
 #include <ToolCore/Assets/ModelImporter.h>
 
 using namespace Atomic;
@@ -167,6 +169,9 @@ void jsapi_init_toolcore(JSVM* vm)
     js_push_class_object_instance(ctx, vm->GetSubsystem<BuildSystem>(), "BuildSystem");
     duk_put_prop_string(ctx, -2, "buildSystem");
 
+    js_push_class_object_instance(ctx, vm->GetSubsystem<NETProjectSystem>(), "NETProjectSystem");
+    duk_put_prop_string(ctx, -2, "netProjectSystem");
+
     duk_push_c_function(ctx, js_atomic_GetLicenseSystem, 0);
     duk_put_prop_string(ctx, -2, "getLicenseSystem");