Make tab views array public

Ref #1024
This commit is contained in:
Zachary Yedidia 2018-03-02 19:50:33 -05:00
parent 88d8b0b181
commit cb45481526
8 changed files with 53 additions and 53 deletions

View file

@ -947,7 +947,7 @@ func (v *View) SaveAll(usePlugin bool) bool {
}
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
v.Save(false)
}
}
@ -1804,12 +1804,12 @@ func (v *View) Quit(usePlugin bool) bool {
// Make sure not to quit if there are unsaved changes
if v.CanClose() {
v.CloseBuffer()
if len(tabs[curTab].views) > 1 {
if len(tabs[curTab].Views) > 1 {
v.splitNode.Delete()
tabs[v.TabNum].Cleanup()
tabs[v.TabNum].Resize()
} else if len(tabs) > 1 {
if len(tabs[v.TabNum].views) == 1 {
if len(tabs[v.TabNum].Views) == 1 {
tabs = tabs[:v.TabNum+copy(tabs[v.TabNum:], tabs[v.TabNum+1:])]
for i, t := range tabs {
t.SetNum(i)
@ -1848,7 +1848,7 @@ func (v *View) QuitAll(usePlugin bool) bool {
closeAll := true
for _, tab := range tabs {
for _, v := range tab.views {
for _, v := range tab.Views {
if !v.CanClose() {
closeAll = false
}
@ -1861,7 +1861,7 @@ func (v *View) QuitAll(usePlugin bool) bool {
if shouldQuit {
for _, tab := range tabs {
for _, v := range tab.views {
for _, v := range tab.Views {
v.CloseBuffer()
}
}
@ -1893,7 +1893,7 @@ func (v *View) AddTab(usePlugin bool) bool {
curTab = len(tabs) - 1
if len(tabs) == 2 {
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
v.ToggleTabbar()
}
}
@ -1986,8 +1986,8 @@ func (v *View) Unsplit(usePlugin bool) bool {
}
curView := tabs[curTab].CurView
for i := len(tabs[curTab].views) - 1; i >= 0; i-- {
view := tabs[curTab].views[i]
for i := len(tabs[curTab].Views) - 1; i >= 0; i-- {
view := tabs[curTab].Views[i]
if view != nil && view.Num != curView {
view.Quit(true)
// messenger.Message("Quit ", view.Buf.Path)
@ -2009,7 +2009,7 @@ func (v *View) NextSplit(usePlugin bool) bool {
}
tab := tabs[curTab]
if tab.CurView < len(tab.views)-1 {
if tab.CurView < len(tab.Views)-1 {
tab.CurView++
} else {
tab.CurView = 0
@ -2033,7 +2033,7 @@ func (v *View) PreviousSplit(usePlugin bool) bool {
if tab.CurView > 0 {
tab.CurView--
} else {
tab.CurView = len(tab.views) - 1
tab.CurView = len(tab.Views) - 1
}
if usePlugin {

View file

@ -131,7 +131,7 @@ func NewBuffer(reader io.Reader, size int64, path string) *Buffer {
if path != "" {
for _, tab := range tabs {
for _, view := range tab.views {
for _, view := range tab.Views {
if view.Buf.Path == path {
return view.Buf
}

View file

@ -246,7 +246,7 @@ func Raw(args []string) {
curTab = len(tabs) - 1
if len(tabs) == 2 {
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
v.ToggleTabbar()
}
}
@ -262,7 +262,7 @@ func TabSwitch(args []string) {
found := false
for _, t := range tabs {
v := t.views[t.CurView]
v := t.Views[t.CurView]
if v.Buf.GetName() == args[0] {
curTab = v.TabNum
found = true
@ -293,7 +293,7 @@ func Cd(args []string) {
}
wd, _ := os.Getwd()
for _, tab := range tabs {
for _, view := range tab.views {
for _, view := range tab.Views {
if len(view.Buf.name) == 0 {
continue
}
@ -444,7 +444,7 @@ func NewTab(args []string) {
curTab = len(tabs) - 1
if len(tabs) == 2 {
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
v.ToggleTabbar()
}
}

View file

@ -338,7 +338,7 @@ func (m *Messenger) Prompt(prompt, placeholder, historyType string, completionTy
m.HandleEvent(event, m.history[historyType])
m.Clear()
for _, v := range tabs[curTab].views {
for _, v := range tabs[curTab].Views {
v.Display()
}
DisplayTabs()

View file

@ -236,7 +236,7 @@ func RedrawAll() {
}
}
for _, v := range tabs[curTab].views {
for _, v := range tabs[curTab].Views {
v.Display()
}
DisplayTabs()
@ -268,7 +268,7 @@ func LoadAll() {
InitColorscheme()
for _, tab := range tabs {
for _, v := range tab.views {
for _, v := range tab.Views {
v.Buf.UpdateRules()
}
}
@ -380,7 +380,7 @@ func main() {
tab.SetNum(len(tabs))
tabs = append(tabs, tab)
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
v.Center(false)
}
@ -459,7 +459,7 @@ func main() {
LoadPlugins()
for _, t := range tabs {
for _, v := range t.views {
for _, v := range t.Views {
GlobalPluginCall("onViewOpen", v)
GlobalPluginCall("onBufferOpen", v.Buf)
}
@ -505,7 +505,7 @@ func main() {
case <-updateterm:
continue
case vnum := <-closeterm:
tabs[curTab].views[vnum].CloseTerminal()
tabs[curTab].Views[vnum].CloseTerminal()
case event = <-events:
}
@ -535,7 +535,7 @@ func main() {
if CurView().mouseReleased {
// We loop through each view in the current tab and make sure the current view
// is the one being clicked in
for _, v := range tabs[curTab].views {
for _, v := range tabs[curTab].Views {
if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
tabs[curTab].CurView = v.Num
}
@ -544,9 +544,9 @@ func main() {
} else if e.Buttons() == tcell.WheelUp || e.Buttons() == tcell.WheelDown {
var view *View
x, y := e.Position()
for _, v := range tabs[curTab].views {
for _, v := range tabs[curTab].Views {
if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
view = tabs[curTab].views[v.Num]
view = tabs[curTab].Views[v.Num]
}
}
if view != nil {

View file

@ -320,7 +320,7 @@ func SetOption(option, value string) error {
// LoadSyntaxFiles()
InitColorscheme()
for _, tab := range tabs {
for _, view := range tab.views {
for _, view := range tab.Views {
view.Buf.UpdateRules()
}
}
@ -343,7 +343,7 @@ func SetOption(option, value string) error {
if len(tabs) != 0 {
if _, ok := CurView().Buf.Settings[option]; ok {
for _, tab := range tabs {
for _, view := range tab.views {
for _, view := range tab.Views {
SetLocalOption(option, value, view)
}
}
@ -389,7 +389,7 @@ func SetLocalOption(option, value string, view *View) error {
// If it is being turned off, we have to hash every open buffer
var empty [16]byte
for _, tab := range tabs {
for _, v := range tab.views {
for _, v := range tab.Views {
if !nativeValue.(bool) {
if v.Buf.origHash == empty {
data, err := ioutil.ReadFile(v.Buf.AbsPath)

View file

@ -70,9 +70,9 @@ func (l *LeafNode) VSplit(buf *Buffer, splitIndex int) {
copy(l.parent.children[splitIndex+1:], l.parent.children[splitIndex:])
l.parent.children[splitIndex] = NewLeafNode(newView, l.parent)
tab.views = append(tab.views, nil)
copy(tab.views[splitIndex+1:], tab.views[splitIndex:])
tab.views[splitIndex] = newView
tab.Views = append(tab.Views, nil)
copy(tab.Views[splitIndex+1:], tab.Views[splitIndex:])
tab.Views[splitIndex] = newView
tab.CurView = splitIndex
} else {
@ -94,9 +94,9 @@ func (l *LeafNode) VSplit(buf *Buffer, splitIndex int) {
l.parent.children[search(l.parent.children, l)] = s
l.parent = s
tab.views = append(tab.views, nil)
copy(tab.views[splitIndex+1:], tab.views[splitIndex:])
tab.views[splitIndex] = newView
tab.Views = append(tab.Views, nil)
copy(tab.Views[splitIndex+1:], tab.Views[splitIndex:])
tab.Views[splitIndex] = newView
tab.CurView = splitIndex
}
@ -123,9 +123,9 @@ func (l *LeafNode) HSplit(buf *Buffer, splitIndex int) {
copy(l.parent.children[splitIndex+1:], l.parent.children[splitIndex:])
l.parent.children[splitIndex] = NewLeafNode(newView, l.parent)
tab.views = append(tab.views, nil)
copy(tab.views[splitIndex+1:], tab.views[splitIndex:])
tab.views[splitIndex] = newView
tab.Views = append(tab.Views, nil)
copy(tab.Views[splitIndex+1:], tab.Views[splitIndex:])
tab.Views[splitIndex] = newView
tab.CurView = splitIndex
} else {
@ -139,7 +139,7 @@ func (l *LeafNode) HSplit(buf *Buffer, splitIndex int) {
s.parent = l.parent
newView := NewView(buf)
newView.TabNum = l.parent.tabNum
newView.Num = len(tab.views)
newView.Num = len(tab.Views)
if splitIndex == 1 {
s.children = []Node{l, NewLeafNode(newView, s)}
} else {
@ -148,9 +148,9 @@ func (l *LeafNode) HSplit(buf *Buffer, splitIndex int) {
l.parent.children[search(l.parent.children, l)] = s
l.parent = s
tab.views = append(tab.views, nil)
copy(tab.views[splitIndex+1:], tab.views[splitIndex:])
tab.views[splitIndex] = newView
tab.Views = append(tab.Views, nil)
copy(tab.Views[splitIndex+1:], tab.Views[splitIndex:])
tab.Views[splitIndex] = newView
tab.CurView = splitIndex
}
@ -167,12 +167,12 @@ func (l *LeafNode) Delete() {
l.parent.children = l.parent.children[:len(l.parent.children)-1]
tab := tabs[l.parent.tabNum]
j := findView(tab.views, l.view)
copy(tab.views[j:], tab.views[j+1:])
tab.views[len(tab.views)-1] = nil // or the zero value of T
tab.views = tab.views[:len(tab.views)-1]
j := findView(tab.Views, l.view)
copy(tab.Views[j:], tab.Views[j+1:])
tab.Views[len(tab.Views)-1] = nil // or the zero value of T
tab.Views = tab.Views[:len(tab.Views)-1]
for i, v := range tab.views {
for i, v := range tab.Views {
v.Num = i
}
if tab.CurView > 0 {

View file

@ -14,7 +14,7 @@ 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
@ -24,12 +24,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
@ -50,7 +50,7 @@ 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
}
}
@ -76,7 +76,7 @@ func (t *Tab) Resize() {
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)
@ -87,7 +87,7 @@ func (t *Tab) Resize() {
// 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
@ -103,7 +103,7 @@ func TabbarString() (string, map[int]int) {
} else {
str += " "
}
buf := t.views[t.CurView].Buf
buf := t.Views[t.CurView].Buf
str += buf.GetName()
if buf.Modified() {
str += " +"