| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter/widgets.dart';
- class AppPlatformMenu extends StatefulWidget {
- const AppPlatformMenu({super.key, required this.child});
- final Widget child;
- @override
- State<AppPlatformMenu> createState() => _AppPlatformMenuState();
- }
- class _AppPlatformMenuState extends State<AppPlatformMenu> {
- @override
- Widget build(BuildContext context) {
- if (defaultTargetPlatform != TargetPlatform.macOS) {
- return widget.child;
- }
- return PlatformMenuBar(
- menus: <MenuItem>[
- PlatformMenu(
- label: 'TerminalStudio',
- menus: [
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.about,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.about,
- ),
- PlatformMenuItemGroup(
- members: [
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.servicesSubmenu,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.servicesSubmenu,
- ),
- ],
- ),
- PlatformMenuItemGroup(
- members: [
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.hide,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.hide,
- ),
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.hideOtherApplications,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.hideOtherApplications,
- ),
- ],
- ),
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.quit,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.quit,
- ),
- ],
- ),
- PlatformMenu(
- label: 'Edit',
- menus: [
- PlatformMenuItemGroup(
- members: [
- PlatformMenuItem(
- label: 'Copy',
- shortcut: const SingleActivator(
- LogicalKeyboardKey.keyC,
- meta: true,
- ),
- onSelected: () {
- final primaryContext = primaryFocus?.context;
- if (primaryContext == null) {
- return;
- }
- Actions.invoke(
- primaryContext,
- CopySelectionTextIntent.copy,
- );
- },
- ),
- PlatformMenuItem(
- label: 'Paste',
- shortcut: const SingleActivator(
- LogicalKeyboardKey.keyV,
- meta: true,
- ),
- onSelected: () {
- final primaryContext = primaryFocus?.context;
- if (primaryContext == null) {
- return;
- }
- Actions.invoke(
- primaryContext,
- const PasteTextIntent(SelectionChangedCause.keyboard),
- );
- },
- ),
- PlatformMenuItem(
- label: 'Select All',
- shortcut: const SingleActivator(
- LogicalKeyboardKey.keyA,
- meta: true,
- ),
- onSelected: () {
- final primaryContext = primaryFocus?.context;
- if (primaryContext == null) {
- return;
- }
- print(primaryContext);
- try {
- final action = Actions.maybeFind<Intent>(
- primaryContext,
- intent: const SelectAllTextIntent(
- SelectionChangedCause.keyboard,
- ),
- );
- print('action: $action');
- } catch (e) {
- print(e);
- }
- Actions.invoke<Intent>(
- primaryContext,
- const SelectAllTextIntent(SelectionChangedCause.keyboard),
- );
- },
- ),
- ],
- ),
- if (PlatformProvidedMenuItem.hasMenu(
- PlatformProvidedMenuItemType.quit,
- ))
- const PlatformProvidedMenuItem(
- type: PlatformProvidedMenuItemType.quit,
- ),
- ],
- ),
- ],
- body: widget.child,
- );
- }
- }
|