Skip to content

Commit

Permalink
Fix and Improve gif stuff
Browse files Browse the repository at this point in the history
Improve my Key Handler
Improve handling of Configuration
Still todo improve menu still not working as wished
  • Loading branch information
LoneWandererProductions committed Nov 20, 2024
1 parent bbd848f commit d52ad48
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CommonControls/ComCtlResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace CommonControls
/// </summary>
internal static class ComCtlResources
{
/// <summary>
/// The global key skip text controls (const). Value: "GlobalKeySkipTextControls"
/// </summary>
internal const string GlobalKeySkipTextControls = "GlobalKeySkipTextControls";

/// <summary>
/// The grid exception validate (const). Value: "Grid dimensions and cell sizes must be non-negative and greater than
/// zero.".
Expand Down
43 changes: 39 additions & 4 deletions CommonControls/GlobalKeyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,52 @@ namespace CommonControls
/// </summary>
public static class GlobalKeyHandler
{
// DependencyProperty to enable or disable global key handling on a specific UIElement.
/// <summary>
/// DependencyProperty to enable or disable global key handling on a specific UIElement.
/// </summary>
public static readonly DependencyProperty AttachProperty =
DependencyProperty.RegisterAttached(
ComCtlResources.GlobalKeyAttach, typeof(bool), typeof(GlobalKeyHandler),
new PropertyMetadata(false, OnAttachChanged));

// DependencyProperty to store a dictionary of key-command pairs for a UIElement.

/// <summary>
/// DependencyProperty to store a dictionary of key-command pairs for a UIElement.
/// </summary>
public static readonly DependencyProperty CommandBindingsProperty =
DependencyProperty.RegisterAttached(
ComCtlResources.GlobalKeyCommandBindings, typeof(Dictionary<Key, ICommand>), typeof(GlobalKeyHandler),
new PropertyMetadata(null));


/// <summary>
/// Skip text controls property
/// </summary>
public static readonly DependencyProperty SkipTextControlsProperty =
DependencyProperty.RegisterAttached(
ComCtlResources.GlobalKeySkipTextControls, typeof(bool), typeof(GlobalKeyHandler),
new PropertyMetadata(true));

/// <summary>
/// Sets the skip text controls.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public static void SetSkipTextControls(UIElement element, bool value)
{
element.SetValue(SkipTextControlsProperty, value);
}

/// <summary>
/// Gets the skip text controls.
/// </summary>
/// <param name="element">The element.</param>
/// <returns>Returns if we skip control.</returns>
public static bool GetSkipTextControls(UIElement element)
{
return (bool)element.GetValue(SkipTextControlsProperty);
}

/// <summary>
/// Sets the Attach property, enabling or disabling key handling on the specified UIElement.
/// When set to true, key events are registered; when false, they are unregistered.
Expand Down Expand Up @@ -91,8 +125,9 @@ private static void OnPreviewKeyDown(object sender, KeyEventArgs e)
// Get the currently focused element using Keyboard.FocusedElement
var focusedElement = Keyboard.FocusedElement;

if (focusedElement is TextBox or RichTextBox)
return; // Skip key handling if focus is inside a TextBox or RichTextBox
// Check if skipping text controls is enabled
if (GetSkipTextControls(element) && focusedElement is TextBox or RichTextBox)
return;

// Retrieve the dictionary of key-command bindings for this element
var bindings = GetCommandBindings(element);
Expand Down
2 changes: 2 additions & 0 deletions SlimViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<local:ImageView x:Name="View" />
</Window.DataContext>
<Grid external:GlobalKeyHandler.Attach="True"
external:GlobalKeyHandler.SkipTextControls="True"
external:GlobalKeyHandler.CommandBindings="{Binding CommandBindings}">
<Grid.RowDefinitions>
<RowDefinition Height="115" />
Expand Down Expand Up @@ -401,5 +402,6 @@
Source="pack://application:,,,/SlimViews;component/Templates/ToolOptionsTemplates.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Window.Resources>
</Window>
2 changes: 1 addition & 1 deletion SlimViews/FilterConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
Title="Filter Config" Height="350" Width="525">
<Window.DataContext>
<local:FilterConfigView />
<local:FilterConfigView x:Name ="FilterView" />
</Window.DataContext>
<Grid Margin="5">
<Grid.RowDefinitions>
Expand Down
26 changes: 21 additions & 5 deletions SlimViews/FilterConfig.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@
* PROGRAMER: Peter Geinitz (Wayfarer)
*/

using System.Windows;
using Imaging;

namespace SlimViews
{
/// <summary>
/// Configuration for our Filters
/// </summary>
{
/// <inheritdoc cref="Window" />
/// <summary>
/// Configuration for our Filters
/// </summary>
public partial class FilterConfig
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="FilterConfig" /> class.
/// Initializes a new instance of the <see cref="T:SlimViews.FilterConfig" /> class.
/// </summary>
public FilterConfig()
{
InitializeComponent();
}

/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="FilterConfig"/> class.
/// </summary>
/// <param name="filter">The filter.</param>
public FilterConfig(ImageFilters filter)
{
InitializeComponent();
FilterView.SelectedFilter = filter;
}
}
}
28 changes: 27 additions & 1 deletion SlimViews/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,11 +1897,24 @@ private void ExplorerAction(object obj)
/// <param name="obj">The object.</param>
private void FilterConfigWindowAction(string obj)
{
var filterConfig = new FilterConfig
var filterConfig = new FilterConfig()
{
Topmost = true,
Owner = Main
};

if (!string.IsNullOrEmpty(obj))
{
var filter = Translator.GetFilterFromString(obj);

// Reassign the TextureConfig to initialize with texture if needed
filterConfig = new FilterConfig(filter)
{
Topmost = true,
Owner = Main
};
}

filterConfig.Show();
}

Expand All @@ -1916,6 +1929,19 @@ private void TextureConfigWindowAction(string obj)
Topmost = true,
Owner = Main
};

if (!string.IsNullOrEmpty(obj))
{
var texture = Translator.GetTextureFromString(obj);

// Reassign the TextureConfig to initialize with texture if needed
textureConfig = new TextureConfig(texture)
{
Topmost = true,
Owner = Main
};
}

textureConfig.Show();
}

Expand Down
12 changes: 9 additions & 3 deletions SlimViews/Templates/ToolOptionsTemplates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<!-- Visibility based on selected texture -->
<Button Content="Texture Config"
Grid.Row="4"
Command="{Binding TextureConfigCommand}"
Grid.Column="2">
<Button.Visibility>
<MultiBinding Converter="{StaticResource ComboBoxVisibilityAndSelectionConverter}">
Expand All @@ -215,6 +216,9 @@
<Binding Path="SelectedIndex" ElementName="TextureCombobox" />
</MultiBinding>
</Button.Visibility>
<Button.CommandParameter>
<Binding Path="SelectedValue" ElementName="TextureCombobox" />
</Button.CommandParameter>
</Button>


Expand Down Expand Up @@ -255,8 +259,8 @@
<!-- Add more filter options if needed -->
</ComboBox>

<Button Name="FilterConfig"
Content="Filter Config"
<Button Content="Filter Config"
Command="{Binding FilterConfigCommand}"
Grid.Row="4"
Grid.Column="2">
<Button.Visibility>
Expand All @@ -267,9 +271,11 @@
<Binding Path="SelectedIndex" ElementName="FilterCombobox" />
</MultiBinding>
</Button.Visibility>
<Button.CommandParameter>
<Binding Path="SelectedValue" ElementName="FilterCombobox" />
</Button.CommandParameter>
</Button>


</Grid>
</ScrollViewer>
</DataTemplate>
Expand Down
4 changes: 2 additions & 2 deletions SlimViews/TextureConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
Title="Texture Config" Height="800" Width="450">
<Window.DataContext>
<local:TextureConfigView />
<local:TextureConfigView x:Name ="TextureView" />
</Window.DataContext>

<Grid Margin="5">
Expand Down Expand Up @@ -66,7 +66,7 @@
<!-- Texture Type Selection ComboBox -->
<TextBlock Grid.Row="0" FontWeight="Bold" Text="Texture Type" Margin="0,5" />
<ComboBox Grid.Row="0" Grid.Column="0" ItemsSource="{Binding TextureOptions}"
SelectedItem="{Binding SelectedTexture}" Width="200" Margin="0,5" />
SelectedItem="{Binding SelectedTexture}" Grid.ColumnSpan="2" />

<!-- General Settings -->
<TextBlock Grid.Row="1" Grid.Column="0" FontWeight="Bold" Text="General Settings" Margin="0,10,0,5" />
Expand Down
20 changes: 18 additions & 2 deletions SlimViews/TextureConfig.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@
* PROGRAMER: Peter Geinitz (Wayfarer)
*/

using System.Windows;
using Imaging;

namespace SlimViews
{
/// <inheritdoc cref="Window" />
/// <summary>
/// Texture config
/// </summary>
public partial class TextureConfig
public sealed partial class TextureConfig
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="TextureConfig" /> class.
/// Initializes a new instance of the <see cref="T:SlimViews.TextureConfig" /> class.
/// </summary>
public TextureConfig()
{
InitializeComponent();
}

/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="TextureConfig"/> class.
/// </summary>
/// <param name="texture">The texture.</param>
public TextureConfig(TextureType texture)
{
InitializeComponent();
TextureView.SelectedTexture = texture;
}
}
}

0 comments on commit d52ad48

Please sign in to comment.