Bläddra i källkod

Update example

xuty 3 år sedan
förälder
incheckning
6b64af6af8
2 ändrade filer med 146 tillägg och 1 borttagningar
  1. 2 1
      example/lib/main.dart
  2. 144 0
      example/lib/src/platform_menu.dart

+ 2 - 1
example/lib/main.dart

@@ -1,6 +1,7 @@
 import 'dart:convert';
 import 'dart:io';
 
+import 'package:example/src/platform_menu.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
@@ -40,7 +41,7 @@ class MyApp extends StatelessWidget {
     return MaterialApp(
       title: 'xterm.dart demo',
       debugShowCheckedModeBanner: false,
-      home: Home(),
+      home: AppPlatformMenu(child: Home()),
       // shortcuts: ,
     );
   }

+ 144 - 0
example/lib/src/platform_menu.dart

@@ -0,0 +1,144 @@
+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) {
+    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,
+    );
+  }
+}