From 9604d81ec8e005880d8a35f49aa03f9bed006e9d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 25 Mar 2013 11:32:26 -0400 Subject: [PATCH] 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 --- src/packages/tabs/lib/tab-bar-view.coffee | 2 ++ src/packages/tabs/spec/tabs-spec.coffee | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/packages/tabs/lib/tab-bar-view.coffee b/src/packages/tabs/lib/tab-bar-view.coffee index fbbab1330..68f41df86 100644 --- a/src/packages/tabs/lib/tab-bar-view.coffee +++ b/src/packages/tabs/lib/tab-bar-view.coffee @@ -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() diff --git a/src/packages/tabs/spec/tabs-spec.coffee b/src/packages/tabs/spec/tabs-spec.coffee index 014e0352d..0a31a02b0 100644 --- a/src/packages/tabs/spec/tabs-spec.coffee +++ b/src/packages/tabs/spec/tabs-spec.coffee @@ -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')