-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
71 lines (58 loc) · 1.26 KB
/
funcs.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"database/sql"
"os"
"path/filepath"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
)
func ToAnyFromInterface[T any](pAny any, pDefault T) T {
var vT T
var vOk bool
vT, vOk = pAny.(T)
if vOk == false {
return pDefault
}
return vT
}
func GetExecutableFileDirName() string {
var vExePath string
var vErr error
vExePath, vErr = os.Executable()
if vErr != nil {
panic(vErr)
}
vExePath, vErr = filepath.EvalSymlinks(vExePath)
if vErr != nil {
panic(vErr)
}
return filepath.Dir(vExePath)
}
func ConfirmDialog(ctx core.Widget, pMsg string, okFunc func(e events.Event)) {
d := core.NewBody("Confirm")
core.NewText(d).SetType(core.TextSupporting).SetText(pMsg)
d.AddBottomBar(func(bar *core.Frame) {
core.NewStretch(bar)
d.AddOK(bar).SetText("Yes").OnClick(okFunc)
d.AddCancel(bar).SetText("No").OnClick(func(e events.Event) {} )
core.NewStretch(bar)
})
d.RunDialog(ctx)
}
func NextId(dbCon *sql.DB) int {
var vSql string
var vRows *sql.Rows
var vErr error
var vInt int
vSql = " select coalesce(max(note_id), 0) + 1 from main.notes "
vRows, vErr = dbCon.Query(vSql)
if vErr != nil {
fmt.Println("Error : ", vErr.Error())
return 0
}
defer vRows.Close()
vRows.Next()
vRows.Scan(&vInt)
return vInt
}