Add archive-as-folder navigation and extraction copy flow
This commit is contained in:
parent
780150500d
commit
6a518896b8
4 changed files with 298 additions and 1 deletions
|
|
@ -437,6 +437,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
|
||||
switch {
|
||||
case key.Matches(msg, m.keys.Quit):
|
||||
m.cleanupArchiveMounts()
|
||||
return m, tea.Quit
|
||||
case key.Matches(msg, m.keys.Help):
|
||||
m.openHelpModal()
|
||||
|
|
@ -800,6 +801,14 @@ func (m *Model) handleOpenSelected() (tea.Model, tea.Cmd) {
|
|||
return m, m.loadPreviewCmd()
|
||||
}
|
||||
|
||||
if isArchiveEntry(selected) {
|
||||
if err := m.enterArchive(selected); err != nil {
|
||||
m.status = err.Error()
|
||||
return m, nil
|
||||
}
|
||||
return m, m.loadPreviewCmd()
|
||||
}
|
||||
|
||||
if isEditableEntry(selected) {
|
||||
return m.handleEdit()
|
||||
}
|
||||
|
|
@ -809,6 +818,19 @@ func (m *Model) handleOpenSelected() (tea.Model, tea.Cmd) {
|
|||
func (m *Model) goParent() error {
|
||||
m.hover = hoverState{}
|
||||
pane := m.activePane()
|
||||
|
||||
if mount, ok := pane.CurrentArchive(); ok && pane.Path == mount.RootPath {
|
||||
if _, popped := pane.PopArchive(); popped {
|
||||
_ = os.RemoveAll(mount.TempDir)
|
||||
}
|
||||
pane.Path = mount.ParentPath
|
||||
if err := m.reloadPane(pane.ID, filepath.Base(mount.SourcePath)); err != nil {
|
||||
return err
|
||||
}
|
||||
m.status = fmt.Sprintf("Closed archive %s", filepath.Base(mount.SourcePath))
|
||||
return nil
|
||||
}
|
||||
|
||||
parent := filepath.Dir(pane.Path)
|
||||
if parent == pane.Path {
|
||||
return nil
|
||||
|
|
@ -878,6 +900,11 @@ func (m *Model) handleDirSize() (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m *Model) handleTransfer(kind fileOpKind) (tea.Model, tea.Cmd) {
|
||||
if m.activePane().InArchive() && kind != opCopy {
|
||||
m.status = "Archive mode is read-only; only copy is allowed"
|
||||
return m, nil
|
||||
}
|
||||
|
||||
sources := m.operationSources()
|
||||
if len(sources) == 0 {
|
||||
m.status = fmt.Sprintf("Nothing to %s", operationVerb(kind))
|
||||
|
|
@ -916,6 +943,11 @@ func (m *Model) handleTransfer(kind fileOpKind) (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m *Model) handleDelete() (tea.Model, tea.Cmd) {
|
||||
if m.activePane().InArchive() {
|
||||
m.status = "Archive mode is read-only; delete is disabled"
|
||||
return m, nil
|
||||
}
|
||||
|
||||
sources := m.operationSources()
|
||||
if len(sources) == 0 {
|
||||
m.status = "Nothing to delete"
|
||||
|
|
@ -1181,6 +1213,11 @@ func (m *Model) cycleSort() (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m *Model) openMkdirModal() {
|
||||
if m.activePane().InArchive() {
|
||||
m.status = "Archive mode is read-only; create directory is disabled"
|
||||
return
|
||||
}
|
||||
|
||||
input := textinput.New()
|
||||
input.Placeholder = "new-directory"
|
||||
input.Focus()
|
||||
|
|
@ -1197,6 +1234,11 @@ func (m *Model) openMkdirModal() {
|
|||
}
|
||||
|
||||
func (m *Model) openRenameModal() {
|
||||
if m.activePane().InArchive() {
|
||||
m.status = "Archive mode is read-only; rename is disabled"
|
||||
return
|
||||
}
|
||||
|
||||
selected, ok := m.activePane().Selected()
|
||||
if !ok || selected.IsParent {
|
||||
m.status = "Select an entry to rename"
|
||||
|
|
@ -2225,6 +2267,36 @@ func copyPlanCmd(kind fileOpKind, sourcePaths []string, targetDir string, overwr
|
|||
}
|
||||
}
|
||||
|
||||
func (m *Model) enterArchive(selected vfs.Entry) error {
|
||||
pane := m.activePane()
|
||||
tempDir, err := vfs.ExtractArchiveToTemp(selected.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pane.PushArchive(ArchiveMount{
|
||||
SourcePath: selected.Path,
|
||||
ParentPath: pane.Path,
|
||||
RootPath: tempDir,
|
||||
TempDir: tempDir,
|
||||
})
|
||||
pane.Path = tempDir
|
||||
if err := m.reloadPane(pane.ID, ""); err != nil {
|
||||
_ = os.RemoveAll(tempDir)
|
||||
_, _ = pane.PopArchive()
|
||||
return err
|
||||
}
|
||||
m.status = fmt.Sprintf("Opened archive %s", selected.DisplayName())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Model) cleanupArchiveMounts() {
|
||||
for _, pane := range []*BrowserPane{&m.left, &m.right} {
|
||||
for _, mount := range pane.ClearArchives() {
|
||||
_ = os.RemoveAll(mount.TempDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func deletePlanCmd(sourcePaths []string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
stats := vfs.TransferStats{}
|
||||
|
|
@ -2630,6 +2702,10 @@ func isEditableEntry(entry vfs.Entry) bool {
|
|||
}
|
||||
}
|
||||
|
||||
func isArchiveEntry(entry vfs.Entry) bool {
|
||||
return !entry.IsDir && !entry.IsParent && entry.Category() == "archive"
|
||||
}
|
||||
|
||||
func (m *Model) hoverIndexFor(pane PaneID) int {
|
||||
if m.hover.ok && m.hover.pane == pane {
|
||||
return m.hover.index
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
|
@ -25,6 +26,14 @@ type BrowserPane struct {
|
|||
Cursor int
|
||||
Offset int
|
||||
Marked map[string]struct{}
|
||||
Archive []ArchiveMount
|
||||
}
|
||||
|
||||
type ArchiveMount struct {
|
||||
SourcePath string
|
||||
ParentPath string
|
||||
RootPath string
|
||||
TempDir string
|
||||
}
|
||||
|
||||
func (p *BrowserPane) Selected() (vfs.Entry, bool) {
|
||||
|
|
@ -171,6 +180,59 @@ func (p *BrowserPane) EnsureVisible(pageSize int) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *BrowserPane) InArchive() bool {
|
||||
return len(p.Archive) > 0
|
||||
}
|
||||
|
||||
func (p *BrowserPane) PushArchive(mount ArchiveMount) {
|
||||
p.Archive = append(p.Archive, mount)
|
||||
}
|
||||
|
||||
func (p *BrowserPane) PopArchive() (ArchiveMount, bool) {
|
||||
if len(p.Archive) == 0 {
|
||||
return ArchiveMount{}, false
|
||||
}
|
||||
last := p.Archive[len(p.Archive)-1]
|
||||
p.Archive = p.Archive[:len(p.Archive)-1]
|
||||
return last, true
|
||||
}
|
||||
|
||||
func (p *BrowserPane) CurrentArchive() (ArchiveMount, bool) {
|
||||
if len(p.Archive) == 0 {
|
||||
return ArchiveMount{}, false
|
||||
}
|
||||
return p.Archive[len(p.Archive)-1], true
|
||||
}
|
||||
|
||||
func (p *BrowserPane) ClearArchives() []ArchiveMount {
|
||||
if len(p.Archive) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]ArchiveMount, len(p.Archive))
|
||||
copy(out, p.Archive)
|
||||
p.Archive = nil
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *BrowserPane) DisplayPath() string {
|
||||
if len(p.Archive) == 0 {
|
||||
return p.Path
|
||||
}
|
||||
top := p.Archive[len(p.Archive)-1]
|
||||
rel, err := filepath.Rel(top.RootPath, p.Path)
|
||||
if err != nil {
|
||||
return p.Path
|
||||
}
|
||||
rel = filepath.ToSlash(rel)
|
||||
if rel == "." {
|
||||
rel = ""
|
||||
}
|
||||
if rel == "" {
|
||||
return top.SourcePath + "::"
|
||||
}
|
||||
return top.SourcePath + "::/" + rel
|
||||
}
|
||||
|
||||
func renderPane(
|
||||
pane BrowserPane,
|
||||
cfg config.Config,
|
||||
|
|
@ -229,7 +291,7 @@ func renderPaneHeader(pane BrowserPane, cfg config.Config, palette theme.Palette
|
|||
return lipgloss.NewStyle().
|
||||
Width(width).
|
||||
Background(headerBg).
|
||||
Render(pathStyle.Render(truncateMiddle(compactPath(pane.Path, cfg.UI.PathDisplay), pathWidth)))
|
||||
Render(pathStyle.Render(truncateMiddle(compactPath(pane.DisplayPath(), cfg.UI.PathDisplay), pathWidth)))
|
||||
}
|
||||
|
||||
func renderColumnsHeader(cfg config.Config, width int, palette theme.Palette, background lipgloss.Color, useNerdIcons bool) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue