From e819ba46e05ba79706f29a8fedef0412a94fc8ce Mon Sep 17 00:00:00 2001 From: debuggerx Date: Fri, 8 Oct 2021 01:44:17 +0800 Subject: [PATCH] feat: use data from provider to render table and make it clickable. --- app/lib/models/solution.dart | 2 + app/lib/pages/gesture_editor.dart | 109 +++++++++++++----------------------- app/lib/pages/home.dart | 36 +++++++++++- app/lib/utils/helper.dart | 11 ++-- app/lib/widgets/dde_data_table.dart | 39 +++++++------ app/resources/langs/en.json | 3 +- app/resources/langs/zh-CN.json | 7 ++- 7 files changed, 107 insertions(+), 100 deletions(-) diff --git a/app/lib/models/solution.dart b/app/lib/models/solution.dart index 664f872..c7c8e69 100644 --- a/app/lib/models/solution.dart +++ b/app/lib/models/solution.dart @@ -77,6 +77,8 @@ class GestureProp { return 'GestureProp{gesture: $gesture, direction: $direction, fingers: $fingers, type: $type, command: $command, remark: $remark}'; } + GestureProp.empty(); + GestureProp.parse(props) { if (props is String) props = json.decode(props); assert(props is Map); diff --git a/app/lib/pages/gesture_editor.dart b/app/lib/pages/gesture_editor.dart index fcc4a70..0dec921 100644 --- a/app/lib/pages/gesture_editor.dart +++ b/app/lib/pages/gesture_editor.dart @@ -1,6 +1,7 @@ import 'package:dde_gesture_manager/constants/constants.dart'; import 'package:dde_gesture_manager/extensions.dart'; import 'package:dde_gesture_manager/models/content_layout.provider.dart'; +import 'package:dde_gesture_manager/models/solution.dart'; import 'package:dde_gesture_manager/models/solution.provider.dart'; import 'package:dde_gesture_manager/utils/helper.dart'; import 'package:dde_gesture_manager/widgets/dde_button.dart'; @@ -11,13 +12,43 @@ import 'package:flutter/material.dart'; class GestureEditor extends StatelessWidget { const GestureEditor({Key? key}) : super(key: key); + List _buildDataRow(List? gestures, BuildContext context) => (gestures ?? []) + .map((gesture) => DDataRow( + onSelectChanged: (selected) { + if (selected == true) + context.read().setProps( + gesture: gesture.gesture, + direction: gesture.direction, + fingers: gesture.fingers, + type: gesture.type, + command: gesture.command, + remark: gesture.remark, + ); + }, + selected: context.watch() == gesture, + cells: [ + Center( + child: Text('${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}').tr(), + ), + Text('${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}').tr(), + Center( + child: Text('${gesture.fingers}'), + ), + Center(child: Text('${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}').tr()), + Text(gesture.command ?? ''), + Text(gesture.remark ?? ''), + ] + .map( + (ele) => DDataCell(ele), + ) + .toList(), + )) + .toList(); + @override Widget build(BuildContext context) { var layoutProvider = context.watch(); var solutionProvider = context.watch(); - solutionProvider.name.sout(); - solutionProvider.gestures.sout(); - return Flexible( child: Padding( padding: const EdgeInsets.all(10), @@ -85,6 +116,7 @@ class GestureEditor extends StatelessWidget { child: ConstrainedBox( constraints: BoxConstraints(minWidth: constraints.maxWidth), child: DDataTable( + showCheckboxColumn: true, headerBackgroundColor: context.t.dialogBackgroundColor, decoration: BoxDecoration( borderRadius: BorderRadius.circular(defaultBorderRadius), @@ -94,8 +126,8 @@ class GestureEditor extends StatelessWidget { ), ), dataRowColor: MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered)) - return Colors.blue; + if (states.contains(MaterialState.hovered)) return Colors.grey; + if (states.contains(MaterialState.selected)) return Colors.green; return null; }), columns: [ @@ -106,72 +138,7 @@ class GestureEditor extends StatelessWidget { DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())), DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())), ], - rows: [ - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_right).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()), - DDataCell(Text('ctrl+w')), - DDataCell(Text('close current page.')), - ], - ), - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()), - DDataCell(Text('ctrl+alt+t')), - DDataCell(Text('reopen last closed page.')), - ], - ), - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()), - DDataCell(Text('ctrl+alt+t')), - DDataCell(Text('reopen last closed page.')), - ], - ), - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()), - DDataCell(Text('ctrl+alt+t')), - DDataCell(Text('reopen last closed page.')), - ], - ), - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()), - DDataCell(Text('ctrl+alt+t')), - DDataCell(Text('reopen last closed page.')), - ], - ), - DDataRow( - cells: [ - DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()), - DDataCell(Text(LocaleKeys.gesture_editor_directions_down).tr()), - DDataCell(Text('3')), - DDataCell(Text(LocaleKeys.gesture_editor_types_commandline).tr()), - DDataCell(Text( - 'dbus-send --type=method_call --dest=com.deepin.dde.Launcher /com/deepin/dde/Launcher com.deepin.dde.Launcher.Toggle')), - DDataCell(TextButton( - onPressed: () => print(123), - child: Text('show launcher.'), - )), - ], - ), - ], + rows: _buildDataRow(solutionProvider.gestures, context), ), ), ), diff --git a/app/lib/pages/home.dart b/app/lib/pages/home.dart index 74c7ef6..a98d674 100644 --- a/app/lib/pages/home.dart +++ b/app/lib/pages/home.dart @@ -24,15 +24,47 @@ class _HomePageState extends State { "gestures": [ { "gesture": "swipe", + "direction": "down", + "fingers": 3, + "type": "shortcut", + "command": "ctrl+w", + "remark": "close current page." + }, + { + "gesture": "swipe", "direction": "up", "fingers": 3, "type": "shortcut", - "command": "ctrl+w" + "command": "ctrl+alt+t", + "remark": "reopen last closed page." + }, + { + "gesture": "pinch", + "direction": "in", + "fingers": 4, + "type": "shortcut", + "command": "ctrl+alt+f", + "remark": "search files." + }, + { + "gesture": "tap", + "fingers": 4, + "type": "built_in", + "command": "handle4FingersTap", + "remark": "handle4FingersTap." + }, + { + "gesture": "swipe", + "direction": "down", + "fingers": 5, + "type": "commandline", + "command": "dbus-send --type=method_call --dest=com.deepin.dde.Launcher /com/deepin/dde/Launcher com.deepin.dde.Launcher.Toggle", + "remark": "toggle launcher." } ] } ''')), - // ChangeNotifierProvider(create: (context) => GesturePropProvider()), + ChangeNotifierProvider(create: (context) => GesturePropProvider.empty()), ], child: Column( mainAxisSize: MainAxisSize.max, diff --git a/app/lib/utils/helper.dart b/app/lib/utils/helper.dart index 3b471dd..c510eac 100644 --- a/app/lib/utils/helper.dart +++ b/app/lib/utils/helper.dart @@ -49,11 +49,11 @@ class H { return preferredPanelsStatus..marketPanelOpened = false; } - static String getGestureName(Gesture gesture) => const { + static String? getGestureName(Gesture? gesture) => const { Gesture.swipe: 'swipe', Gesture.tap: 'tap', Gesture.pinch: 'pinch', - }[gesture]!; + }[gesture]; static Gesture getGestureByName(String gestureName) => const { @@ -63,13 +63,14 @@ class H { }[gestureName] ?? Gesture.swipe; - static String? getGestureDirectionName(GestureDirection direction) => const { + static String? getGestureDirectionName(GestureDirection? direction) => const { GestureDirection.up: 'up', GestureDirection.down: 'down', GestureDirection.left: 'left', GestureDirection.right: 'right', GestureDirection.pinch_in: 'in', GestureDirection.pinch_out: 'out', + GestureDirection.none: 'none', }[direction]; static GestureDirection getGestureDirectionByName(String? directionName) => @@ -83,11 +84,11 @@ class H { }[directionName] ?? GestureDirection.none; - static String getGestureTypeName(GestureType type) => const { + static String? getGestureTypeName(GestureType? type) => const { GestureType.built_in: 'built_in', GestureType.shortcut: 'shortcut', GestureType.commandline: 'commandline', - }[type]!; + }[type]; static GestureType getGestureTypeByName(String typeName) => const { diff --git a/app/lib/widgets/dde_data_table.dart b/app/lib/widgets/dde_data_table.dart index dcd6b06..90f0f65 100644 --- a/app/lib/widgets/dde_data_table.dart +++ b/app/lib/widgets/dde_data_table.dart @@ -990,26 +990,29 @@ class _DDataTableState extends State { int displayColumnIndex = 0; if (displayCheckboxColumn) { - tableColumns[0] = FixedColumnWidth( - effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd); - tableRows[0].children![0] = _buildCheckbox( - context: context, - checked: someChecked ? null : allChecked, - onRowTap: null, - onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked), - overlayColor: null, - tristate: true, - ); + tableColumns[0] = FixedColumnWidth(0); + tableRows[0].children![0] = RectGetter.defaultKey(child: Container()); + // tableColumns[0] = FixedColumnWidth( + // effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd); + // tableRows[0].children![0] = _buildCheckbox( + // context: context, + // checked: someChecked ? null : allChecked, + // onRowTap: null, + // onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked), + // overlayColor: null, + // tristate: true, + // ); rowIndex = 1; for (final DDataRow row in widget.rows) { - tableRows[rowIndex].children![0] = _buildCheckbox( - context: context, - checked: row.selected, - onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected), - onCheckboxChanged: row.onSelectChanged, - overlayColor: row.color ?? effectiveDataRowColor, - tristate: false, - ); + // tableRows[rowIndex].children![0] = _buildCheckbox( + // context: context, + // checked: row.selected, + // onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected), + // onCheckboxChanged: row.onSelectChanged, + // overlayColor: row.color ?? effectiveDataRowColor, + // tristate: false, + // ); + tableRows[rowIndex].children![0] = Container(); rowIndex += 1; } displayColumnIndex += 1; diff --git a/app/resources/langs/en.json b/app/resources/langs/en.json index 3d356f7..f687fa5 100644 --- a/app/resources/langs/en.json +++ b/app/resources/langs/en.json @@ -39,7 +39,8 @@ "left": "left", "right": "right", "in": "pinch-in", - "out": "pinch-out" + "out": "pinch-out", + "none": "/" }, "gestures": { "swipe": "swipe", diff --git a/app/resources/langs/zh-CN.json b/app/resources/langs/zh-CN.json index 5c8dca5..ff97b4d 100644 --- a/app/resources/langs/zh-CN.json +++ b/app/resources/langs/zh-CN.json @@ -39,12 +39,13 @@ "left": "向左", "right": "向右", "in": "向内捏合", - "out": "向外展开" + "out": "向外展开", + "none": "/" }, "gestures": { - "swipe": "滑动", + "swipe": "划", "pinch": "捏", - "tap": "点击" + "tap": "点" }, "types": { "built_in": "内置操作",