Files
pipelines/app/lib/shell/tab_history.dart
T
alan 95902e3e49 Make Settings a first-class destination
Keep Settings location, selection, history, and persistence separate from Pipelines so /settings restores and navigates independently. Update focused navigation coverage and defer notification loading to avoid a mid-build Runs-tab update.
2026-11-12 11:12:49 +00:00

44 lines
1.5 KiB
Dart

import 'destination.dart';
/// The destinations the operator left, most recent first, for the system Back.
///
/// Every destination change (a tap, a search result or notification opening
/// another destination) goes through [record]: the destination being left moves
/// to the top and the destination being opened leaves the stack, so each
/// destination appears at most once and the current one is never in it.
/// Settings is a destination of its own, so leaving it returns to whatever was
/// selected before it.
///
/// [takePrevious] steps back: it removes the top destination and returns it, and
/// the next [record] that opens that destination does not push the one being
/// left, so Back never builds a forward trail.
class TabHistory {
final List<AppDestination> _tabs = [];
AppDestination? _returningTo;
/// The left destinations, most recent first.
List<AppDestination> get tabs => List.unmodifiable(_tabs);
bool get isEmpty => _tabs.isEmpty;
/// Notes a change of the shown destination from [from] to [to].
void record(AppDestination from, AppDestination to) {
if (from == to) return;
final returning = _returningTo == to;
_returningTo = null;
_tabs.remove(to);
if (returning) return;
_tabs
..remove(from)
..insert(0, from);
}
/// The destination Back returns to, removed from the stack; null when empty.
AppDestination? takePrevious() {
if (_tabs.isEmpty) return null;
final previous = _tabs.removeAt(0);
_returningTo = previous;
return previous;
}
}