progress on issues #5 and #7

This commit is contained in:
Vitalii Ganzha 2016-01-05 19:31:37 -08:00
parent df15518a52
commit c4d7c3c21a
9 changed files with 265 additions and 50 deletions

View file

@ -1,24 +1,61 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
namespace VitaliiGanzha.VsDingExtension
{
public class Players : IDisposable
{
private readonly Dictionary<EventType, IList<SoundPlayer>> eventTypeToSoundPlayerMapping;
using System;
using System.Collections.Generic;
using System.IO;
using System.Media;
using Microsoft.VisualStudio.Shell;
public Players()
public sealed class Players : IDisposable
{
private readonly SoundsSelectOptionsPage overridesSettings;
private Dictionary<EventType, IList<SoundPlayer>> eventTypeToSoundPlayerMapping;
public Players(SoundsSelectOptionsPage overridesSettings)
{
eventTypeToSoundPlayerMapping = new Dictionary<EventType, IList<SoundPlayer>>();
eventTypeToSoundPlayerMapping[EventType.BuildCompleted] = new List<SoundPlayer>() { new SoundPlayer(Resources.build) };
eventTypeToSoundPlayerMapping[EventType.BreakpointHit] = new List<SoundPlayer>() { new SoundPlayer(Resources.debug) };
eventTypeToSoundPlayerMapping[EventType.TestsCompletedSuccess] = new List<SoundPlayer>() { new SoundPlayer(Resources.ding) };
eventTypeToSoundPlayerMapping[EventType.TestsCompletedFailure] = new List<SoundPlayer>() { new SoundPlayer(Resources.test_failed) };
this.overridesSettings = overridesSettings;
this.SetupSounds();
}
private void SetupSounds()
{
// Add regular sounds
var tempMapping = new Dictionary<EventType, IList<SoundPlayer>>();
tempMapping[EventType.BuildCompleted] = new List<SoundPlayer>() { new SoundPlayer(Resources.build) };
tempMapping[EventType.BreakpointHit] = new List<SoundPlayer>() { new SoundPlayer(Resources.debug) };
tempMapping[EventType.TestsCompletedSuccess] = new List<SoundPlayer>()
{
new SoundPlayer(Resources.ding)
};
tempMapping[EventType.TestsCompletedFailure] = new List<SoundPlayer>()
{
new SoundPlayer(Resources.test_failed)
};
// Add custom sounds
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnBuildSound, this.overridesSettings.CustomOnBuildSoundLocation, EventType.BuildCompleted);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnBreakpointHitSound, this.overridesSettings.CustomOnBreakpointHitSoundLocation, EventType.BreakpointHit);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnTestCompleteFailureSound, this.overridesSettings.CustomOnTestCompleteFailureSoundLocation, EventType.TestsCompletedFailure);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnTestCompleteSuccesSound, this.overridesSettings.CustomOnTestCompleteSuccesSoundLocation, EventType.TestsCompletedSuccess);
this.eventTypeToSoundPlayerMapping = tempMapping;
}
private void AddSoundOverrideIf(Dictionary<EventType, IList<SoundPlayer>> tempMapping, bool shouldAdd, string fileLocation, EventType eventType)
{
if (shouldAdd)
{
if (!string.IsNullOrWhiteSpace(fileLocation) &&
File.Exists(fileLocation))
{
tempMapping[eventType].Insert(0, new SoundPlayer(fileLocation));
}
}
}
public void SoundSettingsChanged()
{
this.SetupSounds();
}
public void PlaySoundSafe(EventType eventType)

View file

@ -9,7 +9,19 @@ namespace VitaliiGanzha.VsDingExtension
{
private EventType eventType = EventType.None;
public SoundsSelectOptionsPage OptionsPage = null;
public SoundsSelectOptionsPage optionsPage = null;
public SoundsSelectOptionsPage OptionsPage
{
get { return this.optionsPage; }
set
{
this.optionsPage = value;
this.ReadOptions();
this.optionsPage.StoreOptionsNotifier += this.StoreOptions;
this.optionsPage.OnActivateHandler += this.ReadOptions;
}
}
[Category("Data")]
[Description("Gets or sets the event type of the sound to override sound for")]
@ -30,13 +42,11 @@ namespace VitaliiGanzha.VsDingExtension
public SingleSoundSelectControl()
{
InitializeComponent();
ReadOptions();
}
private void chkUseDifferentSound_CheckedChanged(object sender, System.EventArgs e)
{
ValidateProperties();
this.StoreOptions();
}
private void btnBrowse_Click(object sender, EventArgs e)
@ -52,7 +62,6 @@ namespace VitaliiGanzha.VsDingExtension
if (File.Exists(file))
{
this.selectedFileEdit.Text = file;
this.StoreOptions();
}
}

View file

@ -18,6 +18,12 @@ namespace VitaliiGanzha.VsDingExtension
#region Properties
public Action OnApplyHandler { get; set; }
public Action StoreOptionsNotifier { get; set; }
public Action OnActivateHandler { get; set; }
/// <summary>
/// Gets the window an instance of DialogPage that it uses as its user interface.
/// </summary>
@ -46,6 +52,27 @@ namespace VitaliiGanzha.VsDingExtension
}
}
protected override void OnApply(DialogPage.PageApplyEventArgs e)
{
if (this.StoreOptionsNotifier != null)
{
this.StoreOptionsNotifier();
}
if (this.OnApplyHandler != null)
{
this.OnApplyHandler();
}
}
protected override void OnActivate(CancelEventArgs cancelEventArgs)
{
if (this.OnActivateHandler != null)
{
this.OnActivateHandler();
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool OverrideOnBuildSound { get; set; }

View file

@ -1,24 +1,19 @@
namespace VitaliiGanzha.VsDingExtension
namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
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 Microsoft.VisualStudio.TestWindow.Controller;
using Microsoft.VisualStudio.TestWindow.Extensibility;
using Task = System.Threading.Tasks.Task;
using Process = System.Diagnostics.Process;
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.1", IconResourceID = 400)]
[Guid(GuidList.guidVsDingExtensionProjectPkgString)]
@ -31,7 +26,8 @@
private BuildEvents buildEvents;
private DebuggerEvents debugEvents;
private OptionsDialog _options = null;
private Players players = new Players();
private SoundsSelectOptionsPage soundOverridesSettings = null;
private Players players = null;
public VsDingExtensionProjectPackage()
{
@ -49,6 +45,8 @@
buildEvents = applicationObject.Events.BuildEvents;
debugEvents = applicationObject.Events.DebuggerEvents;
players = new Players(this.SoundSettingsOverrides);
this.soundOverridesSettings.OnApplyHandler += () => this.players.SoundSettingsChanged();
SetupEventHandlers();
}
@ -95,12 +93,19 @@
}
}
private void HandleEventSafe(EventType eventType, string messageText)
private SoundsSelectOptionsPage SoundSettingsOverrides
{
HandleEventSafe(eventType, messageText, ToolTipIcon.Info);
get
{
if (this.soundOverridesSettings == null)
{
this.soundOverridesSettings = (SoundsSelectOptionsPage)GetDialogPage(typeof(SoundsSelectOptionsPage));
}
return this.soundOverridesSettings;
}
}
private void HandleEventSafe(EventType eventType, string messageText, ToolTipIcon icon)
private void HandleEventSafe(EventType eventType, string messageText, ToolTipIcon icon = ToolTipIcon.Info)
{
if (!ShouldPerformNotificationAction())
{
@ -111,12 +116,7 @@
ShowNotifyMessage(messageText, icon);
}
private void ShowNotifyMessage(string messageText)
{
ShowNotifyMessage(messageText, ToolTipIcon.Info);
}
private void ShowNotifyMessage(string messageText, ToolTipIcon icon)
private void ShowNotifyMessage(string messageText, ToolTipIcon icon = ToolTipIcon.Info)
{
if (!_options.ShowTrayNotifications)
{
@ -125,11 +125,11 @@
if (Options.ShowTrayDisableMessage)
{
string autoAppendMessage = System.Environment.NewLine + "You can disable this notification in:" + System.Environment.NewLine + "Tools->Options->Ding->Show tray notifications";
string autoAppendMessage = Environment.NewLine + "You can disable this notification in:" + Environment.NewLine + "Tools->Options->Ding->Show tray notifications";
messageText = string.Format("{0}{1}", messageText, autoAppendMessage);
}
System.Threading.Tasks.Task.Run(async () =>
Task.Run(async () =>
{
var tray = new NotifyIcon
{
@ -141,7 +141,7 @@
};
tray.ShowBalloonTip(5000);
await System.Threading.Tasks.Task.Delay(5000);
await Task.Delay(5000);
tray.Icon = (Icon)null;
tray.Visible = false;
tray.Dispose();

View file

@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class WinApiHelper
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]