Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Clear log #180

Merged
merged 6 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Notifications =
@addNotificationsLogSubscriptions() if @notificationsLog?
@subscriptions.add atom.workspace.addOpener (uri) => @createLog() if uri is NotificationsLog::getURI()
@subscriptions.add atom.commands.add 'atom-workspace', 'notifications:toggle-log', -> atom.workspace.toggle(NotificationsLog::getURI())
@subscriptions.add atom.commands.add 'atom-workspace', 'notifications:clear-log', ->
for notification in atom.notifications.getNotifications()
notification.options.dismissable = true
notification.dismissed = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Under what circumstances will there be an already-dismissed notification in the list that we need to dismiss again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-dimissable notifications (ones that dismiss automatically) have .dismissed = true when they are first shown. If someone clears the log we want those notifications to be dismissed right away not wait for the timer to dismiss them automatically.

notification.dismiss()
atom.notifications.clear()

deactivate: ->
@subscriptions.dispose()
Expand Down
14 changes: 12 additions & 2 deletions lib/notifications-log.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module.exports = class NotificationsLog
@typesHidden = typesHidden if typesHidden?
@emitter = new Emitter
@subscriptions = new CompositeDisposable
@subscriptions.add atom.notifications.onDidClearNotifications => @clearLogItems()
@render()
@subscriptions.add new Disposable => @clearLogItems()

render: ->
@element = document.createElement('div')
Expand All @@ -45,6 +47,12 @@ module.exports = class NotificationsLog
@subscriptions.add atom.tooltips.add(button, {title: "Toggle #{type} notifications"})
header.appendChild(button)

button = document.createElement('button')
button.classList.add('notifications-clear-log', 'btn', 'icon', 'icon-trashcan')
button.addEventListener 'click', (e) -> atom.commands.dispatch(atom.views.getView(atom.workspace), "notifications:clear-log")
@subscriptions.add atom.tooltips.add(button, {title: "Clear notifications"})
header.appendChild(button)

lastNotification = null
for notification in atom.notifications.getNotifications()
if lastNotification?
Expand Down Expand Up @@ -95,10 +103,12 @@ module.exports = class NotificationsLog
@logItems.push logItem
@list.insertBefore(logItem.getElement(), @list.firstChild)

@subscriptions.add new Disposable -> logItem.destroy()

onItemClick: (callback) ->
@emitter.on 'item-clicked', callback

onDidDestroy: (callback) ->
@emitter.on 'did-destroy', callback

clearLogItems: ->
logItem.destroy() for logItem in @logItems
@logItems = []
16 changes: 16 additions & 0 deletions spec/notifications-log-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ describe "Notifications Log", ->
expect(notification.dismissed).toBe true
expect(notificationView.element).not.toBeVisible()

describe "when notifications are cleared", ->

beforeEach ->
clearButton = workspaceElement.querySelector('.notifications-log .notifications-clear-log')
atom.notifications.addInfo('A message', dismissable: true)
atom.notifications.addInfo('non-dismissable')
clearButton.click()

it "clears the notifications", ->
expect(atom.notifications.getNotifications()).toHaveLength 0
notifications = workspaceElement.querySelector('atom-notifications')
advanceClock(NotificationElement::animationDuration)
expect(notifications.children).toHaveLength 0
logItems = workspaceElement.querySelector('.notifications-log-items')
expect(logItems.children).toHaveLength 0

describe "the dock pane", ->
notificationsLogPane = null

Expand Down
6 changes: 5 additions & 1 deletion styles/notifications-log.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
background-color: @base-background-color;
border-bottom: 1px solid @base-border-color;

.notification-type {
button {
border: none;
width: @icon-size;
height: @icon-size;
Expand All @@ -24,6 +24,10 @@
opacity: .5;
background: @base-background-color;
}

.notifications-clear-log {
float: right;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UziTech: When you have a moment, can you share screenshots of this new icon is rendered in each of the UI themes that ship with Atom? I suspect it renders just fine, but we want to make sure. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atom Dark

image

Atom Light

image

One Dark

image

One Light

image

}

.notifications-log-items {
Expand Down