Example #1
0
	public startWatching(): () => void {
		if (this.contextService.getWorkspace().folders[0].uri.scheme !== Schemas.file) {
			return () => { };
		}
		let basePath: string = normalize(this.contextService.getWorkspace().folders[0].uri.fsPath);

		if (basePath && basePath.indexOf('\\\\') === 0 && endsWith(basePath, sep)) {
			// for some weird reason, node adds a trailing slash to UNC paths
			// we never ever want trailing slashes as our base path unless
			// someone opens root ("/").
			// See also https://github.com/nodejs/io.js/issues/1765
			basePath = rtrim(basePath, sep);
		}

		const watcher = new OutOfProcessWin32FolderWatcher(
			basePath,
			this.ignored,
			events => this.onRawFileEvents(events),
			error => this.onError(error),
			this.verboseLogging
		);

		return () => {
			this.isDisposed = true;
			watcher.dispose();
		};
	}
Example #2
0
export function getRootPath(contextService: IWorkspaceContextService): string {
	let isWorkspace = contextService.getWorkbenchState() === WorkbenchState.WORKSPACE;
	if (isWorkspace) {
		return contextService.getWorkspace().folders[0].uri.fsPath;
	}

	return undefined;
}
Example #3
0
function revealResourcesInOS(resources: URI[], windowsService: IWindowsService, notificationService: INotificationService, workspaceContextService: IWorkspaceContextService): void {
	if (resources.length) {
		sequence(resources.map(r => () => windowsService.showItemInFolder(paths.normalize(r.fsPath, true))));
	} else if (workspaceContextService.getWorkspace().folders.length) {
		windowsService.showItemInFolder(paths.normalize(workspaceContextService.getWorkspace().folders[0].uri.fsPath, true));
	} else {
		notificationService.info(nls.localize('openFileToReveal', "Open a file first to reveal"));
	}
}
Example #4
0
export function defaultWorkspacePath(contextService: IWorkspaceContextService, historyService: IHistoryService, environmentService: IEnvironmentService): string {

	// Check for current workspace config file first...
	if (contextService.getWorkbenchState() === WorkbenchState.WORKSPACE && !isUntitledWorkspace(contextService.getWorkspace().configuration.fsPath, environmentService)) {
		return dirname(contextService.getWorkspace().configuration.fsPath);
	}

	// ...then fallback to default folder path
	return defaultFolderPath(contextService, historyService);
}
Example #5
0
	private registerListeners(): void {

		// Workspace Folder Change
		this._register(this.contextService.onDidChangeWorkspaceFolders(() => {
			this.encodingOverride = this.getEncodingOverrides();
		}));
	}
Example #6
0
export function loadExperiments(contextService: IWorkspaceContextService, storageService: IStorageService, configurationService: IConfigurationService): ITelemetryExperiments {

	const key = 'experiments.randomness';
	let valueString = storageService.get(key);
	if (!valueString) {
		valueString = Math.random().toString();
		storageService.store(key, valueString);
	}

	const random1 = parseFloat(valueString);
	let [random2, showNewUserWatermark] = splitRandom(random1);
	let [random3, openUntitledFile] = splitRandom(random2);
	let [, openGettingStarted] = splitRandom(random3);

	const newUserDuration = 24 * 60 * 60 * 1000;
	const firstSessionDate = storageService.get('telemetry.firstSessionDate');
	const isNewUser = !firstSessionDate || Date.now() - Date.parse(firstSessionDate) < newUserDuration;
	if (!isNewUser || contextService.hasWorkspace()) {
		showNewUserWatermark = defaultExperiments.showNewUserWatermark;
		openUntitledFile = defaultExperiments.openUntitledFile;
	}

	const isNewSession = !storageService.get('telemetry.lastSessionDate');
	const now = Date.now();
	if (!(isNewSession && now >= beginGettingStartedExp && now < endGettingStartedExp)) {
		openGettingStarted = undefined;
	}

	return applyOverrides(configurationService, {
		showNewUserWatermark,
		openUntitledFile,
		openGettingStarted
	});
}
Example #7
0
	public confirm(confirmation: IConfirmation): boolean {
		if (!confirmation.primaryButton) {
			confirmation.primaryButton = nls.localize({ key: 'yesButton', comment: ['&& denotes a mnemonic'] }, "&&Yes");
		}

		if (!confirmation.secondaryButton) {
			confirmation.secondaryButton = nls.localize('cancelButton', "Cancel");
		}

		let opts: Electron.Dialog.ShowMessageBoxOptions = {
			title: confirmation.title || this.contextService.getConfiguration().env.appName,
			message: confirmation.message,
			buttons: [
				this.mnemonicLabel(confirmation.primaryButton),
				this.mnemonicLabel(confirmation.secondaryButton)
			],
			noLink: true,
			cancelId: 1
		};

		if (confirmation.detail) {
			opts.detail = confirmation.detail;
		}

		let result = this.windowService.getWindow().showMessageBox(opts);

		return result === 0 ? true : false;
	}
Example #8
0
	public confirm(confirmation: IConfirmation): boolean {
		if (!confirmation.primaryButton) {
			confirmation.primaryButton = nls.localize('yesButton', "Yes");
		}

		if (!confirmation.secondaryButton) {
			confirmation.secondaryButton = nls.localize('cancelButton', "Cancel");
		}

		let opts: remote.IMessageBoxOptions = {
			title: confirmation.title || this.contextService.getConfiguration().env.appName,
			message: confirmation.message,
			buttons: [
				confirmation.primaryButton,
				confirmation.secondaryButton
			],
			noLink: true,
			cancelId: 1
		};

		if (confirmation.detail) {
			opts.detail = confirmation.detail;
		}

		let result = this.windowService.getWindow().showMessageBox(opts);

		return result === 0 ? true : false;
	}
Example #9
0
	// Optional workspaceRoot there to be used in tests.
	constructor(
		private editorService: IWorkbenchEditorService,
		contextService: IWorkspaceContextService,
		environmentService: IEnvironmentService,
		workspaceRoot: URI = null,
		envVariables: { [key: string]: string } = process.env
	) {
		super();
		let fsPath = '';
		if (workspaceRoot || (contextService && contextService.getWorkspace())) {
			fsPath = workspaceRoot ? workspaceRoot.fsPath : contextService.getWorkspace().resource.fsPath;
		}
		this._workspaceRoot = Paths.normalize(fsPath, true);
		this._execPath = environmentService.execPath;
		Object.keys(envVariables).forEach(key => {
			this[`env.${key}`] = envVariables[key];
		});
	}
Example #10
0
export function getSettingsTargetName(target: ConfigurationTarget, resource: URI, workspaceContextService: IWorkspaceContextService): string {
	switch (target) {
		case ConfigurationTarget.USER:
			return localize('userSettingsTarget', "User Settings");
		case ConfigurationTarget.WORKSPACE:
			return localize('workspaceSettingsTarget', "Workspace Settings");
		case ConfigurationTarget.FOLDER:
			const root = workspaceContextService.getRoot(resource);
			return root ? paths.basename(root.fsPath) : '';
	}
}