2019-01-22 19:27:59 +01:00
|
|
|
import * as paths from "./fill/paths";
|
2019-01-31 17:59:18 +01:00
|
|
|
import "./fill/platform";
|
2019-01-18 22:46:40 +01:00
|
|
|
import "./fill/storageDatabase";
|
|
|
|
import "./fill/windowsService";
|
2019-02-21 18:55:42 +01:00
|
|
|
import "./fill/workspacesService";
|
2019-01-22 19:27:59 +01:00
|
|
|
import "./fill/environmentService";
|
2019-01-28 18:14:06 +01:00
|
|
|
import "./fill/vscodeTextmate";
|
2019-02-01 19:17:29 +01:00
|
|
|
import "./fill/codeEditor";
|
2019-02-01 19:32:42 +01:00
|
|
|
import "./fill/mouseEvent";
|
2019-02-04 18:27:36 +01:00
|
|
|
import "./fill/menuRegistry";
|
|
|
|
import "./fill/workbenchRegistry";
|
2019-01-31 00:46:17 +01:00
|
|
|
import { PasteAction } from "./fill/paste";
|
2019-01-19 01:04:24 +01:00
|
|
|
import "./fill/dom";
|
|
|
|
import "./vscode.scss";
|
2019-02-06 17:38:58 +01:00
|
|
|
import { IdeClient, IProgress, INotificationHandle } from "@coder/ide";
|
2019-01-18 22:46:40 +01:00
|
|
|
import { registerContextMenuListener } from "vs/base/parts/contextmenu/electron-main/contextmenu";
|
|
|
|
import { LogLevel } from "vs/platform/log/common/log";
|
|
|
|
import { URI } from "vs/base/common/uri";
|
2019-01-30 22:40:01 +01:00
|
|
|
import { INotificationService } from "vs/platform/notification/common/notification";
|
|
|
|
import { IProgressService2, ProgressLocation } from "vs/platform/progress/common/progress";
|
2019-02-21 18:55:42 +01:00
|
|
|
import { ExplorerItem, ExplorerModel } from "vs/workbench/parts/files/common/explorerModel";
|
2019-01-30 22:40:01 +01:00
|
|
|
import { DragMouseEvent } from "vs/base/browser/mouseEvent";
|
|
|
|
import { IEditorService, IResourceEditor } from "vs/workbench/services/editor/common/editorService";
|
|
|
|
import { IEditorGroup } from "vs/workbench/services/group/common/editorGroupsService";
|
2019-02-21 18:55:42 +01:00
|
|
|
import { IWindowsService, IWindowConfiguration } from "vs/platform/windows/common/windows";
|
2019-01-30 22:40:01 +01:00
|
|
|
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
2019-01-30 23:57:22 +01:00
|
|
|
import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
|
2019-02-21 18:55:42 +01:00
|
|
|
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
|
2019-01-18 22:46:40 +01:00
|
|
|
|
2019-02-06 17:18:24 +01:00
|
|
|
export class Client extends IdeClient {
|
2019-01-30 20:27:21 +01:00
|
|
|
private readonly windowId = parseInt(new Date().toISOString().replace(/[-:.TZ]/g, ""), 10);
|
2019-01-30 22:40:01 +01:00
|
|
|
private _serviceCollection: ServiceCollection | undefined;
|
2019-01-30 23:57:22 +01:00
|
|
|
private _clipboardContextKey: RawContextKey<boolean> | undefined;
|
2019-02-06 18:01:15 +01:00
|
|
|
private _builtInExtensionsDirectory: string | undefined;
|
|
|
|
|
|
|
|
public get builtInExtensionsDirectory(): string {
|
|
|
|
if (!this._builtInExtensionsDirectory) {
|
|
|
|
throw new Error("trying to access builtin extensions directory before it has been set");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._builtInExtensionsDirectory;
|
|
|
|
}
|
2019-01-30 22:40:01 +01:00
|
|
|
|
2019-02-21 19:43:49 +01:00
|
|
|
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
|
2019-01-30 22:40:01 +01:00
|
|
|
await this.upload.uploadDropped(
|
2019-02-21 19:43:49 +01:00
|
|
|
originalEvent,
|
2019-01-30 22:40:01 +01:00
|
|
|
(target instanceof ExplorerItem ? target : target.roots[0]).resource,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup, afterDrop: (targetGroup: IEditorGroup) => void, targetIndex?: number): void {
|
|
|
|
this.initData.then((d) => {
|
|
|
|
this.upload.uploadDropped(event, URI.file(d.workingDirectory)).then((paths) => {
|
|
|
|
const uris = paths.map((p) => URI.file(p));
|
|
|
|
if (uris.length) {
|
|
|
|
(this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris);
|
|
|
|
}
|
|
|
|
|
|
|
|
const editors: IResourceEditor[] = uris.map(uri => ({
|
|
|
|
resource: uri,
|
|
|
|
options: {
|
|
|
|
pinned: true,
|
|
|
|
index: targetIndex,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const targetGroup = resolveTargetGroup();
|
|
|
|
|
|
|
|
(this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup).then(() => {
|
|
|
|
afterDrop(targetGroup);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-30 23:57:22 +01:00
|
|
|
/**
|
|
|
|
* Use to toggle the paste option inside editors based on the native clipboard.
|
|
|
|
*/
|
|
|
|
public get clipboardContextKey(): RawContextKey<boolean> {
|
|
|
|
if (!this._clipboardContextKey) {
|
|
|
|
throw new Error("Trying to access clipboard context key before it has been set");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._clipboardContextKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get clipboardText(): Promise<string> {
|
|
|
|
return this.clipboard.readText();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a paste action for use in text inputs.
|
|
|
|
*/
|
2019-01-31 00:46:17 +01:00
|
|
|
public get pasteAction(): PasteAction {
|
|
|
|
return new PasteAction();
|
2019-01-30 23:57:22 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:55:42 +01:00
|
|
|
public set workspace(ws: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined) {
|
|
|
|
if (typeof ws === "undefined") {
|
|
|
|
window.localStorage.removeItem("workspace");
|
|
|
|
} else {
|
|
|
|
window.localStorage.setItem("workspace", JSON.stringify(ws));
|
|
|
|
}
|
|
|
|
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
public get workspace(): undefined | IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier {
|
|
|
|
const ws = window.localStorage.getItem("workspace");
|
|
|
|
try {
|
|
|
|
return JSON.parse(ws!);
|
|
|
|
} catch (ex) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 22:40:01 +01:00
|
|
|
public get serviceCollection(): ServiceCollection {
|
|
|
|
if (!this._serviceCollection) {
|
|
|
|
throw new Error("Trying to access service collection before it has been set");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._serviceCollection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public set serviceCollection(collection: ServiceCollection) {
|
|
|
|
this._serviceCollection = collection;
|
|
|
|
this.progressService = {
|
|
|
|
start: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
|
|
|
|
let lastProgress = 0;
|
|
|
|
|
|
|
|
return (this.serviceCollection.get(IProgressService2) as IProgressService2).withProgress({
|
|
|
|
location: ProgressLocation.Notification,
|
|
|
|
title,
|
|
|
|
cancellable: true,
|
|
|
|
}, (progress) => {
|
|
|
|
return task({
|
|
|
|
report: (p): void => {
|
|
|
|
progress.report({ increment: p - lastProgress });
|
|
|
|
lastProgress = p;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, () => {
|
|
|
|
onCancel();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.notificationService = {
|
|
|
|
error: (error: Error): void => (this.serviceCollection.get(INotificationService) as INotificationService).error(error),
|
|
|
|
prompt: (severity, message, buttons, onCancel): INotificationHandle => {
|
|
|
|
const handle = (this.serviceCollection.get(INotificationService) as INotificationService).prompt(
|
|
|
|
severity, message, buttons, { onCancel },
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
close: (): void => handle.close(),
|
|
|
|
updateMessage: (message): void => handle.updateMessage(message),
|
|
|
|
updateButtons: (buttons): void => handle.updateActions({
|
|
|
|
primary: buttons.map((button) => ({
|
|
|
|
id: "",
|
|
|
|
label: button.label,
|
|
|
|
tooltip: "",
|
|
|
|
class: undefined,
|
|
|
|
enabled: true,
|
|
|
|
checked: false,
|
|
|
|
radio: false,
|
|
|
|
dispose: (): void => undefined,
|
|
|
|
run: (): Promise<void> => Promise.resolve(button.run()),
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:13:04 +01:00
|
|
|
protected initialize(): Promise<void> {
|
|
|
|
registerContextMenuListener();
|
2019-01-18 22:46:40 +01:00
|
|
|
|
2019-01-30 23:57:22 +01:00
|
|
|
this._clipboardContextKey = new RawContextKey("nativeClipboard", this.clipboard.isEnabled);
|
|
|
|
|
2019-02-06 23:55:29 +01:00
|
|
|
return this.task("Start workbench", 1000, async (data, sharedData) => {
|
|
|
|
paths._paths.initialize(data, sharedData);
|
2019-02-06 18:01:15 +01:00
|
|
|
this._builtInExtensionsDirectory = data.builtInExtensionsDirectory;
|
2019-01-28 18:14:06 +01:00
|
|
|
process.env.SHELL = data.shell;
|
2019-01-18 22:46:40 +01:00
|
|
|
|
2019-02-21 18:55:42 +01:00
|
|
|
const workspace = this.workspace || URI.file(data.workingDirectory);
|
|
|
|
const { startup } = require("./startup") as typeof import("vs/workbench/electron-browser/main");
|
|
|
|
const config: IWindowConfiguration = {
|
2019-01-18 22:46:40 +01:00
|
|
|
machineId: "1",
|
|
|
|
windowId: this.windowId,
|
|
|
|
logLevel: LogLevel.Info,
|
|
|
|
mainPid: 1,
|
2019-01-22 19:27:59 +01:00
|
|
|
appRoot: data.dataDirectory,
|
|
|
|
execPath: data.tmpDirectory,
|
2019-01-18 22:46:40 +01:00
|
|
|
userEnv: {},
|
2019-01-22 19:27:59 +01:00
|
|
|
nodeCachedDataDir: data.tmpDirectory,
|
2019-01-18 22:46:40 +01:00
|
|
|
perfEntries: [],
|
|
|
|
_: [],
|
2019-02-21 18:55:42 +01:00
|
|
|
};
|
|
|
|
if ((workspace as IWorkspaceIdentifier).configPath) {
|
|
|
|
config.workspace = workspace as IWorkspaceIdentifier;
|
|
|
|
} else {
|
|
|
|
config.folderUri = workspace as URI;
|
|
|
|
}
|
|
|
|
await startup(config);
|
2019-01-30 23:57:22 +01:00
|
|
|
const contextKeys = this.serviceCollection.get(IContextKeyService) as IContextKeyService;
|
|
|
|
const bounded = this.clipboardContextKey.bindTo(contextKeys);
|
|
|
|
this.clipboard.onPermissionChange((enabled) => {
|
|
|
|
bounded.set(enabled);
|
|
|
|
});
|
2019-01-18 22:46:40 +01:00
|
|
|
this.clipboard.initialize();
|
2019-02-06 23:55:29 +01:00
|
|
|
}, this.initData, this.sharedProcessData);
|
2019-01-18 22:46:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const client = new Client();
|