summaryrefslogtreecommitdiffstats
path: root/tui/mouse.go
blob: 75f8f1d0e88611383c8f59a19015cabc072062d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tui

import (
	"github.com/dundee/gdu/v5/pkg/fs"
	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

func (ui *UI) onMouse(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) {
	if event == nil {
		return nil, action
	}

	if ui.pages.HasPage("confirm") ||
		ui.pages.HasPage("progress") ||
		ui.pages.HasPage("deleting") ||
		ui.pages.HasPage("emptying") ||
		ui.pages.HasPage("help") {
		return nil, action
	}

	// nolint: exhaustive // Why: we don't need to handle all mouse events
	switch action {
	case tview.MouseLeftDoubleClick:
		row, column := ui.table.GetSelection()
		if ui.currentDirPath != ui.topDirPath && row == 0 {
			ui.handleLeft()
		} else {
			selectedFile := ui.table.GetCell(row, column).GetReference().(fs.Item)
			if selectedFile.IsDir() {
				ui.handleRight()
			} else {
				ui.showFile()
			}
		}
		return nil, action
	case tview.MouseScrollUp, tview.MouseScrollDown:
		row, column := ui.table.GetSelection()
		if action == tview.MouseScrollUp && row > 0 {
			row--
		} else if action == tview.MouseScrollDown && row+1 < ui.table.GetRowCount() {
			row++
		}
		ui.table.Select(row, column)
		return nil, action
	}

	return event, action
}