-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
904 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
KaddaOK.AvaloniaApp/Controls/Dialogs/EditSyllableTextDialog.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / build
|
||
} | ||
|
||
if (e.Key == Key.Escape) | ||
{ | ||
dialogHost?.CloseDialogCommand.Execute(null); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.