fork/gdu

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

addielaruefeat: copy path of selected item to clipboard (#645)011b7e8

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