Passed
Push — main ( b4871f...e0c3cc )
by Rafael
01:19
created

ui.ShowCustomDialog   A

Complexity

Conditions 3

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
dl 0
loc 24
rs 9.4
c 0
b 0
f 0
nop 3
1
package ui
2
3
import (
4
	"fyne.io/fyne/v2"
5
	"fyne.io/fyne/v2/container"
6
	"fyne.io/fyne/v2/dialog"
7
	"fyne.io/fyne/v2/widget"
8
	"github.com/rchargel/hdfs-explorer/log"
9
)
10
11
func ShowFatalError(err error) {
12
	errorDialog := dialog.NewError(err, Window)
13
	errorDialog.SetOnClosed(func() {
14
		log.Error.Fatal(err)
15
	})
16
	errorDialog.Show()
17
}
18
19
func ShowConfirm(title, text string, callback func()) {
20
	dialog.NewConfirm(
21
		title,
22
		text,
23
		func(b bool) {
24
			if b {
25
				callback()
26
			}
27
		},
28
		Window,
29
	).Show()
30
}
31
32
func ShowCustomDialog(title string, content fyne.CanvasObject, buttons ...*widget.Button) {
33
	var modal *widget.PopUp
34
35
	closeButton := widget.NewButton(
36
		"Close",
37
		func() { modal.Hide() },
38
	)
39
	buttonList := make([]fyne.CanvasObject, len(buttons)+1)
40
	buttonList[0] = closeButton
41
	idx := 1
42
	for _, button := range buttons {
43
		buttonList[idx] = button
44
		idx++
45
	}
46
	buttonPanel := container.NewHBox(buttonList...)
47
	container := container.NewBorder(
48
		widget.NewLabel(title),
49
		buttonPanel,
50
		nil,
51
		nil,
52
		content,
53
	)
54
	modal = widget.NewModalPopUp(container, Window.Canvas())
55
	modal.Show()
56
}
57