From 34507bc6221ead9cd7f84b0e011617fc1b37e24e Mon Sep 17 00:00:00 2001
From: Vitaly Livshic <shiche@yandex.ru>
Date: Tue, 8 Aug 2017 07:27:32 +0300
Subject: [PATCH] #209 Workspace can be opened from command line

---
 src/dlangide.d          | 13 +++++++++++--
 src/dlangide/ui/frame.d | 16 ++++++++++++++--
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/dlangide.d b/src/dlangide.d
index aa6ba81..5c1ea25 100644
--- a/src/dlangide.d
+++ b/src/dlangide.d
@@ -86,7 +86,16 @@ extern (C) int UIAppMain(string[] args) {
         //pragma(msg, w.click.return_t, "", w.click.params_t);
 
         IDEFrame frame = new IDEFrame(window);
-
+        
+        // Open project, if it specified in command line
+        if (args.length > 1)
+        {
+            Action a = ACTION_FILE_OPEN_WORKSPACE.clone();
+            a.stringParam = args[1];
+            frame.handleAction(a);
+            // Mark that workspace opened to prevent auto open
+            frame.isOpenedWorkspace(true);
+        }
 
         // open home screen tab
         frame.showHomeScreen();
@@ -185,4 +194,4 @@ unittest {
         loaded.save("test_file2.json");
     }
 
-}
\ No newline at end of file
+}
diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d
index 63f77d8..8bc8d83 100644
--- a/src/dlangide/ui/frame.d
+++ b/src/dlangide/ui/frame.d
@@ -82,6 +82,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
     OutputPanel _logPanel;
     DockHost _dockHost;
     TabWidget _tabs;
+    // Is any workspace already opened?
+    private auto openedWorkspace = false;
 
     ///Cache for parsed D files for autocomplete and symbol finding
     import dlangide.tools.d.dcdinterface;
@@ -131,6 +133,16 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
     @property bool isExecutionActive() {
         return _execution !is null;
     }
+    
+    /// Is any workspace already opened?
+    @property bool isOpenedWorkspace() {
+        return openedWorkspace;
+    }
+    
+    /// Is any workspace already opened?
+    @property void isOpenedWorkspace(bool opened) {
+        openedWorkspace = opened;    
+    }
 
     /// called when program execution is stopped
     protected void onProgramExecutionStatus(ProgramExecution process, ExecutionStatus status, int exitCode) {
@@ -460,9 +472,9 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
             _tabs.addTab(home, UIString.fromId("HOME"c), null, true);
             _tabs.selectTab(HOME_SCREEN_ID, true);
              auto _settings = new IDESettings(buildNormalizedPath(settingsDir, "settings.json"));
-            // Auto open last project
+            // Auto open last workspace, if no workspace specified in command line and autoOpen flag set to true
             const auto recentWorkspaces = settings.recentWorkspaces;
-            if (recentWorkspaces.length > 0 && _settings.autoOpenLastProject())
+            if (!openedWorkspace && recentWorkspaces.length > 0 && _settings.autoOpenLastProject())
             {
                 Action a = ACTION_FILE_OPEN_WORKSPACE.clone();
                 a.stringParam = recentWorkspaces[0];