lib/ui/tab: Add Replace method

Also expose a light wrapper method in aerc.go for tab replacement

Signed-off-by: Kevin Kuehler <kkuehler@brave.com>
This commit is contained in:
Kevin Kuehler 2019-06-10 22:05:56 -07:00 committed by Drew DeVault
parent 32f970e053
commit a54f4adb8f
2 changed files with 20 additions and 0 deletions

View File

@ -68,6 +68,22 @@ func (tabs *Tabs) Remove(content Drawable) {
tabs.TabStrip.Invalidate()
}
func (tabs *Tabs) Replace(contentSrc Drawable, contentTarget Drawable, name string) {
replaceTab := &Tab{
Content: contentTarget,
Name: name,
}
for i, tab := range tabs.Tabs {
if tab.Content == contentSrc {
tabs.Tabs[i] = replaceTab
tabs.Select(i)
break
}
}
tabs.TabStrip.Invalidate()
contentTarget.OnInvalidate(tabs.invalidateChild)
}
func (tabs *Tabs) Select(index int) {
if index >= len(tabs.Tabs) {
panic("Tried to set tab index to a non-existing element")

View File

@ -218,6 +218,10 @@ func (aerc *Aerc) RemoveTab(tab ui.Drawable) {
aerc.tabs.Remove(tab)
}
func (aerc *Aerc) ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string) {
aerc.tabs.Replace(tabSrc, tabTarget, name)
}
func (aerc *Aerc) NextTab() {
next := aerc.tabs.Selected + 1
if next >= len(aerc.tabs.Tabs) {