Compare commits

...
Author SHA1 Message Date
XuzandClaude Opus 5.5 3a9e72eab3 版本号改为 0.1.7-beta.2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:47:24 +08:00
XuzandClaude Opus 5.5 27822e7315 SFTP 文件列表点列名即可排序,换目录后列宽和排序箭头不再复位
gpui-kit 只给列标题右边的箭头挂了排序,标题本身的点击用来选列,而文件列表关掉了选列,
所以只能点箭头。现在点列名和点箭头一样:降序、升序、恢复按名称。

表格每次 refresh(每读一次目录)都从委托重新取列,原来拖宽的列会弹回默认宽度,箭头也回到
「未排序」而行仍按原列排着。现在 FileListing 记下拖动后的列宽(ColumnWidthsChanged)和
当前排序,refresh 后照旧。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:46:54 +08:00
XuzandClaude Opus 5.5 e1600ce05c SFTP 本地目录列表在 Windows 上列出各个驱动器
Windows 上每个盘是一个独立的根,目录列表原来只有当前路径的各级和主目录、桌面、文稿、下载,
离不开起始的盘(只能在「打开目录/书签」里手动输入 D:\)。现在「位置」里按 WinSCP 的样子
列出所有盘符:「C: 本地磁盘」「E: 可移动磁盘」「Z: 网络驱动器」「F: CD 驱动器」。

盘符用 GetLogicalDrives 和 GetDriveTypeW 取,不读卷标。位置改在后台随每次读本地目录
一起重新取,所以新插上的 U 盘刷新一下就出现,也不在 UI 线程上碰网络驱动器。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 13:46:54 +08:00
13 changed files with 391 additions and 37 deletions

No files matched your search

+14
View File
@@ -2,6 +2,20 @@
每个版本一节,标题写成 `## [版本号]`,可以在后面加日期。发布流程(`.github/workflows/release.yml`)把与 tag 同版本的那一节原样作为更新说明:显示在 GitHub Release 和官网的更新日志里(ShellRS 的更新对话框用「查看更新内容」打开官网的更新日志),用 Markdown 书写,面向使用者。
## [0.1.7-beta.2]
### 新增
- Windows 上 SFTP 本地目录列表列出各个驱动器,可切换到其他盘。
### 改进
- SFTP 文件列表点列名即可排序。
### 修复
- 修复 SFTP 换目录后拖宽的列恢复原宽。
## [0.1.7-beta.1]
### 修复
Generated
+1 -1
View File
@@ -7738,7 +7738,7 @@ dependencies = [
[[package]]
name = "shellrs"
version = "0.1.7-beta.1"
version = "0.1.7-beta.2"
dependencies = [
"alacritty_terminal",
"anyhow",
+2 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "shellrs"
version = "0.1.7-beta.1"
version = "0.1.7-beta.2"
edition = "2024"
publish = false
description = "SSH client and host manager: terminal, SFTP, port forwarding"
@@ -113,6 +113,7 @@ windows-sys = { version = "0.61", features = [
"Win32_System_IO",
"Win32_System_Pipes",
"Win32_System_Threading",
"Win32_System_WindowsProgramming",
"Win32_UI_WindowsAndMessaging",
] }
+2 -2
View File
@@ -251,7 +251,7 @@ Open a host’s “SFTP” tab to browse local and remote folders. As with termi
Each pane has two rows of toolbar, with the path label below them. When a pane is too narrow, buttons hide whole, from right to left, rather than wrapping (their commands are still in the context menus and shortcuts). A new SFTP tab splits evenly between the local and remote sides; wherever you drag the dividers between the sides and the queue, they stay there until the tab closes, even when you switch to another tab and back:
- First row (navigation):
- The folder list: lists every level from the root to the current folder, plus Home, Desktop, Documents and Downloads on the local side; choose one to go there.
- The folder list: lists every level from the root to the current folder, plus Home, Desktop, Documents and Downloads on the local side, and on Windows every drive (such as “C: Local disk” and “D: Local disk”); choose one to go there.
- Bookmarks: the button opens the “Open folder” dialog (see below); the drop-down arrow next to it lists this host’s bookmarks for this side, which you click to go there, and can also add or remove the current path. Bookmarks are saved in the local database and deleted along with the host.
- Parent folder, Root folder, Home folder, Refresh, Back, Forward.
- Show / hide hidden files: files and folders whose names start with `.`. An open eye means they’re shown, a crossed-out eye that they’re hidden. Local and remote each have their own switch, independent of each other; each side’s choice applies to every SFTP tab and is saved in the settings; both are hidden by default. While they’re hidden, the bottom of the pane says “N hidden”; while they’re shown, hidden files’ text is lighter.
@@ -281,7 +281,7 @@ Works like WinSCP’s Open directory dialog. Open it from the path label, the bo
The status bar below the list normally shows the number of items and how many are selected; while connecting, or when reading a folder takes longer than 0.3 seconds, it shows “Connecting to SFTP…” or “Reading folder…”. When a folder can’t be read or the connection drops, the reason appears in red at the far bottom left of the window (where “Connected to” and the host’s name normally are). A dropped connection is noticed even while idle, without waiting for a refresh, as soon as the same host’s terminal would notice. To reconnect, use the “Reconnect” button in the tab bar or the tab menu. While disconnected, any action in the remote list (refreshing, opening a folder, deleting, uploading, downloading and so on) brings up a “Lost the SFTP connection to …” dialog that explains why and can “Reconnect” right away. None of this makes the list move.
The columns are the same as in WinSCP: Name, Size, Type and Modified on the local side; Name, Size, Modified, Permissions and Owner on the remote side.
The columns are the same as in WinSCP: Name, Size, Type and Modified on the local side; Name, Size, Modified, Permissions and Owner on the remote side. Click a column header (or the arrow at its right) to sort by that column: descending, then ascending, then back to by name; folders always come before files. The order and any column widths you dragged stay when you open another folder or refresh.
- Sizes are shown in KB by default (`4,008,960 KB`, rounded up; only empty files are 0 KB), as in WinSCP. Right-click the “Size” column header to switch to “Bytes” (`4,105,175,040 B`), “Kilobytes (KB)” or “Short (B, KB, MB, GB)”, which uses B, KB, MB or GB depending on the size, such as `3.8 GB`; the choice applies to every SFTP tab and is saved in the settings. Sorting by size always uses the exact number of bytes.
- Times look like `2026/4/22 12:44:53`.
+2 -2
View File
@@ -257,7 +257,7 @@ bash 在 shell 退出时才把这次执行的命令写进历史文件,所以
每一侧面板都有两行工具栏,下方是路径标签。面板太窄放不下时,按钮从右往左整个隐藏,不会换行(对应的命令在右键菜单和快捷键里仍然可用)。新开的 SFTP 标签本地、远程两侧各占一半;两侧和队列之间的分隔线拖到哪里,在这个标签关闭之前都会记住,切到别的标签再回来也不变:
- 第一行(导航):
- 「目录列表」:列出从根到当前目录的每一级,本地另有主目录、桌面、文稿、下载,选中即前往。
- 「目录列表」:列出从根到当前目录的每一级,本地另有主目录、桌面、文稿、下载,Windows 上还有各个驱动器(如「C: 本地磁盘」「D: 本地磁盘」),选中即前往。
- 书签:点按钮打开「打开目录/书签」(见下);旁边的下拉箭头列出这台主机这一侧的书签,点击即前往,也可添加或移除当前路径。书签保存在本地数据库,删除主机时一并删除。
- 上级目录、根目录、主目录、刷新、后退、前进。
- 显示 / 不显示隐藏文件:名称以 `.` 开头的文件和目录。睁开的眼睛表示正在显示,划掉的眼睛表示不显示。本地和远程各自一个开关,互不影响;每一侧的选择对所有 SFTP 标签生效,保存在设置里,默认都不显示。不显示时面板底部写明「隐藏 N 项」;显示时隐藏文件的文字颜色浅一些。
@@ -287,7 +287,7 @@ bash 在 shell 退出时才把这次执行的命令写进历史文件,所以
列表下方的状态栏平时显示项目数和已选数量;连接中和读取目录超过 0.3 秒时显示「正在连接 SFTP…」或「正在读取目录…」。读不了目录或连接断开时,原因用红字显示在窗口最左下角(平时显示「已连接 主机的名称」的位置);空闲时断网也会自己发现,不用等到刷新,时机和同一台主机的终端一样;重新连接用标签栏的「重新连接」按钮或标签菜单;断开时在远程列表里做任何操作(刷新、打开目录、删除、上传下载等)会弹出「SFTP 连接已断开」对话框,说明原因,并可直接「重新连接」。这些都不会让列表移动。
列与 WinSCP 相同:本地为名称、大小、类型、修改时间,远程为名称、大小、修改时间、权限、所有者。
列与 WinSCP 相同:本地为名称、大小、类型、修改时间,远程为名称、大小、修改时间、权限、所有者。点列标题(或它右边的箭头)按这一列排序,依次是降序、升序、恢复按名称;目录始终排在文件前面。换目录、刷新后排序和拖动过的列宽都保持不变。
- 大小默认以 KB 显示(`4,008,960 KB`,向上取整,只有空文件是 0 KB),与 WinSCP 相同。右键「大小」列标题可切换为「字节」(`4,105,175,040 B`)、「千字节(KB)」或「简短格式」(按大小用 B、KB、MB、GB,如 `3.8 GB`),对所有 SFTP 标签生效并保存在设置里。按大小排序始终按实际字节数。
- 时间形如 `2026/4/22 12:44:53`。
+12
View File
@@ -15,6 +15,18 @@ sftp.place.documents:
sftp.place.downloads:
zh-CN: 下载
en: Downloads
sftp.place.drive_local:
zh-CN: "%{drive} 本地磁盘"
en: "%{drive} Local disk"
sftp.place.drive_removable:
zh-CN: "%{drive} 可移动磁盘"
en: "%{drive} Removable disk"
sftp.place.drive_network:
zh-CN: "%{drive} 网络驱动器"
en: "%{drive} Network drive"
sftp.place.drive_optical:
zh-CN: "%{drive} CD 驱动器"
en: "%{drive} CD drive"
sftp.error.remote_path_invalid:
zh-CN: 远程路径不能为空或包含空字符
-7
View File
@@ -117,18 +117,12 @@ impl ExplorerPanel {
.expect("workspace checked host");
let endpoint = login.endpoint();
let home = local_provider.home().to_string_lossy().into_owned();
let places = local_provider
.places()
.into_iter()
.map(|(place, path)| (place, path.to_string_lossy().into_owned()))
.collect();
let local = cx.new(|cx| {
FilePane::new(
PaneSide::Local,
id,
host_id,
home.clone(),
places,
store.clone(),
dispatch.clone(),
window,
@@ -141,7 +135,6 @@ impl ExplorerPanel {
id,
host_id,
String::new(),
Vec::new(),
store.clone(),
dispatch.clone(),
window,
+50 -8
View File
@@ -199,6 +199,43 @@ impl FileListing {
}
}
/// Keep the widths the columns were dragged to: the table takes the
/// columns again on each `refresh`, every listing among them.
pub(super) fn set_widths(&mut self, widths: &[Pixels]) {
for (column, width) in self.columns.iter_mut().zip(widths) {
column.width = *width;
}
}
/// A click on a column's title sorts as one on its arrow does:
/// descending, then ascending, then back to by name.
fn cycle_sort(&mut self, col_ix: usize) {
let sort = match self.sort {
Some((ix, ColumnSort::Descending)) if ix == col_ix => ColumnSort::Ascending,
Some((ix, ColumnSort::Ascending)) if ix == col_ix => ColumnSort::Default,
_ => ColumnSort::Descending,
};
self.set_sort(col_ix, sort);
}
/// Sort by a column, marking it on the columns too, which the table
/// takes again on each `refresh`: otherwise the arrows would go back to
/// unsorted with the next listing while the rows stayed sorted.
fn set_sort(&mut self, col_ix: usize, sort: ColumnSort) {
self.sort = match sort {
ColumnSort::Default => None,
sort => Some((col_ix, sort)),
};
for (ix, column) in self.columns.iter_mut().enumerate() {
column.sort = Some(if ix == col_ix {
sort
} else {
ColumnSort::Default
});
}
self.apply_sort();
}
/// The rows shown, in display order.
pub fn rows(&self) -> &[FileEntry] {
&self.rows
@@ -406,13 +443,14 @@ impl TableDelegate for FileListing {
}
/// `Column::text_right` is not applied by `DataTable`, so the size
/// column aligns itself. A right-click on a title is recorded for the
/// list's menu, which offers the size formats on 大小's, as WinSCP does.
/// column aligns itself. A click on a title sorts by the column, as in
/// WinSCP, rather than only one on the arrow. A right-click is recorded
/// for the list's menu, which offers the size formats on 大小's.
fn render_th(
&mut self,
col_ix: usize,
_: &mut Window,
_: &mut Context<TableState<Self>>,
cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
let column = &self.columns[col_ix];
let key = column.key.clone();
@@ -428,6 +466,14 @@ impl TableDelegate for FileListing {
*menu_hit.borrow_mut() = Some(MenuHit::Column(key.clone()));
})
.on_any_mouse_down(move |_, _, _| geometry.pressed.set(Pressed::Title))
// The table keeps the arrows in its columns, which only a
// `refresh` gives it again.
.on_click(cx.listener(move |table, _, _, cx| {
cx.stop_propagation();
table.delegate_mut().cycle_sort(col_ix);
table.refresh(cx);
cx.notify();
}))
.child(column.name.clone())
}
@@ -593,11 +639,7 @@ impl TableDelegate for FileListing {
_: &mut Window,
cx: &mut Context<TableState<Self>>,
) {
self.sort = match sort {
ColumnSort::Default => None,
sort => Some((col_ix, sort)),
};
self.apply_sort();
self.set_sort(col_ix, sort);
cx.notify();
}
+30 -14
View File
@@ -28,7 +28,7 @@ use gpui_kit::component::{
searchable_list::{SearchableGroup, SearchableListItem, SearchableVec},
select::{Select, SelectEvent, SelectState},
separator::Separator,
table::{DataTable, TableDelegate as _, TableState},
table::{DataTable, TableDelegate as _, TableEvent, TableState},
v_flex,
};
use gpui_kit::prelude::FluentBuilder as _;
@@ -132,7 +132,7 @@ pub struct PathChoice {
title: SharedString,
path: SharedString,
depth: usize,
home: bool,
place: Option<Place>,
side: PaneSide,
}
impl SearchableListItem for PathChoice {
@@ -144,10 +144,10 @@ impl SearchableListItem for PathChoice {
&self.path
}
fn render(&self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let icon = if self.home {
Icon::new(CatalogIcon::House)
} else {
Icon::new(IconName::Folder)
let icon = match self.place {
Some(Place::Home) => Icon::new(CatalogIcon::House),
Some(Place::Drive(..)) => Icon::new(IconName::HardDrive),
_ => Icon::new(IconName::Folder),
};
h_flex()
.gap_2()
@@ -182,7 +182,8 @@ pub struct FilePane {
host_id: HostId,
pub(super) path: String,
home: String,
/// Well-known local places for the 目录列表 select; empty for remote.
/// Well-known local places for the 目录列表 select, read with each
/// local listing; empty for remote.
places: Vec<(Place, String)>,
table: Entity<TableState<FileListing>>,
/// The path label part under the pointer, by the directory it opens.
@@ -236,7 +237,6 @@ impl FilePane {
explorer: ExplorerId,
host_id: HostId,
home: String,
places: Vec<(Place, String)>,
store: Entity<HostStore>,
dispatch: FocusHandle,
window: &mut Window,
@@ -272,6 +272,11 @@ impl FilePane {
}
},
),
cx.subscribe(&table, |_, table, event: &TableEvent, cx| {
if let TableEvent::ColumnWidthsChanged(widths) = event {
table.update(cx, |table, _| table.delegate_mut().set_widths(widths));
}
}),
cx.observe(&store, |_, _, cx| cx.notify()),
cx.observe_global::<ShowHiddenFiles>(|pane, cx| pane.sync_hidden_files(cx)),
// The column titles and the select's groups are kept by
@@ -290,7 +295,7 @@ impl FilePane {
host_id,
path: home.clone(),
home,
places,
places: Vec::new(),
table,
hovered_part: None,
label_width: Rc::default(),
@@ -496,6 +501,10 @@ impl FilePane {
pub fn is_busy(&self) -> bool {
self.busy
}
/// The places the 目录列表 select offers, as of the last local listing.
pub fn places(&self) -> &[(Place, String)] {
&self.places
}
/// Select this row once the next listing arrives.
pub fn select_after_load(&mut self, name: String) {
self.select_after_load = Some(name);
@@ -935,7 +944,7 @@ impl FilePane {
title: title.into(),
path: path.into(),
depth,
home: false,
place: None,
side,
}),
),
@@ -947,7 +956,7 @@ impl FilePane {
title: place.title(),
path: path.clone().into(),
depth: 0,
home: *place == Place::Home,
place: Some(*place),
side,
}),
),
@@ -969,14 +978,21 @@ impl FilePane {
) {
let id = self.begin_load(intent, cx);
self.load_task = Some(cx.spawn_in(window, async move |this, cx| {
let result = cx
let (result, places) = cx
.background_spawn(async move {
provider
let result = provider
.list(&PathBuf::from(path))
.map_err(|e| t!("explorer.list.read_failed", error = e).to_string())
.map_err(|e| t!("explorer.list.read_failed", error = e).to_string());
let places = provider
.places()
.into_iter()
.map(|(place, path)| (place, path.to_string_lossy().into_owned()))
.collect();
(result, places)
})
.await;
let _ = this.update_in(cx, |this, window, cx| {
this.places = places;
this.apply_listing(id, result, window, cx)
});
}));
+61 -2
View File
@@ -693,6 +693,18 @@ pub enum Place {
Desktop,
Documents,
Downloads,
/// A Windows drive by its letter, as WinSCP lists them: `C: 本地磁盘`.
Drive(char, DriveKind),
}
/// What a Windows drive is, which its title says.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DriveKind {
Local,
Removable,
Network,
Optical,
Other,
}
impl Place {
@@ -702,6 +714,16 @@ impl Place {
Self::Desktop => t!("sftp.place.desktop"),
Self::Documents => t!("sftp.place.documents"),
Self::Downloads => t!("sftp.place.downloads"),
Self::Drive(letter, kind) => {
let drive = format!("{letter}:");
match kind {
DriveKind::Local => t!("sftp.place.drive_local", drive = drive),
DriveKind::Removable => t!("sftp.place.drive_removable", drive = drive),
DriveKind::Network => t!("sftp.place.drive_network", drive = drive),
DriveKind::Optical => t!("sftp.place.drive_optical", drive = drive),
DriveKind::Other => drive.into(),
}
}
}
}
}
@@ -710,8 +732,9 @@ impl Place {
pub trait LocalDirectoryProvider: Send + Sync + 'static {
fn home(&self) -> PathBuf;
fn list(&self, path: &Path) -> Result<DirectoryListing>;
/// Well-known folders for the 目录列表 select, home first. Looked up
/// from the platform, without touching the file system.
/// Well-known folders for the 目录列表 select, home first, then the
/// drives on Windows. Read again with each listing, on the same
/// background executor, so a drive plugged in since shows up.
fn places(&self) -> Vec<(Place, PathBuf)> {
Vec::new()
}
@@ -746,6 +769,41 @@ pub trait LocalDirectoryProvider: Send + Sync + 'static {
) -> Result<FileStamp>;
}
pub type SharedLocalDirectoryProvider = std::sync::Arc<dyn LocalDirectoryProvider>;
/// Every drive letter in use, `A:\` to `Z:\`: without them the local pane
/// could not leave the drive it started on.
#[cfg(windows)]
fn drives() -> Vec<(Place, PathBuf)> {
use windows_sys::Win32::{
Storage::FileSystem::{GetDriveTypeW, GetLogicalDrives},
System::WindowsProgramming::{
DRIVE_CDROM, DRIVE_FIXED, DRIVE_RAMDISK, DRIVE_REMOTE, DRIVE_REMOVABLE,
},
};
// SAFETY: takes nothing and returns a bit mask, bit 0 for `A:`.
let letters = unsafe { GetLogicalDrives() };
(b'A'..=b'Z')
.filter(|letter| letters & (1 << (letter - b'A')) != 0)
.map(|letter| {
let root = format!("{}:\\", char::from(letter));
let wide: Vec<u16> = root.encode_utf16().chain([0]).collect();
// SAFETY: `wide` is a null-terminated UTF-16 string that outlives
// the call.
let kind = match unsafe { GetDriveTypeW(wide.as_ptr()) } {
DRIVE_FIXED | DRIVE_RAMDISK => DriveKind::Local,
DRIVE_REMOVABLE => DriveKind::Removable,
DRIVE_REMOTE => DriveKind::Network,
DRIVE_CDROM => DriveKind::Optical,
_ => DriveKind::Other,
};
(Place::Drive(char::from(letter), kind), PathBuf::from(root))
})
.collect()
}
#[cfg(not(windows))]
fn drives() -> Vec<(Place, PathBuf)> {
Vec::new()
}
#[derive(Default)]
pub struct SystemLocalDirectoryProvider;
impl LocalDirectoryProvider for SystemLocalDirectoryProvider {
@@ -761,6 +819,7 @@ impl LocalDirectoryProvider for SystemLocalDirectoryProvider {
]
.into_iter()
.filter_map(|(place, path)| Some((place, path?)))
.chain(drives())
.collect()
}
fn list(&self, path: &Path) -> Result<DirectoryListing> {
+35
View File
@@ -926,6 +926,41 @@ fn paths_and_journals_reject_unsafe_identity() {
});
}
/// Drives are titled as WinSCP does: the letter, then what kind it is.
#[test]
fn drives_are_titled_by_letter_and_kind() {
assert_eq!(Place::Drive('C', DriveKind::Local).title(), "C: 本地磁盘");
assert_eq!(
Place::Drive('E', DriveKind::Removable).title(),
"E: 可移动磁盘"
);
assert_eq!(
Place::Drive('Z', DriveKind::Network).title(),
"Z: 网络驱动器"
);
assert_eq!(
Place::Drive('F', DriveKind::Optical).title(),
"F: CD 驱动器"
);
assert_eq!(Place::Drive('G', DriveKind::Other).title(), "G:");
}
/// Without the drives, the local pane could not leave the one it started on.
#[cfg(windows)]
#[test]
fn local_listing_places_include_the_system_drive() {
let system = std::env::var("SystemDrive").unwrap();
let letter = system.chars().next().unwrap().to_ascii_uppercase();
let places = SystemLocalDirectoryProvider.places();
assert!(
places.contains(&(
Place::Drive(letter, DriveKind::Local),
std::path::PathBuf::from(format!("{letter}:\\"))
)),
"{places:?}"
);
}
/// On Windows std canonicalizes to `\\?\C:\…`, which the pane showed as is.
#[test]
fn local_listing_reports_the_path_people_type() {
+177
View File
@@ -1271,6 +1271,50 @@ async fn sftp_tab_reconnects_from_its_tab_bar_and_reports_at_the_bottom_left(
cx.update(|cx| assert_eq!(workspace.read(cx).explorers_of(HostId(DB_01), cx).len(), 2));
}
/// The 目录列表 select's places, Windows drives among them, are read again
/// with each local listing: a drive plugged in shows up on the next refresh.
#[gpui_kit::test]
async fn local_places_are_read_again_with_each_listing(cx: &mut TestAppContext) {
use shellrs::app::{ExplorerAction, ExplorerCommand};
use shellrs::sftp::{DriveKind, Place};
let local = FakeLocalDirectory::default();
let system = (Place::Drive('C', DriveKind::Local), "/c".to_string());
local
.places
.lock()
.unwrap()
.push((system.0, system.1.clone().into()));
let (handle, workspace) =
open_workspace_with_services(cx, Arc::new(FakeSftpProvider::default()), local.clone());
open_test_explorer(cx, handle).await;
let places = |cx: &mut TestAppContext| {
cx.update(|cx| {
let explorer = workspace.read(cx).explorer(ExplorerId(SFTP_TAB)).unwrap();
explorer.read(cx).local().read(cx).places().to_vec()
})
};
assert_eq!(places(cx), std::slice::from_ref(&system));
let stick = (Place::Drive('E', DriveKind::Removable), "/e".to_string());
local
.places
.lock()
.unwrap()
.push((stick.0, stick.1.clone().into()));
cx.update_window(handle.into(), |_, window, cx| {
window.dispatch_action(
Box::new(ExplorerAction::new(
ExplorerId(SFTP_TAB),
ExplorerCommand::Refresh { remote: false },
)),
cx,
);
})
.unwrap();
cx.run_until_parked();
assert_eq!(places(cx), [system, stick]);
}
#[gpui_kit::test]
async fn sftp_file_commands_confirm_validate_and_send_one_operation(cx: &mut TestAppContext) {
use shellrs::app::{ExplorerAction, ExplorerCommand};
@@ -1514,6 +1558,139 @@ async fn sftp_dragging_outside_the_names_selects_the_rows_crossed(cx: &mut TestA
cx.update(|cx| assert_eq!(pane_selection(&workspace, true, cx), ["目录", "链接目录"]));
}
/// A click on a column title sorts by the column, as one on its arrow does:
/// descending, ascending, then back to by name. The order outlives a
/// refresh, after which the next click carries on from it.
#[gpui_kit::test]
async fn sftp_clicking_a_column_title_sorts_by_it(cx: &mut TestAppContext) {
use shellrs::app::{ExplorerAction, ExplorerCommand};
let provider = Arc::new(FakeSftpProvider::default());
let (handle, workspace) = open_workspace_with_sftp(cx, provider);
open_test_explorer(cx, handle).await;
let pane = ("local-pane", SFTP_TAB);
let names = |cx: &mut TestAppContext| {
cx.run_until_parked();
cx.update(|cx| {
let explorer = workspace.read(cx).explorer(ExplorerId(SFTP_TAB)).unwrap();
let entries = explorer.read(cx).local().read(cx).entries(cx);
entries
.into_iter()
.map(|entry| entry.name.to_string())
.collect::<Vec<_>>()
})
};
let click_size = |cx: &mut TestAppContext| {
cx.update_window(handle.into(), |_, window, cx| {
window.render_frame(cx);
window.within(pane).click("column:size", cx);
})
.unwrap();
};
let by_name = ["..", "目录", "链接目录", "文件 乙.txt", "文件 甲.txt"];
assert_eq!(names(cx), by_name);
// Folders stay ahead of files whichever way.
click_size(cx);
let descending = ["..", "链接目录", "目录", "文件 乙.txt", "文件 甲.txt"];
assert_eq!(names(cx), descending);
cx.update_window(handle.into(), |_, window, cx| {
window.dispatch_action(
Box::new(ExplorerAction::new(
ExplorerId(SFTP_TAB),
ExplorerCommand::Refresh { remote: false },
)),
cx,
);
})
.unwrap();
assert_eq!(names(cx), descending);
click_size(cx);
assert_eq!(
names(cx),
["..", "目录", "链接目录", "文件 甲.txt", "文件 乙.txt"]
);
click_size(cx);
assert_eq!(names(cx), by_name);
}
/// A column dragged wider stays so with the next listing, which gives the
/// table its columns again.
#[gpui_kit::test]
async fn sftp_column_widths_outlive_a_refresh(cx: &mut TestAppContext) {
use gpui_kit::{Modifiers, MouseDownEvent, MouseUpEvent};
use shellrs::app::{ExplorerAction, ExplorerCommand};
let provider = Arc::new(FakeSftpProvider::default());
let (handle, _workspace) = open_workspace_with_sftp(cx, provider);
open_test_explorer(cx, handle).await;
let pane = ("local-pane", SFTP_TAB);
let width = |cx: &mut TestAppContext| {
cx.run_until_parked();
cx.update_window(handle.into(), |_, window, cx| {
window.render_frame(cx);
window
.within(pane)
.find(("col-header", 1usize))
.bounds()
.size
.width
})
.unwrap()
};
let before = width(cx);
// Drag the boundary right of 大小 by 60 pixels.
cx.update_window(handle.into(), |_, window, cx| {
window.render_frame(cx);
let bounds = window.within(pane).find(("col-header", 1usize)).bounds();
let start = point(bounds.right() - px(1.), bounds.center().y);
let event = |x: f32| MouseMoveEvent {
position: point(start.x + px(x), start.y),
pressed_button: Some(MouseButton::Left),
modifiers: Modifiers::default(),
};
window.dispatch_event(
MouseDownEvent {
button: MouseButton::Left,
position: start,
modifiers: Modifiers::default(),
click_count: 1,
first_mouse: false,
}
.to_platform_input(),
cx,
);
for x in [10., 30., 60.] {
window.dispatch_event(event(x).to_platform_input(), cx);
window.render_frame(cx);
}
window.dispatch_event(
MouseUpEvent {
button: MouseButton::Left,
position: point(start.x + px(60.), start.y),
modifiers: Modifiers::default(),
click_count: 1,
}
.to_platform_input(),
cx,
);
})
.unwrap();
let dragged = width(cx);
assert!(dragged > before + px(40.), "{before:?} -> {dragged:?}");
cx.update_window(handle.into(), |_, window, cx| {
window.dispatch_action(
Box::new(ExplorerAction::new(
ExplorerId(SFTP_TAB),
ExplorerCommand::Refresh { remote: false },
)),
cx,
);
})
.unwrap();
assert_eq!(width(cx), dragged);
}
/// As in WinSCP without full row select, only the name cell is the item: a
/// click on the rest of a row, or below the rows, is a click on empty space
/// and clears the selection. A ⌘ click there, or a click on a column title,
+5
View File
@@ -271,6 +271,8 @@ pub struct FakeLocalDirectory {
pub calls: Arc<Mutex<Vec<String>>>,
/// The files the editor reads and writes, in memory.
pub files: Arc<Mutex<std::collections::BTreeMap<std::path::PathBuf, Vec<u8>>>>,
/// The places it offers, such as a drive plugged in.
pub places: Arc<Mutex<Vec<(shellrs::sftp::Place, std::path::PathBuf)>>>,
}
impl FakeLocalDirectory {
@@ -287,6 +289,9 @@ impl LocalDirectoryProvider for FakeLocalDirectory {
fn list(&self, path: &std::path::Path) -> anyhow::Result<DirectoryListing> {
Ok(fake_listing(path.to_str().unwrap()))
}
fn places(&self) -> Vec<(shellrs::sftp::Place, std::path::PathBuf)> {
self.places.lock().unwrap().clone()
}
fn trash(&self, paths: &[std::path::PathBuf]) -> anyhow::Result<()> {
self.record(format!("trash {paths:?}"))
}