Browse Source

Hooking up some NET plugin solution menu items

Josh Engebretson 9 years ago
parent
commit
ae7dc27a67

+ 35 - 2
Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts

@@ -64,6 +64,7 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
             const menu = this.serviceRegistry.uiServices.createPluginMenuItemSource("AtomicNET", {});
             const menu = this.serviceRegistry.uiServices.createPluginMenuItemSource("AtomicNET", {});
             menu.addItem(new Atomic.UIMenuItem("Open Solution", `${this.name}.opensolution`));
             menu.addItem(new Atomic.UIMenuItem("Open Solution", `${this.name}.opensolution`));
             menu.addItem(new Atomic.UIMenuItem("Compile Project", `${this.name}.compileproject`));
             menu.addItem(new Atomic.UIMenuItem("Compile Project", `${this.name}.compileproject`));
+            menu.addItem(new Atomic.UIMenuItem("Generate Solution", `${this.name}.generatesolution`));
             this.menuCreated = true;
             this.menuCreated = true;
         }
         }
 
 
@@ -174,8 +175,15 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
         if (extension == this.name) {
         if (extension == this.name) {
             switch (action) {
             switch (action) {
                 case "compileproject":
                 case "compileproject":
-                this.doFullCompile();
-                return true;
+                    this.doFullCompile();
+                    return true;
+                case "opensolution":
+                    this.openSolution();
+                    return true;
+                case "generatesolution":
+                    this.generateSolution();
+                    return true;
+
             }
             }
         }
         }
     }
     }
@@ -185,6 +193,31 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
     */
     */
     doFullCompile() {
     doFullCompile() {
 
 
+        if (ToolCore.netProjectSystem)
+            ToolCore.netProjectSystem.buildAtomicProject();
+
+    }
+    /**
+    * Open Solution
+    */
+    openSolution() {
+
+        if (ToolCore.netProjectSystem) {
+            ToolCore.netProjectSystem.openSolution();
+        }
+
     }
     }
 
 
+    /**
+    * Generate Solution
+    */
+    generateSolution() {
+
+        if (ToolCore.netProjectSystem) {
+            ToolCore.netProjectSystem.generateSolution();
+        }
+
+    }
+
+
 }
 }

+ 89 - 29
Source/ToolCore/NETTools/NETProjectSystem.cpp

@@ -62,6 +62,23 @@ namespace ToolCore
         projectAssemblyDirty_ = false;
         projectAssemblyDirty_ = false;
     }
     }
 
 
+    void NETProjectSystem::OpenSolution()
+    {
+        if (!visualStudioPath_.Length())
+            return;
+
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+        if (!fileSystem->FileExists(solutionPath_))
+        {
+            if (!GenerateSolution())
+                return;
+        }
+
+        OpenSourceFile(String::EMPTY);
+
+    }
+
     void NETProjectSystem::OpenSourceFile(const String& sourceFilePath)
     void NETProjectSystem::OpenSourceFile(const String& sourceFilePath)
     {
     {
         if (!visualStudioPath_.Length())
         if (!visualStudioPath_.Length())
@@ -75,7 +92,9 @@ namespace ToolCore
             vsSubprocess_ = 0;
             vsSubprocess_ = 0;
 
 
             args.Push(solutionPath_);
             args.Push(solutionPath_);
-            args.Push(sourceFilePath);
+
+            if (sourceFilePath.Length())
+                args.Push(sourceFilePath);
 
 
             try
             try
             {
             {
@@ -89,6 +108,9 @@ namespace ToolCore
         }
         }
         else
         else
         {
         {
+            if (!sourceFilePath.Length())
+                return;
+
             try
             try
             {
             {
                 std::vector<std::string> args;
                 std::vector<std::string> args;
@@ -123,6 +145,69 @@ namespace ToolCore
 
 
     }
     }
 
 
+    void NETProjectSystem::BuildAtomicProject()
+    {
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+        if (!fileSystem->FileExists(solutionPath_))
+        {
+            if (!GenerateSolution())
+            {
+                LOGERRORF("NETProjectSystem::BuildAtomicProject - solutionPath does not exist: %s", solutionPath_.CString());
+                return;
+            }
+        }
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+
+        Project* project = GetSubsystem<ToolSystem>()->GetProject();
+        NETBuildSystem* buildSystem = GetSubsystem<NETBuildSystem>();
+
+        if (buildSystem)
+        {
+            NETBuild* build = buildSystem->BuildAtomicProject(project);
+
+            if (build)
+            {
+                build->SubscribeToEvent(E_NETBUILDRESULT, HANDLER(NETProjectSystem, HandleNETBuildResult));
+            }
+
+        }
+#endif
+
+    }
+
+    bool NETProjectSystem::GenerateSolution()
+    {
+        ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+        Project* project = tsystem->GetProject();
+
+        if (!project)
+        {
+            LOGERRORF("NETProjectSystem::GenerateSolution - No Project Loaded");
+            return false;
+        }
+
+        SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
+
+        gen->SetScriptPlatform("WINDOWS");
+
+        if (!gen->LoadProject(project))
+        {
+            LOGERRORF("NETProjectSystem::GenerateSolution - Unable to Load Project");
+            return false;
+        }
+
+        if (!gen->Generate())
+        {
+            LOGERRORF("NETProjectSystem::GenerateSolution - Unable to Generate Project");
+            return false;
+        }
+
+        return true;
+
+    }
+
 
 
     void NETProjectSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
     void NETProjectSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
     {
     {
@@ -140,39 +225,14 @@ namespace ToolCore
 
 
         if (solutionDirty_)
         if (solutionDirty_)
         {
         {
-            ToolSystem* tsystem = GetSubsystem<ToolSystem>();
-            Project* project = tsystem->GetProject();
-
-            SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
-
-            gen->SetScriptPlatform("WINDOWS");
-
-            if (!gen->LoadProject(project))
-            {
-                return;
-            }
-
-            if (!gen->Generate())
-            {
-                return;
-            }
-
             solutionDirty_ = false;
             solutionDirty_ = false;
-
+            GenerateSolution();
         }
         }
 
 
         if (projectAssemblyDirty_)
         if (projectAssemblyDirty_)
-        {
-            Project* project = GetSubsystem<ToolSystem>()->GetProject();
-            NETBuild* build = GetSubsystem<NETBuildSystem>()->BuildAtomicProject(project);
-
-            if (build)
-            {
-                build->SubscribeToEvent(E_NETBUILDRESULT, HANDLER(NETProjectSystem, HandleNETBuildResult));
-            }
-
+        {        
+            BuildAtomicProject();
             projectAssemblyDirty_ = false;
             projectAssemblyDirty_ = false;
-
         }
         }
 
 
     }
     }

+ 9 - 1
Source/ToolCore/NETTools/NETProjectSystem.h

@@ -50,12 +50,20 @@ namespace ToolCore
         NETProjectSystem(Context* context);
         NETProjectSystem(Context* context);
         virtual ~NETProjectSystem();
         virtual ~NETProjectSystem();
 
 
+        bool GetVisualStudioAvailable() const { return visualStudioPath_.Length() != 0; }
+
         const String& GetSolutionPath() const { return solutionPath_; }
         const String& GetSolutionPath() const { return solutionPath_; }
 
 
-        bool GetVisualStudioAvailable() const { return visualStudioPath_.Length() != 0; }
+        void BuildAtomicProject();        
+
+        /// Open the solution, if opening a source file, better to call OpenSourceFile as will launch VS instance with source file loaded
+        /// otherwise, no guarantee where source file will load when multiple VS instances running
+        void OpenSolution();       
 
 
         void OpenSourceFile(const String& sourceFilePath);
         void OpenSourceFile(const String& sourceFilePath);
 
 
+        bool GenerateSolution();
+
     private:
     private:
 
 
         void HandleUpdate(StringHash eventType, VariantMap& eventData);
         void HandleUpdate(StringHash eventType, VariantMap& eventData);