@@ -12,6 +12,7 @@ import { FileSystemWatcher } from "./../../Services/FileSystemWatcher"
1212import { Event } from "oni-types"
1313
1414import { CallbackCommand , CommandManager } from "./../../Services/CommandManager"
15+ import { Configuration } from "./../../Services/Configuration"
1516import { EditorManager } from "./../../Services/EditorManager"
1617import { getInstance as NotificationsInstance } from "./../../Services/Notifications"
1718import { windowManager } from "./../../Services/WindowManager"
@@ -27,8 +28,8 @@ type Node = ExplorerSelectors.ExplorerNode
2728export class ExplorerSplit {
2829 private _onEnterEvent : Event < void > = new Event < void > ( )
2930 private _selectedId : string = null
30-
3131 private _store : Store < IExplorerState >
32+ private _watcher : FileSystemWatcher = null
3233
3334 public get id ( ) : string {
3435 return "oni.sidebar.explorer"
@@ -39,26 +40,25 @@ export class ExplorerSplit {
3940 }
4041
4142 constructor (
42- // private _configuration: Configuration,
43+ private _configuration : Configuration ,
4344 private _workspace : IWorkspace ,
4445 private _commandManager : CommandManager ,
4546 private _editorManager : EditorManager ,
4647 ) {
4748 this . _store = createStore ( { notifications : NotificationsInstance ( ) } )
4849
49- const Watcher = new FileSystemWatcher ( {
50- target : this . _workspace . activeWorkspace ,
51- options : { ignoreInitial : true , ignored : "**/node_modules" } ,
52- } )
50+ this . _initializeFileSystemWatcher ( )
5351
5452 this . _workspace . onDirectoryChanged . subscribe ( newDirectory => {
5553 this . _store . dispatch ( {
5654 type : "SET_ROOT_DIRECTORY" ,
5755 rootPath : newDirectory ,
5856 } )
5957
60- Watcher . unwatch ( this . _workspace . activeWorkspace )
61- Watcher . watch ( newDirectory )
58+ if ( this . _watcher ) {
59+ this . _watcher . unwatch ( this . _workspace . activeWorkspace )
60+ this . _watcher . watch ( newDirectory )
61+ }
6262 } )
6363
6464 if ( this . _workspace . activeWorkspace ) {
@@ -67,11 +67,6 @@ export class ExplorerSplit {
6767 rootPath : this . _workspace . activeWorkspace ,
6868 } )
6969 }
70-
71- const events = [ "onChange" , "onAdd" , "onAddDir" , "onMove" , "onDelete" , "onDeleteDir" ]
72- events . forEach ( event =>
73- Watcher [ event ] . subscribe ( ( ) => this . _store . dispatch ( { type : "REFRESH" } ) ) ,
74- )
7570 }
7671
7772 public enter ( ) : void {
@@ -104,11 +99,27 @@ export class ExplorerSplit {
10499 )
105100 }
106101
102+ private _initializeFileSystemWatcher ( ) : void {
103+ if ( this . _configuration . getValue ( "explorer.autoRefresh" ) ) {
104+ this . _watcher = new FileSystemWatcher ( {
105+ target : this . _workspace . activeWorkspace ,
106+ options : { ignoreInitial : true , ignored : "**/node_modules" } ,
107+ } )
108+
109+ const events = [ "onChange" , "onAdd" , "onAddDir" , "onMove" , "onDelete" , "onDeleteDir" ]
110+ events . forEach ( event => this . _watcher [ event ] . subscribe ( ( ) => this . _refresh ( ) ) )
111+ }
112+ }
113+
107114 private _inputInProgress = ( ) => {
108115 const { register : { rename, create } } = this . _store . getState ( )
109116 return rename . active || create . active
110117 }
111118
119+ private _refresh ( ) : void {
120+ this . _store . dispatch ( { type : "REFRESH" } )
121+ }
122+
112123 private _initialiseExplorerCommands ( ) : void {
113124 this . _commandManager . registerCommand (
114125 new CallbackCommand (
@@ -153,6 +164,15 @@ export class ExplorerSplit {
153164 ) ,
154165 )
155166
167+ this . _commandManager . registerCommand (
168+ new CallbackCommand (
169+ "explorer.refresh" ,
170+ "Explorer: Refresh the tree" ,
171+ "Updates the explorer with the latest state on the file system" ,
172+ ( ) => ! this . _inputInProgress ( ) && this . _refresh ( ) ,
173+ ) ,
174+ )
175+
156176 this . _commandManager . registerCommand (
157177 new CallbackCommand (
158178 "explorer.create.file" ,
0 commit comments