Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Fix #2149 - Part 1 - Add configuration setting for explorer refresh #2154

Merged
merged 3 commits into from
May 1, 2018
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
8 changes: 7 additions & 1 deletion browser/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ export const start = async (args: string[]): Promise<void> => {
Sidebar.activate(configuration, workspace)
const sidebarManager = Sidebar.getInstance()

Explorer.activate(commandManager, editorManager, Sidebar.getInstance(), workspace)
Explorer.activate(
commandManager,
configuration,
editorManager,
Sidebar.getInstance(),
workspace,
)
Search.activate(commandManager, editorManager, Sidebar.getInstance(), workspace)
Learning.activate(
commandManager,
Expand Down
1 change: 1 addition & 0 deletions browser/src/Input/KeyBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const applyDefaultKeyBindings = (oni: Oni.Plugin.Api, config: Configurati
input.bind("r", "explorer.rename", isExplorerActive)
input.bind("<c-e>", "explorer.create.file", isExplorerActive)
input.bind("<c-f>", "explorer.create.folder", isExplorerActive)
input.bind("<c-r>", "explorer.refresh", isExplorerActive)

// Browser
input.bind("k", "browser.scrollUp")
Expand Down
46 changes: 33 additions & 13 deletions browser/src/Services/Explorer/ExplorerSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FileSystemWatcher } from "./../../Services/FileSystemWatcher"
import { Event } from "oni-types"

import { CallbackCommand, CommandManager } from "./../../Services/CommandManager"
import { Configuration } from "./../../Services/Configuration"
import { EditorManager } from "./../../Services/EditorManager"
import { getInstance as NotificationsInstance } from "./../../Services/Notifications"
import { windowManager } from "./../../Services/WindowManager"
Expand All @@ -27,8 +28,8 @@ type Node = ExplorerSelectors.ExplorerNode
export class ExplorerSplit {
private _onEnterEvent: Event<void> = new Event<void>()
private _selectedId: string = null

private _store: Store<IExplorerState>
private _watcher: FileSystemWatcher = null

public get id(): string {
return "oni.sidebar.explorer"
Expand All @@ -39,26 +40,25 @@ export class ExplorerSplit {
}

constructor(
// private _configuration: Configuration,
private _configuration: Configuration,
private _workspace: IWorkspace,
private _commandManager: CommandManager,
private _editorManager: EditorManager,
) {
this._store = createStore({ notifications: NotificationsInstance() })

const Watcher = new FileSystemWatcher({
target: this._workspace.activeWorkspace,
options: { ignoreInitial: true, ignored: "**/node_modules" },
})
this._initializeFileSystemWatcher()

this._workspace.onDirectoryChanged.subscribe(newDirectory => {
this._store.dispatch({
type: "SET_ROOT_DIRECTORY",
rootPath: newDirectory,
})

Watcher.unwatch(this._workspace.activeWorkspace)
Watcher.watch(newDirectory)
if (this._watcher) {
this._watcher.unwatch(this._workspace.activeWorkspace)
this._watcher.watch(newDirectory)
}
})

if (this._workspace.activeWorkspace) {
Expand All @@ -67,11 +67,6 @@ export class ExplorerSplit {
rootPath: this._workspace.activeWorkspace,
})
}

const events = ["onChange", "onAdd", "onAddDir", "onMove", "onDelete", "onDeleteDir"]
events.forEach(event =>
Watcher[event].subscribe(() => this._store.dispatch({ type: "REFRESH" })),
)
}

public enter(): void {
Expand Down Expand Up @@ -104,11 +99,27 @@ export class ExplorerSplit {
)
}

private _initializeFileSystemWatcher(): void {
if (this._configuration.getValue("explorer.autoRefresh")) {
this._watcher = new FileSystemWatcher({
target: this._workspace.activeWorkspace,
options: { ignoreInitial: true, ignored: "**/node_modules" },
})

const events = ["onChange", "onAdd", "onAddDir", "onMove", "onDelete", "onDeleteDir"]
events.forEach(event => this._watcher[event].subscribe(() => this._refresh()))
}
}

private _inputInProgress = () => {
const { register: { rename, create } } = this._store.getState()
return rename.active || create.active
}

private _refresh(): void {
this._store.dispatch({ type: "REFRESH" })
}

private _initialiseExplorerCommands(): void {
this._commandManager.registerCommand(
new CallbackCommand(
Expand Down Expand Up @@ -153,6 +164,15 @@ export class ExplorerSplit {
),
)

this._commandManager.registerCommand(
new CallbackCommand(
"explorer.refresh",
"Explorer: Refresh the tree",
"Updates the explorer with the latest state on the file system",
() => !this._inputInProgress() && this._refresh(),
),
)

this._commandManager.registerCommand(
new CallbackCommand(
"explorer.create.file",
Expand Down
14 changes: 13 additions & 1 deletion browser/src/Services/Explorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { CommandManager } from "./../CommandManager"
import { Configuration } from "./../Configuration"
import { EditorManager } from "./../EditorManager"
import { SidebarManager } from "./../Sidebar"
import { Workspace } from "./../Workspace"
Expand All @@ -13,9 +14,20 @@ import { ExplorerSplit } from "./ExplorerSplit"

export const activate = (
commandManager: CommandManager,
configuration: Configuration,
editorManager: EditorManager,
sidebarManager: SidebarManager,
workspace: Workspace,
) => {
sidebarManager.add("files-o", new ExplorerSplit(workspace, commandManager, editorManager))
configuration.registerSetting("explorer.autoRefresh", {
description:
"When set to true, the explorer will listen for changes on the file system and refresh automatically.",
requiresReload: true,
defaultValue: false,
})

sidebarManager.add(
"files-o",
new ExplorerSplit(configuration, workspace, commandManager, editorManager),
)
}