6 "github.com/zyedidia/tcell"
10 // This contains all the views in this tab
11 // There is generally only one view per tab, but you can have
12 // multiple views with splits
14 // This is the current view for this tab
20 // NewTabFromView creates a new tab and puts the given view in the tab
21 func NewTabFromView(v *View) *Tab {
23 t.views = append(t.views, v)
26 t.tree = new(SplitTree)
27 t.tree.kind = VerticalSplit
28 t.tree.children = []Node{NewLeafNode(t.views[0], t.tree)}
34 if globalSettings["infobar"].(bool) {
43 // SetNum sets all this tab's views to have the correct tab number
44 func (t *Tab) SetNum(num int) {
46 for _, v := range t.views {
51 func (t *Tab) Cleanup() {
55 func (t *Tab) Resize() {
60 if globalSettings["infobar"].(bool) {
66 for i, v := range t.views {
71 // CurView returns the current view
72 func CurView() *View {
73 curTab := tabs[curTab]
74 return curTab.views[curTab.CurView]
77 // TabbarString returns the string that should be displayed in the tabbar
78 // It also returns a map containing which indicies correspond to which tab number
79 // This is useful when we know that the mouse click has occurred at an x location
80 // but need to know which tab that corresponds to to accurately change the tab
81 func TabbarString() (string, map[int]int) {
83 indicies := make(map[int]int)
84 for i, t := range tabs {
90 str += t.views[t.CurView].Buf.GetName()
96 indicies[len(str)-1] = i + 1
102 // TabbarHandleMouseEvent checks the given mouse event if it is clicking on the tabbar
103 // If it is it changes the current tab accordingly
104 // This function returns true if the tab is changed
105 func TabbarHandleMouseEvent(event tcell.Event) bool {
106 // There is no tabbar displayed if there are less than 2 tabs
111 switch e := event.(type) {
112 case *tcell.EventMouse:
113 button := e.Buttons()
114 // Must be a left click
115 if button == tcell.Button1 {
120 str, indicies := TabbarString()
126 for k := range indicies {
127 keys = append(keys, k)
130 for _, k := range keys {
132 tabnum = indicies[k] - 1
144 // DisplayTabs displays the tabbar at the top of the editor if there are multiple tabs
150 str, _ := TabbarString()
152 tabBarStyle := defStyle.Reverse(true)
153 if style, ok := colorscheme["tabbar"]; ok {
157 // Maybe there is a unicode filename?
158 fileRunes := []rune(str)
159 w, _ := screen.Size()
160 for x := 0; x < w; x++ {
161 if x < len(fileRunes) {
162 screen.SetContent(x, 0, fileRunes[x], nil, tabBarStyle)
164 screen.SetContent(x, 0, ' ', nil, tabBarStyle)