SQL Operations Studio Public Preview 1 (0.23) release source code

This commit is contained in:
Karl Burtram
2017-11-09 14:30:27 -08:00
parent b88ecb8d93
commit 3cdac41339
8829 changed files with 759707 additions and 286 deletions

View File

@@ -0,0 +1,93 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import * as Path from 'vs/base/common/paths';
import URI from 'vs/base/common/uri';
import * as Labels from 'vs/base/common/labels';
import * as Platform from 'vs/base/common/platform';
import { Action } from 'vs/base/common/actions';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditor } from 'vs/platform/editor/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
class ConfigureLocaleAction extends Action {
public static ID = 'workbench.action.configureLocale';
public static LABEL = nls.localize('configureLocale', "Configure Language");
private static DEFAULT_CONTENT: string = [
'{',
`\t// ${nls.localize('displayLanguage', 'Defines VSCode\'s display language.')}`,
`\t// ${nls.localize('doc', 'See {0} for a list of supported languages.', 'https://go.microsoft.com/fwlink/?LinkId=761051')}`,
`\t// ${nls.localize('restart', 'Changing the value requires restarting VSCode.')}`,
`\t"locale":"${Platform.language}"`,
'}'
].join('\n');
constructor(id, label,
@IFileService private fileService: IFileService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
}
public run(event?: any): TPromise<IEditor> {
const file = URI.file(Path.join(this.environmentService.appSettingsHome, 'locale.json'));
return this.fileService.resolveFile(file).then(null, (error) => {
return this.fileService.createFile(file, ConfigureLocaleAction.DEFAULT_CONTENT);
}).then((stat) => {
if (!stat) {
return undefined;
}
return this.editorService.openEditor({
resource: stat.resource,
options: {
forceOpen: true
}
});
}, (error) => {
throw new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", Labels.getPathLabel(file, this.contextService), error));
});
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLocaleAction, ConfigureLocaleAction.ID, ConfigureLocaleAction.LABEL), 'Configure Language');
const schemaId = 'vscode://schemas/locale';
// Keep en-US since we generated files with that content.
const schema: IJSONSchema =
{
id: schemaId,
description: 'Locale Definition file',
type: 'object',
default: {
'locale': 'en'
},
required: ['locale'],
properties: {
locale: {
type: 'string',
enum: ['de', 'en', 'en-US', 'es', 'fr', 'it', 'ja', 'ko', 'ru', 'zh-CN', 'zh-TW'],
description: nls.localize('JsonSchema.locale', 'The UI Language to use.')
}
}
};
const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
jsonRegistry.registerSchema(schemaId, schema);

View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.vs .monaco-workbench .toggle-editor-layout {
background-image: url('editor-layout.svg');
}
.vs-dark .monaco-workbench .toggle-editor-layout,
.hc-black .monaco-workbench .toggle-editor-layout {
background-image: url('editor-layout-inverse.svg') !important;
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-bg{fill:#c5c5c5}.icon-vs-fg{fill:#2b282e}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M0 16V0h11v6h5v10H0z" id="outline" style="display: none;"/><path class="icon-vs-fg" d="M4 14H2V4h7v3H4v7zm10 0H5v-4h9v4z" id="iconFg" style="display: none;"/><path class="icon-vs-bg" d="M10 7V1H1v14h14V7h-5zm-6 7H2V4h7v3H4v7zm10 0H5v-4h9v4z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 562 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-bg{fill:#424242}.icon-vs-fg{fill:#f0eff1}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M0 16V0h11v6h5v10H0z" id="outline" style="display: none;"/><path class="icon-vs-fg" d="M4 14H2V4h7v3H4v7zm10 0H5v-4h9v4z" id="iconFg" style="display: none;"/><path class="icon-vs-bg" d="M10 7V1H1v14h14V7h-5zm-6 7H2V4h7v3H4v7zm10 0H5v-4h9v4z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 562 B

View File

@@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
export class ToggleActivityBarVisibilityAction extends Action {
public static ID = 'workbench.action.toggleActivityBarVisibility';
public static LABEL = nls.localize('toggleActivityBar', "Toggle Activity Bar Visibility");
private static activityBarVisibleKey = 'workbench.activityBar.visible';
constructor(
id: string,
label: string,
@IPartService private partService: IPartService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
this.enabled = !!this.partService;
}
public run(): TPromise<any> {
const visibility = this.partService.isVisible(Parts.ACTIVITYBAR_PART);
const newVisibilityValue = !visibility;
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleActivityBarVisibilityAction.activityBarVisibleKey, value: newVisibilityValue });
return TPromise.as(null);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, ToggleActivityBarVisibilityAction.LABEL), 'View: Toggle Activity Bar Visibility', nls.localize('view', "View"));

View File

@@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./media/actions';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IEditorGroupService, GroupOrientation } from 'vs/workbench/services/group/common/groupService';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
export class ToggleEditorLayoutAction extends Action {
public static ID = 'workbench.action.toggleEditorGroupLayout';
public static LABEL = nls.localize('toggleEditorGroupLayout', "Toggle Editor Group Vertical/Horizontal Layout");
private toDispose: IDisposable[];
constructor(
id: string,
label: string,
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(id, label);
this.toDispose = [];
this.class = 'toggle-editor-layout';
this.updateEnablement();
this.updateLabel();
this.registerListeners();
}
private registerListeners(): void {
this.toDispose.push(this.editorGroupService.onEditorsChanged(() => this.updateEnablement()));
this.toDispose.push(this.editorGroupService.onGroupOrientationChanged(() => this.updateLabel()));
}
private updateLabel(): void {
const editorGroupLayoutVertical = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
this.label = editorGroupLayoutVertical ? nls.localize('horizontalLayout', "Horizontal Editor Group Layout") : nls.localize('verticalLayout', "Vertical Editor Group Layout");
}
private updateEnablement(): void {
this.enabled = this.editorGroupService.getStacksModel().groups.length > 0;
}
public run(): TPromise<any> {
const groupOrientiation = this.editorGroupService.getGroupOrientation();
const newGroupOrientation: GroupOrientation = (groupOrientiation === 'vertical') ? 'horizontal' : 'vertical';
this.editorGroupService.setGroupOrientation(newGroupOrientation);
return TPromise.as(null);
}
public dispose(): void {
this.toDispose = dispose(this.toDispose);
super.dispose();
}
}
CommandsRegistry.registerCommand('_workbench.editor.setGroupOrientation', function (accessor: ServicesAccessor, args: [GroupOrientation]) {
const editorGroupService = accessor.get(IEditorGroupService);
const [orientation] = args;
editorGroupService.setGroupOrientation(orientation);
return TPromise.as<void>(null);
});
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
const group = nls.localize('view', "View");
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleEditorLayoutAction, ToggleEditorLayoutAction.ID, ToggleEditorLayoutAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_1, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_1 } }), 'View: Toggle Editor Group Vertical/Horizontal Layout', group);

View File

@@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Position } from 'vs/workbench/services/part/common/partService';
export class ToggleSidebarPositionAction extends Action {
public static ID = 'workbench.action.toggleSidebarPosition';
public static LABEL = nls.localize('toggleLocation', "Toggle Side Bar Location");
private static sidebarPositionConfigurationKey = 'workbench.sideBar.location';
constructor(
id: string,
label: string,
@IPartService private partService: IPartService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
this.enabled = !!this.partService && !!this.configurationEditingService;
}
public run(): TPromise<any> {
const position = this.partService.getSideBarPosition();
const newPositionValue = (position === Position.LEFT) ? 'right' : 'left';
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleSidebarPositionAction.sidebarPositionConfigurationKey, value: newPositionValue });
return TPromise.as(null);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSidebarPositionAction, ToggleSidebarPositionAction.ID, ToggleSidebarPositionAction.LABEL), 'View: Toggle Side Bar Location', nls.localize('view', "View"));

View File

@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
export class ToggleSidebarVisibilityAction extends Action {
public static ID = 'workbench.action.toggleSidebarVisibility';
public static LABEL = nls.localize('toggleSidebar', "Toggle Side Bar Visibility");
constructor(
id: string,
label: string,
@IPartService private partService: IPartService
) {
super(id, label);
this.enabled = !!this.partService;
}
public run(): TPromise<any> {
const hideSidebar = this.partService.isVisible(Parts.SIDEBAR_PART);
return this.partService.setSideBarHidden(hideSidebar);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSidebarVisibilityAction, ToggleSidebarVisibilityAction.ID, ToggleSidebarVisibilityAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_B }), 'View: Toggle Side Bar Visibility', nls.localize('view', "View"));

View File

@@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
export class ToggleStatusbarVisibilityAction extends Action {
public static ID = 'workbench.action.toggleStatusbarVisibility';
public static LABEL = nls.localize('toggleStatusbar', "Toggle Status Bar Visibility");
private static statusbarVisibleKey = 'workbench.statusBar.visible';
constructor(
id: string,
label: string,
@IPartService private partService: IPartService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService
) {
super(id, label);
this.enabled = !!this.partService;
}
public run(): TPromise<any> {
const visibility = this.partService.isVisible(Parts.STATUSBAR_PART);
const newVisibilityValue = !visibility;
this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleStatusbarVisibilityAction.statusbarVisibleKey, value: newVisibilityValue });
return TPromise.as(null);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleStatusbarVisibilityAction, ToggleStatusbarVisibilityAction.ID, ToggleStatusbarVisibilityAction.LABEL), 'View: Toggle Status Bar Visibility', nls.localize('view', "View"));

View File

@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import { Action } from 'vs/base/common/actions';
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { Registry } from 'vs/platform/registry/common/platform';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IPartService } from 'vs/workbench/services/part/common/partService';
class ToggleZenMode extends Action {
public static ID = 'workbench.action.toggleZenMode';
public static LABEL = nls.localize('toggleZenMode', "Toggle Zen Mode");
constructor(
id: string,
label: string,
@IPartService private partService: IPartService
) {
super(id, label);
this.enabled = !!this.partService;
}
public run(): TPromise<any> {
this.partService.toggleZenMode();
return TPromise.as(null);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleZenMode, ToggleZenMode.ID, ToggleZenMode.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_Z) }), 'View: Toggle Zen Mode', nls.localize('view', "View"));

View File

@@ -0,0 +1,290 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import nls = require('vs/nls');
import { distinct } from 'vs/base/common/arrays';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import URI from 'vs/base/common/uri';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspacesService, WORKSPACE_FILTER } from 'vs/platform/workspaces/common/workspaces';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { isLinux } from 'vs/base/common/platform';
import { dirname } from 'vs/base/common/paths';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { isParent } from 'vs/platform/files/common/files';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
export class OpenFolderAction extends Action {
static ID = 'workbench.action.files.openFolder';
static LABEL = nls.localize('openFolder', "Open Folder...");
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService
) {
super(id, label);
}
run(event?: any, data?: ITelemetryData): TPromise<any> {
return this.windowService.pickFolderAndOpen({ telemetryExtraData: data });
}
}
export class OpenFileFolderAction extends Action {
static ID = 'workbench.action.files.openFileFolder';
static LABEL = nls.localize('openFileFolder', "Open...");
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService
) {
super(id, label);
}
run(event?: any, data?: ITelemetryData): TPromise<any> {
return this.windowService.pickFileFolderAndOpen({ telemetryExtraData: data });
}
}
export abstract class BaseWorkspacesAction extends Action {
constructor(
id: string,
label: string,
protected windowService: IWindowService,
protected environmentService: IEnvironmentService,
protected contextService: IWorkspaceContextService
) {
super(id, label);
}
protected pickFolders(buttonLabel: string, title: string): string[] {
const workspace = this.contextService.getWorkspace();
let defaultPath: string;
if (workspace && workspace.roots.length > 0) {
defaultPath = dirname(workspace.roots[0].fsPath); // pick the parent of the first root by default
}
return this.windowService.showOpenDialog({
buttonLabel,
title,
properties: ['multiSelections', 'openDirectory', 'createDirectory'],
defaultPath
});
}
}
export class AddRootFolderAction extends BaseWorkspacesAction {
static ID = 'workbench.action.addRootFolder';
static LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
constructor(
id: string,
label: string,
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IViewletService private viewletService: IViewletService
) {
super(id, label, windowService, environmentService, contextService);
}
public run(): TPromise<any> {
if (!this.contextService.hasWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL, []).run();
}
if (this.contextService.hasFolderWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL, this.contextService.getWorkspace().roots).run();
}
const folders = super.pickFolders(mnemonicButtonLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")), nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"));
if (!folders || !folders.length) {
return TPromise.as(null);
}
return this.workspaceEditingService.addRoots(folders.map(folder => URI.file(folder))).then(() => {
return this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
});
}
}
class NewWorkspaceAction extends BaseWorkspacesAction {
static ID = 'workbench.action.newWorkspace';
static LABEL = nls.localize('newWorkspace', "New Workspace...");
constructor(
id: string,
label: string,
private presetRoots: URI[],
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService protected windowsService: IWindowsService,
) {
super(id, label, windowService, environmentService, contextService);
}
public run(): TPromise<any> {
const folders = super.pickFolders(mnemonicButtonLabel(nls.localize({ key: 'select', comment: ['&& denotes a mnemonic'] }, "&&Select")), nls.localize('selectWorkspace', "Select Folders for Workspace"));
if (folders && folders.length) {
return this.createWorkspace([...this.presetRoots, ...folders.map(folder => URI.file(folder))]);
}
return TPromise.as(null);
}
private createWorkspace(folders: URI[]): TPromise<void> {
const workspaceFolders = distinct(folders.map(folder => folder.fsPath), folder => isLinux ? folder : folder.toLowerCase());
return this.windowService.createAndOpenWorkspace(workspaceFolders);
}
}
export class RemoveRootFolderAction extends Action {
static ID = 'workbench.action.removeRootFolder';
static LABEL = nls.localize('removeFolderFromWorkspace', "Remove Folder from Workspace");
constructor(
private rootUri: URI,
id: string,
label: string,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService
) {
super(id, label);
}
public run(): TPromise<any> {
return this.workspaceEditingService.removeRoots([this.rootUri]);
}
}
export class SaveWorkspaceAsAction extends BaseWorkspacesAction {
static ID = 'workbench.action.saveWorkspaceAs';
static LABEL = nls.localize('saveWorkspaceAsAction', "Save Workspace As...");
constructor(
id: string,
label: string,
@IWindowService windowService: IWindowService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService private windowsService: IWindowsService,
@IMessageService private messageService: IMessageService
) {
super(id, label, windowService, environmentService, contextService);
}
public run(): TPromise<any> {
if (!this.contextService.hasWorkspace()) {
this.messageService.show(Severity.Info, nls.localize('saveEmptyWorkspaceNotSupported', "Please open a workspace first to save."));
return TPromise.as(null);
}
const configPath = this.getNewWorkspaceConfigPath();
if (configPath) {
if (this.contextService.hasFolderWorkspace()) {
return this.saveFolderWorkspace(configPath);
}
if (this.contextService.hasMultiFolderWorkspace()) {
return this.saveWorkspace(configPath);
}
}
return TPromise.as(null);
}
private saveWorkspace(configPath: string): TPromise<void> {
return this.windowService.saveAndOpenWorkspace(configPath);
}
private saveFolderWorkspace(configPath: string): TPromise<void> {
const workspaceFolders = this.contextService.getWorkspace().roots.map(root => root.fsPath);
return this.windowService.createAndOpenWorkspace(workspaceFolders, configPath);
}
private getNewWorkspaceConfigPath(): string {
const workspace = this.contextService.getWorkspace();
let defaultPath: string;
if (this.contextService.hasMultiFolderWorkspace() && !this.isUntitledWorkspace(workspace.configuration.fsPath)) {
defaultPath = workspace.configuration.fsPath;
} else if (workspace && workspace.roots.length > 0) {
defaultPath = dirname(workspace.roots[0].fsPath); // pick the parent of the first root by default
}
return this.windowService.showSaveDialog({
buttonLabel: mnemonicButtonLabel(nls.localize({ key: 'save', comment: ['&& denotes a mnemonic'] }, "&&Save")),
title: nls.localize('saveWorkspace', "Save Workspace"),
filters: WORKSPACE_FILTER,
defaultPath
});
}
private isUntitledWorkspace(path: string): boolean {
return isParent(path, this.environmentService.workspacesHome, !isLinux /* ignore case */);
}
}
export class OpenWorkspaceAction extends Action {
static ID = 'workbench.action.openWorkspace';
static LABEL = nls.localize('openWorkspaceAction', "Open Workspace...");
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService,
) {
super(id, label);
}
public run(): TPromise<any> {
return this.windowService.openWorkspace();
}
}
export class OpenWorkspaceConfigFileAction extends Action {
public static ID = 'workbench.action.openWorkspaceConfigFile';
public static LABEL = nls.localize('openWorkspaceConfigFile', "Open Workspace Configuration File");
constructor(
id: string,
label: string,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
this.enabled = this.workspaceContextService.hasMultiFolderWorkspace();
}
public run(): TPromise<any> {
return this.editorService.openEditor({ resource: this.workspaceContextService.getWorkspace().configuration });
}
}