Editor almost done. #3
@@ -2,10 +2,12 @@ import 'dart:convert';
|
||||
|
||||
import 'package:dde_gesture_manager/builder/provider_annotation.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/extensions/compare_extension.dart';
|
||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
typedef OnEditEnd(GestureProp prop);
|
||||
|
||||
@ProviderModel(copyable: true)
|
||||
class Scheme {
|
||||
@ProviderModelProp()
|
||||
@@ -26,7 +28,7 @@ class Scheme {
|
||||
id = scheme['id'];
|
||||
name = scheme['name'];
|
||||
description = scheme['desc'];
|
||||
gestures = (scheme['gestures'] as List? ?? []).map<GestureProp>((ele) => GestureProp.parse(ele)).toList();
|
||||
gestures = (scheme['gestures'] as List? ?? []).map<GestureProp>((ele) => GestureProp.parse(ele)).toList()..sort();
|
||||
}
|
||||
|
||||
Scheme.systemDefault() {
|
||||
@@ -42,8 +44,8 @@ class Scheme {
|
||||
}
|
||||
|
||||
enum Gesture {
|
||||
swipe,
|
||||
tap,
|
||||
swipe,
|
||||
pinch,
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ enum GestureType {
|
||||
}
|
||||
|
||||
@ProviderModel(copyable: true)
|
||||
class GestureProp {
|
||||
class GestureProp implements Comparable {
|
||||
@ProviderModelProp()
|
||||
String? id;
|
||||
|
||||
@@ -87,14 +89,14 @@ class GestureProp {
|
||||
String? remark;
|
||||
|
||||
@ProviderModelProp()
|
||||
bool get editMode => _editMode;
|
||||
bool? get editMode => _editMode;
|
||||
|
||||
set editMode(bool val) {
|
||||
_editMode = val;
|
||||
if (val == false) onEditEnd?.call();
|
||||
set editMode(bool? val) {
|
||||
_editMode = val ?? false;
|
||||
if (val == false) onEditEnd?.call(this);
|
||||
}
|
||||
|
||||
VoidCallback? onEditEnd;
|
||||
OnEditEnd? onEditEnd;
|
||||
|
||||
bool _editMode = false;
|
||||
|
||||
@@ -119,4 +121,24 @@ class GestureProp {
|
||||
command = props['command'];
|
||||
remark = props['remark'];
|
||||
}
|
||||
|
||||
copyFrom(GestureProp prop) {
|
||||
this.id = prop.id;
|
||||
this.gesture = prop.gesture;
|
||||
this.direction = prop.direction;
|
||||
this.fingers = prop.fingers;
|
||||
this.type = prop.type;
|
||||
this.command = prop.command;
|
||||
this.remark = prop.remark;
|
||||
}
|
||||
|
||||
@override
|
||||
int compareTo(other) {
|
||||
assert(other is GestureProp);
|
||||
if (fingers.diff(other.fingers) && other.fingers != null) return fingers! - other.fingers as int;
|
||||
if (gesture.diff(other.gesture) && other.gesture != null) return gesture!.index - other.gesture!.index as int;
|
||||
if (direction.diff(other.direction) && other.direction != null)
|
||||
return direction!.index - other.direction!.index as int;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class GestureEditor extends StatelessWidget {
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.read<GesturePropProvider>().copyFrom(GestureProp.empty());
|
||||
context.read<GesturePropProvider>().setProps(editMode: false);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -175,28 +175,53 @@ List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context)
|
||||
bool selected = gesturePropProvider == gesture && !editing;
|
||||
return DDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
if (selected == true)
|
||||
context.read<GesturePropProvider>().setProps(
|
||||
id: gesture.id,
|
||||
editMode: false,
|
||||
);
|
||||
else if (selected == false) {
|
||||
var provider = context.read<GesturePropProvider>();
|
||||
provider.onEditEnd = () {
|
||||
/// todo: resort rows && check where changed
|
||||
};
|
||||
var provider = context.read<GesturePropProvider>();
|
||||
if (selected == true) {
|
||||
provider.setProps(
|
||||
editMode: true,
|
||||
editMode: false,
|
||||
);
|
||||
Future.microtask(() => provider.setProps(
|
||||
id: gesture.id,
|
||||
));
|
||||
} else if (selected == false) {
|
||||
provider.onEditEnd = (prop) {
|
||||
var schemeProvider = context.read<SchemeProvider>();
|
||||
var newGestures = List<GestureProp>.of(schemeProvider.gestures!);
|
||||
var index = newGestures.indexWhere((element) => element == prop);
|
||||
newGestures[index].copyFrom(prop);
|
||||
context.read<SchemeProvider>().setProps(
|
||||
gestures: newGestures..sort(),
|
||||
);
|
||||
};
|
||||
provider.copyFrom(
|
||||
gesture..editMode = true,
|
||||
);
|
||||
}
|
||||
},
|
||||
selected: selected,
|
||||
cells: editing ? _buildRowCellsEditing(gesture) : _buildRowCellsNormal(context, selected, gesture),
|
||||
cells: editing ? _buildRowCellsEditing(context, gesture) : _buildRowCellsNormal(context, selected, gesture),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
List<DDataCell> _buildRowCellsEditing(GestureProp gesture) => [
|
||||
Center(child: Text('1')),
|
||||
List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture) => [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.lightBlue,
|
||||
),
|
||||
child: DropdownButton<int>(
|
||||
items: [3, 4, 5]
|
||||
.map(
|
||||
(e) => DropdownMenuItem<int>(
|
||||
child: Text('$e'),
|
||||
value: e,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: context.watch<GesturePropProvider>().fingers,
|
||||
onChanged: (value) => context.read<GesturePropProvider>().setProps(fingers: value, editMode: true),
|
||||
isExpanded: true,
|
||||
),
|
||||
),
|
||||
Center(child: Text('2')),
|
||||
Center(child: Text('3')),
|
||||
Center(child: Text('4')),
|
||||
|
||||
Reference in New Issue
Block a user