Skip to content

Commit

Permalink
Merge pull request #1 from elsassph/master
Browse files Browse the repository at this point in the history
Better errors handling (parse errors on the UI thread, clear errors panel on new errors and FileSave)
  • Loading branch information
makc committed May 13, 2013
2 parents 3ef1ac3 + 13f26a2 commit e74a545
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
Object toolStrip = (e as DataEvent).Data;
CreateToolbarButton(toolStrip as ToolStrip);
}
break;
break;

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

Expand Down Expand Up @@ -196,7 +200,7 @@ public void InitLocalization()
/// </summary>
public void AddEventHandlers()
{
EventManager.AddEventHandler(this, EventType.Command);
EventManager.AddEventHandler(this, EventType.Command | EventType.FileSave);

watcher = new FileSystemWatcher();
watcher.NotifyFilter = NotifyFilters.LastWrite;
Expand Down Expand Up @@ -273,11 +277,10 @@ private void OnFileChange(Object sender, FileSystemEventArgs e)
{
if (e.FullPath.EndsWith("compile_errors.log"))
{
// [09.05.2013 16:47:46] Philippe Elsass: the problem is that the event may happen before you are allowed to read the file
// [09.05.2013 16:48:03] Philippe Elsass: that's why the FlashErrorWatcher uses a Timer to wait a bit before reading the file
if (timer == null)
{
timer = new System.Timers.Timer();
timer.SynchronizingObject = (Form)PluginBase.MainForm; // thread safe
timer.Interval = 200;
timer.Elapsed += OnTimerElapsed;
timer.Enabled = true;
Expand All @@ -291,6 +294,8 @@ private void OnTimerElapsed(object sender, EventArgs e)
timer.Stop();
timer = null;

ClearErrors();

String message = File.ReadAllText(pathToLog);

// COLT copies sources to "incremental" folder, so let's try to find correct path and patch the output
Expand All @@ -299,6 +304,7 @@ private void OnTimerElapsed(object sender, EventArgs e)

// [09.05.2013 17:26:54] Philippe Elsass: make sure you send the log line by line to the Output
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)
Expand All @@ -315,16 +321,31 @@ private void OnTimerElapsed(object sender, EventArgs e)
{
if (File.Exists(PluginBase.CurrentProject.GetAbsolutePath(Path.Combine(sources[i], file))))
{
TraceManager.AddAsync(line.Replace(incremental, sources[i]), -3); break;
TraceManager.Add(line.Replace(incremental, sources[i]), -3);
hasErrors = true;
break;
}
}
}
else
{
// send as is
TraceManager.AddAsync(line, -3);
TraceManager.Add(line, -3);
}
}

if (hasErrors) ShowErrors();
}

private void ClearErrors()
{
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ResultsPanel.ClearResults", null));
}

private void ShowErrors()
{
// should be an option: if the panel was hidden it captures keyboard focus
//EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ResultsPanel.ShowResults", null));
}

#endregion
Expand All @@ -346,7 +367,7 @@ private void OpenInCOLT()

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

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

0 comments on commit e74a545

Please # to comment.