Skip to content

Commit

Permalink
full config option, removing old files, sending errors back to FD (fa…
Browse files Browse the repository at this point in the history
…iled)
  • Loading branch information
makc committed May 9, 2013
1 parent efe4020 commit 8ca576f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 34 deletions.
90 changes: 80 additions & 10 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class PluginMain : IPlugin
private ToolStripMenuItem menuItem;
private ToolStripButton toolbarButton;
private Boolean active = false;
private FileSystemWatcher watcher;
private String lastErrors = "";

#region Required Properties

Expand Down Expand Up @@ -129,6 +131,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
if (this.toolbarButton != null) this.toolbarButton.Enabled = as3projectIsOpen;
// deactivate if project is closed
active &= as3projectIsOpen;
if (watcher != null) watcher.EnableRaisingEvents &= as3projectIsOpen;
}
else if (cmd == "ASCompletion.ClassPath")
{
Expand Down Expand Up @@ -191,8 +194,11 @@ public void InitLocalization()
/// </summary>
public void AddEventHandlers()
{
// Set events you want to listen (combine as flags)
EventManager.AddEventHandler(this, EventType.Command);

watcher = new FileSystemWatcher();
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(OnFileChange);
}

#endregion
Expand Down Expand Up @@ -233,7 +239,7 @@ private void OnClick(Object sender, System.EventArgs e)

#endregion

#region Plugin settings stuff (reserved for future use :)
#region Plugin settings stuff

/// <summary>
/// Loads the plugin settings
Expand All @@ -259,6 +265,26 @@ public void SaveSettings()

#endregion

private void OnFileChange(Object sender, FileSystemEventArgs e)
{
if (Path.GetFileName(e.FullPath).Contains("compile_errors.log"))
{
/* This hangs FD :( now if someone could fix this...
*
StreamReader stream = File.OpenText(e.FullPath);
String errors = stream.ReadToEnd(); stream.Close();
String message = errors;
if ((lastErrors.Length > 0) && (errors.IndexOf(lastErrors) == 0))
{
message = errors.Substring(lastErrors.Length);
}
TraceManager.AddAsync(message, -3);
lastErrors = errors;
*/
}
}

/// <summary>
/// Opens the project in COLT
Expand All @@ -267,14 +293,51 @@ private void OpenInCOLT()
{
// our options: parse project.ProjectPath (xml file) or use api
AS3Project project = (AS3Project)PluginBase.CurrentProject;

String configCopy = "";
if (this.settingObject.FullConfig)
{
// Construct flex config file name (see AS3ProjectBuilder, line 140)
String projectName = project.Name.Replace(" ", "");
String configFile = Path.Combine("obj", projectName + "Config.xml");

if (!File.Exists(project.GetAbsolutePath(configFile)))
{
TraceManager.AddAsync("Required file (" + projectName + "Config.xml) does not exist, project must be built first...", -1);

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

return;
}

// Create config copy with <file-specs>...</file-specs> commented out
StreamReader src = File.OpenText(project.GetAbsolutePath(configFile));
String config = src.ReadToEnd();
src.Close();

configCopy = Path.Combine("obj", projectName + "ConfigCopy.xml");
StreamWriter dst = File.CreateText(project.GetAbsolutePath(configCopy));
dst.Write(config.Replace("<file-specs", "<!-- file-specs").Replace("/file-specs>", "/file-specs -->"));
dst.Close();
}


// Create COLT subfolder if does not exist yet
String coltFolderPath = project.GetAbsolutePath("colt");
String coltFolderPath = project.GetAbsolutePath(this.settingObject.WorkingFolder);
if (!Directory.Exists(coltFolderPath)) Directory.CreateDirectory(coltFolderPath);

// While at that, start listening for colt/compile_errors.log changes
String pathToLog = Path.Combine(coltFolderPath, "compile_errors.log");
if (File.Exists(pathToLog))
{
StreamReader errorsFile = File.OpenText(pathToLog);
lastErrors = errorsFile.ReadToEnd(); errorsFile.Close();
}
watcher.Path = coltFolderPath;
watcher.EnableRaisingEvents = true;

// Create COLT project with random name (if we'd update same file - are there file locks? how to reopen in colt?)
String coltFileName = project.GetAbsolutePath("colt/" + System.Guid.NewGuid() + ".colt");
String coltFileName = project.GetAbsolutePath(Path.Combine(this.settingObject.WorkingFolder, System.Guid.NewGuid() + ".colt"));
StreamWriter stream = File.CreateText(coltFileName);


Expand All @@ -301,8 +364,10 @@ private void OpenInCOLT()

stream.WriteLine("liveMethods=annotated");

// todo: add fd generated config here, -load-config+=...
//stream.WriteLine("compilerOptions=-swf-version\=13");
if (this.settingObject.FullConfig)
{
stream.WriteLine("compilerOptions=-load-config+\\=\"" + EscapeForCOLT(project.GetAbsolutePath(configCopy)) + "\"");
}

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

Expand All @@ -323,10 +388,15 @@ private void OpenInCOLT()

// Open it with default app (COLT)
Process.Start(coltFileName);
/* seems to be same shit ??
ProcessStartInfo psi = new ProcessStartInfo(coltFileName);
psi.UseShellExecute = true;
Process.Start(psi); */

// Remove older *.colt files
foreach (String oldFile in Directory.GetFiles(coltFolderPath, "*.colt"))
{
if (!coltFileName.Contains(Path.GetFileName(oldFile)))
{
File.Delete(oldFile);
}
}
}

private String EscapeForCOLT(String path)
Expand Down
2 changes: 1 addition & 1 deletion ColtPlugin/Resources/en_US.resX
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@
<value>Open in COLT</value>
</data>
<data name="Info.Description" xml:space="preserve">
<value>COLT FlashDevelop Plugin</value>
<value>COLT Plugin for FlashDevelop.</value>
</data>
</root>
37 changes: 14 additions & 23 deletions ColtPlugin/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,29 @@ namespace ColtPlugin
[Serializable]
public class Settings
{
private Int32 sampleNumber = 69;
private String sampleText = "This is a sample plugin.";
private Keys sampleShortcut = Keys.Control | Keys.F1;
private String workingFolder = "colt";
private Boolean fullConfig = false;

/// <summary>
/// Get and sets the sampleText
/// Get and sets colt folder
/// </summary>
[Description("A sample string setting."), DefaultValue("This is a sample plugin.")]
public String SampleText
[DisplayName("COLT Working Folder")]
[Description("Path to COLT working folder."), DefaultValue("colt")]
public String WorkingFolder
{
get { return this.sampleText; }
set { this.sampleText = value; }
get { return this.workingFolder; }
set { this.workingFolder = value; }
}

/// <summary>
/// Get and sets the sampleNumber
/// Get and sets full config flag
/// </summary>
[Description("A sample integer setting."), DefaultValue(69)]
public Int32 SampleNumber
[DisplayName("Load Full FD Configuration")]
[Description("Attempt to load full FD configuration in COLT. FD project must be built at least once first."), DefaultValue(false)]
public Boolean FullConfig
{
get { return this.sampleNumber; }
set { this.sampleNumber = value; }
}

/// <summary>
/// Get and sets the sampleShortcut
/// </summary>
[Description("A sample shortcut setting."), DefaultValue(Keys.Control | Keys.F1)]
public Keys SampleShortcut
{
get { return this.sampleShortcut; }
set { this.sampleShortcut = value; }
get { return this.fullConfig; }
set { this.fullConfig = value; }
}

}
Expand Down
Binary file modified ColtPlugin/obj/Debug/ColtPlugin.dll
Binary file not shown.

0 comments on commit 8ca576f

Please # to comment.