Update titles after adding/removing tabs

The duplicate title detection requires the tab be on the DOM
so update the title after it is inserted and also update titles
of remaining tabs after one is removed so long titles being used
can go back to short titles if no other tab title duplicates exist.

Closes #446
This commit is contained in:
Kevin Sawicki
2013-03-25 11:32:26 -04:00
parent 0080e09065
commit 9604d81ec8
2 changed files with 13 additions and 0 deletions

View File

@@ -47,9 +47,11 @@ class TabBarView extends SortableList
tab.insertBefore(followingTab)
else
@append(tab)
tab.updateTitle()
removeTabForItem: (item) ->
@tabForItem(item).remove()
tab.updateTitle() for tab in @getTabs()
getTabs: ->
@children('.tab').toArray().map (elt) -> $(elt).view()

View File

@@ -88,6 +88,17 @@ describe "TabBarView", ->
expect(tabBar.getTabs().length).toBe 2
expect(tabBar.find('.tab:contains(Item 2)')).not.toExist()
it "updates the titles of the remaining tabs", ->
expect(tabBar.tabForItem(item2)).toHaveText 'Item 2'
item2.longTitle = '2'
item2a = new TestView('Item 2')
item2a.longTitle = '2a'
pane.showItem(item2a)
expect(tabBar.tabForItem(item2)).toHaveText '2'
expect(tabBar.tabForItem(item2a)).toHaveText '2a'
pane.removeItem(item2a)
expect(tabBar.tabForItem(item2)).toHaveText 'Item 2'
describe "when a tab is clicked", ->
it "shows the associated item on the pane and focuses the pane", ->
spyOn(pane, 'focus')