mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: copy cell content
This commit is contained in:
parent
1a83cb65ed
commit
bb22ca5d93
@ -62,7 +62,7 @@ abstract class GridCellWidget extends StatefulWidget implements CellAccessory, C
|
||||
final GridCellFocusListener beginFocus = GridCellFocusListener();
|
||||
|
||||
@override
|
||||
final Map<CellKeyboardKey, CellKeyboardAction> keyboardActionHandlers = {};
|
||||
final Map<CellKeyboardKey, CellKeyboardAction> shortcutHandlers = {};
|
||||
}
|
||||
|
||||
abstract class GridCellState<T extends GridCellWidget> extends State<T> {
|
||||
@ -94,7 +94,7 @@ abstract class GridFocusNodeCellState<T extends GridCellWidget> extends GridCell
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
widget.keyboardActionHandlers[CellKeyboardKey.onEnter] = () => focusNode.unfocus();
|
||||
widget.shortcutHandlers[CellKeyboardKey.onEnter] = () => focusNode.unfocus();
|
||||
_listenOnFocusNodeChanged();
|
||||
super.initState();
|
||||
}
|
||||
@ -109,7 +109,7 @@ abstract class GridFocusNodeCellState<T extends GridCellWidget> extends GridCell
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.keyboardActionHandlers.remove(CellKeyboardKey.onEnter);
|
||||
widget.shortcutHandlers.clear();
|
||||
focusNode.removeAllListener();
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
|
@ -1,16 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
typedef CellKeyboardAction = VoidCallback;
|
||||
typedef CellKeyboardAction = dynamic Function();
|
||||
|
||||
enum CellKeyboardKey {
|
||||
onEnter,
|
||||
onCopy,
|
||||
onInsert,
|
||||
}
|
||||
|
||||
abstract class CellShortcuts extends Widget {
|
||||
const CellShortcuts({Key? key}) : super(key: key);
|
||||
|
||||
Map<CellKeyboardKey, CellKeyboardAction> get keyboardActionHandlers;
|
||||
Map<CellKeyboardKey, CellKeyboardAction> get shortcutHandlers;
|
||||
}
|
||||
|
||||
class GridCellShortcuts extends StatelessWidget {
|
||||
@ -20,9 +22,17 @@ class GridCellShortcuts extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Shortcuts(
|
||||
shortcuts: {LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent()},
|
||||
shortcuts: {
|
||||
LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyC): const GridCellCopyIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyV): const GridCellInsertIntent(),
|
||||
},
|
||||
child: Actions(
|
||||
actions: {GridCellEnterIdent: GridCellEnterAction(child: child)},
|
||||
actions: {
|
||||
GridCellEnterIdent: GridCellEnterAction(child: child),
|
||||
GridCellCopyIntent: GridCellCopyAction(child: child),
|
||||
GridCellInsertIntent: GridCellInsertAction(child: child),
|
||||
},
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
@ -39,7 +49,46 @@ class GridCellEnterAction extends Action<GridCellEnterIdent> {
|
||||
|
||||
@override
|
||||
void invoke(covariant GridCellEnterIdent intent) {
|
||||
final callback = child.keyboardActionHandlers[CellKeyboardKey.onEnter];
|
||||
final callback = child.shortcutHandlers[CellKeyboardKey.onEnter];
|
||||
if (callback != null) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GridCellCopyIntent extends Intent {
|
||||
const GridCellCopyIntent();
|
||||
}
|
||||
|
||||
class GridCellCopyAction extends Action<GridCellCopyIntent> {
|
||||
final CellShortcuts child;
|
||||
GridCellCopyAction({required this.child});
|
||||
|
||||
@override
|
||||
void invoke(covariant GridCellCopyIntent intent) {
|
||||
final callback = child.shortcutHandlers[CellKeyboardKey.onCopy];
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final s = callback();
|
||||
if (s is String) {
|
||||
Clipboard.setData(ClipboardData(text: s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GridCellInsertIntent extends Intent {
|
||||
const GridCellInsertIntent();
|
||||
}
|
||||
|
||||
class GridCellInsertAction extends Action<GridCellInsertIntent> {
|
||||
final CellShortcuts child;
|
||||
GridCellInsertAction({required this.child});
|
||||
|
||||
@override
|
||||
void invoke(covariant GridCellInsertIntent intent) {
|
||||
final callback = child.shortcutHandlers[CellKeyboardKey.onEnter];
|
||||
if (callback != null) {
|
||||
callback();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'cell_builder.dart';
|
||||
import 'cell_shortcuts.dart';
|
||||
|
||||
class CheckboxCell extends GridCellWidget {
|
||||
final GridCellContextBuilder cellContextBuilder;
|
||||
@ -24,7 +25,13 @@ class _CheckboxCellState extends GridCellState<CheckboxCell> {
|
||||
void initState() {
|
||||
final cellContext = widget.cellContextBuilder.build();
|
||||
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
|
||||
|
||||
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
|
||||
if (_cellBloc.state.isSelected) {
|
||||
return "Yes";
|
||||
} else {
|
||||
return "No";
|
||||
}
|
||||
};
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@ -45,6 +46,7 @@ class _DateCellState extends State<DateCell> {
|
||||
void initState() {
|
||||
final cellContext = widget.cellContextBuilder.build();
|
||||
_cellBloc = getIt<DateCellBloc>(param1: cellContext)..add(const DateCellEvent.initial());
|
||||
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.dateStr;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'cell_builder.dart';
|
||||
import 'cell_shortcuts.dart';
|
||||
|
||||
class NumberCell extends GridCellWidget {
|
||||
final GridCellContextBuilder cellContextBuilder;
|
||||
@ -29,6 +30,9 @@ class _NumberCellState extends GridFocusNodeCellState<NumberCell> {
|
||||
final cellContext = widget.cellContextBuilder.build();
|
||||
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
|
||||
_controller = TextEditingController(text: contentFromState(_cellBloc.state));
|
||||
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
|
||||
return _cellBloc.state.content.fold((content) => content, (r) => null);
|
||||
};
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/workspace/application/grid/prelude.dart';
|
||||
import 'cell_builder.dart';
|
||||
import 'cell_shortcuts.dart';
|
||||
|
||||
class GridTextCellStyle extends GridCellStyle {
|
||||
String? placeholder;
|
||||
@ -44,6 +45,7 @@ class _GridTextCellState extends GridFocusNodeCellState<GridTextCell> {
|
||||
_cellBloc.add(const TextCellEvent.initial());
|
||||
_controller = TextEditingController(text: _cellBloc.state.content);
|
||||
|
||||
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
|
||||
import 'package:app_flowy/workspace/presentation/home/toast.dart';
|
||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_accessory.dart';
|
||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/image.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
@ -86,6 +87,8 @@ class _GridURLCellState extends GridCellState<GridURLCell> {
|
||||
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
|
||||
_cellBloc = URLCellBloc(cellContext: cellContext);
|
||||
_cellBloc.add(const URLCellEvent.initial());
|
||||
|
||||
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user