Skip to content

Commit

Permalink
Add presets for styles view
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Mar 16, 2023
1 parent a85a099 commit 3b20e52
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/lib/dialogs/packs/styles/paragraphs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class _ParagraphsStyleViewState extends State<ParagraphsStyleView> {
menuChildren:
DocumentDefaults.getParagraphTranslations(context)
.entries
.where((element) => !widget
.value.paragraphProperties
.containsKey(element.key))
.map(
(e) => MenuItemButton(
child: Text(e.value),
Expand All @@ -128,7 +131,7 @@ class _ParagraphsStyleViewState extends State<ParagraphsStyleView> {
.toList(),
),
if (_currentStyle != null) ...[
const Divider(),
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.pencilLight),
onPressed: () async {
Expand Down
41 changes: 37 additions & 4 deletions app/lib/dialogs/packs/styles/texts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

import '../../../models/defaults.dart';
import 'text.dart';

class TextsStyleView extends StatefulWidget {
Expand Down Expand Up @@ -34,11 +35,10 @@ class _TextsStyleViewState extends State<TextsStyleView> {
@override
void didUpdateWidget(covariant TextsStyleView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.value != widget.value) {
if (oldWidget.value != widget.value && _currentStyle != null) {
setState(() {
if (!widget.value.spanProperties.containsKey(_currentStyle!) &&
_currentStyle != null) {
_currentStyle = widget.value.spanProperties.keys.firstOrNull;
if (!widget.value.spanProperties.containsKey(_currentStyle!)) {
_currentStyle = widget.value.paragraphProperties.keys.firstOrNull;
}
});
}
Expand Down Expand Up @@ -94,7 +94,40 @@ class _TextsStyleViewState extends State<TextsStyleView> {
));
},
),
MenuAnchor(
builder: (context, controller, _) {
return IconButton(
icon: const Icon(PhosphorIcons.listLight),
onPressed: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
);
},
menuChildren: DocumentDefaults.getSpanTranslations(context)
.entries
.where((element) =>
!widget.value.spanProperties.containsKey(element.key))
.map(
(e) => MenuItemButton(
child: Text(e.value),
onPressed: () {
widget.onChanged(widget.value.copyWith(
spanProperties: {
...widget.value.spanProperties,
e.key: const text.DefinedSpanProperty(),
},
));
},
),
)
.toList(),
),
if (_currentStyle != null) ...[
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.pencilLight),
onPressed: () async {
Expand Down
1 change: 0 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@
},
"code": "Code",
"quote": "Quote",
"blockquote": "Blockquote",
"link": "Link",
"checkbox": "Checkbox",
"deleted": "Deleted",
Expand Down
6 changes: 3 additions & 3 deletions app/lib/models/defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class DocumentDefaults {
'p': AppLocalizations.of(context).paragraph,
'quote': AppLocalizations.of(context).quote,
'code': AppLocalizations.of(context).code,
'blockquote': AppLocalizations.of(context).blockquote,
'blockquote': AppLocalizations.of(context).quote,
};

static String translateParagraph(String key, BuildContext context) =>
translate(key, getParagraphTranslations(context));

static Map<String, String> getBlockTranslations(BuildContext context) => {
static Map<String, String> getSpanTranslations(BuildContext context) => {
'a': AppLocalizations.of(context).link,
'checkbox': AppLocalizations.of(context).checkbox,
'del': AppLocalizations.of(context).deleted,
Expand All @@ -62,5 +62,5 @@ class DocumentDefaults {
};

static String translateBlock(String key, BuildContext context) =>
translate(key, getBlockTranslations(context));
translate(key, getSpanTranslations(context));
}

0 comments on commit 3b20e52

Please sign in to comment.