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'** /// **'Open'**
String get 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. /// No description provided for @paste.
/// ///
/// In en, this message translates to: /// In en, this message translates to:

View File

@@ -461,6 +461,12 @@ class SDe extends S {
@override @override
String get open => 'Öffnen'; 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 @override
String get paste => 'Einfügen'; String get paste => 'Einfügen';

View File

@@ -461,6 +461,12 @@ class SEn extends S {
@override @override
String get open => 'Open'; 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 @override
String get paste => 'Paste'; String get paste => 'Paste';

View File

@@ -461,6 +461,12 @@ class SId extends S {
@override @override
String get open => 'Membuka'; 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 @override
String get paste => 'Tempel'; String get paste => 'Tempel';

View File

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

View File

@@ -1,16 +1,18 @@
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:toolbox/core/persistant_store.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 /// index from 0 -> n : latest -> oldest
class _History { class _ListHistory {
final _HistoryType _history; final _HistoryList _history;
final String _name; final String _name;
final Box<_HistoryType> _box; final Box _box;
_History({ _ListHistory({
required Box<_HistoryType> box, required Box box,
required String name, required String name,
}) : _box = box, }) : _box = box,
_name = name, _name = name,
@@ -22,11 +24,34 @@ class _History {
_box.put(_name, _history); _box.put(_name, _history);
} }
_HistoryType get all => _history; _HistoryList get all => _history;
} }
class HistoryStore extends PersistentStore<_HistoryType> { class _MapHistory {
late final _History sftpPath = _History(box: box, name: 'sftpPath'); 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 /// The performance of highlight is bad
late final editorHighlight = StoreProperty(box, 'editorHighlight', true); 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 // Never show these settings for users
// //
// ------BEGIN------ // ------BEGIN------

View File

@@ -145,6 +145,8 @@
"ok": "OK", "ok": "OK",
"onServerDetailPage": "in Detailansicht des Servers", "onServerDetailPage": "in Detailansicht des Servers",
"open": "Öffnen", "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", "paste": "Einfügen",
"path": "Pfad", "path": "Pfad",
"percentOfSize": "{percent}% von {size}", "percentOfSize": "{percent}% von {size}",

View File

@@ -145,6 +145,8 @@
"ok": "OK", "ok": "OK",
"onServerDetailPage": "On server detail page", "onServerDetailPage": "On server detail page",
"open": "Open", "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", "paste": "Paste",
"path": "Path", "path": "Path",
"percentOfSize": "{percent}% of {size}", "percentOfSize": "{percent}% of {size}",

View File

@@ -145,6 +145,8 @@
"ok": "OKE", "ok": "OKE",
"onServerDetailPage": "Di halaman detail server", "onServerDetailPage": "Di halaman detail server",
"open": "Membuka", "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", "paste": "Tempel",
"path": "Jalur", "path": "Jalur",
"percentOfSize": "{percent}% dari {size}", "percentOfSize": "{percent}% dari {size}",

View File

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

View File

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

View File

@@ -156,6 +156,8 @@ class _SettingPageState extends State<SettingPage> {
_buildServer(), _buildServer(),
_buildTitle('SSH'), _buildTitle('SSH'),
_buildSSH(), _buildSSH(),
_buildTitle('SFTP'),
_buildSFTP(),
_buildTitle(l10n.editor), _buildTitle(l10n.editor),
_buildEditor(), _buildEditor(),
_buildTitle(l10n.fullScreen), _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 // Use hardware keyboard on desktop, so there is no need to set it
if (isMobile) _buildKeyboardType(), if (isMobile) _buildKeyboardType(),
_buildSSHVirtKeys(), _buildSSHVirtKeys(),
_buildSftpRmrDir(),
].map((e) => RoundRectCard(e)).toList(), ].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() { Widget _buildNetViewType() {
final items = NetViewType.values final items = NetViewType.values
.map((e) => PopupMenuItem( .map((e) => PopupMenuItem(

View File

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