Implemented option to disable the busy indicator (animation).
This commit is contained in:
parent
9e29561707
commit
153aca4517
@ -45,7 +45,7 @@
|
||||
<StackPanel Style="{StaticResource WaitCursorWhileBusy}" Background="Transparent">
|
||||
<Grid>
|
||||
<Image Source="{StaticResource ImageSource_Banner}" Stretch="None" MouseLeftButtonDown="Image_MouseLeftButtonDown" Name="Banner"/>
|
||||
<Canvas x:Name="Canvas" IsHitTestVisible="False" Visibility="{Binding IsBusy, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Converter={StaticResource VisibilityConverter}}" Opacity="0.8"/>
|
||||
<Canvas x:Name="Canvas" IsHitTestVisible="False" Visibility="{Binding IsBusyIndicatorVisible, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Converter={StaticResource VisibilityConverter}}" Opacity="0.8"/>
|
||||
</Grid>
|
||||
<Separator Margin="0"/>
|
||||
<StackPanel>
|
||||
|
@ -45,8 +45,9 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
private readonly ReadOnlyObservableCollection<string> m_logFileReadOnly;
|
||||
|
||||
private volatile ModeOfOperation m_modeOfOperation = (ModeOfOperation)(-1);
|
||||
private volatile bool m_busyFlag = false, m_checksumError = false, m_processReceived = false, m_checked = false;
|
||||
private volatile bool m_busyFlag = false, m_checksumError = false, m_processReceived = false, m_disableAnimation = false;
|
||||
private volatile SlunkCryptRunner m_processRunner = null;
|
||||
private uint? m_menuId_disableAnimation = null, m_menuId_enableExpertMode = null;
|
||||
|
||||
private const string ASCII_CHARS = "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
@ -58,9 +59,9 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
{
|
||||
InitializeComponent();
|
||||
m_defaultStatusText = Label_Status.Text;
|
||||
m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.SystemIdle, Dispatcher);
|
||||
m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher);
|
||||
m_dispatcherTimer.Tick += DispatcherTimer_Tick;
|
||||
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(125);
|
||||
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
|
||||
m_logFileReadOnly = new ReadOnlyObservableCollection<string>(m_logFile);
|
||||
}
|
||||
|
||||
@ -76,8 +77,20 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
}
|
||||
set
|
||||
{
|
||||
m_dispatcherTimer.IsEnabled = m_busyFlag = value;
|
||||
if (m_busyFlag != value)
|
||||
{
|
||||
m_dispatcherTimer.IsEnabled = (m_busyFlag = value) && (!m_disableAnimation);
|
||||
NotifyPropertyChanged("IsBusy");
|
||||
NotifyPropertyChanged("IsBusyIndicatorVisible");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBusyIndicatorVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_busyFlag && (!m_disableAnimation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,7 +370,9 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await Task.Yield();
|
||||
new SystemMenu(this).AppendMenu("Enable Expert Mode", SystemMenu_Activated);
|
||||
SystemMenu systemMenu = new SystemMenu(this, SystemMenu_Activated);
|
||||
m_menuId_disableAnimation = systemMenu.AppendMenu("Disable Busy Indicator");
|
||||
m_menuId_enableExpertMode = systemMenu.AppendMenu("Expert Settings");
|
||||
CreateIndicatorElements();
|
||||
}
|
||||
|
||||
@ -377,19 +392,23 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
|
||||
private void SystemMenu_Activated(SystemMenu sender, uint menuId)
|
||||
{
|
||||
if (m_checked = (!m_checked))
|
||||
if (m_menuId_disableAnimation.HasValue && (menuId == m_menuId_disableAnimation.Value))
|
||||
{
|
||||
sender.ModifyMenu(menuId, m_disableAnimation = !m_disableAnimation);
|
||||
if (m_busyFlag)
|
||||
{
|
||||
m_dispatcherTimer.IsEnabled = !m_disableAnimation;
|
||||
NotifyPropertyChanged("IsBusyIndicatorVisible");
|
||||
}
|
||||
}
|
||||
else if (m_menuId_enableExpertMode.HasValue && (menuId == m_menuId_enableExpertMode.Value))
|
||||
{
|
||||
sender.ModifyMenu(menuId, true);
|
||||
try
|
||||
{
|
||||
Process.Start("https://youtu.be/Is_8bjYVmnA").Dispose();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.ModifyMenu(menuId, false);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
@ -11,15 +11,14 @@ using System.Windows.Interop;
|
||||
|
||||
namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
{
|
||||
using ItemInfo = Tuple<string, SystemMenu.SystemMenuActionHandler>;
|
||||
|
||||
class SystemMenu : IDisposable
|
||||
{
|
||||
private const int WM_SYSCOMMAND = 0x112;
|
||||
public delegate void SystemMenuActionHandler(SystemMenu sender, uint menuId);
|
||||
|
||||
private readonly SystemMenuActionHandler m_handler;
|
||||
private readonly HwndSource m_hwndSource;
|
||||
private readonly Dictionary<uint, ItemInfo> m_menuItems = new Dictionary<uint, ItemInfo>();
|
||||
private readonly Dictionary<uint, string> m_menuItems = new Dictionary<uint, string>();
|
||||
|
||||
private bool m_firstItem = true;
|
||||
private uint m_nextMenuId = 100;
|
||||
@ -30,12 +29,16 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
// Constructor
|
||||
// =============================================================================
|
||||
|
||||
public SystemMenu(Window window)
|
||||
public SystemMenu(Window window, SystemMenuActionHandler handler)
|
||||
{
|
||||
if (ReferenceEquals(window, null))
|
||||
{
|
||||
throw new ArgumentNullException("Window must not be null!");
|
||||
}
|
||||
if (ReferenceEquals(m_handler = handler, null))
|
||||
{
|
||||
throw new ArgumentNullException("SystemMenuActionHandler must not be null!");
|
||||
}
|
||||
window.Dispatcher.VerifyAccess();
|
||||
m_hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
|
||||
m_hwndSource.AddHook(WndProcHook);
|
||||
@ -45,16 +48,12 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
// Public methods
|
||||
// =============================================================================
|
||||
|
||||
public uint AppendMenu(string captionStr, SystemMenuActionHandler handler)
|
||||
public uint AppendMenu(string captionStr)
|
||||
{
|
||||
if (m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException("Already disposed!");
|
||||
}
|
||||
if (ReferenceEquals(handler, null))
|
||||
{
|
||||
throw new ArgumentNullException("SystemMenuActionHandler must not be null!");
|
||||
}
|
||||
m_hwndSource.Dispatcher.VerifyAccess();
|
||||
IntPtr hSysMenu = GetSystemMenu(m_hwndSource.Handle, false);
|
||||
if (hSysMenu != IntPtr.Zero)
|
||||
@ -69,7 +68,7 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
if (AppendMenu(hSysMenu, Native.MenuFlags.MF_STRING, m_nextMenuId, captionStr))
|
||||
{
|
||||
uint menuItemId = m_nextMenuId++;
|
||||
m_menuItems.Add(menuItemId, Tuple.Create(captionStr, handler));
|
||||
m_menuItems.Add(menuItemId, captionStr);
|
||||
return menuItemId;
|
||||
}
|
||||
}
|
||||
@ -83,13 +82,13 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
throw new ObjectDisposedException("Already disposed!");
|
||||
}
|
||||
m_hwndSource.Dispatcher.VerifyAccess();
|
||||
ItemInfo itemInfo;
|
||||
if (m_menuItems.TryGetValue(menuId, out itemInfo))
|
||||
string captionStr;
|
||||
if (m_menuItems.TryGetValue(menuId, out captionStr))
|
||||
{
|
||||
IntPtr hSysMenu = GetSystemMenu(m_hwndSource.Handle, false);
|
||||
if (hSysMenu != IntPtr.Zero)
|
||||
{
|
||||
return ModifyMenu(hSysMenu, menuId, Native.MenuFlags.MF_BYCOMMAND | (isChecked ? Native.MenuFlags.MF_CHECKED : Native.MenuFlags.MF_UNCHECKED), menuId, itemInfo.Item1);
|
||||
return ModifyMenu(hSysMenu, menuId, Native.MenuFlags.MF_BYCOMMAND | (isChecked ? Native.MenuFlags.MF_CHECKED : Native.MenuFlags.MF_UNCHECKED), menuId, captionStr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -107,11 +106,10 @@ namespace com.muldersoft.slunkcrypt.gui.utils
|
||||
{
|
||||
if (msg == WM_SYSCOMMAND)
|
||||
{
|
||||
uint menuId = (uint)wParam.ToInt32();
|
||||
ItemInfo itemInfo;
|
||||
if (m_menuItems.TryGetValue(menuId, out itemInfo))
|
||||
uint menuId;
|
||||
if (m_menuItems.ContainsKey(menuId = (uint) wParam.ToInt32()))
|
||||
{
|
||||
itemInfo.Item2(this, menuId);
|
||||
m_handler(this, menuId);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user