Skip to content

Commit

Permalink
First PoC of Tootip Info
Browse files Browse the repository at this point in the history
See #88
  • Loading branch information
Antoine Aflalo committed Apr 29, 2016
1 parent da29cf2 commit 8aae301
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ public ToolTipInfoTypeEnum CurrentTooltipInfo
AppConfigs.Configuration.Save();
}
}

/// <summary>
/// Show the tooltip with the NotifyIcon
/// Show the tooltip with the NotifyIcon
/// </summary>
public void ShowTooltipInfo()
{
var tooltipInfo = _tooltipInfoFactory.Get(CurrentTooltipInfo);
var text = tooltipInfo.TextToDisplay();

if (text == null)
return;

_icon.ShowBalloonTip(1000, TooltipInfo.titleTooltip, text, ToolTipIcon.Info);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ public class TooltipInfoBoth : ITooltipInfo
/// <returns></returns>
public string TextToDisplay()
{
return string.Concat(new TooltipInfoPlayback().TextToDisplay(), "\n",
new TooltipInfoRecording().TextToDisplay());
var playbackToDisplay = new TooltipInfoPlayback().TextToDisplay();
var recordingToDisplay = new TooltipInfoRecording().TextToDisplay();

if(playbackToDisplay == null || recordingToDisplay == null)
return null;

return string.Concat(playbackToDisplay, "\n",
recordingToDisplay);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public string TextToDisplay()
{
var playbackDefaultDevice =
AppModel.Instance.ActiveAudioDeviceLister.GetPlaybackDevices()
.First(device => device.IsDefault(Role.Console));
return string.Format(TooltipInfo.currentlyActive, playbackDefaultDevice);
.FirstOrDefault(device => device.IsDefault(Role.Console));
return playbackDefaultDevice == null ? null : string.Format(TooltipInfo.currentlyActive, playbackDefaultDevice);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public string TextToDisplay()
{
var recordingDevice =
AppModel.Instance.ActiveAudioDeviceLister.GetRecordingDevices()
.First(device => device.IsDefault(Role.Console));
return string.Format(TooltipInfo.currentlyActive, recordingDevice);
.FirstOrDefault(device => device.IsDefault(Role.Console));
return recordingDevice == null ? null : string.Format(TooltipInfo.currentlyActive, recordingDevice);
}

/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions SoundSwitch/Util/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using AudioEndPointControllerWrapper;
using SoundSwitch.Framework;
using SoundSwitch.Framework.Audio;
using SoundSwitch.Framework.TooltipInfoManager;
using SoundSwitch.Framework.Updater;
using SoundSwitch.Model;
using SoundSwitch.Properties;
Expand All @@ -44,10 +45,13 @@ public sealed class TrayIcon : IDisposable
Text = Application.ProductName
};

private readonly TooltipInfoManager _tooltipInfoManager;

private readonly ToolStripMenuItem _updateMenuItem;

public TrayIcon()
{
_tooltipInfoManager = new TooltipInfoManager(NotifyIcon);
_updateMenuItem = new ToolStripMenuItem(TrayIconStrings.NoUpdate, Resources.Update, OnUpdateClick)
{
Enabled = false
Expand Down Expand Up @@ -75,6 +79,13 @@ public TrayIcon()

NotifyIcon.ContextMenuStrip = _settingsMenu;
};

NotifyIcon.MouseMove += (sender, args) =>
{
if (!NotifyIcon.Visible)
return;
_tooltipInfoManager.ShowTooltipInfo();
};
SetEventHandlers();
}

Expand Down

0 comments on commit 8aae301

Please sign in to comment.