mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: hotkey to open settings dialog (#4620)
* feat: hotkey to open settings dialog * chore: change to cmd/ctrl+,
This commit is contained in:
parent
b781c9aa0f
commit
db5372c18e
@ -7,6 +7,7 @@ import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
|
||||
import 'package:appflowy/workspace/application/sidebar/rename_view/rename_view_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar_user.dart';
|
||||
import 'package:hotkey_manager/hotkey_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@ -107,9 +108,15 @@ class HomeHotKeys extends StatelessWidget {
|
||||
getIt<RenameViewBloc>().add(const RenameViewEvent.open()),
|
||||
).register();
|
||||
|
||||
_asyncRegistration(context);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
Future<void> _asyncRegistration(BuildContext context) async {
|
||||
(await openSettingsHotKey(context))?.register();
|
||||
}
|
||||
|
||||
void _selectTab(BuildContext context, int change) {
|
||||
final bloc = context.read<TabsBloc>();
|
||||
bloc.add(TabsEvent.selectTab(bloc.state.currentIndex + change));
|
||||
|
@ -1,8 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
||||
import 'package:appflowy/startup/startup.dart';
|
||||
import 'package:appflowy/user/application/auth/auth_service.dart';
|
||||
import 'package:appflowy/workspace/application/menu/menu_user_bloc.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
|
||||
import 'package:appflowy/workspace/presentation/notifications/widgets/notification_button.dart';
|
||||
import 'package:appflowy/workspace/presentation/settings/settings_dialog.dart';
|
||||
import 'package:appflowy/workspace/presentation/widgets/user_avatar.dart';
|
||||
@ -11,11 +15,42 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
|
||||
show UserProfilePB;
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hotkey_manager/hotkey_manager.dart';
|
||||
|
||||
final GlobalKey _settingsDialogKey = GlobalKey();
|
||||
|
||||
Future<HotKeyItem?> openSettingsHotKey(BuildContext context) async {
|
||||
final userProfileOrFailure = await getIt<AuthService>().getUser();
|
||||
|
||||
return userProfileOrFailure.fold(
|
||||
(e) {
|
||||
Log.error('Failed to get user $e');
|
||||
return null;
|
||||
},
|
||||
(userProfile) => HotKeyItem(
|
||||
hotKey: HotKey(
|
||||
KeyCode.comma,
|
||||
scope: HotKeyScope.inapp,
|
||||
modifiers: [
|
||||
PlatformExtension.isMacOS ? KeyModifier.meta : KeyModifier.control,
|
||||
],
|
||||
),
|
||||
keyDownHandler: (_) {
|
||||
if (_settingsDialogKey.currentContext == null) {
|
||||
_showSettingsDialog(context, userProfile);
|
||||
} else {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.popUntil((route) => route.isFirst);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class SidebarUser extends StatelessWidget {
|
||||
const SidebarUser({
|
||||
@ -83,36 +118,7 @@ class UserSettingButton extends StatelessWidget {
|
||||
return FlowyTooltip(
|
||||
message: LocaleKeys.settings_menu_open.tr(),
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return BlocProvider<DocumentAppearanceCubit>.value(
|
||||
value: BlocProvider.of<DocumentAppearanceCubit>(dialogContext),
|
||||
child: SettingsDialog(
|
||||
userProfile,
|
||||
didLogout: () async {
|
||||
// Pop the dialog using the dialog context
|
||||
Navigator.of(dialogContext).pop();
|
||||
await runAppFlowy();
|
||||
},
|
||||
dismissDialog: () {
|
||||
if (Navigator.of(dialogContext).canPop()) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
} else {
|
||||
Log.warn("Can't pop dialog context");
|
||||
}
|
||||
},
|
||||
restartApp: () async {
|
||||
// Pop the dialog using the dialog context
|
||||
Navigator.of(dialogContext).pop();
|
||||
await runAppFlowy();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
onPressed: () => _showSettingsDialog(context, userProfile),
|
||||
icon: SizedBox.square(
|
||||
dimension: 20,
|
||||
child: FlowySvg(
|
||||
@ -124,3 +130,38 @@ class UserSettingButton extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showSettingsDialog(
|
||||
BuildContext context,
|
||||
UserProfilePB userProfile,
|
||||
) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return BlocProvider<DocumentAppearanceCubit>.value(
|
||||
key: _settingsDialogKey,
|
||||
value: BlocProvider.of<DocumentAppearanceCubit>(dialogContext),
|
||||
child: SettingsDialog(
|
||||
userProfile,
|
||||
didLogout: () async {
|
||||
// Pop the dialog using the dialog context
|
||||
Navigator.of(dialogContext).pop();
|
||||
await runAppFlowy();
|
||||
},
|
||||
dismissDialog: () {
|
||||
if (Navigator.of(dialogContext).canPop()) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
} else {
|
||||
Log.warn("Can't pop dialog context");
|
||||
}
|
||||
},
|
||||
restartApp: () async {
|
||||
// Pop the dialog using the dialog context
|
||||
Navigator.of(dialogContext).pop();
|
||||
await runAppFlowy();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user