Skip to content

Commit

Permalink
Option in settings to disable SFTP folders-first
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperCube committed Feb 17, 2024
1 parent 8d722da commit 52e94e9
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,12 @@ abstract class S {
/// **'Use `rm -r` to delete a folder in SFTP.'**
String get sftpRmrDirSummary;

/// No description provided for @sftpShowFoldersFirst.
///
/// In en, this message translates to:
/// **'Disply folders first'**
String get sftpShowFoldersFirst;

/// No description provided for @sftpSSHConnected.
///
/// In en, this message translates to:
Expand Down
3 changes: 3 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ class SDe extends S {
@override
String get sftpRmrDirSummary => 'Verwenden Sie \"rm -r\", um das Verzeichnis in SFTP zu löschen.';

@override
String get sftpShowFoldersFirst => 'Ordner zuerst anzeigen';

@override
String get sftpSSHConnected => 'SFTP Verbunden';

Expand Down
3 changes: 3 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ class SEn extends S {
@override
String get sftpRmrDirSummary => 'Use `rm -r` to delete a folder in SFTP.';

@override
String get sftpShowFoldersFirst => 'Disply folders first';

@override
String get sftpSSHConnected => 'SFTP Connected';

Expand Down
3 changes: 3 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ class SFr extends S {
@override
String get sftpRmrDirSummary => 'Utilisez `rm -r` pour supprimer un dossier dans SFTP.';

@override
String get sftpShowFoldersFirst => 'Dossiers d\'abord lors du tri';

@override
String get sftpSSHConnected => 'SFTP connecté';

Expand Down
3 changes: 3 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ class SId extends S {
@override
String get sftpRmrDirSummary => 'Gunakan `rm -r` untuk menghapus dir di SFTP';

@override
String get sftpShowFoldersFirst => 'Folder ditampilkan lebih dulu';

@override
String get sftpSSHConnected => 'Sftp terhubung';

Expand Down
6 changes: 6 additions & 0 deletions .dart_tool/flutter_gen/gen_l10n/l10n_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ class SZh extends S {
@override
String get sftpRmrDirSummary => '在 SFTP 中使用 `rm -r` 来删除文件夹';

@override
String get sftpShowFoldersFirst => '排序时文件夹显示在前';

@override
String get sftpSSHConnected => 'SFTP 已连接...';

Expand Down Expand Up @@ -1502,6 +1505,9 @@ class SZhTw extends SZh {
@override
String get sftpRmrDirSummary => '在 SFTP 中使用 `rm -r` 來刪除文件夾';

@override
String get sftpShowFoldersFirst => '排序時文件夾顯示在前';

@override
String get sftpSSHConnected => 'SFTP 已連接...';

Expand Down
3 changes: 3 additions & 0 deletions lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class SettingStore extends PersistentStore {
/// Open SFTP with last viewed path
late final sftpOpenLastPath = property('sftpOpenLastPath', true);

/// Show folders first in SFTP file browser
late final sftpShowFoldersFirst = property('sftpShowFoldersFirst', true);

/// Show tip of suspend
late final showSuspendTip = property('showSuspendTip', true);

Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "Einstellungen",
"sftpDlPrepare": "Verbindung vorbereiten...",
"sftpRmrDirSummary": "Verwenden Sie \"rm -r\", um das Verzeichnis in SFTP zu löschen.",
"sftpShowFoldersFirst": "Ordner zuerst anzeigen",
"sftpSSHConnected": "SFTP Verbunden",
"showDistLogo": "Distributionslogo anzeigen",
"shutdown": "Abschaltung",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "Settings",
"sftpDlPrepare": "Preparing to connect...",
"sftpRmrDirSummary": "Use `rm -r` to delete a folder in SFTP.",
"sftpShowFoldersFirst": "Disply folders first",
"sftpSSHConnected": "SFTP Connected",
"showDistLogo": "Show distribution logo",
"shutdown": "Shutdown",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "Paramètres",
"sftpDlPrepare": "Préparation de la connexion...",
"sftpRmrDirSummary": "Utilisez `rm -r` pour supprimer un dossier dans SFTP.",
"sftpShowFoldersFirst": "Dossiers d'abord lors du tri",
"sftpSSHConnected": "SFTP connecté",
"showDistLogo": "Afficher le logo de la distribution",
"shutdown": "Éteindre",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "Pengaturan",
"sftpDlPrepare": "Bersiap untuk terhubung ...",
"sftpRmrDirSummary": "Gunakan `rm -r` untuk menghapus dir di SFTP",
"sftpShowFoldersFirst": "Folder ditampilkan lebih dulu",
"sftpSSHConnected": "Sftp terhubung",
"showDistLogo": "Tampilkan logo distribusi",
"shutdown": "Matikan",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "设置",
"sftpDlPrepare": "准备连接至服务器...",
"sftpRmrDirSummary": "在 SFTP 中使用 `rm -r` 来删除文件夹",
"sftpShowFoldersFirst": "排序时文件夹显示在前",
"sftpSSHConnected": "SFTP 已连接...",
"showDistLogo": "显示发行版 Logo",
"shutdown": "关机",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"setting": "設置",
"sftpDlPrepare": "準備連接至服務器...",
"sftpRmrDirSummary": "在 SFTP 中使用 `rm -r` 來刪除文件夾",
"sftpShowFoldersFirst": "排序時文件夾顯示在前",
"sftpSSHConnected": "SFTP 已連接...",
"showDistLogo": "顯示發行版 Logo",
"shutdown": "关机",
Expand Down
8 changes: 8 additions & 0 deletions lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ class _SettingPageState extends State<SettingPage> {
children: [
_buildSftpRmrDir(),
_buildSftpOpenLastPath(),
_buildSftpShowFoldersFirst(),
].map((e) => CardX(child: e)).toList(),
);
}
Expand All @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions lib/view/page/storage/sftp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 52e94e9

Please sign in to comment.