2017-08-22 10:29:00 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
using System;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using System.Windows.Controls;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts;
|
2019-05-08 09:56:34 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Shared.Utilities;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-01-11 15:32:47 +01:00
|
|
|
|
namespace SafeExamBrowser.UserInterface.Desktop.Controls
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-03-08 11:43:52 +01:00
|
|
|
|
public partial class ActionCenterApplicationButton : UserControl
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-11-06 08:45:37 +01:00
|
|
|
|
private ApplicationInfo info;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
private IApplicationInstance instance;
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
internal event EventHandler Clicked;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-11-06 08:45:37 +01:00
|
|
|
|
public ActionCenterApplicationButton(ApplicationInfo info, IApplicationInstance instance = null)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
this.info = info;
|
|
|
|
|
this.instance = instance;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeApplicationInstanceButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeApplicationInstanceButton()
|
|
|
|
|
{
|
|
|
|
|
Icon.Content = IconResourceLoader.Load(info.IconResource);
|
2019-03-08 11:43:52 +01:00
|
|
|
|
Text.Text = instance?.Name ?? info.Name;
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty);
|
2019-03-08 11:43:52 +01:00
|
|
|
|
Button.ToolTip = instance?.Name ?? info.Tooltip;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-03-08 11:43:52 +01:00
|
|
|
|
if (instance != null)
|
|
|
|
|
{
|
|
|
|
|
instance.IconChanged += Instance_IconChanged;
|
|
|
|
|
instance.NameChanged += Instance_NameChanged;
|
|
|
|
|
}
|
2019-01-17 16:15:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 08:45:37 +01:00
|
|
|
|
private void Instance_IconChanged(IconResource icon)
|
2019-01-17 16:15:10 +01:00
|
|
|
|
{
|
2019-01-23 14:18:44 +01:00
|
|
|
|
Dispatcher.InvokeAsync(() => Icon.Content = IconResourceLoader.Load(icon));
|
2019-01-17 16:15:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Instance_NameChanged(string name)
|
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Dispatcher.InvokeAsync(() =>
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-01-17 16:15:10 +01:00
|
|
|
|
Text.Text = name;
|
|
|
|
|
Button.ToolTip = name;
|
|
|
|
|
});
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|