提交 1d30452c 编写于 作者: B Benjamin Pasero

grid - add and use IEditorService.editors

上级 6bb20cb3
......@@ -11,7 +11,6 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import * as errors from 'vs/base/common/errors';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
......@@ -29,7 +28,6 @@ export class BackupRestorer implements IWorkbenchContribution {
@INextEditorService private editorService: INextEditorService,
@IBackupFileService private backupFileService: IBackupFileService,
@ITextFileService private textFileService: ITextFileService,
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IFileService private fileService: IFileService
) {
......@@ -82,7 +80,7 @@ export class BackupRestorer implements IWorkbenchContribution {
}
private doOpenEditors(resources: URI[]): TPromise<void> {
const hasOpenedEditors = this.editorGroupService.count > 0;
const hasOpenedEditors = this.editorService.visibleEditors.length > 0;
const inputs = resources.map((resource, index) => this.resolveInput(resource, index, hasOpenedEditors));
// Open all remaining backups as editors and resolve them to load their backups
......
......@@ -189,29 +189,27 @@ export class FileEditorTracker implements IWorkbenchContribution {
private getOpenedFileEditors(dirtyState: boolean): FileEditorInput[] {
const editors: FileEditorInput[] = [];
this.editorGroupService.groups.forEach(group => {
group.editors.forEach(editor => {
if (editor instanceof FileEditorInput) {
if (!!editor.isDirty() === dirtyState) {
editors.push(editor);
}
} else if (editor instanceof SideBySideEditorInput) {
const master = editor.master;
const details = editor.details;
this.editorService.editors.forEach(editor => {
if (editor instanceof FileEditorInput) {
if (!!editor.isDirty() === dirtyState) {
editors.push(editor);
}
} else if (editor instanceof SideBySideEditorInput) {
const master = editor.master;
const details = editor.details;
if (master instanceof FileEditorInput) {
if (!!master.isDirty() === dirtyState) {
editors.push(master);
}
if (master instanceof FileEditorInput) {
if (!!master.isDirty() === dirtyState) {
editors.push(master);
}
}
if (details instanceof FileEditorInput) {
if (!!details.isDirty() === dirtyState) {
editors.push(details);
}
if (details instanceof FileEditorInput) {
if (!!details.isDirty() === dirtyState) {
editors.push(details);
}
}
});
}
});
return editors;
......
......@@ -90,7 +90,7 @@ export class DirtyFilesTracker implements IWorkbenchContribution {
private doOpenDirtyResources(resources: URI[]): void {
const activeEditor = this.editorService.activeControl;
const activeGroup = activeEditor ? activeEditor.group : this.editorGroupService.activeGroup.id;
const activeGroup = activeEditor ? activeEditor.group : this.editorGroupService.activeGroup;
// Open
this.editorService.openEditors(resources.map(resource => {
......
......@@ -16,7 +16,6 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
import { FileOperationResult, FileOperationError } from 'vs/platform/files/common/files';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { IModelService } from 'vs/editor/common/services/modelService';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
function toResource(self, path) {
return URI.file(join('C:\\', Buffer.from(self.test.fullTitle()).toString('base64'), path));
......@@ -26,8 +25,7 @@ class ServiceAccessor {
constructor(
@INextEditorService public editorService: INextEditorService,
@ITextFileService public textFileService: TestTextFileService,
@IModelService public modelService: IModelService,
@INextEditorGroupsService public editorGroupService: INextEditorGroupsService
@IModelService public modelService: IModelService
) {
}
}
......
......@@ -36,7 +36,6 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IViewOptions, ViewsViewletPanel } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { CollapseAction } from 'vs/workbench/browser/viewlet';
import { INextEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { OutlineElement, OutlineModel, TreeElement } from './outlineModel';
import { OutlineController, OutlineDataSource, OutlineItemComparator, OutlineItemCompareType, OutlineItemFilter, OutlineRenderer, OutlineTreeState } from './outlineTree';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
......@@ -74,7 +73,6 @@ class RequestOracle {
constructor(
private readonly _callback: (editor: ICodeEditor, change: IModelContentChangedEvent) => any,
private readonly _featureRegistry: LanguageFeatureRegistry<any>,
@INextEditorGroupsService editorGroupService: INextEditorGroupsService,
@INextEditorService private readonly _editorService: INextEditorService,
) {
_editorService.onDidActiveEditorChange(this._update, this, this._disposables);
......
......@@ -23,7 +23,6 @@ import { QuickOpenEntry, QuickOpenModel } from 'vs/base/parts/quickopen/browser/
import { QuickOpenHandler, EditorQuickOpenEntry } from 'vs/workbench/browser/quickopen';
import { QueryBuilder } from 'vs/workbench/parts/search/common/queryBuilder';
import { EditorInput, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -118,7 +117,7 @@ export class OpenFileHandler extends QuickOpenHandler {
private cacheState: CacheState;
constructor(
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@INextEditorService private editorService: INextEditorService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkbenchThemeService private themeService: IWorkbenchThemeService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
......@@ -151,7 +150,7 @@ export class OpenFileHandler extends QuickOpenHandler {
private doFindResults(searchValue: string, cacheKey?: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> {
const query: IQueryOptions = {
extraFileResources: getOutOfWorkspaceEditorResources(this.editorGroupService, this.contextService),
extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService),
filePattern: searchValue,
cacheKey: cacheKey
};
......@@ -193,7 +192,7 @@ export class OpenFileHandler extends QuickOpenHandler {
private cacheQuery(cacheKey: string): ISearchQuery {
const options: IQueryOptions = {
extraFileResources: getOutOfWorkspaceEditorResources(this.editorGroupService, this.contextService),
extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService),
filePattern: '',
cacheKey: cacheKey,
maxResults: 0,
......
......@@ -24,7 +24,6 @@ import { FindInput } from 'vs/base/browser/ui/findinput/findInput';
import { ITree, IFocusEvent } from 'vs/base/parts/tree/browser/tree';
import { Scope } from 'vs/workbench/common/memento';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { FileChangeType, FileChangesEvent, IFileService } from 'vs/platform/files/common/files';
import { Match, FileMatch, SearchModel, FileMatchOrMatch, IChangeEvent, ISearchWorkbenchService, FolderMatch } from 'vs/workbench/parts/search/common/searchModel';
import { QueryBuilder } from 'vs/workbench/parts/search/common/queryBuilder';
......@@ -118,7 +117,6 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
@ITelemetryService telemetryService: ITelemetryService,
@IFileService private fileService: IFileService,
@INextEditorService private editorService: INextEditorService,
@INextEditorGroupsService private editorGroupService: INextEditorGroupsService,
@IProgressService private progressService: IProgressService,
@INotificationService private notificationService: INotificationService,
@IDialogService private dialogService: IDialogService,
......@@ -1068,7 +1066,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
const includePattern = this.inputPatternIncludes.getValue();
const options: IQueryOptions = {
extraFileResources: getOutOfWorkspaceEditorResources(this.editorGroupService, this.contextService),
extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService),
maxResults: SearchView.MAX_TEXT_RESULTS,
disregardIgnoreFiles: !useExcludesAndIgnoreFiles,
disregardExcludeSettings: !useExcludesAndIgnoreFiles,
......
......@@ -10,10 +10,10 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ISearchConfiguration, ISearchConfigurationProperties } from 'vs/platform/search/common/search';
import { SymbolInformation } from 'vs/editor/common/modes';
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import URI from 'vs/base/common/uri';
import { toResource } from 'vs/workbench/common/editor';
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
export interface IWorkspaceSymbolProvider {
provideWorkspaceSymbols(search: string): TPromise<SymbolInformation[]>;
......@@ -76,17 +76,14 @@ export interface IWorkbenchSearchConfiguration extends ISearchConfiguration {
/**
* Helper to return all opened editors with resources not belonging to the currently opened workspace.
*/
export function getOutOfWorkspaceEditorResources(editorGroupService: INextEditorGroupsService, contextService: IWorkspaceContextService): URI[] {
export function getOutOfWorkspaceEditorResources(editorService: INextEditorService, contextService: IWorkspaceContextService): URI[] {
const resources: URI[] = [];
editorGroupService.groups.forEach(group => {
const editors = group.editors;
editors.forEach(editor => {
const resource = toResource(editor, { supportSideBySide: true });
if (resource && !contextService.isInsideWorkspace(resource)) {
resources.push(resource);
}
});
editorService.editors.forEach(editor => {
const resource = toResource(editor, { supportSideBySide: true });
if (resource && !contextService.isInsideWorkspace(resource)) {
resources.push(resource);
}
});
return resources;
......
......@@ -152,6 +152,15 @@ export class NextEditorService extends Disposable implements INextEditorService
return void 0;
}
get editors(): IEditorInput[] {
const editors: IEditorInput[] = [];
this.nextEditorGroupsService.groups.forEach(group => {
editors.push(...group.editors);
});
return editors;
}
get activeEditor(): IEditorInput {
const activeGroup = this.nextEditorGroupsService.activeGroup;
......
......@@ -77,6 +77,11 @@ export interface INextEditorService {
*/
readonly activeTextEditorControl: ITextEditor;
/**
* All editors that are opened.
*/
readonly editors: ReadonlyArray<IEditorInput>;
/**
* The currently active editor if any.
*/
......
......@@ -290,6 +290,10 @@ suite('Editor service (editor2)', () => {
// Open input
return service.openEditor(input, { pinned: true }).then(editor => {
return service.openEditor(input, { pinned: true }, rightGroup).then(editor => {
const editors = service.editors;
assert.equal(editors.length, 2);
assert.equal(editors[0], input);
assert.equal(editors[1], input);
// Close input
return rootGroup.closeEditor(input).then(() => {
......
......@@ -865,6 +865,7 @@ export class TestNextEditorService implements INextEditorService {
activeControl: IEditor;
activeTextEditorControl: any;
activeEditor: IEditorInput;
editors: ReadonlyArray<IEditorInput> = [];
visibleControls: ReadonlyArray<IEditor> = [];
visibleTextEditorControls = [];
visibleEditors: ReadonlyArray<IEditorInput> = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册