Skip to content

Commit c683c37

Browse files
committed
Add override background to template dialog, closes #1119
1 parent 310ddae commit c683c37

4 files changed

Lines changed: 132 additions & 40 deletions

File tree

app/lib/dialogs/template.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,8 @@ List<Widget> _buildTemplateMenuChildren(
12921292
final isDefault = settings.defaultTemplate == path;
12931293
final template = file.data!;
12941294
final metadata = template.getMetadata()!;
1295+
final templateBackgrounds =
1296+
template.getPage()?.backgrounds ?? const <Background>[];
12951297

12961298
return [
12971299
if (!isCore && fileSystem.storage == null)
@@ -1311,6 +1313,33 @@ List<Widget> _buildTemplateMenuChildren(
13111313
_overrideTools(fileSystem, bloc, [file]);
13121314
},
13131315
),
1316+
if (bloc != null && templateBackgrounds.isNotEmpty)
1317+
SubmenuButton(
1318+
leadingIcon: const PhosphorIcon(PhosphorIconsLight.image),
1319+
menuChildren: [
1320+
MenuItemButton(
1321+
leadingIcon: const PhosphorIcon(PhosphorIconsLight.file),
1322+
child: Text(AppLocalizations.of(context).currentPage),
1323+
onPressed: () {
1324+
_applyTemplateBackgroundsToPages(bloc, template, [null]);
1325+
},
1326+
),
1327+
MenuItemButton(
1328+
leadingIcon: const PhosphorIcon(PhosphorIconsLight.files),
1329+
child: Text(AppLocalizations.of(context).allPages),
1330+
onPressed: () {
1331+
final state = bloc.state;
1332+
if (state is! DocumentLoadSuccess) return;
1333+
_applyTemplateBackgroundsToPages(
1334+
bloc,
1335+
template,
1336+
state.data.getPages(true),
1337+
);
1338+
},
1339+
),
1340+
],
1341+
child: Text(AppLocalizations.of(context).applyBackground),
1342+
),
13141343
MenuItemButton(
13151344
leadingIcon: const PhosphorIcon(PhosphorIconsLight.copy),
13161345
child: Text(AppLocalizations.of(context).duplicate),
@@ -1372,3 +1401,37 @@ List<Widget> _buildTemplateMenuChildren(
13721401
),
13731402
];
13741403
}
1404+
1405+
void _applyTemplateBackgroundsToPages(
1406+
DocumentBloc bloc,
1407+
NoteData template,
1408+
List<String?> pageNames,
1409+
) {
1410+
final state = bloc.state;
1411+
if (state is! DocumentLoadSuccess) return;
1412+
final backgrounds = template.getPage()?.backgrounds ?? const <Background>[];
1413+
for (final background in backgrounds.whereType<SourcedElement>()) {
1414+
final uri = Uri.tryParse(background.source);
1415+
if (uri?.scheme.isNotEmpty ?? true) continue;
1416+
final asset = template.getAsset(background.source);
1417+
if (asset != null) {
1418+
bloc.add(AssetUpdated(background.source, asset));
1419+
}
1420+
}
1421+
final originalPageName = state.pageName;
1422+
var activePageName = originalPageName;
1423+
for (final pageName in pageNames) {
1424+
if (pageName == null) {
1425+
bloc.add(DocumentBackgroundsChanged(backgrounds));
1426+
continue;
1427+
}
1428+
if (pageName != activePageName) {
1429+
bloc.add(PageChanged(pageName));
1430+
activePageName = pageName;
1431+
}
1432+
bloc.add(DocumentBackgroundsChanged(backgrounds));
1433+
}
1434+
if (activePageName != originalPageName) {
1435+
bloc.add(PageChanged(originalPageName));
1436+
}
1437+
}

app/lib/l10n/app_en.arb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
"description": "Spacing property"
9999
},
100100
"background": "Background",
101+
"applyBackground": "Apply background",
102+
"currentPage": "Current page",
103+
"allPages": "All pages",
101104
"box": "Box",
102105
"@box": {
103106
"description": "Box shape"
@@ -144,6 +147,13 @@
144147
"description": "Style property"
145148
},
146149
"solid": "Solid",
150+
"solidColor": "Solid color",
151+
"gradient": "Gradient",
152+
"gradientType": "Gradient type",
153+
"linear": "Linear",
154+
"radial": "Radial",
155+
"tint": "Tint",
156+
"blur": "Blur",
147157
"double": "Double",
148158
"dotted": "Dotted",
149159
"dottedDark": "Dotted dark",
@@ -954,6 +964,9 @@
954964
"ascending": "Ascending",
955965
"descending": "Descending",
956966
"imageScale": "Image scale",
967+
"svgScale": "SVG scale",
968+
"noImageSelected": "No image selected",
969+
"noSvgSelected": "No SVG selected",
957970
"select": "Select",
958971
"@select": {
959972
"description": "Select action"
@@ -1223,6 +1236,14 @@
12231236
"@offset": {
12241237
"description": "Offset property"
12251238
},
1239+
"end": "End",
1240+
"radius": "Radius",
1241+
"focalPoint": "Focal point",
1242+
"useOffCenterStartPoint": "Use an off-center start point",
1243+
"focal": "Focal",
1244+
"focalRadius": "Focal radius",
1245+
"colorStops": "Color stops",
1246+
"addStop": "Add stop",
12261247
"positionDependent": "Position dependent",
12271248
"flipHorizontal": "Flip horizontal",
12281249
"flipVertical": "Flip vertical",

0 commit comments

Comments
 (0)