Option in settings to disable SFTP folders-first

This commit is contained in:
PaperCube
2024-02-17 00:58:57 +00:00
parent 8d722da799
commit 52e94e902b
15 changed files with 49 additions and 6 deletions

View File

@@ -855,6 +855,7 @@ class _SettingPageState extends State<SettingPage> {
children: [
_buildSftpRmrDir(),
_buildSftpOpenLastPath(),
_buildSftpShowFoldersFirst(),
].map((e) => CardX(child: e)).toList(),
);
}
@@ -867,6 +868,13 @@ class _SettingPageState extends State<SettingPage> {
);
}
Widget _buildSftpShowFoldersFirst() {
return ListTile(
title: Text(l10n.sftpShowFoldersFirst),
trailing: StoreSwitch(prop: _setting.sftpShowFoldersFirst),
);
}
Widget _buildNetViewType() {
final items = NetViewType.values
.map((e) => PopupMenuItem(

View File

@@ -15,6 +15,7 @@ import 'package:toolbox/data/res/logger.dart';
import 'package:toolbox/data/res/misc.dart';
import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/view/widget/omit_start_text.dart';
import 'package:toolbox/view/widget/cardx.dart';
@@ -820,11 +821,14 @@ enum _SortType {
;
List<SftpName> sort(List<SftpName> files, {bool reversed = false}) {
var comparator = ChainComparator<SftpName>.create();
if (Stores.setting.sftpShowFoldersFirst.fetch()) {
comparator = comparator.thenTrueFirst((x) => x.attr.isDirectory);
}
switch (this) {
case _SortType.name:
files.sort(
ChainComparator<SftpName>.create()
.thenTrueFirst((x) => x.attr.isDirectory)
comparator
.thenWithComparator(
(a, b) => Comparators.compareStringCaseInsensitive()(
a.filename, b.filename),
@@ -835,8 +839,7 @@ enum _SortType {
break;
case _SortType.time:
files.sort(
ChainComparator<SftpName>.create()
.thenTrueFirst((x) => x.attr.isDirectory)
comparator
.thenCompareBy<num>(
(x) => x.attr.modifyTime ?? 0,
reversed: reversed,
@@ -846,8 +849,7 @@ enum _SortType {
break;
case _SortType.size:
files.sort(
ChainComparator<SftpName>.create()
.thenTrueFirst((x) => x.attr.isDirectory)
comparator
.thenCompareBy<num>(
(x) => x.attr.size ?? 0,
reversed: reversed,