From 463a446a5cf0808acb4f768850bc038980713197 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sat, 28 Dec 2024 14:17:25 +0100 Subject: [PATCH] Restructure tools in current index cubit --- app/lib/cubits/current_index.dart | 122 ++++++++++-- app/lib/cubits/current_index.freezed.dart | 82 +++++++-- app/lib/handlers/hand.dart | 4 +- app/lib/handlers/handler.dart | 47 ++--- app/lib/views/edit.dart | 214 +++++++++++----------- metadata/en-US/changelogs/127.txt | 2 + 6 files changed, 313 insertions(+), 158 deletions(-) create mode 100644 metadata/en-US/changelogs/127.txt diff --git a/app/lib/cubits/current_index.dart b/app/lib/cubits/current_index.dart index f263f0fc0ead..45b696be5d44 100644 --- a/app/lib/cubits/current_index.dart +++ b/app/lib/cubits/current_index.dart @@ -47,12 +47,14 @@ class CurrentIndex with _$CurrentIndex { SettingsCubit settingsCubit, TransformCubit transformCubit, NetworkingService networkingService, { - Handler? temporaryHandler, + Handler? temporaryHandler, @Default([]) List foregrounds, Selection? selection, @Default(false) bool pinned, List? temporaryForegrounds, + @Default({}) Map> toggleableHandlers, @Default([]) List networkingForegrounds, + @Default({}) Map> toggleableForegrounds, @Default(MouseCursor.defer) MouseCursor cursor, MouseCursor? temporaryCursor, @Default(false) bool temporaryClicked, @@ -64,9 +66,8 @@ class CurrentIndex with _$CurrentIndex { @Default(SaveState.unsaved) SaveState saved, PreferredSizeWidget? toolbar, PreferredSizeWidget? temporaryToolbar, - @Default({}) - Map rendererStates, - Map? temporaryRendererStates, + @Default({}) Map rendererStates, + @Default({}) Map? temporaryRendererStates, @Default(ViewOption()) ViewOption viewOption, @Default(HideState.visible) HideState hideUi, @Default(true) bool areaNavigatorCreate, @@ -124,7 +125,7 @@ class CurrentIndexCubit extends Cubit { DocumentBloc bloc, { int? index, BuildContext? context, - Handler? handler, + Handler? handler, }) async { resetInput(bloc); final blocState = bloc.state; @@ -236,7 +237,7 @@ class CurrentIndexCubit extends Cubit { state.handler.dispose(bloc); final handler = Handler.fromTool(tool); state.handler.dispose(bloc); - _disposeForegrounds(false); + _disposeForegrounds(); final foregrounds = handler.createForegrounds(this, docState.data, docState.page, docState.info, docState.currentArea); if (handler.setupForegrounds) { @@ -280,13 +281,10 @@ class CurrentIndexCubit extends Cubit { return null; } - void _disposeForegrounds([bool disposeTemporary = true]) { + void _disposeForegrounds() { for (final r in state.foregrounds) { r.dispose(); } - if (disposeTemporary) { - _disposeTemporaryForegrounds(); - } } void _disposeTemporaryForegrounds() { @@ -295,6 +293,52 @@ class CurrentIndexCubit extends Cubit { } } + void _disposeNetworkingForegrounds() { + for (final r in state.networkingForegrounds) { + r.dispose(); + } + } + + void _disposeToggleableForegrounds() { + for (final r in state.toggleableForegrounds.values.expand((e) => e)) { + r.dispose(); + } + } + + void _disposeAllForegrounds() { + _disposeForegrounds(); + _disposeTemporaryForegrounds(); + _disposeNetworkingForegrounds(); + _disposeToggleableForegrounds(); + } + + R useHandler(DocumentBloc bloc, int index, + R Function(Handler handler) callback) { + Handler? handler; + bool needsDispose = false; + if (state.index == index) { + handler = fetchHandler>(); + } else if (state.toggleableHandlers.containsKey(index)) { + handler = state.toggleableHandlers[index]; + } + if (handler == null) { + List tools = const []; + final blocState = bloc.state; + if (blocState is DocumentLoaded) tools = blocState.info.tools; + handler = Handler.fromTool(tools.elementAtOrNull(index)); + needsDispose = true; + } + final result = callback(handler); + if (needsDispose) { + if (result is Future) { + result.then((value) => handler?.dispose(bloc)); + } else { + handler.dispose(bloc); + } + } + return result; + } + Future refresh(DocumentLoaded blocState) async { final document = blocState.data; final page = blocState.page; @@ -303,7 +347,7 @@ class CurrentIndexCubit extends Cubit { final currentArea = blocState.currentArea; const mapEq = MapEquality(); if (!isClosed) { - _disposeForegrounds(); + _disposeAllForegrounds(); final temporaryForegrounds = state.temporaryHandler ?.createForegrounds(this, document, page, info, currentArea); if (temporaryForegrounds != null && @@ -317,6 +361,18 @@ class CurrentIndexCubit extends Cubit { await Future.wait(foregrounds .map((e) async => await e.setup(document, assetService, page))); } + final toggleableForegrounds = >{}; + for (final entry in state.toggleableHandlers.entries) { + final handler = entry.value; + final index = entry.key; + final foregrounds = + handler.createForegrounds(this, document, page, info, currentArea); + if (handler.setupForegrounds) { + await Future.wait(foregrounds + .map((e) async => await e.setup(document, assetService, page))); + } + toggleableForegrounds[index] = foregrounds; + } final rendererStates = state.handler.rendererStates; final temporaryRendererStates = state.temporaryHandler?.rendererStates; final statesChanged = !mapEq.equals(state.rendererStates, rendererStates); @@ -325,6 +381,7 @@ class CurrentIndexCubit extends Cubit { final shouldBake = statesChanged || temporaryStatesChanged; emit(state.copyWith( temporaryForegrounds: temporaryForegrounds, + toggleableForegrounds: toggleableForegrounds, foregrounds: foregrounds, cursor: state.handler.cursor ?? MouseCursor.defer, temporaryCursor: state.temporaryHandler?.cursor, @@ -367,12 +424,55 @@ class CurrentIndexCubit extends Cubit { return null; } + void enableHandler(DocumentBloc bloc, int index, Handler handler) { + final blocState = bloc.state; + if (blocState is! DocumentLoaded) return; + final document = blocState.data; + final page = blocState.page; + final info = blocState.info; + final currentArea = blocState.currentArea; + final foregrounds = + handler.createForegrounds(this, document, page, info, currentArea); + if (handler.setupForegrounds) { + Future.wait(foregrounds.map( + (e) async => await e.setup(document, blocState.assetService, page))); + } + emit(state.copyWith( + toggleableHandlers: Map.from(state.toggleableHandlers) + ..[index] = handler, + toggleableForegrounds: Map.from(state.toggleableForegrounds) + ..[index] = foregrounds)); + } + + bool disableHandler(DocumentBloc bloc, int index) { + final handler = state.toggleableHandlers[index]; + if (handler == null) { + return false; + } + handler.dispose(bloc); + final foregrounds = state.toggleableForegrounds[index]; + for (final r in foregrounds ?? []) { + r.dispose(); + } + emit(state.copyWith( + toggleableHandlers: Map.from(state.toggleableHandlers)..remove(index), + toggleableForegrounds: Map.from(state.toggleableForegrounds) + ..remove(index))); + return true; + } + + bool isHandlerEnabled(int index) => + state.toggleableHandlers.containsKey(index); + void reset(DocumentBloc bloc) { for (final r in renderers) { r.dispose(); } state.handler.dispose(bloc); state.temporaryHandler?.dispose(bloc); + for (var e in state.toggleableHandlers.values) { + e.dispose(bloc); + } _disposeForegrounds(); emit(state.copyWith( index: null, diff --git a/app/lib/cubits/current_index.freezed.dart b/app/lib/cubits/current_index.freezed.dart index f0b3a1cd1122..854370bbce85 100644 --- a/app/lib/cubits/current_index.freezed.dart +++ b/app/lib/cubits/current_index.freezed.dart @@ -22,14 +22,18 @@ mixin _$CurrentIndex { SettingsCubit get settingsCubit => throw _privateConstructorUsedError; TransformCubit get transformCubit => throw _privateConstructorUsedError; NetworkingService get networkingService => throw _privateConstructorUsedError; - Handler? get temporaryHandler => throw _privateConstructorUsedError; + Handler? get temporaryHandler => throw _privateConstructorUsedError; List get foregrounds => throw _privateConstructorUsedError; Selection? get selection => throw _privateConstructorUsedError; bool get pinned => throw _privateConstructorUsedError; List? get temporaryForegrounds => throw _privateConstructorUsedError; + Map> get toggleableHandlers => + throw _privateConstructorUsedError; List get networkingForegrounds => throw _privateConstructorUsedError; + Map> get toggleableForegrounds => + throw _privateConstructorUsedError; MouseCursor get cursor => throw _privateConstructorUsedError; MouseCursor? get temporaryCursor => throw _privateConstructorUsedError; bool get temporaryClicked => throw _privateConstructorUsedError; @@ -72,12 +76,14 @@ abstract class $CurrentIndexCopyWith<$Res> { SettingsCubit settingsCubit, TransformCubit transformCubit, NetworkingService networkingService, - Handler? temporaryHandler, + Handler? temporaryHandler, List foregrounds, Selection? selection, bool pinned, List? temporaryForegrounds, + Map> toggleableHandlers, List networkingForegrounds, + Map> toggleableForegrounds, MouseCursor cursor, MouseCursor? temporaryCursor, bool temporaryClicked, @@ -126,7 +132,9 @@ class _$CurrentIndexCopyWithImpl<$Res, $Val extends CurrentIndex> Object? selection = freezed, Object? pinned = null, Object? temporaryForegrounds = freezed, + Object? toggleableHandlers = null, Object? networkingForegrounds = null, + Object? toggleableForegrounds = null, Object? cursor = null, Object? temporaryCursor = freezed, Object? temporaryClicked = null, @@ -174,7 +182,7 @@ class _$CurrentIndexCopyWithImpl<$Res, $Val extends CurrentIndex> temporaryHandler: freezed == temporaryHandler ? _value.temporaryHandler : temporaryHandler // ignore: cast_nullable_to_non_nullable - as Handler?, + as Handler?, foregrounds: null == foregrounds ? _value.foregrounds : foregrounds // ignore: cast_nullable_to_non_nullable @@ -191,10 +199,18 @@ class _$CurrentIndexCopyWithImpl<$Res, $Val extends CurrentIndex> ? _value.temporaryForegrounds : temporaryForegrounds // ignore: cast_nullable_to_non_nullable as List?, + toggleableHandlers: null == toggleableHandlers + ? _value.toggleableHandlers + : toggleableHandlers // ignore: cast_nullable_to_non_nullable + as Map>, networkingForegrounds: null == networkingForegrounds ? _value.networkingForegrounds : networkingForegrounds // ignore: cast_nullable_to_non_nullable as List, + toggleableForegrounds: null == toggleableForegrounds + ? _value.toggleableForegrounds + : toggleableForegrounds // ignore: cast_nullable_to_non_nullable + as Map>, cursor: null == cursor ? _value.cursor : cursor // ignore: cast_nullable_to_non_nullable @@ -296,12 +312,14 @@ abstract class _$$CurrentIndexImplCopyWith<$Res> SettingsCubit settingsCubit, TransformCubit transformCubit, NetworkingService networkingService, - Handler? temporaryHandler, + Handler? temporaryHandler, List foregrounds, Selection? selection, bool pinned, List? temporaryForegrounds, + Map> toggleableHandlers, List networkingForegrounds, + Map> toggleableForegrounds, MouseCursor cursor, MouseCursor? temporaryCursor, bool temporaryClicked, @@ -349,7 +367,9 @@ class __$$CurrentIndexImplCopyWithImpl<$Res> Object? selection = freezed, Object? pinned = null, Object? temporaryForegrounds = freezed, + Object? toggleableHandlers = null, Object? networkingForegrounds = null, + Object? toggleableForegrounds = null, Object? cursor = null, Object? temporaryCursor = freezed, Object? temporaryClicked = null, @@ -397,7 +417,7 @@ class __$$CurrentIndexImplCopyWithImpl<$Res> temporaryHandler: freezed == temporaryHandler ? _value.temporaryHandler : temporaryHandler // ignore: cast_nullable_to_non_nullable - as Handler?, + as Handler?, foregrounds: null == foregrounds ? _value._foregrounds : foregrounds // ignore: cast_nullable_to_non_nullable @@ -414,10 +434,18 @@ class __$$CurrentIndexImplCopyWithImpl<$Res> ? _value._temporaryForegrounds : temporaryForegrounds // ignore: cast_nullable_to_non_nullable as List?, + toggleableHandlers: null == toggleableHandlers + ? _value._toggleableHandlers + : toggleableHandlers // ignore: cast_nullable_to_non_nullable + as Map>, networkingForegrounds: null == networkingForegrounds ? _value._networkingForegrounds : networkingForegrounds // ignore: cast_nullable_to_non_nullable as List, + toggleableForegrounds: null == toggleableForegrounds + ? _value._toggleableForegrounds + : toggleableForegrounds // ignore: cast_nullable_to_non_nullable + as Map>, cursor: null == cursor ? _value.cursor : cursor // ignore: cast_nullable_to_non_nullable @@ -504,7 +532,9 @@ class _$CurrentIndexImpl extends _CurrentIndex { this.selection, this.pinned = false, final List? temporaryForegrounds, + final Map> toggleableHandlers = const {}, final List networkingForegrounds = const [], + final Map> toggleableForegrounds = const {}, this.cursor = MouseCursor.defer, this.temporaryCursor, this.temporaryClicked = false, @@ -516,9 +546,8 @@ class _$CurrentIndexImpl extends _CurrentIndex { this.saved = SaveState.unsaved, this.toolbar, this.temporaryToolbar, - final Map rendererStates = - const {}, - final Map? temporaryRendererStates, + final Map rendererStates = const {}, + final Map? temporaryRendererStates = const {}, this.viewOption = const ViewOption(), this.hideUi = HideState.visible, this.areaNavigatorCreate = true, @@ -526,7 +555,9 @@ class _$CurrentIndexImpl extends _CurrentIndex { this.areaNavigatorAsk = false}) : _foregrounds = foregrounds, _temporaryForegrounds = temporaryForegrounds, + _toggleableHandlers = toggleableHandlers, _networkingForegrounds = networkingForegrounds, + _toggleableForegrounds = toggleableForegrounds, _pointers = pointers, _rendererStates = rendererStates, _temporaryRendererStates = temporaryRendererStates, @@ -545,7 +576,7 @@ class _$CurrentIndexImpl extends _CurrentIndex { @override final NetworkingService networkingService; @override - final Handler? temporaryHandler; + final Handler? temporaryHandler; final List _foregrounds; @override @JsonKey() @@ -571,6 +602,16 @@ class _$CurrentIndexImpl extends _CurrentIndex { return EqualUnmodifiableListView(value); } + final Map> _toggleableHandlers; + @override + @JsonKey() + Map> get toggleableHandlers { + if (_toggleableHandlers is EqualUnmodifiableMapView) + return _toggleableHandlers; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_toggleableHandlers); + } + final List _networkingForegrounds; @override @JsonKey() @@ -581,6 +622,16 @@ class _$CurrentIndexImpl extends _CurrentIndex { return EqualUnmodifiableListView(_networkingForegrounds); } + final Map> _toggleableForegrounds; + @override + @JsonKey() + Map> get toggleableForegrounds { + if (_toggleableForegrounds is EqualUnmodifiableMapView) + return _toggleableForegrounds; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_toggleableForegrounds); + } + @override @JsonKey() final MouseCursor cursor; @@ -625,6 +676,7 @@ class _$CurrentIndexImpl extends _CurrentIndex { final Map? _temporaryRendererStates; @override + @JsonKey() Map? get temporaryRendererStates { final value = _temporaryRendererStates; if (value == null) return null; @@ -652,7 +704,7 @@ class _$CurrentIndexImpl extends _CurrentIndex { @override String toString() { - return 'CurrentIndex(index: $index, handler: $handler, cameraViewport: $cameraViewport, settingsCubit: $settingsCubit, transformCubit: $transformCubit, networkingService: $networkingService, temporaryHandler: $temporaryHandler, foregrounds: $foregrounds, selection: $selection, pinned: $pinned, temporaryForegrounds: $temporaryForegrounds, networkingForegrounds: $networkingForegrounds, cursor: $cursor, temporaryCursor: $temporaryCursor, temporaryClicked: $temporaryClicked, lastPosition: $lastPosition, pointers: $pointers, buttons: $buttons, location: $location, embedding: $embedding, saved: $saved, toolbar: $toolbar, temporaryToolbar: $temporaryToolbar, rendererStates: $rendererStates, temporaryRendererStates: $temporaryRendererStates, viewOption: $viewOption, hideUi: $hideUi, areaNavigatorCreate: $areaNavigatorCreate, areaNavigatorExact: $areaNavigatorExact, areaNavigatorAsk: $areaNavigatorAsk)'; + return 'CurrentIndex(index: $index, handler: $handler, cameraViewport: $cameraViewport, settingsCubit: $settingsCubit, transformCubit: $transformCubit, networkingService: $networkingService, temporaryHandler: $temporaryHandler, foregrounds: $foregrounds, selection: $selection, pinned: $pinned, temporaryForegrounds: $temporaryForegrounds, toggleableHandlers: $toggleableHandlers, networkingForegrounds: $networkingForegrounds, toggleableForegrounds: $toggleableForegrounds, cursor: $cursor, temporaryCursor: $temporaryCursor, temporaryClicked: $temporaryClicked, lastPosition: $lastPosition, pointers: $pointers, buttons: $buttons, location: $location, embedding: $embedding, saved: $saved, toolbar: $toolbar, temporaryToolbar: $temporaryToolbar, rendererStates: $rendererStates, temporaryRendererStates: $temporaryRendererStates, viewOption: $viewOption, hideUi: $hideUi, areaNavigatorCreate: $areaNavigatorCreate, areaNavigatorExact: $areaNavigatorExact, areaNavigatorAsk: $areaNavigatorAsk)'; } /// Create a copy of CurrentIndex @@ -672,12 +724,14 @@ abstract class _CurrentIndex extends CurrentIndex { final SettingsCubit settingsCubit, final TransformCubit transformCubit, final NetworkingService networkingService, - {final Handler? temporaryHandler, + {final Handler? temporaryHandler, final List foregrounds, final Selection? selection, final bool pinned, final List? temporaryForegrounds, + final Map> toggleableHandlers, final List networkingForegrounds, + final Map> toggleableForegrounds, final MouseCursor cursor, final MouseCursor? temporaryCursor, final bool temporaryClicked, @@ -711,7 +765,7 @@ abstract class _CurrentIndex extends CurrentIndex { @override NetworkingService get networkingService; @override - Handler? get temporaryHandler; + Handler? get temporaryHandler; @override List get foregrounds; @override @@ -721,8 +775,12 @@ abstract class _CurrentIndex extends CurrentIndex { @override List? get temporaryForegrounds; @override + Map> get toggleableHandlers; + @override List get networkingForegrounds; @override + Map> get toggleableForegrounds; + @override MouseCursor get cursor; @override MouseCursor? get temporaryCursor; diff --git a/app/lib/handlers/hand.dart b/app/lib/handlers/hand.dart index 32448652692e..3a4365aec4b0 100644 --- a/app/lib/handlers/hand.dart +++ b/app/lib/handlers/hand.dart @@ -23,6 +23,6 @@ class GeneralHandHandler extends Handler { _moved ? SystemMouseCursors.grabbing : SystemMouseCursors.grab; } -class HandHandler extends GeneralHandHandler { - HandHandler([super.data]); +class HandHandler extends GeneralHandHandler { + HandHandler([HandTool? tool]) : super(tool ?? HandTool()); } diff --git a/app/lib/handlers/handler.dart b/app/lib/handlers/handler.dart index 45d857964c6e..35351a553e8e 100644 --- a/app/lib/handlers/handler.dart +++ b/app/lib/handlers/handler.dart @@ -221,30 +221,31 @@ abstract class Handler { return Handler.fromTool(tool); } - static Handler fromTool(Tool tool) { + static Handler fromTool(T? tool) { return switch (tool) { - HandTool e => HandHandler(e) as Handler, - SelectTool e => SelectHandler(e), - ImportTool e => ImportHandler(e), - UndoTool e => UndoHandler(e), - RedoTool e => RedoHandler(e), - LabelTool e => LabelHandler(e), - PenTool e => PenHandler(e), - EraserTool e => EraserHandler(e), - PathEraserTool e => PathEraserHandler(e), - CollectionTool e => CollectionHandler(e), - AreaTool e => AreaHandler(e), - LaserTool e => LaserHandler(e), - ShapeTool e => ShapeHandler(e), - StampTool e => StampHandler(e), - PresentationTool e => PresentationHandler(e), - SpacerTool e => SpacerHandler(e), - FullScreenTool e => FullScreenHandler(e), - TextureTool e => TextureHandler(e), - AssetTool e => AssetHandler(e), - EyeDropperTool e => EyeDropperHandler(e), - ExportTool e => ExportHandler(e), - }; + HandTool() => HandHandler(tool), + SelectTool() => SelectHandler(tool), + ImportTool() => ImportHandler(tool), + UndoTool() => UndoHandler(tool), + RedoTool() => RedoHandler(tool), + LabelTool() => LabelHandler(tool), + PenTool() => PenHandler(tool), + EraserTool() => EraserHandler(tool), + PathEraserTool() => PathEraserHandler(tool), + CollectionTool() => CollectionHandler(tool), + AreaTool() => AreaHandler(tool), + LaserTool() => LaserHandler(tool), + ShapeTool() => ShapeHandler(tool), + StampTool() => StampHandler(tool), + PresentationTool() => PresentationHandler(tool), + SpacerTool() => SpacerHandler(tool), + FullScreenTool() => FullScreenHandler(tool), + TextureTool() => TextureHandler(tool), + AssetTool() => AssetHandler(tool), + EyeDropperTool() => EyeDropperHandler(tool), + ExportTool() => ExportHandler(tool), + _ => GeneralHandHandler(tool), + } as Handler; } PreferredSizeWidget? getToolbar(DocumentBloc bloc) => null; diff --git a/app/lib/views/edit.dart b/app/lib/views/edit.dart index 1e1b4974adae..ea95380670d2 100644 --- a/app/lib/views/edit.dart +++ b/app/lib/views/edit.dart @@ -82,37 +82,31 @@ class _EditToolbarState extends State { height: direction == Axis.horizontal ? fullSize : null, width: direction == Axis.horizontal ? null : fullSize, child: BlocBuilder( - buildWhen: (previous, current) => - previous is! DocumentLoadSuccess || - current is! DocumentLoadSuccess || - previous.tool != current.tool || - previous.info.tools != current.info.tools, builder: (context, state) { - if (state is! DocumentLoadSuccess) return Container(); - final tools = state.info.tools; + if (state is! DocumentLoadSuccess) return Container(); + final tools = state.info.tools; - return BlocBuilder( - buildWhen: (previous, current) => - previous.index != current.index || - previous.handler != current.handler || - previous.temporaryHandler != - current.temporaryHandler || - previous.selection != current.selection, - builder: (context, currentIndex) { - return Card( - elevation: 10, - child: _buildBody( - state, - currentIndex, - settings, - tools, - shortcuts, - size, - ), - ); - }, + return BlocBuilder( + buildWhen: (previous, current) => + previous.index != current.index || + previous.handler != current.handler || + previous.temporaryHandler != current.temporaryHandler || + previous.selection != current.selection, + builder: (context, currentIndex) { + return Card( + elevation: 10, + child: _buildBody( + state, + currentIndex, + settings, + tools, + shortcuts, + size, + ), ); - })); + }, + ); + })); }), ); } @@ -169,7 +163,6 @@ class _EditToolbarState extends State { .read() .changeSelection(tempData), onPressed: () { - if (tempData == null) return; if (_mouseState == _MouseState.multi) { context .read() @@ -267,89 +260,90 @@ class _EditToolbarState extends State { ], ); } - var e = tools[i]; - final selected = i == currentIndex.index; - final highlighted = currentIndex.selection?.selected - .any((element) => element.hashCode == e.hashCode) ?? - false; - String tooltip = e.name.trim(); - if (tooltip.isEmpty) { - tooltip = e.getLocalizedName(context); - } - final bloc = context.read(); + return context.read().useHandler(bloc, i, + (handler) { + final selected = i == currentIndex.index; + final tool = handler.data; + final highlighted = currentIndex.selection?.selected.any( + (element) => + element.hashCode == handler.hashCode) ?? + false; + String tooltip = tool.name.trim(); + if (tooltip.isEmpty) { + tooltip = tool.getLocalizedName(context); + } - final handler = Handler.fromTool(e); - - final color = - handler.getStatus(context.read()) == - ToolStatus.disabled - ? Theme.of(context).disabledColor - : null; - var icon = handler.getIcon(bloc) ?? - e.icon(selected - ? PhosphorIconsStyle.fill - : PhosphorIconsStyle.light); - final toolWidget = Padding( - padding: const EdgeInsets.symmetric(horizontal: 4.0), - child: OptionButton( - tooltip: tooltip, - onLongPressed: selected || highlighted - ? null - : () => context - .read() - .insertSelection(e, true), - onSecondaryPressed: () => context - .read() - .changeSelection(e), - focussed: shortcuts.contains(i), - selected: selected, - alwaysShowBottom: e.isAction(), - highlighted: highlighted, - bottomIcon: PhosphorIcon(e.isAction() - ? PhosphorIconsLight.playCircle - : isMobile - ? PhosphorIconsLight.caretUp - : switch (settings.toolbarPosition) { - ToolbarPosition.top || - ToolbarPosition.inline => - PhosphorIconsLight.caretDown, - ToolbarPosition.bottom => - PhosphorIconsLight.caretUp, - ToolbarPosition.left => - PhosphorIconsLight.caretRight, - ToolbarPosition.right => - PhosphorIconsLight.caretLeft, - }), - selectedIcon: _buildIcon(icon, size, color), - icon: _buildIcon(icon, size, color), - onPressed: () { - if (_mouseState == _MouseState.multi) { - context - .read() - .insertSelection(e, true); - } else if (!selected || temp != null) { - context - .read() - .resetSelection(); - context.read().changeTool( - context.read(), - index: i, - handler: handler, - context: context, - ); - } else { - context - .read() - .changeSelection(e, true); - } - })); - return ReorderableGridDelayedDragStartListener( - index: i, - key: ObjectKey(i), - enabled: selected || highlighted, - child: toolWidget, - ); + final color = + handler.getStatus(context.read()) == + ToolStatus.disabled + ? Theme.of(context).disabledColor + : null; + var icon = handler.getIcon(bloc) ?? + tool.icon(selected + ? PhosphorIconsStyle.fill + : PhosphorIconsStyle.light); + final toolWidget = Padding( + padding: const EdgeInsets.symmetric(horizontal: 4.0), + child: OptionButton( + tooltip: tooltip, + onLongPressed: selected || highlighted + ? null + : () => context + .read() + .insertSelection(tool, true), + onSecondaryPressed: () => context + .read() + .changeSelection(tool), + focussed: shortcuts.contains(i), + selected: selected, + alwaysShowBottom: tool.isAction(), + highlighted: highlighted, + bottomIcon: PhosphorIcon(tool.isAction() + ? PhosphorIconsLight.playCircle + : isMobile + ? PhosphorIconsLight.caretUp + : switch (settings.toolbarPosition) { + ToolbarPosition.top || + ToolbarPosition.inline => + PhosphorIconsLight.caretDown, + ToolbarPosition.bottom => + PhosphorIconsLight.caretUp, + ToolbarPosition.left => + PhosphorIconsLight.caretRight, + ToolbarPosition.right => + PhosphorIconsLight.caretLeft, + }), + selectedIcon: _buildIcon(icon, size, color), + icon: _buildIcon(icon, size, color), + onPressed: () { + if (_mouseState == _MouseState.multi) { + context + .read() + .insertSelection(tool, true); + } else if (!selected || temp != null) { + context + .read() + .resetSelection(); + context.read().changeTool( + context.read(), + index: i, + handler: handler, + context: context, + ); + } else { + context + .read() + .changeSelection(tool, true); + } + })); + return ReorderableGridDelayedDragStartListener( + index: i, + key: ObjectKey(i), + enabled: selected || highlighted, + child: toolWidget, + ); + }); }, ), onReorder: (oldIndex, newIndex) { diff --git a/metadata/en-US/changelogs/127.txt b/metadata/en-US/changelogs/127.txt new file mode 100644 index 000000000000..9a1762cd8878 --- /dev/null +++ b/metadata/en-US/changelogs/127.txt @@ -0,0 +1,2 @@ +* Add password protected notes ([#771](https://github.com/LinwoodDev/Butterfly/issues/771)) +* Fix undo/redo tools not showing status correctly \ No newline at end of file