Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 7e61d31

Browse files
committed
Fix deprecation warnings and use new status bar package api
1 parent 4cbacc5 commit 7e61d31

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

lib/index.coffee

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ module.exports =
1818
atom.commands.add 'atom-workspace', 'python-isort:checkImports', ->
1919
pi.checkImports()
2020

21-
atom.config.observe 'python-isort.sortOnSave', {callNow: true}, (value) ->
22-
atom.workspace.eachEditor (editor) ->
21+
atom.config.observe 'python-isort.sortOnSave', (value) ->
22+
atom.workspace.observeTextEditors (editor) ->
2323
if value == true
24-
editor.buffer.on "saved", ->
25-
pi.sortImports()
24+
editor._isortSort = editor.onDidSave -> pi.sortImports()
2625
else
27-
editor.buffer.off "saved", ->
28-
pi.sortImports()
26+
editor._isortSort?.dispose()
2927

30-
atom.config.observe 'python-isort.checkOnSave', {callNow: true}, (value) ->
31-
atom.workspace.eachEditor (editor) ->
28+
atom.config.observe 'python-isort.checkOnSave', (value) ->
29+
atom.workspace.observeTextEditors (editor) ->
3230
if value == true
33-
editor.buffer.on "saved", ->
34-
pi.checkImports()
31+
editor._isortCheck = editor.onDidSave -> pi.checkImports()
3532
else
36-
editor.buffer.off "saved", ->
37-
pi.checkImports()
33+
editor._isortCheck?.dispose()

lib/python-isort.coffee

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fs = require 'fs'
2-
jquery = require('atom').$
2+
$ = require('atom').$
33
process = require 'child_process'
44

55
module.exports =
@@ -11,20 +11,23 @@ class PythonIsort
1111
return false
1212
return editor.getGrammar().name == 'Python'
1313

14-
removeStatusbarItem: ->
15-
if not @checkForPythonContext()
16-
jquery("#python-isort-status").remove()
14+
removeStatusbarItem: =>
15+
@statusBarTile?.destroy()
16+
@statusBarTile = null
1717

18-
updateStatusbarText: (message, isError) ->
19-
if jquery("#python-isort-status").length == 0
20-
statusBar = atom.workspaceView.statusBar
18+
updateStatusbarText: (message, isError) =>
19+
if not @statusBarTile
20+
statusBar = document.querySelector("status-bar")
2121
return unless statusBar?
22-
statusBar.appendLeft('<div id="python-isort-status" class="inline-block">
23-
<span style="font-weight: bold">Isort: </span>
24-
<span id="python-isort-status-message"></span>
25-
</div>')
22+
@statusBarTile = statusBar
23+
.addLeftTile(
24+
item: $('<div id="status-bar-python-isort" class="inline-block">
25+
<span style="font-weight: bold">Isort: </span>
26+
<span id="python-isort-status-message"></span>
27+
</div>'), priority: 100)
2628

27-
statusBarElement = jquery("#python-isort-status-message")
29+
statusBarElement = @statusBarTile.getItem()
30+
.find('#python-isort-status-message')
2831

2932
if isError == true
3033
statusBarElement.addClass("text-error")
@@ -54,9 +57,9 @@ class PythonIsort
5457
updateStatusbarText = @updateStatusbarText
5558
proc.on 'exit', (exit_code, signal) ->
5659
if exit_code == 0
57-
updateStatusbarText(" all python imports are fine", false)
60+
updateStatusbarText("", false)
5861
else
59-
updateStatusbarText("python imports are unsorted", true)
62+
updateStatusbarText("x", true)
6063

6164
sortImports: ->
6265
if not @checkForPythonContext()
@@ -71,5 +74,5 @@ class PythonIsort
7174
return
7275

7376
proc = process.spawn isortpath, params
74-
@updateStatusbarText(" all python imports are fine", false)
77+
@updateStatusbarText("", false)
7578
@reload

0 commit comments

Comments
 (0)