mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Messages -> notifications
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
57
spec/notification-manager-spec.coffee
Normal file
57
spec/notification-manager-spec.coffee
Normal 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'
|
||||
13
spec/notification-spec.coffee
Normal file
13
spec/notification-spec.coffee
Normal 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'
|
||||
@@ -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})
|
||||
|
||||
@@ -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
|
||||
44
src/notification-manager.coffee
Normal file
44
src/notification-manager.coffee
Normal 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
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
# Experimental: This will likely change, do not use.
|
||||
module.exports =
|
||||
class Message
|
||||
class Notification
|
||||
constructor: (@type, @message, @options={}) ->
|
||||
|
||||
getOptions: -> @options
|
||||
Reference in New Issue
Block a user