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

Commit

Permalink
add readonly indicator option to turn off autorefresh, fix readonly a…
Browse files Browse the repository at this point in the history
…utorefresh
  • Loading branch information
jmtoniolo committed May 7, 2020
1 parent d4ae871 commit 1356ba3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/read-only-indicator-view.coffee
Expand Up @@ -10,7 +10,9 @@ class ReadOnlyIndicatorView extends HTMLDivElement
@readOnlySpan.textContent = ' [RW]'
@appendChild(@readOnlySpan)
@handleEvents()

@listenerRunning = false
@watcher = 0
@autorefresh = atom.config.get('read-only-indicator.autorefresh')
@position = atom.config.get('read-only-indicator.position')
if @position == 'left'
@tile = @statusBar.addLeftTile(item: this, priority: 200)
Expand All @@ -27,14 +29,12 @@ class ReadOnlyIndicatorView extends HTMLDivElement
@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.onDidChangeActivePaneItem =>
@subscribeToActiveTextEditor()
item = atom.workspace.getActivePaneItem()
filePath = item?.getPath?()
if filePath != undefined
fs.watch(filePath, (event, filename ) => @subscribeToActiveTextEditor() )

@subscribeToActiveTextEditor()

subscribeToActiveTextEditor: ->
@editorSubscriptions?.dispose()
@listenerRunning = false
@updateStatusBar()

updateStatusBar: ->
Expand All @@ -48,7 +48,11 @@ class ReadOnlyIndicatorView extends HTMLDivElement
if filePath == undefined
@style.display = 'none'
else

if @autorefresh
if not @listenerRunning
if @watcher
@watcher.close()
@watcher = fs.watch(filePath , ( c, f ) => @subscribeToActiveTextEditor() )
@showIcon = atom.config.get('read-only-indicator.showIcon')
if @showIcon == true
@readOnlySpan.classList.add('iconed')
Expand Down

0 comments on commit 1356ba3

Please sign in to comment.