Skip to content

Commit

Permalink
fixes #3, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
makc committed Jun 10, 2013
1 parent 03c1927 commit c06c271
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 37 deletions.
4 changes: 4 additions & 0 deletions ColtPlugin/ColtPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@
<Name>PluginCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\colt_run.png" />
<EmbeddedResource Include="Resources\colt_save.png" />
</ItemGroup>
</Project>
153 changes: 119 additions & 34 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public class PluginMain : IPlugin
private String pluginHelp = "makc3d.wordpress.com/about/";
private String pluginDesc = "COLT FD Plugin";
private String pluginAuth = "Makc"; // as if
private String buttonText = "Open in COLT";
private String settingFilename;
private Settings settingObject;
private ToolStripMenuItem menuItem;
private ToolStripButton toolbarButton;
private ToolStripButton toolbarButton, toolbarButton2;
private FileSystemWatcher watcher;
private String pathToLog;
private System.Timers.Timer timer;
Expand Down Expand Up @@ -133,6 +132,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
Boolean as3projectIsOpen = (project != null) && (project.Language == "as3");
if (menuItem != null) menuItem.Enabled = as3projectIsOpen;
if (toolbarButton != null) toolbarButton.Enabled = as3projectIsOpen;
if (toolbarButton2 != null) toolbarButton2.Enabled = as3projectIsOpen && (GetCOLTFile() != null);
// modified or new project - reconnect in any case
ConnectToCOLT();
}
Expand All @@ -144,7 +144,8 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
else if (cmd == "ProjectManager.ToolBar")
{
Object toolStrip = (e as DataEvent).Data;
CreateToolbarButton(toolStrip as ToolStrip);
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));
}
break;

Expand Down Expand Up @@ -206,7 +207,6 @@ public void InitLocalization()
break;
}
pluginDesc = LocaleHelper.GetString("Info.Description");
buttonText = LocaleHelper.GetString("Info.ButtonText");
}

/// <summary>
Expand All @@ -229,19 +229,20 @@ public void AddEventHandlers()

private void CreateMenuItem(ToolStripMenuItem projectMenu)
{
menuItem = new ToolStripMenuItem(buttonText, GetImage("colt.png"), new EventHandler(OnClick), null);
menuItem = new ToolStripMenuItem(LocaleHelper.GetString("Menu.ExportToCOLT"), GetImage("colt_save.png"), new EventHandler(OnClick), null);
menuItem.Enabled = false;
projectMenu.DropDownItems.Add(menuItem);
}

private void CreateToolbarButton(ToolStrip toolStrip)
private ToolStripButton CreateToolbarButton(ToolStrip toolStrip, String image, String hint, EventHandler handler)
{
toolbarButton = new ToolStripButton();
toolbarButton.Image = GetImage("colt.png");
toolbarButton.Text = buttonText;
toolbarButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
toolbarButton.Click += new EventHandler(OnClick);
toolStrip.Items.Add(toolbarButton);
ToolStripButton button = new ToolStripButton();
button.Image = GetImage(image);
button.Text = LocaleHelper.GetString(hint);
button.DisplayStyle = ToolStripItemDisplayStyle.Image;
button.Click += handler;
toolStrip.Items.Add(button);
return button;
}

/// <summary>
Expand All @@ -259,6 +260,11 @@ private void OnClick(Object sender, System.EventArgs e)
OpenInCOLT();
}

private void OnClick2(Object sender, System.EventArgs e)
{
OpenInCOLT(false);
}

#endregion

#region Plugin settings stuff
Expand Down Expand Up @@ -374,6 +380,8 @@ private void ShowErrors()

#endregion

#region Meta tags

/// <summary>
/// Generate meta tags
/// </summary>
Expand Down Expand Up @@ -428,6 +436,8 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
return "";
}

#endregion

/// <summary>
/// Connects to COLT
/// </summary>
Expand Down Expand Up @@ -458,7 +468,62 @@ private void ConnectToCOLT(Boolean create = false)
/// <summary>
/// Opens the project in COLT
/// </summary>
private void OpenInCOLT()
private void OpenInCOLT(Boolean create = true)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
ConnectToCOLT(true);


// Find or create COLT project to open
String coltFileName = create ? ExportCOLTFile() : GetCOLTFile();


// Open it with default app (COLT)
try
{
if (coltFileName != null)
{
Process.Start(coltFileName);
}

else
{
toolbarButton2.Enabled = false;
}
}

catch (Exception e)
{
TraceManager.Add("Could not start COLT: " + e.ToString());
}

}

/// <summary>
/// Returns path to existing COLT project or null.
/// </summary>
private String GetCOLTFile()
{
IProject project = PluginBase.CurrentProject;

try
{
String[] files = Directory.GetFiles(project.GetAbsolutePath(settingObject.WorkingFolder), "*.colt");
if (files.Length > 0) return files[0];
}

catch (Exception)
{
}

return null;
}

/// <summary>
/// Exports the project to COLT and returns path to it or null.
/// </summary>
private String ExportCOLTFile()
{
// our options: parse project.ProjectPath (xml file) or use api
AS3Project project = (AS3Project)PluginBase.CurrentProject;
Expand All @@ -476,7 +541,7 @@ private void OpenInCOLT()

EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));

return;
return null;
}

// Create config copy with <file-specs>...</file-specs> commented out
Expand All @@ -486,14 +551,9 @@ private void OpenInCOLT()
.Replace("<file-specs", "<!-- file-specs")
.Replace("/file-specs>", "/file-specs -->"));
}


// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
ConnectToCOLT(true);


// Create COLT project with random name (todo: separate buttons for project export and project open)
// Create COLT project with random name
String coltFileName = project.GetAbsolutePath(Path.Combine(settingObject.WorkingFolder, System.Guid.NewGuid() + ".colt"));
StreamWriter stream = File.CreateText(coltFileName);

Expand All @@ -510,9 +570,9 @@ private void OpenInCOLT()
stream.WriteLine("libraryPaths=" + libraryPaths);

stream.WriteLine("clearMessages=true");

stream.WriteLine("targetPlayerVersion=" + project.MovieOptions.Version + ".0");

stream.WriteLine("mainClass=" + EscapeForCOLT(project.GetAbsolutePath(project.CompileTargets[0])));

stream.WriteLine("maxLoopIterations=10000");
Expand All @@ -526,7 +586,7 @@ private void OpenInCOLT()
stream.WriteLine("useCustomSDKConfiguration=true");
stream.WriteLine("customConfigPath=" + EscapeForCOLT(project.GetAbsolutePath(configCopy)) + "\"");
}

stream.WriteLine("target=SWF"); // use project.MovieOptions.Platform switch ??

String outputPath = project.OutputPath;
Expand All @@ -549,24 +609,42 @@ private void OpenInCOLT()
sourcePaths += EscapeForCOLT(project.GetAbsolutePath(sourcePath)) + ";";
stream.WriteLine("sourcePaths=" + sourcePaths);

// size, frame rate and background color
stream.WriteLine("compilerOptions=-default-size " + project.MovieOptions.Width + " " + project.MovieOptions.Height +
" -default-frame-rate " + project.MovieOptions.Fps +
" -default-background-color " + project.MovieOptions.BackgroundColorInt);

stream.Close();

// Open it with default app (COLT)
try
// size, frame rate and background color
String[] coltAdditionalOptionsKeys = {
"-default-size",
"-default-frame-rate",
"-default-background-color"
};
String[] coltAdditionalOptions = {
coltAdditionalOptionsKeys[0] + " " + project.MovieOptions.Width + " " + project.MovieOptions.Height,
coltAdditionalOptionsKeys[1] + " " + project.MovieOptions.Fps,
coltAdditionalOptionsKeys[2] + " " + project.MovieOptions.BackgroundColorInt
};

String additionalOptions = "";
foreach (String option in project.CompilerOptions.Additional)
{
Process.Start(coltFileName);
for (int i = 0; i < coltAdditionalOptionsKeys.Length; i++)
{
if (option.Contains(coltAdditionalOptionsKeys[i]))
{
coltAdditionalOptions[i] = "";
}
}
additionalOptions += option + " ";
}

catch (Exception e)
foreach (String option in coltAdditionalOptions)
{
TraceManager.Add("Could not start COLT: " + e.ToString());
additionalOptions += option + " ";
}

stream.WriteLine("compilerOptions=" + additionalOptions.Trim());

stream.Close();


// Remove older *.colt files
foreach (String oldFile in Directory.GetFiles(project.GetAbsolutePath(settingObject.WorkingFolder), "*.colt"))
{
Expand All @@ -575,6 +653,13 @@ private void OpenInCOLT()
File.Delete(oldFile);
}
}


// Enable "open" button
toolbarButton2.Enabled = true;


return coltFileName;
}

private String EscapeForCOLT(String path)
Expand Down
9 changes: 6 additions & 3 deletions ColtPlugin/Resources/en_US.resX
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Info.ButtonText" xml:space="preserve">
<value>Open in COLT</value>
</data>
<data name="Info.Description" xml:space="preserve">
<value>COLT Plugin for FlashDevelop.</value>
</data>
<data name="Menu.ExportToCOLT" xml:space="preserve">
<value>Export to COLT</value>
</data>
<data name="Menu.OpenInCOLT" xml:space="preserve">
<value>Open in COLT</value>
</data>
</root>
Binary file modified ColtPlugin/obj/Debug/ColtPlugin.dll
Binary file not shown.

0 comments on commit c06c271

Please # to comment.