mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: editor lang parse
This commit is contained in:
@@ -15,7 +15,6 @@ import 'package:server_box/data/model/container/ps.dart';
|
||||
import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/provider/container.dart';
|
||||
import 'package:server_box/view/page/ssh/page.dart';
|
||||
import 'package:server_box/view/widget/two_line_text.dart';
|
||||
|
||||
class ContainerPage extends StatefulWidget {
|
||||
final SpiRequiredArgs args;
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:computer/computer.dart';
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_highlight/themes/a11y-light.dart';
|
||||
import 'package:flutter_highlight/themes/monokai.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/data/res/highlight.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/data/store/setting.dart';
|
||||
|
||||
import 'package:server_box/view/widget/two_line_text.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
import 'package:server_box/view/widget/code_find_panel_view.dart';
|
||||
|
||||
enum EditorPageRetType { path, text }
|
||||
|
||||
final class EditorPageRet {
|
||||
final EditorPageRetType typ;
|
||||
final String val;
|
||||
|
||||
const EditorPageRet(this.typ, this.val);
|
||||
}
|
||||
|
||||
final class EditorPageArgs {
|
||||
/// If path is not null, then it's a file editor
|
||||
/// If path is null, then it's a text editor
|
||||
final String? path;
|
||||
|
||||
/// Only used when path is null
|
||||
final String? text;
|
||||
|
||||
/// Code of language, eg: dart, go, etc.
|
||||
/// Higher priority than [path]
|
||||
final String? langCode;
|
||||
|
||||
final String? title;
|
||||
|
||||
final void Function(BuildContext, EditorPageRet) onSave;
|
||||
|
||||
const EditorPageArgs({
|
||||
this.path,
|
||||
this.text,
|
||||
this.langCode,
|
||||
this.title,
|
||||
required this.onSave,
|
||||
});
|
||||
}
|
||||
|
||||
class EditorPage extends StatefulWidget {
|
||||
final EditorPageArgs? args;
|
||||
|
||||
const EditorPage({super.key, this.args});
|
||||
|
||||
static const route = AppRoute<void, EditorPageArgs>(
|
||||
page: EditorPage.new,
|
||||
path: '/editor',
|
||||
);
|
||||
|
||||
@override
|
||||
State<EditorPage> createState() => _EditorPageState();
|
||||
}
|
||||
|
||||
class _EditorPageState extends State<EditorPage> {
|
||||
final _focusNode = FocusNode();
|
||||
|
||||
late CodeLineEditingController _controller;
|
||||
late CodeFindController _findController;
|
||||
late Map<String, TextStyle> _codeTheme;
|
||||
|
||||
String? _langCode;
|
||||
var _saved = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_findController.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = CodeLineEditingController();
|
||||
_findController = CodeFindController(_controller);
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
if (context.isDark) {
|
||||
_codeTheme = themeMap[Stores.setting.editorDarkTheme.fetch()] ?? monokaiTheme;
|
||||
} else {
|
||||
_codeTheme = themeMap[Stores.setting.editorTheme.fetch()] ?? a11yLightTheme;
|
||||
}
|
||||
_focusNode.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
_pop();
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: _codeTheme['root']?.backgroundColor,
|
||||
appBar: _buildAppBar(),
|
||||
body: _buildBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return CustomAppBar(
|
||||
centerTitle: true,
|
||||
title: TwoLineText(
|
||||
up: widget.args?.title ?? widget.args?.path?.getFileName() ?? l10n.unknown,
|
||||
down: l10n.editor,
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
tooltip: libL10n.search,
|
||||
onPressed: () => _findController.findMode(),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.language),
|
||||
tooltip: libL10n.language,
|
||||
onSelected: (value) {
|
||||
_langCode = value;
|
||||
},
|
||||
initialValue: _langCode,
|
||||
itemBuilder: (BuildContext context) {
|
||||
return Highlights.all.keys.map((e) {
|
||||
return PopupMenuItem(
|
||||
value: e,
|
||||
child: Text(e),
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.save),
|
||||
tooltip: l10n.save,
|
||||
onPressed: _onSave,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return Container(
|
||||
color: _EditorReTheme.getBackground(_codeTheme),
|
||||
child: CodeEditor(
|
||||
controller: _controller,
|
||||
findController: _findController,
|
||||
wordWrap: Stores.setting.editorSoftWrap.fetch(),
|
||||
focusNode: _focusNode,
|
||||
indicatorBuilder: (context, editingController, chunkController, notifier) {
|
||||
return Row(
|
||||
children: [
|
||||
DefaultCodeLineNumber(
|
||||
controller: editingController,
|
||||
notifier: notifier,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
findBuilder: (context, controller, readOnly) =>
|
||||
CodeFindPanelView(controller: controller, readOnly: readOnly),
|
||||
// toolbarController: const ContextMenuControllerImpl(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension on _EditorPageState {
|
||||
Future<void> _init() async {
|
||||
/// Higher priority than [path]
|
||||
if (Stores.setting.editorHighlight.fetch()) {
|
||||
_langCode = widget.args?.langCode ?? Highlights.getCode(widget.args?.path);
|
||||
}
|
||||
if (_langCode == null) {
|
||||
_setupCtrl();
|
||||
} else {
|
||||
Future.delayed(const Duration(milliseconds: 377)).then(
|
||||
(value) async => await _setupCtrl(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setupCtrl() async {
|
||||
final path = widget.args?.path;
|
||||
final text = widget.args?.text;
|
||||
if (path != null) {
|
||||
final code = await Computer.shared.startNoParam(
|
||||
() => File(path).readAsString(),
|
||||
);
|
||||
_controller.text = code;
|
||||
} else if (text != null) {
|
||||
_controller.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
void _onSave() async {
|
||||
// If path is not null, then it's a file editor
|
||||
final path = widget.args?.path;
|
||||
if (path != null) {
|
||||
final (res, _) = await context.showLoadingDialog(
|
||||
fn: () => File(path).writeAsString(_controller.text),
|
||||
);
|
||||
if (res == null) {
|
||||
context.showSnackBar(libL10n.fail);
|
||||
return;
|
||||
}
|
||||
final ret = EditorPageRet(EditorPageRetType.path, path);
|
||||
widget.args?.onSave(context, ret);
|
||||
_saved = true;
|
||||
|
||||
final pop_ = SettingStore.instance.closeAfterSave.fetch();
|
||||
if (pop_) _pop();
|
||||
return;
|
||||
}
|
||||
// it's a text editor
|
||||
final ret = EditorPageRet(EditorPageRetType.text, _controller.text);
|
||||
widget.args?.onSave(context, ret);
|
||||
_saved = true;
|
||||
|
||||
final pop_ = SettingStore.instance.closeAfterSave.fetch();
|
||||
if (pop_) _pop();
|
||||
}
|
||||
|
||||
void _pop() async {
|
||||
if (!_saved) {
|
||||
final ret = await context.showRoundDialog(
|
||||
title: libL10n.attention,
|
||||
child: Text(libL10n.askContinue(libL10n.exit)),
|
||||
actions: Btnx.cancelOk,
|
||||
);
|
||||
if (ret != true) return;
|
||||
}
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
|
||||
class _EditorReTheme {
|
||||
static Color? getBackground(Map<String, TextStyle> codeTheme) {
|
||||
return codeTheme['root']?.backgroundColor;
|
||||
}
|
||||
|
||||
// static TextStyle? getTextStyle(Map<String, TextStyle> codeTheme) {
|
||||
// return codeTheme['root'];
|
||||
// }
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/data/model/app/shell_func.dart';
|
||||
import 'package:server_box/data/model/server/proc.dart';
|
||||
import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/view/widget/two_line_text.dart';
|
||||
|
||||
class ProcessPage extends StatefulWidget {
|
||||
final SpiRequiredArgs args;
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/provider/pve.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/view/widget/percent_circle.dart';
|
||||
import 'package:server_box/view/widget/two_line_text.dart';
|
||||
|
||||
final class PvePageArgs {
|
||||
final Spi spi;
|
||||
|
||||
@@ -209,7 +209,7 @@ extension _Server on _AppSettingsPageState {
|
||||
final map = Stores.setting.getAllMap(includeInternalKeys: true);
|
||||
final keys = map.keys;
|
||||
|
||||
void onSave(BuildContext context, EditorPageRet ret) {
|
||||
void onSave(EditorPageRet ret) {
|
||||
if (ret.typ != EditorPageRetType.text) {
|
||||
context.showRoundDialog(
|
||||
title: libL10n.fail,
|
||||
@@ -240,9 +240,12 @@ extension _Server on _AppSettingsPageState {
|
||||
context,
|
||||
args: EditorPageArgs(
|
||||
text: text,
|
||||
langCode: 'json',
|
||||
lang: ProgLang.json,
|
||||
title: libL10n.setting,
|
||||
onSave: onSave,
|
||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import 'package:server_box/data/res/url.dart';
|
||||
import 'package:server_box/data/model/app/net_view.dart';
|
||||
import 'package:server_box/data/res/build_data.dart';
|
||||
import 'package:server_box/view/page/backup.dart';
|
||||
import 'package:server_box/view/page/editor.dart';
|
||||
import 'package:server_box/view/page/private_key/list.dart';
|
||||
import 'package:server_box/view/page/setting/platform/android.dart';
|
||||
import 'package:server_box/view/page/setting/platform/ios.dart';
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:server_box/data/provider/sftp.dart';
|
||||
import 'package:server_box/data/res/misc.dart';
|
||||
|
||||
import 'package:server_box/data/model/app/path_with_prefix.dart';
|
||||
import 'package:server_box/view/page/editor.dart';
|
||||
import 'package:server_box/data/store/setting.dart';
|
||||
import 'package:server_box/view/page/storage/sftp.dart';
|
||||
import 'package:server_box/view/page/storage/sftp_mission.dart';
|
||||
|
||||
@@ -103,16 +103,14 @@ class _LocalFilePageState extends State<LocalFilePage> with AutomaticKeepAliveCl
|
||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 13),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0 && _path.canBack) {
|
||||
return CardX(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.arrow_back),
|
||||
title: const Text('..'),
|
||||
onTap: () {
|
||||
_path.update('..');
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.arrow_back),
|
||||
title: const Text('..'),
|
||||
onTap: () {
|
||||
_path.update('..');
|
||||
setState(() {});
|
||||
},
|
||||
).cardx;
|
||||
}
|
||||
|
||||
if (_path.canBack) index--;
|
||||
@@ -218,10 +216,13 @@ class _LocalFilePageState extends State<LocalFilePage> with AutomaticKeepAliveCl
|
||||
context,
|
||||
args: EditorPageArgs(
|
||||
path: file.absolute.path,
|
||||
onSave: (context, _) {
|
||||
onSave: (_) {
|
||||
context.showSnackBar(l10n.saved);
|
||||
setState(() {});
|
||||
},
|
||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -13,17 +13,15 @@ import 'package:server_box/data/model/sftp/worker.dart';
|
||||
import 'package:server_box/data/provider/sftp.dart';
|
||||
import 'package:server_box/data/res/misc.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/view/page/editor.dart';
|
||||
import 'package:server_box/data/store/setting.dart';
|
||||
import 'package:server_box/view/page/ssh/page.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/widget/omit_start_text.dart';
|
||||
import 'package:server_box/view/widget/two_line_text.dart';
|
||||
import 'package:server_box/view/widget/unix_perm.dart';
|
||||
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
|
||||
|
||||
final class SftpPageArgs {
|
||||
final Spi spi;
|
||||
final bool isSelect;
|
||||
@@ -108,15 +106,15 @@ extension _UI on _SftpPageState {
|
||||
(_SortType.size, l10n.size),
|
||||
(_SortType.time, l10n.time),
|
||||
];
|
||||
return _sortOption.listenVal((value) {
|
||||
return _sortOption.listenVal(
|
||||
(value) {
|
||||
return PopupMenuButton<_SortType>(
|
||||
icon: const Icon(Icons.sort),
|
||||
itemBuilder: (context) {
|
||||
return options.map((r) {
|
||||
final (type, name) = r;
|
||||
final selected = type == value.sortBy;
|
||||
final title =
|
||||
selected ? "$name (${value.reversed ? '-' : '+'})" : name;
|
||||
final title = selected ? "$name (${value.reversed ? '-' : '+'})" : name;
|
||||
return PopupMenuItem(
|
||||
value: type,
|
||||
child: Text(
|
||||
@@ -353,7 +351,7 @@ extension _Actions on _SftpPageState {
|
||||
context,
|
||||
args: EditorPageArgs(
|
||||
path: localPath,
|
||||
onSave: (context, _) {
|
||||
onSave: (_) {
|
||||
SftpProvider.add(SftpReq(
|
||||
req.spi,
|
||||
remotePath,
|
||||
@@ -362,6 +360,9 @@ extension _Actions on _SftpPageState {
|
||||
));
|
||||
context.showSnackBar(l10n.added2List);
|
||||
},
|
||||
closeAfterSave: SettingStore.instance.closeAfterSave.fetch(),
|
||||
softWrap: SettingStore.instance.editorSoftWrap.fetch(),
|
||||
enableHighlight: SettingStore.instance.editorHighlight.fetch(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -653,9 +654,7 @@ extension _Actions on _SftpPageState {
|
||||
fs.removeAt(0);
|
||||
}
|
||||
|
||||
if (fs.isNotEmpty &&
|
||||
fs.firstOrNull?.filename == '..' &&
|
||||
_status.path.path == '/') {
|
||||
if (fs.isNotEmpty && fs.firstOrNull?.filename == '..' && _status.path.path == '/') {
|
||||
fs.removeAt(0);
|
||||
}
|
||||
if (mounted) {
|
||||
@@ -909,9 +908,7 @@ const _extCmdMap = {
|
||||
|
||||
/// Return fmt: 2021-01-01 00:00:00
|
||||
String _getTime(int? unixMill) {
|
||||
return DateTime.fromMillisecondsSinceEpoch((unixMill ?? 0) * 1000)
|
||||
.toString()
|
||||
.replaceFirst('.000', '');
|
||||
return DateTime.fromMillisecondsSinceEpoch((unixMill ?? 0) * 1000).toString().replaceFirst('.000', '');
|
||||
}
|
||||
|
||||
enum _SortType {
|
||||
@@ -930,8 +927,7 @@ enum _SortType {
|
||||
files.sort(
|
||||
comparator
|
||||
.thenWithComparator(
|
||||
(a, b) => Comparators.compareStringCaseInsensitive()(
|
||||
a.filename, b.filename),
|
||||
(a, b) => Comparators.compareStringCaseInsensitive()(a.filename, b.filename),
|
||||
reversed: reversed,
|
||||
)
|
||||
.compare,
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:re_editor/re_editor.dart';
|
||||
|
||||
const EdgeInsetsGeometry _kDefaultFindMargin = EdgeInsets.only(right: 10);
|
||||
const double _kDefaultFindPanelWidth = 360;
|
||||
const double _kDefaultFindPanelHeight = 36;
|
||||
const double _kDefaultReplacePanelHeight = _kDefaultFindPanelHeight * 2;
|
||||
const double _kDefaultFindIconSize = 16;
|
||||
const double _kDefaultFindIconWidth = 30;
|
||||
const double _kDefaultFindIconHeight = 30;
|
||||
const double _kDefaultFindInputFontSize = 13;
|
||||
const double _kDefaultFindResultFontSize = 12;
|
||||
const EdgeInsetsGeometry _kDefaultFindPadding = EdgeInsets.only(left: 5, right: 5, top: 2.5, bottom: 2.5);
|
||||
const EdgeInsetsGeometry _kDefaultFindInputContentPadding = EdgeInsets.only(left: 5, right: 5);
|
||||
|
||||
class CodeFindPanelView extends StatelessWidget implements PreferredSizeWidget {
|
||||
final CodeFindController controller;
|
||||
final EdgeInsetsGeometry margin;
|
||||
final bool readOnly;
|
||||
final Color? iconColor;
|
||||
final Color? iconSelectedColor;
|
||||
final double iconSize;
|
||||
final double inputFontSize;
|
||||
final double resultFontSize;
|
||||
final Color? inputTextColor;
|
||||
final Color? resultFontColor;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final InputDecoration decoration;
|
||||
|
||||
const CodeFindPanelView({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.margin = _kDefaultFindMargin,
|
||||
required this.readOnly,
|
||||
this.iconSelectedColor,
|
||||
this.iconColor,
|
||||
this.iconSize = _kDefaultFindIconSize,
|
||||
this.inputFontSize = _kDefaultFindInputFontSize,
|
||||
this.resultFontSize = _kDefaultFindResultFontSize,
|
||||
this.inputTextColor,
|
||||
this.resultFontColor,
|
||||
this.padding = _kDefaultFindPadding,
|
||||
this.decoration = const InputDecoration(
|
||||
filled: true,
|
||||
contentPadding: _kDefaultFindInputContentPadding,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(0)), gapPadding: 0),
|
||||
),
|
||||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize {
|
||||
final value = controller.value;
|
||||
final height = value == null
|
||||
? 0.0
|
||||
: (value.replaceMode ? _kDefaultReplacePanelHeight : _kDefaultFindPanelHeight) + margin.vertical;
|
||||
return Size(double.infinity, height);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (controller.value == null) return UIs.placeholder;
|
||||
|
||||
return Container(
|
||||
margin: margin,
|
||||
alignment: Alignment.topRight,
|
||||
height: preferredSize.height,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: SizedBox(
|
||||
width: _kDefaultFindPanelWidth,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildFindInputView(context),
|
||||
if (controller.value!.replaceMode) _buildReplaceInputView(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFindInputView(BuildContext context) {
|
||||
final CodeFindValue value = controller.value!;
|
||||
final String result;
|
||||
if (value.result == null) {
|
||||
result = libL10n.empty;
|
||||
} else {
|
||||
final index = value.result?.index;
|
||||
final count = value.result?.matches.length;
|
||||
result = '$index/$count';
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: _kDefaultFindPanelWidth / 1.75,
|
||||
height: _kDefaultFindPanelHeight,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
_buildTextField(
|
||||
context: context,
|
||||
controller: controller.findInputController,
|
||||
focusNode: controller.findInputFocusNode,
|
||||
iconsWidth: _kDefaultFindIconWidth * 1.5,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_buildCheckText(
|
||||
context: context,
|
||||
text: 'Aa',
|
||||
checked: value.option.caseSensitive,
|
||||
onPressed: controller.toggleCaseSensitive,
|
||||
),
|
||||
_buildCheckText(
|
||||
context: context,
|
||||
text: '.*',
|
||||
checked: value.option.regex,
|
||||
onPressed: controller.toggleRegex,
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
)),
|
||||
Text(result, style: TextStyle(color: resultFontColor, fontSize: resultFontSize)),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_buildIconButton(
|
||||
onPressed: value.result == null ? null : controller.previousMatch,
|
||||
icon: Icons.arrow_upward,
|
||||
tooltip: libL10n.previous,
|
||||
),
|
||||
_buildIconButton(
|
||||
onPressed: value.result == null ? null : controller.nextMatch,
|
||||
icon: Icons.arrow_downward,
|
||||
tooltip: libL10n.next,
|
||||
),
|
||||
_buildIconButton(
|
||||
onPressed: controller.close,
|
||||
icon: Icons.close,
|
||||
tooltip: libL10n.close,
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReplaceInputView(BuildContext context) {
|
||||
final CodeFindValue value = controller.value!;
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: _kDefaultFindPanelWidth / 1.75,
|
||||
height: _kDefaultFindPanelHeight,
|
||||
child: _buildTextField(
|
||||
context: context,
|
||||
controller: controller.replaceInputController,
|
||||
focusNode: controller.replaceInputFocusNode,
|
||||
),
|
||||
),
|
||||
_buildIconButton(
|
||||
onPressed: value.result == null ? null : controller.replaceMatch,
|
||||
icon: Icons.done,
|
||||
tooltip: libL10n.replace,
|
||||
),
|
||||
_buildIconButton(
|
||||
onPressed: value.result == null ? null : controller.replaceAllMatches,
|
||||
icon: Icons.done_all,
|
||||
tooltip: libL10n.replaceAll,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField({
|
||||
required BuildContext context,
|
||||
required TextEditingController controller,
|
||||
required FocusNode focusNode,
|
||||
double iconsWidth = 0,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: padding,
|
||||
child: TextField(
|
||||
maxLines: 1,
|
||||
focusNode: focusNode,
|
||||
style: TextStyle(color: inputTextColor, fontSize: inputFontSize),
|
||||
decoration: decoration.copyWith(
|
||||
contentPadding:
|
||||
(decoration.contentPadding ?? EdgeInsets.zero).add(EdgeInsets.only(right: iconsWidth))),
|
||||
controller: controller,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCheckText({
|
||||
required BuildContext context,
|
||||
required String text,
|
||||
required bool checked,
|
||||
required VoidCallback onPressed,
|
||||
}) {
|
||||
final Color selectedColor = iconSelectedColor ?? Theme.of(context).primaryColor;
|
||||
return GestureDetector(
|
||||
onTap: onPressed,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: SizedBox(
|
||||
width: _kDefaultFindIconWidth * 0.75,
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: checked ? selectedColor : iconColor,
|
||||
fontSize: inputFontSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton({required IconData icon, VoidCallback? onPressed, String? tooltip}) {
|
||||
return IconButton(
|
||||
onPressed: onPressed,
|
||||
icon: Icon(
|
||||
icon,
|
||||
size: iconSize,
|
||||
),
|
||||
constraints: const BoxConstraints(maxWidth: _kDefaultFindIconWidth, maxHeight: _kDefaultFindIconHeight),
|
||||
tooltip: tooltip,
|
||||
splashRadius: max(_kDefaultFindIconWidth, _kDefaultFindIconHeight) / 2,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TwoLineText extends StatelessWidget {
|
||||
const TwoLineText({super.key, required this.up, required this.down});
|
||||
final String up;
|
||||
final String down;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
up,
|
||||
style: UIs.text15,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
down,
|
||||
style: UIs.text11,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user