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

grid - some cleanup

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