Messages -> notifications

This commit is contained in:
Ben Ogle
2014-11-20 18:53:06 -08:00
parent 25caaa92f1
commit 9c6a5fb4fa
9 changed files with 120 additions and 120 deletions

View File

@@ -6,7 +6,7 @@ module.exports =
BufferedNodeProcess: require '../src/buffered-node-process'
BufferedProcess: require '../src/buffered-process'
GitRepository: require '../src/git-repository'
Message: require '../src/message'
Message: require '../src/notification'
Point: Point
Range: Range
Emitter: Emitter

View File

@@ -1,57 +0,0 @@
MessageManager = require '../src/message-manager'
describe "MessageManager", ->
[manager] = []
beforeEach ->
manager = new MessageManager
describe "the atom global", ->
it "has a messages instance", ->
expect(atom.messages instanceof MessageManager).toBe true
describe "adding events", ->
addSpy = null
beforeEach ->
addSpy = jasmine.createSpy()
manager.onDidAddMessage(addSpy)
it "emits an event when a message has been added", ->
manager.add('error', 'Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'error'
expect(message.getMessage()).toBe 'Some error!'
expect(message.getIcon()).toBe 'someIcon'
it "emits a fatal error ::addFatalError has been called", ->
manager.addFatalError('Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'fatal'
it "emits an error ::addError has been called", ->
manager.addError('Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'error'
it "emits a warning message ::addWarning has been called", ->
manager.addWarning('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'warning'
it "emits an info message ::addInfo has been called", ->
manager.addInfo('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'info'
it "emits a success message ::addSuccess has been called", ->
manager.addSuccess('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
message = addSpy.mostRecentCall.args[0]
expect(message.getType()).toBe 'success'

View File

@@ -1,13 +0,0 @@
Message = require '../src/message'
describe "Message", ->
[message] = []
describe "::getIcon()", ->
it "returns a default when no icon specified", ->
message = new Message('error', 'message!')
expect(message.getIcon()).toBe 'bug'
it "returns the icon specified", ->
message = new Message('error', 'message!', icon: 'my-icon')
expect(message.getIcon()).toBe 'my-icon'

View File

@@ -0,0 +1,57 @@
NotificationManager = require '../src/notification-manager'
describe "NotificationManager", ->
[manager] = []
beforeEach ->
manager = new NotificationManager
describe "the atom global", ->
it "has a notifications instance", ->
expect(atom.notifications instanceof NotificationManager).toBe true
describe "adding events", ->
addSpy = null
beforeEach ->
addSpy = jasmine.createSpy()
manager.onDidAddNotification(addSpy)
it "emits an event when a notification has been added", ->
manager.add('error', 'Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'error'
expect(notification.getMessage()).toBe 'Some error!'
expect(notification.getIcon()).toBe 'someIcon'
it "emits a fatal error ::addFatalError has been called", ->
manager.addFatalError('Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'fatal'
it "emits an error ::addError has been called", ->
manager.addError('Some error!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'error'
it "emits a warning notification ::addWarning has been called", ->
manager.addWarning('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'warning'
it "emits an info notification ::addInfo has been called", ->
manager.addInfo('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'info'
it "emits a success notification ::addSuccess has been called", ->
manager.addSuccess('Something!', icon: 'someIcon')
expect(addSpy).toHaveBeenCalled()
notification = addSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'success'

View File

@@ -0,0 +1,13 @@
Notification = require '../src/notification'
describe "Notification", ->
[notification] = []
describe "::getIcon()", ->
it "returns a default when no icon specified", ->
notification = new Notification('error', 'message!')
expect(notification.getIcon()).toBe 'bug'
it "returns the icon specified", ->
notification = new Notification('error', 'message!', icon: 'my-icon')
expect(notification.getIcon()).toBe 'my-icon'

View File

@@ -146,8 +146,8 @@ class Atom extends Model
# Public: A {TooltipManager} instance
tooltips: null
# Experimental: A {MessageManager} instance
messages: null
# Experimental: A {NotificationManager} instance
notifications: null
# Public: A {Project} instance
project: null
@@ -223,7 +223,7 @@ class Atom extends Model
ViewRegistry = require './view-registry'
CommandRegistry = require './command-registry'
TooltipManager = require './tooltip-manager'
MessageManager = require './message-manager'
NotificationManager = require './notification-manager'
PackageManager = require './package-manager'
Clipboard = require './clipboard'
GrammarRegistry = require './grammar-registry'
@@ -250,7 +250,7 @@ class Atom extends Model
@keymaps = new KeymapManager({configDirPath, resourcePath})
@keymap = @keymaps # Deprecated
@tooltips = new TooltipManager
@messages = new MessageManager
@notifications = new NotificationManager
@commands = new CommandRegistry
@views = new ViewRegistry
@packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode})

View File

@@ -1,44 +0,0 @@
{Emitter, Disposable} = require 'event-kit'
Message = require '../src/message'
# Experimental: Allows messaging the user. This will likely change, dont use
# quite yet!
module.exports =
class MessageManager
constructor: ->
@messages = []
@emitter = new Emitter
###
Section: Events
###
onDidAddMessage: (callback) ->
@emitter.on 'did-add-message', callback
###
Section: Adding Messages
###
addSuccess: (messageString, options) ->
@addMessage(new Message('success', messageString, options))
addInfo: (messageString, options) ->
@addMessage(new Message('info', messageString, options))
addWarning: (messageString, options) ->
@addMessage(new Message('warning', messageString, options))
addError: (messageString, options) ->
@addMessage(new Message('error', messageString, options))
addFatalError: (messageString, options) ->
@addMessage(new Message('fatal', messageString, options))
add: (type, messageString, options) ->
@addMessage(new Message(type, messageString, options))
addMessage: (message) ->
@messages.push(message)
@emitter.emit('did-add-message', message)
message

View File

@@ -0,0 +1,44 @@
{Emitter, Disposable} = require 'event-kit'
Notification = require '../src/notification'
# Experimental: Allows messaging the user. This will likely change, dont use
# quite yet!
module.exports =
class NotificationManager
constructor: ->
@notifications = []
@emitter = new Emitter
###
Section: Events
###
onDidAddNotification: (callback) ->
@emitter.on 'did-add-notification', callback
###
Section: Adding Notifications
###
addSuccess: (message, options) ->
@addNotification(new Notification('success', message, options))
addInfo: (message, options) ->
@addNotification(new Notification('info', message, options))
addWarning: (message, options) ->
@addNotification(new Notification('warning', message, options))
addError: (message, options) ->
@addNotification(new Notification('error', message, options))
addFatalError: (message, options) ->
@addNotification(new Notification('fatal', message, options))
add: (type, message, options) ->
@addNotification(new Notification(type, message, options))
addNotification: (notification) ->
@notifications.push(notification)
@emitter.emit('did-add-notification', notification)
notification

View File

@@ -1,7 +1,7 @@
# Experimental: This will likely change, do not use.
module.exports =
class Message
class Notification
constructor: (@type, @message, @options={}) ->
getOptions: -> @options