]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/tab.go
Merge pull request #1201 from Calinou/use-more-ini-highlighting
[micro.git] / cmd / micro / tab.go
index 941e787aac56619ce4e3d9302c1d46b45b31b275..88c260a60c371c2dd9b34ee60a2fe637ea169ebc 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "path/filepath"
        "sort"
 
        "github.com/zyedidia/tcell"
@@ -8,11 +9,13 @@ import (
 
 var tabBarOffset int
 
+// A Tab holds an array of views and a splitTree to determine how the
+// views should be arranged
 type Tab struct {
        // This contains all the views in this tab
        // There is generally only one view per tab, but you can have
        // multiple views with splits
-       views []*View
+       Views []*View
        // This is the current view for this tab
        CurView int
 
@@ -22,12 +25,12 @@ type Tab struct {
 // 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.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)}
+       t.tree.children = []Node{NewLeafNode(t.Views[0], t.tree)}
 
        w, h := screen.Size()
        t.tree.width = w
@@ -36,6 +39,9 @@ func NewTabFromView(v *View) *Tab {
        if globalSettings["infobar"].(bool) {
                t.tree.height--
        }
+       if globalSettings["keymenu"].(bool) {
+               t.tree.height -= 2
+       }
 
        t.Resize()
 
@@ -45,15 +51,18 @@ func NewTabFromView(v *View) *Tab {
 // SetNum sets all this tab's views to have the correct tab number
 func (t *Tab) SetNum(num int) {
        t.tree.tabNum = num
-       for _, v := range t.views {
+       for _, v := range t.Views {
                v.TabNum = num
        }
 }
 
+// Cleanup cleans up the tree (for example if views have closed)
 func (t *Tab) Cleanup() {
        t.tree.Cleanup()
 }
 
+// Resize handles a resize event from the terminal and resizes
+// all child views correctly
 func (t *Tab) Resize() {
        w, h := screen.Size()
        t.tree.width = w
@@ -62,18 +71,24 @@ func (t *Tab) Resize() {
        if globalSettings["infobar"].(bool) {
                t.tree.height--
        }
+       if globalSettings["keymenu"].(bool) {
+               t.tree.height -= 2
+       }
 
        t.tree.ResizeSplits()
 
-       for i, v := range t.views {
+       for i, v := range t.Views {
                v.Num = i
+               if v.Type == vtTerm {
+                       v.term.Resize(v.Width, v.Height)
+               }
        }
 }
 
 // CurView returns the current view
 func CurView() *View {
        curTab := tabs[curTab]
-       return curTab.views[curTab.CurView]
+       return curTab.Views[curTab.CurView]
 }
 
 // TabbarString returns the string that should be displayed in the tabbar
@@ -83,15 +98,27 @@ func CurView() *View {
 func TabbarString() (string, map[int]int) {
        str := ""
        indicies := make(map[int]int)
+       unique := make(map[string]int)
+
+       for _, t := range tabs {
+               unique[filepath.Base(t.Views[t.CurView].Buf.GetName())]++
+       }
+
        for i, t := range tabs {
+               buf := t.Views[t.CurView].Buf
+               name := filepath.Base(buf.GetName())
+
                if i == curTab {
                        str += "["
                } else {
                        str += " "
                }
-               buf := t.views[t.CurView].Buf
-               str += buf.GetName()
-               if buf.IsModified {
+               if unique[name] == 1 {
+                       str += name
+               } else {
+                       str += buf.GetName()
+               }
+               if buf.Modified() {
                        str += " +"
                }
                if i == curTab {
@@ -99,8 +126,9 @@ func TabbarString() (string, map[int]int) {
                } else {
                        str += " "
                }
-               indicies[Count(str)-1] = i + 1
                str += " "
+
+               indicies[Count(str)-2] = i + 1
        }
        return str, indicies
 }