Snapshot the v5 hosts screen mid-restructure, with handoff notes to resume it

This commit is contained in:
2026-08-07 15:26:00 +02:00
parent bea0279937
commit 06f9dcfc27
5 changed files with 1095 additions and 554 deletions
+135 -504
View File
@@ -9,113 +9,75 @@ using DodoSSH.Client.Shell.ViewModels;
namespace DodoSSH.Client.App.Views;
/// <summary>
/// The grid of groups and hosts, and everything on it that is a gesture rather than a binding.
/// The flat board of host cards, and everything on it that is a gesture rather than a binding.
/// </summary>
/// <remarks>
/// <para>
/// All of this was <c>HostSidebar</c>'s until the host list became a grid of cards. It moved with the list
/// rather than staying with the editor: every handler here is about the thing that was clicked, dragged or
/// right-clicked, and the drawer beside the grid has none of those. See <see cref="HostDrawer"/>.
/// ◆ <b>v5: THE GRID OF GROUP CARDS AND THE BREADCRUMB TRAIL ARE GONE, AND SO IS THE DRAG.</b> The desktop
/// used to hold one level of the group tree at a time — a wrap of group cards above the hosts, opened by a
/// double-click, with a trail above it saying where you were — the way a directory pane holds one directory.
/// That model is retired outright rather than folded into the new board: every group is now a heading, in
/// label order, all of them at once, exactly the flattening the phone's <c>SidebarRows</c> has always drawn.
/// A host is filed under a group through the group's own picker in its editor, or through the "Change
/// group…" entry the chosen-hosts menu already carried — dragging a card onto another card had exactly one
/// destination, a group card, and that card is what left. See <c>VaultViewModel.HostSections</c>.
/// </para>
/// <para>
/// ◆ <b>There are two selections on this screen and they are not the same thing.</b> The <c>ListBox</c> holds
/// one — the card the drawer, CONNECT and the ordinary menu are about — and the vault holds a <em>set</em>,
/// which is what Ctrl, Shift and a band dragged across the grid build. The set is the phone's, built here by
/// a pointer instead of by a long press; see <c>VaultViewModel.ChooseHosts</c> and Android's
/// <c>HostsScreen</c>. Everything below that reads a modifier is about keeping the two from being confused
/// for one another: a plain press drops the set, so no command ever runs while both are saying something
/// different.
/// ◆ <b>ONE SECTION, ONE <c>ListBox</c>.</b> The two shapes worth weighing were a single mixed list of
/// header rows and host rows in one <c>WrapPanel</c>, or an <c>ItemsControl</c> of sections each holding its
/// own card list. The first is what the phone's single flat list already is, and reusing it here would have
/// meant a header row pretending to be as wide as the row it sits on so the wrap panel breaks a line before
/// and after it — a real technique, and a fragile one to get right at every width this window can be resized
/// to. The second costs a real thing: there is no longer one <c>ListBox</c> owning one <c>SelectedItem</c>,
/// so multi-select and the marquee have to be taught to reach across however many section lists are on
/// screen. That is what most of this file now does. It was chosen anyway, because a <c>WrapPanel</c> that
/// only ever holds cards of one kind is the ordinary, well-trodden case, and "reach across N lists instead
/// of one" is a bounded, mechanical problem — enumerate every list, not the fixed one named in the markup —
/// where "make a wrap panel break a line for one specific child" is a harder one to be sure of without a
/// custom panel this application does not otherwise need.
/// </para>
/// <para>
/// Its data context is the <c>VaultViewModel</c>, as <see cref="KeychainScreen"/>'s is, so every binding in the
/// markup is a property of the vault. The window hands it over; see <see cref="MainWindow"/>. The drawer
/// beside the grid inherits the same one.
/// ◆ <b>SELECTION IS ONE-WAY INTO EVERY SECTION AND WRITTEN BY HAND ON THE WAY OUT.</b> Each section's
/// <c>ListBox</c> binds <c>SelectedItem</c> from <c>VaultViewModel.SelectedSidebarRow</c> so the right card
/// lights up wherever it lives, but not back — a two-way binding shared by several independently-rebuilt
/// lists would have each list's own <c>Reset</c> (one per filter keystroke, one per background sync) racing
/// to null the one shared property, which is the same hazard <c>VaultViewModel.RebuildVisibleHosts</c>
/// already documents for a single list and multiplies it by the section count. So a card being pressed is
/// what actually moves the selection, here in code, exactly as a Ctrl or Shift modifier already had to be —
/// see <see cref="OnPointerPressed"/>.
/// </para>
/// <para>
/// ◆ <b>THERE ARE STILL TWO SELECTIONS ON THIS SCREEN, AND THEY ARE STILL NOT THE SAME THING.</b>
/// <c>SelectedHost</c> is the card the drawer, CONNECT and the ordinary menu are about; the chosen set is
/// what Ctrl, Shift and the band build on top of it, as <c>IsChosen</c> on the row. Every handler below that
/// reads a modifier is about keeping the two from being confused for one another, on the same terms this
/// screen has always used — see <c>VaultViewModel.ChooseHosts</c> and Android's <c>HostsScreen</c>.
/// </para>
/// <para>
/// Its data context is the <c>VaultViewModel</c>, as <see cref="KeychainScreen"/>'s is. The window hands it
/// over; see <see cref="MainWindow"/>.
/// </para>
/// </remarks>
internal sealed partial class HostsScreen : UserControl
{
/// <summary>
/// How hosts travel from the cards they were picked up on to the group card they are dropped on.
/// </summary>
/// <summary>How far the pointer has to travel before a press on the empty space becomes a band.</summary>
/// <remarks>
/// <para>
/// An in-process format carrying the rows themselves, rather than text carrying ids. The drag never
/// leaves this window — there is nothing outside it that could accept a host — and the rows are what the
/// drop needs: they know which vault each edit has to return to, which an id on its own does not.
/// </para>
/// <para>
/// A list rather than one row, because a drag that starts on a ticked card carries every ticked card.
/// Moving whichever one the pointer happened to be holding and leaving the other five where they are is
/// a gesture that quietly does a fraction of what it looks like it does.
/// </para>
/// </remarks>
private static readonly DataFormat<IReadOnlyList<HostRowViewModel>> HostFormat =
DataFormat.CreateInProcessFormat<IReadOnlyList<HostRowViewModel>>("dodossh-host-rows");
/// <summary>How far the pointer has to travel before a press becomes a drag.</summary>
/// <remarks>
/// A threshold, because a press on this grid is nearly always a click: selecting a host, or the first
/// half of the double-click that connects. Starting a drag on the press itself would turn every one of
/// those into a drag gesture the user never asked for. The band on the empty space between the cards
/// uses it for the same reason — a click there means "nothing is chosen any more", and a rectangle that
/// flashed up on every one of those would be a gesture reported where none happened.
/// A threshold, because a press on the space around the cards is nearly always a click that drops the
/// chosen set — see <see cref="OnBandPressed"/>. Starting a band on the press itself would turn every one
/// of those into a rectangle nobody asked for.
/// </remarks>
private const double DragThreshold = 5;
/// <summary>How close to the top or bottom of the grid a drag has to be held to scroll it.</summary>
/// <remarks>
/// Deeper than a card's own margin, because the band has to be reachable while the pointer is still
/// carrying something the user is looking at — a band the width of a hairline would only be found by
/// accident, and only by somebody who did not need it.
/// </remarks>
private const double EdgeBand = 48;
/// <summary>How far one drag event inside that band moves the grid.</summary>
/// <remarks>
/// Roughly a third of a card, so a pointer moving inside the band travels the grid at about the speed it
/// is moving. A step of a whole card would jump the target out from under the pointer between two events.
/// </remarks>
private const double EdgeStep = 24;
/// <summary>The press a drag would start from, or null once it has become one or been let go of.</summary>
/// <remarks>
/// Held because <see cref="DragDrop.DoDragDropAsync"/> takes the press rather than the movement: the
/// gesture belongs to the pointer that went down, and the platform needs that event to hand the drag
/// over to the operating system.
/// </remarks>
private PointerPressedEventArgs? press;
/// <summary>What that press would carry: the ticked hosts, or the one card it landed on.</summary>
private IReadOnlyList<HostRowViewModel> pickedUp = [];
private Point origin;
/// <summary>The group card the pointer is currently over, while a drag is in flight.</summary>
private ListBoxItem? marked;
/// <summary>
/// Where a Shift-click measures its run from: the last card pressed without one.
/// </summary>
/// <summary>Where a Shift-click measures its run from: the last card pressed without one.</summary>
/// <remarks>
/// Kept here rather than in the vault because it is a fact about the gesture rather than about the
/// keychain — it is what the pointer last touched, and it means nothing to the phone or to any command.
/// Null until something has been pressed, which is what a Shift-click into an untouched grid falls back
/// Null until something has been pressed, which is what a Shift-click into an untouched board falls back
/// to the selected card for.
/// </remarks>
private HostRowViewModel? anchor;
/// <summary>
/// The ticked card a plain press landed on, which the release collapses the set onto.
/// </summary>
/// <remarks>
/// ◆ <b>A plain press on a card that is already ticked cannot drop the set, because it may be the start
/// of a drag of all of it.</b> So the decision is deferred to the release: if no drag began, the press
/// was an ordinary click and means what a click always means here — this one card, and nothing else. If
/// one did, <see cref="Forget"/> clears this on the way out and the set survives the journey.
/// </remarks>
private HostRowViewModel? collapse;
/// <summary>Whether a band is being dragged out over the grid right now.</summary>
/// <summary>Whether a band is being dragged out over the board right now.</summary>
private bool banding;
/// <summary>The corner it was started from, in the scroller's own coordinates.</summary>
@@ -133,53 +95,17 @@ internal sealed partial class HostsScreen : UserControl
InitializeComponent();
// Wired here rather than in the markup because it is a gesture rather than a binding, which is how
// the transfers screen opens a directory too. Double-clicking a machine to get a shell on it is what
// every other client of this kind does, and CONNECT stays: it is the one in the drawer with the
// password box above it, and a host that asks for a password still needs it typed first.
HostGrid.DoubleTapped += OnHostActivated;
// the transfers screen opens a directory too. Attached to the board rather than to any one section's
// list, since double-tapping a card in any of them means the same thing and DoubleTapped bubbles.
Board.DoubleTapped += OnHostActivated;
// And a group card opens the group, on the same gesture, for the same reason: going inside
// something by double-clicking it is what the transfers screen's directories do and what every file
// manager does. One click used to open a group, which made the card that names a group and the
// control that narrows the grid to it the same press — so there was no way to select a group in
// order to rename it without also losing sight of every host outside it.
GroupGrid.DoubleTapped += OnGroupActivated;
// Tunnelled, so the card under the pointer is read before the ListBox has answered the press itself.
// Bubbling would work for the drag but not for the menu: by then the control has already decided
// what is selected, and the menu is about to open against it. It is also what lets a modifier click
// stop the press dead — see OnPointerPressed, where a Ctrl-click must tick a card without the list
// moving its own selection onto it.
HostGrid.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Tunnel);
HostGrid.AddHandler(ContextRequestedEvent, OnContextRequested, RoutingStrategies.Tunnel);
// And the group cards answer a right click the same way, for the same reason: their menu's commands
// read the vault's group selection, and without this they would act on whichever card was selected
// before — or, with none, on the group the trail ends with, which is not on screen at all.
GroupGrid.AddHandler(ContextRequestedEvent, OnGroupContextRequested, RoutingStrategies.Tunnel);
HostGrid.PointerMoved += OnPointerMoved;
HostGrid.PointerReleased += OnPointerReleased;
HostGrid.PointerCaptureLost += OnPointerCaptureLost;
// Tunnelled, so the card under the pointer is read before whichever section's ListBox has answered
// the press itself. Bubbling would work for a plain click but not for the menu or for Ctrl/Shift: by
// the time either reaches this control the list has already decided what it thinks is selected.
Board.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Tunnel);
Board.AddHandler(ContextRequestedEvent, OnContextRequested, RoutingStrategies.Tunnel);
WireTheBand();
// The host grid is where a drag starts and the group cards are where it lands. They used to be the
// same control: the target was a heading among the cards, and with the headings gone the group cards
// are the only thing on this screen that names a group. A card dropped onto another card is refused
// rather than filed beside it — in a grid with no headings there is nothing to say which group that
// would be, and a gesture whose result you cannot see before you let go is one that files machines
// somewhere the user did not intend.
DragDrop.AddDragOverHandler(GroupGrid, OnDragOver);
DragDrop.AddDragLeaveHandler(GroupGrid, OnDragLeave);
DragDrop.AddDropHandler(GroupGrid, OnDrop);
// Everywhere else the pointer can be during a drag, and it is a handler rather than the absence of
// one because AllowDrop is an inherited property: it is set on the scroller so that a drag anywhere
// over the grid is reported at all, and that makes every card inside it a drop target as far as the
// platform is concerned. This is where all of them but a group card are turned down — and where a
// drag held at the top or bottom edge pulls the grid towards the target.
DragDrop.AddDragOverHandler(Scroll, OnDragOverScroll);
}
/// <summary>The band's own wiring, and the two keys that go with a set.</summary>
@@ -190,17 +116,17 @@ internal sealed partial class HostsScreen : UserControl
/// </remarks>
private void WireTheBand()
{
// Esc and Ctrl+A, on the grid rather than on the window: both are ordinary editing keys that mean
// Esc and Ctrl+A, on the board rather than on the window: both are ordinary editing keys that mean
// something else everywhere else, and Ctrl+A in the find box above has to go on selecting the text
// in it. The grid takes focus on a press, so the keys work from the moment anything has been
// in it. The board takes focus on a press, so the keys work from the moment anything has been
// touched; see KeyboardTarget for the other half of who has the keyboard on this screen.
HostGrid.KeyDown += OnGridKey;
Board.KeyDown += OnGridKey;
// ◆ The band is the scroller's rather than the list's, because the space it is dragged out over is
// mostly not the list's: a WrapPanel of cards is exactly as tall as its cards, so everything below
// the last row — usually most of the screen — belongs to the stack around it. Tunnelled for the
// reason the list's own press is, and it runs first, so it has to recognise a press on a card and
// leave it alone.
// ◆ The band is the scroller's rather than any one section list's, because the space it is dragged
// out over is mostly not a list's: a WrapPanel of cards is exactly as tall as its cards, and the gaps
// between sections and below the last one belong to the stack around them. Tunnelled for the reason
// the board's own press is, and it runs first, so it has to recognise a press on a card and leave it
// alone.
Scroll.AddHandler(PointerPressedEvent, OnBandPressed, RoutingStrategies.Tunnel);
Scroll.PointerMoved += OnBandMoved;
Scroll.PointerReleased += OnBandReleased;
@@ -224,15 +150,13 @@ internal sealed partial class HostsScreen : UserControl
/// <para>
/// It has to be a control the keyboard can actually go to. <c>Focus()</c> on a collapsed control is
/// measurably a no-op and is not replayed when the control is revealed, so handing the keyboard to
/// something that is not there would swallow it: the terminal would let go and nothing would take it.
/// The grid no longer folds away as the sidebar's list could, but an empty grid is still a
/// <c>ListBox</c> with no item to take focus — and an empty grid is exactly what a filter that matches
/// nothing produces, which is a state somebody typing is very likely to be in. The find box is the
/// answer then, and it is a good one: it is where they were typing.
/// something that is not there would swallow it. <c>Board</c> is focusable and holds every section, so it
/// answers as long as one card is on it; an empty board is what a filter matching nothing produces, and
/// the find box is the answer then — it is where they were typing.
/// </para>
/// </remarks>
internal IInputElement KeyboardTarget =>
Vault is { HasVisibleHosts: true } ? HostGrid : HostFilter;
Vault is { HasHostBoardEntries: true } ? Board : HostFilter;
/// <remarks>
/// Fire-and-forget, as the transfers screen's is: the command reports its own failures onto the status
@@ -241,31 +165,15 @@ internal sealed partial class HostsScreen : UserControl
/// </remarks>
private void OnHostActivated(object? sender, TappedEventArgs e)
{
// Only over a card. A double-tap on the space around them must not connect to whichever host was
// selected before — which is what an unguarded handler would do, on a machine the user is not even
// pointing at.
// Only over a card. A double-tap on the space around them, or on a section heading, must not connect
// to whichever host was selected before — which is what an unguarded handler would do, on a machine
// the user is not even pointing at.
if (Vault is { } vault && RowUnder(e.Source) is HostRowViewModel)
{
_ = vault.ConnectCommand.ExecuteAsync(null);
}
}
/// <summary>
/// Opens the group card that was double-clicked.
/// </summary>
/// <remarks>
/// Guarded over the space around the cards exactly as the host grid's is, and it is the same mistake
/// being guarded against: an unguarded handler would open whichever group happened to be selected when
/// somebody double-clicked the gap beside it, throwing every host outside that group off the screen.
/// </remarks>
private void OnGroupActivated(object? sender, TappedEventArgs e)
{
if (Vault is { } vault && RowUnder(e.Source) is HostGroupRowViewModel group)
{
vault.OpenGroupCommand.Execute(group);
}
}
/// <summary>
/// Points the menu at whatever was right-clicked.
/// </summary>
@@ -283,8 +191,9 @@ internal sealed partial class HostsScreen : UserControl
/// behind the menu.
/// </para>
/// <para>
/// Cancelled outright over the space around the cards. That is not a host, and a menu offering Connect,
/// Edit and Delete over it would be entries that either do nothing or act on something else entirely.
/// Cancelled outright over the space around the cards, or on a section heading. Neither is a host, and a
/// menu offering Connect, Edit and Delete over either would be entries that either do nothing or act on
/// something else entirely.
/// </para>
/// </remarks>
private void OnContextRequested(object? sender, ContextRequestedEventArgs e)
@@ -302,68 +211,39 @@ internal sealed partial class HostsScreen : UserControl
if (!vault.IsChoosingHosts)
{
vault.SelectedSidebarRow = row;
vault.SelectedHost = row;
}
}
/// <summary>
/// Points the group menu at whatever was right-clicked.
/// </summary>
/// <remarks>
/// <para>
/// The host grid's rule, applied to the cards above it — see <see cref="OnContextRequested"/>. What is
/// different is what an unaimed menu would have done: <c>GroupTarget</c> falls back to the open group
/// when no card is selected, so Edit and Delete over a card would have been offered about the group whose
/// contents are showing rather than the one the pointer is on. This menu is the only way to either of
/// them now, so aiming it is the whole of aiming them.
/// </para>
/// <para>
/// Cancelled outright over the space around the cards, as the host grid's is. That is not a group, and
/// the fallback is exactly what would make the menu look like it worked there.
/// </para>
/// </remarks>
private void OnGroupContextRequested(object? sender, ContextRequestedEventArgs e)
{
if (Vault is not { } vault || RowUnder(e.Source) is not HostGroupRowViewModel row)
{
e.Handled = true;
return;
}
vault.SelectedGroup = row;
}
/// <summary>
/// Ticks cards, or remembers a press that may become a drag.
/// Ticks cards, or moves the selection.
/// </summary>
/// <remarks>
/// <para>
/// ◆ <b>Ctrl and Shift are answered here and go no further.</b> Both mark the event handled, which is
/// what stops the <c>ListBox</c> underneath from moving its own selection onto the card: a Ctrl-click
/// that also selected would light the card it had just unticked, and the drawer would open on a machine
/// the user was removing from a set. Handled on the way down is the only place that can be said —
/// by the time the press bubbles the control has already answered it.
/// what stops whichever section's <c>ListBox</c> the press landed in from moving its own selection onto
/// the card: a Ctrl-click that also selected would light the card it had just unticked, and the drawer
/// would open on a machine the user was removing from a set. Handled on the way down is the only place
/// that can be said — by the time the press bubbles the control has already answered it.
/// </para>
/// <para>
/// <b>A plain press drops the set</b>, unless it lands on a card already in it. That is the rule every
/// file manager has and the reason the two selections on this screen can never disagree: after an
/// ordinary click there is exactly one card in play. Landing on a ticked card defers the same decision
/// to the release, because the press may be the start of a drag of the whole set; see
/// <see cref="collapse"/>.
/// <b>A plain press moves the selection and drops the chosen set</b>, which is every file manager's rule
/// and the reason the two selections on this screen can never disagree: after an ordinary click there is
/// exactly one card in play. Not marked handled — the section list's own native selection is left to
/// follow along, which is harmless now that it is only <c>OneWay</c> bound: whatever it shows locally is
/// overwritten the moment <see cref="VaultViewModel.SelectedHost"/>'s change reaches every section again.
/// </para>
/// <para>
/// Nothing here refuses while the drawer's editor is open, and the phone's own <c>ChooseHost</c> does.
/// The difference is real: there a sheet is over the list and the row under the finger is not what was
/// aimed at, where the grid sits beside the editor in plain view. Ticking is free anyway — the seven
/// aimed at, where the board sits beside the editor in plain view. Ticking is free anyway — the seven
/// things that can then be done to a set each refuse for themselves, and say so.
/// </para>
/// </remarks>
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
Forget();
if (Vault is not { } vault
|| !e.GetCurrentPoint(HostGrid).Properties.IsLeftButtonPressed
|| !e.GetCurrentPoint(Board).Properties.IsLeftButtonPressed
|| RowUnder(e.Source) is not HostRowViewModel row)
{
return;
@@ -375,7 +255,7 @@ internal sealed partial class HostsScreen : UserControl
{
vault.ChooseHostRun(anchor ?? vault.SelectedHost, row, replacing: !control);
HostGrid.Focus();
Board.Focus();
e.Handled = true;
return;
@@ -386,7 +266,7 @@ internal sealed partial class HostsScreen : UserControl
vault.ToggleHostChoiceCommand.Execute(row);
anchor = row;
HostGrid.Focus();
Board.Focus();
e.Handled = true;
return;
@@ -394,82 +274,23 @@ internal sealed partial class HostsScreen : UserControl
anchor = row;
// Read before anything is cleared, since clearing is one of the two things it decides.
if (row.IsChosen)
{
collapse = row;
pickedUp = vault.ChosenHosts;
}
else
{
if (vault.IsChoosingHosts)
{
vault.ClearHostChoiceCommand.Execute(null);
}
pickedUp = [row];
}
press = e;
origin = e.GetPosition(HostGrid);
}
/// <remarks>
/// The drag is started from the remembered press once the pointer has travelled far enough — see
/// <see cref="DragThreshold"/>. Fire-and-forget, because the drag loop runs for as long as the user holds
/// the button and an event handler cannot wait on that; what happens after it is only clearing the mark.
/// </remarks>
private void OnPointerMoved(object? sender, PointerEventArgs e)
{
if (press is not { } pressed || pickedUp.Count == 0)
{
return;
}
if (!e.GetCurrentPoint(HostGrid).Properties.IsLeftButtonPressed)
{
Forget();
return;
}
var moved = e.GetPosition(HostGrid) - origin;
if (Math.Abs(moved.X) < DragThreshold && Math.Abs(moved.Y) < DragThreshold)
{
return;
}
var carried = pickedUp;
Forget();
_ = DragAsync(pressed, carried);
}
/// <remarks>
/// Where a press on a ticked card turns out to have been a click after all: no drag started, so it means
/// what every other click on a card means. See <see cref="collapse"/>.
/// </remarks>
private void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (collapse is not null && Vault is { } vault)
if (vault.IsChoosingHosts)
{
vault.ClearHostChoiceCommand.Execute(null);
}
Forget();
vault.SelectedHost = row;
}
private void OnPointerCaptureLost(object? sender, PointerCaptureLostEventArgs e) => Forget();
/// <summary>
/// Esc drops the set, and Ctrl+A is every card on the screen.
/// Esc drops the set, and Ctrl+A is every card on the board.
/// </summary>
/// <remarks>
/// <para>
/// Every card <em>on the screen</em>: <c>VisibleHosts</c>, which is one level of the tree with whatever
/// is in the find box already applied. Ctrl+A over a filtered grid that quietly ticked forty machines
/// including the thirty-two not being shown would be the worst possible input to Delete.
/// Every card <em>on the board</em>: <see cref="VaultViewModel.HostBoardOrder"/>, which is every section
/// with whatever the find box and the two toolbar flyouts have already narrowed it to, and every card a
/// fold has not hidden. Ctrl+A over a filtered board that quietly ticked machines it is not showing would
/// be the worst possible input to Delete.
/// </para>
/// <para>
/// Handled only when they did something. Esc has other jobs on this window — it closes the palette, and
@@ -492,10 +313,12 @@ internal sealed partial class HostsScreen : UserControl
return;
}
if (e.Key is Key.A && e.KeyModifiers.HasFlag(KeyModifiers.Control) && vault.HasVisibleHosts)
if (e.Key is Key.A && e.KeyModifiers.HasFlag(KeyModifiers.Control) && vault.HasHostBoardEntries)
{
vault.ChooseHosts(vault.VisibleHosts, replacing: true);
anchor = vault.VisibleHosts[0];
var order = vault.HostBoardOrder.ToList();
vault.ChooseHosts(order, replacing: true);
anchor = order[0];
e.Handled = true;
}
}
@@ -505,16 +328,16 @@ internal sealed partial class HostsScreen : UserControl
/// </summary>
/// <remarks>
/// <para>
/// ◆ <b>Only below the top of the host grid, and only where there is nothing to press.</b> The scroller
/// also holds the group cards, the trail and whichever panel the set's menu raised, and a rectangle
/// dragged out from inside any of those would be a gesture aimed at hosts started on something that is
/// not one. The ceiling is the grid's own top edge rather than a list of exclusions, so a panel opening
/// above it moves the ceiling with no code here changing.
/// ◆ <b>Only where there is nothing to press.</b> The scroller holds every section heading, every card
/// list and whichever panel the set's menu raised, and a rectangle dragged out from inside any of those
/// would be a gesture aimed at hosts started on something that is not one. <see cref="TakesThePress"/> is
/// the guard, and it is ancestor-based rather than naming one control, which is what lets it work
/// regardless of how many section lists happen to be realized.
/// </para>
/// <para>
/// The pointer is captured, because a band is nearly always dragged past the edge of the control it
/// started in — down onto the status bar, or off the window entirely — and without capture the moves
/// stop arriving and the release lands somewhere else, leaving a rectangle painted over the grid with
/// stop arriving and the release lands somewhere else, leaving a rectangle painted over the board with
/// nothing left to take it down.
/// </para>
/// <para>
@@ -533,19 +356,12 @@ internal sealed partial class HostsScreen : UserControl
return;
}
var at = e.GetPosition(Scroll);
if (at.Y < (HostGrid.TranslatePoint(default, Scroll)?.Y ?? double.MaxValue))
{
return;
}
banding = true;
bandFrom = at;
bandFrom = e.GetPosition(Scroll);
bandAdds = e.KeyModifiers.HasFlag(KeyModifiers.Control);
e.Pointer.Capture(Scroll);
HostGrid.Focus();
Board.Focus();
}
/// <remarks>
@@ -628,15 +444,16 @@ internal sealed partial class HostsScreen : UserControl
/// <summary>The hosts whose cards a rectangle over the scroller touches.</summary>
/// <remarks>
/// Touches rather than contains, which is what makes a band usable at all: cards are 232 pixels wide and
/// a rectangle that had to swallow one whole would mean dragging across the full width of every card in
/// the run, and would tick nothing at all for a band drawn down the middle of a column.
/// Touches rather than contains, which is what makes a band usable at all: a rectangle that had to
/// swallow a card whole would tick nothing for a band drawn down the middle of a column. Gathered from
/// every section's own list — see <see cref="AllCardContainers"/> — rather than one named control, since
/// a band drawn across two sections has to touch cards in both.
/// </remarks>
private List<HostRowViewModel> CardsIn(Rect box)
{
var hit = new List<HostRowViewModel>();
foreach (var container in HostGrid.GetRealizedContainers())
foreach (var container in AllCardContainers())
{
if (container.DataContext is HostRowViewModel row
&& container.TranslatePoint(default, Scroll) is { } corner
@@ -649,227 +466,41 @@ internal sealed partial class HostsScreen : UserControl
return hit;
}
/// <summary>Every realized card, across every section's own list.</summary>
/// <remarks>
/// A section is a <c>ListBox</c> of its own — see the type's remarks — so there is no single control
/// whose <c>GetRealizedContainers()</c> would answer for the whole board. Found by class rather than by
/// name, because how many sections exist is a fact about the keychain rather than the markup: a flat
/// keychain draws one, a filed one draws several, and neither shape is known until the vault says so.
/// </remarks>
private List<ListBoxItem> AllCardContainers() =>
[.. this.GetVisualDescendants()
.OfType<ListBox>()
.Where(list => list.Classes.Contains("sectioncards"))
.SelectMany(list => list.GetRealizedContainers())
.OfType<ListBoxItem>()];
/// <summary>Whether what was pressed is something that answers a press itself.</summary>
/// <remarks>
/// Everything a band must not start from, asked as "is this inside one" rather than by hit-testing a
/// rectangle: the cards, the scrollbar, and the controls on whichever panel is up. Missing the scrollbar
/// is the one that would be felt every day — dragging the thumb would paint a band down the grid and
/// tick everything it passed.
/// rectangle: the cards, the scrollbar, and the controls on whichever panel is up or in a section's own
/// heading. Missing the scrollbar is the one that would be felt every day — dragging the thumb would
/// paint a band down the board and tick everything it passed.
/// </remarks>
private static bool TakesThePress(object? source) => source is Visual visual
&& visual.GetSelfAndVisualAncestors().Any(element =>
element is ListBoxItem or ScrollBar or Button or ComboBox or TextBox);
/// <summary>Carries the picked-up hosts for as long as the user holds them.</summary>
private async Task DragAsync(PointerPressedEventArgs pressed, IReadOnlyList<HostRowViewModel> rows)
{
var carried = new DataTransfer();
carried.Add(DataTransferItem.Create(HostFormat, rows));
try
{
// ConfigureAwait(true): what follows touches the grid's own containers, and those are the UI
// thread's.
await DragDrop
.DoDragDropAsync(pressed, carried, DragDropEffects.Move)
.ConfigureAwait(true);
}
finally
{
// Whatever the drop did or did not do. A mark left behind would be a card that looks like a
// target for a drag that ended somewhere else entirely.
Unmark();
}
}
/// <summary>
/// Says whether what is under the pointer would take these hosts, and marks it if it would.
/// </summary>
/// <remarks>
/// A drag whose hosts are all already in the group under the pointer is refused, which is not pedantry:
/// <c>DragDropEffects.None</c> is what turns the cursor into the "no" one, and a drag that looks like it
/// would do something and then does nothing is worse than one that says so while it is still in the air.
/// A set with even one host from somewhere else is accepted, because filing that one is a real move.
/// </remarks>
private void OnDragOver(object? sender, DragEventArgs e)
{
e.Handled = true;
if (Target(e) is not { } target)
{
e.DragEffects = DragDropEffects.None;
Unmark();
return;
}
e.DragEffects = DragDropEffects.Move;
Mark(target.Container);
}
private void OnDragLeave(object? sender, DragEventArgs e) => Unmark();
/// <summary>
/// Carries the grid under a drag that is over the cards rather than over a group.
/// </summary>
/// <remarks>
/// <para>
/// <b>Without this the gesture is only available to whoever can see both ends of it.</b> The group cards
/// are the first thing in the scrolling stack and the host being filed may be the fortieth card down, and
/// a drag cannot use the wheel — the pointer button is held. So a drag held near the top edge pulls the
/// grid down towards the target, which is what every file manager does with a drag near the edge of a
/// list.
/// </para>
/// <para>
/// A step per event rather than a timer, and that is a real limit rather than a simplification: a
/// stationary pointer receives no drag events on any platform this runs on, so the scroll follows the
/// pointer moving inside the band and stops when it stops. A timer would scroll on its own and would then
/// need cancelling on the drop, on the leave, and on the drag that ends outside the window entirely.
/// </para>
/// <para>
/// Reached only when the group cards did not handle the event first, which is what makes refusing the
/// drop here correct: the space around the cards is not a target, and saying so keeps the "no" cursor on
/// everything that is not a group.
/// </para>
/// </remarks>
private void OnDragOverScroll(object? sender, DragEventArgs e)
{
if (e.DataTransfer.TryGetValue(HostFormat) is null)
{
return;
}
e.Handled = true;
e.DragEffects = DragDropEffects.None;
Unmark();
var at = e.GetPosition(Scroll).Y;
var height = Scroll.Bounds.Height;
var step = at switch
{
_ when at < EdgeBand => -EdgeStep,
_ when at > height - EdgeBand => EdgeStep,
_ => 0,
};
if (step == 0)
{
return;
}
var furthest = Math.Max(0, Scroll.Extent.Height - Scroll.Viewport.Height);
Scroll.Offset = Scroll.Offset.WithY(Math.Clamp(Scroll.Offset.Y + step, 0, furthest));
}
/// <remarks>
/// <para>
/// Two commands for the same gesture, and which one runs is how many cards were picked up. One host is
/// <c>MoveHostToGroup</c>, which has always been what a drag does and which keeps that host selected. A
/// set goes through <c>FileChosenHostsUnder</c>, which makes the refusals once rather than per host —
/// a group belongs to one vault — and reports a count rather than forty status lines in a row.
/// </para>
/// <para>
/// Fire-and-forget, like every other command this control runs: the move writes to the vault and reports
/// itself onto the status line, and a drop handler that awaited it would be an event handler returning a
/// task nothing observes.
/// </para>
/// </remarks>
private void OnDrop(object? sender, DragEventArgs e)
{
e.Handled = true;
Unmark();
if (Vault is not { } vault || Target(e) is not { } target)
{
e.DragEffects = DragDropEffects.None;
return;
}
e.DragEffects = DragDropEffects.Move;
if (target.Hosts.Count > 1)
{
vault.FileChosenHostsUnderCommand.Execute(target.Group);
return;
}
vault.MoveHostToGroupCommand.Execute(new HostGroupMove(target.Hosts[0], target.Group.EntityId));
}
/// <summary>
/// Where a drag currently is, or null if it is over nothing that would take it.
/// </summary>
/// <remarks>
/// <para>
/// One kind of target: a group card. It is the control that already answers "which group", it is drawn
/// at the top of the screen where a drag can reach it from anywhere in the grid, and what it does when
/// dropped on is what it says on it. The space around the cards takes nothing.
/// </para>
/// <para>
/// A group the vault no longer has is read as no group at all, which is what the list already does with
/// a dangling reference — see <c>VaultViewModel.RebuildSidebarRows</c>. That is decided in the command
/// rather than here, so the rule has one home.
/// </para>
/// </remarks>
private static DropTarget? Target(DragEventArgs e)
{
if (e.DataTransfer.TryGetValue(HostFormat) is not { Count: > 0 } dragged
|| Container(e.Source) is not { DataContext: HostGroupRowViewModel group } container
|| dragged.All(row => row.Host.GroupId == group.EntityId))
{
return null;
}
return new DropTarget(dragged, group, container);
}
private void Mark(ListBoxItem container)
{
if (ReferenceEquals(marked, container))
{
return;
}
Unmark();
marked = container;
marked.Classes.Add("droptarget");
}
private void Unmark()
{
marked?.Classes.Remove("droptarget");
marked = null;
}
/// <summary>Lets go of a press that turned out not to be a drag, or has become one.</summary>
private void Forget()
{
press = null;
pickedUp = [];
collapse = null;
}
/// <summary>The view model of the grid item an event happened on, if it happened on one.</summary>
private static object? RowUnder(object? source) => Container(source)?.DataContext;
/// <summary>The view model of the grid item an event happened on, if it happened on a host card.</summary>
private static HostRowViewModel? RowUnder(object? source) =>
Container(source)?.DataContext as HostRowViewModel;
/// <remarks>
/// Walks up from whatever was actually hit — a text block, a border, the card's own grid — because that
/// is what an event's source is. Anything not inside an item, which is the space around the cards,
/// yields null.
/// is what an event's source is. Anything not inside a card, which includes a section's own heading and
/// the space around them, yields null.
/// </remarks>
private static ListBoxItem? Container(object? source) => source is Visual visual
? visual.FindAncestorOfType<ListBoxItem>(includeSelf: true)
: null;
/// <summary>A drag in flight, and where it would land.</summary>
/// <remarks>
/// The group is the card rather than its id, which it was while only one host could be dragged: the
/// command that files a set takes the card, because the refusal it makes is about which vault the group
/// is in. The way out of a group is still the host's own editor, which is the one place "no group" can be
/// said in words.
/// </remarks>
private sealed record DropTarget(
IReadOnlyList<HostRowViewModel> Hosts, HostGroupRowViewModel Group, ListBoxItem Container);
}
@@ -0,0 +1,54 @@
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace DodoSSH.Client.App.Views;
/// <summary>
/// Turns a host card's <c>MonogramHue</c> string into the background or foreground brush the mock pairs it
/// with.
/// </summary>
/// <remarks>
/// <para>
/// The four pairs are the design's own and are not in <c>Palette.axaml</c>: that file is another wave's, and
/// none of the shared palette's existing keys is this hue ramp — a monogram's colour is a property of the
/// four-way hash in <c>HostRowViewModel.MonogramHue</c>, not a fact the rest of the theme has any use for.
/// Held here, beside the one screen that reads it, rather than invented as four new shared resources for a
/// single card.
/// </para>
/// <para>
/// Two instances rather than one converter taking a "which half" parameter, so the markup names each with a
/// <c>StaticResource</c>-shaped reference instead of a converter parameter that means nothing without
/// reading this file.
/// </para>
/// </remarks>
internal sealed class MonogramBrushConverter(bool background) : IValueConverter
{
/// <summary>The fill behind the two letters.</summary>
internal static MonogramBrushConverter Background { get; } = new(background: true);
/// <summary>The colour of the two letters themselves.</summary>
internal static MonogramBrushConverter Foreground { get; } = new(background: false);
/// <summary>violet, green, amber, gray — the four pairs the mock assigns a monogram.</summary>
private static readonly Dictionary<string, (string Background, string Foreground)> Pairs = new(
StringComparer.Ordinal)
{
["violet"] = ("#241C4F", "#A78BFA"),
["green"] = ("#103A2F", "#34D399"),
["amber"] = ("#423211", "#F5B942"),
["gray"] = ("#1E1E2C", "#9C9EB4"),
};
/// <inheritdoc />
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var pair = value is string hue && Pairs.TryGetValue(hue, out var found) ? found : Pairs["gray"];
return new SolidColorBrush(Color.Parse(background ? pair.Background : pair.Foreground));
}
/// <inheritdoc />
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException("The monogram hue is read-only.");
}