mirror of
https://github.com/atom/atom.git
synced 2026-02-05 04:05:05 -05:00
Move status-bar to packages folder
This commit is contained in:
1
src/packages/status-bar/index.coffee
Normal file
1
src/packages/status-bar/index.coffee
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require 'status-bar/src/status-bar'
|
||||
168
src/packages/status-bar/spec/status-bar-spec.coffee
Normal file
168
src/packages/status-bar/spec/status-bar-spec.coffee
Normal file
@@ -0,0 +1,168 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
RootView = require 'root-view'
|
||||
StatusBar = require 'status-bar'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "StatusBar", ->
|
||||
[rootView, editor, statusBar, buffer] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
rootView.simulateDomAttachment()
|
||||
StatusBar.activate(rootView)
|
||||
editor = rootView.getActiveEditor()
|
||||
statusBar = rootView.find('.status-bar').view()
|
||||
buffer = editor.getBuffer()
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "@initialize", ->
|
||||
it "appends a status bar to all existing and new editors", ->
|
||||
expect(rootView.panes.find('.pane').length).toBe 1
|
||||
expect(rootView.panes.find('.pane > .status-bar').length).toBe 1
|
||||
editor.splitRight()
|
||||
expect(rootView.find('.pane').length).toBe 2
|
||||
expect(rootView.panes.find('.pane > .status-bar').length).toBe 2
|
||||
|
||||
describe ".initialize(editor)", ->
|
||||
it "displays the editor's buffer path, cursor buffer position, and buffer modified indicator", ->
|
||||
expect(statusBar.currentPath.text()).toBe 'sample.js'
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
expect(statusBar.cursorPosition.text()).toBe '1,1'
|
||||
|
||||
describe "when associated with an unsaved buffer", ->
|
||||
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
|
||||
rootView.remove()
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
rootView.simulateDomAttachment()
|
||||
StatusBar.activate(rootView)
|
||||
statusBar = rootView.find('.status-bar').view()
|
||||
expect(statusBar.currentPath.text()).toBe 'untitled'
|
||||
expect(statusBar.cursorPosition.text()).toBe '1,1'
|
||||
|
||||
describe "when the associated editor's path changes", ->
|
||||
it "updates the path in the status bar", ->
|
||||
rootView.open(require.resolve 'fixtures/sample.txt')
|
||||
expect(statusBar.currentPath.text()).toBe 'sample.txt'
|
||||
|
||||
describe "when the associated editor's buffer's content changes", ->
|
||||
it "enables the buffer modified indicator", ->
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
editor.insertText("\n")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
editor.backspace()
|
||||
|
||||
describe "when the buffer content has changed from the content on disk", ->
|
||||
it "disables the buffer modified indicator on save", ->
|
||||
path = "/tmp/atom-whitespace.txt"
|
||||
fs.write(path, "")
|
||||
rootView.open(path)
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
editor.insertText("\n")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
editor.save()
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
it "disables the buffer modified indicator if the content matches again", ->
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
editor.insertText("\n")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
editor.backspace()
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
it "disables the buffer modified indicator when the change is undone", ->
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
editor.insertText("\n")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
editor.undo()
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
describe "when the buffer changes", ->
|
||||
it "updates the buffer modified indicator for the new buffer", ->
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
editor.insertText("\n")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
|
||||
it "doesn't update the buffer modified indicator for the old buffer", ->
|
||||
oldBuffer = editor.getBuffer()
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
oldBuffer.setText("new text")
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
describe "when the associated editor's cursor position changes", ->
|
||||
it "updates the cursor position in the status bar", ->
|
||||
editor.setCursorScreenPosition([1, 2])
|
||||
expect(statusBar.cursorPosition.text()).toBe '2,3'
|
||||
|
||||
describe "git branch label", ->
|
||||
beforeEach ->
|
||||
fs.remove('/tmp/.git') if fs.isDirectory('/tmp/.git')
|
||||
rootView.attachToDom()
|
||||
|
||||
it "displays the current branch for files in repositories", ->
|
||||
path = require.resolve('fixtures/git/master.git/HEAD')
|
||||
rootView.open(path)
|
||||
expect(statusBar.branchArea).toBeVisible()
|
||||
expect(statusBar.branchLabel.text()).toBe 'master'
|
||||
|
||||
it "doesn't display the current branch for a file not in a repository", ->
|
||||
path = '/tmp/temp.txt'
|
||||
rootView.open(path)
|
||||
expect(statusBar.branchArea).toBeHidden()
|
||||
expect(statusBar.branchLabel.text()).toBe ''
|
||||
|
||||
describe "git status label", ->
|
||||
[repo, path, originalPathText, newPath] = []
|
||||
|
||||
beforeEach ->
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new.txt')
|
||||
fs.write(newPath, "I'm new here")
|
||||
originalPathText = fs.read(path)
|
||||
rootView.attachToDom()
|
||||
|
||||
afterEach ->
|
||||
fs.write(path, originalPathText)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
|
||||
it "displays the modified icon for a changed file", ->
|
||||
fs.write(path, "i've changed for the worse")
|
||||
rootView.open(path)
|
||||
expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon')
|
||||
|
||||
it "doesn't display the modified icon for an unchanged file", ->
|
||||
rootView.open(path)
|
||||
expect(statusBar.gitStatusIcon).toHaveText('')
|
||||
|
||||
it "displays the new icon for a new file", ->
|
||||
rootView.open(newPath)
|
||||
expect(statusBar.gitStatusIcon).toHaveClass('new-status-icon')
|
||||
|
||||
it "updates when a git-status-change event occurs", ->
|
||||
fs.write(path, "i've changed for the worse")
|
||||
rootView.open(path)
|
||||
expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon')
|
||||
fs.write(path, originalPathText)
|
||||
rootView.getActiveEditor().getBuffer().trigger 'git-status-change'
|
||||
expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon')
|
||||
|
||||
it "updates when the window receives focus", ->
|
||||
fs.write(path, "i've changed for the worse")
|
||||
rootView.open(path)
|
||||
expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon')
|
||||
fs.write(path, originalPathText)
|
||||
$(window).trigger 'focus'
|
||||
expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon')
|
||||
93
src/packages/status-bar/src/status-bar.coffee
Normal file
93
src/packages/status-bar/src/status-bar.coffee
Normal file
@@ -0,0 +1,93 @@
|
||||
_ = require 'underscore'
|
||||
{View, $$} = require 'space-pen'
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class StatusBar extends View
|
||||
@activate: (rootView) ->
|
||||
requireStylesheet 'status-bar.css'
|
||||
|
||||
for editor in rootView.getEditors()
|
||||
@appendToEditorPane(rootView, editor) if rootView.parents('html').length
|
||||
|
||||
rootView.on 'editor-open', (e, editor) =>
|
||||
@appendToEditorPane(rootView, editor)
|
||||
|
||||
@appendToEditorPane: (rootView, editor) ->
|
||||
if pane = editor.pane()
|
||||
pane.append(new StatusBar(rootView, editor))
|
||||
|
||||
@content: ->
|
||||
@div class: 'status-bar', =>
|
||||
@div class: 'file-info', =>
|
||||
@span class: 'current-path', outlet: 'currentPath'
|
||||
@span class: 'buffer-modified', outlet: 'bufferModified'
|
||||
@div class: 'cursor-position', =>
|
||||
@span outlet: 'gitStatusIcon'
|
||||
@span outlet: 'branchArea', =>
|
||||
@span class: 'octicons branch-icon'
|
||||
@span class: 'branch-label', outlet: 'branchLabel'
|
||||
@span outlet: 'cursorPosition'
|
||||
|
||||
initialize: (@rootView, @editor) ->
|
||||
@updatePathText()
|
||||
@editor.on 'editor-path-change', =>
|
||||
@subscribeToBuffer()
|
||||
@updatePathText()
|
||||
|
||||
@updateCursorPositionText()
|
||||
@editor.on 'cursor-move', => @updateCursorPositionText()
|
||||
$(window).on 'focus', => @updateStatusBar()
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer?.off '.status-bar'
|
||||
@buffer = @editor.getBuffer()
|
||||
@buffer.on 'contents-modified.status-bar', (e) => @updateBufferHasModifiedText(e.differsFromDisk)
|
||||
@buffer.on 'after-save.status-bar', => @updateStatusBar()
|
||||
@buffer.on 'git-status-change.status-bar', => @updateStatusBar()
|
||||
@updateStatusBar()
|
||||
|
||||
updateStatusBar: ->
|
||||
@updateBranchText()
|
||||
@updateBufferHasModifiedText(@buffer.isModified())
|
||||
@updateStatusText()
|
||||
|
||||
updateBufferHasModifiedText: (differsFromDisk)->
|
||||
if differsFromDisk
|
||||
@bufferModified.text('*') unless @isModified
|
||||
@isModified = true
|
||||
else
|
||||
@bufferModified.text('') if @isModified
|
||||
@isModified = false
|
||||
|
||||
updateBranchText: ->
|
||||
path = @editor.getPath()
|
||||
@branchArea.hide()
|
||||
return unless path
|
||||
|
||||
head = @buffer.getGit()?.getShortHead()
|
||||
@branchLabel.text(head)
|
||||
@branchArea.show() if head
|
||||
|
||||
updateStatusText: ->
|
||||
path = @editor.getPath()
|
||||
@gitStatusIcon.empty()
|
||||
return unless path
|
||||
|
||||
@gitStatusIcon.removeClass().addClass('octicons')
|
||||
if @buffer.getGit()?.isPathModified(path)
|
||||
@gitStatusIcon.addClass('modified-status-icon')
|
||||
else if @buffer.getGit()?.isPathNew(path)
|
||||
@gitStatusIcon.addClass('new-status-icon')
|
||||
|
||||
updatePathText: ->
|
||||
if path = @editor.getPath()
|
||||
@currentPath.text(@rootView.project.relativize(path))
|
||||
else
|
||||
@currentPath.text('untitled')
|
||||
|
||||
updateCursorPositionText: ->
|
||||
{ row, column } = @editor.getCursorBufferPosition()
|
||||
@cursorPosition.text("#{row + 1},#{column + 1}")
|
||||
Reference in New Issue
Block a user