new: open sftp with last viewed path

This commit is contained in:
lollipopkit
2023-10-14 23:03:12 +08:00
parent c9d54f4fea
commit a397f81988
14 changed files with 123 additions and 12 deletions

View File

@@ -968,6 +968,18 @@ abstract class S {
/// **'Open'**
String get open;
/// No description provided for @openLastPath.
///
/// In en, this message translates to:
/// **'Open the last path'**
String get openLastPath;
/// No description provided for @openLastPathTip.
///
/// In en, this message translates to:
/// **'Different servers will have different logs, and the log is the path to the exit'**
String get openLastPathTip;
/// No description provided for @paste.
///
/// In en, this message translates to:

View File

@@ -461,6 +461,12 @@ class SDe extends S {
@override
String get open => 'Öffnen';
@override
String get openLastPath => 'Öffnen Sie den letzten Pfad';
@override
String get openLastPathTip => 'Verschiedene Server haben unterschiedliche Einträge, und der Eintrag ist der Pfad zum Ausgang';
@override
String get paste => 'Einfügen';

View File

@@ -461,6 +461,12 @@ class SEn extends S {
@override
String get open => 'Open';
@override
String get openLastPath => 'Open the last path';
@override
String get openLastPathTip => 'Different servers will have different logs, and the log is the path to the exit';
@override
String get paste => 'Paste';

View File

@@ -461,6 +461,12 @@ class SId extends S {
@override
String get open => 'Membuka';
@override
String get openLastPath => 'Buka jalur terakhir';
@override
String get openLastPathTip => 'Server yang berbeda akan memiliki catatan yang berbeda, dan catatan tersebut adalah jalur menuju pintu keluar';
@override
String get paste => 'Tempel';

View File

@@ -461,6 +461,12 @@ class SZh extends S {
@override
String get open => '打开';
@override
String get openLastPath => '打开上次的路径';
@override
String get openLastPathTip => '不同的服务器会有不同的记录,且记录的是退出时的路径';
@override
String get paste => '粘贴';
@@ -1211,6 +1217,12 @@ class SZhTw extends SZh {
@override
String get open => '打開';
@override
String get openLastPath => '打開上次的路徑';
@override
String get openLastPathTip => '不同的服務器會有不同的記錄,且記錄的是退出時的路徑';
@override
String get paste => '貼上';

View File

@@ -1,16 +1,18 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:toolbox/core/persistant_store.dart';
typedef _HistoryType = List<String>;
typedef _HistoryList = List<String>;
typedef _HistoryMap = Map<String, String>;
/// index from 0 -> n : latest -> oldest
class _History {
final _HistoryType _history;
class _ListHistory {
final _HistoryList _history;
final String _name;
final Box<_HistoryType> _box;
final Box _box;
_History({
required Box<_HistoryType> box,
_ListHistory({
required Box box,
required String name,
}) : _box = box,
_name = name,
@@ -22,11 +24,34 @@ class _History {
_box.put(_name, _history);
}
_HistoryType get all => _history;
_HistoryList get all => _history;
}
class HistoryStore extends PersistentStore<_HistoryType> {
late final _History sftpPath = _History(box: box, name: 'sftpPath');
class _MapHistory {
final _HistoryMap _history;
final String _name;
final Box _box;
late final _History sshCmds = _History(box: box, name: 'sshCmds');
_MapHistory({
required Box box,
required String name,
}) : _box = box,
_name = name,
_history = box.get(name, defaultValue: <String, String>{})!;
void put(String id, String val) {
_history[id] = val;
_box.put(_name, _history);
}
String? fetch(String id) => _history[id];
}
class HistoryStore extends PersistentStore {
/// Paths that user has visited by 'Locate' button
late final sftpGoPath = _ListHistory(box: box, name: 'sftpPath');
late final sftpLastPath = _MapHistory(box: box, name: 'sftpLastPath');
late final sshCmds = _ListHistory(box: box, name: 'sshCmds');
}

View File

@@ -215,6 +215,9 @@ class SettingStore extends PersistentStore {
/// The performance of highlight is bad
late final editorHighlight = StoreProperty(box, 'editorHighlight', true);
/// Open SFTP with last viewed path
late final sftpOpenLastPath = StoreProperty(box, 'sftpOpenLastPath', true);
// Never show these settings for users
//
// ------BEGIN------

View File

@@ -145,6 +145,8 @@
"ok": "OK",
"onServerDetailPage": "in Detailansicht des Servers",
"open": "Öffnen",
"openLastPath": "Öffnen Sie den letzten Pfad",
"openLastPathTip": "Verschiedene Server haben unterschiedliche Einträge, und der Eintrag ist der Pfad zum Ausgang",
"paste": "Einfügen",
"path": "Pfad",
"percentOfSize": "{percent}% von {size}",

View File

@@ -145,6 +145,8 @@
"ok": "OK",
"onServerDetailPage": "On server detail page",
"open": "Open",
"openLastPath": "Open the last path",
"openLastPathTip": "Different servers will have different logs, and the log is the path to the exit",
"paste": "Paste",
"path": "Path",
"percentOfSize": "{percent}% of {size}",

View File

@@ -145,6 +145,8 @@
"ok": "OKE",
"onServerDetailPage": "Di halaman detail server",
"open": "Membuka",
"openLastPath": "Buka jalur terakhir",
"openLastPathTip": "Server yang berbeda akan memiliki catatan yang berbeda, dan catatan tersebut adalah jalur menuju pintu keluar",
"paste": "Tempel",
"path": "Jalur",
"percentOfSize": "{percent}% dari {size}",

View File

@@ -145,6 +145,8 @@
"ok": "好",
"onServerDetailPage": "在服务器详情页",
"open": "打开",
"openLastPath": "打开上次的路径",
"openLastPathTip": "不同的服务器会有不同的记录,且记录的是退出时的路径",
"paste": "粘贴",
"path": "路径",
"percentOfSize": "{size} 的 {percent}%",

View File

@@ -145,6 +145,8 @@
"ok": "好",
"onServerDetailPage": "在服務器詳情頁",
"open": "打開",
"openLastPath": "打開上次的路徑",
"openLastPathTip": "不同的服務器會有不同的記錄,且記錄的是退出時的路徑",
"paste": "貼上",
"path": "路徑",
"percentOfSize": "{size} 的 {percent}%",

View File

@@ -156,6 +156,8 @@ class _SettingPageState extends State<SettingPage> {
_buildServer(),
_buildTitle('SSH'),
_buildSSH(),
_buildTitle('SFTP'),
_buildSFTP(),
_buildTitle(l10n.editor),
_buildEditor(),
_buildTitle(l10n.fullScreen),
@@ -230,7 +232,6 @@ class _SettingPageState extends State<SettingPage> {
// Use hardware keyboard on desktop, so there is no need to set it
if (isMobile) _buildKeyboardType(),
_buildSSHVirtKeys(),
_buildSftpRmrDir(),
].map((e) => RoundRectCard(e)).toList(),
);
}
@@ -842,6 +843,23 @@ class _SettingPageState extends State<SettingPage> {
);
}
Widget _buildSFTP() {
return Column(
children: [
_buildSftpRmrDir(),
_buildSftpOpenLastPath(),
].map((e) => RoundRectCard(e)).toList(),
);
}
Widget _buildSftpOpenLastPath() {
return ListTile(
title: Text(l10n.openLastPath),
subtitle: Text(l10n.openLastPathTip, style: UIs.textGrey),
trailing: StoreSwitch(prop: _setting.sftpOpenLastPath),
);
}
Widget _buildNetViewType() {
final items = NetViewType.values
.map((e) => PopupMenuItem(

View File

@@ -647,6 +647,12 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
_status.files = fs;
});
context.pop();
// Only update history when success
if (Stores.setting.sftpOpenLastPath.fetch()) {
Stores.history.sftpLastPath.put(widget.spi.id, listPath);
}
return true;
}
return false;
@@ -679,7 +685,14 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
@override
FutureOr<void> afterFirstLayout(BuildContext context) {
_status.path = AbsolutePath(widget.initPath ?? '/');
var initPath = '/';
if (Stores.setting.sftpOpenLastPath.fetch()) {
final history = Stores.history.sftpLastPath.fetch(widget.spi.id);
if (history != null) {
initPath = history;
}
}
_status.path = AbsolutePath(widget.initPath ?? initPath);
_listDir();
}
}