]> git.lizzy.rs Git - micro.git/blob - cmd/micro/action/tab.go
Split improvements
[micro.git] / cmd / micro / action / tab.go
1 package action
2
3 import (
4         "github.com/zyedidia/micro/cmd/micro/views"
5         "github.com/zyedidia/tcell"
6 )
7
8 var MainTab *TabPane
9
10 type TabPane struct {
11         *views.Node
12         Panes  []*EditPane
13         active int
14 }
15
16 func (t *TabPane) HandleEvent(event tcell.Event) {
17         switch e := event.(type) {
18         case *tcell.EventMouse:
19                 switch e.Buttons() {
20                 case tcell.Button1:
21                         mx, my := e.Position()
22
23                         for i, p := range t.Panes {
24                                 v := p.GetView()
25                                 inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
26                                 if inpane {
27                                         t.active = i
28                                         p.SetActive(true)
29                                 } else {
30                                         p.SetActive(false)
31                                 }
32                         }
33                 }
34         }
35         t.Panes[t.active].HandleEvent(event)
36 }
37
38 func (t *TabPane) SetActive(i int) {
39         t.active = i
40         for j, p := range t.Panes {
41                 if j == i {
42                         p.SetActive(true)
43                 } else {
44                         p.SetActive(false)
45                 }
46         }
47 }
48
49 func (t *TabPane) Resize() {
50         for _, p := range t.Panes {
51                 v := t.GetNode(p.splitID).GetView()
52                 pv := p.GetView()
53                 pv.X, pv.Y = v.X, v.Y
54                 p.SetView(pv)
55                 p.Resize(v.W, v.H)
56         }
57 }
58
59 func (t *TabPane) CurPane() *EditPane {
60         return t.Panes[t.active]
61 }