diff --git a/app/lib/builder/provider_generator.dart b/app/lib/builder/provider_generator.dart index 205c260..513fb12 100644 --- a/app/lib/builder/provider_generator.dart +++ b/app/lib/builder/provider_generator.dart @@ -22,7 +22,9 @@ class ProviderGenerator extends GeneratorForAnnotation { List fields = []; element.fields.forEach((field) { var annotation = field.metadata.firstWhereOrNull( - (m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp'); + (m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp') ?? + field.getter?.metadata.firstWhereOrNull( + (m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp'); if (annotation != null) fields.add( AnnotationField( @@ -77,7 +79,7 @@ String? _genCopyFunc(String displayName, List fields, bool copy return ''' void copyFrom(${displayName} other) { bool changed = false; - ${fields.map((f) => 'if (other.${f.name}.diff(this.${f.name})) {this.${f.name} = other.${f.name}; changed = true; }').join('\n')} + ${fields.map((f) => 'if (other.${f.name} != this.${f.name}) {this.${f.name} = other.${f.name}; changed = true; }').join('\n')} if (changed) notifyListeners(); } '''; diff --git a/app/lib/models/scheme.dart b/app/lib/models/scheme.dart index 22be9fb..b3d5d62 100644 --- a/app/lib/models/scheme.dart +++ b/app/lib/models/scheme.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:dde_gesture_manager/builder/provider_annotation.dart'; import 'package:dde_gesture_manager/extensions.dart'; import 'package:dde_gesture_manager/utils/helper.dart'; +import 'package:flutter/material.dart'; @ProviderModel(copyable: true) class Scheme { @@ -76,6 +77,20 @@ class GestureProp { @ProviderModelProp() String? remark; + @ProviderModelProp() + bool get editMode => _editMode; + + set editMode(bool val) { + _editMode = val; + if (val == false) onEditEnd?.call(); + } + + VoidCallback? onEditEnd; + + bool _editMode = false; + + + @override bool operator ==(Object other) => other is GestureProp && diff --git a/app/lib/pages/gesture_editor.dart b/app/lib/pages/gesture_editor.dart index 11545c5..4e4f56a 100644 --- a/app/lib/pages/gesture_editor.dart +++ b/app/lib/pages/gesture_editor.dart @@ -13,72 +13,6 @@ 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) { - bool selected = context.watch() == gesture; - return 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: selected, - cells: [ - Center( - child: Text( - '${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ).tr(), - ), - Center( - child: Text( - '${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ).tr()), - Center( - child: Text( - '${gesture.fingers}', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ), - ), - Center( - child: Text( - '${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ).tr()), - Text( - gesture.command ?? '', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ), - Text( - gesture.remark ?? '', - style: TextStyle( - color: selected ? Colors.white : null, - ), - ), - ] - .map( - (ele) => DDataCell(ele), - ) - .toList(), - ); - }).toList(); - @override Widget build(BuildContext context) { var layoutProvider = context.watch(); @@ -131,54 +65,59 @@ class GestureEditor extends StatelessWidget { ), Container(height: 10), Expanded( - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(defaultBorderRadius), - border: Border.all( - width: .2, - color: context.t.dividerColor, + child: GestureDetector( + onTap: () { + context.read().copyFrom(GestureProp.empty()); + }, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(defaultBorderRadius), + border: Border.all( + width: .2, + color: context.t.dividerColor, + ), ), - ), - width: double.infinity, - clipBehavior: Clip.antiAlias, - child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { - return Scrollbar( - isAlwaysShown: true, - child: SingleChildScrollView( - primary: true, - scrollDirection: Axis.horizontal, - child: ConstrainedBox( - constraints: BoxConstraints(minWidth: constraints.maxWidth), - child: DDataTable( - showCheckboxColumn: true, - headerBackgroundColor: context.t.dialogBackgroundColor, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(defaultBorderRadius), - border: Border.all( - width: .2, - color: context.t.dividerColor, + width: double.infinity, + clipBehavior: Clip.antiAlias, + child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { + return Scrollbar( + isAlwaysShown: true, + child: SingleChildScrollView( + primary: true, + scrollDirection: Axis.horizontal, + child: ConstrainedBox( + constraints: BoxConstraints(minWidth: constraints.maxWidth), + child: DDataTable( + showCheckboxColumn: true, + headerBackgroundColor: context.t.dialogBackgroundColor, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(defaultBorderRadius), + border: Border.all( + width: .2, + color: context.t.dividerColor, + ), ), + dataRowColor: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) return context.t.dialogBackgroundColor; + if (states.contains(MaterialState.selected)) + return context.read().currentActiveColor; + return null; + }), + columns: [ + DDataColumn(label: Text(LocaleKeys.gesture_editor_gesture.tr()), center: true), + DDataColumn(label: Text(LocaleKeys.gesture_editor_direction.tr()), center: true), + DDataColumn(label: Text(LocaleKeys.gesture_editor_fingers.tr()), center: true), + DDataColumn(label: Text(LocaleKeys.gesture_editor_type.tr()), center: true), + DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())), + DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())), + ], + rows: _buildDataRows(schemeProvider.gestures, context), ), - dataRowColor: MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered)) return context.t.dialogBackgroundColor; - if (states.contains(MaterialState.selected)) - return context.read().currentActiveColor; - return null; - }), - columns: [ - DDataColumn(label: Text(LocaleKeys.gesture_editor_gesture.tr()), center: true), - DDataColumn(label: Text(LocaleKeys.gesture_editor_direction.tr()), center: true), - DDataColumn(label: Text(LocaleKeys.gesture_editor_fingers.tr()), center: true), - DDataColumn(label: Text(LocaleKeys.gesture_editor_type.tr()), center: true), - DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())), - DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())), - ], - rows: _buildDataRow(schemeProvider.gestures, context), ), ), - ), - ); - }), + ); + }), + ), ), ), Container(height: 10), @@ -200,3 +139,92 @@ class GestureEditor extends StatelessWidget { ); } } + +List _buildDataRows(List? gestures, BuildContext context) => (gestures ?? []).map((gesture) { + var gesturePropProvider = context.watch(); + bool editing = gesturePropProvider == gesture && gesturePropProvider.editMode == true; + bool selected = gesturePropProvider == gesture && !editing; + return 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, + editMode: false, + ); + else if (selected == false) { + var provider = context.read(); + provider.onEditEnd = () { + /// todo: resort rows && check where changed + }; + provider.setProps( + editMode: true, + ); + } + }, + selected: selected, + cells: editing ? _buildRowCellsEditing(gesture) : _buildRowCellsNormal(selected, gesture), + ); + }).toList(); + +List _buildRowCellsEditing(GestureProp gesture) => [ + Text('1'), + Text('2'), + Text('3'), + Text('4'), + TextField(controller: TextEditingController(text: gesture.command)), + TextField(controller: TextEditingController(text: gesture.remark)), + ].map((e) => DDataCell(e)).toList(); + +List _buildRowCellsNormal(bool selected, GestureProp gesture) => [ + Center( + child: Text( + '${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ).tr(), + ), + Center( + child: Text( + '${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ).tr()), + Center( + child: Text( + '${gesture.fingers}', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ), + ), + Center( + child: Text( + '${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ).tr()), + Text( + gesture.command ?? '', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ), + Text( + gesture.remark ?? '', + style: TextStyle( + color: selected ? Colors.white : null, + ), + ), + ] + .map( + (ele) => DDataCell(ele), + ) + .toList(); diff --git a/app/lib/pages/local_manager.dart b/app/lib/pages/local_manager.dart index 191301e..b4c8218 100644 --- a/app/lib/pages/local_manager.dart +++ b/app/lib/pages/local_manager.dart @@ -158,64 +158,6 @@ class _LocalManagerState extends State { ), ], ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: ListView.builder( - controller: _scrollController, - itemBuilder: (context, index) => GestureDetector( - onDoubleTap: () { - context.read().copyFrom(localSchemes[index].scheme); - setState(() { - _selectedIndex = index; - }); - }, - onTap: () { - setState(() { - _selectedIndex = index; - }); - }, - child: MouseRegion( - cursor: SystemMouseCursors.click, - onEnter: (_) { - setState(() { - _hoveringIndex = index; - }); - }, - child: Container( - color: _getItemBackgroundColor(index), - child: Padding( - padding: const EdgeInsets.only(right: 12.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - localSchemes[index].scheme.name ?? '', - style: TextStyle( - color: index == _selectedIndex ? Colors.white : null, - ), - ), - Text( - '456', - style: TextStyle( - color: index == _selectedIndex ? Colors.white : null, - ), - ), - ], - ), - ), - ), - ), - ), - itemCount: localSchemes.length, - ), - ), - Container( - height: 150, - color: Colors.black, - ), - ], ), ), ], diff --git a/app/lib/utils/helper.dart b/app/lib/utils/helper.dart index 2e274fc..4b891ef 100644 --- a/app/lib/utils/helper.dart +++ b/app/lib/utils/helper.dart @@ -103,7 +103,6 @@ class H { var list = inp.split(','); if (list.length != 4) return null; var rgba = list.map((e) => int.parse(e) ~/ 257).toList(); - rgba.sout(); return Color.fromARGB(rgba[3], rgba[0], rgba[1], rgba[2]); } }