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'; import 'package:uuid/uuid.dart'; @ProviderModel(copyable: true) class Scheme { @ProviderModelProp() String? id; @ProviderModelProp() String? name; @ProviderModelProp() String? description; @ProviderModelProp() List? gestures; Scheme.parse(scheme) { if (scheme is String) scheme = json.decode(scheme); assert(scheme is Map); id = scheme['id']; name = scheme['name']; description = scheme['desc']; gestures = (scheme['gestures'] as List? ?? []).map((ele) => GestureProp.parse(ele)).toList(); } Scheme.systemDefault() { this.id = Uuid.NAMESPACE_NIL; this.name = LocaleKeys.local_manager_default_scheme_label.tr(); this.description = LocaleKeys.local_manager_default_scheme_description.tr(); this.gestures = []; } Scheme.create({this.name, this.description, this.gestures}) { this.id = Uuid().v1(); } } enum Gesture { swipe, tap, pinch, } enum GestureDirection { up, down, left, right, pinch_in, pinch_out, none, } enum GestureType { built_in, commandline, shortcut, } @ProviderModel(copyable: true) class GestureProp { @ProviderModelProp() String? id; @ProviderModelProp() Gesture? gesture; @ProviderModelProp() GestureDirection? direction; @ProviderModelProp() int? fingers; @ProviderModelProp() GestureType? type; @ProviderModelProp() String? command; @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 && other.id == this.id; @override String toString() { return 'GestureProp{gesture: $gesture, direction: $direction, fingers: $fingers, type: $type, command: $command, remark: $remark}'; } GestureProp.empty() : this.id = Uuid.NAMESPACE_NIL; GestureProp.parse(props) { if (props is String) props = json.decode(props); assert(props is Map); id = Uuid().v1(); gesture = H.getGestureByName(props['gesture']); direction = H.getGestureDirectionByName(props['direction']); fingers = props['fingers']; type = H.getGestureTypeByName(props['type']); command = props['command']; remark = props['remark']; } }