Skip to content

Commit

Permalink
[FZ Editor] Layout hotkeys for quick swap UI (#10200)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova authored Mar 15, 2021
1 parent de23098 commit aaa5bd1
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 155 deletions.
86 changes: 48 additions & 38 deletions src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,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 @@ -420,45 +421,45 @@
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"
Expand Down Expand Up @@ -496,6 +497,15 @@
SpinButtonPlacementMode="Compact"
HorizontalAlignment="Left"
AutomationProperties.LabeledBy="{Binding ElementName=sensitivityRadiusValue}" />

<TextBlock Text="{x:Static props:Resources.QuickKey_Select}"
Margin="0,16,0,0"
Foreground="{DynamicResource PrimaryForegroundBrush}" />
<ComboBox x:Name="quickKeySelectionComboBox"
Margin="0,6,0,0"
ItemsSource="{Binding QuickKeysAvailable}"
SelectedItem="{Binding QuickKey}"
Width="106" />
</StackPanel>
</Grid>
</ui:ContentDialog>
Expand Down

This file was deleted.

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 += FastAccessKeys_PropertyChanged;
}

protected LayoutModel(string name)
Expand All @@ -27,7 +30,7 @@ protected LayoutModel(string name)
protected LayoutModel(string uuid, string name, LayoutType type)
: this()
{
_guid = Guid.Parse(uuid);
Uuid = uuid;
Name = name;
Type = type;
}
Expand All @@ -48,6 +51,9 @@ protected LayoutModel(LayoutModel other)
_isApplied = other._isApplied;
_sensitivityRadius = other._sensitivityRadius;
_zoneCount = other._zoneCount;
_quickKey = other._quickKey;

MainWindowSettingsModel.QuickKeys.PropertyChanged += FastAccessKeys_PropertyChanged;
}

// Name - the display name for this layout model - is also used as the key in the registry
Expand Down Expand Up @@ -88,6 +94,17 @@ public string Uuid
{
return "{" + Guid.ToString().ToUpperInvariant() + "}";
}

set
{
try
{
_guid = Guid.Parse(value);
}
catch (Exception)
{
}
}
}

public bool IsCustom
Expand Down Expand Up @@ -158,6 +175,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 +266,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 +312,17 @@ public void Persist()
{
PersistData();
}

private void FastAccessKeys_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

0 comments on commit aaa5bd1

Please sign in to comment.