SEBWIN-220: Implemented mechanism to prevent (accidental) closing of taskbar by ALT+F4.
This commit is contained in:
parent
50dcb7502a
commit
cd5bbfcb47
9 changed files with 60 additions and 11 deletions
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Behaviour.OperationModel;
|
||||
|
@ -250,7 +251,7 @@ namespace SafeExamBrowser.Client.Behaviour
|
|||
shutdown.Invoke();
|
||||
}
|
||||
|
||||
private void Taskbar_QuitButtonClicked()
|
||||
private void Taskbar_QuitButtonClicked(CancelEventArgs args)
|
||||
{
|
||||
var result = messageBox.Show(TextKey.MessageBox_Quit, TextKey.MessageBox_QuitTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
|
@ -266,6 +267,10 @@ namespace SafeExamBrowser.Client.Behaviour
|
|||
messageBox.Show(TextKey.MessageBox_QuitError, TextKey.MessageBox_QuitErrorTitle, icon: MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void WindowMonitor_WindowChanged(IntPtr window)
|
||||
|
|
|
@ -8,5 +8,8 @@
|
|||
|
||||
namespace SafeExamBrowser.Contracts.Browser
|
||||
{
|
||||
/// <summary>
|
||||
/// Event handler used to control (e.g. allow or prohibit) download requests.
|
||||
/// </summary>
|
||||
public delegate void DownloadRequestedEventHandler(string fileName, DownloadEventArgs args);
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@
|
|||
<Compile Include="UserInterface\Browser\IBrowserWindow.cs" />
|
||||
<Compile Include="UserInterface\MessageBox\IMessageBox.cs" />
|
||||
<Compile Include="UserInterface\IProgressIndicator.cs" />
|
||||
<Compile Include="UserInterface\Taskbar\QuitButtonClickedEventHandler.cs" />
|
||||
<Compile Include="UserInterface\Windows\IRuntimeWindow.cs" />
|
||||
<Compile Include="UserInterface\MessageBox\MessageBoxResult.cs" />
|
||||
<Compile Include="UserInterface\Taskbar\INotificationButton.cs" />
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
namespace SafeExamBrowser.Contracts.UserInterface.Taskbar
|
||||
{
|
||||
public delegate void QuitButtonClickedEventHandler();
|
||||
|
||||
/// <summary>
|
||||
/// Defines the functionality of the application taskbar. The taskbar is the main user interface element via which the user can access
|
||||
/// the browser, third-party applications, system controls and so on.
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SafeExamBrowser.Contracts.UserInterface.Taskbar
|
||||
{
|
||||
/// <summary>
|
||||
/// Event handler used to define the control flow when the <see cref="ITaskbar"/>'s quit button is clicked.
|
||||
/// </summary>
|
||||
public delegate void QuitButtonClickedEventHandler(CancelEventArgs args);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
|
||||
|
@ -16,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Classic.Controls
|
|||
{
|
||||
public partial class QuitButton : UserControl
|
||||
{
|
||||
public QuitButtonClickedEventHandler Clicked;
|
||||
public event QuitButtonClickedEventHandler Clicked;
|
||||
|
||||
public QuitButton()
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ namespace SafeExamBrowser.UserInterface.Classic.Controls
|
|||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Clicked?.Invoke();
|
||||
Clicked?.Invoke(new CancelEventArgs());
|
||||
}
|
||||
|
||||
private void LoadIcon()
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace SafeExamBrowser.UserInterface.Classic
|
|||
{
|
||||
public partial class Taskbar : Window, ITaskbar
|
||||
{
|
||||
private bool allowClose;
|
||||
private ILogger logger;
|
||||
|
||||
public event QuitButtonClickedEventHandler QuitButtonClicked;
|
||||
|
@ -28,7 +29,7 @@ namespace SafeExamBrowser.UserInterface.Classic
|
|||
|
||||
Closing += Taskbar_Closing;
|
||||
Loaded += (o, args) => InitializeBounds();
|
||||
QuitButton.Clicked += () => QuitButtonClicked?.Invoke();
|
||||
QuitButton.Clicked += QuitButton_Clicked;
|
||||
}
|
||||
|
||||
public void AddApplication(IApplicationButton button)
|
||||
|
@ -87,8 +88,21 @@ namespace SafeExamBrowser.UserInterface.Classic
|
|||
});
|
||||
}
|
||||
|
||||
private void QuitButton_Clicked(CancelEventArgs args)
|
||||
{
|
||||
QuitButtonClicked?.Invoke(args);
|
||||
allowClose = !args.Cancel;
|
||||
}
|
||||
|
||||
private void Taskbar_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (!allowClose)
|
||||
{
|
||||
e.Cancel = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var child in SystemControlStackPanel.Children)
|
||||
{
|
||||
if (child is ISystemControl systemControl)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
|
||||
|
@ -23,7 +24,7 @@ namespace SafeExamBrowser.UserInterface.Windows10.Controls
|
|||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Clicked?.Invoke();
|
||||
Clicked?.Invoke(new CancelEventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace SafeExamBrowser.UserInterface.Windows10
|
|||
{
|
||||
public partial class Taskbar : Window, ITaskbar
|
||||
{
|
||||
private bool allowClose;
|
||||
private ILogger logger;
|
||||
|
||||
public event QuitButtonClickedEventHandler QuitButtonClicked;
|
||||
|
@ -26,9 +27,9 @@ namespace SafeExamBrowser.UserInterface.Windows10
|
|||
|
||||
InitializeComponent();
|
||||
|
||||
Loaded += (o, args) => InitializeBounds();
|
||||
Closing += Taskbar_Closing;
|
||||
QuitButtonClicked += Taskbar_QuitButtonClicked;
|
||||
Loaded += (o, args) => InitializeBounds();
|
||||
QuitButtonClicked += QuitButton_Clicked;
|
||||
}
|
||||
|
||||
public void AddApplication(IApplicationButton button)
|
||||
|
@ -87,13 +88,21 @@ namespace SafeExamBrowser.UserInterface.Windows10
|
|||
});
|
||||
}
|
||||
|
||||
private void Taskbar_QuitButtonClicked()
|
||||
private void QuitButton_Clicked(CancelEventArgs args)
|
||||
{
|
||||
QuitButtonClicked?.Invoke();
|
||||
QuitButtonClicked?.Invoke(args);
|
||||
allowClose = !args.Cancel;
|
||||
}
|
||||
|
||||
private void Taskbar_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (!allowClose)
|
||||
{
|
||||
e.Cancel = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var child in SystemControlStackPanel.Children)
|
||||
{
|
||||
if (child is ISystemControl systemControl)
|
||||
|
|
Loading…
Reference in a new issue