diff --git a/ColtPlugin/PluginMain.cs b/ColtPlugin/PluginMain.cs index 905cbf7..204504e 100644 --- a/ColtPlugin/PluginMain.cs +++ b/ColtPlugin/PluginMain.cs @@ -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 @@ -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") { @@ -191,8 +194,11 @@ public void InitLocalization() /// 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 @@ -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 /// /// Loads the plugin settings @@ -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; + */ + } + } /// /// Opens the project in COLT @@ -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 ... 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 -->")); + 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); @@ -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 ?? @@ -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) diff --git a/ColtPlugin/Resources/en_US.resX b/ColtPlugin/Resources/en_US.resX index 7ecc2a0..92f45f0 100644 --- a/ColtPlugin/Resources/en_US.resX +++ b/ColtPlugin/Resources/en_US.resX @@ -121,6 +121,6 @@ Open in COLT - COLT FlashDevelop Plugin + COLT Plugin for FlashDevelop. \ No newline at end of file diff --git a/ColtPlugin/Settings.cs b/ColtPlugin/Settings.cs index 63b7c14..47090cd 100644 --- a/ColtPlugin/Settings.cs +++ b/ColtPlugin/Settings.cs @@ -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; /// - /// Get and sets the sampleText + /// Get and sets colt folder /// - [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; } } /// - /// Get and sets the sampleNumber + /// Get and sets full config flag /// - [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; } - } - - /// - /// Get and sets the sampleShortcut - /// - [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; } } } diff --git a/ColtPlugin/obj/Debug/ColtPlugin.dll b/ColtPlugin/obj/Debug/ColtPlugin.dll index 5248e8a..1f6884e 100644 Binary files a/ColtPlugin/obj/Debug/ColtPlugin.dll and b/ColtPlugin/obj/Debug/ColtPlugin.dll differ