Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/en/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -1456,9 +1456,11 @@ panel goes to the folder it was in.
### Upload and download

Upload: drag files or folders from Explorer or Finder onto the file table
(they go to the current folder) or onto a folder in the folder tree. The
toolbar's upload button and the context menu can also choose files or a
folder.
(they go to the current folder) or onto a folder in the folder tree. To
upload from the clipboard, copy files or folders in your system's file
manager, click the remote file table, and press Cmd+V on macOS or Ctrl+V
on Windows and Linux. The files go to the current remote folder. The
toolbar's upload button and the context menu can also choose files or a folder.

Download: select files or folders and click the download button. They are
saved in the download folder, which is the system's Downloads folder
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ shell 的工作目录变了,比如执行 `cd /var/log` 之后,文件面板

### 上传和下载

上传:把文件或文件夹从资源管理器 / Finder 拖到文件表格(传到当前目录)或目录树的某个文件夹上。也可以用工具栏的上传按钮或右键菜单选文件、选文件夹。
上传:把文件或文件夹从资源管理器 / Finder 拖到文件表格(传到当前目录)或目录树的某个文件夹上。也可以先在系统文件管理器复制文件或文件夹,再点击远程文件表格,按 Cmd+V(macOS)或 Ctrl+V(Windows 和 Linux)上传到当前远程目录。也可以用工具栏的上传按钮或右键菜单选文件、选文件夹。

下载:选中文件或文件夹,点下载按钮。存到下载目录,默认是系统的“下载”文件夹(`~/Downloads`),可以在选项的“传输”页修改。右键菜单的“下载到…”自己选位置。“传输”页勾选“每次下载时询问保存位置”后,下载按钮每次都先用系统的选择文件夹对话框问保存位置。

Expand Down
141 changes: 141 additions & 0 deletions internal/app/filepaste_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package app

import (
"os"
"path/filepath"
"runtime"
"testing"

"finallyshell/locales"

"github.com/egoist/mygo/plugins/terminal"
"github.com/egoist/mygo/transfer"
"github.com/egoist/mygo/ui"
)

func TestPasteUploadFocus(t *testing.T) {
a, p := testApp(t)
s := demoSession(a, "files", "127.0.0.1")
a.active = 0
s.sftp = localSFTP(t)
remote, local := t.TempDir(), t.TempDir()
s.files.cwd, s.files.pathEdit, s.files.entries = remote, remote, nil

conn := &keyConn{done: make(chan struct{})}
defer close(conn.done)
opts := a.terminalOptions(s.Host)
opts.Conn = conn
term, err := terminal.New(opts)
if err != nil {
t.Fatal(err)
}
defer term.Close()
s.setTerm(term)

report := filepath.Join(local, "report #1.txt")
folder := filepath.Join(local, "photos")
if err := os.WriteFile(report, []byte("report"), 0o600); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(folder, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(folder, "a.txt"), []byte("photo"), 0o600); err != nil {
t.Fatal(err)
}

tt := ui.NewTester(a.View, 1280, 820)
p.tt = tt
paste := func() { tt.Key(ui.Cmd, ui.KeyV) }
box, ok := tt.Find(locales.ColName())
if !ok {
t.Fatal("file table is missing")
}
focusTable := func() { tt.ClickAt(box.X+40, box.Y+100) }

files, err := transfer.FileData(report, folder)
if err != nil {
t.Fatal(err)
}
payload, err := files.Read(transfer.FileList)
if err != nil {
t.Fatal(err)
}
var read bool
offer := func(format transfer.Format, text string) {
read = false
tt.SetClipboardData(transfer.New(transfer.NewItem(
transfer.Lazy(format, func() ([]byte, error) {
read = true
return payload, nil
}),
transfer.Bytes(transfer.Text, []byte(text)),
)))
}

// A clipboard with both representations must follow the focused control.
offer(transfer.FileList, "echo pasted")
up, ok := tt.Find(locales.ParentFolder())
if !ok {
t.Fatal("parent folder button is missing")
}
tt.ClickAt(up.X-24, up.Y+up.H/2) // the path field is left of the button
tt.Key(ui.Cmd, ui.KeyA)
paste()
if read || s.files.pathEdit != "echo pasted" {
t.Fatalf("path field pasted %q, file clipboard read: %v", s.files.pathEdit, read)
}

tt.ClickAt(760, 260)
conn.sent(t, term)
terminalPaste := a.shortcut(scPaste)
tt.Key(terminalPaste.Mods, terminalPaste.Key)
if got := conn.sent(t, term); read || got != "echo pasted" {
t.Fatalf("terminal pasted %q, file clipboard read: %v", got, read)
}
if ui.Cmd == ui.Ctrl {
paste()
if got := conn.sent(t, term); read || got != "\x16" {
t.Fatalf("terminal sent %q for Ctrl+V, file clipboard read: %v", got, read)
}
}

focusTable() // the empty body is focusable even with no selected row
tt.SetClipboard(report)
paste()
offer(transfer.FileList, "echo pasted")
tt.KeyRepeat(ui.Cmd, ui.KeyV)
if read {
t.Fatal("key repeat read the file clipboard")
}
paste()
p.until(t, "pasted uploads", func() bool { return len(a.transfers.jobs) == 2 && a.transfers.active() == 0 })
for name, want := range map[string]string{"report #1.txt": "report", "photos/a.txt": "photo"} {
if got, err := os.ReadFile(filepath.Join(remote, name)); err != nil || string(got) != want {
t.Fatalf("uploaded %s: %q, %v", name, got, err)
}
}
p.until(t, "refreshed listing", func() bool { return !s.files.loading && len(s.files.entries) == 2 })

// URI lists also work. On macOS the native Edit menu routes Cmd+V
// through an edit command, so exercise that path as well as key events.
offer(transfer.URIList, "")
if runtime.GOOS == "darwin" {
tt.Command("paste")
} else {
paste()
}
p.until(t, "replace confirmation", func() bool { return a.replace != nil })
question := a.replace
offer(transfer.FileList, "")
paste()
if read || a.replace != question {
t.Fatal("paste escaped the replace dialog")
}
tt.Key(0, ui.KeyEscape)
if a.replace != nil {
t.Fatal("replace dialog did not close")
}
paste()
p.until(t, "replace confirmation after focus returns", func() bool { return a.replace != nil })
}
9 changes: 9 additions & 0 deletions internal/app/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"finallyshell/internal/widgets"
"finallyshell/locales"

"github.com/egoist/mygo/transfer"
"github.com/egoist/mygo/ui"
)

Expand Down Expand Up @@ -362,6 +363,14 @@ func (a *App) fileTable(c *ui.Context, s *Session) {
a.openRemoteFile(s, path.Join(f.cwd, e.Name))
}
}
// Handle file paste only with the table's focus. The terminal and
// text fields keep their own paste behavior.
if s.sftp != nil && f.cwd != "" && f.table.Shortcut(c, ui.Cmd, ui.KeyV) && !c.ShortcutRepeated() {
data := c.Services().ReadClipboardData(transfer.FileList, transfer.URIList)
if files, err := data.Files(); err == nil && len(files) > 0 {
a.upload(s, files, f.cwd)
}
}
// F2 renames the row chosen; Delete, or Cmd+Backspace as in
// Finder, deletes those chosen.
rename := f.table.Shortcut(c, 0, ui.KeyF2)
Expand Down