mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 06:28:33 +03:00
Tabs indicate when their items are modified
This commit is contained in:
parent
24c9f11cc9
commit
a1dc2cfc2d
@ -11,7 +11,9 @@ class TabView extends View
|
|||||||
|
|
||||||
initialize: (@item, @pane) ->
|
initialize: (@item, @pane) ->
|
||||||
@item.on? 'title-changed', => @updateTitle()
|
@item.on? 'title-changed', => @updateTitle()
|
||||||
|
@item.on? 'modified-status-changed', => @updateModifiedStatus()
|
||||||
@updateTitle()
|
@updateTitle()
|
||||||
|
@updateModifiedStatus()
|
||||||
|
|
||||||
updateTitle: ->
|
updateTitle: ->
|
||||||
return if @updatingTitle
|
return if @updatingTitle
|
||||||
@ -32,11 +34,11 @@ class TabView extends View
|
|||||||
@siblings('.tab').views()
|
@siblings('.tab').views()
|
||||||
|
|
||||||
updateModifiedStatus: ->
|
updateModifiedStatus: ->
|
||||||
if @buffer.isModified()
|
if @item.isModified?()
|
||||||
@toggleClass('file-modified') unless @isModified
|
@addClass('modified') unless @isModified
|
||||||
@isModified = true
|
@isModified = true
|
||||||
else
|
else
|
||||||
@removeClass('file-modified') if @isModified
|
@removeClass('modified') if @isModified
|
||||||
@isModified = false
|
@isModified = false
|
||||||
|
|
||||||
updateFileName: ->
|
updateFileName: ->
|
||||||
|
@ -76,6 +76,12 @@ describe "TabBarView", ->
|
|||||||
expect(tabBar.find('.tab').length).toBe 4
|
expect(tabBar.find('.tab').length).toBe 4
|
||||||
expect(tabBar.tabAtIndex(1).find('.title')).toHaveText 'Item 3'
|
expect(tabBar.tabAtIndex(1).find('.title')).toHaveText 'Item 3'
|
||||||
|
|
||||||
|
it "adds the 'modified' class to the new tab if the item is initially modified", ->
|
||||||
|
editSession2 = project.buildEditSession('sample.txt')
|
||||||
|
editSession2.insertText('x')
|
||||||
|
pane.showItem(editSession2)
|
||||||
|
expect(tabBar.tabForItem(editSession2)).toHaveClass 'modified'
|
||||||
|
|
||||||
describe "when an item is removed from the pane", ->
|
describe "when an item is removed from the pane", ->
|
||||||
it "removes the item's tab from the tab bar", ->
|
it "removes the item's tab from the tab bar", ->
|
||||||
pane.removeItem(item2)
|
pane.removeItem(item2)
|
||||||
@ -108,7 +114,7 @@ describe "TabBarView", ->
|
|||||||
editSession1.buffer.setPath('/this/is-a/test.txt')
|
editSession1.buffer.setPath('/this/is-a/test.txt')
|
||||||
expect(tabBar.tabForItem(editSession1)).toHaveText 'test.txt'
|
expect(tabBar.tabForItem(editSession1)).toHaveText 'test.txt'
|
||||||
|
|
||||||
describe "when two tabs have the same file name", ->
|
describe "when two tabs have the same title", ->
|
||||||
it "displays the long title on the tab if it's available from the item", ->
|
it "displays the long title on the tab if it's available from the item", ->
|
||||||
item1.title = "Old Man"
|
item1.title = "Old Man"
|
||||||
item1.longTitle = "Grumpy Old Man"
|
item1.longTitle = "Grumpy Old Man"
|
||||||
@ -126,6 +132,22 @@ describe "TabBarView", ->
|
|||||||
expect(tabBar.tabForItem(item1)).toHaveText "Grumpy Old Man"
|
expect(tabBar.tabForItem(item1)).toHaveText "Grumpy Old Man"
|
||||||
expect(tabBar.tabForItem(item2)).toHaveText "Old Man"
|
expect(tabBar.tabForItem(item2)).toHaveText "Old Man"
|
||||||
|
|
||||||
|
describe "when a tab item's modified status changes", ->
|
||||||
|
it "adds or removes the 'modified' class to the tab based on the status", ->
|
||||||
|
tab = tabBar.tabForItem(editSession1)
|
||||||
|
expect(editSession1.isModified()).toBeFalsy()
|
||||||
|
expect(tab).not.toHaveClass 'modified'
|
||||||
|
|
||||||
|
editSession1.insertText('x')
|
||||||
|
advanceClock(editSession1.buffer.stoppedChangingDelay)
|
||||||
|
expect(editSession1.isModified()).toBeTruthy()
|
||||||
|
expect(tab).toHaveClass 'modified'
|
||||||
|
|
||||||
|
editSession1.undo()
|
||||||
|
advanceClock(editSession1.buffer.stoppedChangingDelay)
|
||||||
|
expect(editSession1.isModified()).toBeFalsy()
|
||||||
|
expect(tab).not.toHaveClass 'modified'
|
||||||
|
|
||||||
describe "when a pane item moves to a new index", ->
|
describe "when a pane item moves to a new index", ->
|
||||||
it "updates the order of the tabs to match the new item order", ->
|
it "updates the order of the tabs to match the new item order", ->
|
||||||
expect(tabBar.getTabs().map (tab) -> tab.text()).toEqual ["Item 1", "sample.js", "Item 2"]
|
expect(tabBar.getTabs().map (tab) -> tab.text()).toEqual ["Item 1", "sample.js", "Item 2"]
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab.file-modified .close-icon {
|
.tab.modified .close-icon {
|
||||||
top: 11px;
|
top: 11px;
|
||||||
width: 5px;
|
width: 5px;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
@ -61,11 +61,11 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab.file-modified .close-icon:before {
|
.tab.modified .close-icon:before {
|
||||||
content: "";
|
content: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab.file-modified:hover .close-icon {
|
.tab.modified:hover .close-icon {
|
||||||
border: none;
|
border: none;
|
||||||
width: 12px;
|
width: 12px;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
@ -73,7 +73,7 @@
|
|||||||
top: 5px;
|
top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab.file-modified:hover .close-icon:before {
|
.tab.modified:hover .close-icon:before {
|
||||||
content: "\f081";
|
content: "\f081";
|
||||||
color: #66a6ff;
|
color: #66a6ff;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user