curView int
// Generally this is the name of the current view's buffer
name string
+
+ tree *SplitTree
}
+// NewTabFromView creates a new tab and puts the given view in the tab
func NewTabFromView(v *View) *Tab {
t := new(Tab)
t.views = append(t.views, v)
t.views[0].Num = 0
+
+ t.tree = new(SplitTree)
+ t.tree.kind = VerticalSplit
+ t.tree.children = []Node{NewLeafNode(t.views[0], t.tree)}
+
+ w, h := screen.Size()
+ t.tree.width = w
+ t.tree.height = h - 1
return t
}
+// SetNum sets all this tab's views to have the correct tab number
func (t *Tab) SetNum(num int) {
for _, v := range t.views {
v.TabNum = num
}
}
+func (t *Tab) Cleanup() {
+ t.tree.Cleanup()
+}
+
+func (t *Tab) Resize() {
+ w, h := screen.Size()
+ t.tree.width = w
+ t.tree.height = h - 1
+ t.tree.ResizeSplits()
+}
+
// CurView returns the current view
func CurView() *View {
curTab := tabs[curTab]
return curTab.views[curTab.curView]
}
+// TabbarString returns the string that should be displayed in the tabbar
+// It also returns a map containing which indicies correspond to which tab number
+// This is useful when we know that the mouse click has occured at an x location
+// but need to know which tab that corresponds to to accurately change the tab
func TabbarString() (string, map[int]int) {
str := ""
indicies := make(map[int]int)
- indicies[0] = 0
for i, t := range tabs {
if i == curTab {
str += "["
return str, indicies
}
+// TabbarHandleMouseEvent checks the given mouse event if it is clicking on the tabbar
+// If it is it changes the current tab accordingly
+// This function returns true if the tab is changed
func TabbarHandleMouseEvent(event tcell.Event) bool {
+ // There is no tabbar displayed if there are less than 2 tabs
if len(tabs) <= 1 {
return false
}
switch e := event.(type) {
case *tcell.EventMouse:
button := e.Buttons()
+ // Must be a left click
if button == tcell.Button1 {
x, y := e.Position()
if y != 0 {
return false
}
+// DisplayTabs displays the tabbar at the top of the editor if there are multiple tabs
func DisplayTabs() {
if len(tabs) <= 1 {
return