Skip to content

Commit

Permalink
Implement contextual menu on secondary click (#9)
Browse files Browse the repository at this point in the history
* Switch from actions buttons to action menu

* Rename action and submit on enter

* Dart fixes

* Refactor rename and delete dialogs

* Convert mixin to extension

* Add auto focus to buttons in dialogs

* Change primary dialog button to FIlledButton

* Improve keyboard accessibility for context menu

* Improve keyboard navigation in list

* Update

* Fixups

* Make new file dialog button filled

* Remove unused code

* Update dependencies

* Fix compile issue for now. Awaiting PR

* Use flutter master

* Update libraries and pigeon
  • Loading branch information
Fernthedev authored Dec 12, 2023
1 parent 69abff8 commit d59f067
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 365 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
channel: 'master'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path
Expand Down
14 changes: 12 additions & 2 deletions lib/pages/adb_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ class _ADBDownloadDialogState extends State<ADBDownloadDialog> {
return AlertDialog(
title: const Text("ADB not found"),
content: const Text("Do you want to download ADB?"),
actions: [TextButton(onPressed: _download, child: const Text("Ok"))],
actions: [
FilledButton(
autofocus: true,
onPressed: _download,
child: const Text("Ok"),
)
],
);
}

Expand All @@ -81,7 +87,11 @@ class _ADBDownloadDialogState extends State<ADBDownloadDialog> {
title: const Text("Suffered error downloading"),
content: Text(messages),
actions: [
TextButton(onPressed: _continue, child: const Text("Continue anyways"))
FilledButton(
autofocus: true,
onPressed: _continue,
child: const Text("Continue anyways"),
)
],
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
key: ValueKey(file),
onWatch: () => _watchFile(file),
isCard: true,
fileWrapper: file,
fileData: file,
));
});
}
Expand Down Expand Up @@ -692,7 +692,7 @@ class _NewFileDialogState extends State<NewFileDialog> {
},
);

var confirmButton = TextButton(
var confirmButton = FilledButton(
child: const Text('Ok'),
onPressed: () {
var path = Adb.adbPathContext
Expand Down
8 changes: 6 additions & 2 deletions lib/pages/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ class _LogPageState extends State<LogPage> {
title: const Text("Error while streaming logcat"),
content: Text(error),
actions: [
TextButton(onPressed: _queueSave, child: const Text("Save")),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text("Back"))
child: const Text("Back")),
FilledButton(
autofocus: true,
onPressed: _queueSave,
child: const Text("Save"),
)
],
));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pigeon.g.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v14.0.0), do not edit directly.
// Autogenerated from Pigeon (v15.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers

Expand Down
5 changes: 2 additions & 3 deletions lib/utils/adb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:async/async.dart';
import 'package:desktop_adb_file_browser/utils/platform.dart';
import 'package:desktop_adb_file_browser/widgets/browser/file_data.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:path/path.dart';
Expand Down Expand Up @@ -423,7 +422,7 @@ class Device {
final String? deviceManufacturer;
final String modelName;

Device(
const Device(
{required this.serialName,
this.deviceManufacturer,
required this.modelName});
Expand All @@ -437,7 +436,7 @@ class FileListingData {
final DateTime date;
final String path;

FileListingData(
const FileListingData(
{required this.permission,
required this.user,
required this.size,
Expand Down
77 changes: 77 additions & 0 deletions lib/widgets/adaptive/menu_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AdaptiveContextualMenu extends StatelessWidget {
const AdaptiveContextualMenu({
super.key,
required this.child,
required this.menuChildren,
this.focusNode,
this.menuController,
});

final Widget child;
final List<Widget> menuChildren;

final FocusNode? focusNode;
final MenuController? menuController;

@override
Widget build(BuildContext context) {
return Focus(
canRequestFocus: false,
onKeyEvent: _onKeyEvent,
child: GestureDetector(
onTapDown: _handleTapDown,
onSecondaryTapDown: _handleSecondaryTapDown,
child: MenuAnchor(
consumeOutsideTap: false,
controller: menuController,
menuChildren: menuChildren,
childFocusNode: focusNode,
child: child,
),
),
);
}

void _handleSecondaryTapDown(TapDownDetails details) {
menuController?.open(position: details.localPosition);
}

void _handleTapDown(TapDownDetails details) {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
// Don't open the menu on these platforms with a Ctrl-tap (or a
// tap).
break;
case TargetPlatform.iOS:
case TargetPlatform.macOS:
// Only open the menu on these platforms if the control button is down
// when the tap occurs.
if (HardwareKeyboard.instance.logicalKeysPressed
.contains(LogicalKeyboardKey.controlLeft) ||
HardwareKeyboard.instance.logicalKeysPressed
.contains(LogicalKeyboardKey.controlRight)) {
menuController?.open(position: details.localPosition);
}
}
}

KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
if (node.hasFocus) {
final isCtrl = HardwareKeyboard.instance.logicalKeysPressed
.contains(LogicalKeyboardKey.controlLeft) || HardwareKeyboard.instance.logicalKeysPressed
.contains(LogicalKeyboardKey.controlRight);
if (event.logicalKey == LogicalKeyboardKey.enter && isCtrl) {
menuController?.open();
}
}

return KeyEventResult.ignored;
}
}
64 changes: 0 additions & 64 deletions lib/widgets/better_lazy_data_table.dart.old

This file was deleted.

Loading

0 comments on commit d59f067

Please sign in to comment.