Skip to content

Commit

Permalink
Add option to import svg as text, closes #596
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jan 1, 2025
1 parent 8f09746 commit e752ebb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 35 deletions.
2 changes: 1 addition & 1 deletion api/lib/src/models/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum LabelMode { markdown, text }

enum Axis2D { horizontal, vertical }

enum ImportType { image, camera, svg, pdf, document, markdown, xopp }
enum ImportType { image, camera, svg, svgText, pdf, document, markdown, xopp }

enum SelectMode { rectangle, lasso }

Expand Down
1 change: 1 addition & 0 deletions api/lib/src/models/tool.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions app/lib/handlers/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,47 @@ Future<void> showImportAssetWizard(ImportType type, BuildContext context,
return importAsset(AssetFileType.image, content);
case ImportType.svg:
return importWithDialog(AssetFileType.svg);
case ImportType.svgText:
final controller = TextEditingController();
final result = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(AppLocalizations.of(context).import),
scrollable: true,
content: TextField(
maxLines: null,
minLines: 3,
controller: controller,
autocorrect: false,
autofocus: true,
decoration: InputDecoration(
hintText: AppLocalizations.of(context).svgText,
border: OutlineInputBorder(),
suffixIcon: IconButton(
icon: const Icon(PhosphorIconsLight.clipboard),
onPressed: () async {
final clipboard =
await Clipboard.getData(Clipboard.kTextPlain);
final data = clipboard?.text;
if (data != null) controller.text = data;
},
),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
),
ElevatedButton(
onPressed: () => Navigator.pop(context, true),
child: Text(AppLocalizations.of(context).import),
),
],
),
);
if (result != true) return;
return importAsset(AssetFileType.svg, utf8.encode(controller.text));
case ImportType.pdf:
return importWithDialog(AssetFileType.pdf);
case ImportType.document:
Expand Down
3 changes: 2 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -635,5 +635,6 @@
"unencryptWarning": "This will unencrypt the document. The password will be removed and everyone with access will be able to open it.",
"confirmPassword": "Confirm password",
"passwordMismatch": "The passwords do not match",
"action": "Action"
"action": "Action",
"svgText": "SVG text"
}
2 changes: 2 additions & 0 deletions app/lib/visualizer/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ extension ImportTypeVisualizer on ImportType {
ImportType.image => AppLocalizations.of(context).image,
ImportType.pdf => AppLocalizations.of(context).pdf,
ImportType.svg => AppLocalizations.of(context).svg,
ImportType.svgText => AppLocalizations.of(context).svgText,
ImportType.camera => AppLocalizations.of(context).camera,
ImportType.markdown => AppLocalizations.of(context).markdown,
ImportType.xopp => 'Xournal++',
Expand All @@ -172,6 +173,7 @@ extension ImportTypeVisualizer on ImportType {
ImportType.image => PhosphorIcons.image,
ImportType.pdf => PhosphorIcons.filePdf,
ImportType.svg => PhosphorIcons.fileSvg,
ImportType.svgText => PhosphorIcons.article,
ImportType.camera => PhosphorIcons.camera,
ImportType.markdown => PhosphorIcons.textbox,
ImportType.xopp => PhosphorIcons.notebook,
Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1590,10 +1590,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "8b338d4486ab3fbc0ba0db9f9b4f5239b6697fcee427939a40e720cbb9ee0a69"
sha256: "154360849a56b7b67331c21f09a386562d88903f90a1099c5987afc1912e1f29"
url: "https://pub.dev"
source: hosted
version: "5.9.0"
version: "5.10.0"
win32_registry:
dependency: transitive
description:
Expand Down
62 changes: 31 additions & 31 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metadata/en-US/changelogs/127.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add color property
* Move grid into own tool
* Add password protected notes ([#771](https://github.com/LinwoodDev/Butterfly/issues/771))
* Add option to import svg as text ([#596](https://github.com/LinwoodDev/Butterfly/issues/596))
* Fix undo/redo tools not showing status correctly
* Fix grid not working correctly
* Fix capture thumbnail uses wrong position
Expand Down

0 comments on commit e752ebb

Please sign in to comment.