diff --git a/lib/core/iconography.dart b/lib/core/iconography.dart index 7731ef6..0712b9a 100644 --- a/lib/core/iconography.dart +++ b/lib/core/iconography.dart @@ -152,6 +152,10 @@ class KapyIcons { 0xE017, HugeIcons.strokeRoundedMinimizeScreen, ); + static const cloudRounded = KapyIconData( + 0xE0D3, + HugeIcons.strokeRoundedCloud, + ); static const cloudOffRounded = KapyIconData( 0xE018, HugeIcons.strokeRoundedCloudOff, @@ -347,6 +351,10 @@ class KapyIcons { 0xE048, HugeIcons.strokeRoundedUserGroup, ); + static const personAddRounded = KapyIconData( + 0xE0D4, + HugeIcons.strokeRoundedUserAdd01, + ); static const groupOutlined = KapyIconData( 0xE092, HugeIcons.strokeRoundedUserMultiple, @@ -355,6 +363,10 @@ class KapyIcons { 0xE0D0, HugeIcons.strokeRoundedFilterHorizontal, ); + static const layersRounded = KapyIconData( + 0xE0D5, + HugeIcons.strokeRoundedLayers01, + ); static const listViewRounded = KapyIconData( 0xE0D1, HugeIcons.strokeRoundedListView, diff --git a/lib/core/theme.dart b/lib/core/theme.dart index 3d8ac2d..fe85f38 100644 --- a/lib/core/theme.dart +++ b/lib/core/theme.dart @@ -111,6 +111,11 @@ class CalcPalette extends ThemeExtension { final Color cardTitle; final Color accentText; + /// The page's edge, and the slash between a breadcrumb's steps or the dot + /// between a note's dates: fainter than any text that is meant to be read. + final Color pageBorder; + final Color textDivider; + /// How much of the desktop the window's chrome lets through: a multiplier on /// the alpha of every [GlassSurface]. 1 is fully opaque. /// @@ -237,6 +242,8 @@ class CalcPalette extends ThemeExtension { required this.switchTrackOff, required this.cardTitle, required this.accentText, + required this.pageBorder, + required this.textDivider, this.translucency = 1, this.paperTranslucency = 1, }); @@ -301,6 +308,8 @@ class CalcPalette extends ThemeExtension { Color? switchTrackOff, Color? cardTitle, Color? accentText, + Color? pageBorder, + Color? textDivider, double? translucency, double? paperTranslucency, }) => CalcPalette( @@ -362,6 +371,8 @@ class CalcPalette extends ThemeExtension { switchTrackOff: switchTrackOff ?? this.switchTrackOff, cardTitle: cardTitle ?? this.cardTitle, accentText: accentText ?? this.accentText, + pageBorder: pageBorder ?? this.pageBorder, + textDivider: textDivider ?? this.textDivider, translucency: translucency ?? this.translucency, paperTranslucency: paperTranslucency ?? this.paperTranslucency, ); @@ -432,6 +443,8 @@ class CalcPalette extends ThemeExtension { switchTrackOff: mix(switchTrackOff, other.switchTrackOff), cardTitle: mix(cardTitle, other.cardTitle), accentText: mix(accentText, other.accentText), + pageBorder: mix(pageBorder, other.pageBorder), + textDivider: mix(textDivider, other.textDivider), translucency: translucency + (other.translucency - translucency) * t, paperTranslucency: paperTranslucency + (other.paperTranslucency - paperTranslucency) * t, @@ -1015,6 +1028,8 @@ class KapyTheme { switchTrackOff: Color(0xFF3A362F), cardTitle: Color(0xFFD9D3C6), accentText: Color(0xFF9DB384), + pageBorder: Color(0xFF2E2A25), + textDivider: Color(0xFF554F47), ); /// A cool, clean paper palette rather than the previous warm stationery. @@ -1079,6 +1094,8 @@ class KapyTheme { switchTrackOff: Color(0xFFDAD8D2), cardTitle: Color(0xFF2A2620), accentText: Color(0xFF56703C), + pageBorder: Color(0xFFE3E1DC), + textDivider: Color(0xFFB9BBC0), ); /// Transparency mode. diff --git a/lib/ui/context_menu.dart b/lib/ui/context_menu.dart index 188d2c4..411af09 100644 --- a/lib/ui/context_menu.dart +++ b/lib/ui/context_menu.dart @@ -229,3 +229,77 @@ class _KapyContextMenuLayout extends SingleChildLayoutDelegate { preferredBounds != oldDelegate.preferredBounds || mediaPadding != oldDelegate.mediaPadding; } + +/// One line of a note's actions menu, wherever it opens: a note's row in the +/// list, or the page's More button. +class KapyMenuAction { + const KapyMenuAction({ + required this.value, + required this.label, + required this.icon, + this.hint, + this.destructive = false, + this.enabled = true, + }); + + final String value; + final String label; + final KapyIconData icon; + final String? hint; + final bool destructive; + final bool enabled; +} + +/// A [KapyMenuAction] as drawn in a desktop menu or a touch sheet. +class KapyMenuActionRow extends StatelessWidget { + const KapyMenuActionRow(this.action, {super.key, required this.touch}); + + final KapyMenuAction action; + final bool touch; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final foreground = !action.enabled + ? palette.textTertiary + : action.destructive + ? Theme.of(context).colorScheme.error + : palette.textPrimary; + return Row( + children: [ + KapyIcon( + action.icon, + size: touch + ? AppControlMetrics.iconAction + : AppControlMetrics.iconControl, + color: action.destructive || !action.enabled + ? foreground + : palette.textSecondary, + ), + SizedBox(width: touch ? 14 : 10), + Expanded( + child: Text( + action.label, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: touch ? AppTypeScale.body : AppTypeScale.control, + color: foreground, + ), + ), + ), + if (action.hint case final hint?) ...[ + SizedBox(width: touch ? 18 : 10), + Text( + hint, + maxLines: 1, + style: TextStyle( + fontSize: AppTypeScale.control, + color: palette.textTertiary, + ), + ), + ], + ], + ); + } +} diff --git a/lib/ui/home_page.dart b/lib/ui/home_page.dart index c88f830..74fd8a9 100644 --- a/lib/ui/home_page.dart +++ b/lib/ui/home_page.dart @@ -59,10 +59,13 @@ import 'editor_panes.dart'; import 'billing/note_limit_dialog.dart'; import 'billing/pro_sheet.dart'; import 'empty_state.dart'; +import 'context_menu.dart'; import 'hidden_notes_gate.dart'; import 'kapy_header_mascot.dart'; import 'mobile_page_swipe.dart'; import 'notes_list.dart'; +import 'page_card.dart'; +import 'page_toolbar.dart'; import 'sidebar.dart'; import 'settings_dialog.dart'; import 'sidebar_swipe.dart'; @@ -2557,6 +2560,9 @@ class _HomePageState extends State with WidgetsBindingObserver { final space = _space; final listFits = _listFits; final listShown = _listShown; + final pinned = + selected != null && + widget.notes.pinnedNoteIds.contains(selected.id); return Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -2698,32 +2704,41 @@ class _HomePageState extends State with WidgetsBindingObserver { pageInset, pageInset, ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - NoteToolbar( - mascotController: _kapyHeader, - sidebarVisible: listShown, - sidebarShortcut: _sidebarShortcut, - onToggleSidebar: _toggleList, - onCreate: _createNote, - onShare: _shareSelected, - members: _selectedMembers, - present: _selectedPresence, - currentUserId: - widget.account?.sharing?.userId ?? '', - noteShared: selected?.isShared ?? false, - alwaysOnTop: widget.prefs.alwaysOnTop, - onToggleAlwaysOnTop: _pinToggle, - alwaysOnTopShortcut: _pinShortcut, - onSplit: _specialMode || !_workspace.canSplit - ? null - : _splitEditor, - splitTooltip: _splitTooltip, - updates: widget.updates, - ), - Expanded(child: _buildWideWorkspace()), - ], + child: PageCard( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + PageToolbar( + space: space.title, + section: pinned ? 'Pinned' : null, + listVisible: listFits && listShown, + onShowList: _toggleList, + showListShortcut: _sidebarShortcut, + onCreate: _createNote, + newNoteShortcut: widget.shortcuts + .bindingFor(ShortcutAction.newNote) + ?.displayLabel, + noteOpen: selected != null, + syncStatus: widget.account?.sync?.status, + members: _selectedMembers, + present: _selectedPresence, + currentUserId: + widget.account?.sharing?.userId ?? '', + noteShared: selected?.isShared ?? false, + onShare: _shareSelected, + pinned: pinned, + onTogglePin: + selected == null || _specialMode + ? null + : () => _togglePinnedNote(selected.id), + moreActions: _pageActions(selected), + onMore: (action) => + _runPageAction(action, selected), + updates: widget.updates, + ), + Expanded(child: _buildWideWorkspace()), + ], + ), ), ), ], @@ -2739,18 +2754,91 @@ class _HomePageState extends State with WidgetsBindingObserver { ); } - /// The split button's words, which also say why it is grey when it is. - String get _splitTooltip { - if (!_specialMode) { - if (_workspace.paneCount >= EditorWorkspace.maxPanes) { - return 'Up to three notes side by side'; - } - if (_selectedId == null) return 'Choose a note for this pane first'; - } + /// What the page's More menu offers: the window's own actions, then the + /// open note's, in the order and on the terms of that note's menu in the + /// list. + List _pageActions(Note? note) { + final splitBlocker = _specialMode + ? null + : _workspace.paneCount >= EditorWorkspace.maxPanes + ? 'Up to three notes side by side' + : _selectedId == null + ? 'Choose a note for this pane first' + : null; + final canSplit = !_specialMode && _workspace.canSplit; + final mayEdit = note != null && _canEditNote(note); + final removeShortcut = widget.shortcuts + .bindingFor(ShortcutAction.deleteNote) + ?.displayLabel; + final alwaysOnTop = widget.prefs.alwaysOnTop; return [ - 'Split view', - ?widget.shortcuts.bindingFor(ShortcutAction.splitEditor)?.displayLabel, - ].join(' '); + KapyMenuAction( + value: 'split', + label: canSplit ? 'Split view' : splitBlocker ?? 'Split view', + icon: KapyIcons.viewColumnOutlined, + hint: canSplit + ? widget.shortcuts + .bindingFor(ShortcutAction.splitEditor) + ?.displayLabel + : null, + enabled: canSplit, + ), + if (_pinToggle != null) + KapyMenuAction( + value: 'on-top', + label: alwaysOnTop ? 'Stop keeping on top' : 'Keep on top', + icon: KapyIcons.layersRounded, + hint: _pinShortcut, + ), + if (mayEdit && !_specialMode && !note.isShared) + const KapyMenuAction( + value: 'hide', + label: 'Move to Hidden Notes', + icon: hiddenIcon, + ), + if (mayEdit && _archiveMode) + const KapyMenuAction( + value: 'restore', + label: 'Restore note', + icon: restoreIcon, + ), + if (mayEdit && _hiddenMode) + const KapyMenuAction( + value: 'unhide', + label: 'Move to Notes', + icon: unhideIcon, + ), + if (mayEdit) + KapyMenuAction( + value: _specialMode ? 'delete' : 'archive', + label: _specialMode ? 'Delete permanently' : 'Archive note', + icon: _specialMode ? deleteIcon : archiveIcon, + hint: removeShortcut, + destructive: true, + ), + ]; + } + + void _runPageAction(String action, Note? note) { + switch (action) { + case 'split': + _splitEditor(); + case 'on-top': + _pinToggle?.call(); + } + if (note == null) return; + switch (action) { + case 'hide': + unawaited(_hideNote(note.id)); + case 'restore': + _restoreNote(note.id); + case 'unhide': + _unhideNote(note.id); + case 'archive': + _archiveNote(note.id); + case 'delete': + unawaited(_deleteNote(note.id)); + } } Widget _buildWideWorkspace() { @@ -2966,6 +3054,9 @@ class _HomePageState extends State with WidgetsBindingObserver { alwaysOnTop: widget.prefs.alwaysOnTop, onToggleAlwaysOnTop: _pinToggle, alwaysOnTopShortcut: _pinShortcut, + newNoteShortcut: widget.shortcuts + .bindingFor(ShortcutAction.newNote) + ?.displayLabel, updates: widget.updates, ), ), diff --git a/lib/ui/page_card.dart b/lib/ui/page_card.dart new file mode 100644 index 0000000..e51d518 --- /dev/null +++ b/lib/ui/page_card.dart @@ -0,0 +1,49 @@ +import 'package:material_ui/material_ui.dart'; + +import '../core/theme.dart'; + +/// The page the open note is written on: a rounded sheet a step lighter than +/// the window, which clips whatever is on it to its corners. +class PageCard extends StatelessWidget { + const PageCard({super.key, required this.child}); + + final Widget child; + + static const double radius = 20; + static const double borderWidth = 1.5; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + return DecoratedBox( + key: const ValueKey('page-card'), + decoration: BoxDecoration( + color: palette.paperColor, + borderRadius: const BorderRadius.all(Radius.circular(radius)), + border: Border.all(color: palette.pageBorder, width: borderWidth), + boxShadow: const [ + BoxShadow( + color: Color(0x40000000), + offset: Offset(0, 1), + blurRadius: 2, + ), + BoxShadow( + color: Color(0x66000000), + offset: Offset(0, 16), + blurRadius: 32, + spreadRadius: -20, + ), + ], + ), + child: Padding( + padding: const EdgeInsets.all(borderWidth), + child: ClipRRect( + borderRadius: const BorderRadius.all( + Radius.circular(radius - borderWidth), + ), + child: child, + ), + ), + ); + } +} diff --git a/lib/ui/page_toolbar.dart b/lib/ui/page_toolbar.dart new file mode 100644 index 0000000..d376936 --- /dev/null +++ b/lib/ui/page_toolbar.dart @@ -0,0 +1,348 @@ +import 'dart:async'; + +import 'package:material_ui/material_ui.dart'; + +import '../core/platform.dart'; +import '../core/theme.dart'; +import '../data/update_checker.dart'; +import '../sync/presence.dart'; +import '../sync/spaces.dart'; +import '../sync/sync_service.dart' show SyncStatus; +import 'compact_icon_button.dart'; +import 'context_menu.dart'; +import 'member_avatars.dart'; +import 'tonal_button.dart'; +import 'toolbar.dart' show UpdateRestartButton; +import 'window_drag_area.dart'; + +/// The bar across the top of the page: where the open note lives, whether it +/// is saved, and what can be done with it. +/// +/// While the notes list is hidden it also leads with the way back to the +/// list and a new note, which the list's own header offers otherwise. Its +/// empty stretches drag the window. +class PageToolbar extends StatelessWidget { + const PageToolbar({ + super.key, + required this.space, + required this.listVisible, + required this.onShowList, + required this.onCreate, + required this.onMore, + this.section, + this.showListShortcut, + this.newNoteShortcut, + this.noteOpen = false, + this.syncStatus, + this.members = const [], + this.present = const [], + this.currentUserId = '', + this.noteShared = false, + this.onShare, + this.pinned = false, + this.onTogglePin, + this.moreActions = const [], + this.updates, + }); + + /// The breadcrumb: the space the list is showing, then the open note's + /// place in it, such as Pinned. + final String space; + final String? section; + + final bool listVisible; + final VoidCallback onShowList; + final String? showListShortcut; + final VoidCallback onCreate; + final String? newNoteShortcut; + + /// Whether there is a note on the page for Saved to speak for. + final bool noteOpen; + + /// Null without an account, where every note is saved on this device alone. + final SyncStatus? syncStatus; + + final List members; + final List present; + final String currentUserId; + final bool noteShared; + + /// Null greys Share rather than removing it, so the buttons beside it stay + /// put as the selection comes and goes. + final VoidCallback? onShare; + + final bool pinned; + final VoidCallback? onTogglePin; + + /// Everything else the page offers, under More. + final List moreActions; + final ValueChanged onMore; + + /// Offers "Update and restart" once a release has downloaded. Null where + /// the app does not update itself. + final UpdateChecker? updates; + + static const double height = 56; + + /// Narrower than this, Saved steps aside for the breadcrumb. + static const double _savedWidth = 460; + + /// Narrower than this, "Update and restart" shortens to "Update". + static const double _updateLabelWidth = 680; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final actionExtent = AppPlatform.hasPointer + ? 32.0 + : AppControlMetrics.iconButtonExtent; + final showListShortcut = this.showListShortcut; + final newNoteShortcut = this.newNoteShortcut; + final updates = this.updates; + + return SizedBox( + key: const ValueKey('page-toolbar'), + height: AppControlMetrics.scaleBar(context, height), + child: Stack( + children: [ + const Positioned.fill( + child: WindowDragArea(child: SizedBox.expand()), + ), + Padding( + padding: const EdgeInsets.only(left: 24, right: 16), + child: LayoutBuilder( + builder: (context, constraints) => Row( + children: [ + if (!listVisible) ...[ + CompactIconButton( + key: const ValueKey('page-show-list'), + tooltip: ['Show notes', ?showListShortcut].join(' '), + extent: AppControlMetrics.tonalButtonHeight, + radius: 8, + onPressed: onShowList, + icon: KapyIcon( + KapyIcons.menuOpenRounded, + size: AppControlMetrics.iconAction, + strokeWidth: 1.7, + ), + ), + const SizedBox(width: 4), + TonalButton( + key: const ValueKey('page-new-note'), + icon: KapyIcons.addRounded, + tooltip: ['New note', ?newNoteShortcut].join(' '), + onPressed: onCreate, + ), + const SizedBox(width: 10), + SizedBox( + width: 1, + height: 16, + child: ColoredBox(color: palette.controlBorder), + ), + const SizedBox(width: 8), + ], + Expanded( + child: Align( + alignment: Alignment.centerLeft, + child: WindowDragArea( + child: _Breadcrumb(space: space, section: section), + ), + ), + ), + if (members.isNotEmpty) + Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 8, right: 6), + child: MemberAvatars( + members: members, + present: present, + currentUserId: currentUserId, + onPressed: onShare, + ), + ), + ), + if (updates != null) + UpdateRestartButton( + updates: updates, + wide: constraints.maxWidth >= _updateLabelWidth, + ), + if (noteOpen && constraints.maxWidth >= _savedWidth) ...[ + _SaveStatus(syncStatus), + const SizedBox(width: 6), + ], + TonalButton( + key: const ValueKey('page-share'), + tall: true, + icon: KapyIcons.personAddRounded, + label: 'Share', + tooltip: noteShared ? 'Manage sharing' : null, + onPressed: onShare, + ), + const SizedBox(width: 6), + CompactIconButton( + key: const ValueKey('page-pin'), + tooltip: pinned ? 'Unpin note' : 'Pin note', + extent: actionExtent, + radius: 10, + foregroundColor: pinned ? palette.clay : null, + onPressed: onTogglePin, + icon: KapyIcon( + KapyIcons.pinOutlined, + size: AppControlMetrics.iconAction, + strokeWidth: 1.9, + ), + ), + const SizedBox(width: 6), + Builder( + builder: (buttonContext) => CompactIconButton( + key: const ValueKey('page-more'), + tooltip: 'More', + extent: actionExtent, + radius: 10, + onPressed: moreActions.isEmpty + ? null + : () => _showMore(buttonContext), + icon: KapyIcon( + KapyIcons.moreRounded, + size: AppControlMetrics.iconAction, + strokeWidth: 2.2, + ), + ), + ), + ], + ), + ), + ), + ], + ), + ); + } + + /// Opens under More, its right edge on the button's. + void _showMore(BuildContext context) { + final box = context.findRenderObject() as RenderBox?; + if (box == null) return; + unawaited( + showKapyContextMenu( + context: context, + globalPosition: box.localToGlobal( + Offset(box.size.width, box.size.height + 4), + ), + items: [ + for (final action in moreActions) + PopupMenuItem( + key: ValueKey('page-more-${action.value}'), + value: action.value, + enabled: action.enabled, + height: 36, + child: KapyMenuActionRow(action, touch: false), + ), + ], + ).then((choice) { + if (choice != null) onMore(choice); + }), + ); + } +} + +class _Breadcrumb extends StatelessWidget { + const _Breadcrumb({required this.space, required this.section}); + + final String space; + final String? section; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final style = TextStyle( + fontSize: AppTypeScale.control, + height: 16 / 13, + color: palette.textTertiary, + ); + final section = this.section; + return Row( + key: const ValueKey('page-breadcrumb'), + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: Text( + space, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: style.copyWith(fontWeight: FontWeight.w500), + ), + ), + if (section != null) ...[ + const SizedBox(width: 8), + ExcludeSemantics( + child: Text('/', style: style.copyWith(color: palette.textDivider)), + ), + const SizedBox(width: 8), + Flexible( + child: Text( + section, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: style.copyWith( + fontWeight: FontWeight.w600, + color: palette.textSecondary, + ), + ), + ), + ], + ], + ); + } +} + +/// Saved, or what is keeping the note from being saved everywhere yet. +/// +/// Every keystroke is written to this device as it is typed, so a note on +/// the page is always saved here; with an account it says whether the other +/// devices have it too. +class _SaveStatus extends StatelessWidget { + const _SaveStatus(this.status); + + final SyncStatus? status; + + @override + Widget build(BuildContext context) { + final palette = context.palette; + final (icon, label, tooltip) = switch (status) { + SyncStatus.syncing => (KapyIcons.cloudRounded, 'Syncing', null), + SyncStatus.offline => ( + KapyIcons.cloudOffRounded, + 'Offline', + 'Saved on this device. It syncs once you are back online.', + ), + _ => (KapyIcons.cloudRounded, 'Saved', null), + }; + final row = Padding( + key: const ValueKey('page-saved'), + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + KapyIcon( + icon, + size: 15, + strokeWidth: 1.8, + color: palette.textTertiary, + ), + const SizedBox(width: 5), + Text( + label, + maxLines: 1, + style: TextStyle( + fontSize: AppTypeScale.body, + height: 16 / 12.5, + fontWeight: FontWeight.w500, + color: palette.textTertiary, + ), + ), + ], + ), + ); + return tooltip == null ? row : Tooltip(message: tooltip, child: row); + } +} diff --git a/lib/ui/sidebar.dart b/lib/ui/sidebar.dart index 8ae727c..105791d 100644 --- a/lib/ui/sidebar.dart +++ b/lib/ui/sidebar.dart @@ -2643,22 +2643,6 @@ class _SearchShortcutHint extends StatelessWidget { } } -class _NoteActionChoice { - const _NoteActionChoice({ - required this.value, - required this.label, - required this.icon, - this.hint, - this.destructive = false, - }); - - final String value; - final String label; - final KapyIconData icon; - final String? hint; - final bool destructive; -} - /// How a [NoteRow] draws its note: the compact list's row, or the desktop /// list's row or sticky card beside the spaces rail. enum NoteRowStyle { compact, row, card } @@ -2784,7 +2768,7 @@ class _NoteRowState extends State { widget.onTap(); } - List<_NoteActionChoice> _availableActions() { + List _availableActions() { // Named only where there is a keyboard to press it on: this same menu // opens on a long press on a phone, and a chord nobody there can type is // a line of noise beside the thing they came to tap. @@ -2793,32 +2777,32 @@ class _NoteRowState extends State { : null; return [ if (_canOpenToSide) - _NoteActionChoice( + KapyMenuAction( value: 'open-side', label: 'Open to the side', icon: KapyIcons.viewColumnOutlined, hint: AppPlatform.isMacOS ? 'Option + Click' : 'Alt + Click', ), if (widget.onTogglePin != null) - _NoteActionChoice( + KapyMenuAction( value: 'pin', label: widget.pinned ? 'Unpin note' : 'Pin note', icon: widget.pinned ? KapyIcons.pinRounded : KapyIcons.pinOutlined, ), if (widget.onShare != null) - _NoteActionChoice( + KapyMenuAction( value: 'share', label: widget.shared ? 'Manage sharing' : 'Share note', icon: KapyIcons.peopleOutlined, ), if (widget.onHide != null) - const _NoteActionChoice( + const KapyMenuAction( value: 'hide', label: 'Move to Hidden Notes', icon: hiddenIcon, ), if (widget.onDelete != null) - _NoteActionChoice( + KapyMenuAction( value: 'delete', label: 'Delete permanently', icon: deleteIcon, @@ -2826,13 +2810,13 @@ class _NoteRowState extends State { destructive: true, ), if (widget.onRestore != null) - const _NoteActionChoice( + const KapyMenuAction( value: 'restore', label: 'Restore note', icon: restoreIcon, ), if (widget.onUnhide != null) - const _NoteActionChoice( + const KapyMenuAction( value: 'unhide', label: 'Move to Notes', icon: unhideIcon, @@ -2841,7 +2825,7 @@ class _NoteRowState extends State { // keep it last, after the protected-folder alternative, and use the // same warning colour as the permanent action in Archived Notes. if (widget.onArchive != null) - _NoteActionChoice( + KapyMenuAction( value: 'archive', label: 'Archive note', icon: archiveIcon, @@ -2853,54 +2837,9 @@ class _NoteRowState extends State { String _actionKey(String value) => '$value-note-${widget.note.id}'; - Widget _actionContents( - BuildContext context, - _NoteActionChoice action, { - required bool touch, - }) { - final palette = context.palette; - final foreground = action.destructive - ? Theme.of(context).colorScheme.error - : palette.textPrimary; - return Row( - children: [ - KapyIcon( - action.icon, - size: touch - ? AppControlMetrics.iconAction - : AppControlMetrics.iconControl, - color: action.destructive ? foreground : palette.textSecondary, - ), - SizedBox(width: touch ? 14 : 10), - Expanded( - child: Text( - action.label, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: touch ? AppTypeScale.body : AppTypeScale.control, - color: foreground, - ), - ), - ), - if (action.hint case final hint?) ...[ - SizedBox(width: touch ? 18 : 10), - Text( - hint, - maxLines: 1, - style: TextStyle( - fontSize: AppTypeScale.control, - color: palette.textTertiary, - ), - ), - ], - ], - ); - } - Future _showTouchActions( BuildContext context, - List<_NoteActionChoice> actions, + List actions, ) => showModalBottomSheet( context: context, isScrollControlled: true, @@ -2954,11 +2893,7 @@ class _NoteRowState extends State { horizontal: 20, vertical: 14, ), - child: _actionContents( - sheetContext, - action, - touch: true, - ), + child: KapyMenuActionRow(action, touch: true), ), ), ], @@ -2983,9 +2918,10 @@ class _NoteRowState extends State { // to the whole list rather than to the note it belongs to. final row = (widget.style == NoteRowStyle.compact - ? this.context - : Scrollable.maybeOf(this.context)?.context ?? this.context) - .findRenderObject() + ? this.context + : Scrollable.maybeOf(this.context)?.context ?? + this.context) + .findRenderObject() as RenderBox?; final rowOrigin = row?.localToGlobal(Offset.zero); final preferredBounds = row == null || rowOrigin == null @@ -3006,7 +2942,7 @@ class _NoteRowState extends State { key: ValueKey(_actionKey(action.value)), value: action.value, height: 36, - child: _actionContents(context, action, touch: false), + child: KapyMenuActionRow(action, touch: false), ), ], ); diff --git a/lib/ui/tonal_button.dart b/lib/ui/tonal_button.dart index 0b3892e..be7dad0 100644 --- a/lib/ui/tonal_button.dart +++ b/lib/ui/tonal_button.dart @@ -1,5 +1,6 @@ import 'package:material_ui/material_ui.dart'; +import '../core/platform.dart'; import '../core/theme.dart'; import 'keycap.dart'; @@ -18,6 +19,7 @@ class TonalButton extends StatelessWidget { this.label, this.shortcut, this.tooltip, + this.tall = false, }) : assert(icon != null || label != null), assert( label != null || tooltip != null, @@ -34,24 +36,43 @@ class TonalButton extends StatelessWidget { final String? tooltip; + /// The page toolbar's Share: two points taller, with rounder corners and a + /// finer icon than the notes list's New note. + final bool tall; + @override Widget build(BuildContext context) { final palette = context.palette; final icon = this.icon; final label = this.label; final shortcut = this.shortcut; + final pointer = AppPlatform.hasPointer; + final fine = pointer && (tall || label == null); final button = FilledButton( onPressed: onPressed, style: ButtonStyle( minimumSize: WidgetStatePropertyAll( - Size.square(AppControlMetrics.tonalButtonHeight), + Size.square( + tall && pointer ? 32 : AppControlMetrics.tonalButtonHeight, + ), ), + shape: tall + ? const WidgetStatePropertyAll( + RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10)), + ), + ) + : null, padding: WidgetStatePropertyAll( label == null ? EdgeInsets.zero : EdgeInsetsDirectional.only( - start: icon == null ? 12 : 9, + start: icon == null + ? 12 + : tall + ? 10 + : 9, end: shortcut == null ? 12 : 6, ), ), @@ -78,8 +99,8 @@ class TonalButton extends StatelessWidget { if (icon != null) KapyIcon( icon, - size: AppControlMetrics.iconControl, - strokeWidth: 2.2, + size: fine ? 15 : AppControlMetrics.iconControl, + strokeWidth: fine ? 2 : 2.2, ), if (icon != null && label != null) const SizedBox(width: 6), if (label != null) Text(label), diff --git a/lib/ui/toolbar.dart b/lib/ui/toolbar.dart index a439371..34dbacf 100644 --- a/lib/ui/toolbar.dart +++ b/lib/ui/toolbar.dart @@ -3,7 +3,6 @@ import 'dart:math' as math; import 'package:material_ui/material_ui.dart'; -import '../core/platform.dart'; import '../core/theme.dart'; import '../core/toast.dart'; import '../data/update_checker.dart'; @@ -11,7 +10,6 @@ import '../sync/presence.dart'; import '../sync/spaces.dart'; import 'app_logo.dart'; import 'compact_icon_button.dart'; -import 'editor_panes.dart'; import 'glass_surface.dart'; import 'kapy_header_mascot.dart'; import 'member_avatars.dart'; @@ -35,8 +33,7 @@ class NoteToolbar extends StatelessWidget { this.alwaysOnTop = false, this.onToggleAlwaysOnTop, this.alwaysOnTopShortcut, - this.onSplit, - this.splitTooltip, + this.newNoteShortcut, this.mascotController, this.members = const [], this.present = const [], @@ -76,15 +73,8 @@ class NoteToolbar extends StatelessWidget { /// preferences rather than written here, because the binding is editable. final String? alwaysOnTopShortcut; - /// Opens a pane beside the open note. Null greys the button out rather than - /// removing it: once three notes are side by side, while the focused pane is - /// still empty, and in the archive. - final VoidCallback? onSplit; - - /// What the split button says, which is also why it is grey when it is. - /// Null leaves the button out altogether where there is only ever one note - /// on screen, which is a phone. - final String? splitTooltip; + /// The current chord for a new note, taught by the + button's tooltip. + final String? newNoteShortcut; /// Drives the optional animated mark without changing toolbar geometry. final KapyHeaderController? mascotController; @@ -296,15 +286,14 @@ class NoteToolbar extends StatelessWidget { } Widget _trailing({required bool wide}) { - final splitTooltip = this.splitTooltip; final updates = this.updates; return Row( mainAxisSize: MainAxisSize.min, children: [ - if (updates != null) _UpdateButton(updates: updates, wide: wide), + if (updates != null) UpdateRestartButton(updates: updates, wide: wide), _ToolbarButton( icon: KapyIcons.addRounded, - tooltip: AppPlatform.isMacOS ? 'New note ⌘N' : 'New note Ctrl+N', + tooltip: ['New note', ?newNoteShortcut].join(' '), onPressed: onCreate, ), const SizedBox(width: 2), @@ -313,15 +302,6 @@ class NoteToolbar extends StatelessWidget { tooltip: noteShared ? 'Sharing' : 'Share note', onPressed: onShare, ), - if (splitTooltip != null) ...[ - const SizedBox(width: 2), - _ToolbarButton( - key: const ValueKey('toolbar-split-view'), - glyph: SplitViewIcon(size: AppControlMetrics.iconAction), - tooltip: splitTooltip, - onPressed: onSplit, - ), - ], ], ); } @@ -345,8 +325,12 @@ class NoteToolbar extends StatelessWidget { /// list opened. Draws nothing at all until there is something to install, /// and listens to the checker itself, so a download counting up its percent /// rebuilds this and not the page under it. -class _UpdateButton extends StatelessWidget { - const _UpdateButton({required this.updates, required this.wide}); +class UpdateRestartButton extends StatelessWidget { + const UpdateRestartButton({ + super.key, + required this.updates, + required this.wide, + }); final UpdateChecker updates; final bool wide; @@ -419,17 +403,13 @@ class _UpdateButton extends StatelessWidget { class _ToolbarButton extends StatelessWidget { const _ToolbarButton({ super.key, - this.icon, - this.glyph, + required this.icon, required this.tooltip, required this.onPressed, this.selected = false, - }) : assert((icon == null) != (glyph == null)); - - final KapyIconData? icon; + }); - /// A drawn icon, for an action the icon font has nothing clear for. - final Widget? glyph; + final KapyIconData icon; final String tooltip; /// Null greys the action out rather than removing it. @@ -448,7 +428,7 @@ class _ToolbarButton extends StatelessWidget { : selected ? palette.textPrimary : palette.textSecondary, - icon: glyph ?? KapyIcon(icon!, size: AppControlMetrics.iconAction), + icon: KapyIcon(icon, size: AppControlMetrics.iconAction), ); } } diff --git a/test/app_test.dart b/test/app_test.dart index 45f832e..ebe056a 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -42,6 +42,8 @@ import 'package:kapy_notes/ui/notes_list.dart'; import 'package:kapy_notes/ui/sidebar.dart'; import 'package:kapy_notes/ui/sidebar_swipe.dart'; import 'package:kapy_notes/ui/spaces_rail.dart'; +import 'package:kapy_notes/ui/page_card.dart'; +import 'package:kapy_notes/ui/page_toolbar.dart'; import 'package:kapy_notes/ui/toolbar.dart'; import 'package:kapy_notes/ui/window_drag_area.dart'; @@ -237,6 +239,14 @@ Future hoverNote(WidgetTester tester, String noteId) async { return mouse; } +/// Opens the page's More menu and picks [value] from it. +Future pickPageAction(WidgetTester tester, String value) async { + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(ValueKey('page-more-$value'))); + await tester.pumpAndSettle(); +} + Future openNoteActions(WidgetTester tester, String noteId) async { final mouse = await hoverNote(tester, noteId); await tester.tap(find.byKey(ValueKey('note-actions-$noteId'))); @@ -377,7 +387,7 @@ void main() { await pumpApp(tester); expect(find.byType(EmptyState), findsOneWidget); - expect(find.byKey(const ValueKey('toolbar-app-wordmark')), findsOneWidget); + expect(find.byType(PageToolbar), findsOneWidget); expect(find.text('No notes yet'), findsOneWidget); await tester.tap(emptyStateNewNote()); @@ -540,41 +550,38 @@ void main() { expect(notes.notes.single.body, 'Earlier thought'); }); - testWidgets('the pin sits beside the lockup, outside its drag region', ( + testWidgets('the page pins its note, and More keeps the window on top', ( tester, ) async { await pumpApp(tester); + final note = notes.create(body: 'alpha'); + await tester.pumpAndSettle(); + await tester.tap(find.widgetWithText(NoteRow, 'alpha')); await tester.pumpAndSettle(); - final pin = findKapyIcon(KapyIcons.pinOutlined); - final wordmark = find.byKey(const ValueKey('toolbar-app-wordmark')); - expect(pin, findsOneWidget); - - // The lockup is window chrome and drags the window. The pin must not be - // under that: DragToMoveArea recognises double taps, so it holds the - // gesture arena for the timeout and a button beneath it answers late on - // every single click. + // A button, so it answers at once rather than after the drag region's + // double-tap timeout. + final pin = find.byKey(const ValueKey('page-pin')); expect( find.ancestor(of: pin, matching: find.byType(WindowDragArea)), findsNothing, - reason: 'the pin would answer a double-tap timeout late on every click', ); + await tester.tap(pin); + await tester.pumpAndSettle(); + expect(notes.isPinned(note.id), isTrue); expect( - find.ancestor(of: wordmark, matching: find.byType(WindowDragArea)), + find.descendant( + of: find.byKey(const ValueKey('page-breadcrumb')), + matching: find.text('Pinned'), + ), findsOneWidget, - reason: 'the lockup still has to drag the window', ); - // Beside it, and on the trailing side of it. - expect( - tester.getCenter(pin).dx, - greaterThan(tester.getCenter(wordmark).dx), - ); - - await tester.tap(pin); + await pickPageAction(tester, 'on-top'); + expect(prefs.alwaysOnTop, isTrue); + await tester.tap(find.byKey(const ValueKey('page-more'))); await tester.pumpAndSettle(); - expect(findKapyIcon(KapyIcons.pinRounded), findsOneWidget); - expect(findKapyIcon(KapyIcons.pinOutlined), findsNothing); + expect(find.text('Stop keeping on top'), findsOneWidget); }); testWidgets('a first run opens on a page, with the notes list closed', ( @@ -593,7 +600,7 @@ void main() { expect(notesToggleWithLabel('Show notes'), findsOneWidget); expect( find.descendant( - of: find.byType(NoteToolbar), + of: find.byType(PageToolbar), matching: notesToggleWithLabel('Hide notes'), ), findsNothing, @@ -606,10 +613,6 @@ void main() { AppPlatform.debugTargetPlatformOverride = TargetPlatform.windows; addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); - Finder toolbarIcon(KapyIconData icon) => find.descendant( - of: find.byType(NoteToolbar), - matching: findKapyIcon(icon), - ); final barrier = find.byKey(const ValueKey('sidebar-overlay-barrier')); await pumpApp(tester, size: const Size(620, 620), sidebarVisible: false); @@ -626,7 +629,7 @@ void main() { expect(prefs.sidebarVisible, isTrue); expect( tester.getRect(find.byType(Sidebar)).right, - lessThanOrEqualTo(tester.getRect(find.byType(NoteToolbar)).left), + lessThanOrEqualTo(tester.getRect(find.byType(PageCard)).left), ); // Narrowed again, the window folds it away and keeps every action. @@ -634,9 +637,9 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(Sidebar), findsNothing); expect(barrier, findsNothing); - expect(toolbarIcon(KapyIcons.menuRounded), findsOneWidget); - expect(toolbarIcon(KapyIcons.addRounded), findsOneWidget); - expect(toolbarIcon(KapyIcons.peopleOutlined), findsOneWidget); + for (final key in ['page-show-list', 'page-new-note', 'page-share']) { + expect(find.byKey(ValueKey(key)), findsOneWidget); + } tester.view.physicalSize = const Size(760, 620); await tester.pumpAndSettle(); @@ -646,7 +649,7 @@ void main() { ); testWidgets( - 'the pin survives every desktop width, and never reaches a phone', + 'Keep on top survives every desktop width, and never reaches a phone', (tester) async { // The bug this replaces: the compact toolbar is a second call site, and // it was reached by a narrow desktop window as well as by a phone. The @@ -657,24 +660,17 @@ void main() { LayoutPrefs.minimumWindowSize, ]) { await pumpApp(tester, size: size); + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); expect( - findKapyIcon(KapyIcons.pinOutlined), + find.byKey(const ValueKey('page-more-on-top')), findsOneWidget, - reason: 'the pin went missing at $size', + reason: 'Keep on top went missing at $size', ); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); } - // The list opened over a narrow window's page leaves the toolbar, and - // the pin on it, where they were. - await pumpApp(tester, size: const Size(700, 620)); - await tester.tap(notesToggleWithLabel('Show notes')); - await tester.pumpAndSettle(); - expect( - findKapyIcon(KapyIcons.pinOutlined), - findsOneWidget, - reason: 'the pin went under the list', - ); - // A phone has no window to float, so the control is absent rather than // present and inert. AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; @@ -688,31 +684,8 @@ void main() { testWidgets('keeps exchange-rate status out of the toolbar', (tester) async { await pumpApp(tester); - final toolbar = find.byType(NoteToolbar); - final wordmark = find.byKey(const ValueKey('toolbar-app-wordmark')); - final add = find - .descendant(of: toolbar, matching: findKapyIcon(KapyIcons.addRounded)) - .first; - final menu = findKapyIcon(KapyIcons.menuRounded); - - expect(toolbar, findsOneWidget); + expect(find.byType(PageToolbar), findsOneWidget); expect(find.textContaining('Rates'), findsNothing); - expect( - find.descendant(of: toolbar, matching: find.text(AppWordmark.name)), - findsOneWidget, - ); - expect( - tester.getCenter(wordmark).dx, - closeTo(tester.getCenter(toolbar).dx, 0.5), - ); - expect(tester.getCenter(menu).dx, lessThan(tester.getCenter(add).dx)); - expect( - find.descendant( - of: toolbar, - matching: findKapyIcon(KapyIcons.moreRounded), - ), - findsNothing, - ); }); testWidgets('uses compact toolbar and roomier footer surfaces on desktop', ( @@ -722,22 +695,19 @@ void main() { notes.create(); await tester.pumpAndSettle(); - final toolbar = find.byType(NoteToolbar); - Finder toolbarButton(KapyIconData icon) => find - .ancestor( - of: find.descendant(of: toolbar, matching: findKapyIcon(icon)), - matching: find.byType(IconButton), - ) - .first; - + Finder pageButton(String key, Type type) => find.descendant( + of: find.byKey(ValueKey(key)), + matching: find.byType(type), + ); expect( - tester.getSize(toolbarButton(KapyIcons.addRounded)), - const Size.square(24), + tester.getSize(pageButton('page-pin', IconButton)), + const Size.square(32), ); expect( - tester.getSize(toolbarButton(KapyIcons.menuRounded)), - const Size.square(24), + tester.getSize(pageButton('page-more', IconButton)), + const Size.square(32), ); + expect(tester.getSize(pageButton('page-share', FilledButton)).height, 32); final footerBold = find.descendant( of: find.byKey(const ValueKey('format-bold')), matching: find.byType(IconButton), @@ -828,12 +798,11 @@ void main() { expect(find.widgetWithText(NoteRow, 'Weekend budget'), findsOneWidget); expect( find.descendant( - of: find.byType(NoteToolbar), + of: find.byType(PageToolbar), matching: find.text('Weekend budget'), ), findsNothing, ); - expect(find.byKey(const ValueKey('toolbar-app-wordmark')), findsOneWidget); }); testWidgets('opens footer settings and resets desktop panel widths', ( @@ -1593,30 +1562,19 @@ void main() { expect(recorded.shift, isTrue); }); - testWidgets('the pin icon answers the click on a narrow window', ( + testWidgets('Keep on top answers from More in a narrow window', ( tester, ) async { - // The default window is 600 wide, under the two-pane breakpoint, so this - // is the layout a fresh install actually opens in — and the one where the - // toolbar was reading a preference nothing was listening to. + // The size a fresh install opens at. await pumpApp(tester, size: LayoutPrefs.defaultWindowSize); notes.create(body: 'alpha'); await tester.pumpAndSettle(); - expect(findKapyIcon(KapyIcons.pinOutlined), findsOneWidget); - - await tester.tap(findKapyIcon(KapyIcons.pinOutlined)); - await tester.pumpAndSettle(); - // The window really did go on top; the icon has to say so in the same - // frame, without waiting for something else to redraw the page. + await pickPageAction(tester, 'on-top'); expect(prefs.alwaysOnTop, isTrue); - expect(findKapyIcon(KapyIcons.pinRounded), findsOneWidget); - - await tester.tap(findKapyIcon(KapyIcons.pinRounded)); - await tester.pumpAndSettle(); + await pickPageAction(tester, 'on-top'); expect(prefs.alwaysOnTop, isFalse); - expect(findKapyIcon(KapyIcons.pinOutlined), findsOneWidget); }); testWidgets('rebinding a shortcut updates the hints already on screen', ( @@ -1665,9 +1623,17 @@ void main() { expect(find.byTooltip('Bold · Cmd + Shift + K'), findsOneWidget); - // The toolbar spells its pin shortcut out too, from the same source. + // More spells out Keep on top's shortcut too, from the same source. + Finder onTopHint(String label) => find.descendant( + of: find.byKey(const ValueKey('page-more-on-top')), + matching: find.text(label), + ); final pin = shortcuts.bindingFor(ShortcutAction.toggleAlwaysOnTop)!; - expect(find.byTooltip('Keep on top ${pin.displayLabel}'), findsOneWidget); + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); + expect(onTopHint(pin.displayLabel), findsOneWidget); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); shortcuts.update( ShortcutAction.toggleAlwaysOnTop, @@ -1680,7 +1646,9 @@ void main() { ); await tester.pumpAndSettle(); - expect(find.byTooltip('Keep on top Cmd + Shift + J'), findsOneWidget); + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); + expect(onTopHint('Cmd + Shift + J'), findsOneWidget); }); testWidgets('a shortcut can be removed, and then answers nothing', ( @@ -1966,8 +1934,7 @@ void main() { await tester.tap(find.widgetWithText(NoteRow, 'Alpha')); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const ValueKey('toolbar-split-view'))); - await tester.pumpAndSettle(); + await pickPageAction(tester, 'split'); await tester.tap(find.widgetWithText(NoteRow, 'Bravo')); await tester.pumpAndSettle(); await tester.tap(find.byKey(const ValueKey('pane-title-0'))); @@ -2058,17 +2025,20 @@ void main() { expect(find.byType(EditorPaneFrame), findsOneWidget); expect(find.byKey(const ValueKey('pane-title-0')), findsNothing); - // The title bar's split button opens an empty pane beside the note, and + // More's Split view opens an empty pane beside the note, and // the list fills whichever pane has the focus: the new one. - await tester.tap(find.byKey(const ValueKey('toolbar-split-view'))); - await tester.pumpAndSettle(); + await pickPageAction(tester, 'split'); expect(find.byType(EditorPaneFrame), findsNWidgets(2)); expect(find.text('Choose a note'), findsOneWidget); + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); expect( - find.byTooltip('Choose a note for this pane first'), + find.text('Choose a note for this pane first'), findsOneWidget, reason: 'no second blank beside the first', ); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); await tester.tap(find.widgetWithText(NoteRow, 'Third note')); await tester.pumpAndSettle(); @@ -2156,7 +2126,19 @@ void main() { // Three is as many as there are. await press(ShortcutAction.splitEditor); expect(find.byType(EditorPaneFrame), findsNWidgets(3)); - expect(find.byTooltip('Up to three notes side by side'), findsOneWidget); + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); + expect( + tester + .widget>( + find.byKey(const ValueKey('page-more-split')), + ) + .enabled, + isFalse, + ); + expect(find.text('Up to three notes side by side'), findsOneWidget); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); await press(ShortcutAction.focusSecondPane); expect(fieldInPane(tester, 1).focusNode!.hasFocus, isTrue); @@ -2381,14 +2363,18 @@ void main() { expect(prefs.sidebarVisible, isTrue); }); - testWidgets('the hamburger tooltip includes its current shortcut', ( + testWidgets('the show-list tooltip includes its current shortcut', ( tester, ) async { - await pumpApp(tester); + await pumpApp(tester, sidebarVisible: false); - final menu = findKapyIcon(KapyIcons.menuRounded).first; final tooltip = tester.widget( - find.ancestor(of: menu, matching: find.byType(Tooltip)).first, + find + .descendant( + of: find.byKey(const ValueKey('page-show-list')), + matching: find.byType(Tooltip), + ) + .first, ); expect( tooltip.message, @@ -2805,12 +2791,12 @@ void main() { }); testWidgets('the toolbar plus answers the same way', (tester) async { - await pumpApp(tester); - await tester.tap(find.byTooltip('New note ⌘N')); + await pumpApp(tester, sidebarVisible: false); + await tester.tap(find.byKey(const ValueKey('page-new-note'))); await tester.pumpAndSettle(); final made = notes.notes.length; - await tester.tap(find.byTooltip('New note ⌘N')); + await tester.tap(find.byKey(const ValueKey('page-new-note'))); await tester.pumpAndSettle(); expect(notes.notes, hasLength(made)); }); @@ -2989,7 +2975,10 @@ void main() { .widgetList(find.byType(NoteRow)) .map((row) => row.note.title) .toList(); - expect(find.text('Pinned'), findsOneWidget); + expect( + find.descendant(of: find.byType(Sidebar), matching: find.text('Pinned')), + findsOneWidget, + ); expect( find.descendant(of: find.byType(Sidebar), matching: find.text('Notes')), findsOneWidget, @@ -3231,7 +3220,7 @@ void main() { notes.create(body: 'Trip plan'); await pumpApp(tester, account: account); - await tester.tap(find.byTooltip('Share note').first); + await tester.tap(find.byKey(const ValueKey('page-share'))); await tester.pumpAndSettle(); // Not the share sheet, which would have nothing to share with, and not @@ -4876,7 +4865,7 @@ void main() { // The page moves up to the rail, with the canvas's margin on that side // too now that no list sits against it. expect( - tester.getRect(find.byType(NoteToolbar)).left, + tester.getRect(find.byType(PageCard)).left, tester.getRect(find.byType(SpacesRail)).right + 12, ); @@ -4884,7 +4873,7 @@ void main() { await tester.pumpAndSettle(); expect(prefs.sidebarVisible, isTrue); expect( - tester.getRect(find.byType(NoteToolbar)).left, + tester.getRect(find.byType(PageCard)).left, tester.getRect(find.byType(Sidebar)).right, ); }); @@ -4975,7 +4964,7 @@ void main() { // One way in: the page's toolbar no longer carries a second gear. expect( find.descendant( - of: find.byType(NoteToolbar), + of: find.byType(PageToolbar), matching: findKapyIcon(KapyIcons.settingsOutlined), ), findsNothing, @@ -5111,7 +5100,7 @@ void main() { // The page stands a margin in from the rail, as in Paper's window with // the list hidden. expect( - tester.getRect(find.byType(NoteToolbar)).left, + tester.getRect(find.byType(PageCard)).left, tester.getRect(find.byType(SpacesRail)).right + 12, ); }); @@ -5123,7 +5112,7 @@ void main() { notes.create(body: 'First note'); notes.create(body: 'Second note'); await pumpApp(tester, size: const Size(600, 720)); - final page = tester.getRect(find.byType(NoteToolbar)); + final page = tester.getRect(find.byType(PageCard)); Future open() async { await tester.tap(notesToggleWithLabel('Show notes')); @@ -5134,7 +5123,7 @@ void main() { // Over the page, which keeps its place and its width. await open(); - expect(tester.getRect(find.byType(NoteToolbar)), page); + expect(tester.getRect(find.byType(PageCard)), page); // A click on the page beside it. await tester.tapAt(Offset(page.right - 8, page.center.dy)); @@ -5207,11 +5196,6 @@ void main() { await tester.pumpAndSettle(); final rail = tester.getRect(find.byType(SpacesRail)); - final toolbar = find.byType(NoteToolbar); - final menu = find.descendant( - of: toolbar, - matching: notesToggleWithLabel('Hide notes'), - ); // The rail runs down the window's left edge, and its spaces start below // the strip the traffic lights are drawn in, which it keeps clear. @@ -5220,20 +5204,19 @@ void main() { tester.getRect(find.byKey(const ValueKey('rail-notes'))).top, greaterThanOrEqualTo(WindowChrome.trafficLightsHeight), ); - // Everything else starts beside it, so the page's toolbar no longer - // steps aside for controls that are not over it. + // Everything else starts beside it, so the page's toolbar never steps + // aside for controls that are not over it. expect(tester.getRect(find.byType(Sidebar)).left, rail.right); - expect(tester.getRect(toolbar).left, greaterThanOrEqualTo(rail.right)); expect( - tester.getTopLeft(menu).dx - tester.getTopLeft(toolbar).dx, - lessThan(WindowChrome.trafficLightsWidth), + tester.getRect(find.byType(PageCard)).left, + greaterThanOrEqualTo(rail.right), ); prefs.toggleSidebar(); await tester.pumpAndSettle(); expect( - tester.getTopLeft(toolbar).dx, + tester.getTopLeft(find.byKey(const ValueKey('page-show-list'))).dx, greaterThanOrEqualTo(WindowChrome.trafficLightsWidth), ); expect(notesToggleWithLabel('Show notes'), findsOneWidget); @@ -5258,9 +5241,9 @@ void main() { greaterThanOrEqualTo(bar.bottom), ); // The page stands on the canvas, a margin in from the window's edges. - final toolbar = tester.getRect(find.byType(NoteToolbar)); - expect(toolbar.top, 12); - expect(toolbar.right, 1100 - 12); + final page = tester.getRect(find.byType(PageCard)); + expect(page.top, 12); + expect(page.right, 1100 - 12); }, skip: !WindowChrome.overlaysContent); testWidgets('keeps every pane inside the display safe area', ( @@ -5290,11 +5273,7 @@ void main() { tester.getRect(find.byType(SidebarWindowBar)).top, greaterThanOrEqualTo(safeTop), ); - expect(tester.getTopLeft(find.byType(NoteToolbar)).dy, safeTop + 12); - expect( - tester.getTopLeft(find.text(AppWordmark.name)).dy, - greaterThanOrEqualTo(safeTop), - ); + expect(tester.getTopLeft(find.byType(PageCard)).dy, safeTop + 12); expect( tester.getTopLeft(findKapyIcon(KapyIcons.addRounded).last).dy, greaterThanOrEqualTo(safeTop), @@ -5319,7 +5298,7 @@ void main() { // The page itself runs down to the canvas's margin, and its footer holds // the controls above the indicator rather than the page stopping short // over a band of canvas. - expect(tester.getRect(find.byType(NoteFooter)).bottom, size.height - 12); + expect(tester.getRect(find.byType(PageCard)).bottom, size.height - 12); }); testWidgets('lifts the two-pane layout clear of a software keyboard', ( diff --git a/test/golden_test.dart b/test/golden_test.dart index 4666c87..eafb4bc 100644 --- a/test/golden_test.dart +++ b/test/golden_test.dart @@ -654,7 +654,7 @@ void main() { addTearDown(mouse.removePointer); await mouse.addPointer(location: Offset.zero); await mouse.moveTo( - tester.getCenter(find.byKey(const ValueKey('toolbar-notes-toggle'))), + tester.getCenter(find.byKey(const ValueKey('page-more'))), ); await tester.pumpAndSettle(); diff --git a/test/goldens/desktop_dark.png b/test/goldens/desktop_dark.png index f2d0b3f..539dde9 100644 Binary files a/test/goldens/desktop_dark.png and b/test/goldens/desktop_dark.png differ diff --git a/test/goldens/desktop_dark_archive.png b/test/goldens/desktop_dark_archive.png index 230101f..427d137 100644 Binary files a/test/goldens/desktop_dark_archive.png and b/test/goldens/desktop_dark_archive.png differ diff --git a/test/goldens/desktop_dark_archive_selecting.png b/test/goldens/desktop_dark_archive_selecting.png index 78053b9..8b5dd74 100644 Binary files a/test/goldens/desktop_dark_archive_selecting.png and b/test/goldens/desktop_dark_archive_selecting.png differ diff --git a/test/goldens/desktop_dark_blank_note.png b/test/goldens/desktop_dark_blank_note.png index a7726f0..d8f974a 100644 Binary files a/test/goldens/desktop_dark_blank_note.png and b/test/goldens/desktop_dark_blank_note.png differ diff --git a/test/goldens/desktop_dark_collapsed.png b/test/goldens/desktop_dark_collapsed.png index 4ccfb83..7f90fa4 100644 Binary files a/test/goldens/desktop_dark_collapsed.png and b/test/goldens/desktop_dark_collapsed.png differ diff --git a/test/goldens/desktop_dark_editor_context_menu.png b/test/goldens/desktop_dark_editor_context_menu.png index 27a09f7..100b827 100644 Binary files a/test/goldens/desktop_dark_editor_context_menu.png and b/test/goldens/desktop_dark_editor_context_menu.png differ diff --git a/test/goldens/desktop_dark_empty.png b/test/goldens/desktop_dark_empty.png index 6f4df58..1ecfae0 100644 Binary files a/test/goldens/desktop_dark_empty.png and b/test/goldens/desktop_dark_empty.png differ diff --git a/test/goldens/desktop_dark_header_hover.png b/test/goldens/desktop_dark_header_hover.png index 42be8f4..28122ed 100644 Binary files a/test/goldens/desktop_dark_header_hover.png and b/test/goldens/desktop_dark_header_hover.png differ diff --git a/test/goldens/desktop_dark_hover_surfaces.png b/test/goldens/desktop_dark_hover_surfaces.png index cb4ecbe..f07464b 100644 Binary files a/test/goldens/desktop_dark_hover_surfaces.png and b/test/goldens/desktop_dark_hover_surfaces.png differ diff --git a/test/goldens/desktop_dark_images.png b/test/goldens/desktop_dark_images.png index 652619c..5c5a7a2 100644 Binary files a/test/goldens/desktop_dark_images.png and b/test/goldens/desktop_dark_images.png differ diff --git a/test/goldens/desktop_dark_narrow_list.png b/test/goldens/desktop_dark_narrow_list.png index f506a00..d1ecfa5 100644 Binary files a/test/goldens/desktop_dark_narrow_list.png and b/test/goldens/desktop_dark_narrow_list.png differ diff --git a/test/goldens/desktop_dark_narrow_results_divider_hover.png b/test/goldens/desktop_dark_narrow_results_divider_hover.png index 299342c..a71aa40 100644 Binary files a/test/goldens/desktop_dark_narrow_results_divider_hover.png and b/test/goldens/desktop_dark_narrow_results_divider_hover.png differ diff --git a/test/goldens/desktop_dark_note_actions.png b/test/goldens/desktop_dark_note_actions.png index b2dce09..a0e99fc 100644 Binary files a/test/goldens/desktop_dark_note_actions.png and b/test/goldens/desktop_dark_note_actions.png differ diff --git a/test/goldens/desktop_dark_note_pinned.png b/test/goldens/desktop_dark_note_pinned.png index 66bb9b3..3378963 100644 Binary files a/test/goldens/desktop_dark_note_pinned.png and b/test/goldens/desktop_dark_note_pinned.png differ diff --git a/test/goldens/desktop_dark_pinned.png b/test/goldens/desktop_dark_pinned.png index 76551cb..539dde9 100644 Binary files a/test/goldens/desktop_dark_pinned.png and b/test/goldens/desktop_dark_pinned.png differ diff --git a/test/goldens/desktop_dark_results_divider_hover.png b/test/goldens/desktop_dark_results_divider_hover.png index 1be27ab..72c4bef 100644 Binary files a/test/goldens/desktop_dark_results_divider_hover.png and b/test/goldens/desktop_dark_results_divider_hover.png differ diff --git a/test/goldens/desktop_dark_results_restore_hover.png b/test/goldens/desktop_dark_results_restore_hover.png index 637b83f..f2f1640 100644 Binary files a/test/goldens/desktop_dark_results_restore_hover.png and b/test/goldens/desktop_dark_results_restore_hover.png differ diff --git a/test/goldens/desktop_dark_settings.png b/test/goldens/desktop_dark_settings.png index 5462045..a677eb3 100644 Binary files a/test/goldens/desktop_dark_settings.png and b/test/goldens/desktop_dark_settings.png differ diff --git a/test/goldens/desktop_dark_settings_appearance_end.png b/test/goldens/desktop_dark_settings_appearance_end.png index 1544658..5e5b472 100644 Binary files a/test/goldens/desktop_dark_settings_appearance_end.png and b/test/goldens/desktop_dark_settings_appearance_end.png differ diff --git a/test/goldens/desktop_dark_settings_shortcuts.png b/test/goldens/desktop_dark_settings_shortcuts.png index 7e6104d..348623b 100644 Binary files a/test/goldens/desktop_dark_settings_shortcuts.png and b/test/goldens/desktop_dark_settings_shortcuts.png differ diff --git a/test/goldens/desktop_dark_settings_updates.png b/test/goldens/desktop_dark_settings_updates.png index ebc2623..e27d29c 100644 Binary files a/test/goldens/desktop_dark_settings_updates.png and b/test/goldens/desktop_dark_settings_updates.png differ diff --git a/test/goldens/desktop_dark_update_ready.png b/test/goldens/desktop_dark_update_ready.png index 93af8a2..cd20e9e 100644 Binary files a/test/goldens/desktop_dark_update_ready.png and b/test/goldens/desktop_dark_update_ready.png differ diff --git a/test/goldens/desktop_light.png b/test/goldens/desktop_light.png index 6f6f8fc..ef13f89 100644 Binary files a/test/goldens/desktop_light.png and b/test/goldens/desktop_light.png differ diff --git a/test/goldens/desktop_light_settings_appearance.png b/test/goldens/desktop_light_settings_appearance.png index eb83f33..ab3a7fb 100644 Binary files a/test/goldens/desktop_light_settings_appearance.png and b/test/goldens/desktop_light_settings_appearance.png differ diff --git a/test/goldens/desktop_windows_dark_settings.png b/test/goldens/desktop_windows_dark_settings.png index 47d4209..3f90449 100644 Binary files a/test/goldens/desktop_windows_dark_settings.png and b/test/goldens/desktop_windows_dark_settings.png differ diff --git a/test/goldens/desktop_windows_dark_update.png b/test/goldens/desktop_windows_dark_update.png index 57cc099..7925bef 100644 Binary files a/test/goldens/desktop_windows_dark_update.png and b/test/goldens/desktop_windows_dark_update.png differ diff --git a/test/goldens/sidebar_streak_dark.png b/test/goldens/sidebar_streak_dark.png index 3c0c406..288cab8 100644 Binary files a/test/goldens/sidebar_streak_dark.png and b/test/goldens/sidebar_streak_dark.png differ diff --git a/test/goldens/sidebar_streak_light.png b/test/goldens/sidebar_streak_light.png index 59995f5..1d552c2 100644 Binary files a/test/goldens/sidebar_streak_light.png and b/test/goldens/sidebar_streak_light.png differ diff --git a/test/goldens/welcome_desktop_dark.png b/test/goldens/welcome_desktop_dark.png index d21e87b..e59fbc3 100644 Binary files a/test/goldens/welcome_desktop_dark.png and b/test/goldens/welcome_desktop_dark.png differ diff --git a/test/kapy_header_trigger_test.dart b/test/kapy_header_trigger_test.dart index cd1ad2b..2a9e70b 100644 --- a/test/kapy_header_trigger_test.dart +++ b/test/kapy_header_trigger_test.dart @@ -1,5 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:kapy_notes/app.dart'; +import 'package:kapy_notes/core/platform.dart'; import 'package:kapy_notes/data/layout_prefs.dart'; import 'package:kapy_notes/data/notes_store.dart'; import 'package:kapy_notes/data/rates.dart'; @@ -34,7 +35,10 @@ Future<_AppFixture> _pumpApp(WidgetTester tester, {String body = ''}) async { fixture.shortcuts.load(); fixture.notes.create(body: body); - tester.view.physicalSize = const Size(1100, 760); + // The animated mark lives in the phone's title bar. + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); + tester.view.physicalSize = const Size(390, 760); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget( diff --git a/test/page_toolbar_test.dart b/test/page_toolbar_test.dart new file mode 100644 index 0000000..027ee04 --- /dev/null +++ b/test/page_toolbar_test.dart @@ -0,0 +1,204 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:kapy_notes/core/platform.dart'; +import 'package:kapy_notes/core/theme.dart'; +import 'package:kapy_notes/sync/sync_service.dart' show SyncStatus; +import 'package:kapy_notes/ui/context_menu.dart'; +import 'package:kapy_notes/ui/page_card.dart'; +import 'package:kapy_notes/ui/page_toolbar.dart'; +import 'package:material_ui/material_ui.dart'; + +import 'test_fonts.dart'; + +void main() { + setUpAll(loadTestFonts); + setUp(() => AppPlatform.debugTargetPlatformOverride = TargetPlatform.macOS); + tearDown(() => AppPlatform.debugTargetPlatformOverride = null); + + Widget harness(PageToolbar toolbar, {double width = 1016}) => MaterialApp( + theme: KapyTheme.dark(), + home: Scaffold( + body: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: width, + height: 300, + child: PageCard(child: Column(children: [toolbar, const Spacer()])), + ), + ), + ), + ); + + PageToolbar toolbar({ + bool listVisible = true, + bool noteOpen = true, + SyncStatus? syncStatus, + String? section = 'Pinned', + List moreActions = const [], + ValueChanged? onMore, + VoidCallback? onShowList, + VoidCallback? onCreate, + }) => PageToolbar( + space: 'My notes', + section: section, + listVisible: listVisible, + onShowList: onShowList ?? () {}, + onCreate: onCreate ?? () {}, + showListShortcut: 'Cmd + \\', + newNoteShortcut: 'Cmd + N', + noteOpen: noteOpen, + syncStatus: syncStatus, + onShare: () {}, + pinned: true, + onTogglePin: () {}, + moreActions: moreActions, + onMore: onMore ?? (_) {}, + ); + + final showList = find.byKey(const ValueKey('page-show-list')); + final newNote = find.byKey(const ValueKey('page-new-note')); + final saved = find.byKey(const ValueKey('page-saved')); + + testWidgets('beside the list it leads with the breadcrumb alone', ( + tester, + ) async { + await tester.pumpWidget(harness(toolbar())); + + expect(showList, findsNothing); + expect(newNote, findsNothing); + final crumb = find.byKey(const ValueKey('page-breadcrumb')); + expect( + find.descendant(of: crumb, matching: find.text('My notes')), + findsOneWidget, + ); + expect( + find.descendant(of: crumb, matching: find.text('Pinned')), + findsOneWidget, + ); + // Paper's 24 from the page's edge, inside its 1.5 border. + expect(tester.getTopLeft(crumb).dx, 25.5); + }); + + testWidgets('with the list hidden it leads with show-list and a new note', ( + tester, + ) async { + var shown = 0; + var created = 0; + await tester.pumpWidget( + harness( + toolbar( + listVisible: false, + onShowList: () => shown++, + onCreate: () => created++, + ), + ), + ); + + expect(tester.getSize(showList), const Size.square(30)); + expect( + find.descendant( + of: showList, + matching: find.byTooltip('Show notes Cmd + \\'), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: newNote, + matching: find.byTooltip('New note Cmd + N'), + ), + findsOneWidget, + ); + expect(tester.getTopLeft(newNote).dx - tester.getTopRight(showList).dx, 4); + expect( + tester.getTopLeft(find.byKey(const ValueKey('page-breadcrumb'))).dx, + greaterThan(tester.getTopRight(newNote).dx + 18), + ); + + await tester.tap(showList); + await tester.tap(newNote); + expect((shown, created), (1, 1)); + }); + + testWidgets('Saved speaks for the open note, and for sync', (tester) async { + await tester.pumpWidget(harness(toolbar())); + expect( + find.descendant(of: saved, matching: find.text('Saved')), + findsOneWidget, + ); + + await tester.pumpWidget(harness(toolbar(syncStatus: SyncStatus.syncing))); + expect(find.text('Syncing'), findsOneWidget); + + await tester.pumpWidget(harness(toolbar(syncStatus: SyncStatus.offline))); + expect(find.text('Offline'), findsOneWidget); + expect( + find.byTooltip( + 'Saved on this device. It syncs once you are back online.', + ), + findsOneWidget, + ); + + await tester.pumpWidget(harness(toolbar(noteOpen: false))); + expect(saved, findsNothing); + }); + + testWidgets('a narrow page gives Saved up before anything else', ( + tester, + ) async { + await tester.pumpWidget(harness(toolbar(listVisible: false), width: 420)); + + expect(saved, findsNothing); + for (final key in ['page-share', 'page-pin', 'page-more']) { + expect(find.byKey(ValueKey(key)), findsOneWidget); + } + expect(tester.takeException(), isNull); + }); + + testWidgets('More lists its actions and hands back the one picked', ( + tester, + ) async { + String? picked; + await tester.pumpWidget( + harness( + toolbar( + moreActions: const [ + KapyMenuAction( + value: 'split', + label: 'Up to three notes side by side', + icon: KapyIcons.viewColumnOutlined, + enabled: false, + ), + KapyMenuAction( + value: 'archive', + label: 'Archive note', + icon: KapyIcons.archiveOutlined, + destructive: true, + ), + ], + onMore: (value) => picked = value, + ), + ), + ); + + await tester.tap(find.byKey(const ValueKey('page-more'))); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const ValueKey('page-more-split'))); + await tester.pumpAndSettle(); + expect(picked, isNull); + + await tester.tap(find.byKey(const ValueKey('page-more-archive'))); + await tester.pumpAndSettle(); + expect(picked, 'archive'); + }); + + testWidgets('More has nothing to open with nothing to offer', (tester) async { + await tester.pumpWidget(harness(toolbar())); + final more = tester.widget( + find.descendant( + of: find.byKey(const ValueKey('page-more')), + matching: find.byType(IconButton), + ), + ); + expect(more.onPressed, isNull); + }); +} diff --git a/test/toolbar_test.dart b/test/toolbar_test.dart index 74f193f..1eab0ce 100644 --- a/test/toolbar_test.dart +++ b/test/toolbar_test.dart @@ -94,30 +94,6 @@ void main() { }); } - testWidgets('split view is the extreme-right action beside sharing', ( - tester, - ) async { - await tester.pumpWidget( - harness( - NoteToolbar( - onToggleSidebar: () {}, - onCreate: () {}, - onShare: () {}, - onSplit: () {}, - splitTooltip: 'Split view', - ), - ), - ); - - final add = tester.getCenter(findKapyIcon(KapyIcons.addRounded)).dx; - final share = tester.getCenter(findKapyIcon(KapyIcons.peopleOutlined)).dx; - final split = tester - .getCenter(find.byKey(const ValueKey('toolbar-split-view'))) - .dx; - expect(add, lessThan(share)); - expect(share, lessThan(split)); - }); - testWidgets('the wordmark keeps the exact centre either way', ( tester, ) async { diff --git a/test/welcome_note_test.dart b/test/welcome_note_test.dart index d328864..339725a 100644 --- a/test/welcome_note_test.dart +++ b/test/welcome_note_test.dart @@ -214,7 +214,10 @@ void main() { testWidgets('gives Kapy the one beat the word total already earns', ( tester, ) async { - await pumpLaunch(tester, MemoryStore()); + // The animated mark lives in the phone's title bar. + AppPlatform.debugTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => AppPlatform.debugTargetPlatformOverride = null); + await pumpLaunch(tester, MemoryStore(), size: const Size(390, 760)); final mascot = tester.widget( find.byType(KapyHeaderMascot),