Skip to content

Commit

Permalink
feat: integrate cmd palette into menubar
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdSquared committed Jan 17, 2024
1 parent bbd2ca0 commit 79338c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ class PeregrineHomeView extends ConsumerWidget {
}
return Scaffold(
backgroundColor: const Color(0xffb69d7c),
body: DesktopFrame(
entryBoxFocusNode: entryBoxFocusNode,
searchBoxFocusNode: searchBoxFocusNode,
child: PretCmdPaletteScope(
searchItems: ref.read(tagsProvider).keys.toList(),
body: PretCmdPaletteScope(
searchItems: ref.read(tagsProvider).keys.toList(),
child: DesktopFrame(
entryBoxFocusNode: entryBoxFocusNode,
searchBoxFocusNode: searchBoxFocusNode,
child: view,
),
),
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/desktop_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:pret_a_porter/pret_a_porter.dart';

import '../main.dart';
import '../model/tag_data.dart';
import 'pret_command_palette.dart';

class DesktopFrame extends ConsumerWidget {
final Widget child;
Expand Down Expand Up @@ -37,13 +38,14 @@ class DesktopFrame extends ConsumerWidget {
),
onSelected: entryBoxFocusNode.requestFocus,
),
const PlatformMenuItem(
PlatformMenuItem(
label: 'Quick Open Tag',
shortcut: SingleActivator(
shortcut: const SingleActivator(
LogicalKeyboardKey.keyP,
meta: true,
),
//onSelected: () => PretCmdPalette.of(context).togglePalette(),
onSelected: () =>
PretPaletteToggle.of(context).togglePalette(),
),
],
),
Expand Down
6 changes: 6 additions & 0 deletions lib/widgets/pret_command_palette.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import 'package:pret_a_porter/pret_a_porter.dart';

import '../main.dart';

/// this only works above a PlatformMenuBar widget if
/// you comment out the `return false` in
/// [DefaultPlatformMenuDelegate.debugLockDelegate]. No idea why.
class PretCmdPaletteScope extends ConsumerStatefulWidget {
final Widget child;
final List<String> searchItems;
Expand All @@ -26,10 +29,12 @@ class PretCmdPaletteScopeState extends ConsumerState<PretCmdPaletteScope> {
int selectedIndex = 0;
final TextEditingController _controller = TextEditingController();
late List<String> filteredItems = widget.searchItems;
final FocusNode paletteFocusNode = FocusNode();

void togglePalette() => setState(() {
_isPaletteShown = !_isPaletteShown;
selectedIndex = 0;
_isPaletteShown ? paletteFocusNode.requestFocus() : null;
});

void handleSelect() {
Expand Down Expand Up @@ -105,6 +110,7 @@ class PretCmdPaletteScopeState extends ConsumerState<PretCmdPaletteScope> {
controller: _controller,
autofocus: true,
onChanged: updateFilteredItems,
focusNode: paletteFocusNode,
),
Expanded(
child: ListView.builder(
Expand Down

0 comments on commit 79338c5

Please sign in to comment.