Skip to content

Commit 6d8bd28

Browse files
committed
Change quite a few cool things
1 parent 179cda7 commit 6d8bd28

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

addons/banana/lib/banana.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class MakeRootSayBanana extends DictionariesAddon {
2525

2626
@override
2727
FutureOr<void> onRegister(bool debug) {
28-
DictionariesWidgetInjection(target: DictionariesWidgetInjectionTarget.rootNode, build: (context, widget) {
29-
widget = widget as DictionariesRootNodeWidget;
28+
DictionariesWidgetInjection<DictionariesRootNodeWidget>(target: DictionariesWidgetInjectionTarget.rootNode, build: (context, widget) {
3029
return widget..nameText = SelectableText("Banana!")..addWidget(DictionariesRootNodeSlot.beforeContextMenuButton, IconButton(onPressed: () {
3130
banana(context);
3231
}, icon: Text('🍌')));

lib/addons.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,30 @@ enum DictionariesWidgetInjectionTarget {
9191
rootNode,
9292
}
9393

94-
final class DictionariesWidgetInjection extends DictionariesUIInjection {
94+
final class DictionariesWidgetInjection<T extends DictionariesWidget> extends DictionariesUIInjection {
9595
final DictionariesWidgetInjectionTarget target;
96-
final DictionariesWidget Function(BuildContext context, DictionariesWidget widget) build;
96+
final DictionariesWidget Function(BuildContext context, T widget) _build;
97+
98+
DictionariesWidget build(BuildContext context, DictionariesWidget widget) {
99+
if (widget is T) {
100+
return _build(context, widget);
101+
} else {
102+
Logger.warn("Detected type mismatch when building ${this.runtimeType}.");
103+
return widget;
104+
}
105+
}
97106

98-
const DictionariesWidgetInjection({required this.target, required this.build});
107+
const DictionariesWidgetInjection({required this.target, required DictionariesWidget Function(BuildContext context, T widget) build}) : _build = build;
99108
}
100109

101110
final class DictionariesMaterialAppInjection extends DictionariesUIInjection {
102111
final MaterialApp Function(BuildContext context, MaterialApp widget) build;
103112

104113
const DictionariesMaterialAppInjection({required this.build});
114+
115+
void inject(AddonContext context) {
116+
injectedAddonUIs.add((this, context));
117+
}
105118
}
106119

107120
class DictionariesMenuBarInjection {

lib/src/editor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class ObjectEditorState extends State<ObjectEditorDesktop> {
363363
thickness: 1,
364364
color: Colors.grey,
365365
),
366-
).apply(context, DictionariesWidgetInjectionTarget.rootNode);
366+
).apply<DictionariesRootNodeWidget>(context, DictionariesWidgetInjectionTarget.rootNode);
367367
},
368368
);
369369
}

lib/src/main.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'package:dictionaries/src/preview.dart';
55
import 'package:dictionaries/tabview.dart';
66
import 'package:flutter/material.dart';
77

8+
const bool showSettings = false;
9+
810
enum DataType {
911
json,
1012
yaml,
@@ -69,7 +71,7 @@ class _ObjectEditorPageState extends State<ObjectEditorPage> with TickerProvider
6971
@override
7072
void initState() {
7173
root = widget.root;
72-
tabs = [ObjectEditorTabType.base, ObjectEditorTabType.settings].map((x) => UserFocusedTab<ObjectEditorTabType>(attachment: x, child: objectEditorTabTypeContent(context, x, root), thumbnail: objectEditorTabTypeToWidget(x), reorderable: false)).toList();
74+
tabs = [ObjectEditorTabType.base, ObjectEditorTabType.settings].where((x) => objectEditorTabTypeToWidget(x) != null).map((x) => UserFocusedTab<ObjectEditorTabType>(attachment: x, child: objectEditorTabTypeContent(context, x, root), thumbnail: objectEditorTabTypeToWidget(x)!, reorderable: false)).toList();
7375
controller = UserFocusedTabViewController(tabs);
7476
super.initState();
7577
}
@@ -112,7 +114,7 @@ class _ObjectEditorPageState extends State<ObjectEditorPage> with TickerProvider
112114
}, onSelected: (value) {
113115
if (value is DataType) {
114116
var type = dataTypeToObjectEditorTabType(value);
115-
controller!.addTab(UserFocusedTab(child: objectEditorTabTypeContent(context, type, root), thumbnail: objectEditorTabTypeToWidget(type), attachment: type, showCloseButton: true));
117+
controller!.addTab(UserFocusedTab(child: objectEditorTabTypeContent(context, type, root), thumbnail: objectEditorTabTypeToWidget(type)!, attachment: type, showCloseButton: true));
116118
}
117119
}),
118120
),
@@ -124,13 +126,13 @@ class _ObjectEditorPageState extends State<ObjectEditorPage> with TickerProvider
124126
);
125127
}
126128

127-
Widget objectEditorTabTypeToWidget(ObjectEditorTabType objectEditorTabType) {
129+
Widget? objectEditorTabTypeToWidget(ObjectEditorTabType objectEditorTabType) {
128130
switch (objectEditorTabType) {
129131
case ObjectEditorTabType.base: return Icon(Icons.edit);
130132
case ObjectEditorTabType.json: return Text("JSON");
131133
case ObjectEditorTabType.yaml: return Text("YAML");
132134
case ObjectEditorTabType.plist: return Text("PList");
133-
case ObjectEditorTabType.settings: return Icon(Icons.settings);
135+
case ObjectEditorTabType.settings: return showSettings ? Icon(Icons.settings) : null;
134136
}
135137
}
136138

lib/src/nodes.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class RootNode extends AllNodeData {
478478

479479
XmlBuilder builder = XmlBuilder();
480480
builder.processing('xml', 'version="1.0" encoding="UTF-8"');
481+
builder.doctype("plist", publicId: "-//Apple//DTD PLIST 1.0//EN", systemId: "http://www.apple.com/DTDs/PropertyList-1.0.dtd");
481482

482483
builder.element('plist', nest: () {
483484
builder.attribute('version', '1.0');

lib/src/preview.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,29 @@ class _ObjectEditorPreviewState extends State<ObjectEditorPreview> {
6666
],
6767
),
6868
body: Scrollbar(
69-
controller: horizontalScrollController,
70-
notificationPredicate: (notif) => notif.metrics.axis == Axis.horizontal,
69+
controller: verticalScrollController,
7170
child: SingleChildScrollView(
72-
controller: horizontalScrollController,
73-
scrollDirection: Axis.horizontal,
74-
child: ConstrainedBox(
75-
constraints: BoxConstraints(
76-
minWidth: MediaQuery.of(context).size.width - 4,
77-
),
78-
child: HighlightView(
79-
text!,
80-
language: dataTypeToLanguage(widget.type),
81-
theme: isLight ? atomOneLightTheme : gruvboxDarkTheme,
82-
padding: EdgeInsets.all(12),
83-
textStyle: TextStyle(
84-
fontFamily: 'monospace',
85-
fontSize: 14,
71+
controller: verticalScrollController,
72+
child: Scrollbar(
73+
controller: horizontalScrollController,
74+
notificationPredicate: (notif) => notif.metrics.axis == Axis.horizontal,
75+
child: SingleChildScrollView(
76+
controller: horizontalScrollController,
77+
scrollDirection: Axis.horizontal,
78+
child: ConstrainedBox(
79+
constraints: BoxConstraints(
80+
minWidth: MediaQuery.of(context).size.width - 4,
81+
),
82+
child: HighlightView(
83+
text!,
84+
language: dataTypeToLanguage(widget.type),
85+
theme: isLight ? atomOneLightTheme : gruvboxDarkTheme,
86+
padding: EdgeInsets.all(12),
87+
textStyle: TextStyle(
88+
fontFamily: 'monospace',
89+
fontSize: 14,
90+
),
91+
),
8692
),
8793
),
8894
),

0 commit comments

Comments
 (0)