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-01-17 11:12:17 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2017-08-22 15:47:42 +02:00
|
|
|
|
using System.Windows.Media;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
using System.Windows.Threading;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
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 TaskbarApplicationControl : UserControl, IApplicationControl
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
private IApplication application;
|
|
|
|
|
private IApplicationInstance single;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
public TaskbarApplicationControl(IApplication application)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
this.application = application;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
2019-03-08 11:43:52 +01:00
|
|
|
|
InitializeApplicationControl();
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 11:43:52 +01:00
|
|
|
|
private void InitializeApplicationControl()
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2017-08-22 15:47:42 +02:00
|
|
|
|
var originalBrush = Button.Background;
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
application.InstanceStarted += Application_InstanceStarted;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Button.Click += Button_Click;
|
2019-11-15 16:00:03 +01:00
|
|
|
|
Button.Content = IconResourceLoader.Load(application.Info.Icon);
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Button.MouseEnter += (o, args) => InstancePopup.IsOpen = InstanceStackPanel.Children.Count > 1;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => InstancePopup.IsOpen = InstancePopup.IsMouseOver));
|
2019-08-30 12:30:00 +02:00
|
|
|
|
Button.ToolTip = application.Info.Tooltip;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
InstancePopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => InstancePopup.IsOpen = IsMouseOver));
|
2017-08-22 15:47:42 +02:00
|
|
|
|
|
|
|
|
|
InstancePopup.Opened += (o, args) =>
|
|
|
|
|
{
|
2019-01-17 11:12:17 +01:00
|
|
|
|
Background = Brushes.LightGray;
|
|
|
|
|
Button.Background = Brushes.LightGray;
|
2017-08-22 15:47:42 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InstancePopup.Closed += (o, args) =>
|
|
|
|
|
{
|
|
|
|
|
Background = originalBrush;
|
|
|
|
|
Button.Background = originalBrush;
|
|
|
|
|
};
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
private void Application_InstanceStarted(IApplicationInstance instance)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
var button = new TaskbarApplicationInstanceButton(instance, application.Info);
|
|
|
|
|
|
|
|
|
|
instance.Terminated += (_) => RemoveInstance(button);
|
|
|
|
|
InstanceStackPanel.Children.Add(button);
|
|
|
|
|
|
|
|
|
|
if (single == default(IApplicationInstance))
|
|
|
|
|
{
|
|
|
|
|
single = instance;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
if (InstanceStackPanel.Children.Count == 0)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
application.Start();
|
|
|
|
|
}
|
|
|
|
|
else if (InstanceStackPanel.Children.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
single.Activate();
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InstancePopup.IsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
private void RemoveInstance(TaskbarApplicationInstanceButton button)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2019-01-23 14:18:44 +01:00
|
|
|
|
Dispatcher.InvokeAsync(() =>
|
2019-01-17 11:12:17 +01:00
|
|
|
|
{
|
2019-08-30 12:30:00 +02:00
|
|
|
|
InstanceStackPanel.Children.Remove(button);
|
|
|
|
|
|
|
|
|
|
if (InstanceStackPanel.Children.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
single = default(IApplicationInstance);
|
|
|
|
|
}
|
2019-01-23 14:18:44 +01:00
|
|
|
|
});
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|