greenshot/GreenshotConfluencePlugin/Support/LanguageChangedEventManager.cs
2016-09-22 20:40:13 +02:00

52 lines
1.6 KiB
C#

using System;
using System.Windows;
namespace TranslationByMarkupExtension
{
public class LanguageChangedEventManager : WeakEventManager
{
public static void AddListener(TranslationManager source, IWeakEventListener listener)
{
CurrentManager.ProtectedAddListener(source, listener);
}
public static void RemoveListener(TranslationManager source, IWeakEventListener listener)
{
CurrentManager.ProtectedRemoveListener(source, listener);
}
private void OnLanguageChanged(object sender, EventArgs e)
{
DeliverEvent(sender, e);
}
protected override void StartListening(object source)
{
var manager = (TranslationManager)source;
manager.LanguageChanged += OnLanguageChanged;
}
protected override void StopListening(object source)
{
var manager = (TranslationManager)source;
manager.LanguageChanged -= OnLanguageChanged;
}
private static LanguageChangedEventManager CurrentManager
{
get
{
Type managerType = typeof(LanguageChangedEventManager);
var manager = (LanguageChangedEventManager)GetCurrentManager(managerType);
if (manager == null)
{
manager = new LanguageChangedEventManager();
SetCurrentManager(managerType, manager);
}
return manager;
}
}
}
}