From f298933cd84317f99fbf75e4f5d3ebf5d5d4f6db Mon Sep 17 00:00:00 2001 From: "Konstiantyn.Usenko" Date: Mon, 8 Sep 2025 16:18:47 +0200 Subject: [PATCH 1/6] Enhance application version handling and UI layout adjustments --- src/FlaUInspect/App.xaml.cs | 27 +-- src/FlaUInspect/Resources/RibbonIcons.xaml | 33 +++- src/FlaUInspect/ViewModels/MainViewModel.cs | 46 +++++- src/FlaUInspect/Views/MainWindow.xaml | 172 ++++++++++++++++---- 4 files changed, 219 insertions(+), 59 deletions(-) diff --git a/src/FlaUInspect/App.xaml.cs b/src/FlaUInspect/App.xaml.cs index 8dc0830..07e2cd2 100644 --- a/src/FlaUInspect/App.xaml.cs +++ b/src/FlaUInspect/App.xaml.cs @@ -8,30 +8,22 @@ namespace FlaUInspect; public partial class App { private void ApplicationStart(object sender, StartupEventArgs e) { - AssemblyInformationalVersionAttribute? versionAttribute = Assembly.GetEntryAssembly()?.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; - + var versionAttribute = Assembly.GetEntryAssembly()?.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute; + string applicationVersion = versionAttribute?.Version ?? "N/A"; InternalLogger logger = new (); #if AUTOMATION_UIA3 - MainViewModel mainViewModel = new (AutomationType.UIA3, logger); + MainViewModel mainViewModel = new (AutomationType.UIA3, applicationVersion, logger); MainWindow mainWindow = new () { DataContext = mainViewModel }; - if (versionAttribute != null) { - mainWindow.Title += " version" + versionAttribute.InformationalVersion; - } - //Re-enable normal shutdown mode. Current.ShutdownMode = ShutdownMode.OnMainWindowClose; Current.MainWindow = mainWindow; mainWindow.Show(); #elif AUTOMATION_UIA2 - MainViewModel mainViewModel = new (AutomationType.UIA2, logger); + MainViewModel mainViewModel = new (AutomationType.UIA2, applicationVersion, logger); MainWindow mainWindow = new() { DataContext = mainViewModel }; - - if (versionAttribute != null) { - mainWindow.Title += " version" + versionAttribute.InformationalVersion; - } - + //Re-enable normal shutdown mode. Current.ShutdownMode = ShutdownMode.OnMainWindowClose; Current.MainWindow = mainWindow; @@ -41,14 +33,11 @@ private void ApplicationStart(object sender, StartupEventArgs e) { ChooseVersionWindow dialog = new (); if (dialog.ShowDialog() == true) { - MainViewModel mainViewModel = new (dialog.SelectedAutomationType, logger); + + MainViewModel mainViewModel = new (dialog.SelectedAutomationType, applicationVersion, logger); MainWindow mainWindow = new() { DataContext = mainViewModel }; - if (versionAttribute != null) { - mainWindow.Title += " version" + versionAttribute.InformationalVersion; - } - - //Re-enable normal shutdown mode. + //Re-enable normal shutdown mode. Current.ShutdownMode = ShutdownMode.OnMainWindowClose; Current.MainWindow = mainWindow; mainWindow.Show(); diff --git a/src/FlaUInspect/Resources/RibbonIcons.xaml b/src/FlaUInspect/Resources/RibbonIcons.xaml index 08aaaac..b6bcc12 100644 --- a/src/FlaUInspect/Resources/RibbonIcons.xaml +++ b/src/FlaUInspect/Resources/RibbonIcons.xaml @@ -4,14 +4,14 @@ + x:Shared="False" Width="24" Height="24"> - + - + @@ -134,4 +134,31 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FlaUInspect/ViewModels/MainViewModel.cs b/src/FlaUInspect/ViewModels/MainViewModel.cs index 6eb7d58..0e35962 100644 --- a/src/FlaUInspect/ViewModels/MainViewModel.cs +++ b/src/FlaUInspect/ViewModels/MainViewModel.cs @@ -36,9 +36,12 @@ public class MainViewModel : ObservableObject { private AutomationElement? _rootElement; private RelayCommand? _startNewInstanceCommand; private ITreeWalker? _treeWalker; + private RelayCommand _infoCommand; + private RelayCommand _closeInfoCommand; - public MainViewModel(AutomationType automationType, InternalLogger logger) { + public MainViewModel(AutomationType automationType, string applicationVersion, InternalLogger logger) { _logger = logger; + ApplicationVersion = applicationVersion; _logger.LogEvent += (_, _) => { Application.Current.Dispatcher.Invoke(() => ErrorCount = _logger.Messages.Count); }; @@ -46,6 +49,7 @@ public MainViewModel(AutomationType automationType, InternalLogger logger) { SelectedAutomationType = automationType; Elements = []; BindingOperations.EnableCollectionSynchronization(Elements, _itemsLock); + } public ICommand OpenErrorListCommand => @@ -74,6 +78,11 @@ public bool EnableHoverMode { } } + public bool EnableHighLightSelectionMode { + get => GetProperty(); + set => SetProperty(value); + } + public bool EnableFocusTrackingMode { get => GetProperty(); set { @@ -150,6 +159,21 @@ public IEnumerable ElementPatterns { get => _elementPatterns ?? Enumerable.Empty(); private set => SetProperty(ref _elementPatterns, value as ObservableCollection); } + public ICommand InfoCommand => _infoCommand ??= new RelayCommand(_ => { + IsInfoVisible = !IsInfoVisible; + }); + + public bool IsInfoVisible { + get => GetProperty(); + set => SetProperty(value); + } + public string? ApplicationVersion { + get => GetProperty(); + set => SetProperty(value); + } + public ICommand CloseInfoCommand => _closeInfoCommand ??= new RelayCommand(_ => { + IsInfoVisible = false; + }); private void ReadPatternsForSelectedItem(AutomationElement? selectedItemAutomationElement) { if (SelectedItem?.AutomationElement == null || selectedItemAutomationElement == null) { @@ -160,6 +184,10 @@ private void ReadPatternsForSelectedItem(AutomationElement? selectedItemAutomati return; } + if (EnableHighLightSelectionMode) { + ElementHighlighter.HighlightElement(SelectedItem.AutomationElement, _logger); + } + try { HashSet supportedPatterns = [.. selectedItemAutomationElement.GetSupportedPatterns()]; IDictionary patternItemsForElement = _patternItemsFactory.CreatePatternItemsForElement(selectedItemAutomationElement, supportedPatterns); @@ -289,7 +317,19 @@ private void ElementToSelectChanged(AutomationElement? obj) { SelectedItem.IsSelected = true; } - private static ElementViewModel? FindElement(ElementViewModel parent, AutomationElement element) { - return parent.Children.FirstOrDefault(child => child?.AutomationElement?.Equals(element) ?? false); + private ElementViewModel? FindElement(ElementViewModel parent, AutomationElement element) { + return parent.Children.FirstOrDefault(child => { + if (child?.AutomationElement == null) { + return false; + } + + try { + return child.AutomationElement.Equals(element); + } catch (Exception e) { + _logger.LogError(e.ToString()); + } + + return false; + }); } } \ No newline at end of file diff --git a/src/FlaUInspect/Views/MainWindow.xaml b/src/FlaUInspect/Views/MainWindow.xaml index 37c3fe8..934d2d0 100644 --- a/src/FlaUInspect/Views/MainWindow.xaml +++ b/src/FlaUInspect/Views/MainWindow.xaml @@ -8,11 +8,11 @@ xmlns:viewModels="clr-namespace:FlaUInspect.ViewModels" xmlns:models="clr-namespace:FlaUInspect.Models" Title="FlaUInspect" - d:DesignHeight="350" - d:DesignWidth="500" + d:DesignHeight="600" + d:DesignWidth="800" ResizeMode="CanResizeWithGrip" mc:Ignorable="d" - d:LayoutOverrides="Width, Height"> + d:LayoutOverrides="Width, Height" d:DataContext="{d:DesignInstance viewModels:MainViewModel}"> @@ -54,18 +54,62 @@ - - + + + + - + + + - - + - - + + + + + + + + - + - + + - + - + + + + + @@ -159,7 +225,7 @@ - + @@ -275,7 +341,7 @@ AncestorType=ContentPresenter}" /> - + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + @@ -225,7 +226,7 @@ - + @@ -333,7 +334,8 @@ ItemsSource="{Binding Children}"> - + - + -