Skip to content

Commit

Permalink
add better handling of seirrajson serialization and construction
Browse files Browse the repository at this point in the history
  • Loading branch information
joekolodz committed Mar 29, 2024
1 parent 0dfacfe commit eb3b19e
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 518 deletions.
113 changes: 44 additions & 69 deletions src/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -448,88 +448,61 @@
</ControlTemplate>

<Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type models:ActionCatalogItem}">
<StackPanel Orientation="Horizontal">
<TextBlock
Text="{Binding ActionName}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Focusable="True"
Background="Transparent"
Foreground="{StaticResource TextBrush}"
Width="300"
/>
<Button Command="{Binding RemoveActionCatalogItemCommand}"
CommandParameter="{Binding}"
Visibility="{Binding IsRemovable, Converter={StaticResource BooleanToVisibilityConverter}}"
ToolTip="Remove Action"
ToolTipService.InitialShowDelay="800"
HorizontalContentAlignment="Right"
HorizontalAlignment="Right"
Background="Transparent"
BorderBrush="Transparent">
<Image Source="../Images/remove_red_26x26.png" Height="12" Width="12"/>
</Button>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>

<Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<CheckBox></CheckBox>
<ToggleButton
Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
ClickMode="Press">
Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
ClickMode="Press">
</ToggleButton>
<ContentPresenter
Name="ContentSite"
Content="{TemplateBinding ComboBox.SelectionBoxItem}"
ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False"
Margin="3,3,23,3"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
Name="ContentSite"
Content="{TemplateBinding ComboBox.SelectionBoxItem}"
ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False"
Margin="3,3,23,3"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBox x:Name="PART_EditableTextBox"
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
SelectionBrush="{StaticResource SelectedBorderBrush}"
CaretBrush="{StaticResource TextBrush}"
Margin="3,3,23,3"
Focusable="True"
Background="Transparent"
Foreground="{TemplateBinding Foreground}"
FontSize="14"
Visibility="Hidden"
IsReadOnly="{TemplateBinding IsReadOnly}"/>
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
SelectionBrush="{StaticResource SelectedBorderBrush}"
CaretBrush="{StaticResource TextBrush}"
Margin="3,3,23,3"
Focusable="True"
Background="Transparent"
Foreground="{TemplateBinding Foreground}"
FontSize="14"
Visibility="Hidden"
IsReadOnly="{TemplateBinding IsReadOnly}"/>
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid
Name="DropDown"
Background="Azure"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
Name="DropDown"
Background="Azure"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border
x:Name="DropDownBorder"
Background="{StaticResource SelectedBrush}"
BorderThickness="1"/>
x:Name="DropDownBorder"
Background="{StaticResource SelectedBrush}"
BorderThickness="1"/>
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
Expand Down Expand Up @@ -561,6 +534,8 @@
</Setter>
</Style>



<Style TargetType="TabItem" x:Key="CustomTabItem">
<Setter Property="Template">
<Setter.Value>
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/KeypressActions.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</Image.Style>
</Image>
</Grid>
<TextBox Text="{Binding TimeInMilliseconds}" Width="66" HorizontalAlignment="Stretch" TextAlignment="Center" BorderBrush="{StaticResource HoverBorderBrush}"/>
<TextBox Text="{Binding TimeInMilliseconds}" ToolTip="Time in milliseconds that should pass before this keystroke action should take place" Width="66" HorizontalAlignment="Stretch" TextAlignment="Center" BorderBrush="{StaticResource HoverBorderBrush}"/>
</StackPanel>
</Grid>

Expand Down
32 changes: 29 additions & 3 deletions src/Controls/MacroTransport.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,46 @@
SelectionChanged="ActionList_OnSelectionChanged"
Text="{Binding ActionName, UpdateSourceTrigger=LostFocus}"
ItemsSource="{Binding DataContext.ActionCatalog.Catalog, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DockPanel}}}"
DisplayMemberPath="ActionName"
IsEditable="True"
IsTextSearchEnabled="False"
FontSize="14"
Height="28"
Width="300"
Margin="0,2,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock
Text="{Binding ActionName}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Focusable="True"
Background="Transparent"
Foreground="{StaticResource TextBrush}"
Width="300"
/>
<Button Command="{Binding RemoveActionCatalogItemCommand}"
CommandParameter="{Binding}"
Visibility="{Binding IsRemovable, Converter={StaticResource BooleanToVisibilityConverter}}"
ToolTip="Remove Action"
ToolTipService.InitialShowDelay="800"
HorizontalContentAlignment="Right"
HorizontalAlignment="Right"
Background="Transparent"
BorderBrush="Transparent">
<Image Source="../Images/remove_red_26x26.png" Height="12" Width="12"/>
</Button>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,0">
<CheckBox Margin="0,2,0,0" IsChecked="{Binding IsOneShot}" ToolTip="Play all keystrokes in order. Do not wait for button release" ToolTipService.InitialShowDelay="800">One Shot</CheckBox>
<Label Content="Repeats" Foreground="{StaticResource TextBrush}" Margin="81,0,0,0"/>
<TextBox Text="{Binding RepeatCount}" ToolTip="Number of times to repeat this button press. -1 for infinite" ToolTipService.InitialShowDelay="800" Foreground="{StaticResource TextBrush}" CaretBrush="{StaticResource TextBrush}" Margin="0,0,2,0" Width="100" Height="20" FontSize="12" Background="{StaticResource WindowBackgroundBrush}" BorderBrush="{StaticResource NormalBorderBrush}"/>
<TextBox Text="{Binding RepeatCount}" ToolTip="Number of times to repeat this button press. -1 for infinite" ToolTipService.InitialShowDelay="800" Foreground="{StaticResource TextBrush}" CaretBrush="{StaticResource TextBrush}" Margin="0,0,2,0" Width="101" Height="20" FontSize="12" Background="{StaticResource WindowBackgroundBrush}" BorderBrush="{StaticResource NormalBorderBrush}"/>
</StackPanel>
</StackPanel>
</UserControl>
7 changes: 5 additions & 2 deletions src/Models/ActionCatalogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@

namespace SierraHOTAS.Models
{
[SierraJsonObject(SierraJsonObject.MemberSerialization.OptIn)]
public class ActionCatalogItem : INotifyPropertyChanged, IComparable<ActionCatalogItem>
{
public event EventHandler<ActionCatalogItemRemovedRequestedEventArgs> RemoveRequested;

private string _actionName;
public const string NO_ACTION_TEXT = "<No Action>";

[SierraJsonProperty]
public Guid Id { get; set; }

[SierraJsonIgnore]
public bool NoAction { get; set; } = false;

[SierraJsonIgnore] public bool IsRemovable => !NoAction;
public bool IsRemovable => !NoAction;

[DefaultValue("")]
[SierraJsonProperty]
public string ActionName
{
get => _actionName;
Expand All @@ -35,6 +37,7 @@ public string ActionName
}
}

[SierraJsonProperty]
public ObservableCollection<ButtonAction> Actions { get; set; }

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
6 changes: 5 additions & 1 deletion src/Models/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void SaveQuickProfilesList(Dictionary<int, QuickProfileItem> list, string
{
fileName = BuildCurrentPath(fileName);
Logging.Log.Debug($"Saving Quick List as :{fileName}");

try
{
_fileIo.WriteAllText(fileName, Serializer.ToJSON(list, new CustomSierraJsonConverter()));
Expand Down Expand Up @@ -145,6 +145,10 @@ public IHOTASCollection FileOpen(string path)
if (version == HOTASCollection.FileFormatVersion)
{
collection = Serializer.ToObject<HOTASCollection>(json, new CustomSierraJsonConverter());
if (collection.ActionCatalog == null)
{
collection.SetCatalog(new ActionCatalog());
}
collection.ActionCatalog.PostDeserializeProcess();
}
//else - based on version, use factory to get old version and convert/map to latest version, then re-save
Expand Down
Loading

0 comments on commit eb3b19e

Please sign in to comment.