feat (Editor): Add an option to set the editor font family (#1078)
* feat (Editor): Add an option to set the editor font family Add the `editorFontFamily` property to the settings storage and implement font family selection functionality on editor-related pages. Also, update all pages that use the editor settings to support the newly added font family option. * refactor(editor): Optimize the logic for editor font settings Standardize the method for retrieving font settings on the editor page to avoid redundant calls to the `fetch()` method. Extract the font retrieval logic into variables or anonymous functions to improve code readability and performance.
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -9,7 +9,7 @@
|
|||||||
[submodule "fl_lib"]
|
[submodule "fl_lib"]
|
||||||
path = packages/fl_lib
|
path = packages/fl_lib
|
||||||
url = https://github.com/lollipopkit/fl_lib
|
url = https://github.com/lollipopkit/fl_lib
|
||||||
branch = main
|
branch = before-sqlite
|
||||||
[submodule "fl_build"]
|
[submodule "fl_build"]
|
||||||
path = packages/fl_build
|
path = packages/fl_build
|
||||||
url = https://github.com/lppcg/fl_build.git
|
url = https://github.com/lppcg/fl_build.git
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ abstract final class GithubIds {
|
|||||||
'jjyou-github',
|
'jjyou-github',
|
||||||
'yeluonight',
|
'yeluonight',
|
||||||
'Yinhono',
|
'Yinhono',
|
||||||
|
'kuvaldini',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ class SettingStore extends HiveStore {
|
|||||||
|
|
||||||
late final editorFontSize = propertyDefault('editorFontSize', 12.5);
|
late final editorFontSize = propertyDefault('editorFontSize', 12.5);
|
||||||
|
|
||||||
|
late final editorFontFamily = propertyDefault('editorFontFamily', '');
|
||||||
|
|
||||||
/// Trusted SSH host key fingerprints keyed by `serverId::keyType`.
|
/// Trusted SSH host key fingerprints keyed by `serverId::keyType`.
|
||||||
late final sshKnownHostFingerprints = propertyDefault<Map<String, String>>(
|
late final sshKnownHostFingerprints = propertyDefault<Map<String, String>>(
|
||||||
'sshKnownHostFingerprints',
|
'sshKnownHostFingerprints',
|
||||||
|
|||||||
@@ -465,6 +465,7 @@ extension _App on _AppSettingsPageState {
|
|||||||
|
|
||||||
/// Encode [map] to String with indent `\t`
|
/// Encode [map] to String with indent `\t`
|
||||||
final text = jsonIndentEncoder.convert(mapForEditor);
|
final text = jsonIndentEncoder.convert(mapForEditor);
|
||||||
|
final editorFont = _setting.editorFontFamily.fetch();
|
||||||
await EditorPage.route.go(
|
await EditorPage.route.go(
|
||||||
context,
|
context,
|
||||||
args: EditorPageArgs(
|
args: EditorPageArgs(
|
||||||
@@ -472,9 +473,10 @@ extension _App on _AppSettingsPageState {
|
|||||||
lang: ProgLang.json,
|
lang: ProgLang.json,
|
||||||
title: libL10n.setting,
|
title: libL10n.setting,
|
||||||
onSave: onSave,
|
onSave: onSave,
|
||||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
closeAfterSave: _setting.closeAfterSave.fetch(),
|
||||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
softWrap: _setting.editorSoftWrap.fetch(),
|
||||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
enableHighlight: _setting.editorHighlight.fetch(),
|
||||||
|
fontFamily: editorFont.isEmpty ? null : editorFont,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ extension _Editor on _AppSettingsPageState {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
_buildEditorWrap(),
|
_buildEditorWrap(),
|
||||||
|
_buildEditorFontFamily(),
|
||||||
_buildEditorFontSize(),
|
_buildEditorFontSize(),
|
||||||
_buildEditorTheme(),
|
_buildEditorTheme(),
|
||||||
_buildEditorDarkTheme(),
|
_buildEditorDarkTheme(),
|
||||||
@@ -96,6 +97,43 @@ extension _Editor on _AppSettingsPageState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildEditorFontFamily() {
|
||||||
|
return ListTile(
|
||||||
|
leading: const Icon(MingCute.font_fill),
|
||||||
|
title: Text(libL10n.font),
|
||||||
|
trailing: ValBuilder(
|
||||||
|
listenable: _setting.editorFontFamily.listenable(),
|
||||||
|
builder: (val) => Text(
|
||||||
|
val.isEmpty ? libL10n.auto.toLowerCase() : val,
|
||||||
|
style: UIs.text15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () => _showFontFamilyDialog(_setting.editorFontFamily),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showFontFamilyDialog(HiveProp<String> property) {
|
||||||
|
final ctrl = TextEditingController(text: property.fetch());
|
||||||
|
void onSave() {
|
||||||
|
context.pop();
|
||||||
|
property.put(ctrl.text.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
context.showRoundDialog(
|
||||||
|
title: libL10n.font,
|
||||||
|
child: Input(
|
||||||
|
controller: ctrl,
|
||||||
|
autoFocus: true,
|
||||||
|
type: TextInputType.text,
|
||||||
|
icon: Icons.font_download,
|
||||||
|
hint: 'monospace / Consolas / Fira Code ...',
|
||||||
|
suggestion: false,
|
||||||
|
onSubmitted: (_) => onSave(),
|
||||||
|
),
|
||||||
|
actions: Btn.ok(onTap: onSave).toList,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _showFontSizeDialog(HiveProp<double> property) {
|
void _showFontSizeDialog(HiveProp<double> property) {
|
||||||
final ctrl = TextEditingController(text: property.fetch().toString());
|
final ctrl = TextEditingController(text: property.fetch().toString());
|
||||||
void onSave() {
|
void onSave() {
|
||||||
|
|||||||
@@ -69,10 +69,12 @@ extension _SSH on _AppSettingsPageState {
|
|||||||
// iOS can't copy file to app dir, so we need to use the original path
|
// iOS can't copy file to app dir, so we need to use the original path
|
||||||
if (isIOS) {
|
if (isIOS) {
|
||||||
_setting.fontPath.put(path);
|
_setting.fontPath.put(path);
|
||||||
|
await FontUtils.loadFrom(path);
|
||||||
} else {
|
} else {
|
||||||
final fontFile = File(path);
|
final fontFile = File(path);
|
||||||
await fontFile.copy(Paths.font);
|
await fontFile.copy(Paths.font);
|
||||||
_setting.fontPath.put(Paths.font);
|
_setting.fontPath.put(Paths.font);
|
||||||
|
await FontUtils.loadFrom(Paths.font);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.pop();
|
context.pop();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import 'package:server_box/data/model/sftp/worker.dart';
|
|||||||
import 'package:server_box/data/provider/server/all.dart';
|
import 'package:server_box/data/provider/server/all.dart';
|
||||||
import 'package:server_box/data/provider/sftp.dart';
|
import 'package:server_box/data/provider/sftp.dart';
|
||||||
import 'package:server_box/data/res/misc.dart';
|
import 'package:server_box/data/res/misc.dart';
|
||||||
import 'package:server_box/data/store/setting.dart';
|
import 'package:server_box/data/res/store.dart';
|
||||||
import 'package:server_box/view/page/storage/sftp.dart';
|
import 'package:server_box/view/page/storage/sftp.dart';
|
||||||
import 'package:server_box/view/page/storage/sftp_mission.dart';
|
import 'package:server_box/view/page/storage/sftp_mission.dart';
|
||||||
|
|
||||||
@@ -366,9 +366,13 @@ extension _OnTapFile on _LocalFilePageState {
|
|||||||
context.showSnackBar(libL10n.saved);
|
context.showSnackBar(libL10n.saved);
|
||||||
setStateSafe(() {});
|
setStateSafe(() {});
|
||||||
},
|
},
|
||||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
closeAfterSave: Stores.setting.closeAfterSave.fetch(),
|
||||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
softWrap: Stores.setting.editorSoftWrap.fetch(),
|
||||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
enableHighlight: Stores.setting.editorHighlight.fetch(),
|
||||||
|
fontFamily: () {
|
||||||
|
final font = Stores.setting.editorFontFamily.fetch();
|
||||||
|
return font.isEmpty ? null : font;
|
||||||
|
}(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import 'package:server_box/data/provider/server/single.dart';
|
|||||||
import 'package:server_box/data/provider/sftp.dart';
|
import 'package:server_box/data/provider/sftp.dart';
|
||||||
import 'package:server_box/data/res/misc.dart';
|
import 'package:server_box/data/res/misc.dart';
|
||||||
import 'package:server_box/data/res/store.dart';
|
import 'package:server_box/data/res/store.dart';
|
||||||
import 'package:server_box/data/store/setting.dart';
|
|
||||||
import 'package:server_box/view/page/ssh/page/page.dart';
|
import 'package:server_box/view/page/ssh/page/page.dart';
|
||||||
import 'package:server_box/view/page/storage/local.dart';
|
import 'package:server_box/view/page/storage/local.dart';
|
||||||
import 'package:server_box/view/page/storage/sftp_mission.dart';
|
import 'package:server_box/view/page/storage/sftp_mission.dart';
|
||||||
@@ -360,9 +359,13 @@ extension _Actions on _SftpPageState {
|
|||||||
.add(SftpReq(req.spi, remotePath, localPath, SftpReqType.upload));
|
.add(SftpReq(req.spi, remotePath, localPath, SftpReqType.upload));
|
||||||
context.showSnackBar(l10n.added2List);
|
context.showSnackBar(l10n.added2List);
|
||||||
},
|
},
|
||||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
closeAfterSave: Stores.setting.closeAfterSave.fetch(),
|
||||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
softWrap: Stores.setting.editorSoftWrap.fetch(),
|
||||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
enableHighlight: Stores.setting.editorHighlight.fetch(),
|
||||||
|
fontFamily: () {
|
||||||
|
final font = Stores.setting.editorFontFamily.fetch();
|
||||||
|
return font.isEmpty ? null : font;
|
||||||
|
}(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule packages/fl_lib updated: c1d32f89cd...ffb12c8672
Reference in New Issue
Block a user