update cursor position when menu is dismissed
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
1ad55d9914
commit
ca97826b80
@ -109,13 +109,17 @@ class MenuConfig {
|
||||
this.boxWidth});
|
||||
}
|
||||
|
||||
typedef DismissCallback = Function();
|
||||
|
||||
abstract class MenuEntryBase<T> {
|
||||
bool dismissOnClicked;
|
||||
DismissCallback? dismissCallback;
|
||||
RxBool? enabled;
|
||||
|
||||
MenuEntryBase({
|
||||
this.dismissOnClicked = false,
|
||||
this.enabled,
|
||||
this.dismissCallback,
|
||||
});
|
||||
List<mod_menu.PopupMenuEntry<T>> build(BuildContext context, MenuConfig conf);
|
||||
|
||||
@ -146,12 +150,14 @@ class MenuEntryRadioOption {
|
||||
String value;
|
||||
bool dismissOnClicked;
|
||||
RxBool? enabled;
|
||||
DismissCallback? dismissCallback;
|
||||
|
||||
MenuEntryRadioOption({
|
||||
required this.text,
|
||||
required this.value,
|
||||
this.dismissOnClicked = false,
|
||||
this.enabled,
|
||||
this.dismissCallback,
|
||||
});
|
||||
}
|
||||
|
||||
@ -177,8 +183,13 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
required this.optionSetter,
|
||||
this.padding,
|
||||
dismissOnClicked = false,
|
||||
dismissCallback,
|
||||
RxBool? enabled,
|
||||
}) : super(dismissOnClicked: dismissOnClicked, enabled: enabled) {
|
||||
}) : super(
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
enabled: enabled,
|
||||
dismissCallback: dismissCallback,
|
||||
) {
|
||||
() async {
|
||||
_curOption.value = await curOptionGetter();
|
||||
}();
|
||||
@ -249,6 +260,9 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
|
||||
onPressed() {
|
||||
if (opt.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (opt.dismissCallback != null) {
|
||||
opt.dismissCallback!();
|
||||
}
|
||||
}
|
||||
setOption(opt.value);
|
||||
}
|
||||
@ -360,6 +374,9 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
|
||||
onPressed: () {
|
||||
if (opt.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (opt.dismissCallback != null) {
|
||||
opt.dismissCallback!();
|
||||
}
|
||||
}
|
||||
setOption(opt.value);
|
||||
},
|
||||
@ -421,7 +438,12 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
this.textStyle,
|
||||
this.padding,
|
||||
RxBool? enabled,
|
||||
}) : super(dismissOnClicked: dismissOnClicked, enabled: enabled);
|
||||
dismissCallback,
|
||||
}) : super(
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
enabled: enabled,
|
||||
dismissCallback: dismissCallback,
|
||||
);
|
||||
|
||||
RxBool get curOption;
|
||||
Future<void> setOption(bool? option);
|
||||
@ -463,6 +485,9 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
if (super.dismissOnClicked &&
|
||||
Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (super.dismissCallback != null) {
|
||||
super.dismissCallback!();
|
||||
}
|
||||
}
|
||||
setOption(v);
|
||||
},
|
||||
@ -474,6 +499,9 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
if (super.dismissOnClicked &&
|
||||
Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (super.dismissCallback != null) {
|
||||
super.dismissCallback!();
|
||||
}
|
||||
}
|
||||
setOption(v);
|
||||
},
|
||||
@ -485,6 +513,9 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
|
||||
onPressed: () {
|
||||
if (super.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (super.dismissCallback != null) {
|
||||
super.dismissCallback!();
|
||||
}
|
||||
}
|
||||
setOption(!curOption.value);
|
||||
},
|
||||
@ -508,6 +539,7 @@ class MenuEntrySwitch<T> extends MenuEntrySwitchBase<T> {
|
||||
EdgeInsets? padding,
|
||||
dismissOnClicked = false,
|
||||
RxBool? enabled,
|
||||
dismissCallback,
|
||||
}) : super(
|
||||
switchType: switchType,
|
||||
text: text,
|
||||
@ -515,6 +547,7 @@ class MenuEntrySwitch<T> extends MenuEntrySwitchBase<T> {
|
||||
padding: padding,
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
enabled: enabled,
|
||||
dismissCallback: dismissCallback,
|
||||
) {
|
||||
() async {
|
||||
_curOption.value = await getter();
|
||||
@ -551,12 +584,15 @@ class MenuEntrySwitch2<T> extends MenuEntrySwitchBase<T> {
|
||||
EdgeInsets? padding,
|
||||
dismissOnClicked = false,
|
||||
RxBool? enabled,
|
||||
dismissCallback,
|
||||
}) : super(
|
||||
switchType: switchType,
|
||||
text: text,
|
||||
textStyle: textStyle,
|
||||
padding: padding,
|
||||
dismissOnClicked: dismissOnClicked);
|
||||
switchType: switchType,
|
||||
text: text,
|
||||
textStyle: textStyle,
|
||||
padding: padding,
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
dismissCallback: dismissCallback,
|
||||
);
|
||||
|
||||
@override
|
||||
RxBool get curOption => getter();
|
||||
@ -627,9 +663,11 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
|
||||
this.padding,
|
||||
dismissOnClicked = false,
|
||||
RxBool? enabled,
|
||||
dismissCallback,
|
||||
}) : super(
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
enabled: enabled,
|
||||
dismissCallback: dismissCallback,
|
||||
);
|
||||
|
||||
Widget _buildChild(BuildContext context, MenuConfig conf) {
|
||||
@ -641,6 +679,9 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
|
||||
? () {
|
||||
if (super.dismissOnClicked && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
if (super.dismissCallback != null) {
|
||||
super.dismissCallback!();
|
||||
}
|
||||
}
|
||||
proc();
|
||||
}
|
||||
|
@ -231,6 +231,8 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
);
|
||||
}
|
||||
|
||||
_menuDismissCallback() => widget.ffi.inputModel.refreshMousePos();
|
||||
|
||||
Widget _buildMenubar(BuildContext context) {
|
||||
final List<Widget> menubarItems = [];
|
||||
if (!isWebDesktop) {
|
||||
@ -374,6 +376,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
onPressed: () {
|
||||
if (Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
_menuDismissCallback();
|
||||
}
|
||||
RxInt display = CurrentDisplayState.find(widget.id);
|
||||
if (display.value != i) {
|
||||
@ -551,6 +554,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
onPressed: () {
|
||||
if (Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
_menuDismissCallback();
|
||||
}
|
||||
showSetOSPassword(
|
||||
widget.id, false, widget.ffi.dialogManager);
|
||||
@ -563,6 +567,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
@ -574,6 +579,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Text(
|
||||
@ -585,6 +591,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
connect(context, widget.id, isTcpTunneling: true);
|
||||
},
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
]);
|
||||
// {handler.get_audit_server() && <li #note>{translate('Note')}</li>}
|
||||
@ -602,6 +609,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -618,6 +626,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -635,6 +644,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
|
||||
@ -649,6 +659,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
|
||||
if (pi.platform == kPeerPlatformWindows) {
|
||||
@ -667,6 +678,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
if (pi.platform != kPeerPlatformAndroid &&
|
||||
@ -681,6 +693,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
showConfirmSwitchSidesDialog(widget.id, widget.ffi.dialogManager),
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -696,6 +709,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
|
||||
@ -717,6 +731,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
// },
|
||||
// padding: padding,
|
||||
// dismissOnClicked: true,
|
||||
// dismissCallback: _menuDismissCallback,
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
@ -762,11 +777,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: translate('Scale original'),
|
||||
value: kRemoteViewStyleOriginal,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Scale adaptive'),
|
||||
value: kRemoteViewStyleAdaptive,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
],
|
||||
curOptionGetter: () async {
|
||||
@ -782,6 +799,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryDivider<String>(),
|
||||
MenuEntryRadios<String>(
|
||||
@ -791,21 +809,26 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: translate('Good image quality'),
|
||||
value: kRemoteImageQualityBest,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Balanced'),
|
||||
value: kRemoteImageQualityBalanced,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Optimize reaction time'),
|
||||
value: kRemoteImageQualityLow,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Custom'),
|
||||
value: kRemoteImageQualityCustom,
|
||||
dismissOnClicked: true),
|
||||
text: translate('Custom'),
|
||||
value: kRemoteImageQualityCustom,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
],
|
||||
curOptionGetter: () async =>
|
||||
// null means peer id is not found, which there's no need to care about
|
||||
@ -970,12 +993,14 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: translate('ScrollAuto'),
|
||||
value: kRemoteScrollStyleAuto,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
enabled: widget.ffi.canvasModel.imageOverflow,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Scrollbar'),
|
||||
value: kRemoteScrollStyleBar,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
enabled: widget.ffi.canvasModel.imageOverflow,
|
||||
),
|
||||
],
|
||||
@ -988,6 +1013,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
displayMenu.insert(3, MenuEntryDivider<String>());
|
||||
|
||||
@ -1058,6 +1084,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1084,11 +1111,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: translate('Auto'),
|
||||
value: 'auto',
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
MenuEntryRadioOption(
|
||||
text: 'VP9',
|
||||
value: 'vp9',
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
];
|
||||
if (codecs[0]) {
|
||||
@ -1096,6 +1125,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: 'H264',
|
||||
value: 'h264',
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
if (codecs[1]) {
|
||||
@ -1103,6 +1133,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: 'H265',
|
||||
value: 'h265',
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
return list;
|
||||
@ -1119,6 +1150,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -1141,6 +1173,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
);
|
||||
}());
|
||||
}
|
||||
@ -1163,6 +1196,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
);
|
||||
}());
|
||||
}
|
||||
@ -1182,6 +1216,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
|
||||
final perms = widget.ffi.ffiModel.permissions;
|
||||
@ -1219,6 +1254,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -1290,6 +1326,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
onPressed: () {
|
||||
if (Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
_menuDismissCallback();
|
||||
}
|
||||
showKBLayoutTypeChooser(
|
||||
localPlatform, widget.ffi.dialogManager);
|
||||
@ -1302,6 +1339,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
proc: () {},
|
||||
padding: EdgeInsets.zero,
|
||||
dismissOnClicked: false,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -1321,6 +1359,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: dismissOnClicked,
|
||||
dismissCallback: _menuDismissCallback,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user