Files
OpenNest/OpenNest.Avalonia/Controls/EditableCombo.cs
T
ajandClaude Opus 5.5 f76bad4bac feat(avalonia): Nest > Edit, Clear Nest and the nest defaults
Nest > Edit opens Edit Nest as the WinForms dialog has it: the Info tab
(name, dates, thickness with the standard gauges, material and grade
from the posts and machines, customer, units, status and author), the
Defaults tab (plate size, part and edge spacing, quadrant, and "Use
these defaults for new nests") and the Notes tab. Done is enabled while
the name, thickness and size read and the edge spacing leaves room; it
is one "Nest Info" undo step through the shared NestCommands, a typed
author is remembered for new nests, and the name stays the file's. A
click on the status bar's material label opens it too (a right-click
offers it in a menu), with the WinForms tooltip.

Nest > Clear Nest... asks before leaving one empty plate, as one "Clear
Nest" step; it is refused while Auto Nest or a save runs or the plate
tool is busy. Tools > Nest Defaults... edits the machine, units, plate
size, quadrant, spacing and common-line usage new nests start from,
saved where they are read (the nest server once it holds them, read-only
while it cannot be reached), and Save Current Plate as Defaults saves
the shown plate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:49:17 -05:00

88 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Layout;
namespace OpenNest.Avalonia.Controls
{
/// <summary>
/// A text box with a list to pick from, as a WinForms drop-down combo box: any text can be
/// typed, typing offers the items that start with it, and the arrow button lists them all.
/// </summary>
internal sealed class EditableCombo : UserControl
{
private readonly AutoCompleteBox box = new()
{
FilterMode = AutoCompleteFilterMode.StartsWith,
MinimumPrefixLength = 1,
MaxDropDownHeight = 320,
HorizontalAlignment = HorizontalAlignment.Stretch,
};
private IReadOnlyList<string> items = Array.Empty<string>();
public EditableCombo()
{
var open = new Button
{
Content = "▾",
Padding = new global::Avalonia.Thickness(6, 0),
VerticalAlignment = VerticalAlignment.Stretch,
Focusable = false,
};
open.Click += (_, _) => ShowAll();
box.DropDownClosed += (_, _) => box.FilterMode = AutoCompleteFilterMode.StartsWith;
box.TextChanged += (_, _) => TextChanged?.Invoke(this, EventArgs.Empty);
box.LostFocus += (_, _) => LostFocusText?.Invoke(this, EventArgs.Empty);
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
grid.Children.Add(box);
Grid.SetColumn(open, 1);
grid.Children.Add(open);
Content = grid;
}
/// <summary>Raised when the text changes, typed or picked.</summary>
public event EventHandler TextChanged;
/// <summary>Raised when the box loses the keyboard, for tidying the typed text.</summary>
public event EventHandler LostFocusText;
public string Text
{
get => box.Text ?? "";
set => box.Text = value ?? "";
}
/// <summary>The items listed, in order; the text is kept.</summary>
public IReadOnlyList<string> Items
{
get => items;
set
{
var text = Text;
items = (value ?? Array.Empty<string>()).ToList();
box.ItemsSource = items;
if (Text != text)
Text = text;
}
}
public bool FocusText() => box.Focus();
// Lists every item, whatever is typed, as a WinForms combo box's arrow does.
private void ShowAll()
{
if (items.Count == 0)
return;
box.FilterMode = AutoCompleteFilterMode.None;
var text = Text;
box.ItemsSource = null;
box.ItemsSource = items;
if (Text != text)
Text = text;
box.IsDropDownOpen = true;
}
}
}