fork/gdu

git clone https://git.julia.blue/fork/gdu

cosmolifeat: move items to XDG trash with D key (#12) (#608)9ca5c60

subvolume
1.6 KiB67 linesraw
1package tui
2
3import (
4	"time"
5
6	"github.com/dundee/gdu/v5/pkg/fs"
7	"github.com/gdamore/tcell/v2"
8	"github.com/rivo/tview"
9)
10
11func (ui *UI) onMouse(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) {
12	if event == nil {
13		return nil, action
14	}
15
16	if ui.pages.HasPage("confirm") ||
17		ui.pages.HasPage("progress") ||
18		ui.pages.HasPage("deleting") ||
19		ui.pages.HasPage("emptying") ||
20		ui.pages.HasPage("moving to trash") ||
21		ui.pages.HasPage("help") {
22		return nil, action
23	}
24
25	// nolint: exhaustive // Why: we don't need to handle all mouse events
26	switch action {
27	case tview.MouseLeftDoubleClick:
28		row, column := ui.table.GetSelection()
29		if ui.currentDirPath != ui.topDirPath && row == 0 {
30			ui.handleLeft()
31		} else {
32			selectedFile := ui.table.GetCell(row, column).GetReference().(fs.Item)
33			if selectedFile.IsDir() {
34				ui.handleRight()
35			} else {
36				if ui.noViewFile {
37					previousHeaderText := ui.header.GetText(false)
38
39					ui.header.SetText(" Viewing files is disabled!")
40
41					go func() {
42						time.Sleep(2 * time.Second)
43						ui.app.QueueUpdateDraw(func() {
44							ui.header.Clear()
45							ui.header.SetText(previousHeaderText)
46						})
47					}()
48
49					return nil, action
50				}
51				ui.showFile()
52			}
53		}
54		return nil, action
55	case tview.MouseScrollUp, tview.MouseScrollDown:
56		row, column := ui.table.GetSelection()
57		if action == tview.MouseScrollUp && row > 0 {
58			row--
59		} else if action == tview.MouseScrollDown && row+1 < ui.table.GetRowCount() {
60			row++
61		}
62		ui.table.Select(row, column)
63		return nil, action
64	}
65
66	return event, action
67}