Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
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/layout" |
||
8 | "fyne.io/fyne/v2/widget" |
||
9 | "github.com/rchargel/hdfs-explorer/log" |
||
10 | ) |
||
11 | |||
12 | func ShowFatalError(err error) { |
||
13 | errorDialog := dialog.NewError(err, Window) |
||
14 | errorDialog.SetOnClosed(func() { |
||
15 | log.Error.Fatal(err) |
||
16 | }) |
||
17 | errorDialog.Show() |
||
18 | } |
||
19 | |||
20 | func ShowConfirm(title, text string, callback func()) { |
||
21 | dialog.NewConfirm( |
||
22 | title, |
||
23 | text, |
||
24 | func(b bool) { |
||
25 | if b { |
||
26 | callback() |
||
27 | } |
||
28 | }, |
||
29 | Window, |
||
30 | ).Show() |
||
31 | } |
||
32 | |||
33 | func NewCustomDialog(title string, content fyne.CanvasObject, buttons ...*widget.Button) *widget.PopUp { |
||
34 | var modal *widget.PopUp |
||
35 | |||
36 | closeButton := widget.NewButton( |
||
37 | "Close", |
||
38 | func() { modal.Hide() }, |
||
39 | ) |
||
40 | buttonList := make([]fyne.CanvasObject, len(buttons)+2) |
||
41 | buttonList[0] = layout.NewSpacer() |
||
42 | buttonList[1] = closeButton |
||
43 | idx := 2 |
||
44 | for _, button := range buttons { |
||
45 | buttonList[idx] = button |
||
46 | idx++ |
||
47 | } |
||
48 | buttonPanel := container.NewHBox(buttonList...) |
||
49 | container := container.NewBorder( |
||
50 | widget.NewLabel(title), |
||
51 | buttonPanel, |
||
52 | nil, |
||
53 | nil, |
||
54 | content, |
||
55 | ) |
||
56 | modal = widget.NewModalPopUp(container, Window.Canvas()) |
||
57 | return modal |
||
58 | } |
||
59 |