mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-05 15:55:19 +01:00
new: editor custom theme
This commit is contained in:
79
lib/data/res/highlight.dart
Normal file
79
lib/data/res/highlight.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:highlight/highlight_core.dart';
|
||||
import 'package:highlight/languages/accesslog.dart';
|
||||
import 'package:highlight/languages/awk.dart';
|
||||
import 'package:highlight/languages/bash.dart';
|
||||
import 'package:highlight/languages/cmake.dart';
|
||||
import 'package:highlight/languages/cpp.dart';
|
||||
import 'package:highlight/languages/css.dart';
|
||||
import 'package:highlight/languages/dart.dart';
|
||||
import 'package:highlight/languages/diff.dart';
|
||||
import 'package:highlight/languages/go.dart';
|
||||
import 'package:highlight/languages/htmlbars.dart';
|
||||
import 'package:highlight/languages/ini.dart';
|
||||
import 'package:highlight/languages/java.dart';
|
||||
import 'package:highlight/languages/javascript.dart';
|
||||
import 'package:highlight/languages/json.dart';
|
||||
import 'package:highlight/languages/kotlin.dart';
|
||||
import 'package:highlight/languages/lisp.dart';
|
||||
import 'package:highlight/languages/lua.dart';
|
||||
import 'package:highlight/languages/nix.dart';
|
||||
import 'package:highlight/languages/objectivec.dart';
|
||||
import 'package:highlight/languages/perl.dart';
|
||||
import 'package:highlight/languages/php.dart';
|
||||
import 'package:highlight/languages/powershell.dart';
|
||||
import 'package:highlight/languages/python.dart';
|
||||
import 'package:highlight/languages/ruby.dart';
|
||||
import 'package:highlight/languages/rust.dart';
|
||||
import 'package:highlight/languages/sql.dart';
|
||||
import 'package:highlight/languages/swift.dart';
|
||||
import 'package:highlight/languages/tex.dart';
|
||||
import 'package:highlight/languages/typescript.dart';
|
||||
import 'package:highlight/languages/vim.dart';
|
||||
import 'package:highlight/languages/xml.dart';
|
||||
import 'package:highlight/languages/yaml.dart';
|
||||
|
||||
// KEY: fileNameSuffix
|
||||
// VAL: highlight
|
||||
final _suffix2HighlightMap = {
|
||||
'dart': dart,
|
||||
'go': go,
|
||||
'rust': rust,
|
||||
'lua': lua,
|
||||
'sh': bash,
|
||||
'py': python,
|
||||
'js': javascript,
|
||||
'ts': typescript,
|
||||
'java': java,
|
||||
'kt': kotlin,
|
||||
'swift': swift,
|
||||
'c': cpp,
|
||||
'oc': objectivec,
|
||||
'ruby': ruby,
|
||||
'perl': perl,
|
||||
'php': php,
|
||||
'nix': nix,
|
||||
'lisp': lisp,
|
||||
'sql': sql,
|
||||
'powershell': powershell,
|
||||
'log': accesslog,
|
||||
'ini': ini,
|
||||
'cmake': cmake,
|
||||
'awk': awk,
|
||||
'json': json,
|
||||
'yaml': yaml,
|
||||
'xml': xml,
|
||||
'cpp': cpp,
|
||||
'diff': diff,
|
||||
'css': css,
|
||||
'html': htmlbars,
|
||||
'tex': tex,
|
||||
'vim': vim,
|
||||
};
|
||||
|
||||
extension HighlightString on String? {
|
||||
Mode? get highlight {
|
||||
if (this == null) return null;
|
||||
final suffix = this!.split('.').last;
|
||||
return _suffix2HighlightMap[suffix];
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,8 @@ class SettingStore extends PersistentStore {
|
||||
// SSH virtual key (ctrl | alt) auto turn off
|
||||
StoreProperty<bool> get sshVirtualKeyAutoOff =>
|
||||
property('sshVirtualKeyAutoOff', defaultValue: true);
|
||||
|
||||
// Editor theme
|
||||
StoreProperty<String> get editorTheme =>
|
||||
property('editorTheme', defaultValue: 'monokai');
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"downloadFinished": "Download abgeschlossen",
|
||||
"downloadStatus": "{percent}% von {size}",
|
||||
"edit": "Bearbeiten",
|
||||
"editor": "Redakteure",
|
||||
"encode": "Encode",
|
||||
"error": "Fehler",
|
||||
"exampleName": "Servername",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"downloadFinished": "Download finished",
|
||||
"downloadStatus": "{percent}% of {size}",
|
||||
"edit": "Edit",
|
||||
"editor": "Editor",
|
||||
"encode": "Encode",
|
||||
"error": "Error",
|
||||
"exampleName": "Example name",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"downloadFinished": "下载完成",
|
||||
"downloadStatus": "{size} 的 {percent}%",
|
||||
"edit": "编辑",
|
||||
"editor": "编辑器",
|
||||
"encode": "编码",
|
||||
"error": "错误",
|
||||
"exampleName": "名称示例",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"downloadFinished": "下載完成",
|
||||
"downloadStatus": "{size} 的 {percent}%",
|
||||
"edit": "編輯",
|
||||
"editor": "編輯器",
|
||||
"encode": "編碼",
|
||||
"error": "錯誤",
|
||||
"exampleName": "名稱範例",
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import 'package:code_text_field/code_text_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||
import 'package:flutter_highlight/themes/monokai-sublime.dart';
|
||||
import 'package:highlight/languages/java.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_highlight/themes/monokai.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/data/res/highlight.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
class EditorPage extends StatefulWidget {
|
||||
final String? initCode;
|
||||
const EditorPage({Key? key, this.initCode}) : super(key: key);
|
||||
final String? fileName;
|
||||
const EditorPage({Key? key, this.initCode, this.fileName}) : super(key: key);
|
||||
|
||||
@override
|
||||
_EditorPageState createState() => _EditorPageState();
|
||||
@@ -15,16 +19,18 @@ class EditorPage extends StatefulWidget {
|
||||
class _EditorPageState extends State<EditorPage> {
|
||||
late CodeController _controller;
|
||||
late final _focusNode = FocusNode();
|
||||
final _setting = locator<SettingStore>();
|
||||
late Map<String, TextStyle> _codeTheme;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode.requestFocus();
|
||||
_controller = CodeController(
|
||||
text: widget.initCode,
|
||||
language: java,
|
||||
analyzer: const DefaultLocalAnalyzer(),
|
||||
);
|
||||
text: widget.initCode,
|
||||
language: widget.fileName.highlight,
|
||||
);
|
||||
_codeTheme = themeMap[_setting.editorTheme.fetch()] ?? monokaiTheme;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -37,28 +43,23 @@ class _EditorPageState extends State<EditorPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: monokaiSublimeTheme['root']!.backgroundColor,
|
||||
backgroundColor: _codeTheme['root']!.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Editor'),
|
||||
title: Text(widget.fileName ?? ''),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.done),
|
||||
onPressed: () {
|
||||
context.pop(_controller.fullText);
|
||||
context.pop(_controller.text);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: CodeTheme(
|
||||
data: CodeThemeData(styles: monokaiSublimeTheme),
|
||||
child: SingleChildScrollView(
|
||||
child: CodeField(
|
||||
controller: _controller,
|
||||
gutterStyle: const GutterStyle(
|
||||
width: 37,
|
||||
showLineNumbers: false,
|
||||
),
|
||||
),
|
||||
data: CodeThemeData(styles: _codeTheme),
|
||||
child: CodeField(
|
||||
controller: _controller,
|
||||
textStyle: const TextStyle(fontFamily: 'SourceCode'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/locale.dart';
|
||||
@@ -39,6 +40,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
final maxRetryKey = GlobalKey<PopupMenuButtonState<int>>();
|
||||
final fontSizeKey = GlobalKey<PopupMenuButtonState<double>>();
|
||||
final localeKey = GlobalKey<PopupMenuButtonState<String>>();
|
||||
final editorThemeKey = GlobalKey<PopupMenuButtonState<String>>();
|
||||
|
||||
late final SettingStore _setting;
|
||||
late final ServerProvider _serverProvider;
|
||||
@@ -52,6 +54,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
late int _updateInterval;
|
||||
late double _fontSize;
|
||||
late String _localeCode;
|
||||
late String _editorTheme;
|
||||
|
||||
String? _pushToken;
|
||||
|
||||
@@ -74,6 +77,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_maxRetryCount = _setting.maxRetryCount.fetch()!;
|
||||
_selectedColorValue = _setting.primaryColor.fetch()!;
|
||||
_fontSize = _setting.termFontSize.fetch()!;
|
||||
_editorTheme = _setting.editorTheme.fetch()!;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -94,6 +98,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
// SSH
|
||||
_buildTitle('SSH'),
|
||||
_buildSSH(),
|
||||
// Editor
|
||||
_buildTitle('Editor'),
|
||||
_buildEditor(),
|
||||
const SizedBox(height: 37),
|
||||
],
|
||||
),
|
||||
@@ -116,7 +123,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
final children = [
|
||||
_buildLocale(),
|
||||
_buildThemeMode(),
|
||||
_buildAppColorPreview(),
|
||||
_buildAppColor(),
|
||||
_buildLaunchPage(),
|
||||
_buildCheckUpdate(),
|
||||
];
|
||||
@@ -152,6 +159,14 @@ class _SettingPageState extends State<SettingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditor() {
|
||||
return Column(
|
||||
children: [
|
||||
_buildEditorTheme(),
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDistLogoSwitch() {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
@@ -232,7 +247,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppColorPreview() {
|
||||
Widget _buildAppColor() {
|
||||
return ListTile(
|
||||
trailing: ClipOval(
|
||||
child: Container(
|
||||
@@ -247,6 +262,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
onTap: () async {
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.appPrimaryColor),
|
||||
child: MaterialColorPicker(
|
||||
shrinkWrap: true,
|
||||
allowShades: true,
|
||||
@@ -442,23 +458,21 @@ class _SettingPageState extends State<SettingPage> {
|
||||
onTap: () {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () async => await _pickFontFile(),
|
||||
child: Text(_s.pickFile),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => setState(() {
|
||||
_setting.fontPath.delete();
|
||||
context.pop();
|
||||
_showRestartSnackbar();
|
||||
}),
|
||||
child: Text(_s.clear),
|
||||
)
|
||||
],
|
||||
),
|
||||
title: Text(_s.font),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async => await _pickFontFile(),
|
||||
child: Text(_s.pickFile),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => setState(() {
|
||||
_setting.fontPath.delete();
|
||||
context.pop();
|
||||
_showRestartSnackbar();
|
||||
}),
|
||||
child: Text(_s.clear),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -606,4 +620,37 @@ class _SettingPageState extends State<SettingPage> {
|
||||
trailing: buildSwitch(context, _setting.sshVirtualKeyAutoOff),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditorTheme() {
|
||||
final items = themeMap.keys.map(
|
||||
(key) {
|
||||
return PopupMenuItem<String>(
|
||||
value: key,
|
||||
child: Text(key),
|
||||
);
|
||||
},
|
||||
).toList();
|
||||
return ListTile(
|
||||
title: Text(_s.editor + _s.theme),
|
||||
trailing: PopupMenuButton(
|
||||
key: editorThemeKey,
|
||||
itemBuilder: (BuildContext context) => items,
|
||||
initialValue: _editorTheme,
|
||||
onSelected: (String idx) {
|
||||
setState(() {
|
||||
_editorTheme = idx;
|
||||
});
|
||||
_setting.editorTheme.put(idx);
|
||||
_showRestartSnackbar();
|
||||
},
|
||||
child: Text(
|
||||
_editorTheme,
|
||||
style: textSize15,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
editorThemeKey.currentState?.showButtonMenu();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,12 +180,14 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
context.pop();
|
||||
final stat = await file.stat();
|
||||
if (stat.size > 1024 * 1024) {
|
||||
showRoundDialog(context: context, child: Text('too big'));
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: Text(_s.fileTooLarge(fileName, stat.size, '1m')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final f = await File(file.absolute.path).readAsString();
|
||||
AppRoute(EditorPage(initCode: f), 'sftp dled editor')
|
||||
.go(context);
|
||||
AppRoute(EditorPage(initCode: f), 'sftp dled editor').go(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user