11fs = require ' fs'
2- jquery = require (' atom' ).$
2+ $ = require (' atom' ).$
33process = require ' child_process'
44
55module .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" )
@@ -37,11 +40,15 @@ class PythonIsort
3740 editor = atom .workspace .getActiveEditor ()
3841 return editor .getPath ()
3942
40- checkForUnsortedImports : ->
43+ checkImports : ->
44+ if not @ checkForPythonContext ()
45+ return
46+
4147 params = [@ getFilePath (), " -c" , " -vb" ]
4248 isortpath = atom .config .get " python-isort.isortPath"
4349
44- if not fs .existsSync (isortpath)
50+ which = process .spawnSync (' which' , [' isort' ]).status
51+ if which == 1 and not fs .existsSync (isortpath)
4552 @ updateStatusbarText (" unable to open " + isortpath, false )
4653 return
4754
@@ -50,21 +57,22 @@ class PythonIsort
5057 updateStatusbarText = @updateStatusbarText
5158 proc .on ' exit' , (exit_code , signal ) ->
5259 if exit_code == 0
53- updateStatusbarText (" √ all python imports are fine " , false )
60+ updateStatusbarText (" √" , false )
5461 else
55- updateStatusbarText (" python imports are unsorted " , true )
62+ updateStatusbarText (" x " , true )
5663
5764 sortImports : ->
58- if not @checkForPythonContext
65+ if not @ checkForPythonContext ()
5966 return
6067
6168 params = [@ getFilePath (), " -vb" ]
6269 isortpath = atom .config .get " python-isort.isortPath"
6370
64- if not fs .existsSync (isortpath)
71+ which = process .spawnSync (' which' , [' isort' ]).status
72+ if which == 1 and not fs .existsSync (isortpath)
6573 @ updateStatusbarText (" unable to open " + isortpath, false )
6674 return
6775
6876 proc = process .spawn isortpath, params
69- @ updateStatusbarText (" √ all python imports are fine " , false )
77+ @ updateStatusbarText (" √" , false )
7078 @reload
0 commit comments