提交 8bb9ce0c 编写于 作者: B Benjamin Pasero

grid - some cleanup

上级 d2baa66b
......@@ -48,9 +48,14 @@ export interface ICodeEditorService {
}
/**
* Uses `editor.getControl()` and returns either a `codeEditor` or a `diffEditor` or nothing.
* Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing.
*/
export function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEditor: ICodeEditor; diffEditor: IDiffEditor } {
export function getCodeEditor(editor: { getControl: () => any }): ICodeEditor {
let r = getCodeOrDiffEditor(editor);
return r.codeEditor || (r.diffEditor && <ICodeEditor>r.diffEditor.getModifiedEditor()) || null;
}
function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEditor: ICodeEditor; diffEditor: IDiffEditor } {
if (editor) {
let control = editor.getControl();
if (control) {
......@@ -74,11 +79,3 @@ export function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEd
diffEditor: null
};
}
/**
* Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing.
*/
export function getCodeEditor(editor: { getControl: () => any }): ICodeEditor {
let r = getCodeOrDiffEditor(editor);
return r.codeEditor || (r.diffEditor && <ICodeEditor>r.diffEditor.getModifiedEditor()) || null;
}
......@@ -8,8 +8,7 @@ import { IAction, IActionRunner, ActionRunner } from 'vs/base/common/actions';
import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { Component } from 'vs/workbench/common/component';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IComposite } from 'vs/workbench/common/composite';
import { IEditorControl } from 'vs/workbench/common/editor';
import { IComposite, ICompositeControl } from 'vs/workbench/common/composite';
import { Event, Emitter } from 'vs/base/common/event';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -193,7 +192,7 @@ export abstract class Composite extends Component implements IComposite {
/**
* Returns the underlying composite control or null if it is not accessible.
*/
public getControl(): IEditorControl {
public getControl(): ICompositeControl {
return null;
}
......
......@@ -35,7 +35,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import URI from 'vs/base/common/uri';
import { getCodeOrDiffEditor } from 'vs/editor/browser/services/codeEditorService';
import { once } from 'vs/base/common/event';
import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/nextEditorService';
import { INextEditorGroup, INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
......@@ -150,7 +149,7 @@ export class TextDiffEditor extends BaseTextEditor {
}
// Set Editor Model
const diffEditor = <IDiffEditor>this.getControl();
const diffEditor = this.getControl();
diffEditor.setModel((<TextDiffEditorModel>resolvedModel).textDiffEditorModel);
// Apply Options from TextOptions
......@@ -192,7 +191,7 @@ export class TextDiffEditor extends BaseTextEditor {
public setOptions(options: EditorOptions): void {
const textOptions = <TextEditorOptions>options;
if (textOptions && types.isFunction(textOptions.apply)) {
textOptions.apply(<IDiffEditor>this.getControl(), ScrollType.Smooth);
textOptions.apply(this.getControl(), ScrollType.Smooth);
}
}
......@@ -367,12 +366,8 @@ export class TextDiffEditor extends BaseTextEditor {
}
private retrieveTextDiffEditorViewState(resource: URI): IDiffEditorViewState {
const editor = getCodeOrDiffEditor(this).diffEditor;
if (!editor) {
return null; // not supported for non-diff editors
}
const model = editor.getModel();
const control = this.getControl();
const model = control.getModel();
if (!model || !model.modified || !model.original) {
return null; // view state always needs a model
}
......@@ -386,7 +381,7 @@ export class TextDiffEditor extends BaseTextEditor {
return null; // prevent saving view state for a model that is not the expected one
}
return editor.saveViewState();
return control.saveViewState();
}
private toDiffEditorViewStateResource(modelOrInput: IDiffEditorModel | DiffEditorInput): URI {
......
......@@ -20,11 +20,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Scope } from 'vs/workbench/common/memento';
import { getCodeEditor, getCodeOrDiffEditor } from 'vs/editor/browser/services/codeEditorService';
import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService';
import { ITextFileService, SaveReason, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { isDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { isDiffEditor, isCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
......@@ -238,12 +238,8 @@ export abstract class BaseTextEditor extends BaseEditor {
}
protected retrieveTextEditorViewState(resource: URI): IEditorViewState {
const editor = getCodeOrDiffEditor(this).codeEditor;
if (!editor) {
return null; // not supported for diff editors
}
const model = editor.getModel();
const control = this.getControl() as ICodeEditor;
const model = control.getModel();
if (!model) {
return null; // view state always needs a model
}
......@@ -257,7 +253,7 @@ export abstract class BaseTextEditor extends BaseEditor {
return null; // prevent saving view state for a model that is not the expected one
}
return editor.saveViewState();
return control.saveViewState();
}
/**
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { IAction, IActionItem } from 'vs/base/common/actions';
import { IEditorControl } from 'vs/workbench/common/editor';
export interface IComposite {
......@@ -41,10 +40,15 @@ export interface IComposite {
/**
* Returns the underlying control of this composite.
*/
getControl(): IEditorControl;
getControl(): ICompositeControl;
/**
* Asks the underlying control to focus.
*/
focus(): void;
}
/**
* Marker interface for the composite control
*/
export interface ICompositeControl { }
......@@ -19,6 +19,7 @@ import { ITextModel } from 'vs/editor/common/model';
import { Schemas } from 'vs/base/common/network';
import { LRUCache } from 'vs/base/common/map';
import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { ICompositeControl } from 'vs/workbench/common/composite';
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated();
......@@ -79,7 +80,7 @@ export interface IEditor {
/**
* Marker interface for the editor control
*/
export interface IEditorControl { }
export interface IEditorControl extends ICompositeControl { }
export interface IFileInputFactory {
......
......@@ -15,7 +15,7 @@ import { IDebugService, IEnablement, CONTEXT_BREAKPOINTS_FOCUSED, CONTEXT_WATCH_
import { Expression, Variable, Breakpoint, FunctionBreakpoint } from 'vs/workbench/parts/debug/common/debugModel';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
......@@ -54,10 +54,8 @@ export function registerCommands(): void {
handler: (accessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(INextEditorService);
const editor = editorService.activeControl;
const control = <ICodeEditor>editor.getControl();
if (control) {
const control = editorService.activeTextEditorControl;
if (isCodeEditor(control)) {
const model = control.getModel();
if (model) {
const position = control.getPosition();
......@@ -203,9 +201,8 @@ export function registerCommands(): void {
const inlineBreakpointHandler = (accessor: ServicesAccessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(INextEditorService);
const editor = editorService.activeControl;
const control = editor && <ICodeEditor>editor.getControl();
if (control) {
const control = editorService.activeTextEditorControl;
if (isCodeEditor(control)) {
const position = control.getPosition();
const modelUri = control.getModel().uri;
const bp = debugService.getModel().getBreakpoints({ lineNumber: position.lineNumber, uri: modelUri })
......
......@@ -328,20 +328,17 @@ export class ConfigurationManager implements IConfigurationManager {
return TPromise.as(adapter);
}
const editor = this.editorService.activeControl;
const codeEditor = this.editorService.activeTextEditorControl;
let candidates: Debugger[];
if (editor) {
const codeEditor = editor.getControl();
if (isCodeEditor(codeEditor)) {
const model = codeEditor.getModel();
const language = model ? model.getLanguageIdentifier().language : undefined;
const adapters = this.debuggers.filter(a => a.languages && a.languages.indexOf(language) >= 0);
if (adapters.length === 1) {
return TPromise.as(adapters[0]);
}
if (adapters.length > 1) {
candidates = adapters;
}
if (isCodeEditor(codeEditor)) {
const model = codeEditor.getModel();
const language = model ? model.getLanguageIdentifier().language : undefined;
const adapters = this.debuggers.filter(a => a.languages && a.languages.indexOf(language) >= 0);
if (adapters.length === 1) {
return TPromise.as(adapters[0]);
}
if (adapters.length > 1) {
candidates = adapters;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册