feat: automatically calculate the available drop-down menu options。

pull/4/head
DebuggerX 4 years ago
parent 2fef238bf2
commit 13752b3451

@ -165,10 +165,11 @@ class GestureEditor extends StatelessWidget {
enabled: !gesturePropProvider.editMode! && !schemeTree.fullFiled,
onTap: () {
var schemeProvider = context.read<SchemeProvider>();
context.read<SchemeProvider>().setProps(gestures: [
context.read<SchemeProvider>().setProps(
gestures: [
...?schemeProvider.gestures,
H.getNextAvailableGestureProp(schemeProvider.buildSchemeTree())!,
]);
]..sort());
},
),
DButton.delete(
@ -181,8 +182,9 @@ class GestureEditor extends StatelessWidget {
];
context.read<SchemeProvider>().setProps(gestures: newGestures);
if (newGestures.length > 0)
gesturePropProvider.copyFrom(newGestures[
(index ?? 0) > newGestures.length - 1 ? newGestures.length - 1 : index ?? 0]);
gesturePropProvider.copyFrom(
newGestures[(index ?? 0) > newGestures.length - 1 ? newGestures.length - 1 : index ?? 0]
..editMode = false);
},
),
DButton.duplicate(
@ -217,10 +219,11 @@ class GestureEditor extends StatelessWidget {
newGestureProp.remark = copiedGesturePropProvider.remark;
}
newGestureProp.id = Uuid().v1();
context.read<SchemeProvider>().setProps(gestures: [
context.read<SchemeProvider>().setProps(
gestures: [
...?schemeProvider.gestures,
newGestureProp,
]);
]..sort());
},
),
]
@ -280,16 +283,45 @@ List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context)
}
},
selected: selected,
cells: editing ? _buildRowCellsEditing(context, gesture) : _buildRowCellsNormal(context, selected, gesture),
cells: editing ? _buildRowCellsEditing(context) : _buildRowCellsNormal(context, selected, gesture),
);
}).toList();
List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture) => [
List<DDataCell> _buildRowCellsEditing(BuildContext context) {
var gesture = context.read<GesturePropProvider>();
var schemeTree = context.read<SchemeProvider>().buildSchemeTree();
var availableFingers = schemeTree.nodes.where((node) => !node.fullFiled).map((e) => e.fingers);
if (!availableFingers.contains(gesture.fingers)) {
availableFingers = [...availableFingers, gesture.fingers!]..sort();
}
var availableGestures = schemeTree.nodes
.firstWhere((node) => node.fingers == gesture.fingers)
.nodes
.where((node) => !node.fullFiled)
.map((e) => e.type);
if (!availableGestures.any((type) => type == gesture.gesture)) {
availableGestures = [...availableGestures, gesture.gesture!]..sort();
}
var availableDirection = schemeTree.nodes
.firstWhere((node) => node.fingers == gesture.fingers)
.nodes
.firstWhere((node) => node.type == gesture.gesture)
.nodes
.where((node) => !node.fullFiled)
.map((e) => e.direction);
if (!availableDirection.any((direction) => direction == gesture.direction)) {
availableDirection = [...availableDirection, gesture.direction!]..sort((a, b) => a.index - b.index);
}
return [
DButton.dropdown(
enabled: true,
child: DropdownButton<int>(
icon: Icon(Icons.keyboard_arrow_down_rounded),
items: [3, 4, 5]
items: availableFingers
.map(
(e) => DropdownMenuItem<int>(
child: Text('$e'),
@ -297,7 +329,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
)
.toList(),
value: context.watch<GesturePropProvider>().fingers,
value: gesture.fingers,
onChanged: (value) => context.read<GesturePropProvider>().setProps(
fingers: value,
editMode: true,
@ -307,10 +339,10 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
DButton.dropdown(
enabled: true,
width: 60.0,
width: 100.0,
child: DropdownButton<Gesture>(
icon: Icon(Icons.keyboard_arrow_down_rounded),
items: Gesture.values
items: availableGestures
.map(
(e) => DropdownMenuItem<Gesture>(
child: Text(
@ -321,7 +353,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
)
.toList(),
value: context.watch<GesturePropProvider>().gesture,
value: gesture.gesture,
onChanged: (value) => context.read<GesturePropProvider>().setProps(
gesture: value,
editMode: true,
@ -334,7 +366,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
width: 100.0,
child: DropdownButton<GestureDirection>(
icon: Icon(Icons.keyboard_arrow_down_rounded),
items: GestureDirection.values
items: availableDirection
.map(
(e) => DropdownMenuItem<GestureDirection>(
child: Text(
@ -345,7 +377,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
)
.toList(),
value: context.watch<GesturePropProvider>().direction,
value: gesture.direction,
onChanged: (value) => context.read<GesturePropProvider>().setProps(
direction: value,
editMode: true,
@ -369,7 +401,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
)
.toList(),
value: context.watch<GesturePropProvider>().type,
value: gesture.type,
onChanged: (value) => context.read<GesturePropProvider>().setProps(
type: value,
command: '',
@ -388,6 +420,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
),
].map((e) => DDataCell(e)).toList();
}
Widget _buildCommandCellsEditing(BuildContext context) {
var gesture = context.read<GesturePropProvider>();

@ -28,7 +28,7 @@ class _HomePageState extends State<HomePage> {
"direction": "down",
"fingers": 3,
"type": "shortcut",
"command": "ctrl+w",
"command": "Control_L+w",
"remark": "close current page."
},
{
@ -36,7 +36,7 @@ class _HomePageState extends State<HomePage> {
"direction": "up",
"fingers": 3,
"type": "shortcut",
"command": "ctrl+alt+t",
"command": "Control_L+Alt_L+t",
"remark": "reopen last closed page."
},
{
@ -44,7 +44,7 @@ class _HomePageState extends State<HomePage> {
"direction": "in",
"fingers": 4,
"type": "shortcut",
"command": "ctrl+alt+f",
"command": "Control_L+Alt_L+f",
"remark": "search files."
},
{

Loading…
Cancel
Save