summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorKevin Kuehler <kkuehler@brave.com>2019-06-10 22:05:56 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-11 09:34:45 -0400
commita54f4adb8f28855e7a8e5f24072f4d969b3b674d (patch)
treed93d13caac01d4b5a90e9742b947fa590b3d2fbd /lib
parent32f970e0531a0811392d2836773870acf649cf26 (diff)
downloadaerc-a54f4adb8f28855e7a8e5f24072f4d969b3b674d.tar.gz
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/tab.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index ed96ec4..61d544a 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -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")