Skip to content

Commit

Permalink
Merge pull request #2 from vercellone/master
Browse files Browse the repository at this point in the history
Apply options dialog Interval property immediately
  • Loading branch information
onlyutkarsh committed Jun 4, 2015
2 parents 59458a6 + 4877f6d commit d15d24b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace VSOStatusInspector {
public class OptionsChangedEventArgs : System.EventArgs {
public double Interval { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
</COMReference>
</ItemGroup>
<ItemGroup>
<Compile Include="EventArgs\OptionsChangedEventArgs.cs" />
<Compile Include="Guids.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="VSOStatusInspectorOptions.cs">
Expand Down
15 changes: 15 additions & 0 deletions VSOStatusInspector.Package/VSOStatusInspectorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,20 @@ public int Interval
get { return _interval; }
set { _interval = value; }
}

protected override void OnApply(PageApplyEventArgs e)
{
base.OnApply(e);
if (OnOptionsChanged != null)
{
var optionsEventArg = new OptionsChangedEventArgs
{
Interval = Interval,
};
OnOptionsChanged(this, optionsEventArg);
}
}

public event EventHandler<OptionsChangedEventArgs> OnOptionsChanged;
}
}
30 changes: 24 additions & 6 deletions VSOStatusInspector.Package/VSOStatusInspectorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ namespace VSOStatusInspector
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
[ProvideBindingPath]
[ProvideOptionPage(typeof(VSOStatusInspectorOptions), EXTENSION_NAME, "General", 0, 0, true)]
public sealed class VSOStatusInspectorPackage : Package
public sealed class VSOStatusInspectorPackage : Package, IDisposable
{
private const string EXTENSION_NAME = "VSO Status Inspector";
private IVsStatusbar _bar;
private IntPtr _hdcBitmap = IntPtr.Zero;
private VSOStatusInspectorOptions _options;
private Guid _paneGuid = new Guid("{170638A1-CFD7-47C8-975A-FBAA9E532AD5}");
private IVsOutputWindow _outputWindow;
private Timer _timer;

public VSOStatusInspectorPackage()
{
Expand All @@ -45,15 +46,19 @@ protected override void Initialize()

//get interval from options
_options = (VSOStatusInspectorOptions)GetDialogPage(typeof(VSOStatusInspectorOptions));
if (_options != null)
{
_options.OnOptionsChanged += OnOptionsChanged;
}

//call the timer code first without waiting for timer trigger
OnTimerTick(null, null);

//Set the timer
var timer = new Timer();
timer.Interval = TimeSpan.FromSeconds(_options.Interval).TotalMilliseconds;
timer.Elapsed += OnTimerTick;
timer.Start();
_timer = new Timer();
_timer.Interval = TimeSpan.FromSeconds(_options.Interval).TotalMilliseconds;
_timer.Elapsed += OnTimerTick;
_timer.Start();
}

private void WriteToOutputWindow(string message)
Expand Down Expand Up @@ -154,6 +159,12 @@ private void OnTimerTick(object sender, ElapsedEventArgs e)
}
}

private void OnOptionsChanged(object sender, OptionsChangedEventArgs e)
{
_timer.Interval = TimeSpan.FromSeconds(e.Interval).TotalMilliseconds;
WriteToOutputWindow(String.Format("Interval changed to {0} seconds", e.Interval));
}

/// <summary>
/// Gets the status bar.
/// </summary>
Expand Down Expand Up @@ -208,6 +219,13 @@ public static Bitmap ResizeImage(Bitmap imgToResize, int newHeight)
return bitmap;
}


public void Dispose()
{
if (_timer != null)
{
_timer.Dispose();
}
}

}
}

0 comments on commit d15d24b

Please sign in to comment.