diff --git a/app/lib/models/local_schemes_linux.dart b/app/lib/models/local_schemes_linux.dart index aefe39b..9c36fb3 100644 --- a/app/lib/models/local_schemes_linux.dart +++ b/app/lib/models/local_schemes_linux.dart @@ -49,15 +49,16 @@ class LocalSchemes implements LocalSchemesInterface { Future create() async { var _supportDirectory = await getApplicationSupportDirectory(); return LocalSchemeEntryLinux( - path: join(_supportDirectory.path, 'schemes', '${Uuid().v1()}.json'), - scheme: Scheme.create(), - lastModifyTime: DateTime.now(), - ); + path: join(_supportDirectory.path, 'schemes', '${Uuid().v1()}.json'), + scheme: Scheme.create(), + lastModifyTime: DateTime.now(), + ); } @override void remove(String path) { - File(path).delete(); + var file = File(path); + if (file.existsSync()) file.delete(); } } diff --git a/app/lib/models/scheme.dart b/app/lib/models/scheme.dart index 292b1bb..5ffea37 100644 --- a/app/lib/models/scheme.dart +++ b/app/lib/models/scheme.dart @@ -175,7 +175,7 @@ class Scheme { 'uploaded': uploaded, 'name': name, 'desc': description, - 'gestures': gestures, + 'gestures': gestures?.map((e) => e.toJson()).toList(), }; } diff --git a/app/lib/pages/gesture_editor.dart b/app/lib/pages/gesture_editor.dart index b29d6e7..aeb17c9 100644 --- a/app/lib/pages/gesture_editor.dart +++ b/app/lib/pages/gesture_editor.dart @@ -508,7 +508,7 @@ List _buildRowCellsEditing(BuildContext context) { _buildCommandCellsEditing(context), TableCellTextField( initText: gesture.remark, - hint: 'pls input cmd', + hint: LocaleKeys.gesture_editor_hints_remark.tr(), onComplete: (value) => context.read().setProps( remark: value, editMode: true, @@ -523,7 +523,7 @@ Widget _buildCommandCellsEditing(BuildContext context) { case GestureType.commandline: return TableCellTextField( initText: gesture.command, - hint: 'pls input cmd', + hint: LocaleKeys.gesture_editor_hints_command.tr(), onComplete: (value) => context.read().setProps( command: value, editMode: true, diff --git a/app/lib/pages/local_manager.dart b/app/lib/pages/local_manager.dart index cba1f3c..72d2252 100644 --- a/app/lib/pages/local_manager.dart +++ b/app/lib/pages/local_manager.dart @@ -26,7 +26,7 @@ class LocalManager extends StatefulWidget { class _LocalManagerState extends State { late ScrollController _scrollController; - String? _hoveringItem; + String? _hoveringItemPath; late String _selectedItemPath; @override @@ -51,7 +51,7 @@ class _LocalManagerState extends State { Color _getItemBackgroundColor(int index, String itemPath) { Color _color = index % 2 == 0 ? context.t.scaffoldBackgroundColor : context.t.backgroundColor; - if (itemPath == _hoveringItem) _color = context.t.dialogBackgroundColor; + if (itemPath == _hoveringItemPath) _color = context.t.dialogBackgroundColor; if (itemPath == _selectedItemPath) _color = context.read().currentActiveColor; return _color; } @@ -144,7 +144,7 @@ class _LocalManagerState extends State { cursor: SystemMouseCursors.click, onEnter: (_) { setState(() { - _hoveringItem = localSchemes[index].path; + _hoveringItemPath = localSchemes[index].path; }); }, child: Container( @@ -196,8 +196,13 @@ class _LocalManagerState extends State { onTap: () async { var localSchemesProvider = context.read(); var newSchemes = [...?localSchemesProvider.schemes]; - newSchemes.add(await localSchemesProvider.create()); + var newEntry = await localSchemesProvider.create(); + newSchemes.add(newEntry); localSchemesProvider.setProps(schemes: newSchemes..sort()); + setState(() { + _selectedItemPath = newEntry.path; + }); + _handleItemClick(context, newEntry); }, ), DButton.delete( @@ -209,12 +214,33 @@ class _LocalManagerState extends State { newSchemes.removeAt(index); localSchemesProvider.setProps(schemes: newSchemes); localSchemesProvider.remove(_selectedItemPath); + var newSelectedItem = newSchemes[(index - 1).clamp(1, newSchemes.length)]; + setState(() { + _selectedItemPath = newSelectedItem.path; + }); + _handleItemClick(context, newSelectedItem); + }, + ), + DButton.duplicate( + enabled: _selectedItemPath.notNull, + onTap: () async { + var localSchemesProvider = context.read(); + var newSchemes = [...?localSchemesProvider.schemes]; + var index = newSchemes.indexWhere((element) => element.path == _selectedItemPath); + var newEntry = await localSchemesProvider.create(); + newEntry.scheme = Scheme.parse(newSchemes[index].scheme.toJson()); + newEntry.scheme.id = Uuid().v1(); + newEntry.scheme.name = '${newEntry.scheme.name} (${LocaleKeys.str_copy.tr()})'; + newEntry.scheme.fromMarket = false; + newEntry.scheme.uploaded = false; + newSchemes.add(newEntry); + localSchemesProvider.setProps(schemes: newSchemes..sort()); setState(() { - _selectedItemPath = newSchemes[(index - 1).clamp(1, newSchemes.length)].path; + _selectedItemPath = newEntry.path; }); + _handleItemClick(context, newEntry); }, ), - DButton.duplicate(enabled: _selectedItemPath.notNull), DButton.apply( enabled: true, onTap: () { diff --git a/app/lib/widgets/dde_text_field.dart b/app/lib/widgets/dde_text_field.dart index aec1aa3..e775713 100644 --- a/app/lib/widgets/dde_text_field.dart +++ b/app/lib/widgets/dde_text_field.dart @@ -2,7 +2,6 @@ import 'package:dde_gesture_manager/constants/constants.dart'; import 'package:dde_gesture_manager/extensions.dart'; import 'package:dde_gesture_manager/models/settings.provider.dart'; import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; class DTextField extends StatefulWidget { final String? initText; @@ -52,6 +51,10 @@ class _DTextFieldState extends State { void didUpdateWidget(covariant DTextField oldWidget) { if (oldWidget.initText != widget.initText) { _controller.text = widget.initText ?? ''; + if (widget.initText == LocaleKeys.str_new_scheme.tr() || + (widget.initText ?? '').contains('(${LocaleKeys.str_copy.tr()})')) { + _focusNode.requestFocus(); + } } super.didUpdateWidget(oldWidget); } diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 979df7b..e64e791 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -38,14 +38,14 @@ dependencies: uuid: ^3.0.5 adaptive_scrollbar: ^2.1.0 flutter_platform_alert: ^0.2.1 + cached_network_image: ^3.2.0 + url_launcher: ^6.0.17 markdown_editor_ot: path: 3rd_party/markdown_editor_ot cherry_toast: path: 3rd_party/cherry_toast xdg_directories_web: path: 3rd_party/xdg_directories_web - cached_network_image: ^3.2.0 - url_launcher: ^6.0.17 dev_dependencies: flutter_test: diff --git a/app/resources/langs/en.json b/app/resources/langs/en.json index 276b910..105a844 100644 --- a/app/resources/langs/en.json +++ b/app/resources/langs/en.json @@ -59,6 +59,10 @@ "info": { "name": "Scheme Name", "description": "Description" + }, + "hints": { + "command": "Please enter the command you want to execute", + "remark": "Please enter a remark information" } }, "operation": { @@ -70,7 +74,8 @@ }, "str": { "null": "Null", - "new_scheme": "New gesture scheme" + "new_scheme": "New gesture scheme", + "copy": "copy" }, "built_in_commands": { "ShowWorkspace": "ShowWorkspace", diff --git a/app/resources/langs/zh-CN.json b/app/resources/langs/zh-CN.json index 53cdbdb..f4be855 100644 --- a/app/resources/langs/zh-CN.json +++ b/app/resources/langs/zh-CN.json @@ -59,6 +59,10 @@ "info": { "name": "方案名称", "description": "方案描述" + }, + "hints": { + "command": "请输入要执行的命令", + "remark": "请输入备注信息" } }, "operation": { @@ -70,7 +74,8 @@ }, "str": { "null": "无", - "new_scheme": "新建手势方案" + "new_scheme": "新建手势方案", + "copy": "副本" }, "built_in_commands": { "ShowWorkspace": "显示工作区",