|
10 | 10 | using System; |
11 | 11 | using System.ComponentModel; |
12 | 12 | using System.Diagnostics.CodeAnalysis; |
13 | | -using System.Runtime.CompilerServices; |
14 | 13 | using System.Runtime.InteropServices; |
15 | 14 | using System.Threading; |
16 | 15 | using Process = System.Diagnostics.Process; |
@@ -42,13 +41,15 @@ namespace GtmExtension |
42 | 41 | [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] // Load the extension when a solution is open. |
43 | 42 | public sealed class GtmPackage : AsyncPackage |
44 | 43 | { |
45 | | - private string gtmExe; |
| 44 | + private string gtmExe, prevPath, status; |
46 | 45 | private IVsStatusbar statusBar; |
47 | 46 | private IVsEditorAdaptersFactoryService editor; |
48 | 47 | private WindowEvents windowEvents; |
49 | 48 | private DocumentEvents documentEvents; |
50 | 49 | private IVsTextManager textManager; |
51 | 50 | private IWpfTextView wpfTextView; |
| 51 | + private DateTime lastUpdate; |
| 52 | + private static readonly TimeSpan updateInterval = TimeSpan.FromSeconds(30.0); |
52 | 53 |
|
53 | 54 | /// <summary> |
54 | 55 | /// GtmPackage GUID string. |
@@ -229,9 +230,25 @@ private void DocumentEvents_DocumentSaved(Document Document) |
229 | 230 | { |
230 | 231 | Update(Document.FullName); |
231 | 232 | } |
232 | | - private void Update(string path, [CallerMemberName] string message = null) |
| 233 | + private void Update(string path) |
233 | 234 | { |
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; |
235 | 252 | } |
236 | 253 | #endregion |
237 | 254 | } |
|
0 commit comments