Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration file to save selected mode and version #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add configuration file to save selected mode and version
The UIA version and selected modes are saved in the App.config.
If the mode and version is set at application start, then both is set.
Also when switching the mode it is saved in the config.
Additionally, when the UIA version wants to be changed then the new menu entry is selected
Lill-Tindemann committed May 27, 2023
commit 221b2877a328b207ca048356200ae07cc3ebe03c
4 changes: 4 additions & 0 deletions src/FlaUInspect/FlaUInspect.csproj
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
@@ -176,6 +177,9 @@
<Resource Include="Resources\Calendar.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FlaUI.Core">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="FlaUI.UIA2">
<Version>3.2.0</Version>
</PackageReference>
69 changes: 64 additions & 5 deletions src/FlaUInspect/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Linq;
@@ -31,6 +32,16 @@ public MainViewModel()
var info = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location);
Process.Start(info);
});
StartNewInstanceWithVersionSelectionCommand = new RelayCommand(o =>
{
// Reset UIA version in configuration
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("version");
config.Save(ConfigurationSaveMode.Minimal);

var info = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location);
Process.Start(info);
});
CaptureSelectedItemCommand = new RelayCommand(o =>
{
if (SelectedItemInTree == null)
@@ -65,8 +76,19 @@ public bool EnableHoverMode
{
if (SetProperty(value))
{
if (value) { _hoverMode.Start(); }
else { _hoverMode.Stop(); }
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("EnableHoverMode");
if (value)
{
config.AppSettings.Settings.Add("EnableHoverMode", "true");
_hoverMode.Start();
}
else
{
config.AppSettings.Settings.Add("EnableHoverMode", "false");
_hoverMode.Stop();
}
config.Save(ConfigurationSaveMode.Minimal);
}
}
}
@@ -78,16 +100,42 @@ public bool EnableFocusTrackingMode
{
if (SetProperty(value))
{
if (value) { _focusTrackingMode.Start(); }
else { _focusTrackingMode.Stop(); }
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("EnableFocusTrackingMode");
if (value)
{
config.AppSettings.Settings.Add("EnableFocusTrackingMode", "true");
_focusTrackingMode.Start();
}
else
{
config.AppSettings.Settings.Add("EnableFocusTrackingMode", "false");
_focusTrackingMode.Stop();
}
config.Save(ConfigurationSaveMode.Minimal);
}
}
}

public bool EnableXPath
{
get { return GetProperty<bool>(); }
set { SetProperty(value); }
set
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("EnableXPath");
if (value)
{
config.AppSettings.Settings.Add("EnableXPath", "true");
}
else
{
config.AppSettings.Settings.Add("EnableXPath", "false");
}
config.Save(ConfigurationSaveMode.Minimal);

SetProperty(value);
}
}

public AutomationType SelectedAutomationType
@@ -100,6 +148,8 @@ public AutomationType SelectedAutomationType

public ICommand StartNewInstanceCommand { get; private set; }

public ICommand StartNewInstanceWithVersionSelectionCommand { get; private set; }

public ICommand CaptureSelectedItemCommand { get; private set; }

public ICommand RefreshCommand { get; private set; }
@@ -135,6 +185,15 @@ public void Initialize(AutomationType selectedAutomationType)
// Initialize focus tracking
_focusTrackingMode = new FocusTrackingMode(_automation);
_focusTrackingMode.ElementFocused += ElementToSelectChanged;

// Set modes from config file
var enableHoverMode = ConfigurationManager.AppSettings["EnableHoverMode"];
var enableFocusTrackingMode = ConfigurationManager.AppSettings["EnableFocusTrackingMode"];
var enableXPath = ConfigurationManager.AppSettings["EnableXPath"];

EnableHoverMode = enableHoverMode == "true";
EnableFocusTrackingMode = enableFocusTrackingMode == "true";
EnableXPath = enableXPath == "true";
}

private void ElementToSelectChanged(AutomationElement obj)
1 change: 1 addition & 0 deletions src/FlaUInspect/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_New Instance" Command="{Binding StartNewInstanceCommand}" />
<MenuItem Header="_New Instance with version selection" Command="{Binding StartNewInstanceWithVersionSelectionCommand}" />
<MenuItem Header="_Capture selected item" Command="{Binding CaptureSelectedItemCommand}" />
<MenuItem Header="_Refresh" Command="{Binding RefreshCommand}" InputGestureText="F5" />
<Separator />
35 changes: 30 additions & 5 deletions src/FlaUInspect/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Reflection;
using System.Configuration;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using FlaUI.Core;
using FlaUInspect.ViewModels;

namespace FlaUInspect.Views
@@ -36,12 +38,35 @@ private void MainWindow_Loaded(object sender, System.EventArgs e)
{
if (!_vm.IsInitialized)
{
var dlg = new ChooseVersionWindow { Owner = this };
if (dlg.ShowDialog() != true)
// Start application if version is saved
var version = ConfigurationManager.AppSettings["version"];
if (version == "2")
{
Close();
_vm.Initialize(AutomationType.UIA2);
}
else if (version == "3")
{
_vm.Initialize(AutomationType.UIA3);
}
else
{
var dlg = new ChooseVersionWindow { Owner = this };
if (dlg.ShowDialog() != true)
{
Close();
}
// Save selected UIA version if dialog is not closed
else if (dlg.SelectedAutomationType == AutomationType.UIA2
|| dlg.SelectedAutomationType == AutomationType.UIA3)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("version");
config.AppSettings.Settings.Add("version", dlg.SelectedAutomationType == AutomationType.UIA2 ? "2" : "3");
config.Save(ConfigurationSaveMode.Minimal);
}

_vm.Initialize(dlg.SelectedAutomationType);
}
_vm.Initialize(dlg.SelectedAutomationType);
Loaded -= MainWindow_Loaded;
}
}