mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
feat(app): hubs, types and tags UI, themes, key bindings and slash commands
Settings screen (themes incl. Sweet, rebindable shortcuts), rich text escapes, page sidebar with the local graph, sortable All pages, tree view changes and the Type/Tags rows in the page header. Docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e18fd2c27e
commit
88ef4a97a5
32 files changed
+5431
-375
No files matched your search
@@ -6,7 +6,17 @@ import '../theme/theme.dart';
|
||||
import '../widgets/common.dart';
|
||||
import '../widgets/dates.dart';
|
||||
|
||||
/// Every non-journal page, most recently edited first, loaded in pages of 100.
|
||||
enum PageSort {
|
||||
edited('Edited'),
|
||||
created('Created'),
|
||||
title('Title');
|
||||
|
||||
const PageSort(this.label);
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// Every non-journal note (hubs are folders, not pages), sortable. The whole list is loaded in
|
||||
/// batches of 200 and sorted on the client; the list itself is built lazily.
|
||||
class AllPagesView extends StatefulWidget {
|
||||
const AllPagesView({super.key});
|
||||
|
||||
@@ -16,96 +26,250 @@ class AllPagesView extends StatefulWidget {
|
||||
|
||||
class _AllPagesViewState extends State<AllPagesView> {
|
||||
final _pages = <PageDto>[];
|
||||
bool _loading = false;
|
||||
bool _done = false;
|
||||
PageSort _sort = PageSort.edited;
|
||||
bool _ascending = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_more();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _more() async {
|
||||
if (_loading || _done) return;
|
||||
_loading = true;
|
||||
final batch = await AppScope.read(context).backend
|
||||
.listPages(limit: 100, offset: _pages.length);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_pages.addAll(batch);
|
||||
_done = batch.length < 100;
|
||||
_loading = false;
|
||||
Future<void> _load() async {
|
||||
final backend = AppScope.read(context).backend;
|
||||
var offset = 0;
|
||||
while (true) {
|
||||
final batch = await backend.listPages(limit: 200, offset: offset);
|
||||
if (!mounted) return;
|
||||
offset += batch.length;
|
||||
setState(() => _pages.addAll(batch.where((p) => !p.isHub)));
|
||||
if (batch.length < 200) return;
|
||||
}
|
||||
}
|
||||
|
||||
List<PageDto> get _sorted {
|
||||
final list = [..._pages];
|
||||
int cmp(PageDto a, PageDto b) => switch (_sort) {
|
||||
PageSort.edited => a.updatedAt.compareTo(b.updatedAt),
|
||||
PageSort.created => a.createdAt.compareTo(b.createdAt),
|
||||
PageSort.title => a.title.toLowerCase().compareTo(b.title.toLowerCase()),
|
||||
};
|
||||
list.sort((a, b) {
|
||||
final c = cmp(a, b);
|
||||
// Time sorts default to newest first, so "descending" is the natural direction there.
|
||||
final flip = _sort == PageSort.title ? _ascending : !_ascending;
|
||||
return flip ? c : -c;
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
Future<void> _cleanUp() async {
|
||||
final app = AppScope.read(context);
|
||||
final candidates = await app.backend.legacyCandidates();
|
||||
if (!mounted) return;
|
||||
final removed = await showDialog<List<String>>(
|
||||
context: context,
|
||||
builder: (_) => CleanupDialog(candidates: candidates),
|
||||
);
|
||||
if (removed == null || removed.isEmpty) return;
|
||||
await app.queue.run(() => app.backend.purgePages(removed));
|
||||
app.recent.removeWhere((p) => removed.contains(p.id));
|
||||
app.reload();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final app = AppScope.read(context);
|
||||
final colors = context.colors;
|
||||
final pages = _sorted;
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) => NotificationListener<ScrollNotification>(
|
||||
onNotification: (n) {
|
||||
if (n.metrics.extentAfter < 600) _more();
|
||||
return false;
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
sidePadding(box.maxWidth),
|
||||
36,
|
||||
sidePadding(box.maxWidth),
|
||||
80,
|
||||
),
|
||||
itemCount: _pages.length + 1,
|
||||
itemBuilder: (context, i) {
|
||||
if (i == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Text(
|
||||
'All pages',
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
);
|
||||
}
|
||||
final p = _pages[i - 1];
|
||||
final edited = DateTime.fromMillisecondsSinceEpoch(
|
||||
p.updatedAt.toInt(),
|
||||
);
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => app.openId(p.id),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
builder: (context, box) => ListView.builder(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
sidePadding(box.maxWidth),
|
||||
36,
|
||||
sidePadding(box.maxWidth),
|
||||
80,
|
||||
),
|
||||
itemCount: pages.length + 1,
|
||||
itemBuilder: (context, i) {
|
||||
if (i == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'All pages',
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
),
|
||||
PopupMenuButton<PageSort>(
|
||||
key: const ValueKey('page-sort'),
|
||||
tooltip: 'Sort by',
|
||||
initialValue: _sort,
|
||||
onSelected: (v) => setState(() {
|
||||
_sort = v;
|
||||
_ascending = false;
|
||||
}),
|
||||
itemBuilder: (_) => [
|
||||
for (final v in PageSort.values)
|
||||
PopupMenuItem(value: v, child: Text(v.label)),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text(
|
||||
p.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.ink),
|
||||
_sort.label,
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
),
|
||||
if (p.originJournal != null)
|
||||
Text(
|
||||
'born ${shortDate(parseDay(p.originJournal!))}',
|
||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: 70,
|
||||
child: Text(
|
||||
shortDate(edited),
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 12, color: colors.muted),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const ValueKey('page-sort-direction'),
|
||||
tooltip: _ascending ? 'Ascending' : 'Descending',
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
color: colors.muted,
|
||||
icon: Icon(
|
||||
_ascending
|
||||
? Icons.arrow_upward_rounded
|
||||
: Icons.arrow_downward_rounded,
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () => setState(() => _ascending = !_ascending),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextLink(
|
||||
'Clean up',
|
||||
icon: Icons.cleaning_services_outlined,
|
||||
onTap: _cleanUp,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
}
|
||||
final p = pages[i - 1];
|
||||
final edited = DateTime.fromMillisecondsSinceEpoch(
|
||||
p.updatedAt.toInt(),
|
||||
);
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => app.openId(p.id),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.ink),
|
||||
),
|
||||
),
|
||||
if (p.originJournal != null)
|
||||
Text(
|
||||
'born ${shortDate(parseDay(p.originJournal!))}',
|
||||
style: TextStyle(fontSize: 12, color: colors.faint),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SizedBox(
|
||||
width: 70,
|
||||
child: Text(
|
||||
shortDate(edited),
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 12, color: colors.muted),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Lists legacy Logseq pages with checkboxes; pops with the ids to delete (or null).
|
||||
class CleanupDialog extends StatefulWidget {
|
||||
const CleanupDialog({super.key, required this.candidates});
|
||||
final List<LegacyCandidate> candidates;
|
||||
|
||||
@override
|
||||
State<CleanupDialog> createState() => _CleanupDialogState();
|
||||
}
|
||||
|
||||
class _CleanupDialogState extends State<CleanupDialog> {
|
||||
late final Set<String> _checked = {
|
||||
for (final c in widget.candidates)
|
||||
if (c.preselected) c.id,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final items = widget.candidates;
|
||||
return AlertDialog(
|
||||
title: const Text('Remove legacy Logseq pages'),
|
||||
content: SizedBox(
|
||||
width: 460,
|
||||
child: items.isEmpty
|
||||
? Text(
|
||||
'No legacy pages found.',
|
||||
style: TextStyle(color: colors.muted),
|
||||
)
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'This deletes the selected pages and their blocks.',
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Flexible(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
for (final c in items)
|
||||
CheckboxListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: _checked.contains(c.id),
|
||||
onChanged: (v) => setState(
|
||||
() => v == true
|
||||
? _checked.add(c.id)
|
||||
: _checked.remove(c.id),
|
||||
),
|
||||
title: Text(c.title),
|
||||
subtitle: Text(
|
||||
'${c.reason} · ${c.blocks} '
|
||||
'${c.blocks == 1 ? 'block' : 'blocks'}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.faint,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
if (items.isNotEmpty)
|
||||
TextButton(
|
||||
onPressed: _checked.isEmpty
|
||||
? null
|
||||
: () => Navigator.pop(context, _checked.toList()),
|
||||
child: Text('Delete (${_checked.length})'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend/graph_backend.dart';
|
||||
import '../state/app_state.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/pickers.dart';
|
||||
|
||||
/// "Convert to hub": title, description, member checklist and what to do with the outline.
|
||||
/// Pops `true` once the page has been converted.
|
||||
class ConvertToHubDialog extends StatefulWidget {
|
||||
const ConvertToHubDialog({super.key, required this.page});
|
||||
final PageDto page;
|
||||
|
||||
@override
|
||||
State<ConvertToHubDialog> createState() => _ConvertToHubDialogState();
|
||||
}
|
||||
|
||||
class _ConvertToHubDialogState extends State<ConvertToHubDialog> {
|
||||
HubPreviewDto? _preview;
|
||||
final _title = TextEditingController();
|
||||
final _description = TextEditingController();
|
||||
final _noteTitle = TextEditingController();
|
||||
final _checked = <String>{};
|
||||
bool _keep = false;
|
||||
bool _busy = false;
|
||||
String? _error;
|
||||
Object? _loadError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_title.dispose();
|
||||
_description.dispose();
|
||||
_noteTitle.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final app = AppScope.read(context);
|
||||
try {
|
||||
final p = await app.backend.hubConversionPreview(widget.page.id);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_preview = p;
|
||||
_title.text = p.suggestedTitle;
|
||||
_description.text = p.suggestedDescription;
|
||||
_noteTitle.text = p.suggestedNoteTitle;
|
||||
_checked.addAll(p.members.map((m) => m.id));
|
||||
_keep = p.proseBlocks > 0;
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _loadError = e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _convert() async {
|
||||
final p = _preview!;
|
||||
final app = AppScope.read(context);
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
await app.queue.run(
|
||||
() => app.backend.convertToHub(
|
||||
widget.page.id,
|
||||
_title.text.trim(),
|
||||
_description.text.trim(),
|
||||
[
|
||||
for (final m in p.members)
|
||||
if (_checked.contains(m.id)) m.id,
|
||||
],
|
||||
keepOutlineAs: _keep ? _noteTitle.text.trim() : null,
|
||||
),
|
||||
report: false,
|
||||
);
|
||||
if (mounted) Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_error = errorText(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final p = _preview;
|
||||
return AlertDialog(
|
||||
title: const Text('Convert to hub'),
|
||||
content: SizedBox(
|
||||
width: 480,
|
||||
child: _loadError != null
|
||||
? Text(errorText(_loadError!))
|
||||
: p == null
|
||||
? const SizedBox(
|
||||
height: 80,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
key: const ValueKey('convert-title'),
|
||||
controller: _title,
|
||||
onChanged: (_) => setState(() {}),
|
||||
decoration: const InputDecoration(labelText: 'Title'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
key: const ValueKey('convert-description'),
|
||||
controller: _description,
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'MEMBERS (${_checked.length}/${p.members.length})',
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
if (p.members.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'No candidates found. Add notes from the hub afterwards.',
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 220),
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
for (final m in p.members)
|
||||
CheckboxListTile(
|
||||
key: ValueKey('member-${m.id}'),
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: _checked.contains(m.id),
|
||||
title: Text(m.title),
|
||||
onChanged: (v) => setState(
|
||||
() => v == true
|
||||
? _checked.add(m.id)
|
||||
: _checked.remove(m.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CheckboxListTile(
|
||||
key: const ValueKey('keep-outline'),
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: _keep,
|
||||
title: const Text('Keep the original outline in a note'),
|
||||
subtitle: p.blocks == 0
|
||||
? null
|
||||
: Text(
|
||||
_keep
|
||||
? '${p.blocks} blocks move to the note'
|
||||
: '${p.blocks} blocks will be deleted',
|
||||
style: TextStyle(color: colors.faint),
|
||||
),
|
||||
onChanged: (v) => setState(() => _keep = v == true),
|
||||
),
|
||||
if (_keep)
|
||||
TextField(
|
||||
key: const ValueKey('convert-note-title'),
|
||||
controller: _noteTitle,
|
||||
onChanged: (_) => setState(() {}),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Note title',
|
||||
errorText: _noteTitle.text.trim().isEmpty
|
||||
? 'A title is required to keep the outline'
|
||||
: null,
|
||||
),
|
||||
),
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Text(
|
||||
_error!,
|
||||
key: const ValueKey('convert-error'),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _busy ? null : () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed:
|
||||
p == null ||
|
||||
_busy ||
|
||||
_title.text.trim().isEmpty ||
|
||||
(_keep && _noteTitle.text.trim().isEmpty)
|
||||
? null
|
||||
: _convert,
|
||||
child: const Text('Convert'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -22,23 +22,25 @@ class GraphView extends StatefulWidget {
|
||||
const GraphView({super.key, this.mode = GraphMode.network, this.focusId});
|
||||
final GraphMode mode;
|
||||
|
||||
/// Page to focus in the local and synapse modes.
|
||||
/// Page to focus in the synapse mode.
|
||||
final String? focusId;
|
||||
|
||||
@override
|
||||
State<GraphView> createState() => _GraphViewState();
|
||||
}
|
||||
|
||||
/// How the clusters mode groups pages.
|
||||
enum ClusterBy { hubs, tags, communities }
|
||||
|
||||
class _GraphViewState extends State<GraphView> {
|
||||
late GraphMode _mode = widget.mode;
|
||||
GraphModel? _model;
|
||||
Object? _error;
|
||||
GraphFilter _filter = const GraphFilter();
|
||||
ColorBy _colorBy = ColorBy.cluster;
|
||||
int _depth = 2;
|
||||
|
||||
/// Journals are context for a neighbourhood, so the local mode shows them by default.
|
||||
bool _localJournals = true;
|
||||
/// Clusters mode grouping; null = hubs when the graph has any, else communities.
|
||||
ClusterBy? _clusterBy;
|
||||
int? _focus;
|
||||
BrainOverlay? _brain;
|
||||
SubGraph? _sub;
|
||||
@@ -82,6 +84,10 @@ class _GraphViewState extends State<GraphView> {
|
||||
}
|
||||
}
|
||||
|
||||
ClusterBy get _grouping =>
|
||||
_clusterBy ??
|
||||
((_model?.hasHubs ?? false) ? ClusterBy.hubs : ClusterBy.communities);
|
||||
|
||||
void _setMode(GraphMode m) {
|
||||
setState(() => _mode = m);
|
||||
_rebuildSub();
|
||||
@@ -102,16 +108,18 @@ class _GraphViewState extends State<GraphView> {
|
||||
if (m == null) return;
|
||||
switch (_mode) {
|
||||
case GraphMode.network || GraphMode.clusters:
|
||||
setState(() => _sub = m.subgraph(_filter.apply(m), _filter.kinds));
|
||||
case GraphMode.local:
|
||||
final f = _focus;
|
||||
if (f == null) return;
|
||||
final kinds = _filter.kinds;
|
||||
final hood = m.neighbourhood(f, _depth, kinds);
|
||||
final nodes = hood.keys
|
||||
.where((i) => i == f || _localJournals || !m.isJournal(i))
|
||||
.toList();
|
||||
setState(() => _sub = m.subgraph(nodes, kinds));
|
||||
final nodes = _filter.apply(m);
|
||||
// Hub grouping: layout-only springs to the home hub so folders cluster spatially.
|
||||
final springs = _mode != GraphMode.clusters
|
||||
? const <(int, int, double)>[]
|
||||
: switch (_grouping) {
|
||||
ClusterBy.hubs => m.hubSprings(nodes),
|
||||
ClusterBy.tags => m.tagSprings(nodes),
|
||||
ClusterBy.communities => const <(int, int, double)>[],
|
||||
};
|
||||
setState(
|
||||
() => _sub = m.subgraph(nodes, _filter.kinds, springs: springs),
|
||||
);
|
||||
case GraphMode.brain:
|
||||
final f = _focus;
|
||||
if (f == null) return;
|
||||
@@ -348,39 +356,25 @@ class _GraphViewState extends State<GraphView> {
|
||||
items: const {
|
||||
ColorBy.cluster: 'Colour: cluster',
|
||||
ColorBy.tag: 'Colour: tag',
|
||||
ColorBy.hub: 'Colour: hub',
|
||||
ColorBy.none: 'Colour: none',
|
||||
},
|
||||
onChanged: (c) => setState(() => _colorBy = c ?? ColorBy.cluster),
|
||||
),
|
||||
];
|
||||
case GraphMode.local:
|
||||
return [
|
||||
search,
|
||||
_Labeled(
|
||||
'Depth $_depth',
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Slider(
|
||||
key: const ValueKey('depth'),
|
||||
value: _depth.toDouble(),
|
||||
min: 1,
|
||||
max: 3,
|
||||
divisions: 2,
|
||||
onChanged: (v) {
|
||||
setState(() => _depth = v.round());
|
||||
_rebuildSub();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
chip('Journals', _localJournals, (v) {
|
||||
setState(() => _localJournals = v);
|
||||
_rebuildSub();
|
||||
}),
|
||||
if (_focus != null)
|
||||
_FocusLink(
|
||||
title: m.node(_focus!).title,
|
||||
onTap: () => _open(_focus!),
|
||||
if (_mode == GraphMode.clusters)
|
||||
_Dropdown<ClusterBy>(
|
||||
key: const ValueKey('cluster-group'),
|
||||
value: _grouping,
|
||||
hint: 'Group',
|
||||
items: const {
|
||||
ClusterBy.hubs: 'Group: hubs',
|
||||
ClusterBy.tags: 'Group: tags',
|
||||
ClusterBy.communities: 'Group: communities',
|
||||
},
|
||||
onChanged: (v) {
|
||||
_clusterBy = v;
|
||||
_rebuildSub();
|
||||
},
|
||||
),
|
||||
];
|
||||
case GraphMode.brain:
|
||||
@@ -426,11 +420,17 @@ class _GraphViewState extends State<GraphView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_mode == GraphMode.tree) return TreeCanvas(model: m, onTap: _open);
|
||||
if (_mode == GraphMode.tree) {
|
||||
return TreeCanvas(
|
||||
model: m,
|
||||
onTap: _open,
|
||||
name: AppScope.read(context).backend.graphName,
|
||||
);
|
||||
}
|
||||
final sub = _sub;
|
||||
if (sub == null) return const SizedBox.shrink();
|
||||
final app = AppScope.read(context);
|
||||
final explore = _mode == GraphMode.local || _mode == GraphMode.brain;
|
||||
final explore = _mode == GraphMode.brain;
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
@@ -438,7 +438,13 @@ class _GraphViewState extends State<GraphView> {
|
||||
key: ValueKey(_mode),
|
||||
sub: sub,
|
||||
cache: app.graphPositions,
|
||||
colorBy: _mode == GraphMode.clusters ? ColorBy.cluster : _colorBy,
|
||||
colorBy: _mode == GraphMode.clusters
|
||||
? switch (_grouping) {
|
||||
ClusterBy.hubs => ColorBy.hub,
|
||||
ClusterBy.tags => ColorBy.tagGroup,
|
||||
ClusterBy.communities => ColorBy.cluster,
|
||||
}
|
||||
: _colorBy,
|
||||
hulls: _mode == GraphMode.clusters,
|
||||
focus: explore ? _focus : null,
|
||||
brain: _mode == GraphMode.brain ? _brain : null,
|
||||
@@ -485,6 +491,7 @@ class _Labeled extends StatelessWidget {
|
||||
|
||||
class _Dropdown<T> extends StatelessWidget {
|
||||
const _Dropdown({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.hint,
|
||||
required this.items,
|
||||
@@ -566,17 +573,39 @@ class _Legend extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
Widget hubMark() => Padding(
|
||||
padding: const EdgeInsets.only(right: 14),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 11,
|
||||
height: 11,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: colors.muted,
|
||||
border: Border.all(color: colors.ink, width: 1.6),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text('Hub', style: TextStyle(fontSize: 11.5, color: colors.muted)),
|
||||
],
|
||||
),
|
||||
);
|
||||
final items = mode == GraphMode.brain
|
||||
? [
|
||||
line(palette[3], 'Synapse (thicker = stronger)', w: 3),
|
||||
line(colors.accent, 'Activation pulse', w: 3),
|
||||
hubMark(),
|
||||
]
|
||||
: [
|
||||
line(colors.muted, 'Link'),
|
||||
line(colors.accent, 'Tag'),
|
||||
line(palette[2], 'Property'),
|
||||
line(colors.ref, 'Block ref / embed'),
|
||||
line(colors.ink, 'Contains (hub → note)', w: 1),
|
||||
line(colors.faint, 'Mention', dashed: true),
|
||||
hubMark(),
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
@@ -679,6 +708,8 @@ class _LocalGraphPanelState extends State<LocalGraphPanel> {
|
||||
EdgeKind.blockRef,
|
||||
EdgeKind.embed,
|
||||
EdgeKind.mention,
|
||||
EdgeKind.contains,
|
||||
EdgeKind.tagged,
|
||||
};
|
||||
final hood = m.neighbourhood(f, _depth, kinds).keys.toList();
|
||||
setState(() => _sub = m.subgraph(hood, kinds));
|
||||
@@ -721,15 +752,6 @@ class _LocalGraphPanelState extends State<LocalGraphPanel> {
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Open in graph view',
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 15,
|
||||
color: colors.muted,
|
||||
icon: const Icon(Icons.open_in_full_rounded),
|
||||
onPressed: () =>
|
||||
app.go(GraphRoute(GraphMode.local, focusId: widget.pageId)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend/graph_backend.dart';
|
||||
import '../state/app_state.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/common.dart';
|
||||
import '../widgets/dates.dart';
|
||||
import '../widgets/pickers.dart';
|
||||
import '../widgets/tags.dart';
|
||||
import 'graph_view.dart';
|
||||
import 'page_screen.dart';
|
||||
|
||||
/// A hub: title, short description and its members (sub-hubs first, then notes). It has no
|
||||
/// outline. Membership is stored on the member, so adding/removing edits the member.
|
||||
class HubScreen extends StatefulWidget {
|
||||
const HubScreen({
|
||||
super.key,
|
||||
required this.page,
|
||||
required this.aliases,
|
||||
required this.structure,
|
||||
required this.hubSizes,
|
||||
});
|
||||
final PageDto page;
|
||||
final List<String> aliases;
|
||||
final PageStructure? structure;
|
||||
final Map<String, int> hubSizes;
|
||||
|
||||
@override
|
||||
State<HubScreen> createState() => _HubScreenState();
|
||||
}
|
||||
|
||||
class _HubScreenState extends State<HubScreen> {
|
||||
late final _desc = TextEditingController(text: widget.page.description);
|
||||
late final _focus = FocusNode()..addListener(_blur);
|
||||
late String _committed = widget.page.description;
|
||||
AppState? _app;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_app = AppScope.read(context);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_commit();
|
||||
_desc.dispose();
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _blur() {
|
||||
if (!_focus.hasFocus) _commit();
|
||||
}
|
||||
|
||||
void _commit() {
|
||||
final text = _desc.text.trim();
|
||||
if (text == _committed) return;
|
||||
_committed = text;
|
||||
final app = _app!;
|
||||
app.queue
|
||||
.run(() => app.backend.setHubDescription(widget.page.id, text))
|
||||
.ignore();
|
||||
}
|
||||
|
||||
Future<void> _add() async {
|
||||
final app = AppScope.read(context);
|
||||
final hub = widget.page;
|
||||
final st = widget.structure;
|
||||
final taken = {hub.id, ...?st?.members.map((m) => m.id)};
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final r = await showPagePicker(
|
||||
context,
|
||||
heading: 'Add to ${hub.title}',
|
||||
canCreateNote: true,
|
||||
canCreateHub: true,
|
||||
search: (q) async {
|
||||
if (q.isEmpty) {
|
||||
final l = await app.backend.listPages(limit: 20);
|
||||
return [
|
||||
for (final p in l)
|
||||
if (!taken.contains(p.id))
|
||||
PickItem(id: p.id, title: p.title, isHub: p.isHub),
|
||||
];
|
||||
}
|
||||
final hits = await app.backend.searchTitles(q);
|
||||
return [
|
||||
for (final h in hits)
|
||||
if (!taken.contains(h.pageId))
|
||||
PickItem(id: h.pageId, title: h.title),
|
||||
];
|
||||
},
|
||||
);
|
||||
if (r == null || !mounted) return;
|
||||
try {
|
||||
await app.queue.run(() async {
|
||||
final String id;
|
||||
if (r.item != null) {
|
||||
id = r.item!.id;
|
||||
} else if (r.newHub) {
|
||||
id = (await app.backend.createHub(r.newTitle!, '')).id;
|
||||
} else {
|
||||
id = (await app.backend.createPageFromTemplate(
|
||||
hub.id,
|
||||
r.newTitle!,
|
||||
)).id;
|
||||
}
|
||||
await app.backend.addToHub(id, hub.id);
|
||||
}, report: false);
|
||||
app.reload();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openTemplate() async {
|
||||
final app = AppScope.read(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
app.openId(await app.backend.hubTemplate(widget.page.id));
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _remove(PageBrief m) async {
|
||||
final app = AppScope.read(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
await app.queue.run(
|
||||
() => app.backend.removeFromHub(m.id, widget.page.id),
|
||||
report: false,
|
||||
);
|
||||
app.reload();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final app = AppScope.read(context);
|
||||
final st = widget.structure;
|
||||
final page = widget.page;
|
||||
final members = st?.members ?? const <PageBrief>[];
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) {
|
||||
final pad = sidePadding(box.maxWidth);
|
||||
return ListView(
|
||||
padding: EdgeInsets.fromLTRB(pad, 36, pad, 120),
|
||||
children: [
|
||||
if (st != null && st.nsPath.isNotEmpty) ...[
|
||||
Breadcrumb(path: st.nsPath),
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: TitleField(page: page)),
|
||||
PageMenu(page: page, structure: st),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
key: const ValueKey('hub-description'),
|
||||
controller: _desc,
|
||||
focusNode: _focus,
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.muted),
|
||||
decoration: const InputDecoration.collapsed(
|
||||
hintText: 'Add a short description',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 14,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (st != null && st.inHubs.isNotEmpty)
|
||||
InHubs(pageId: page.id, hubs: st.inHubs),
|
||||
if (page.originJournal != null)
|
||||
TextLink(
|
||||
'Born ${longDate(page.originJournal!)}',
|
||||
icon: Icons.spa_outlined,
|
||||
onTap: () => app.openTitle(page.originJournal!),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TagBar(page: page),
|
||||
const SizedBox(height: 28),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SectionLabel(
|
||||
'Members',
|
||||
trailing: Text(
|
||||
'${members.length}',
|
||||
style: TextStyle(fontSize: 11, color: colors.faint),
|
||||
),
|
||||
),
|
||||
),
|
||||
TextLink(
|
||||
'Template',
|
||||
icon: Icons.article_outlined,
|
||||
onTap: _openTemplate,
|
||||
style: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
TextLink(
|
||||
'Add',
|
||||
icon: Icons.add_rounded,
|
||||
onTap: _add,
|
||||
style: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (st != null && members.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'Empty. Add notes or sub-hubs to organise them here.',
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
),
|
||||
for (final m in members)
|
||||
_MemberRow(
|
||||
key: ValueKey('member-${m.id}'),
|
||||
member: m,
|
||||
count: widget.hubSizes[m.id],
|
||||
onOpen: () => app.openId(m.id),
|
||||
onRemove: () => _remove(m),
|
||||
),
|
||||
const SizedBox(height: 36),
|
||||
LocalGraphPanel(key: ValueKey('local-${page.id}'), pageId: page.id),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MemberRow extends StatefulWidget {
|
||||
const _MemberRow({
|
||||
super.key,
|
||||
required this.member,
|
||||
required this.count,
|
||||
required this.onOpen,
|
||||
required this.onRemove,
|
||||
});
|
||||
final PageBrief member;
|
||||
final int? count;
|
||||
final VoidCallback onOpen;
|
||||
final VoidCallback onRemove;
|
||||
|
||||
@override
|
||||
State<_MemberRow> createState() => _MemberRowState();
|
||||
}
|
||||
|
||||
class _MemberRowState extends State<_MemberRow> {
|
||||
bool _hover = false;
|
||||
|
||||
Future<void> _menu(Offset at) async {
|
||||
final r = await showMenu<bool>(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(at.dx, at.dy, at.dx, at.dy),
|
||||
items: const [PopupMenuItem(value: true, child: Text('Remove from hub'))],
|
||||
);
|
||||
if (r == true) widget.onRemove();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final m = widget.member;
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hover = true),
|
||||
onExit: (_) => setState(() => _hover = false),
|
||||
child: GestureDetector(
|
||||
onLongPressStart: (d) => _menu(d.globalPosition),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: widget.onOpen,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
m.isHub ? Icons.folder_outlined : Icons.description_outlined,
|
||||
size: 17,
|
||||
color: colors.accent.withAlpha(0xCC),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
m.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.5, color: colors.ink),
|
||||
),
|
||||
),
|
||||
if (m.isHub && widget.count != null)
|
||||
Text(
|
||||
'${widget.count}',
|
||||
style: TextStyle(fontSize: 11.5, color: colors.faint),
|
||||
),
|
||||
SizedBox(
|
||||
width: 28,
|
||||
child: _hover
|
||||
? InkResponse(
|
||||
key: ValueKey('remove-${m.id}'),
|
||||
radius: 14,
|
||||
onTap: widget.onRemove,
|
||||
child: Icon(
|
||||
Icons.close_rounded,
|
||||
size: 15,
|
||||
color: colors.faint,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend/graph_backend.dart';
|
||||
import '../state/app_state.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/pickers.dart';
|
||||
|
||||
/// Sidebar "HUBS" section: a collapsible folder tree (root hubs, their sub-hubs and pages).
|
||||
/// Always visible, with a "+" to create a hub; root hubs start expanded.
|
||||
class HubsSection extends StatefulWidget {
|
||||
const HubsSection({super.key, required this.onOpen, this.selectedId});
|
||||
final void Function(String id) onOpen;
|
||||
final String? selectedId;
|
||||
|
||||
@override
|
||||
State<HubsSection> createState() => _HubsSectionState();
|
||||
}
|
||||
|
||||
class _HubsSectionState extends State<HubsSection> {
|
||||
HubsDto? _data;
|
||||
Map<String, HubDto> _byId = const {};
|
||||
int? _generation;
|
||||
AppState? _app;
|
||||
Timer? _refresh;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final app = AppScope.of(context);
|
||||
if (_app != app) {
|
||||
_app?.queue.revision.removeListener(_edited);
|
||||
_app = app..queue.revision.addListener(_edited);
|
||||
}
|
||||
if (_generation != app.generation) {
|
||||
_generation = app.generation;
|
||||
_load();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refresh?.cancel();
|
||||
_app?.queue.revision.removeListener(_edited);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _edited() {
|
||||
_refresh?.cancel();
|
||||
_refresh = Timer(const Duration(milliseconds: 1500), _load);
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final app = _app;
|
||||
if (app == null) return;
|
||||
try {
|
||||
final d = await app.backend.hubs();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_data = d;
|
||||
_byId = {for (final h in d.hubs) h.id: h};
|
||||
});
|
||||
} catch (e) {
|
||||
debugPrint('hubs load failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _create() async {
|
||||
final app = AppScope.read(context);
|
||||
final hub = await showNameDialog<PageDto>(
|
||||
context,
|
||||
heading: 'New hub',
|
||||
confirm: 'Create',
|
||||
submit: (t) =>
|
||||
app.queue.run(() => app.backend.createHub(t, ''), report: false),
|
||||
);
|
||||
if (hub == null) return;
|
||||
app.reload();
|
||||
app.openId(hub.id);
|
||||
}
|
||||
|
||||
void _toggle(String id) {
|
||||
final open = AppScope.read(context).expandedHubs;
|
||||
setState(() => open.contains(id) ? open.remove(id) : open.add(id));
|
||||
}
|
||||
|
||||
/// Rows of a hub's subtree. `path` holds the hubs above, which guards against cycles.
|
||||
void _rows(
|
||||
List<Widget> out,
|
||||
HubDto hub,
|
||||
int depth,
|
||||
Set<String> path,
|
||||
Set<String> open,
|
||||
) {
|
||||
final expanded = open.contains(hub.id);
|
||||
// Keys use the full path: a sub-hub can sit in several hubs.
|
||||
final inner = {...path, hub.id};
|
||||
final at = inner.join('/');
|
||||
out.add(
|
||||
_TreeRow(
|
||||
key: ValueKey('hub-$at'),
|
||||
label: hub.title,
|
||||
depth: depth,
|
||||
isHub: true,
|
||||
expanded: expanded,
|
||||
selected: widget.selectedId == hub.id,
|
||||
onToggle: () => _toggle(hub.id),
|
||||
onTap: () => widget.onOpen(hub.id),
|
||||
),
|
||||
);
|
||||
if (!expanded) return;
|
||||
// Only sub-hubs are children here; notes are listed on the hub's own screen.
|
||||
for (final m in hub.members) {
|
||||
final sub = hub.subHubs.contains(m.id) ? _byId[m.id] : null;
|
||||
if (sub != null && !inner.contains(sub.id)) {
|
||||
_rows(out, sub, depth + 1, inner, open);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = _data;
|
||||
final open = AppScope.read(context).expandedHubs;
|
||||
final rows = <Widget>[];
|
||||
for (final id in data?.roots ?? const <String>[]) {
|
||||
final h = _byId[id];
|
||||
if (h != null) _rows(rows, h, 0, const {}, open);
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'HUBS',
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
InkResponse(
|
||||
key: const ValueKey('new-hub'),
|
||||
radius: 12,
|
||||
onTap: _create,
|
||||
child: Icon(
|
||||
Icons.add_rounded,
|
||||
size: 16,
|
||||
color: context.colors.faint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
...rows,
|
||||
const SizedBox(height: 22),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TreeRow extends StatefulWidget {
|
||||
const _TreeRow({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.depth,
|
||||
required this.isHub,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
this.expanded = false,
|
||||
this.onToggle,
|
||||
});
|
||||
final String label;
|
||||
final int depth;
|
||||
final bool isHub;
|
||||
final bool expanded;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
/// Non-null for hubs that can be expanded.
|
||||
final VoidCallback? onToggle;
|
||||
|
||||
@override
|
||||
State<_TreeRow> createState() => _TreeRowState();
|
||||
}
|
||||
|
||||
class _TreeRowState extends State<_TreeRow> {
|
||||
bool _hover = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final active = widget.selected;
|
||||
final toggle = widget.onToggle;
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hover = true),
|
||||
onExit: (_) => setState(() => _hover = false),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 1),
|
||||
padding: EdgeInsets.only(left: 4.0 + 14 * widget.depth, right: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: active
|
||||
? colors.accentSoft
|
||||
: _hover
|
||||
? colors.line.withAlpha(0x66)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
height: 28,
|
||||
child: toggle == null
|
||||
? null
|
||||
: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: toggle,
|
||||
child: Icon(
|
||||
widget.expanded
|
||||
? Icons.expand_more_rounded
|
||||
: Icons.chevron_right_rounded,
|
||||
size: 16,
|
||||
color: colors.faint,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: widget.onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.isHub
|
||||
? (widget.expanded
|
||||
? Icons.folder_open_outlined
|
||||
: Icons.folder_outlined)
|
||||
: Icons.description_outlined,
|
||||
size: 14,
|
||||
color: active ? colors.accent : colors.faint,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: active
|
||||
? FontWeight.w600
|
||||
: FontWeight.w500,
|
||||
color: active ? colors.ink : colors.muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,11 @@ import '../state/outline_controller.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/common.dart';
|
||||
import '../widgets/dates.dart';
|
||||
import '../widgets/pickers.dart';
|
||||
import '../widgets/tags.dart';
|
||||
import 'convert_dialog.dart';
|
||||
import 'graph_view.dart';
|
||||
import 'hub_screen.dart';
|
||||
import 'journals_view.dart';
|
||||
|
||||
/// A single page: title, aliases, outline, linked references and related notes.
|
||||
@@ -24,6 +28,8 @@ class _PageScreenState extends State<PageScreen> {
|
||||
OutlineController? _outline;
|
||||
List<BacklinkGroup>? _backlinks;
|
||||
List<RelatedDto>? _related;
|
||||
PageStructure? _structure;
|
||||
Map<String, int> _hubSizes = const {};
|
||||
Object? _error;
|
||||
|
||||
@override
|
||||
@@ -69,6 +75,8 @@ class _PageScreenState extends State<PageScreen> {
|
||||
app.pageShown(view.page);
|
||||
// Make sure pending writes (e.g. a link just typed elsewhere) are visible.
|
||||
await app.queue.idle;
|
||||
if (view.page.journalDate == null) await _loadStructure();
|
||||
if (view.page.isHub) return;
|
||||
final results = await Future.wait([
|
||||
app.backend.backlinks(view.page.id),
|
||||
app.backend.related(view.page.id),
|
||||
@@ -83,6 +91,27 @@ class _PageScreenState extends State<PageScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hub and namespace context of the page (not shown for journals).
|
||||
Future<void> _loadStructure() async {
|
||||
final app = AppScope.read(context);
|
||||
final id = _view!.page.id;
|
||||
try {
|
||||
final st = await app.backend.pageStructure(id);
|
||||
var sizes = const <String, int>{};
|
||||
if (st.isHub && st.members.any((m) => m.isHub)) {
|
||||
final hubs = await app.backend.hubs();
|
||||
sizes = {for (final h in hubs.hubs) h.id: h.members.length};
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_structure = st;
|
||||
_hubSizes = sizes;
|
||||
});
|
||||
} catch (e) {
|
||||
debugPrint('page structure failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_error != null) {
|
||||
@@ -92,10 +121,20 @@ class _PageScreenState extends State<PageScreen> {
|
||||
}
|
||||
final view = _view;
|
||||
if (view == null) return const SizedBox.shrink();
|
||||
if (view.page.isHub) {
|
||||
return HubScreen(
|
||||
page: view.page,
|
||||
aliases: view.aliases,
|
||||
structure: _structure,
|
||||
hubSizes: _hubSizes,
|
||||
);
|
||||
}
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) {
|
||||
final wide = box.maxWidth >= 1180;
|
||||
final mainWidth = wide ? box.maxWidth - 300 : box.maxWidth;
|
||||
final open = AppScope.of(context).pageSidebar;
|
||||
final wide = box.maxWidth >= 900;
|
||||
final side = open && wide;
|
||||
final mainWidth = side ? box.maxWidth - 300 : box.maxWidth;
|
||||
final pad = sidePadding(mainWidth);
|
||||
final scroll = CustomScrollView(
|
||||
slivers: [
|
||||
@@ -104,12 +143,18 @@ class _PageScreenState extends State<PageScreen> {
|
||||
padding: EdgeInsets.symmetric(horizontal: pad),
|
||||
sliver: SliverMainAxisGroup(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: _Header(view: view)),
|
||||
SliverToBoxAdapter(
|
||||
child: _Header(view: view, structure: _structure),
|
||||
),
|
||||
if (_structure != null)
|
||||
SliverToBoxAdapter(
|
||||
child: _NamespaceSection(structure: _structure!),
|
||||
),
|
||||
OutlineSliver(controller: _outline!),
|
||||
SliverToBoxAdapter(
|
||||
child: _LinkedReferences(groups: _backlinks),
|
||||
),
|
||||
if (!wide) ...[
|
||||
if (open && !wide) ...[
|
||||
SliverToBoxAdapter(child: RelatedPanel(related: _related)),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
@@ -124,7 +169,7 @@ class _PageScreenState extends State<PageScreen> {
|
||||
),
|
||||
],
|
||||
);
|
||||
if (!wide) return scroll;
|
||||
if (!side) return scroll;
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -154,8 +199,9 @@ class _PageScreenState extends State<PageScreen> {
|
||||
}
|
||||
|
||||
class _Header extends StatelessWidget {
|
||||
const _Header({required this.view});
|
||||
const _Header({required this.view, required this.structure});
|
||||
final PageData view;
|
||||
final PageStructure? structure;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -185,13 +231,38 @@ class _Header extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
] else ...[
|
||||
_TitleField(page: page),
|
||||
if (structure != null && structure!.nsPath.isNotEmpty) ...[
|
||||
Breadcrumb(path: structure!.nsPath),
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: TitleField(page: page)),
|
||||
IconButton(
|
||||
key: const ValueKey('page-sidebar-toggle'),
|
||||
tooltip: AppScope.of(context).pageSidebar
|
||||
? 'Hide graph sidebar'
|
||||
: 'Show graph sidebar',
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 20,
|
||||
color: AppScope.of(context).pageSidebar
|
||||
? colors.accent
|
||||
: colors.muted,
|
||||
icon: const Icon(Icons.view_sidebar_outlined),
|
||||
onPressed: AppScope.read(context).togglePageSidebar,
|
||||
),
|
||||
PageMenu(page: page, structure: structure),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
spacing: 14,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (structure != null && structure!.inHubs.isNotEmpty)
|
||||
InHubs(pageId: page.id, hubs: structure!.inHubs),
|
||||
if (page.originJournal != null)
|
||||
TextLink(
|
||||
'Born ${longDate(page.originJournal!)}',
|
||||
@@ -202,6 +273,9 @@ class _Header extends StatelessWidget {
|
||||
_Aliases(page: page, initial: view.aliases),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TagBar(page: page),
|
||||
if (page.isTag) TaggedNotes(tag: page.title),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -210,15 +284,15 @@ class _Header extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Page title; editing it renames the page (and rewrites every link to it).
|
||||
class _TitleField extends StatefulWidget {
|
||||
const _TitleField({required this.page});
|
||||
class TitleField extends StatefulWidget {
|
||||
const TitleField({super.key, required this.page});
|
||||
final PageDto page;
|
||||
|
||||
@override
|
||||
State<_TitleField> createState() => _TitleFieldState();
|
||||
State<TitleField> createState() => TitleFieldState();
|
||||
}
|
||||
|
||||
class _TitleFieldState extends State<_TitleField> {
|
||||
class TitleFieldState extends State<TitleField> {
|
||||
late final _text = TextEditingController(text: widget.page.title);
|
||||
late final _focus = FocusNode()..addListener(_blur);
|
||||
late String _committed = widget.page.title;
|
||||
@@ -244,10 +318,12 @@ class _TitleFieldState extends State<_TitleField> {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
await app.queue.run(() => app.backend.renamePage(widget.page.id, title));
|
||||
final old = _committed;
|
||||
_committed = title;
|
||||
app.renamed(widget.page.id, title);
|
||||
// The core rewrote links in other blocks, possibly on this page: reload them.
|
||||
app.reload();
|
||||
// The core rewrote links in other blocks, possibly on this page: reload them. The
|
||||
// route must not keep opening the old title (that would create a duplicate page).
|
||||
app.replaceWithId(widget.page.id, old);
|
||||
} catch (e) {
|
||||
_text.text = _committed;
|
||||
messenger.showSnackBar(SnackBar(content: Text('Rename failed: $e')));
|
||||
@@ -494,3 +570,248 @@ class RelatedPanel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Namespace ancestors of the page, `A / B` above the title. Segments open their page
|
||||
/// (virtual ones are created on open, like links).
|
||||
class Breadcrumb extends StatelessWidget {
|
||||
const Breadcrumb({super.key, required this.path});
|
||||
final List<NamespaceEntry> path;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final app = AppScope.read(context);
|
||||
return Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.account_tree_outlined, size: 14, color: colors.faint),
|
||||
for (var i = 0; i < path.length; i++) ...[
|
||||
if (i > 0)
|
||||
Text('/', style: TextStyle(fontSize: 12, color: colors.faint)),
|
||||
TextLink(
|
||||
path[i].title.split('/').last,
|
||||
onTap: () => path[i].id != null
|
||||
? app.openId(path[i].id!)
|
||||
: app.openTitle(path[i].title),
|
||||
style: const TextStyle(fontSize: 12.5),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// "In: hub, hub" chips for the hubs containing the page; each has a remove button.
|
||||
class InHubs extends StatelessWidget {
|
||||
const InHubs({super.key, required this.pageId, required this.hubs});
|
||||
final String pageId;
|
||||
final List<PageBrief> hubs;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final app = AppScope.read(context);
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Text('In', style: TextStyle(fontSize: 12, color: colors.faint)),
|
||||
for (final h in hubs)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextLink(
|
||||
h.title,
|
||||
icon: Icons.folder_outlined,
|
||||
onTap: () => app.openId(h.id),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
InkResponse(
|
||||
key: ValueKey('leave-${h.id}'),
|
||||
radius: 10,
|
||||
onTap: () async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
await app.queue.run(
|
||||
() => app.backend.removeFromHub(pageId, h.id),
|
||||
report: false,
|
||||
);
|
||||
app.reload();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text(errorText(e))),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(3),
|
||||
child: Icon(
|
||||
Icons.close_rounded,
|
||||
size: 12,
|
||||
color: colors.faint,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The page's "⋯" menu: hub conversion and hub membership.
|
||||
class PageMenu extends StatelessWidget {
|
||||
const PageMenu({super.key, required this.page, required this.structure});
|
||||
final PageDto page;
|
||||
final PageStructure? structure;
|
||||
|
||||
Future<void> _addToHub(BuildContext context) async {
|
||||
final app = AppScope.read(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final taken = {page.id, ...?structure?.inHubs.map((h) => h.id)};
|
||||
final r = await showPagePicker(
|
||||
context,
|
||||
heading: 'Add to hub',
|
||||
canCreateHub: true,
|
||||
search: (q) async {
|
||||
final all = await app.backend.hubs();
|
||||
return [
|
||||
for (final h in all.hubs)
|
||||
if (!taken.contains(h.id) &&
|
||||
h.title.toLowerCase().contains(q.toLowerCase()))
|
||||
PickItem(id: h.id, title: h.title, isHub: true),
|
||||
];
|
||||
},
|
||||
);
|
||||
if (r == null) return;
|
||||
try {
|
||||
await app.queue.run(() async {
|
||||
final id =
|
||||
r.item?.id ?? (await app.backend.createHub(r.newTitle!, '')).id;
|
||||
await app.backend.addToHub(page.id, id);
|
||||
}, report: false);
|
||||
app.reload();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _toHub(BuildContext context) async {
|
||||
final app = AppScope.read(context);
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => ConvertToHubDialog(page: page),
|
||||
);
|
||||
if (ok == true) {
|
||||
app.recent.removeWhere((p) => p.id == page.id);
|
||||
app.replaceWithId(page.id, page.title);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _toNote(BuildContext context) async {
|
||||
final app = AppScope.read(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
await app.queue.run(
|
||||
() => app.backend.convertToNote(page.id),
|
||||
report: false,
|
||||
);
|
||||
app.reload();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(errorText(e))));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => PopupMenuButton<String>(
|
||||
key: const ValueKey('page-menu'),
|
||||
icon: Icon(Icons.more_horiz_rounded, color: context.colors.faint),
|
||||
tooltip: 'More',
|
||||
onSelected: (v) => switch (v) {
|
||||
'hub' => _toHub(context),
|
||||
'note' => _toNote(context),
|
||||
_ => _addToHub(context),
|
||||
},
|
||||
itemBuilder: (_) => [
|
||||
if (!page.isHub)
|
||||
const PopupMenuItem(value: 'hub', child: Text('Convert to hub…')),
|
||||
if (page.isHub)
|
||||
const PopupMenuItem(value: 'note', child: Text('Convert to note')),
|
||||
const PopupMenuItem(value: 'add', child: Text('Add to hub…')),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// "Namespace" listing (title-kin children) under the header.
|
||||
class _NamespaceSection extends StatelessWidget {
|
||||
const _NamespaceSection({required this.structure});
|
||||
final PageStructure structure;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
final app = AppScope.read(context);
|
||||
final st = structure;
|
||||
if (st.nsChildren.isEmpty) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SectionLabel(
|
||||
'Namespace',
|
||||
trailing: Text(
|
||||
'${st.nsChildren.length}',
|
||||
style: TextStyle(fontSize: 11, color: colors.faint),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
children: [
|
||||
for (final c in st.nsChildren)
|
||||
SizedBox(
|
||||
width: 230,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => c.id != null
|
||||
? app.openId(c.id!)
|
||||
: app.openTitle(c.title),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.account_tree_outlined,
|
||||
size: 16,
|
||||
color: colors.accent.withAlpha(0xCC),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
c.title.split('/').last,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: colors.ink,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../state/app_state.dart';
|
||||
import '../state/keymap.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/common.dart';
|
||||
|
||||
/// Theme picker and key bindings.
|
||||
class SettingsView extends StatelessWidget {
|
||||
const SettingsView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final app = AppScope.of(context);
|
||||
final colors = context.colors;
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) => ListView(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
sidePadding(box.maxWidth),
|
||||
36,
|
||||
sidePadding(box.maxWidth),
|
||||
80,
|
||||
),
|
||||
children: [
|
||||
Text('Settings', style: Theme.of(context).textTheme.headlineLarge),
|
||||
const SizedBox(height: 28),
|
||||
_Heading('Theme'),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
_ThemeCard(
|
||||
id: autoThemeId,
|
||||
label: 'System',
|
||||
swatch: [
|
||||
SynapseColors.light.paper,
|
||||
SynapseColors.dark.paper,
|
||||
SynapseColors.light.accent,
|
||||
SynapseColors.dark.accent,
|
||||
],
|
||||
selected: app.themeId == autoThemeId,
|
||||
),
|
||||
for (final t in appThemes)
|
||||
_ThemeCard(
|
||||
id: t.id,
|
||||
label: t.label,
|
||||
swatch: [
|
||||
t.colors.paper,
|
||||
t.colors.surface,
|
||||
t.colors.accent,
|
||||
t.colors.ref,
|
||||
],
|
||||
selected: app.themeId == t.id,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 36),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _Heading('Keyboard shortcuts')),
|
||||
TextLink(
|
||||
'Reset all',
|
||||
icon: Icons.restart_alt_rounded,
|
||||
onTap: () => app.resetKey(null),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'Click a shortcut, then press the new combination. Esc cancels.',
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
for (final editor in [false, true]) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 14, bottom: 4),
|
||||
child: Text(
|
||||
editor ? 'EDITOR' : 'APP',
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
for (final a in AppAction.values.where((a) => a.editor == editor))
|
||||
_BindingRow(action: a),
|
||||
],
|
||||
const SizedBox(height: 28),
|
||||
Text(
|
||||
'Type "/" in a block for commands (link, bold, headings, todo, ...). '
|
||||
'Prefix a character with a backslash to show it literally: \\*not italic\\*.',
|
||||
style: TextStyle(fontSize: 13, color: colors.muted),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Heading extends StatelessWidget {
|
||||
const _Heading(this.text);
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(text, style: Theme.of(context).textTheme.headlineSmall),
|
||||
);
|
||||
}
|
||||
|
||||
class _ThemeCard extends StatelessWidget {
|
||||
const _ThemeCard({
|
||||
required this.id,
|
||||
required this.label,
|
||||
required this.swatch,
|
||||
required this.selected,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String label;
|
||||
final List<Color> swatch;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = context.colors;
|
||||
return InkWell(
|
||||
key: ValueKey('theme-$id'),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () => AppScope.read(context).setTheme(id),
|
||||
child: Container(
|
||||
width: 132,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: selected ? colors.accent : colors.line,
|
||||
width: selected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final c in swatch)
|
||||
Expanded(child: Container(height: 28, color: c)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
|
||||
color: colors.ink,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BindingRow extends StatefulWidget {
|
||||
const _BindingRow({required this.action});
|
||||
final AppAction action;
|
||||
|
||||
@override
|
||||
State<_BindingRow> createState() => _BindingRowState();
|
||||
}
|
||||
|
||||
class _BindingRowState extends State<_BindingRow> {
|
||||
final _focus = FocusNode();
|
||||
bool _listening = false;
|
||||
String? _conflict;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
KeyEventResult _onKey(FocusNode _, KeyEvent e) {
|
||||
if (!_listening || e is! KeyDownEvent) return KeyEventResult.ignored;
|
||||
if (e.logicalKey == LogicalKeyboardKey.escape) {
|
||||
setState(() => _listening = false);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
final kb = HardwareKeyboard.instance;
|
||||
final combo = Combo(
|
||||
e.logicalKey,
|
||||
ctrl: kb.isControlPressed || kb.isMetaPressed,
|
||||
shift: kb.isShiftPressed,
|
||||
alt: kb.isAltPressed,
|
||||
);
|
||||
if (combo.isModifierOnly) return KeyEventResult.handled;
|
||||
final owner = AppScope.read(context).bindKey(widget.action, combo);
|
||||
setState(() {
|
||||
_listening = false;
|
||||
_conflict = owner == null ? null : 'Already used by "${owner.label}"';
|
||||
});
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final app = AppScope.of(context);
|
||||
final colors = context.colors;
|
||||
final a = widget.action;
|
||||
return Focus(
|
||||
focusNode: _focus,
|
||||
onKeyEvent: _onKey,
|
||||
onFocusChange: (f) {
|
||||
if (!f && _listening) setState(() => _listening = false);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
a.label,
|
||||
style: TextStyle(fontSize: 14, color: colors.ink),
|
||||
),
|
||||
),
|
||||
if (_conflict != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Text(
|
||||
_conflict!,
|
||||
style: TextStyle(fontSize: 12, color: colors.ref),
|
||||
),
|
||||
),
|
||||
OutlinedButton(
|
||||
key: ValueKey('bind-${a.name}'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(120, 32),
|
||||
side: BorderSide(
|
||||
color: _listening ? colors.accent : colors.line,
|
||||
),
|
||||
foregroundColor: colors.ink,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_listening = true;
|
||||
_conflict = null;
|
||||
});
|
||||
_focus.requestFocus();
|
||||
},
|
||||
child: Text(
|
||||
_listening ? 'Press keys…' : app.keymap.of(a).label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: app.keymap.isCustom(a) ? colors.accent : colors.ink,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Reset',
|
||||
iconSize: 16,
|
||||
visualDensity: VisualDensity.compact,
|
||||
color: colors.faint,
|
||||
onPressed: app.keymap.isCustom(a) ? () => app.resetKey(a) : null,
|
||||
icon: const Icon(Icons.restart_alt_rounded),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../state/app_state.dart';
|
||||
import '../state/keymap.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../widgets/dates.dart';
|
||||
import 'all_pages_view.dart';
|
||||
import 'journals_view.dart';
|
||||
import 'page_screen.dart';
|
||||
import 'hubs_tree.dart';
|
||||
import 'quick_switcher.dart';
|
||||
import 'graph_view.dart';
|
||||
import 'settings_view.dart';
|
||||
|
||||
/// App frame: sidebar (navigation, recents, theme), top bar and the current view.
|
||||
class Shell extends StatefulWidget {
|
||||
@@ -39,39 +42,21 @@ class _ShellState extends State<Shell> {
|
||||
);
|
||||
});
|
||||
}
|
||||
final actions = <AppAction, VoidCallback>{
|
||||
AppAction.quickSwitcher: () => showQuickSwitcher(context),
|
||||
AppAction.journals: () => app.go(const JournalsRoute()),
|
||||
AppAction.graph: () => app.go(const GraphRoute(GraphMode.network)),
|
||||
AppAction.timeline: () => app.go(const TimelineRoute()),
|
||||
AppAction.sidebar: () => setState(() => _sidebar = !_sidebar),
|
||||
AppAction.pageSidebar: app.togglePageSidebar,
|
||||
AppAction.settings: () => app.go(const SettingsRoute()),
|
||||
AppAction.back: app.back,
|
||||
AppAction.forward: app.forward,
|
||||
};
|
||||
return CallbackShortcuts(
|
||||
bindings: {
|
||||
const SingleActivator(LogicalKeyboardKey.keyK, control: true): () =>
|
||||
showQuickSwitcher(context),
|
||||
const SingleActivator(LogicalKeyboardKey.keyK, meta: true): () =>
|
||||
showQuickSwitcher(context),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyJ,
|
||||
control: true,
|
||||
shift: true,
|
||||
): () =>
|
||||
app.go(const JournalsRoute()),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyG,
|
||||
control: true,
|
||||
shift: true,
|
||||
): () =>
|
||||
app.go(const GraphRoute(GraphMode.network)),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.keyT,
|
||||
control: true,
|
||||
shift: true,
|
||||
): () =>
|
||||
app.go(const TimelineRoute()),
|
||||
const SingleActivator(
|
||||
LogicalKeyboardKey.backslash,
|
||||
control: true,
|
||||
): () =>
|
||||
setState(() => _sidebar = !_sidebar),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true):
|
||||
app.back,
|
||||
const SingleActivator(LogicalKeyboardKey.arrowRight, alt: true):
|
||||
app.forward,
|
||||
for (final e in actions.entries)
|
||||
...Map.fromEntries(activators(app.keymap.of(e.key), e.value)),
|
||||
},
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
@@ -125,6 +110,7 @@ class _ShellState extends State<Shell> {
|
||||
focusId: route.focusId,
|
||||
),
|
||||
AllPagesRoute() => const AllPagesView(),
|
||||
SettingsRoute() => const SettingsView(),
|
||||
PageTarget() => PageScreen(target: route),
|
||||
},
|
||||
),
|
||||
@@ -164,15 +150,19 @@ class _TopBar extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
icon(Icons.menu_rounded, 'Toggle sidebar (Ctrl+\\)', onMenu),
|
||||
icon(
|
||||
Icons.menu_rounded,
|
||||
'Toggle sidebar (${app.keymap.of(AppAction.sidebar).label})',
|
||||
onMenu,
|
||||
),
|
||||
icon(
|
||||
Icons.arrow_back_rounded,
|
||||
'Back (Alt+←)',
|
||||
'Back (${app.keymap.of(AppAction.back).label})',
|
||||
app.canGoBack ? app.back : null,
|
||||
),
|
||||
icon(
|
||||
Icons.arrow_forward_rounded,
|
||||
'Forward (Alt+→)',
|
||||
'Forward (${app.keymap.of(AppAction.forward).label})',
|
||||
app.canGoForward ? app.forward : null,
|
||||
),
|
||||
const Spacer(),
|
||||
@@ -214,7 +204,10 @@ class _SearchPill extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
Text('Search', style: TextStyle(fontSize: 13, color: colors.muted)),
|
||||
const SizedBox(width: 18),
|
||||
Text('Ctrl K', style: TextStyle(fontSize: 11, color: colors.faint)),
|
||||
Text(
|
||||
AppScope.of(context).keymap.of(AppAction.quickSwitcher).label,
|
||||
style: TextStyle(fontSize: 11, color: colors.faint),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -275,31 +268,34 @@ class _Sidebar extends StatelessWidget {
|
||||
selected: route is GraphRoute,
|
||||
onTap: () => go(const GraphRoute(GraphMode.network)),
|
||||
),
|
||||
_NavItem(
|
||||
icon: Icons.timeline_rounded,
|
||||
label: 'Timeline',
|
||||
selected: route is TimelineRoute,
|
||||
onTap: () => go(const TimelineRoute()),
|
||||
),
|
||||
_NavItem(
|
||||
icon: Icons.description_outlined,
|
||||
label: 'All pages',
|
||||
selected: route is AllPagesRoute,
|
||||
onTap: () => go(const AllPagesRoute()),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
'RECENT',
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
_NavItem(
|
||||
icon: Icons.settings_outlined,
|
||||
label: 'Settings',
|
||||
selected: route is SettingsRoute,
|
||||
onTap: () => go(const SettingsRoute()),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const SizedBox(height: 22),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
HubsSection(
|
||||
selectedId: route is PageTarget ? route.id : null,
|
||||
onOpen: (id) => go(PageTarget(id: id)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
||||
child: Text(
|
||||
'RECENT',
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
for (final p in app.recent)
|
||||
_NavItem(
|
||||
label: p.isJournal ? longDate(p.title) : p.title,
|
||||
@@ -418,3 +414,29 @@ class _Logo extends CustomPainter {
|
||||
@override
|
||||
bool shouldRepaint(_Logo old) => old.color != color;
|
||||
}
|
||||
|
||||
/// The shortcut activators for `combo` (Ctrl also answers to Cmd on macOS).
|
||||
List<MapEntry<ShortcutActivator, VoidCallback>> activators(
|
||||
Combo combo,
|
||||
VoidCallback run,
|
||||
) => [
|
||||
MapEntry(
|
||||
SingleActivator(
|
||||
combo.key,
|
||||
control: combo.ctrl,
|
||||
shift: combo.shift,
|
||||
alt: combo.alt,
|
||||
),
|
||||
run,
|
||||
),
|
||||
if (combo.ctrl && defaultTargetPlatform == TargetPlatform.macOS)
|
||||
MapEntry(
|
||||
SingleActivator(
|
||||
combo.key,
|
||||
meta: true,
|
||||
shift: combo.shift,
|
||||
alt: combo.alt,
|
||||
),
|
||||
run,
|
||||
),
|
||||
];
|
||||
Reference in new issue
Block a user