提交 5d429192 编写于 作者: B Benjamin Pasero

debt - fix some layer breakers in workbench

上级 217f9622
......@@ -27,7 +27,7 @@ import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/
import { IEditorAction, ICommonCodeEditor, IModelContentChangedEvent, IModelOptionsChangedEvent, IModelLanguageChangedEvent, ICursorPositionChangedEvent, EndOfLineSequence, EditorType, IModel, IDiffEditorModel, IEditor } from 'vs/editor/common/editorCommon';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/common/linesOperations';
import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/workbench/parts/indentation/common/indentation';
import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/workbench/common/editor/indentation';
import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor';
import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor';
import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/editor';
......@@ -42,10 +42,9 @@ import { StyleMutator } from 'vs/base/browser/styleMutator';
import { Selection } from 'vs/editor/common/core/selection';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { TabFocus } from 'vs/editor/common/config/commonEditorConfig';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IExtensionsViewlet, VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { getCodeEditor as getEditorWidget } from 'vs/editor/common/services/codeEditorService';
function getCodeEditor(editorWidget: IEditor): ICommonCodeEditor {
......@@ -680,24 +679,20 @@ function isWritableCodeEditor(e: IBaseEditor): boolean {
export class ShowLanguageExtensionsAction extends Action {
static ID = 'workbench.extensions.action.showLanguageExtensions';
static ID = 'workbench.action.showLanguageExtensions';
constructor(
private extension: string,
@IViewletService private viewletService: IViewletService,
private fileExtension: string,
@ICommandService private commandService: ICommandService,
@IExtensionGalleryService galleryService: IExtensionGalleryService
) {
super(ShowLanguageExtensionsAction.ID, nls.localize('showLanguageExtensions', "Search Marketplace Extensions for '{0}'...", extension), null, true);
super(ShowLanguageExtensionsAction.ID, nls.localize('showLanguageExtensions', "Search Marketplace Extensions for '{0}'...", fileExtension));
this.enabled = galleryService.isEnabled();
}
run(): TPromise<void> {
return this.viewletService.openViewlet(VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search(`ext:${this.extension.replace(/^\./, '')}`);
viewlet.focus();
});
return this.commandService.executeCommand('workbench.extensions.action.showLanguageExtensions', this.fileExtension).then(() => void 0);
}
}
......
......@@ -5,11 +5,12 @@
import * as nls from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { ICommonCodeEditor, EditorContextKeys } from 'vs/editor/common/editorCommon';
import { ICommonCodeEditor, EditorContextKeys, ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, IActionOptions, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/parts/indentation/common/indentationCommands';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IModelService } from 'vs/editor/common/services/modelService';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
@editorAction
export class IndentationToSpacesAction extends EditorAction {
......@@ -160,3 +161,61 @@ export class DetectIndentation extends EditorAction {
model.detectIndentation(creationOpts.insertSpaces, creationOpts.tabSize);
}
}
function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void {
if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
// Model is empty
return;
}
let spaces = '';
for (let i = 0; i < tabSize; i++) {
spaces += ' ';
}
const content = model.getLinesContent();
for (let i = 0; i < content.length; i++) {
let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1);
if (lastIndentationColumn === 0) {
lastIndentationColumn = model.getLineMaxColumn(i + 1);
}
const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) :
content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) +
content[i].substr(lastIndentationColumn);
builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text);
}
}
export class IndentationToSpacesCommand implements ICommand {
private selectionId: string;
constructor(private selection: Selection, private tabSize: number) { }
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
this.selectionId = builder.trackSelection(this.selection);
getIndentationEditOperations(model, builder, this.tabSize, true);
}
public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
return helper.getTrackedSelection(this.selectionId);
}
}
export class IndentationToTabsCommand implements ICommand {
private selectionId: string;
constructor(private selection: Selection, private tabSize: number) { }
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
this.selectionId = builder.trackSelection(this.selection);
getIndentationEditOperations(model, builder, this.tabSize, false);
}
public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
return helper.getTrackedSelection(this.selectionId);
}
}
......@@ -81,7 +81,6 @@ import 'vs/workbench/parts/emmet/browser/emmet.browser.contribution';
import 'vs/workbench/parts/emmet/node/emmet.contribution';
// Code Editor enhacements
import 'vs/workbench/parts/indentation/common/indentation';
import 'vs/workbench/parts/codeEditor/codeEditor.contribution';
import 'vs/workbench/parts/execution/electron-browser/execution.contribution';
......
......@@ -18,7 +18,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewlet } from 'vs/workbench/parts/extensions/common/extensions';
import { ExtensionsConfigurationInitialContent } from 'vs/workbench/parts/extensions/common/extensionsFileTemplate';
import { LocalExtensionType, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService } from 'vs/platform/message/common/message';
import { ToggleViewletAction } from 'vs/workbench/browser/viewlet';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
......@@ -29,7 +29,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IExtensionService, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import URI from 'vs/base/common/uri';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
export class InstallAction extends Action {
......@@ -1290,4 +1290,15 @@ export class EnableAllWorkpsaceAction extends Action {
super.dispose();
this.disposables = dispose(this.disposables);
}
}
\ No newline at end of file
}
CommandsRegistry.registerCommand('workbench.extensions.action.showLanguageExtensions', function (accessor: ServicesAccessor, fileExtension: string) {
const viewletService = accessor.get(IViewletService);
return viewletService.openViewlet(VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search(`ext:${fileExtension.replace(/^\./, '')}`);
viewlet.focus();
});
});
......@@ -149,7 +149,7 @@ const enableAllWorkspaceAction = new SyncActionDescriptor(EnableAllWorkpsaceActi
actionRegistry.registerWorkbenchAction(enableAllWorkspaceAction, 'Extensions: Enable All (Workspace)', ExtensionsLabel);
const checkForUpdatesAction = new SyncActionDescriptor(CheckForUpdatesAction, CheckForUpdatesAction.ID, CheckForUpdatesAction.LABEL);
actionRegistry.registerWorkbenchAction(checkForUpdatesAction, `Extensions: ${CheckForUpdatesAction.LABEL}`, ExtensionsLabel);
actionRegistry.registerWorkbenchAction(checkForUpdatesAction, `Extensions: Check for Updates`, ExtensionsLabel);
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Range } from 'vs/editor/common/core/range';
import { ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel } from 'vs/editor/common/editorCommon';
import { Selection } from 'vs/editor/common/core/selection';
function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void {
if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
// Model is empty
return;
}
let spaces = '';
for (let i = 0; i < tabSize; i++) {
spaces += ' ';
}
const content = model.getLinesContent();
for (let i = 0; i < content.length; i++) {
let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1);
if (lastIndentationColumn === 0) {
lastIndentationColumn = model.getLineMaxColumn(i + 1);
}
const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) :
content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) +
content[i].substr(lastIndentationColumn);
builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text);
}
}
export class IndentationToSpacesCommand implements ICommand {
private selectionId: string;
constructor(private selection: Selection, private tabSize: number) { }
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
this.selectionId = builder.trackSelection(this.selection);
getIndentationEditOperations(model, builder, this.tabSize, true);
}
public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
return helper.getTrackedSelection(this.selectionId);
}
}
export class IndentationToTabsCommand implements ICommand {
private selectionId: string;
constructor(private selection: Selection, private tabSize: number) { }
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
this.selectionId = builder.trackSelection(this.selection);
getIndentationEditOperations(model, builder, this.tabSize, false);
}
public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
return helper.getTrackedSelection(this.selectionId);
}
}
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Selection } from 'vs/editor/common/core/selection';
import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/parts/indentation/common/indentationCommands';
import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/common/editor/indentation';
import { testCommand } from 'vs/editor/test/common/commands/commandTestUtils';
function testIndentationToSpacesCommand(lines: string[], selection: Selection, tabSize: number, expectedLines: string[], expectedSelection: Selection): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册