Browse Source

Adding edit command to AtomicTool

Josh Engebretson 10 years ago
parent
commit
4d930dcd20

+ 1 - 1
Source/AtomicEditor/Source/AEApplication.cpp

@@ -184,7 +184,7 @@ void AEApplication::Setup()
             String argument = arguments[i].Substring(1).ToLower();
             String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
 
-            if (argument == "project" && value.Length())
+            if (argument == "-project" && value.Length())
             {
                 Vector<String> projectFiles;
                 filesystem->ScanDir(projectFiles, value, "*.atomic", SCAN_FILES, false);

+ 5 - 0
Source/ToolCore/Command/CommandParser.cpp

@@ -6,6 +6,7 @@
 #include "BuildCmd.h"
 #include "ImportCmd.h"
 #include "PlayCmd.h"
+#include "EditCmd.h"
 
 namespace ToolCore
 {
@@ -50,6 +51,10 @@ Command* CommandParser::Parse(const Vector<String>& arguments)
             {
                 cmd = new PlayCmd(context_);
             }
+            else if (argument == "edit")
+            {
+                cmd = new EditCmd(context_);
+            }
 
         }
 

+ 87 - 0
Source/ToolCore/Command/EditCmd.cpp

@@ -0,0 +1,87 @@
+#include <Poco/Process.h>
+
+#include <Atomic/Core/StringUtils.h>
+#include <Atomic/IO/Log.h>
+#include <Atomic/IO/File.h>
+
+#include "../ToolSystem.h"
+#include "../ToolEnvironment.h"
+#include "../Project/Project.h"
+#include "../Build/BuildEvents.h"
+#include "../Build/BuildSystem.h"
+
+#include "EditCmd.h"
+
+namespace ToolCore
+{
+
+EditCmd::EditCmd(Context* context) : Command(context)
+{
+
+}
+
+EditCmd::~EditCmd()
+{
+
+}
+
+bool EditCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
+{
+    String argument = arguments[startIndex].ToLower();
+    String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
+
+    if (argument != "edit")
+    {
+        errorMsg = "Unable to parse edit command";
+        return false;
+    }
+
+    return true;
+}
+
+bool EditCmd::LaunchEditorProcess(const String& command, const Vector<String>& args, const String& initialDirectory)
+{
+    Poco::Process::Args pargs;
+
+    for (unsigned i = 0; i < args.Size(); i++)
+        pargs.push_back(args[i].CString());
+
+    std::string pcommand = command.CString();
+    std::string pinitialDirectory = initialDirectory.CString();
+
+    // this can take an ENV as well, may come in useful
+    Poco::ProcessHandle handle(Poco::Process::launch(pcommand, pargs, pinitialDirectory));
+
+    if (!Poco::Process::isRunning(handle))
+    {
+        Error(ToString("Unable to launch editor process: %s", command.CString()));
+        return false;
+    }
+
+    handle.wait();
+
+    return true;
+
+}
+
+
+void EditCmd::Run()
+{
+    LOGINFOF("Editing project");
+
+    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+    ToolEnvironment* env = GetSubsystem<ToolCore::ToolEnvironment>();
+    Project* project = tsystem->GetProject();
+    const String& editorBinary = env->GetEditorBinary();
+
+    Vector<String> vargs;
+    vargs.Push("--project");
+    vargs.Push(project->GetProjectPath());
+
+    LaunchEditorProcess(editorBinary, vargs, "");
+
+    Finished();
+
+}
+
+}

+ 30 - 0
Source/ToolCore/Command/EditCmd.h

@@ -0,0 +1,30 @@
+
+#pragma once
+
+#include "Command.h"
+
+using namespace Atomic;
+
+namespace ToolCore
+{
+
+class EditCmd: public Command
+{
+    OBJECT(EditCmd);
+
+public:
+
+    EditCmd(Context* context);
+    virtual ~EditCmd();
+
+    bool Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg);
+
+    void Run();
+
+private:
+
+    bool LaunchEditorProcess(const String& command, const Vector<String>& args, const String& initialDirectory);
+
+};
+
+}

+ 8 - 1
Source/ToolCore/Command/PlayCmd.cpp

@@ -32,7 +32,7 @@ bool PlayCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String
 
     if (argument != "play")
     {
-        errorMsg = "Unable to parse build command";
+        errorMsg = "Unable to parse play command";
         return false;
     }
 
@@ -53,7 +53,12 @@ bool PlayCmd::LaunchPlayerProcess(const String& command, const Vector<String>& a
     Poco::ProcessHandle handle(Poco::Process::launch(pcommand, pargs, pinitialDirectory));
 
     if (!Poco::Process::isRunning(handle))
+    {
+        Error(ToString("Unable to launch player process: %s", command.CString()));
         return false;
+    }
+
+    handle.wait();
 
     return true;
 
@@ -87,6 +92,8 @@ void PlayCmd::Run()
     // TODO: use IPC (maybe before this set log location/access the log and output it, we need access to errors)
     LaunchPlayerProcess(editorBinary, vargs, "");
 
+    Finished();
+
 }
 
 }

+ 1 - 0
Source/ToolCore/Project/Project.cpp

@@ -103,6 +103,7 @@ bool Project::Load(const String& fullpath)
 {
     loading_ = true;
 
+    projectPath_ = GetPath(fullpath);
     projectFilePath_ = fullpath;
     SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
     bool result = pfile->Load(this);

+ 2 - 0
Source/ToolCore/Project/Project.h

@@ -55,6 +55,7 @@ public:
     ProjectBuildSettings* GetBuildSettings() { return buildSettings_; }
     ProjectUserPrefs* GetUserPrefs() { return userPrefs_; }
 
+    const String& GetProjectPath() { return projectPath_; }
     const String& GetProjectFilePath() { return projectFilePath_; }
     String GetUserPrefsFullPath();
     String GetBuildSettingsFullPath();
@@ -73,6 +74,7 @@ private:
 
     String version_;
 
+    String projectPath_;
     String projectFilePath_;
     String resourcePath_;