opt.: confirm of suspend & etc.

This commit is contained in:
lollipopkit
2023-10-05 17:08:21 +08:00
parent 153bfc191d
commit ef144e27cb
20 changed files with 182 additions and 235 deletions

View File

@@ -153,7 +153,9 @@ class BackupPage extends StatelessWidget {
await context.showRoundDialog(
title: Text(l10n.restore),
child: Text(l10n.restoreSureWithDate(backup.date)),
child: Text(l10n.askContinue(
'${l10n.restore} ${l10n.backup}(${backup.date})',
)),
actions: [
TextButton(
onPressed: () => context.pop(),

View File

@@ -249,7 +249,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
void _showImageRmDialog(DockerImage e) {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(e.repo)),
child: Text(l10n.askContinue('${l10n.delete} Image(${e.repo})')),
actions: [
TextButton(
onPressed: () => context.pop(),
@@ -365,7 +365,9 @@ class _DockerManagePageState extends State<DockerManagePage> {
case DockerMenuType.rm:
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(dItem.name)),
child: Text(l10n.askContinue(
'${l10n.delete} Container(${dItem.name})',
)),
actions: [
TextButton(
onPressed: () async {

View File

@@ -91,7 +91,9 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage> {
onPressed: () {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(widget.pki!.id)),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.privateKey}(${widget.pki!.id})',
)),
actions: [
TextButton(
onPressed: () {

View File

@@ -160,7 +160,9 @@ class _ProcessPageState extends State<ProcessPage> {
onLongPress: () {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureStop(proc.pid)),
child: Text(l10n.askContinue(
'${l10n.stop} ${l10n.process}(${proc.pid})',
)),
actions: [
TextButton(
onPressed: () async {

View File

@@ -111,7 +111,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
onPressed: () {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureToDeleteServer(widget.spi!.name)),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.server}(${widget.spi!.name})',
)),
actions: [
TextButton(
onPressed: () {
@@ -315,14 +317,14 @@ class _ServerEditPageState extends State<ServerEditPage> {
}
void _onSave() async {
if (_ipController.text == '') {
if (_ipController.text.isEmpty) {
context.showSnackBar(l10n.plzEnterHost);
return;
}
if (_keyIdx.value == null && _passwordController.text == '') {
if (_keyIdx.value == null && _passwordController.text.isEmpty) {
final cancel = await context.showRoundDialog<bool>(
title: Text(l10n.attention),
child: Text(l10n.sureNoPwd),
child: Text(l10n.askContinue(l10n.useNoPwd)),
actions: [
TextButton(
onPressed: () => context.pop(false),

View File

@@ -3,6 +3,7 @@ import 'package:circle_chart/circle_chart.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/media_queryx.dart';
@@ -244,35 +245,38 @@ class _ServerPageState extends State<ServerPage>
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () async {
if (Stores.first.showSuspendTip.fetch()) {
await context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.suspendTip),
onPressed: () => _askFor(
func: () async {
if (Stores.first.showSuspendTip.fetch()) {
await context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.suspendTip),
);
Stores.first.showSuspendTip.put(false);
}
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
);
Stores.first.showSuspendTip.put(false);
}
srv.client?.execWithPwd(
ShellFunc.suspend.exec,
context: context,
);
},
},
msg: 'Suspend ${srv.spi.name}',
),
icon: const Icon(Icons.stop),
tooltip: 'Suspend',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
onPressed: () => _askFor(func: () => srv.client?.execWithPwd(
ShellFunc.shutdown.exec,
context: context,
),
), msg: 'Shutdown ${srv.spi.name}',),
icon: const Icon(Icons.power_off),
tooltip: 'Shutdown',
),
IconButton(
onPressed: () => srv.client?.execWithPwd(
onPressed: () => _askFor(func: () => srv.client?.execWithPwd(
ShellFunc.reboot.exec,
context: context,
),
), msg: 'Reboot ${srv.spi.name}',),
icon: const Icon(Icons.restart_alt),
tooltip: 'Reboot',
),
@@ -531,4 +535,20 @@ class _ServerPageState extends State<ServerPage>
}
return 107;
}
void _askFor({required void Function() func, required String msg}) {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.askContinue(msg)),
actions: [
TextButton(
onPressed: () {
context.pop();
func();
},
child: Text(l10n.ok),
),
],
);
}
}

View File

@@ -105,7 +105,9 @@ class _SettingPageState extends State<SettingPage> {
child: InkWell(
onTap: () => context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(l10n.all)),
child: Text(l10n.askContinue(
'${l10n.delete}: **${l10n.all}** ${l10n.setting}',
)),
actions: [
TextButton(
onPressed: () {
@@ -113,8 +115,10 @@ class _SettingPageState extends State<SettingPage> {
context.pop();
context.showSnackBar(l10n.success);
},
child: Text(l10n.ok,
style: const TextStyle(color: Colors.red)),
child: Text(
l10n.ok,
style: const TextStyle(color: Colors.red),
),
),
],
),
@@ -880,7 +884,9 @@ class _SettingPageState extends State<SettingPage> {
(e) => TextButton(
onPressed: () => context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(e)),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.server}($e)',
)),
actions: [
TextButton(
onPressed: () => Pros.server.delServer(e),

View File

@@ -1,6 +1,7 @@
import 'package:after_layout/after_layout.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/context/snackbar.dart';
import 'package:toolbox/data/res/provider.dart';
@@ -56,8 +57,22 @@ class _SnippetEditPageState extends State<SnippetEditPage>
return [
IconButton(
onPressed: () {
Pros.snippet.del(widget.snippet!);
context.pop();
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.snippet}(${widget.snippet!.name})',
)),
actions: [
TextButton(
onPressed: () {
Pros.snippet.del(widget.snippet!);
context.pop();
context.pop();
},
child: Text(l10n.ok, style: UIs.textRed),
),
],
);
},
tooltip: l10n.delete,
icon: const Icon(Icons.delete),

View File

@@ -410,8 +410,9 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
context.pop();
final isDir = file.attr.isDirectory;
final useRmrf = Stores.setting.sftpRmrfDir.fetch();
final dirText = (isDir && !useRmrf) ? '\n${l10n.sureDirEmpty}' : '';
final text = '${l10n.sureDelete(file.filename)}$dirText';
final dirText = (isDir && !useRmrf) ? '\n${l10n.dirEmpty}' : '';
final text = l10n.askContinue(
'${l10n.delete} ${l10n.files}(${file.filename})\n$dirText');
final child = Text(text);
context.showRoundDialog(
child: child,
@@ -475,7 +476,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
),
TextButton(
onPressed: () async {
if (textController.text == '') {
if (textController.text.isEmpty) {
context.showRoundDialog(
child: Text(l10n.fieldMustNotEmpty),
actions: [
@@ -512,7 +513,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
actions: [
TextButton(
onPressed: () async {
if (textController.text == '') {
if (textController.text.isEmpty) {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.fieldMustNotEmpty),
@@ -553,7 +554,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
TextButton(onPressed: () => context.pop(), child: Text(l10n.cancel)),
TextButton(
onPressed: () async {
if (textController.text == '') {
if (textController.text.isEmpty) {
context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.fieldMustNotEmpty),
@@ -566,7 +567,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
);
return;
}
await _status.client!.rename(file.filename, textController.text);
await _status.client?.rename(file.filename, textController.text);
context.pop();
_listDir();
},
@@ -610,7 +611,8 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
/// Only return true if the path is changed
Future<bool> _listDir() async {
context.showLoadingDialog();
// Allow dismiss, because may this op will take a long time
context.showLoadingDialog(barrierDismiss: true);
if (_status.client == null) {
final sftpc = await _client?.sftp();
_status.client = sftpc;

View File

@@ -137,7 +137,9 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
return IconButton(
onPressed: () => context.showRoundDialog(
title: Text(l10n.attention),
child: Text(l10n.sureDelete(name)),
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.mission}($name)',
)),
actions: [
TextButton(
onPressed: () {