From 50aa8e12ad8c84d66139d46e3afe9cb3a2ad917a Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 23 Aug 2024 10:00:36 +0800 Subject: [PATCH] desktop file transfer, all columns respond to tap, add right click item border (#9153) When right click selected item, the border is not obvious but can feel some change. Signed-off-by: 21pages --- .../lib/desktop/pages/file_manager_page.dart | 103 +++++++++++------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart index 682ffa831..05af83cd3 100644 --- a/flutter/lib/desktop/pages/file_manager_page.dart +++ b/flutter/lib/desktop/pages/file_manager_page.dart @@ -930,6 +930,7 @@ class _FileManagerViewState extends State { BuildContext context, ScrollController scrollController) { final fd = controller.directory.value; final entries = fd.entries; + Rx rightClickEntry = Rx(null); return ListSearchActionListener( node: _keyboardNode, @@ -989,6 +990,53 @@ class _FileManagerViewState extends State { ? " " : "${entry.lastModified().toString().replaceAll(".000", "")} "; var secondaryPosition = RelativeRect.fromLTRB(0, 0, 0, 0); + onTap() { + final items = selectedItems; + // handle double click + if (_checkDoubleClick(entry)) { + controller.openDirectory(entry.path); + items.clear(); + return; + } + _onSelectedChanged(items, filteredEntries, entry, isLocal); + } + + onSecondaryTap() { + final items = [ + if (!entry.isDrive && + versionCmp(_ffi.ffiModel.pi.version, "1.3.0") >= 0) + mod_menu.PopupMenuItem( + child: Text("Rename"), + height: CustomPopupMenuTheme.height, + onTap: () { + controller.renameAction(entry, isLocal); + }, + ) + ]; + if (items.isNotEmpty) { + rightClickEntry.value = entry; + final future = mod_menu.showMenu( + context: context, + position: secondaryPosition, + items: items, + ); + future.then((value) { + rightClickEntry.value = null; + }); + future.onError((error, stackTrace) { + rightClickEntry.value = null; + }); + } + } + + onSecondaryTapDown(details) { + secondaryPosition = RelativeRect.fromLTRB( + details.globalPosition.dx, + details.globalPosition.dy, + details.globalPosition.dx, + details.globalPosition.dy); + } + return Padding( padding: EdgeInsets.symmetric(vertical: 1), child: Obx(() => Container( @@ -999,6 +1047,12 @@ class _FileManagerViewState extends State { borderRadius: BorderRadius.all( Radius.circular(5.0), ), + border: rightClickEntry.value == entry + ? Border.all( + color: MyTheme.button, + width: 1.0, + ) + : null, ), key: ValueKey(entry.name), height: kDesktopFileTransferRowHeight, @@ -1047,46 +1101,9 @@ class _FileManagerViewState extends State { ]), )), ), - onTap: () { - final items = selectedItems; - // handle double click - if (_checkDoubleClick(entry)) { - controller.openDirectory(entry.path); - items.clear(); - return; - } - _onSelectedChanged( - items, filteredEntries, entry, isLocal); - }, - onSecondaryTap: () { - final items = [ - if (!entry.isDrive && - versionCmp(_ffi.ffiModel.pi.version, - "1.3.0") >= - 0) - mod_menu.PopupMenuItem( - child: Text("Rename"), - height: CustomPopupMenuTheme.height, - onTap: () { - controller.renameAction(entry, isLocal); - }, - ) - ]; - if (items.isNotEmpty) { - mod_menu.showMenu( - context: context, - position: secondaryPosition, - items: items, - ); - } - }, - onSecondaryTapDown: (details) { - secondaryPosition = RelativeRect.fromLTRB( - details.globalPosition.dx, - details.globalPosition.dy, - details.globalPosition.dx, - details.globalPosition.dy); - }, + onTap: onTap, + onSecondaryTap: onSecondaryTap, + onSecondaryTapDown: onSecondaryTapDown, ), SizedBox( width: 2.0, @@ -1111,6 +1128,9 @@ class _FileManagerViewState extends State { )), ), ), + onTap: onTap, + onSecondaryTap: onSecondaryTap, + onSecondaryTapDown: onSecondaryTapDown, ), // Divider from header. SizedBox( @@ -1133,6 +1153,9 @@ class _FileManagerViewState extends State { : MyTheme.darkGray), ), ), + onTap: onTap, + onSecondaryTap: onSecondaryTap, + onSecondaryTapDown: onSecondaryTapDown, ), ), ],