fixes for new options functionaity

This commit is contained in:
Vitalii Ganzha 2015-06-05 14:48:04 -07:00
parent 00a0240863
commit 006d1c1d0b
3 changed files with 53 additions and 43 deletions

View File

@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5BD9D4DB-8683-4698-8D24-01EE7306F73A}"
ProjectSection(SolutionItems) = preProject
IntegrationTests.testsettings = IntegrationTests.testsettings

View File

@ -1,9 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>..\VsDingExtensionProject\Resources\speaker.ico</ApplicationIcon>
@ -130,6 +135,7 @@
<Compile Include="..\VsDingExtensionProject\Guids.cs" />
<Compile Include="..\VsDingExtensionProject\OptionsDialog.cs">
<Link>OptionsDialog.cs</Link>
<SubType>Component</SubType>
</Compile>
<Compile Include="..\VsDingExtensionProject\Properties\AssemblyInfo.cs" />
<Compile Include="..\VsDingExtensionProject\Resources.Designer.cs" />

View File

@ -1,19 +1,21 @@
using System;
namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Media;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TestWindow.Extensibility;
using Process = System.Diagnostics.Process;
namespace VitaliiGanzha.VsDingExtension
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidVsDingExtensionProjectPkgString)]
@ -28,17 +30,13 @@ namespace VitaliiGanzha.VsDingExtension
private SoundPlayer buildCompleteSoundPlayer;
private SoundPlayer debugSoundPlayer;
private SoundPlayer testCompleteSoundPlayer;
private bool onlyOnUnFocus;
private bool onBuild;
private bool onTestRunCompleted;
private bool onBreakpoint;
private OptionsDialog _options = null;
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
public VsDingExtensionProjectPackage()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", ToString()));
@ -46,12 +44,6 @@ namespace VitaliiGanzha.VsDingExtension
#region Package Members
protected override void OnSaveOptions(string key, Stream stream)
{
base.OnSaveOptions(key, stream);
ApplySettings();
}
protected override void Initialize()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
@ -62,18 +54,17 @@ namespace VitaliiGanzha.VsDingExtension
testCompleteSoundPlayer = new SoundPlayer(Resources.ding);
applicationObject = (DTE2)GetService(typeof(DTE));
ApplySettings();
buildEvents = applicationObject.Events.BuildEvents;
debugEvents = applicationObject.Events.DebuggerEvents;
buildEvents.OnBuildDone += (scope, action) =>
{
if (onBuild)
if (Options.BuildBeep)
PlaySafe(buildCompleteSoundPlayer);
};
debugEvents.OnEnterBreakMode += delegate(dbgEventReason reason, ref dbgExecutionAction action)
{
if (reason != dbgEventReason.dbgEventReasonStep && onBreakpoint)
if (reason != dbgEventReason.dbgEventReasonStep && Options.BreakpointBeep)
{
PlaySafe(debugSoundPlayer);
}
@ -92,9 +83,21 @@ namespace VitaliiGanzha.VsDingExtension
operationState.StateChanged += OperationStateOnStateChanged;
}
private OptionsDialog Options
{
get
{
if (_options == null)
{
_options = (OptionsDialog)GetDialogPage(typeof(OptionsDialog));
}
return _options;
}
}
private void PlaySafe(SoundPlayer soundPlayer)
{
if (onlyOnUnFocus && !ApplicationIsActivated())
if (ShouldPlaySound())
{
try
{
@ -107,25 +110,24 @@ namespace VitaliiGanzha.VsDingExtension
}
}
private bool ShouldPlaySound()
{
if (!Options.BeepOnUnfocus)
{
return true;
}
return Options.BeepOnUnfocus && !ApplicationIsActivated();
}
private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs)
{
if (onTestRunCompleted && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished))
if (Options.TestBeep && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished))
{
PlaySafe(testCompleteSoundPlayer);
}
}
#endregion
private void ApplySettings()
{
onlyOnUnFocus = (applicationObject.Properties["Ding", "Options"].Item("BeepOnUnfocus").Value as bool?) ?? false;
onBreakpoint = (applicationObject.Properties["Ding", "Options"].Item("BreakpointBeep").Value as bool?) ?? true;
onTestRunCompleted = (applicationObject.Properties["Ding", "Options"].Item("TestBeep").Value as bool?) ?? true;
onBuild = (applicationObject.Properties["Ding", "Options"].Item("BuildBeep").Value as bool?) ?? true;
Debug.WriteLine(string.Format("OnlyOnUnFocus: {0}", onlyOnUnFocus));
}
public bool ApplicationIsActivated()
{
var activatedHandle = GetForegroundWindow();