diff --git a/ColtPlugin/PluginMain.cs b/ColtPlugin/PluginMain.cs
index 992788b..6bb296b 100644
--- a/ColtPlugin/PluginMain.cs
+++ b/ColtPlugin/PluginMain.cs
@@ -35,6 +35,7 @@ public class PluginMain : IPlugin
private String pathToLog;
private System.Timers.Timer timer;
private Keys MakeItLiveKeys = Keys.Control | Keys.Shift | Keys.L;
+ private Boolean allowBuildInterception = true;
#region Required Properties
@@ -148,6 +149,16 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
toolbarButton = CreateToolbarButton(toolStrip as ToolStrip, "colt_save.png", "Menu.ExportToCOLT", new EventHandler(OnClick));
toolbarButton2 = CreateToolbarButton(toolStrip as ToolStrip, "colt_run.png", "Menu.OpenInCOLT", new EventHandler(OnClick2));
}
+ else if ((cmd == "ProjectManager.BuildingProject") || (cmd == "ProjectManager.TestingProject"))
+ {
+ // todo: FD might send this for projects other than PluginBase.CurrentProject - figure out how to catch that
+ if (settingObject.InterceptBuilds && allowBuildInterception)
+ {
+ new AppStarter(ProductionBuild, cmd == "ProjectManager.TestingProject");
+
+ e.Handled = true;
+ }
+ }
break;
case EventType.FileSave:
@@ -258,12 +269,12 @@ private static Image GetImage(String imageName)
private void OnClick(Object sender, System.EventArgs e)
{
- new AppStarter(ExportAndOpen);
+ new AppStarter(ExportAndOpen, settingObject.AutoRun);
}
private void OnClick2(Object sender, System.EventArgs e)
{
- new AppStarter(FindAndOpen);
+ new AppStarter(FindAndOpen, settingObject.AutoRun);
}
#endregion
@@ -440,7 +451,7 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
#endregion
///
- /// Connects to COLT
+ /// Connects to COLT (todo: rename)
///
private void ConnectToCOLT(Boolean create = false)
{
@@ -466,10 +477,38 @@ private void ConnectToCOLT(Boolean create = false)
}
}
+ ///
+ /// Makes production build and optionally runs it
+ ///
+ private void ProductionBuild(Boolean run)
+ {
+ // make sure the COLT project is open
+ // todo: currently no way to know if this fails, check the state before running the build in the future
+ if (toolbarButton2.Enabled) FindAndOpen(false); else ExportAndOpen(false);
+
+ try
+ {
+ JsonRpcClient client = new JsonRpcClient();
+ client.Invoke("runProductionCompilation", new Object[] { "TEST", /*run*/false });
+
+ // leverage FD launch mechanism
+ // todo: does runProductionCompilation block? no idea atm
+ if (run)
+ {
+ EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.PlayOutput", null));
+ }
+ }
+ catch (Exception details)
+ {
+ TraceManager.Add(details.ToString(), -1);
+ }
+ }
+
+
///
/// Opens the project in COLT
///
- private void FindAndOpen()
+ private void FindAndOpen(Boolean run)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
@@ -485,10 +524,11 @@ private void FindAndOpen()
{
JsonRpcClient client = new JsonRpcClient();
client.Invoke("loadProject", new Object[] { "TEST", coltFileName });
+ if (run) client.Invoke("runBaseCompilation", new Object[] { "TEST" });
}
catch (Exception details)
{
- TraceManager.Add("FindAndOpen failed\n" + details, -1);
+ TraceManager.Add(details.ToString(), -1);
}
}
@@ -499,7 +539,7 @@ private void FindAndOpen()
}
- private void ExportAndOpen()
+ private void ExportAndOpen(Boolean run)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
@@ -507,29 +547,31 @@ private void ExportAndOpen()
// Create COLT project in it
COLTRemoteProject project = ExportCOLTProject();
- try
+ if (project != null)
{
- JsonRpcClient client = new JsonRpcClient();
- client.Invoke("createProject", new Object[] { "TEST", project });
-//Object state = client.Invoke("getState", new Object[] { "TEST" });
-//TraceManager.Add("State: " + state);
- }
- catch (Exception details)
- {
- TraceManager.Add("ExportAndOpen failed\n" + details, -1);
- }
+ try
+ {
+ JsonRpcClient client = new JsonRpcClient();
+ client.Invoke("createProject", new Object[] { "TEST", project });
+ if (run) client.Invoke("runBaseCompilation", new Object[] { "TEST" });
+ }
+ catch (Exception details)
+ {
+ TraceManager.Add(details.ToString(), -1);
+ }
- // Remove older *.colt files
- foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
- {
- if (!project.path.Contains(Path.GetFileName(oldFile)))
+ // Remove older *.colt files
+ foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
{
- File.Delete(oldFile);
+ if (!project.path.Contains(Path.GetFileName(oldFile)))
+ {
+ File.Delete(oldFile);
+ }
}
- }
- // Enable "open" button
- toolbarButton2.Enabled = true;
+ // Enable "open" button
+ toolbarButton2.Enabled = true;
+ }
}
///
@@ -568,7 +610,16 @@ private COLTRemoteProject ExportCOLTProject()
{
TraceManager.Add("Required file (" + projectName + "Config.xml) does not exist, project must be built first...", -1);
- EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));
+ try
+ {
+ allowBuildInterception = false;
+ EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));
+ }
+
+ finally
+ {
+ allowBuildInterception = true;
+ }
return null;
}
diff --git a/ColtPlugin/Rpc/AppStarter.cs b/ColtPlugin/Rpc/AppStarter.cs
index 232df80..b28b4d4 100644
--- a/ColtPlugin/Rpc/AppStarter.cs
+++ b/ColtPlugin/Rpc/AppStarter.cs
@@ -6,25 +6,27 @@
using System.Net;
using System.Timers;
- public delegate void AppStarterDelegate ();
+ public delegate void AppStarterDelegate(Boolean param);
- class AppStarter
+ public class AppStarter
{
private AppStarterDelegate callback;
+ private Boolean callbackParam;
private String tempColtFile;
private Timer timer;
private int count;
- public AppStarter(AppStarterDelegate onConnected)
+ public AppStarter(AppStarterDelegate onConnected, Boolean onConnectedParam)
{
if (COLTIsRunning())
{
- onConnected();
+ onConnected(onConnectedParam);
}
else
{
callback = onConnected;
+ callbackParam = onConnectedParam;
tempColtFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".colt");
File.CreateText(tempColtFile).Close();
@@ -57,7 +59,7 @@ private void OnTimer(Object sender = null, EventArgs e = null)
if (COLTIsRunning())
{
// we are good to go
- callback();
+ callback(callbackParam);
CleanUp();
return;
@@ -88,12 +90,21 @@ private Boolean COLTIsRunning ()
WebClient client = new WebClient();
try
{
- client.DownloadString("http://127.0.0.1:8091/crossdomain.xml");
- return true;
+ // this must always throw
+ client.DownloadString("http://127.0.0.1:8091/rpc/coltService");
}
- catch (Exception)
+ catch (WebException e)
{
+ if (e.Status == WebExceptionStatus.ProtocolError)
+ {
+ if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.InternalServerError)
+ {
+ // until rpc is ready, this should be 404, not 500
+ // todo: still does not work - colt crashes :S
+ return true;
+ }
+ }
}
return false;
diff --git a/ColtPlugin/Settings.cs b/ColtPlugin/Settings.cs
index 47090cd..9500690 100644
--- a/ColtPlugin/Settings.cs
+++ b/ColtPlugin/Settings.cs
@@ -10,7 +10,9 @@ namespace ColtPlugin
public class Settings
{
private String workingFolder = "colt";
+ private Boolean autorun = true;
private Boolean fullConfig = false;
+ private Boolean interceptBuilds = false;
///
/// Get and sets colt folder
@@ -23,6 +25,17 @@ public String WorkingFolder
set { this.workingFolder = value; }
}
+ ///
+ /// Get and sets full autorun flag
+ ///
+ [DisplayName("Automatically run COLT project")]
+ [Description("Automatically compile and run COLT project after opening it in COLT."), DefaultValue(true)]
+ public Boolean AutoRun
+ {
+ get { return this.autorun; }
+ set { this.autorun = value; }
+ }
+
///
/// Get and sets full config flag
///
@@ -34,6 +47,16 @@ public Boolean FullConfig
set { this.fullConfig = value; }
}
+ ///
+ /// Get and sets production builds flag
+ ///
+ [DisplayName("Use COLT for FD builds")]
+ [Description("Use COLT fast compiler to build your FD projects."), DefaultValue(false)]
+ public Boolean InterceptBuilds
+ {
+ get { return this.interceptBuilds; }
+ set { this.interceptBuilds = value; }
+ }
}
}