wip: add notificator util.
This commit is contained in:
@@ -246,10 +246,10 @@ class GestureProp implements Comparable {
|
||||
|
||||
Map toJson() => {
|
||||
'id': id,
|
||||
'gesture': H.getGestureName(gesture),
|
||||
'gesture': gesture?.name,
|
||||
'direction': H.getGestureDirectionName(direction),
|
||||
'fingers': fingers,
|
||||
'type': H.getGestureTypeName(type),
|
||||
'type': type?.name,
|
||||
'command': command,
|
||||
'remark': remark,
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:dde_gesture_manager/models/settings.provider.dart';
|
||||
import 'package:dde_gesture_manager/pages/content.dart';
|
||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||
import 'package:dde_gesture_manager/utils/keyboard_mapper.dart';
|
||||
import 'package:dde_gesture_manager/utils/notificator.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/dde_text_field.dart';
|
||||
@@ -126,32 +127,27 @@ class GestureEditor extends StatelessWidget {
|
||||
controller: horizontalCtrl,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||
child: IgnorePointer(
|
||||
ignoring: schemeProvider.readOnly,
|
||||
child: DDataTable(
|
||||
showBottomBorder: true,
|
||||
headingRowHeight: _headingRowHeight,
|
||||
showCheckboxColumn: true,
|
||||
headerBackgroundColor: context.t.dialogBackgroundColor,
|
||||
verticalScrollController: verticalCtrl,
|
||||
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 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())),
|
||||
],
|
||||
rows: _buildDataRows(schemeProvider.gestures, context),
|
||||
),
|
||||
child: DDataTable(
|
||||
showBottomBorder: true,
|
||||
headingRowHeight: _headingRowHeight,
|
||||
showCheckboxColumn: true,
|
||||
headerBackgroundColor: context.t.dialogBackgroundColor,
|
||||
verticalScrollController: verticalCtrl,
|
||||
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 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())),
|
||||
],
|
||||
rows: _buildDataRows(context, schemeProvider.gestures, schemeProvider.readOnly),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -169,9 +165,7 @@ class GestureEditor extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
DButton.add(
|
||||
enabled: !schemeProvider.readOnly &&
|
||||
!gesturePropProvider.editMode! &&
|
||||
!schemeTree.fullFiled,
|
||||
enabled: !schemeProvider.readOnly && !gesturePropProvider.editMode! && !schemeTree.fullFiled,
|
||||
onTap: () {
|
||||
var schemeProvider = context.read<SchemeProvider>();
|
||||
var newGestures = [
|
||||
@@ -201,15 +195,16 @@ class GestureEditor extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
DButton.duplicate(
|
||||
enabled: !schemeProvider.readOnly &&
|
||||
gesturePropProvider != GestureProp.empty() &&
|
||||
!gesturePropProvider.editMode!,
|
||||
enabled: gesturePropProvider != GestureProp.empty() && !gesturePropProvider.editMode!,
|
||||
onTap: () {
|
||||
var schemeProvider = context.read<SchemeProvider>();
|
||||
context.read<CopiedGesturePropProvider>().copyFrom(
|
||||
schemeProvider.gestures!.firstWhere((element) => element.id == gesturePropProvider.id));
|
||||
|
||||
/// todo: give some info to UI.
|
||||
Notificator.success(
|
||||
context,
|
||||
title: LocaleKeys.info_gesture_prop_duplicated_title.tr(),
|
||||
description: LocaleKeys.info_gesture_prop_duplicated_description.tr(),
|
||||
);
|
||||
},
|
||||
),
|
||||
DButton.paste(
|
||||
@@ -306,7 +301,8 @@ class GestureEditor extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context) => (gestures ?? []).map((gesture) {
|
||||
List<DDataRow> _buildDataRows(BuildContext context, List<GestureProp>? gestures, bool readOnly) =>
|
||||
(gestures ?? []).map((gesture) {
|
||||
var gesturePropProvider = context.watch<GesturePropProvider>();
|
||||
bool editing = gesturePropProvider == gesture && gesturePropProvider.editMode == true;
|
||||
bool selected = gesturePropProvider == gesture && !editing;
|
||||
@@ -320,7 +316,7 @@ List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context)
|
||||
Future.microtask(() => provider.setProps(
|
||||
id: gesture.id,
|
||||
));
|
||||
} else if (selected == false) {
|
||||
} else if (selected == false && !readOnly) {
|
||||
provider.onEditEnd = (prop) {
|
||||
var schemeProvider = context.read<SchemeProvider>();
|
||||
var newGestures = List<GestureProp>.of(schemeProvider.gestures!);
|
||||
@@ -408,7 +404,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context) {
|
||||
.map(
|
||||
(e) => DropdownMenuItem<Gesture>(
|
||||
child: Text(
|
||||
'${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(e)}',
|
||||
'${LocaleKeys.gesture_editor_gestures}.${e.name}',
|
||||
textScaleFactor: .8,
|
||||
).tr(),
|
||||
value: e,
|
||||
@@ -456,7 +452,7 @@ List<DDataCell> _buildRowCellsEditing(BuildContext context) {
|
||||
.map(
|
||||
(e) => DropdownMenuItem<GestureType>(
|
||||
child: Text(
|
||||
'${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(e)}',
|
||||
'${LocaleKeys.gesture_editor_types}.${e.name}',
|
||||
textScaleFactor: .8,
|
||||
).tr(),
|
||||
value: e,
|
||||
@@ -545,7 +541,7 @@ List<DDataCell> _buildRowCellsNormal(BuildContext context, bool selected, Gestur
|
||||
),
|
||||
Center(
|
||||
child: Text(
|
||||
'${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}',
|
||||
'${LocaleKeys.gesture_editor_gestures}.${gesture.gesture?.name}',
|
||||
).tr(),
|
||||
),
|
||||
Center(
|
||||
@@ -554,7 +550,7 @@ List<DDataCell> _buildRowCellsNormal(BuildContext context, bool selected, Gestur
|
||||
).tr()),
|
||||
Center(
|
||||
child: Text(
|
||||
'${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}',
|
||||
'${LocaleKeys.gesture_editor_types}.${gesture.type?.name}',
|
||||
).tr()),
|
||||
gesture.type == GestureType.shortcut
|
||||
? Row(
|
||||
|
||||
@@ -51,7 +51,7 @@ class _LocalManagerState extends State<LocalManager> {
|
||||
|
||||
Color _getItemBackgroundColor(int index, String itemPath) {
|
||||
Color _color = index % 2 == 0 ? context.t.scaffoldBackgroundColor : context.t.backgroundColor;
|
||||
if (itemPath == _hoveringItem) _color = context.t.scaffoldBackgroundColor;
|
||||
if (itemPath == _hoveringItem) _color = context.t.dialogBackgroundColor;
|
||||
if (itemPath == _selectedItemPath) _color = context.read<SettingsProvider>().currentActiveColor;
|
||||
return _color;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class _LocalManagerState extends State<LocalManager> {
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) {
|
||||
setState(() {
|
||||
_hoveringItem = localSchemes[index].scheme.id!;
|
||||
_hoveringItem = localSchemes[index].path;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
export 'alert_web.dart' if (dart.library.io) 'alert_platform.dart';
|
||||
|
||||
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
|
||||
|
||||
abstract class Alert {
|
||||
Future<CustomButton> showAlert({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
});
|
||||
|
||||
Future<CustomButton> showConfirm({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
String? negativeButtonTitle,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'alert_interface.dart';
|
||||
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
|
||||
|
||||
class AlertImpl implements Alert {
|
||||
@override
|
||||
Future<CustomButton> showAlert({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
}) =>
|
||||
FlutterPlatformAlert.showCustomAlert(
|
||||
windowTitle: windowTitle,
|
||||
text: text,
|
||||
positiveButtonTitle: positiveButtonTitle,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<CustomButton> showConfirm({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
String? negativeButtonTitle,
|
||||
}) =>
|
||||
FlutterPlatformAlert.showCustomAlert(
|
||||
windowTitle: windowTitle,
|
||||
text: text,
|
||||
positiveButtonTitle: positiveButtonTitle,
|
||||
negativeButtonTitle: negativeButtonTitle,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
|
||||
|
||||
import 'alert_interface.dart';
|
||||
|
||||
import 'dart:html' as html;
|
||||
|
||||
class AlertImpl implements Alert {
|
||||
@override
|
||||
Future<CustomButton> showAlert({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
}) {
|
||||
html.window.alert([windowTitle, text].join('\n'));
|
||||
return Future.value(CustomButton.positiveButton);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CustomButton> showConfirm({
|
||||
required String windowTitle,
|
||||
required String text,
|
||||
String? positiveButtonTitle,
|
||||
String? negativeButtonTitle,
|
||||
}) {
|
||||
var confirmed = html.window.confirm([windowTitle, text].join('\n'));
|
||||
return Future.value(
|
||||
confirmed ? CustomButton.positiveButton : CustomButton.negativeButton,
|
||||
);
|
||||
}
|
||||
}
|
||||
+11
-25
@@ -6,6 +6,15 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
extension EnumByName<T extends Enum> on Iterable<T> {
|
||||
T? findByName(String name) {
|
||||
for (var value in this) {
|
||||
if (value.name == name) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class H {
|
||||
H._();
|
||||
|
||||
@@ -50,19 +59,7 @@ class H {
|
||||
return preferredPanelsStatus..marketPanelOpened = false;
|
||||
}
|
||||
|
||||
static String? getGestureName(Gesture? gesture) => const {
|
||||
Gesture.swipe: 'swipe',
|
||||
Gesture.tap: 'tap',
|
||||
Gesture.pinch: 'pinch',
|
||||
}[gesture];
|
||||
|
||||
static Gesture getGestureByName(String gestureName) =>
|
||||
const {
|
||||
'swipe': Gesture.swipe,
|
||||
'tap': Gesture.tap,
|
||||
'pinch': Gesture.pinch,
|
||||
}[gestureName] ??
|
||||
Gesture.swipe;
|
||||
static Gesture getGestureByName(String gestureName) => Gesture.values.findByName(gestureName) ?? Gesture.swipe;
|
||||
|
||||
static String? getGestureDirectionName(GestureDirection? direction) => const {
|
||||
GestureDirection.up: 'up',
|
||||
@@ -85,19 +82,8 @@ class H {
|
||||
}[directionName] ??
|
||||
GestureDirection.none;
|
||||
|
||||
static String? getGestureTypeName(GestureType? type) => const {
|
||||
GestureType.built_in: 'built_in',
|
||||
GestureType.shortcut: 'shortcut',
|
||||
GestureType.commandline: 'commandline',
|
||||
}[type];
|
||||
|
||||
static GestureType getGestureTypeByName(String typeName) =>
|
||||
const {
|
||||
'built_in': GestureType.built_in,
|
||||
'shortcut': GestureType.shortcut,
|
||||
'commandline': GestureType.commandline,
|
||||
}[typeName] ??
|
||||
GestureType.built_in;
|
||||
GestureType.values.findByName(typeName) ?? GestureType.built_in;
|
||||
|
||||
static Color? parseQtActiveColor(String? inp) {
|
||||
if (inp == null) return null;
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
import 'package:cherry_toast/cherry_toast.dart';
|
||||
import 'package:cherry_toast/resources/arrays.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
|
||||
|
||||
import 'alert_interface.dart';
|
||||
|
||||
class Notificator {
|
||||
static Future<CustomButton> showAlert({
|
||||
required String title,
|
||||
required String description,
|
||||
String? positiveButtonTitle,
|
||||
}) {
|
||||
return AlertImpl().showAlert(
|
||||
windowTitle: title,
|
||||
text: description,
|
||||
positiveButtonTitle: positiveButtonTitle,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<CustomButton> showConfirm({
|
||||
required String title,
|
||||
required String description,
|
||||
String? positiveButtonTitle,
|
||||
String? negativeButtonTitle,
|
||||
}) {
|
||||
return AlertImpl().showConfirm(
|
||||
windowTitle: title,
|
||||
text: description,
|
||||
positiveButtonTitle: positiveButtonTitle,
|
||||
negativeButtonTitle: negativeButtonTitle,
|
||||
);
|
||||
}
|
||||
|
||||
static _setToastIconBackgroundColor(CherryToast toast, bool isDarkMode) {
|
||||
var hslColor = HSLColor.fromColor(toast.themeColor);
|
||||
toast.themeColor = hslColor.withLightness((hslColor.lightness + (isDarkMode ? 0.4 : 0.1)).clamp(0, 1)).toColor();
|
||||
}
|
||||
|
||||
static CherryToast info(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? description,
|
||||
}) {
|
||||
var themeData = Theme.of(context);
|
||||
var toast = CherryToast.info(
|
||||
title: title,
|
||||
description: description,
|
||||
autoDismiss: true,
|
||||
animationType: ANIMATION_TYPE.FROM_TOP,
|
||||
animationDuration: Duration(milliseconds: 300),
|
||||
toastDuration: Duration(seconds: 3),
|
||||
backgroundColor: themeData.backgroundColor,
|
||||
titleStyle: themeData.textTheme.bodyText1!.copyWith(fontWeight: FontWeight.bold),
|
||||
descriptionStyle: themeData.textTheme.bodyText1!,
|
||||
);
|
||||
_setToastIconBackgroundColor(toast, themeData.brightness == Brightness.dark);
|
||||
toast.show(context);
|
||||
return toast;
|
||||
}
|
||||
|
||||
static CherryToast warning(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? description,
|
||||
}) {
|
||||
var themeData = Theme.of(context);
|
||||
var toast = CherryToast.warning(
|
||||
title: title,
|
||||
description: description,
|
||||
autoDismiss: true,
|
||||
animationType: ANIMATION_TYPE.FROM_TOP,
|
||||
animationDuration: Duration(milliseconds: 300),
|
||||
toastDuration: Duration(seconds: 3),
|
||||
backgroundColor: themeData.backgroundColor,
|
||||
titleStyle: themeData.textTheme.bodyText1!.copyWith(fontWeight: FontWeight.bold),
|
||||
descriptionStyle: themeData.textTheme.bodyText1!,
|
||||
);
|
||||
_setToastIconBackgroundColor(toast, themeData.brightness == Brightness.dark);
|
||||
toast.show(context);
|
||||
return toast;
|
||||
}
|
||||
|
||||
static CherryToast error(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? description,
|
||||
}) {
|
||||
var themeData = Theme.of(context);
|
||||
var toast = CherryToast.error(
|
||||
title: title,
|
||||
description: description,
|
||||
autoDismiss: true,
|
||||
animationType: ANIMATION_TYPE.FROM_TOP,
|
||||
animationDuration: Duration(milliseconds: 300),
|
||||
toastDuration: Duration(seconds: 3),
|
||||
backgroundColor: themeData.backgroundColor,
|
||||
titleStyle: themeData.textTheme.bodyText1!.copyWith(fontWeight: FontWeight.bold),
|
||||
descriptionStyle: themeData.textTheme.bodyText1!,
|
||||
);
|
||||
_setToastIconBackgroundColor(toast, themeData.brightness == Brightness.dark);
|
||||
toast.show(context);
|
||||
return toast;
|
||||
}
|
||||
|
||||
static CherryToast success(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? description,
|
||||
}) {
|
||||
var themeData = Theme.of(context);
|
||||
var toast = CherryToast.success(
|
||||
title: title,
|
||||
description: description,
|
||||
autoDismiss: true,
|
||||
animationType: ANIMATION_TYPE.FROM_TOP,
|
||||
animationDuration: Duration(milliseconds: 300),
|
||||
toastDuration: Duration(seconds: 3),
|
||||
backgroundColor: themeData.backgroundColor,
|
||||
titleStyle: themeData.textTheme.bodyText1!.copyWith(fontWeight: FontWeight.bold),
|
||||
descriptionStyle: themeData.textTheme.bodyText1!,
|
||||
);
|
||||
_setToastIconBackgroundColor(toast, themeData.brightness == Brightness.dark);
|
||||
toast.show(context);
|
||||
return toast;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ typedef DataColumnSortCallback = void Function(int columnIndex, bool ascending);
|
||||
///
|
||||
/// One column configuration must be provided for each column to
|
||||
/// display in the table. The list of [DataColumn] objects is passed
|
||||
/// as the `columns` argument to the [new DataTable] constructor.
|
||||
/// as the `columns` argument to the [DataTable] constructor.
|
||||
@immutable
|
||||
class DDataColumn {
|
||||
/// Creates the configuration for a column of a [DataTable].
|
||||
@@ -73,7 +73,7 @@ class DDataColumn {
|
||||
///
|
||||
/// One row configuration must be provided for each row to
|
||||
/// display in the table. The list of [DataRow] objects is passed
|
||||
/// as the `rows` argument to the [new DataTable] constructor.
|
||||
/// as the `rows` argument to the [DataTable] constructor.
|
||||
///
|
||||
/// The data for this row of the table is provided in the [cells]
|
||||
/// property of the [DataRow] object.
|
||||
@@ -995,7 +995,7 @@ class _DDataTableState extends State<DDataTable> {
|
||||
|
||||
List<Widget> _skickyHeaders = [];
|
||||
var _headerBackgroundHSLColor = HSLColor.fromColor(widget.headerBackgroundColor);
|
||||
HSLColor.fromColor(widget.headerBackgroundColor).withSaturation(.1).toColor();
|
||||
// HSLColor.fromColor(widget.headerBackgroundColor).withSaturation(.1).toColor();
|
||||
if (_headersRect != null && _headersRect!.length > 0) {
|
||||
for (var i = 0; i < _headersRect!.length; i++) {
|
||||
_skickyHeaders.add(Positioned(
|
||||
|
||||
Reference in New Issue
Block a user