Skip to content

Commit

Permalink
keyboard use on edit tab
Browse files Browse the repository at this point in the history
  • Loading branch information
KaddaOK committed Mar 10, 2024
1 parent 8d0c6d7 commit 8cf46c5
Show file tree
Hide file tree
Showing 13 changed files with 904 additions and 388 deletions.
1 change: 1 addition & 0 deletions KaddaOK.AvaloniaApp/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Application.Resources>
<local:WaveformToPointConverter x:Key="WaveformToPointConverter" />
<local:WaveformToLengthConverter x:Key="WaveformToLengthConverter" />
<local:ObjectEqualityBooleanConverter x:Key="ObjectEqualityBooleanConverter" />
<local:RoundingConverter x:Key="RoundingConverter" />
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
xmlns:models="clr-namespace:KaddaOK.AvaloniaApp.Models"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="KaddaOK.AvaloniaApp.Controls.Dialogs.EditLineTimingDialog"
x:DataType="models:EditingLine">
x:DataType="models:EditingLine"
Focusable="True"
AttachedToVisualTree="UserControl_AttachedToVisualTree"
KeyDown="UserControl_KeyDown">
<dialogs:ModalDialogChrome Title="Edit Line Timing">
<Grid
RowDefinitions="50,85,100,85,90,50"
Expand Down
11 changes: 11 additions & 0 deletions KaddaOK.AvaloniaApp/Controls/Dialogs/EditLineTimingDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ private void NewRectanglesItemsControl_PointerReleased(object? sender, PointerRe
{
EditLinesViewModel?.EditLineTimingDialogPointerReleased(sender, args);
}

private void UserControl_KeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
{
EditLinesViewModel?.EditLineTimingDialogKeyDown(sender, e);
e.Handled = true;
}

private void UserControl_AttachedToVisualTree(object? sender, Avalonia.VisualTreeAttachmentEventArgs e)
{
this.Focus();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
and the timing dialog will open automatically for you to check the new distribution.)
</TextBlock>
<TextBox
AttachedToVisualTree="TextBox_AttachedToVisualTree"
Grid.Row="2"
Margin="0 8 0 0"
HorizontalAlignment="Stretch"
x:Name="EditWordTextBox"
Text="{Binding Text, Mode=OneWay}" />
Text="{Binding Text, Mode=OneWay}"
KeyDown="TextBox_KeyDown"/>
<StackPanel
Grid.Row="3"
Orientation="Horizontal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.VisualTree;
using DialogHostAvalonia;

namespace KaddaOK.AvaloniaApp.Controls.Dialogs
{
public partial class EditSyllableTextDialog : UserControl
{
private DialogHost? dialogHost;

public EditSyllableTextDialog()
{
InitializeComponent();
}

private void TextBox_AttachedToVisualTree(object? sender, Avalonia.VisualTreeAttachmentEventArgs e)
{
(sender as TextBox)?.Focus();
dialogHost = this.FindAncestorOfType<DialogHost>();
}

private void TextBox_KeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
dialogHost?.CloseDialogCommand.Execute(((TextBox)sender).Text);

Check warning on line 27 in KaddaOK.AvaloniaApp/Controls/Dialogs/EditSyllableTextDialog.axaml.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 27 in KaddaOK.AvaloniaApp/Controls/Dialogs/EditSyllableTextDialog.axaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

if (e.Key == Key.Escape)
{
dialogHost?.CloseDialogCommand.Execute(null);
}
}
}
}
18 changes: 18 additions & 0 deletions KaddaOK.AvaloniaApp/ObjectEqualityBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Avalonia.Data.Converters;

namespace KaddaOK.AvaloniaApp
{
public class ObjectEqualityBooleanConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values.Count != 2 || values.Any(v => v == null || v.ToString() == "(unset)")) return null;

return values[0] == values[1];
}
}
}
72 changes: 16 additions & 56 deletions KaddaOK.AvaloniaApp/ObservableStack.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,37 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;

namespace KaddaOK.AvaloniaApp
{
/// <summary>
/// Per https://stackoverflow.com/a/56177896/
/// </summary>
public class ObservableStack<T> : Stack<T>, INotifyCollectionChanged, INotifyPropertyChanged
public class ObservableStack<T> : ObservableCollection<T>
{
#region Constructors
public T? Peek => Items.LastOrDefault();

public ObservableStack() : base() { }

public ObservableStack(IEnumerable<T> collection) : base(collection) { }

public ObservableStack(int capacity) : base(capacity) { }

#endregion

#region Overrides

public new virtual T? Pop()
public T? Pop()
{
var item = base.Pop();
OnCollectionChanged(NotifyCollectionChangedAction.Remove, item);

return item;
}

public new virtual void Push(T? item)
{
if (item != null)
var popIndex = Items.Count - 1;
var itemToPop = Items[popIndex];
if (itemToPop != null)
{
base.Push(item);
OnCollectionChanged(NotifyCollectionChangedAction.Add, item);
RemoveAt(popIndex);
}
}

public new virtual void Clear()
{
base.Clear();
OnCollectionChanged(NotifyCollectionChangedAction.Reset, default);
return itemToPop;
}

#endregion

#region CollectionChanged

public event NotifyCollectionChangedEventHandler? CollectionChanged;

protected virtual void OnCollectionChanged(NotifyCollectionChangedAction action, T? item)
public void Push(T? item)
{
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(
action
, item
, item == null ? -1 : 0)
);

OnPropertyChanged(nameof(Count));
Add(item);
}

#endregion

#region PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged(string proertyName)
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(proertyName));
base.OnCollectionChanged(e);
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Count)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Peek)));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class DesignTimeEditLinesViewModel : EditLinesViewModel
{
public DesignTimeEditLinesViewModel() : base(DesignTimeKaraokeProcess.Get(), new LineSplitter(), new WordMerger(), new MinMaxFloatWaveStreamSampler())
{
UndoStack.Add(new ChosenLinesAction("[]", "did this before this view"));
UndoStack.Add(new ChosenLinesAction("[]", "and then I did this"));
RedoStack.Add(new ChosenLinesAction("[]", "already undid this first"));
RedoStack.Add(new ChosenLinesAction("[]", "then undid this"));
}
}
}
Loading

0 comments on commit 8cf46c5

Please sign in to comment.