add close confirmation dialog
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
06541be459
commit
39a1545e94
@ -48,22 +48,25 @@ class _DesktopServerPageState extends State<DesktopServerPage>
|
|||||||
],
|
],
|
||||||
child: Consumer<ServerModel>(
|
child: Consumer<ServerModel>(
|
||||||
builder: (context, serverModel, child) => Container(
|
builder: (context, serverModel, child) => Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border:
|
border: Border.all(color: MyTheme.color(context).border!)),
|
||||||
Border.all(color: MyTheme.color(context).border!)),
|
child: Scaffold(
|
||||||
child: Scaffold(
|
backgroundColor: MyTheme.color(context).bg,
|
||||||
backgroundColor: MyTheme.color(context).bg,
|
body: Overlay(initialEntries: [
|
||||||
body: Center(
|
OverlayEntry(builder: (context) {
|
||||||
child: Column(
|
gFFI.dialogManager.setOverlayState(Overlay.of(context));
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
return Center(
|
||||||
children: [
|
child: Column(
|
||||||
Expanded(child: ConnectionManager()),
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
SizedBox.fromSize(size: Size(0, 15.0)),
|
children: [
|
||||||
],
|
Expanded(child: ConnectionManager()),
|
||||||
),
|
SizedBox.fromSize(size: Size(0, 15.0)),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
)));
|
);
|
||||||
|
})
|
||||||
|
]),
|
||||||
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -109,7 +112,8 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
theme: isDarkTheme() ? TarBarTheme.dark() : TarBarTheme.light(),
|
theme: isDarkTheme() ? TarBarTheme.dark() : TarBarTheme.light(),
|
||||||
showTitle: false,
|
showTitle: false,
|
||||||
showMaximize: false,
|
showMaximize: false,
|
||||||
showMinimize: false,
|
showMinimize: true,
|
||||||
|
showClose: true,
|
||||||
controller: serverModel.tabController,
|
controller: serverModel.tabController,
|
||||||
tabType: DesktopTabType.cm,
|
tabType: DesktopTabType.cm,
|
||||||
pageViewBuilder: (pageView) => Row(children: [
|
pageViewBuilder: (pageView) => Row(children: [
|
||||||
|
@ -314,6 +314,8 @@ class DesktopTab extends StatelessWidget {
|
|||||||
Offstage(offstage: tail == null, child: tail),
|
Offstage(offstage: tail == null, child: tail),
|
||||||
WindowActionPanel(
|
WindowActionPanel(
|
||||||
mainTab: isMainWindow,
|
mainTab: isMainWindow,
|
||||||
|
tabType: tabType,
|
||||||
|
state: state,
|
||||||
theme: theme,
|
theme: theme,
|
||||||
showMinimize: showMinimize,
|
showMinimize: showMinimize,
|
||||||
showMaximize: showMaximize,
|
showMaximize: showMaximize,
|
||||||
@ -327,6 +329,8 @@ class DesktopTab extends StatelessWidget {
|
|||||||
|
|
||||||
class WindowActionPanel extends StatelessWidget {
|
class WindowActionPanel extends StatelessWidget {
|
||||||
final bool mainTab;
|
final bool mainTab;
|
||||||
|
final DesktopTabType tabType;
|
||||||
|
final Rx<DesktopTabState> state;
|
||||||
final TarBarTheme theme;
|
final TarBarTheme theme;
|
||||||
|
|
||||||
final bool showMinimize;
|
final bool showMinimize;
|
||||||
@ -337,6 +341,8 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
const WindowActionPanel(
|
const WindowActionPanel(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.mainTab,
|
required this.mainTab,
|
||||||
|
required this.tabType,
|
||||||
|
required this.state,
|
||||||
required this.theme,
|
required this.theme,
|
||||||
this.showMinimize = true,
|
this.showMinimize = true,
|
||||||
this.showMaximize = true,
|
this.showMaximize = true,
|
||||||
@ -411,22 +417,53 @@ class WindowActionPanel extends StatelessWidget {
|
|||||||
message: 'Close',
|
message: 'Close',
|
||||||
icon: IconFont.close,
|
icon: IconFont.close,
|
||||||
theme: theme,
|
theme: theme,
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
if (mainTab) {
|
action() {
|
||||||
windowManager.close();
|
if (mainTab) {
|
||||||
} else {
|
windowManager.close();
|
||||||
// only hide for multi window, not close
|
} else {
|
||||||
Future.delayed(Duration.zero, () {
|
// only hide for multi window, not close
|
||||||
WindowController.fromWindowId(windowId!).hide();
|
Future.delayed(Duration.zero, () {
|
||||||
});
|
WindowController.fromWindowId(windowId!).hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
onClose?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tabType != DesktopTabType.main &&
|
||||||
|
state.value.tabs.length > 1) {
|
||||||
|
closeConfirmDialog(action);
|
||||||
|
} else {
|
||||||
|
action();
|
||||||
}
|
}
|
||||||
onClose?.call();
|
|
||||||
},
|
},
|
||||||
is_close: true,
|
is_close: true,
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeConfirmDialog(Function() callback) async {
|
||||||
|
final res = await gFFI.dialogManager
|
||||||
|
.show<bool>((setState, close) => CustomAlertDialog(
|
||||||
|
title: Row(children: [
|
||||||
|
Icon(Icons.warning_amber_sharp,
|
||||||
|
color: Colors.redAccent, size: 28),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Text(translate("Warning")),
|
||||||
|
]),
|
||||||
|
content: Text(translate("Disconnect all devices?")),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => close(), child: Text(translate("Cancel"))),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => close(true), child: Text(translate("OK"))),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
if (res == true) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user