mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Update window title when a pane item's title changes
This commit is contained in:
committed by
probablycorey
parent
c1d19c4c5c
commit
d4fc718e8e
@@ -363,6 +363,24 @@ describe "Pane", ->
|
||||
pane.trigger 'pane:show-item-9' # don't fail on out-of-bounds indices
|
||||
expect(pane.activeItem).toBe pane.itemAtIndex(0)
|
||||
|
||||
describe "when the title of the active item changes", ->
|
||||
it "emits pane:active-item-title-changed", ->
|
||||
activeItemTitleChangedHandler = jasmine.createSpy("activeItemTitleChangedHandler")
|
||||
pane.on 'pane:active-item-title-changed', activeItemTitleChangedHandler
|
||||
|
||||
expect(pane.activeItem).toBe view1
|
||||
|
||||
view2.trigger 'title-changed'
|
||||
expect(activeItemTitleChangedHandler).not.toHaveBeenCalled()
|
||||
|
||||
view1.trigger 'title-changed'
|
||||
expect(activeItemTitleChangedHandler).toHaveBeenCalled()
|
||||
activeItemTitleChangedHandler.reset()
|
||||
|
||||
pane.showItem(view2)
|
||||
view2.trigger 'title-changed'
|
||||
expect(activeItemTitleChangedHandler).toHaveBeenCalled()
|
||||
|
||||
describe ".remove()", ->
|
||||
it "destroys all the pane's items", ->
|
||||
pane.remove()
|
||||
|
||||
@@ -159,7 +159,7 @@ describe "RootView", ->
|
||||
rootView.trigger(event)
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
|
||||
describe "title", ->
|
||||
describe "window title", ->
|
||||
describe "when the project has no path", ->
|
||||
it "sets the title to 'untitled'", ->
|
||||
project.setPath(undefined)
|
||||
@@ -174,6 +174,12 @@ describe "RootView", ->
|
||||
item = rootView.getActivePaneItem()
|
||||
expect(rootView.title).toBe "#{item.getTitle()} - #{project.getPath()}"
|
||||
|
||||
describe "when the title of the active pane item changes", ->
|
||||
it "updates the window title based on the item's new title", ->
|
||||
editSession = rootView.getActivePaneItem()
|
||||
editSession.buffer.setPath('/tmp/hi')
|
||||
expect(rootView.title).toBe "#{editSession.getTitle()} - #{project.getPath()}"
|
||||
|
||||
describe "when the active pane's item changes", ->
|
||||
it "updates the title to the new item's title plus the project path", ->
|
||||
rootView.getActivePane().showNextItem()
|
||||
|
||||
@@ -94,10 +94,13 @@ class Pane extends View
|
||||
showItem: (item) ->
|
||||
return if !item? or item is @activeItem
|
||||
|
||||
@autosaveActiveItem() if @activeItem
|
||||
if @activeItem
|
||||
@activeItem.off? 'title-changed', @activeItemTitleChanged
|
||||
@autosaveActiveItem()
|
||||
|
||||
isFocused = @is(':has(:focus)')
|
||||
@addItem(item)
|
||||
item.on? 'title-changed', @activeItemTitleChanged
|
||||
view = @viewForItem(item)
|
||||
@itemViews.children().not(view).hide()
|
||||
@itemViews.append(view) unless view.parent().is(@itemViews)
|
||||
@@ -107,6 +110,9 @@ class Pane extends View
|
||||
@activeView = view
|
||||
@trigger 'pane:active-item-changed', [item]
|
||||
|
||||
activeItemTitleChanged: =>
|
||||
@trigger 'pane:active-item-title-changed'
|
||||
|
||||
addItem: (item) ->
|
||||
return if _.include(@items, item)
|
||||
index = @getActiveItemIndex() + 1
|
||||
|
||||
@@ -32,8 +32,6 @@ class RootView extends View
|
||||
panes = deserialize(panesViewState) if panesViewState?.deserializer is 'PaneContainer'
|
||||
new RootView({panes})
|
||||
|
||||
title: null
|
||||
|
||||
initialize: ->
|
||||
@command 'toggle-dev-tools', => atom.toggleDevTools()
|
||||
@on 'focus', (e) => @handleFocus(e)
|
||||
@@ -44,6 +42,7 @@ class RootView extends View
|
||||
@on 'pane:became-active', => @updateTitle()
|
||||
@on 'pane:active-item-changed', '.active.pane', => @updateTitle()
|
||||
@on 'pane:removed', => @updateTitle() unless @getActivePane()
|
||||
@on 'pane:active-item-title-changed', '.active.pane', => @updateTitle()
|
||||
|
||||
@command 'window:increase-font-size', =>
|
||||
config.set("editor.fontSize", config.get("editor.fontSize") + 1)
|
||||
|
||||
Reference in New Issue
Block a user