Merge pull request #5710 from NicKoehler/manager-columns

Changed File Manager column behaviour
This commit is contained in:
RustDesk 2023-09-16 18:53:31 +08:00 committed by GitHub
commit 55114082e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 31 deletions

View File

@ -74,10 +74,6 @@ const int kDesktopDefaultDisplayHeight = 720;
const int kMobileMaxDisplaySize = 1280; const int kMobileMaxDisplaySize = 1280;
const int kDesktopMaxDisplaySize = 3840; const int kDesktopMaxDisplaySize = 3840;
const double kDesktopFileTransferNameColWidth = 200;
const double kDesktopFileTransferModifiedColWidth = 120;
const double kDesktopFileTransferMinimumWidth = 100;
const double kDesktopFileTransferMaximumWidth = 300;
const double kDesktopFileTransferRowHeight = 30.0; const double kDesktopFileTransferRowHeight = 30.0;
const double kDesktopFileTransferHeaderHeight = 25.0; const double kDesktopFileTransferHeaderHeight = 25.0;
@ -142,6 +138,7 @@ const kRemoteScrollStyleBar = 'scrollbar';
/// [kScrollModeDefault] Mouse or touchpad, the default scroll mode. /// [kScrollModeDefault] Mouse or touchpad, the default scroll mode.
const kScrollModeDefault = 'default'; const kScrollModeDefault = 'default';
/// [kScrollModeReverse] Mouse or touchpad, the reverse scroll mode. /// [kScrollModeReverse] Mouse or touchpad, the reverse scroll mode.
const kScrollModeReverse = 'reverse'; const kScrollModeReverse = 'reverse';

View File

@ -364,15 +364,20 @@ class _FileManagerViewState extends State<FileManagerView> {
final _breadCrumbScroller = ScrollController(); final _breadCrumbScroller = ScrollController();
final _keyboardNode = FocusNode(); final _keyboardNode = FocusNode();
final _listSearchBuffer = TimeoutStringBuffer(); final _listSearchBuffer = TimeoutStringBuffer();
final _nameColWidth = kDesktopFileTransferNameColWidth.obs; final _nameColWidth = 0.0.obs;
final _modifiedColWidth = kDesktopFileTransferModifiedColWidth.obs; final _modifiedColWidth = 0.0.obs;
final _sizeColWidth = 0.0.obs;
final _fileListScrollController = ScrollController(); final _fileListScrollController = ScrollController();
final _globalHeaderKey = GlobalKey();
/// [_lastClickTime], [_lastClickEntry] help to handle double click /// [_lastClickTime], [_lastClickEntry] help to handle double click
var _lastClickTime = var _lastClickTime =
DateTime.now().millisecondsSinceEpoch - bind.getDoubleClickTime() - 1000; DateTime.now().millisecondsSinceEpoch - bind.getDoubleClickTime() - 1000;
Entry? _lastClickEntry; Entry? _lastClickEntry;
double? _windowWidthPrev;
double _fileTransferMinimumWidth = 0.0;
FileController get controller => widget.controller; FileController get controller => widget.controller;
bool get isLocal => widget.controller.isLocal; bool get isLocal => widget.controller.isLocal;
FFI get _ffi => widget._ffi; FFI get _ffi => widget._ffi;
@ -398,6 +403,7 @@ class _FileManagerViewState extends State<FileManagerView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_handleColumnPorportions();
return Container( return Container(
margin: const EdgeInsets.all(16.0), margin: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@ -429,6 +435,27 @@ class _FileManagerViewState extends State<FileManagerView> {
); );
} }
void _handleColumnPorportions() {
final windowWidthNow = MediaQuery.of(context).size.width;
if (_windowWidthPrev == null) {
_windowWidthPrev = windowWidthNow;
final defaultColumnWidth = windowWidthNow * 0.115;
_fileTransferMinimumWidth = defaultColumnWidth / 3;
_nameColWidth.value = defaultColumnWidth;
_modifiedColWidth.value = defaultColumnWidth;
_sizeColWidth.value = defaultColumnWidth;
}
if (_windowWidthPrev != windowWidthNow) {
final difference = windowWidthNow / _windowWidthPrev!;
_windowWidthPrev = windowWidthNow;
_fileTransferMinimumWidth *= difference;
_nameColWidth.value *= difference;
_modifiedColWidth.value *= difference;
_sizeColWidth.value *= difference;
}
}
void onLocationFocusChanged() { void onLocationFocusChanged() {
debugPrint("focus changed on local"); debugPrint("focus changed on local");
if (_locationNode.hasFocus) { if (_locationNode.hasFocus) {
@ -1143,9 +1170,21 @@ class _FileManagerViewState extends State<FileManagerView> {
return false; return false;
} }
void _onDrag(double dx, RxDouble column1, RxDouble column2) {
if (column1.value + dx <= _fileTransferMinimumWidth ||
column2.value - dx <= _fileTransferMinimumWidth) {
return;
}
column1.value += dx;
column2.value -= dx;
column1.value = max(_fileTransferMinimumWidth, column1.value);
column2.value = max(_fileTransferMinimumWidth, column2.value);
}
Widget _buildFileBrowserHeader(BuildContext context) { Widget _buildFileBrowserHeader(BuildContext context) {
final padding = EdgeInsets.all(1.0); final padding = EdgeInsets.all(1.0);
return SizedBox( return SizedBox(
key: _globalHeaderKey,
height: kDesktopFileTransferHeaderHeight, height: kDesktopFileTransferHeaderHeight,
child: Row( child: Row(
children: [ children: [
@ -1155,11 +1194,8 @@ class _FileManagerViewState extends State<FileManagerView> {
), ),
DraggableDivider( DraggableDivider(
axis: Axis.vertical, axis: Axis.vertical,
onPointerMove: (dx) { onPointerMove: (dx) =>
_nameColWidth.value += dx; _onDrag(dx, _nameColWidth, _modifiedColWidth),
_nameColWidth.value = min(kDesktopFileTransferMaximumWidth,
max(kDesktopFileTransferMinimumWidth, _nameColWidth.value));
},
padding: padding, padding: padding,
), ),
Obx( Obx(
@ -1168,15 +1204,12 @@ class _FileManagerViewState extends State<FileManagerView> {
), ),
DraggableDivider( DraggableDivider(
axis: Axis.vertical, axis: Axis.vertical,
onPointerMove: (dx) { onPointerMove: (dx) =>
_modifiedColWidth.value += dx; _onDrag(dx, _modifiedColWidth, _sizeColWidth),
_modifiedColWidth.value = min(
kDesktopFileTransferMaximumWidth,
max(kDesktopFileTransferMinimumWidth,
_modifiedColWidth.value));
},
padding: padding), padding: padding),
Expanded(child: headerItemFunc(null, SortBy.size, translate("Size"))) Expanded(
child: headerItemFunc(
_sizeColWidth.value, SortBy.size, translate("Size")))
], ],
), ),
); );
@ -1201,23 +1234,20 @@ class _FileManagerViewState extends State<FileManagerView> {
height: kDesktopFileTransferHeaderHeight, height: kDesktopFileTransferHeaderHeight,
child: Row( child: Row(
children: [ children: [
Flexible( Expanded(
flex: 2,
child: Text( child: Text(
name, name,
style: headerTextStyle, style: headerTextStyle,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
).marginSymmetric(horizontal: 4), ).marginOnly(left: 4),
), ),
Flexible( ascending.value != null
flex: 1, ? Icon(
child: ascending.value != null ascending.value!
? Icon( ? Icons.keyboard_arrow_up_rounded
ascending.value! : Icons.keyboard_arrow_down_rounded,
? Icons.keyboard_arrow_up_rounded )
: Icons.keyboard_arrow_down_rounded, : SizedBox()
)
: const Offstage())
], ],
), ),
), ),