-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenubar.go
95 lines (82 loc) · 2.25 KB
/
menubar.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package justext
import (
"os"
"strconv"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
)
// MenuBarView : ...
func MenuBarView() *tview.Grid {
fileMenu := tview.NewDropDown().
SetOptions([]string{"File", "Open", "Save", "Save As", "Quit"}, nil).
SetCurrentOption(0)
editMenu := tview.NewDropDown().
SetOptions([]string{"Edit", "Word Count", "Copy", "Paste", "Select All"}, nil).
SetCurrentOption(0)
State.MenuGrid = tview.NewGrid().
SetColumns(-1, -1, -1, -1, -1, -1).
SetBorders(false).
AddItem(fileMenu, 0, 0, 1, 1, 1, 1, true).
AddItem(editMenu, 0, 1, 1, 1, 1, 1, false)
fileMenu.SetSelectedFunc(func(text string, index int) {
switch text {
case "Open":
path, _ := os.Getwd()
table := listDir(path)
runTable(table, State.App)
// form := tview.NewForm().
// AddInputField("File Name", "", 0, nil, nil)
// form.AddButton("Open", func() {
// openFile(form.GetFormItem(0).(*tview.InputField).GetText())
// DisplayEditor()
// })
// State.App.SetRoot(form, true).SetFocus(form)
fileMenu.SetCurrentOption(0)
case "Save":
saveFile()
DisplayEditor()
fileMenu.SetCurrentOption(0)
case "Save As":
form := tview.NewForm().
AddInputField("File Name", "", 0, nil, nil)
form.AddButton("Save", func() {
State.Filename = form.GetFormItem(0).(*tview.InputField).GetText()
saveFile()
DisplayEditor()
})
State.App.SetRoot(form, true).SetFocus(form)
fileMenu.SetCurrentOption(0)
case "Quit":
State.App.Stop()
}
})
editMenu.SetSelectedFunc(func(text string, index int) {
switch text {
case "Word Count":
UpdateStatusBar("Word count: " + strconv.Itoa(WordCount()))
}
})
fileMenu.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEsc {
State.App.SetRoot(State.MainGrid, true)
State.App.SetFocus(State.TextView)
fileMenu.SetCurrentOption(0)
}
if key == tcell.KeyTab {
State.App.SetFocus(editMenu)
fileMenu.SetCurrentOption(0)
}
})
editMenu.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEsc {
State.App.SetRoot(State.MainGrid, true)
State.App.SetFocus(State.TextView)
editMenu.SetCurrentOption(0)
}
if key == tcell.KeyTab {
State.App.SetFocus(fileMenu)
editMenu.SetCurrentOption(0)
}
})
return State.MenuGrid
}