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

[FancyZones Editor] Quick layout switch hotkeys #10437

Merged
merged 11 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ finalizer
findstr
FIXEDFILEINFO
FLASHZONES
FLASHZONESONQUICKSWITCH
Fle
fluentui
flyout
Expand Down Expand Up @@ -1685,6 +1686,7 @@ Queryable
QUERYENDSESSION
QUERYOPEN
QUEUESYNC
QUICKLAYOUTSWITCH
qwertyuiopasdfghjklzxcvbnm
qword
qwrtyuiopsghjklzxvnm
Expand Down Expand Up @@ -2095,6 +2097,7 @@ Timeline
timeunion
timeutil
titlecase
TLayout
tlb
tlbimp
tmp
Expand Down
97 changes: 56 additions & 41 deletions src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@

</Grid>
</ScrollViewer>

<Button x:Name="NewLayoutButton"
Click="NewLayoutButton_Click"
HorizontalAlignment="Right"
Expand Down Expand Up @@ -355,6 +356,7 @@
PrimaryButtonClick="EditLayoutDialog_PrimaryButtonClick"
SecondaryButtonClick="EditLayoutDialog_SecondaryButtonClick"
Title="{x:Static props:Resources.Edit_Layout}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Opened="Dialog_Opened"
Closed="Dialog_Closed">
<Grid DataContext="{Binding SelectedModel}"
Expand Down Expand Up @@ -419,55 +421,55 @@
HorizontalAlignment="Center"
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeTemplateToVisibilityConverter}}">

<Button x:Name="decrementZones"
Width="40"
Height="40"
AutomationProperties.Name="{x:Static props:Resources.Zone_Count_Decrement}"
ToolTip="{x:Static props:Resources.Zone_Count_Decrement}"
Foreground="{DynamicResource SystemControlBackgroundAccentBrush}"
Style="{StaticResource IconOnlyButtonStyle}"
Click="DecrementZones_Click">
<Button.Content>
<TextBlock Text="&#xE108;"
FontFamily="Segoe MDL2 Assets" />
</Button.Content>
</Button>

<TextBlock x:Name="zoneCount"
Text="{Binding TemplateZoneCount}"
FontWeight="SemiBold"
FontSize="18"
Width="32"
HorizontalAlignment="Center"
TextAlignment="Center"
Margin="0,-4,0,0"
ToolTip="Number of zones"
VerticalAlignment="Center" />
<Button x:Name="decrementZones"
Width="40"
Height="40"
AutomationProperties.Name="{x:Static props:Resources.Zone_Count_Decrement}"
ToolTip="{x:Static props:Resources.Zone_Count_Decrement}"
Foreground="{DynamicResource SystemControlBackgroundAccentBrush}"
Style="{StaticResource IconOnlyButtonStyle}"
Click="DecrementZones_Click">
<Button.Content>
<TextBlock Text="&#xE108;"
FontFamily="Segoe MDL2 Assets" />
</Button.Content>
</Button>

<Button x:Name="incrementZones"
Width="40"
Height="40"
AutomationProperties.Name="{x:Static props:Resources.Zone_Count_Increment}"
ToolTip="{x:Static props:Resources.Zone_Count_Increment}"
Foreground="{DynamicResource SystemControlBackgroundAccentBrush}"
Style="{StaticResource IconOnlyButtonStyle}"
Click="IncrementZones_Click">
<Button.Content>
<TextBlock Text="&#xE109;"
FontFamily="Segoe MDL2 Assets" />
</Button.Content>
</Button>
</StackPanel>
<TextBlock x:Name="zoneCount"
Text="{Binding TemplateZoneCount}"
FontWeight="SemiBold"
FontSize="18"
Width="32"
HorizontalAlignment="Center"
TextAlignment="Center"
Margin="0,-4,0,0"
ToolTip="Number of zones"
VerticalAlignment="Center" />

<Button x:Name="incrementZones"
Width="40"
Height="40"
AutomationProperties.Name="{x:Static props:Resources.Zone_Count_Increment}"
ToolTip="{x:Static props:Resources.Zone_Count_Increment}"
Foreground="{DynamicResource SystemControlBackgroundAccentBrush}"
Style="{StaticResource IconOnlyButtonStyle}"
Click="IncrementZones_Click">
<Button.Content>
<TextBlock Text="&#xE109;"
FontFamily="Segoe MDL2 Assets" />
</Button.Content>
</Button>
</StackPanel>
<TextBox Text="{Binding Name}"
ui:ControlHelper.Header="{x:Static props:Resources.Name}"
Margin="0,16,0,0"
Margin="0,16,2,0"
Visibility="{Binding IsCustom, Converter={StaticResource BooleanToVisibilityConverter}}"
HorizontalAlignment="Stretch" />

<CheckBox x:Name="spaceAroundSetting"
Content="{x:Static props:Resources.Show_Space_Zones}"
IsChecked="{Binding ShowSpacing}"
Margin="0,16,0,0"
Margin="0,16,12,0"
Visibility="{Binding Converter={StaticResource LayoutModelTypeToVisibilityConverter}}" />

<ui:NumberBox Margin="0,6,0,0"
Expand All @@ -483,7 +485,8 @@

<TextBlock Text="{x:Static props:Resources.Distance_adjacent_zones}"
IsEnabled="{Binding ShowSpacing}"
Margin="0,16,0,0"
Margin="0,16,12,0"
TextWrapping="Wrap"
Foreground="{DynamicResource PrimaryForegroundBrush}"
x:Name="sensitivityRadiusValue" />

Expand All @@ -495,6 +498,18 @@
SpinButtonPlacementMode="Compact"
HorizontalAlignment="Left"
AutomationProperties.LabeledBy="{Binding ElementName=sensitivityRadiusValue}" />

<TextBlock Text="{x:Static props:Resources.QuickKey_Select}"
Margin="0,16,12,0"
Foreground="{DynamicResource PrimaryForegroundBrush}"
TextWrapping="Wrap"
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeCustomToVisibilityConverter}}"/>
<ComboBox x:Name="quickKeySelectionComboBox"
Margin="0,6,0,0"
ItemsSource="{Binding QuickKeysAvailable}"
SelectedItem="{Binding QuickKey}"
Width="106"
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeCustomToVisibilityConverter}}"/>
</StackPanel>
</Grid>
</ui:ContentDialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

Expand All @@ -16,6 +17,8 @@ protected LayoutModel()
{
_guid = Guid.NewGuid();
Type = LayoutType.Custom;

MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
}

protected LayoutModel(string name)
Expand Down Expand Up @@ -48,6 +51,9 @@ protected LayoutModel(LayoutModel other)
_isApplied = other._isApplied;
_sensitivityRadius = other._sensitivityRadius;
_zoneCount = other._zoneCount;
_quickKey = other._quickKey;

MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
}

// Name - the display name for this layout model - is also used as the key in the registry
Expand Down Expand Up @@ -158,6 +164,55 @@ public int SensitivityRadius

private int _sensitivityRadius = LayoutSettings.DefaultSensitivityRadius;

public List<string> QuickKeysAvailable
{
get
{
List<string> result = new List<string>();
foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
{
if (pair.Value == string.Empty || pair.Value == Uuid)
{
result.Add(pair.Key);
}
}

return result;
}
}

public string QuickKey
{
get
{
return _quickKey == -1 ? Properties.Resources.Quick_Key_None : _quickKey.ToString();
}

set
{
string none = Properties.Resources.Quick_Key_None;
var intValue = value == none ? -1 : int.Parse(value);
if (intValue != _quickKey)
{
string prev = _quickKey == -1 ? none : _quickKey.ToString();
_quickKey = intValue;

if (intValue != -1)
{
MainWindowSettingsModel.QuickKeys.SelectKey(value, Uuid);
}
else
{
MainWindowSettingsModel.QuickKeys.FreeKey(prev);
}

FirePropertyChanged(nameof(QuickKey));
}
}
}

private int _quickKey = -1;

// TemplateZoneCount - number of zones selected in the picker window for template layouts
public int TemplateZoneCount
{
Expand Down Expand Up @@ -200,6 +255,11 @@ protected virtual void FirePropertyChanged([CallerMemberName] string propertyNam
// Removes this Layout from the registry and the loaded CustomModels list
public void Delete()
{
if (_quickKey != -1)
{
MainWindowSettingsModel.QuickKeys.FreeKey(QuickKey);
}

var customModels = MainWindowSettingsModel.CustomModels;
int i = customModels.IndexOf(this);
if (i != -1)
Expand Down Expand Up @@ -241,5 +301,17 @@ public void Persist()
{
PersistData();
}

private void QuickSwitchKeys_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
{
if (pair.Value == Uuid)
{
QuickKey = pair.Key.ToString();
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FancyZonesEditor.Models
{
public enum LayoutType
{
Blank = -1,
Blank = 0,
Focus,
Columns,
Rows,
Expand Down
Loading