Skip to content

Commit

Permalink
Fix always showing Tooltip
Browse files Browse the repository at this point in the history
See #88
  • Loading branch information
Antoine Aflalo committed Apr 29, 2016
1 parent 8aae301 commit 426e2d4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions SoundSwitch/Framework/TooltipInfoManager/TooltipInfoManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Forms;
using System;
using System.Windows.Forms;
using SoundSwitch.Framework.Configuration;
using SoundSwitch.Framework.TooltipInfoManager.TootipInfo;
using SoundSwitch.Properties;
Expand All @@ -9,11 +10,14 @@ public class TooltipInfoManager
{
private readonly NotifyIcon _icon;
private readonly TooltipInfoFactory _tooltipInfoFactory;
private bool _isBallontipVisible;

public TooltipInfoManager(NotifyIcon icon)
{
_icon = icon;
_tooltipInfoFactory = new TooltipInfoFactory();
_icon.BalloonTipShown += IconOnBalloonTipShown;
_icon.BalloonTipClosed += IconOnBalloonTipClosed;
}

public ToolTipInfoTypeEnum CurrentTooltipInfo
Expand All @@ -26,18 +30,38 @@ public ToolTipInfoTypeEnum CurrentTooltipInfo
}
}

private void IconOnBalloonTipClosed(object sender, EventArgs eventArgs)
{
_isBallontipVisible = false;
}

private void IconOnBalloonTipShown(object sender, EventArgs eventArgs)
{
_isBallontipVisible = true;
}


/// <summary>
/// Show the tooltip with the NotifyIcon
/// </summary>
public void ShowTooltipInfo()
{
if (_isBallontipVisible)
return;

var tooltipInfo = _tooltipInfoFactory.Get(CurrentTooltipInfo);
var text = tooltipInfo.TextToDisplay();

if (text == null)
return;

_icon.ShowBalloonTip(1000, TooltipInfo.titleTooltip, text, ToolTipIcon.Info);
_icon.ShowBalloonTip(1000, $"{Application.ProductName}: {TooltipInfo.titleTooltip}", text, ToolTipIcon.Info);
}

~TooltipInfoManager()
{
_icon.BalloonTipClosed -= IconOnBalloonTipClosed;
_icon.BalloonTipShown -= IconOnBalloonTipShown;
}
}
}

0 comments on commit 426e2d4

Please sign in to comment.