Skip to content

Commit dffc537

Browse files
committed
Executed command gtm record.
1 parent 450aa0b commit dffc537

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/GtmExtension/GtmPackage.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System;
1111
using System.ComponentModel;
1212
using System.Diagnostics.CodeAnalysis;
13-
using System.Runtime.CompilerServices;
1413
using System.Runtime.InteropServices;
1514
using System.Threading;
1615
using Process = System.Diagnostics.Process;
@@ -42,13 +41,15 @@ namespace GtmExtension
4241
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] // Load the extension when a solution is open.
4342
public sealed class GtmPackage : AsyncPackage
4443
{
45-
private string gtmExe;
44+
private string gtmExe, prevPath, status;
4645
private IVsStatusbar statusBar;
4746
private IVsEditorAdaptersFactoryService editor;
4847
private WindowEvents windowEvents;
4948
private DocumentEvents documentEvents;
5049
private IVsTextManager textManager;
5150
private IWpfTextView wpfTextView;
51+
private DateTime lastUpdate;
52+
private static readonly TimeSpan updateInterval = TimeSpan.FromSeconds(30.0);
5253

5354
/// <summary>
5455
/// GtmPackage GUID string.
@@ -229,9 +230,25 @@ private void DocumentEvents_DocumentSaved(Document Document)
229230
{
230231
Update(Document.FullName);
231232
}
232-
private void Update(string path, [CallerMemberName] string message = null)
233+
private void Update(string path)
233234
{
234-
statusBar.SetText(message + ": " + path + " (" + DateTime.Now.ToString("o") + ").");
235+
var time = DateTime.Now;
236+
if (time - lastUpdate >= updateInterval ||
237+
path != prevPath)
238+
{
239+
status = ExecuteForOutput(gtmExe, $"record --status \"{path}\"");
240+
if (!string.IsNullOrWhiteSpace(status))
241+
{
242+
statusBar.SetText($"GTM: {status}*");
243+
}
244+
245+
prevPath = path;
246+
}
247+
else if (!string.IsNullOrWhiteSpace(status))
248+
{
249+
statusBar.SetText($"GTM: {status}");
250+
}
251+
lastUpdate = time;
235252
}
236253
#endregion
237254
}

0 commit comments

Comments
 (0)