-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide ability to add source directories to the Explorer panel
A directory can be added to the Explorer panel via the window menu by clicking on `File->Open Source Directory...`.
- Loading branch information
Showing
12 changed files
with
243 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2016 Vadim Macagon | ||
// MIT License, see LICENSE file for full terms. | ||
|
||
export const IPC_CONNECT = 'source-dir-registry:connect'; | ||
export const IPC_DISCONNECT = 'source-dir-registry:disconnect'; | ||
export const IPC_UPDATE = 'source-dir-registry:update'; | ||
|
||
export interface IConnectResponse { | ||
dirPaths: string[]; | ||
} | ||
|
||
export interface IUpdateRequest { | ||
kind: 'add'; | ||
dirPaths: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) 2016 Vadim Macagon | ||
// MIT License, see LICENSE file for full terms. | ||
|
||
export { OpenSourceDirCommand } from './open-src-dir'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2016 Vadim Macagon | ||
// MIT License, see LICENSE file for full terms. | ||
|
||
import { ICommand, ICommandArgs } from '../../common/command-table'; | ||
import { PathPicker } from '../platform/path-picker'; | ||
import { SourceDirRegistry } from '../source-dir-registry'; | ||
|
||
/** | ||
* Opens a source directory and displays it in the `Explorer` panel. | ||
* | ||
* If a directory path is not supplied the user will be prompted for one. | ||
*/ | ||
export class OpenSourceDirCommand implements ICommand { | ||
private _pathPicker: PathPicker; | ||
private _sourceDirRegistry: SourceDirRegistry; | ||
|
||
constructor(params: OpenSourceDirCommand.IConstructorParams) { | ||
this._pathPicker = params.pathPicker; | ||
this._sourceDirRegistry = params.sourceDirRegistry; | ||
} | ||
|
||
/** | ||
* If the directory path is not supplied a native directory selection dialog will be displayed. | ||
* | ||
* @return A promise that will be resolved when the command is done. | ||
*/ | ||
async execute({ dirPath, browserWindow }: OpenSourceDirCommand.IArgs): Promise<void> { | ||
if (!dirPath) { | ||
dirPath = await this._pathPicker.promptForPath({ | ||
title: 'Open Source Directory', pathKind: 'dir', parentWindow: browserWindow | ||
}); | ||
if (dirPath === null) { | ||
return; | ||
} | ||
} | ||
this._sourceDirRegistry.add(dirPath); | ||
} | ||
} | ||
|
||
export namespace OpenSourceDirCommand { | ||
export interface IConstructorParams { | ||
pathPicker: PathPicker; | ||
sourceDirRegistry: SourceDirRegistry; | ||
} | ||
|
||
export interface IArgs extends ICommandArgs { | ||
/** Absolute path to a source directory. */ | ||
dirPath?: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2016 Vadim Macagon | ||
// MIT License, see LICENSE file for full terms. | ||
|
||
import { ipcMain } from 'electron'; | ||
import * as ipc from '../common/ipc/source-dir-registry'; | ||
|
||
/** | ||
* Maintains a list of all currently open source directories. | ||
* | ||
* The list of source directories can be accessed in the renderer process via | ||
* [[RendererSourceDirRegistry]]. Any changes made to the list of source directories in | ||
* [[SourceDirRegistry]] will be propagated to all [[RendererSourceDirRegistry]] instances. | ||
*/ | ||
export class SourceDirRegistry { | ||
/** Absolute paths to source directories. */ | ||
private _dirPaths: string[] = []; | ||
/** Hosts of all remote [[RendererSourceDirRegistry]] instances. */ | ||
private _subscribers = new Set<GitHubElectron.WebContents>(); | ||
|
||
constructor() { | ||
this._onConnectRequest = this._onConnectRequest.bind(this); | ||
ipcMain.on(ipc.IPC_CONNECT, this._onConnectRequest); | ||
} | ||
|
||
dispose(): void { | ||
ipcMain.removeListener(ipc.IPC_CONNECT, this._onConnectRequest); | ||
this._subscribers.clear(); | ||
} | ||
|
||
add(...sourceDirPaths: string[]): void { | ||
this._dirPaths.push(...sourceDirPaths); | ||
const request: ipc.IUpdateRequest = { kind: 'add', dirPaths: sourceDirPaths }; | ||
this._subscribers.forEach(subscriber => subscriber.send(ipc.IPC_UPDATE, request)); | ||
} | ||
|
||
private _onConnectRequest(event: GitHubElectron.IMainIPCEvent): void { | ||
const webContents = event.sender; | ||
|
||
if (this._subscribers.has(webContents)) { | ||
throw new Error(`Subscriber is already connected.`); | ||
} | ||
this._subscribers.add(webContents); | ||
ipcMain.once(ipc.IPC_DISCONNECT, (event: GitHubElectron.IMainIPCEvent) => { | ||
this._subscribers.delete(event.sender); | ||
}); | ||
const response: ipc.IConnectResponse = { | ||
dirPaths: this._dirPaths | ||
}; | ||
webContents.send(ipc.IPC_CONNECT, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.