wip: shortcut listener widget.

This commit is contained in:
2021-11-09 18:38:44 +08:00
parent eeeaba3c0a
commit 4eb7bc256c
4 changed files with 252 additions and 34 deletions
+129 -33
View File
@@ -8,6 +8,7 @@ import 'package:dde_gesture_manager/models/settings.provider.dart';
import 'package:dde_gesture_manager/utils/helper.dart';
import 'package:dde_gesture_manager/widgets/dde_button.dart';
import 'package:dde_gesture_manager/widgets/dde_data_table.dart';
import 'package:dde_gesture_manager/widgets/table_cell_shortcut_listener.dart';
import 'package:dde_gesture_manager/widgets/table_cell_text_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -46,7 +47,8 @@ class GestureEditor extends StatelessWidget {
visible: layoutProvider.localManagerOpened == false,
child: DButton(
width: defaultButtonHeight,
onTap: () => H.openPanel(context, PanelType.local_manager),
onTap: () =>
H.openPanel(context, PanelType.local_manager),
child: Icon(
CupertinoIcons.square_list,
),
@@ -75,11 +77,14 @@ class GestureEditor extends StatelessWidget {
Expanded(
child: GestureDetector(
onTap: () {
context.read<GesturePropProvider>().setProps(editMode: false);
context
.read<GesturePropProvider>()
.setProps(editMode: false);
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(defaultBorderRadius),
borderRadius:
BorderRadius.circular(defaultBorderRadius),
border: Border.all(
width: .2,
color: context.t.dividerColor,
@@ -87,16 +92,19 @@ class GestureEditor extends StatelessWidget {
),
width: double.infinity,
clipBehavior: Clip.antiAlias,
child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
child: LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
return AdaptiveScrollbar(
controller: verticalCtrl,
underColor: Colors.transparent,
sliderDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(_scrollBarWidth / 2),
borderRadius:
BorderRadius.circular(_scrollBarWidth / 2),
color: Colors.grey.withOpacity(.4),
),
sliderActiveDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(_scrollBarWidth / 2),
borderRadius:
BorderRadius.circular(_scrollBarWidth / 2),
color: Colors.grey.withOpacity(.6),
),
position: ScrollbarPosition.right,
@@ -106,11 +114,13 @@ class GestureEditor extends StatelessWidget {
width: _scrollBarWidth,
underColor: Colors.transparent,
sliderDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(_scrollBarWidth / 2),
borderRadius:
BorderRadius.circular(_scrollBarWidth / 2),
color: Colors.grey.withOpacity(.4),
),
sliderActiveDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(_scrollBarWidth / 2),
borderRadius:
BorderRadius.circular(_scrollBarWidth / 2),
color: Colors.grey.withOpacity(.6),
),
controller: horizontalCtrl,
@@ -119,28 +129,58 @@ class GestureEditor extends StatelessWidget {
scrollDirection: Axis.horizontal,
controller: horizontalCtrl,
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth),
constraints: BoxConstraints(
minWidth: constraints.maxWidth),
child: DDataTable(
showBottomBorder: true,
headingRowHeight: _headingRowHeight,
showCheckboxColumn: true,
headerBackgroundColor: context.t.dialogBackgroundColor,
headerBackgroundColor:
context.t.dialogBackgroundColor,
verticalScrollController: verticalCtrl,
dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) return context.t.dialogBackgroundColor;
dataRowColor:
MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return context.t.dialogBackgroundColor;
if (states.contains(MaterialState.selected))
return context.read<SettingsProvider>().currentActiveColor;
return context
.read<SettingsProvider>()
.currentActiveColor;
return null;
}),
columns: [
DDataColumn(label: Text(LocaleKeys.gesture_editor_fingers.tr()), center: true),
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_type.tr()), center: true),
DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())),
DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())),
DDataColumn(
label: Text(LocaleKeys
.gesture_editor_fingers
.tr()),
center: true),
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_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),
rows: _buildDataRows(
schemeProvider.gestures, context),
),
),
),
@@ -170,9 +210,12 @@ class GestureEditor extends StatelessWidget {
}
}
List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context) => (gestures ?? []).map((gesture) {
List<DDataRow> _buildDataRows(
List<GestureProp>? gestures, BuildContext context) =>
(gestures ?? []).map((gesture) {
var gesturePropProvider = context.watch<GesturePropProvider>();
bool editing = gesturePropProvider == gesture && gesturePropProvider.editMode == true;
bool editing = gesturePropProvider == gesture &&
gesturePropProvider.editMode == true;
bool selected = gesturePropProvider == gesture && !editing;
return DDataRow(
onSelectChanged: (selected) {
@@ -200,11 +243,15 @@ List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context)
}
},
selected: selected,
cells: editing ? _buildRowCellsEditing(context, gesture) : _buildRowCellsNormal(context, selected, gesture),
cells: editing
? _buildRowCellsEditing(context, gesture)
: _buildRowCellsNormal(context, selected, gesture),
);
}).toList();
List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture) => [
List<DDataCell> _buildRowCellsEditing(
BuildContext context, GestureProp gesture) =>
[
DButton.dropdown(
enabled: true,
child: DropdownButton<int>(
@@ -297,14 +344,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
isExpanded: true,
),
),
TableCellTextField(
initText: gesture.command,
hint: 'pls input cmd',
onComplete: (value) => context.read<GesturePropProvider>().setProps(
command: value,
editMode: true,
),
),
_buildCommandCellsEditing(context),
TableCellTextField(
initText: gesture.remark,
hint: 'pls input cmd',
@@ -315,7 +355,63 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context, GestureProp gesture)
),
].map((e) => DDataCell(e)).toList();
List<DDataCell> _buildRowCellsNormal(BuildContext context, bool selected, GestureProp gesture) => [
Widget _buildCommandCellsEditing(BuildContext context) {
'build cmd cell'.sout();
var gesture = context.read<GesturePropProvider>();
switch (gesture.type) {
case GestureType.commandline:
return TableCellTextField(
initText: gesture.command,
hint: 'pls input cmd',
onComplete: (value) => context.read<GesturePropProvider>().setProps(
command: value,
editMode: true,
),
);
case GestureType.built_in:
return DButton.dropdown(
enabled: true,
width: 250.0,
child: DropdownButton<String>(
icon: Icon(Icons.keyboard_arrow_down_rounded),
items: builtInCommands
.map(
(e) => DropdownMenuItem<String>(
child: Text(
e,
textScaleFactor: .8,
),
value: e,
),
)
.toList(),
value: builtInCommands.contains(gesture.command)
? gesture.command
: builtInCommands.first,
onChanged: (value) => context.read<GesturePropProvider>().setProps(
command: value,
editMode: true,
),
isExpanded: true,
),
);
case GestureType.shortcut:
return TableCellShortcutListener(
width: 150.0,
initShortcut: gesture.command ?? '',
onComplete: (value) => context.read<GesturePropProvider>().setProps(
command: value,
editMode: true,
),
);
default:
throw Exception('Unknown gesture command type.');
}
}
List<DDataCell> _buildRowCellsNormal(
BuildContext context, bool selected, GestureProp gesture) =>
[
Center(
child: Text(
'${gesture.fingers}',