From 5d8fe407a0559908147d103ebd3a1778d3c6c3be Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Thu, 7 Dec 2023 18:39:55 +0100 Subject: [PATCH] Add right click as alternative to long press --- app/lib/views/edit.dart | 3 + app/lib/views/toolbar/color.dart | 87 ++++++++++--------- app/lib/widgets/option_button.dart | 4 +- app/pubspec.lock | 4 +- app/pubspec.yaml | 2 +- .../metadata/android/en-US/changelogs/82.txt | 1 + 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/app/lib/views/edit.dart b/app/lib/views/edit.dart index 82cf896fac7a..e53c83f3c83a 100644 --- a/app/lib/views/edit.dart +++ b/app/lib/views/edit.dart @@ -273,6 +273,9 @@ class _EditToolbarState extends State { : () => context .read() .insertSelection(e, true), + onSecondaryPressed: () => context + .read() + .changeSelection(e), focussed: shortcuts.contains(i), selected: selected, highlighted: highlighted, diff --git a/app/lib/views/toolbar/color.dart b/app/lib/views/toolbar/color.dart index 9f064cef5719..f916d9b427d4 100644 --- a/app/lib/views/toolbar/color.dart +++ b/app/lib/views/toolbar/color.dart @@ -137,52 +137,53 @@ class _ColorToolbarViewState extends State { children: [ ...List.generate(palette.colors.length, (index) { final value = palette!.colors[index]; + void changeColor() async { + var palette = pack?.getPalette(colorPalette!.name); + final settingsCubit = context.read(); + final response = await showDialog< + ColorPickerResponse>( + context: context, + builder: (context) => + ColorPicker( + value: Color(value), + suggested: settingsCubit.state.recentColors + .map((e) => Color(e)) + .toList(), + secondaryActions: (close) => [ + OutlinedButton( + onPressed: () => + close(ColorPickerToolbarAction.delete), + child: + Text(AppLocalizations.of(context).delete), + ), + ], + ), + ); + if (response == null) return; + if (response.action == + ColorPickerToolbarAction.delete) { + palette = palette?.copyWith( + colors: List.from(palette.colors) + ..removeAt(index), + ); + } else { + palette = palette?.copyWith( + colors: List.from(palette.colors) + ..[index] = response.color, + ); + } + bloc.add(PackUpdated( + colorPalette!.pack, pack!.setPalette(palette!))); + widget.onChanged(response.color); + setState(() {}); + } + return ColorButton( color: Color(value), selected: value == color, - onTap: () { - widget.onChanged(value); - }, - onLongPress: () async { - var palette = pack?.getPalette(colorPalette!.name); - final settingsCubit = context.read(); - final response = await showDialog< - ColorPickerResponse>( - context: context, - builder: (context) => - ColorPicker( - value: Color(value), - suggested: settingsCubit.state.recentColors - .map((e) => Color(e)) - .toList(), - secondaryActions: (close) => [ - OutlinedButton( - onPressed: () => - close(ColorPickerToolbarAction.delete), - child: - Text(AppLocalizations.of(context).delete), - ), - ], - ), - ); - if (response == null) return; - if (response.action == - ColorPickerToolbarAction.delete) { - palette = palette?.copyWith( - colors: List.from(palette.colors) - ..removeAt(index), - ); - } else { - palette = palette?.copyWith( - colors: List.from(palette.colors) - ..[index] = response.color, - ); - } - bloc.add(PackUpdated( - colorPalette!.pack, pack!.setPalette(palette!))); - widget.onChanged(response.color); - setState(() {}); - }, + onTap: () => widget.onChanged(value), + onSecondaryTap: changeColor, + onLongPress: changeColor, ); }), Padding( diff --git a/app/lib/widgets/option_button.dart b/app/lib/widgets/option_button.dart index 9c896f2f280f..0adfdd895be9 100644 --- a/app/lib/widgets/option_button.dart +++ b/app/lib/widgets/option_button.dart @@ -4,7 +4,7 @@ import 'package:phosphor_flutter/phosphor_flutter.dart'; class OptionButton extends StatefulWidget { final Widget icon; final Widget? selectedIcon; - final VoidCallback? onPressed, onLongPressed; + final VoidCallback? onPressed, onSecondaryPressed, onLongPressed; final bool selected, highlighted, focussed; final String tooltip; @@ -14,6 +14,7 @@ class OptionButton extends StatefulWidget { required this.icon, this.selectedIcon, this.onPressed, + this.onSecondaryPressed, this.onLongPressed, this.selected = false, this.highlighted = false, @@ -72,6 +73,7 @@ class _OptionButtonState extends State radius: 12, borderRadius: BorderRadius.circular(12), onTap: widget.onPressed, + onSecondaryTap: widget.onSecondaryPressed, onLongPress: widget.onLongPressed == null ? null : () { diff --git a/app/pubspec.lock b/app/pubspec.lock index 9407358b8345..9634b6555fea 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -748,8 +748,8 @@ packages: dependency: "direct main" description: path: "packages/material_leap" - ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" - resolved-ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" + ref: "7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e" + resolved-ref: "7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e" url: "https://github.com/LinwoodDev/dart_pkgs.git" source: git version: "0.0.1" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index ff4fde09bc5b..4e2d470a2940 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -70,7 +70,7 @@ dependencies: material_leap: git: url: https://github.com/LinwoodDev/dart_pkgs.git - ref: 75b5ec0e51096ae169df3cd4f02c9f6affe22a81 + ref: 7a0a8dc7eaca62e83d85259dab12e11b5f14ac8e path: packages/material_leap lw_sysinfo: git: diff --git a/fastlane/metadata/android/en-US/changelogs/82.txt b/fastlane/metadata/android/en-US/changelogs/82.txt index d77c5df64bea..e08dbbab04ba 100644 --- a/fastlane/metadata/android/en-US/changelogs/82.txt +++ b/fastlane/metadata/android/en-US/changelogs/82.txt @@ -1,3 +1,4 @@ +* Add right click as alternative to long press * Change default scale of label to 5 * Improve documentation of shortcuts ([#534](https://github.com/LinwoodDev/Butterfly/issues/534)) * Fix closing of settings on click on mobile ([#537](https://github.com/LinwoodDev/Butterfly/issues/537))