2017-08-22 10:29:00 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
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;
|
2023-03-24 18:18:02 +01:00
|
|
|
|
using System.Windows.Automation;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using System.Windows.Controls;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.Resources.Icons;
|
2019-05-08 09:56:34 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Shared.Utilities;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2020-03-16 18:29:06 +01:00
|
|
|
|
namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2020-03-16 18:29:06 +01:00
|
|
|
|
internal partial class ApplicationButton : UserControl
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
private readonly IApplication<IApplicationWindow> application;
|
2023-03-24 18:18:02 +01:00
|
|
|
|
private readonly IApplicationWindow window;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
internal event EventHandler Clicked;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2024-02-13 11:04:36 +01:00
|
|
|
|
internal ApplicationButton(IApplication<IApplicationWindow> application, IApplicationWindow window = null)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-12-02 15:48:06 +01:00
|
|
|
|
this.application = application;
|
2019-11-28 17:22:04 +01:00
|
|
|
|
this.window = window;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeApplicationInstanceButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeApplicationInstanceButton()
|
|
|
|
|
{
|
2022-11-08 11:02:56 +01:00
|
|
|
|
var tooltip = window?.Title ?? application.Tooltip;
|
2023-03-24 18:18:02 +01:00
|
|
|
|
|
|
|
|
|
Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty);
|
2022-11-08 11:02:56 +01:00
|
|
|
|
Button.ToolTip = tooltip;
|
2023-03-24 18:18:02 +01:00
|
|
|
|
Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon);
|
|
|
|
|
Text.Text = window?.Title ?? application.Name;
|
|
|
|
|
|
|
|
|
|
if (tooltip != default)
|
|
|
|
|
{
|
|
|
|
|
AutomationProperties.SetName(Button, string.Empty);
|
|
|
|
|
}
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2023-03-24 18:18:02 +01:00
|
|
|
|
if (window != default)
|
2019-03-08 11:43:52 +01:00
|
|
|
|
{
|
2019-11-28 17:22:04 +01:00
|
|
|
|
window.IconChanged += Window_IconChanged;
|
|
|
|
|
window.TitleChanged += Window_TitleChanged;
|
2019-03-08 11:43:52 +01:00
|
|
|
|
}
|
2019-01-17 16:15:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 17:22:04 +01:00
|
|
|
|
private void Window_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
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 17:22:04 +01:00
|
|
|
|
private void Window_TitleChanged(string title)
|
2019-01-17 16:15:10 +01:00
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Dispatcher.InvokeAsync(() =>
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-11-28 17:22:04 +01:00
|
|
|
|
Text.Text = title;
|
|
|
|
|
Button.ToolTip = title;
|
2019-01-17 16:15:10 +01:00
|
|
|
|
});
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|