Skip to content

Commit

Permalink
in fact, let's wait for proper api with updates. also closes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
makc committed Jun 7, 2013
1 parent 76d952a commit a16b148
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
99 changes: 58 additions & 41 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class PluginMain : IPlugin
private Settings settingObject;
private ToolStripMenuItem menuItem;
private ToolStripButton toolbarButton;
private Boolean active = false;
private FileSystemWatcher watcher;
private String pathToLog;
private System.Timers.Timer timer;
Expand Down Expand Up @@ -134,21 +133,8 @@ 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;
// deactivate
active = false;
if (watcher != null) watcher.EnableRaisingEvents = false;
if (timer != null) { timer.Stop(); timer = null; }
}
else if (cmd == "ASCompletion.ClassPath")
{
// apparently project setting changes; reopen already opened COLT project
if (active && (settingObject.AlwaysOverwriteProjects || (MessageBox.Show(
LocaleHelper.GetString("SettingsChanged.DialogText"),
LocaleHelper.GetString("SettingsChanged.DialogTitle"),
MessageBoxButtons.YesNo) == DialogResult.Yes)))
{
OpenInCOLT();
}
// modified or new project - reconnect in any case
ConnectToCOLT();
}
else if (cmd == "ProjectManager.Menu")
{
Expand All @@ -163,7 +149,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
break;

case EventType.FileSave:
if (active) ClearErrors();
if (watcher.EnableRaisingEvents) ClearErrors();
break;

case EventType.Keys: // shortcut pressed
Expand Down Expand Up @@ -244,6 +230,7 @@ public void AddEventHandlers()
private void CreateMenuItem(ToolStripMenuItem projectMenu)
{
menuItem = new ToolStripMenuItem(buttonText, GetImage("colt.png"), new EventHandler(OnClick), null);
menuItem.Enabled = false;
projectMenu.DropDownItems.Add(menuItem);
}

Expand All @@ -269,7 +256,6 @@ private static Image GetImage(String imageName)

private void OnClick(Object sender, System.EventArgs e)
{
active = true;
OpenInCOLT();
}

Expand Down Expand Up @@ -332,35 +318,43 @@ private void OnTimerElapsed(object sender, EventArgs e)
String incremental = "colt\\incremental";
String[] sources = PluginBase.CurrentProject.SourcePaths;

// [09.05.2013 17:26:54] Philippe Elsass: make sure you send the log line by line to the Output
// send the log line by line
String[] messageLines = message.Split(new Char[] {'\r', '\n'});
bool hasErrors = false;
foreach (String line in messageLines) if (line.Length > 0)
{
// [08.05.2013 18:04:15] Philippe Elsass: you can also specify '-3' as 2nd parameter to the traces (error level)
// [08.05.2013 18:05:02] Philippe Elsass: so it will appear in red in the output and have an error icon in the results panel
int errorLevel = -3;
if (line.Contains(incremental))
{
// carefully take the file name out
String file = line.Substring(0, line.IndexOf("): col"));
file = file.Substring(0, file.LastIndexOf("("));
file = file.Substring(file.IndexOf(incremental) + incremental.Length + 1);

// look for it in all source folders
for (int i = 0; i < sources.Length; i++)
try
{
if (File.Exists(PluginBase.CurrentProject.GetAbsolutePath(Path.Combine(sources[i], file))))
// carefully take the file name out
String file = line.Substring(0, line.IndexOf("): col"));
file = file.Substring(0, file.LastIndexOf("("));
file = file.Substring(file.IndexOf(incremental) + incremental.Length + 1);

// look for it in all source folders
for (int i = 0; i < sources.Length; i++)
{
TraceManager.Add(line.Replace(incremental, sources[i]), -3);
hasErrors = true;
break;
if (File.Exists(PluginBase.CurrentProject.GetAbsolutePath(Path.Combine(sources[i], file))))
{
TraceManager.Add(line.Replace(incremental, sources[i]), errorLevel);
hasErrors = true;
break;
}
}
}

catch (Exception)
{
// unexpected format, send as is
TraceManager.Add(line, errorLevel);
}
}
else
{
// send as is
TraceManager.Add(line, -3);
TraceManager.Add(line, errorLevel);
}
}

Expand Down Expand Up @@ -434,6 +428,33 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
return "";
}

/// <summary>
/// Connects to COLT
/// </summary>
private void ConnectToCOLT(Boolean create = false)
{
// todo: clean up after previous connection

// for now, shut down errors log watcher and its timer
watcher.EnableRaisingEvents = false;
if (timer != null) { timer.Stop(); timer = null; }

// todo: if current project is opened in COLT - connect to it

// for now, create the folder and subscribe to errors log updates
IProject project = PluginBase.CurrentProject;

String coltFolderPath = project.GetAbsolutePath(settingObject.WorkingFolder);
if (create && !Directory.Exists(coltFolderPath)) Directory.CreateDirectory(coltFolderPath);

if (Directory.Exists(coltFolderPath))
{
pathToLog = Path.Combine(coltFolderPath, "compile_errors.log");
watcher.Path = coltFolderPath;
watcher.EnableRaisingEvents = true;
}
}

/// <summary>
/// Opens the project in COLT
/// </summary>
Expand Down Expand Up @@ -468,15 +489,11 @@ private void OpenInCOLT()


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

// While at that, start listening for colt/compile_errors.log changes
pathToLog = Path.Combine(coltFolderPath, "compile_errors.log");
watcher.Path = coltFolderPath;
watcher.EnableRaisingEvents = true;
ConnectToCOLT(true);


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

Expand Down Expand Up @@ -551,7 +568,7 @@ private void OpenInCOLT()
}

// Remove older *.colt files
foreach (String oldFile in Directory.GetFiles(coltFolderPath, "*.colt"))
foreach (String oldFile in Directory.GetFiles(project.GetAbsolutePath(settingObject.WorkingFolder), "*.colt"))
{
if (!coltFileName.Contains(Path.GetFileName(oldFile)))
{
Expand Down
6 changes: 0 additions & 6 deletions ColtPlugin/Resources/en_US.resX
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,4 @@
<data name="Info.Description" xml:space="preserve">
<value>COLT Plugin for FlashDevelop.</value>
</data>
<data name="SettingsChanged.DialogText" xml:space="preserve">
<value>Do you want to overwrite COLT project to reflect new settings?</value>
</data>
<data name="SettingsChanged.DialogTitle" xml:space="preserve">
<value>Project settings have changed</value>
</data>
</root>
12 changes: 0 additions & 12 deletions ColtPlugin/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class Settings
{
private String workingFolder = "colt";
private Boolean fullConfig = false;
private Boolean alwaysOverwriteProjects = false;

/// <summary>
/// Get and sets colt folder
Expand All @@ -35,17 +34,6 @@ public Boolean FullConfig
set { this.fullConfig = value; }
}

/// <summary>
/// Get and sets full config flag
/// </summary>
[DisplayName("Always overwrite COLT projects")]
[Description("Select this option to always overwrite COLT projects when FD project settings change."), DefaultValue(false)]
public Boolean AlwaysOverwriteProjects
{
get { return this.alwaysOverwriteProjects; }
set { this.alwaysOverwriteProjects = value; }
}

}

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

0 comments on commit a16b148

Please # to comment.