PanelContainer: Bug fixes and integration
This commit is contained in:
parent
c40be89564
commit
389276ee34
15
main.go
15
main.go
@ -199,6 +199,10 @@ func main() {
|
|||||||
fileMenu.AddItems([]ui.Item{&ui.ItemEntry{Name: "New File", Shortcut: "Ctrl+N", Callback: func() {
|
fileMenu.AddItems([]ui.Item{&ui.ItemEntry{Name: "New File", Shortcut: "Ctrl+N", Callback: func() {
|
||||||
textEdit := ui.NewTextEdit(screen, "", []byte{}, &theme) // No file path, no contents
|
textEdit := ui.NewTextEdit(screen, "", []byte{}, &theme) // No file path, no contents
|
||||||
tabContainer := getActiveTabContainer()
|
tabContainer := getActiveTabContainer()
|
||||||
|
if tabContainer == nil {
|
||||||
|
tabContainer = ui.NewTabContainer(&theme)
|
||||||
|
panelContainer.SetSelected(tabContainer)
|
||||||
|
}
|
||||||
tabContainer.AddTab("noname", textEdit)
|
tabContainer.AddTab("noname", textEdit)
|
||||||
tabContainer.FocusTab(tabContainer.GetTabCount() - 1)
|
tabContainer.FocusTab(tabContainer.GetTabCount() - 1)
|
||||||
changeFocus(panelContainer)
|
changeFocus(panelContainer)
|
||||||
@ -224,6 +228,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
textEdit := ui.NewTextEdit(screen, path, bytes, &theme)
|
textEdit := ui.NewTextEdit(screen, path, bytes, &theme)
|
||||||
|
if tabContainer == nil {
|
||||||
|
tabContainer = ui.NewTabContainer(&theme)
|
||||||
|
panelContainer.SetSelected(tabContainer)
|
||||||
|
}
|
||||||
tabContainer.AddTab(path, textEdit)
|
tabContainer.AddTab(path, textEdit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +284,12 @@ func main() {
|
|||||||
if tabContainer != nil && tabContainer.GetTabCount() > 0 {
|
if tabContainer != nil && tabContainer.GetTabCount() > 0 {
|
||||||
tabContainer.RemoveTab(tabContainer.GetSelectedTabIdx())
|
tabContainer.RemoveTab(tabContainer.GetSelectedTabIdx())
|
||||||
} else { // No tabs open; close the editor
|
} else { // No tabs open; close the editor
|
||||||
closing = true
|
// if the selected is root: close editor. otherwise close panel
|
||||||
|
if panelContainer.IsRootSelected() {
|
||||||
|
closing = true
|
||||||
|
} else {
|
||||||
|
panelContainer.DeleteSelected()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}})
|
}}})
|
||||||
|
|
||||||
|
@ -35,7 +35,9 @@ func (c *PanelContainer) ClearSelected() Component {
|
|||||||
item := (**c.selected).Left
|
item := (**c.selected).Left
|
||||||
(**c.selected).Left = nil
|
(**c.selected).Left = nil
|
||||||
(**c.selected).Kind = PanelKindEmpty
|
(**c.selected).Kind = PanelKindEmpty
|
||||||
(*c.selected).UpdateSplits()
|
if p := (**c.selected).Parent; p != nil {
|
||||||
|
p.UpdateSplits()
|
||||||
|
}
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +54,13 @@ func (c *PanelContainer) DeleteSelected() Component {
|
|||||||
} else {
|
} else {
|
||||||
item := (**c.selected).Left
|
item := (**c.selected).Left
|
||||||
p := (**c.selected).Parent
|
p := (**c.selected).Parent
|
||||||
|
|
||||||
|
if c.focused {
|
||||||
|
(*c.selected).SetFocused(false) // Unfocus item
|
||||||
|
}
|
||||||
|
|
||||||
|
// we're shifting panel right to left,
|
||||||
|
// need to focus left
|
||||||
if p != nil {
|
if p != nil {
|
||||||
if *c.selected == (*p).Left { // If we're deleting the parent's Left
|
if *c.selected == (*p).Left { // If we're deleting the parent's Left
|
||||||
(*p).Left = (*p).Right
|
(*p).Left = (*p).Right
|
||||||
@ -59,16 +68,28 @@ func (c *PanelContainer) DeleteSelected() Component {
|
|||||||
} else { // Deleting parent's Right
|
} else { // Deleting parent's Right
|
||||||
(*p).Right = nil
|
(*p).Right = nil
|
||||||
}
|
}
|
||||||
(*p).Kind = PanelKindSingle
|
|
||||||
|
|
||||||
if c.focused {
|
if (*p).Left != nil { // Left == panel ; SHOULD NOT BE PANEL
|
||||||
(*c.selected).SetFocused(false) // Unfocus item
|
// asserting left is panel:
|
||||||
|
// if left is not a Leaf !.IsLeaf():
|
||||||
|
// make the parent match the left:
|
||||||
|
// p.Left = panel's Left
|
||||||
|
// p.Right = panel's Right
|
||||||
|
// p.Kind = panel's kind
|
||||||
|
// else:
|
||||||
|
// parent left = panel's left
|
||||||
|
// parent's kind = panel's kind
|
||||||
|
panel := (*p).Left.(*Panel)
|
||||||
|
|
||||||
|
(*p).Left = (*panel).Left
|
||||||
|
(*p).Right = (*panel).Right
|
||||||
|
(*p).Kind = (*panel).Kind
|
||||||
|
} else {
|
||||||
|
(*p).Kind = PanelKindEmpty
|
||||||
}
|
}
|
||||||
c.selected = &p
|
c.selected = &p
|
||||||
|
(*p).UpdateSplits()
|
||||||
} else if c.floatingMode { // Deleting a floating Panel without a parent
|
} else if c.floatingMode { // Deleting a floating Panel without a parent
|
||||||
if c.focused {
|
|
||||||
c.floating[0].SetFocused(false) // Unfocus Panel and item
|
|
||||||
}
|
|
||||||
c.floating[0] = nil
|
c.floating[0] = nil
|
||||||
copy(c.floating, c.floating[1:]) // Shift items to front
|
copy(c.floating, c.floating[1:]) // Shift items to front
|
||||||
c.floating = c.floating[:len(c.floating)-1] // Shrink slice's len by one
|
c.floating = c.floating[:len(c.floating)-1] // Shrink slice's len by one
|
||||||
@ -81,7 +102,7 @@ func (c *PanelContainer) DeleteSelected() Component {
|
|||||||
} else {
|
} else {
|
||||||
panic("Panel does not have parent and is not floating")
|
panic("Panel does not have parent and is not floating")
|
||||||
}
|
}
|
||||||
(*c.selected).UpdateSplits()
|
|
||||||
if c.focused {
|
if c.focused {
|
||||||
(*c.selected).SetFocused(c.focused)
|
(*c.selected).SetFocused(c.focused)
|
||||||
}
|
}
|
||||||
@ -106,7 +127,7 @@ func (c *PanelContainer) SwapNeighborsSelected() {
|
|||||||
// Turns the selected Panel into a split panel, moving its contents to its Left field,
|
// Turns the selected Panel into a split panel, moving its contents to its Left field,
|
||||||
// and putting the given Panel at the Right field. `panel` cannot be nil.
|
// and putting the given Panel at the Right field. `panel` cannot be nil.
|
||||||
func (c *PanelContainer) splitSelectedWithPanel(kind SplitKind, panel *Panel) {
|
func (c *PanelContainer) splitSelectedWithPanel(kind SplitKind, panel *Panel) {
|
||||||
(**c.selected).Left = &Panel{Parent: *c.selected, Left: (**c.selected).Left, Kind: PanelKindSingle}
|
(**c.selected).Left = &Panel{Parent: *c.selected, Left: (**c.selected).Left, Kind: (**c.selected).Kind}
|
||||||
(**c.selected).Right = panel
|
(**c.selected).Right = panel
|
||||||
(**c.selected).Right.(*Panel).Parent = *c.selected
|
(**c.selected).Right.(*Panel).Parent = *c.selected
|
||||||
|
|
||||||
@ -145,7 +166,14 @@ func (c *PanelContainer) SplitSelected(kind SplitKind, item Component) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PanelContainer) IsRootSelected() bool {
|
||||||
|
return *c.selected == c.root
|
||||||
|
}
|
||||||
|
|
||||||
func (c *PanelContainer) GetSelected() Component {
|
func (c *PanelContainer) GetSelected() Component {
|
||||||
|
if !(*c.selected).IsLeaf() {
|
||||||
|
panic("selected is not leaf")
|
||||||
|
}
|
||||||
return (**c.selected).Left
|
return (**c.selected).Left
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user