Skip to content

Commit

Permalink
fix: proper context menu for foldout ancestor/descendant display
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdSquared committed Sep 25, 2024
1 parent eda70c8 commit c391f7a
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 288 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ SPEC CHECKSUMS:
file_picker: ce3938a0df3cc1ef404671531facef740d03f920
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
irondash_engine_context: 3458bf979b90d616ffb8ae03a150bafe2e860cc9
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
super_native_extensions: 4916b3c627a9c7fffdc48a23a9eca0b1ac228fa7
SwiftyGif: 93a1cc87bf3a51916001cf8f3d63835fb64c819f
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: 7be2f5f74864d463a8ad433546ed1de7e0f29aef

Expand Down
2 changes: 1 addition & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
14 changes: 2 additions & 12 deletions lib/widgets/entry_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,8 @@ class EntryListViewState extends ConsumerState<EntryListView> {
),
SuperSliverList.builder(
itemCount: entries.length,
itemBuilder: (context, index) {
var entryId = entries[index];
return scm.ContextMenuWidget(
menuProvider: (_) => buildEntryCardContextMenu(
entryId: entryId,
addAncestorCallback: (_) => ref
.read(currentAncestorsProvider.notifier)
.addAncestor(entryId),
),
child: PeregrineEntryCard(entryId: entryId),
);
})
itemBuilder: (context, index) =>
PeregrineEntryCard(entryId: entries[index]))
],
);
}
Expand Down
277 changes: 145 additions & 132 deletions lib/widgets/peregrine_entry_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:markdown_widget/markdown_widget.dart';
import 'package:pret_a_porter/pret_a_porter.dart';
import 'package:super_context_menu/super_context_menu.dart' as scm;

import '../context_menus.dart';
import '../format_utils.dart';
import '../main.dart';
import '../vendor/latex.dart';
Expand Down Expand Up @@ -71,143 +73,154 @@ class _PeregrineEntryCardState extends ConsumerState<PeregrineEntryCard> {
),
)
: Container(),
PretCard(
padding: EdgeInsets.only(
top: PretConfig.thinElementSpacing,
left: PretConfig.defaultElementSpacing,
right: PretConfig.defaultElementSpacing,
bottom: entry.isEncrypted && ref.watch(isLocked)
? PretConfig.thinElementSpacing
: PretConfig.defaultElementSpacing,
scm.ContextMenuWidget(
menuProvider: (_) => buildEntryCardContextMenu(
entryId: widget.entryId,
addAncestorCallback: (_) => ref
.read(currentAncestorsProvider.notifier)
.addAncestor(widget.entryId),
),
child: entry.isEncrypted && ref.watch(isLocked)
? const Text.rich(TextSpan(text: '🔒', children: [
TextSpan(
text:
'This entry is encrypted. Unlock the app to view.',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontStyle: FontStyle.italic,
),
)
]))
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
entry.ancestors.isNotEmpty && widget.isTopLevel
? Text.rich(
TextSpan(
text: '${entry.ancestors.length} ancestors',
style: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
child: PretCard(
padding: EdgeInsets.only(
top: PretConfig.thinElementSpacing,
left: PretConfig.defaultElementSpacing,
right: PretConfig.defaultElementSpacing,
bottom: entry.isEncrypted && ref.watch(isLocked)
? PretConfig.thinElementSpacing
: PretConfig.defaultElementSpacing,
),
child: entry.isEncrypted && ref.watch(isLocked)
? const Text.rich(TextSpan(text: '🔒', children: [
TextSpan(
text:
'This entry is encrypted. Unlock the app to view.',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
fontStyle: FontStyle.italic,
),
)
]))
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
entry.ancestors.isNotEmpty
? Text.rich(
TextSpan(
text:
'${entry.ancestors.length} ancestors',
style: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => setState(() {
_ancestorsShown =
!_ancestorsShown;
}),
),
recognizer: TapGestureRecognizer()
..onTap = () => setState(() {
_ancestorsShown = !_ancestorsShown;
}),
),
)
: Container(),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: [
Text('${formatDate(entry.date)} '),
Text(formatTime(entry.date)),
],
),
const Padding(
padding: EdgeInsets.all(
PretConfig.minElementSpacing),
),
Expanded(
child: Wrap(
spacing: PretConfig.minElementSpacing,
runSpacing: PretConfig.minElementSpacing,
alignment: WrapAlignment.end,
children: entry.tags
.map((tag) => OutlinedButton(
style: const ButtonStyle(
minimumSize:
MaterialStatePropertyAll(
Size(32, 32),
),
visualDensity:
VisualDensity.compact,
shape: MaterialStatePropertyAll(
RoundedRectangleBorder(
borderRadius: PretConfig
.thinBorderRadius,
)
: Container(),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: [
Text('${formatDate(entry.date)} '),
Text(formatTime(entry.date)),
],
),
const Padding(
padding: EdgeInsets.all(
PretConfig.minElementSpacing),
),
Expanded(
child: Wrap(
spacing: PretConfig.minElementSpacing,
runSpacing: PretConfig.minElementSpacing,
alignment: WrapAlignment.end,
children: entry.tags
.map((tag) => OutlinedButton(
style: const ButtonStyle(
minimumSize:
MaterialStatePropertyAll(
Size(32, 32),
),
),
padding:
MaterialStatePropertyAll(
EdgeInsets.all(
//PretConfig.minElementSpacing / 2,
PretConfig
.minElementSpacing),
)),
onPressed: () => ref
.read(entryFilterProvider
.notifier)
.setTagFilter(tag),
child: Text(
'#$tag',
)))
.toList()),
),
],
),
const Padding(
padding: EdgeInsets.only(
top: PretConfig.minElementSpacing),
),
...MarkdownGenerator(
generators: [latexGenerator],
inlineSyntaxList: [LatexSyntax()],
linesMargin: const EdgeInsets.all(0),
).buildWidgets(
stripTagOnlyLines(entry.input),
config: MarkdownConfig(configs: [
ImgConfig(builder: (url, attributes) {
if (url.contains(r'data:image/png;base64,')) {
return Image.memory(base64Decode(
url.replaceAll(
'data:image/png;base64,', '')));
} else {
return Image.network(url);
}
}),
const CodeConfig(
style: TextStyle(
fontFamily: 'Menlo',
backgroundColor: Color(0xffeff1f3),
visualDensity:
VisualDensity.compact,
shape:
MaterialStatePropertyAll(
RoundedRectangleBorder(
borderRadius: PretConfig
.thinBorderRadius,
),
),
padding:
MaterialStatePropertyAll(
EdgeInsets.all(
//PretConfig.minElementSpacing / 2,
PretConfig
.minElementSpacing),
)),
onPressed: () => ref
.read(entryFilterProvider
.notifier)
.setTagFilter(tag),
child: Text(
'#$tag',
)))
.toList()),
),
),
]),
),
entry.descendants.isNotEmpty && widget.isTopLevel
? Text.rich(
TextSpan(
text:
'${entry.descendants.length} descendants',
style: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => setState(() {
_descendantsShown =
!_descendantsShown;
}),
],
),
const Padding(
padding: EdgeInsets.only(
top: PretConfig.minElementSpacing),
),
...MarkdownGenerator(
generators: [latexGenerator],
inlineSyntaxList: [LatexSyntax()],
linesMargin: const EdgeInsets.all(0),
).buildWidgets(
stripTagOnlyLines(entry.input),
config: MarkdownConfig(configs: [
ImgConfig(builder: (url, attributes) {
if (url.contains(r'data:image/png;base64,')) {
return Image.memory(base64Decode(
url.replaceAll(
'data:image/png;base64,', '')));
} else {
return Image.network(url);
}
}),
const CodeConfig(
style: TextStyle(
fontFamily: 'Menlo',
backgroundColor: Color(0xffeff1f3),
),
)
: Container(),
]),
),
]),
),
entry.descendants.isNotEmpty
? Text.rich(
TextSpan(
text:
'${entry.descendants.length} descendants',
style: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => setState(() {
_descendantsShown =
!_descendantsShown;
}),
),
)
: Container(),
]),
),
),
_descendantsShown
? Container(
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ SPEC CHECKSUMS:
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
super_native_extensions: 85efee3a7495b46b04befcfc86ed12069264ebf3
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95
url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

Expand Down
2 changes: 1 addition & 1 deletion macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
Loading

0 comments on commit c391f7a

Please sign in to comment.