From 3cd5fe44c8648b381cc5ea39d6016abcceb58943 Mon Sep 17 00:00:00 2001 From: MayurSMahajan Date: Sat, 24 Aug 2024 16:11:02 +0530 Subject: [PATCH] refactor: extract edit and reset btns as widgets --- .../pages/settings_shortcuts_view.dart | 98 ++++++++++++------- 1 file changed, 63 insertions(+), 35 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart index 042559360e..4bbecde1e2 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart @@ -413,8 +413,8 @@ class _ShortcutSettingTileState extends State { if (isHovering) Row( children: [ - GestureDetector( - onTap: () { + EditShortcutBtn( + onEdit: () { if (widget.canStartEditing()) { setState(() { widget.onStartEditing(); @@ -422,41 +422,11 @@ class _ShortcutSettingTileState extends State { }); } }, - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: FlowyTooltip( - message: LocaleKeys.settings_shortcutsPage_editTooltip.tr(), - child: const FlowySvg( - FlowySvgs.edit_s, - size: Size.square(16), - ), - ), - ), ), const HSpace(16), - Opacity( - opacity: canReset ? 1 : 0.5, - child: GestureDetector( - onTap: canReset - ? () => _resetIndividualCommand(widget.command) - : null, - child: MouseRegion( - cursor: - canReset ? SystemMouseCursors.click : MouseCursor.defer, - child: FlowyTooltip( - message: canReset - ? LocaleKeys.settings_shortcutsPage_resetSingleTooltip - .tr() - : LocaleKeys - .settings_shortcutsPage_unavailableResetSingleTooltip - .tr(), - child: const FlowySvg( - FlowySvgs.restore_s, - size: Size.square(16), - ), - ), - ), - ), + ResetShortcutBtn( + onReset: () => _resetIndividualCommand(widget.command), + canReset: canReset, ), ], ), @@ -507,6 +477,64 @@ class _ShortcutSettingTileState extends State { } } +class EditShortcutBtn extends StatelessWidget { + const EditShortcutBtn({super.key, required this.onEdit}); + + final VoidCallback onEdit; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onEdit, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: FlowyTooltip( + message: LocaleKeys.settings_shortcutsPage_editTooltip.tr(), + child: const FlowySvg( + FlowySvgs.edit_s, + size: Size.square(16), + ), + ), + ), + ); + } +} + +class ResetShortcutBtn extends StatelessWidget { + const ResetShortcutBtn({ + super.key, + required this.onReset, + required this.canReset, + }); + + final bool canReset; + final VoidCallback onReset; + + @override + Widget build(BuildContext context) { + return Opacity( + opacity: canReset ? 1 : 0.5, + child: GestureDetector( + onTap: canReset ? onReset : null, + child: MouseRegion( + cursor: canReset ? SystemMouseCursors.click : MouseCursor.defer, + child: FlowyTooltip( + message: canReset + ? LocaleKeys.settings_shortcutsPage_resetSingleTooltip.tr() + : LocaleKeys + .settings_shortcutsPage_unavailableResetSingleTooltip + .tr(), + child: const FlowySvg( + FlowySvgs.restore_s, + size: Size.square(16), + ), + ), + ), + ), + ); + } +} + @visibleForTesting class KeyBadge extends StatelessWidget { const KeyBadge({super.key, required this.keyLabel});