Skip to content

Commit

Permalink
Merge pr9088 (microsoft#6)
Browse files Browse the repository at this point in the history
* [FZ Editor] Custom button with automation event on click (microsoft#12338)

* Custom button with automation event on click

* Rename MyButton to ClickAutomationEventButton

* Rename property to OnClickAutomationValue

* Remove unneeded line

* [FZE] Send close signal to Editor when the main app closes (microsoft#12510)

* [Settings/ImageResizer] New UI for sizes listview (microsoft#12269)

* Flyout for ImageResizer sizes

* Narrator support

* Improved spaces

* Fixed icons and added a confirmation dialog

* Add updatesourcetrigger

* Spellcheck fix

* Fixed missing strings

* Added messagedialog

* Fixes

* Focus fix

* Accesibility fix

Co-authored-by: Niels Laute <niels9001@hotmail.com>

* [Setup] Better prevent FileInUse errors during install (microsoft#12512)

* [ColorPicker] Close only flyout with escape key (microsoft#12441)

When the escape key is pressed in the Color Picker editor, only the
adjust color flyout should be closed instead of the whole window.

* [Bug Report Tool] Get Settings event viewer data (microsoft#12521)

Adds the event viewer events of PowerToys.Settings.exe to bug reports.

Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
Co-authored-by: Andrey Nekrasov <yuyoyuppe@users.noreply.github.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Niels Laute <niels9001@hotmail.com>
  • Loading branch information
5 people authored Jul 27, 2021
1 parent 6164433 commit b965624
Show file tree
Hide file tree
Showing 25 changed files with 1,826 additions and 1,508 deletions.
3 changes: 3 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ Functiondiscoverykeys
fwlink
fwrite
fxcop
FZE
gabime
GAC
gacutil
Expand Down Expand Up @@ -1300,6 +1301,7 @@ MSDN
msedge
mshtmdid
msi
MSIFASTINSTALL
MSIHANDLE
MSIINSTALLER
MSIL
Expand Down Expand Up @@ -2095,6 +2097,7 @@ todo
toggleswitch
toolbar
Toolchain
toolkitconverters
toolset
toolstrip
tooltip
Expand Down
3 changes: 2 additions & 1 deletion installer/PowerToysSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
/>

<!-- Close 'PowerToys.exe' before uninstall-->
<Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" />
<Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
<Property Id="MSIFASTINSTALL" Value="DisableShutdown" />
<util:CloseApplication CloseMessage="yes" Target="PowerToys.exe" ElevatedCloseMessage="yes" RebootPrompt="no" TerminateProcess="0" />
</Product>

Expand Down
6 changes: 5 additions & 1 deletion installer/PowerToysSetupCustomActions/CustomAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,14 @@ UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
}
processes.resize(bytes / sizeof(processes[0]));

std::array<std::wstring_view, 4> processesToTerminate = {
std::array<std::wstring_view, 8> processesToTerminate = {
L"PowerLauncher.exe",
L"PowerToys.Settings.exe",
L"PowerToys.Awake.exe",
L"PowerToys.FancyZones.exe",
L"Microsoft.PowerToys.Settings.UI.exe",
L"FancyZonesEditor.exe",
L"ColorPickerUI.exe",
L"PowerToys.exe"
};

Expand Down
4 changes: 4 additions & 0 deletions src/common/interop/interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public
return gcnew String(CommonSharedConstants::RUN_EXIT_EVENT);
}

static String ^ FZEExitEvent() {
return gcnew String(CommonSharedConstants::FZE_EXIT_EVENT);
}

static String ^ ColorPickerSendSettingsTelemetryEvent() {
return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/interop/shared_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace CommonSharedConstants
const wchar_t RUN_SEND_SETTINGS_TELEMETRY_EVENT[] = L"Local\\PowerToysRunInvokeEvent-638ec522-0018-4b96-837d-6bd88e06f0d6";

const wchar_t RUN_EXIT_EVENT[] = L"Local\\PowerToysRunExitEvent-3e38e49d-a762-4ef1-88f2-fd4bc7481516";

const wchar_t FZE_EXIT_EVENT[] = L"Local\\PowerToys-FZE-ExitEvent-ca8c73de-a52c-4274-b691-46e9592d3b43";

const wchar_t COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT[] = L"Local\\ColorPickerSettingsTelemetryEvent-6c7071d8-4014-46ec-b687-913bd8a422f1";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<ui:FlyoutService.Flyout>
<ui:Flyout x:Name="DetailsFlyout"
Placement="Bottom"
Opened="DetailsFlyout_Opened"
Closed="DetailsFlyout_Closed">
<Grid Margin="0,4,0,12"
KeyboardNavigation.TabNavigation="Contained"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ private void DetailsFlyout_Closed(object sender, object e)
#pragma warning restore CA1801 // Review unused parameters
{
HideDetails();
AppStateHandler.BlockEscapeKeyClosingColorPickerEditor = false;

// Revert to original color
var originalColorBackground = new SolidColorBrush(_originalColor);
Expand All @@ -250,6 +251,15 @@ private void DetailsFlyout_Closed(object sender, object e)
HexCode.Text = ColorToHex(_originalColor);
}

#pragma warning disable CA1822 // Mark members as static
#pragma warning disable CA1801 // Review unused parameters
private void DetailsFlyout_Opened(object sender, object e)
#pragma warning restore CA1801 // Review unused parameters
#pragma warning restore CA1822 // Mark members as static
{
AppStateHandler.BlockEscapeKeyClosingColorPickerEditor = true;
}

private void ColorVariationButton_Click(object sender, RoutedEventArgs e)
{
var selectedColor = ((SolidColorBrush)((Button)sender).Background).Color;
Expand Down
11 changes: 10 additions & 1 deletion src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class AppStateHandler
private bool _colorPickerShown;
private object _colorPickerVisibilityLock = new object();

// Blocks using the escape key to close the color picker editor when the adjust color flyout is open.
public static bool BlockEscapeKeyClosingColorPickerEditor { get; set; }

[ImportingConstructor]
public AppStateHandler(IColorEditorViewModel colorEditorViewModel, IUserSettings userSettings)
{
Expand All @@ -36,6 +39,7 @@ public AppStateHandler(IColorEditorViewModel colorEditorViewModel, IUserSettings

public void StartUserSession()
{
EndUserSession(); // Ends current user session if there's an active one.
lock (_colorPickerVisibilityLock)
{
if (!_colorPickerShown && !IsColorPickerEditorVisible())
Expand Down Expand Up @@ -149,7 +153,7 @@ private void HideColorPickerEditor()
}
}

private bool IsColorPickerEditorVisible()
public bool IsColorPickerEditorVisible()
{
if (_colorEditorWindow != null)
{
Expand All @@ -160,6 +164,11 @@ private bool IsColorPickerEditorVisible()
return false;
}

public bool IsColorPickerVisible()
{
return _colorPickerShown;
}

private void MainWindow_Closed(object sender, EventArgs e)
{
AppClosed?.Invoke(this, EventArgs.Empty);
Expand Down
13 changes: 10 additions & 3 deletions src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e)
var virtualCode = e.KeyboardData.VirtualCode;

// ESC pressed
if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape))
if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape)
&& e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown
)
{
e.Handled = _appStateHandler.EndUserSession();
return;
if (_appStateHandler.IsColorPickerVisible()
|| !AppStateHandler.BlockEscapeKeyClosingColorPickerEditor
)
{
e.Handled = _appStateHandler.EndUserSession();
return;
}
}

if ((System.Windows.Application.Current as ColorPickerUI.App).IsRunningDetachedFromPowerToys())
Expand Down
30 changes: 25 additions & 5 deletions src/modules/fancyzones/FancyZonesModuleInterface/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,31 @@ class FancyZonesModuleInterface : public PowertoyModuleIface
m_hProcess = sei.hProcess;
}
}


void SendFZECloseEvent()
{
auto exitEvent = CreateEventW(nullptr, false, false, CommonSharedConstants::FZE_EXIT_EVENT);
if (!exitEvent)
{
Logger::warn(L"Failed to create exitEvent. {}", get_last_error_or_default(GetLastError()));
}
else
{
Logger::trace(L"Signaled exitEvent");
if (!SetEvent(exitEvent))
{
Logger::warn(L"Failed to signal exitEvent. {}", get_last_error_or_default(GetLastError()));
}

ResetEvent(exitEvent);
CloseHandle(exitEvent);
}
}

void Disable(bool const traceEvent)
{
m_enabled = false;
// Log telemetry

if (traceEvent)
{
Trace::FancyZones::EnableFancyZones(false);
Expand All @@ -178,14 +197,15 @@ class FancyZonesModuleInterface : public PowertoyModuleIface
{
ResetEvent(m_toggleEditorEvent);
}

if (m_hProcess)
{
TerminateProcess(m_hProcess, 0);
SendFZECloseEvent();
m_hProcess = nullptr;
}
}
}

std::wstring app_name;
//contains the non localized key of the powertoy
std::wstring app_key;
Expand Down
9 changes: 9 additions & 0 deletions src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public App()
FancyZonesEditorIO = new FancyZonesEditorIO();
Overlay = new Overlay();
MainWindowSettings = new MainWindowSettingsModel();

new Thread(() =>
{
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, interop.Constants.FZEExitEvent());
if (eventHandle.WaitOne())
{
Environment.Exit(0);
}
}).Start();
}

private void OnStartup(object sender, StartupEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FancyZonesEditor"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="Body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
<StackPanel Margin="16"
FocusManager.FocusedElement="{Binding ElementName=newZoneButton}">

<Button x:Name="newZoneButton"
AutomationProperties.LabeledBy="{Binding ElementName=newZoneName}"
<local:ClickAutomationEventButton x:Name="newZoneButton"
HorizontalAlignment="Stretch"
Height="64"
Width="64"
Expand All @@ -49,7 +48,8 @@
ToolTip="{x:Static props:Resources.Add_zone}"
DataContext="{Binding Path=Model, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
IsEnabled="{Binding IsZoneAddingAllowed}"
Click="OnAddZone" />
Click="OnAddZone"
OnClickAutomationValue="{x:Static props:Resources.New_zone_added}" />

<Grid Margin="0,24,0,0">
<Grid.ColumnDefinitions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Button x:Class="FancyZonesEditor.ClickAutomationEventButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FancyZonesEditor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
</Button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;

namespace FancyZonesEditor
{
public partial class ClickAutomationEventButton : Button
{
public ClickAutomationEventButton()
: base()
{
InitializeComponent();
Click += OnClick;
}

public string OnClickAutomationValue
{
get { return (string)GetValue(OnClickAutomationValueProperty); }
set { SetValue(OnClickAutomationValueProperty, value); }
}

public static readonly DependencyProperty OnClickAutomationValueProperty =
DependencyProperty.Register(
"Value", typeof(string), typeof(ClickAutomationEventButton));

private void OnClick(object sender, RoutedEventArgs e)
{
if (AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged))
{
ClickAutomationEventButtonAutomationPeer peer =
UIElementAutomationPeer.FromElement(this) as ClickAutomationEventButtonAutomationPeer;

if (peer != null)
{
peer.RaisePropertyChangedEvent(
ValuePatternIdentifiers.ValueProperty,
null,
OnClickAutomationValue);
}
}
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new ClickAutomationEventButtonAutomationPeer(this);
}

public class ClickAutomationEventButtonAutomationPeer : FrameworkElementAutomationPeer, IValueProvider
{
public ClickAutomationEventButtonAutomationPeer(ClickAutomationEventButton control)
: base(control)
{
}

protected override string GetClassNameCore()
{
return nameof(ClickAutomationEventButton);
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Button;
}

public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Value)
{
return this;
}

return base.GetPattern(patternInterface);
}

public void SetValue(string value)
{
MyOwner.OnClickAutomationValue = value;
}

private ClickAutomationEventButton MyOwner
{
get
{
return (ClickAutomationEventButton)Owner;
}
}

public string Value
{
get { return MyOwner.OnClickAutomationValue; }
}

public bool IsReadOnly
{
get { return !IsEnabled(); }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Resource Include="images\FancyZonesEditor.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\interop\PowerToysInterop.vcxproj" />
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\..\common\Microsoft.PowerToys.Common.UI\Microsoft.PowerToys.Common.UI.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit b965624

Please sign in to comment.