提交 e20bed14 编写于 作者: B Benjamin Pasero

make editor dirty event emit for all inputs open

上级 9064fc4e
......@@ -419,6 +419,7 @@ export class CloseEditorAction extends Action {
let input = editorIdentifier ? editorIdentifier.editor : null;
if (!input) {
// Get Top Editor at Position
let visibleEditors = this.editorService.getVisibleEditors();
if (visibleEditors[position]) {
......
......@@ -120,13 +120,13 @@ export class EditorPart extends Part implements IEditorPart {
}
private registerListeners(): void {
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_STATE_CHANGED, (event: EditorInputEvent) => this.onEditorInputStateChanged(event)));
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_DIRTY_STATE_CHANGED, (event: EditorInputEvent) => this.onEditorInputDirtyStateChanged(event)));
const unbind = this.stacks.onEditorDisposed(editor => this.onEditorDisposed(editor));
this.toUnbind.push(() => unbind.dispose());
}
private onEditorInputStateChanged(event: EditorInputEvent): void {
private onEditorInputDirtyStateChanged(event: EditorInputEvent): void {
if (this.sideBySideControl) {
this.sideBySideControl.updateTitleArea(event.editorInput);
}
......
......@@ -115,7 +115,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
private titleContainer: Builder[];
private titleLabel: Builder[];
private titleDescription: Builder[];
private editorInputStateDescription: Builder[];
private progressBar: ProgressBar[];
private editorTitleToolbar: ToolBar[];
......@@ -168,7 +167,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.titleContainer = [];
this.titleLabel = [];
this.titleDescription = [];
this.editorInputStateDescription = [];
this.editorTitleToolbar = [];
this.editorActionsToolbar = [];
this.progressBar = [];
......
......@@ -58,9 +58,9 @@ export class EventType {
static EDITOR_INPUT_CHANGED = 'editorInputChanged';
/**
* Event type for when the editor input state changed.
* Event type for when the editor input dirty state changed.
*/
static EDITOR_INPUT_STATE_CHANGED = 'editorInputStateChanged';
static EDITOR_INPUT_DIRTY_STATE_CHANGED = 'editorInputDirtyStateChanged';
/**
* Event type for when the editor input failed to be set to the editor.
......
......@@ -10,6 +10,7 @@ import nls = require('vs/nls');
import {MIME_UNKNOWN} from 'vs/base/common/mime';
import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import arrays = require('vs/base/common/arrays');
import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
import {EditorInput, EditorOptions} from 'vs/workbench/common/editor';
import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor';
......@@ -64,7 +65,6 @@ export class FileTracker implements IWorkbenchContribution {
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onUntitledEditorDeleted(e)));
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onUntitledEditorDirty(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_DIRTY, (e: TextFileChangeEvent) => this.onTextFileDirty(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_SAVING, (e: TextFileChangeEvent) => this.onTextFileSaving(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_SAVE_ERROR, (e: TextFileChangeEvent) => this.onTextFileSaveError(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_SAVED, (e: TextFileChangeEvent) => this.onTextFileSaved(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_REVERTED, (e: TextFileChangeEvent) => this.onTextFileReverted(e)));
......@@ -75,7 +75,7 @@ export class FileTracker implements IWorkbenchContribution {
}
private onTextFileDirty(e: TextFileChangeEvent): void {
this.emitInputStateChangeEvent(e.resource);
this.emitInputDirtyStateChangeEvent(e.resource, true);
if (this.textFileService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY) {
this.updateActivityBadge(); // no indication needed when auto save is enabled for short delay
......@@ -84,17 +84,13 @@ export class FileTracker implements IWorkbenchContribution {
this.updateActiveEditor(e.resource);
}
private onTextFileSaving(e: TextFileChangeEvent): void {
this.emitInputStateChangeEvent(e.resource);
}
private onTextFileSaveError(e: TextFileChangeEvent): void {
this.emitInputStateChangeEvent(e.resource);
this.emitInputDirtyStateChangeEvent(e.resource, true);
this.updateActivityBadge();
}
private onTextFileSaved(e: TextFileChangeEvent): void {
this.emitInputStateChangeEvent(e.resource);
this.emitInputDirtyStateChangeEvent(e.resource, false);
if (this.lastDirtyCount > 0) {
this.updateActivityBadge();
......@@ -102,7 +98,7 @@ export class FileTracker implements IWorkbenchContribution {
}
private onTextFileReverted(e: TextFileChangeEvent): void {
this.emitInputStateChangeEvent(e.resource);
this.emitInputDirtyStateChangeEvent(e.resource, false);
if (this.lastDirtyCount > 0) {
this.updateActivityBadge();
......@@ -112,7 +108,7 @@ export class FileTracker implements IWorkbenchContribution {
private onUntitledEditorDirty(e: UntitledEditorEvent): void {
let input = this.untitledEditorService.get(e.resource);
if (input) {
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_STATE_CHANGED, new EditorInputEvent(input));
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_DIRTY_STATE_CHANGED, new EditorInputEvent(input));
}
this.updateActivityBadge();
......@@ -122,7 +118,7 @@ export class FileTracker implements IWorkbenchContribution {
private onUntitledEditorDeleted(e: UntitledEditorEvent): void {
let input = this.untitledEditorService.get(e.resource);
if (input) {
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_STATE_CHANGED, new EditorInputEvent(input));
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_DIRTY_STATE_CHANGED, new EditorInputEvent(input));
}
if (this.lastDirtyCount > 0) {
......@@ -156,14 +152,15 @@ export class FileTracker implements IWorkbenchContribution {
}
}
private emitInputStateChangeEvent(resource: URI): void {
private emitInputDirtyStateChangeEvent(resource: URI, gotDirty: boolean): void {
// Find all file editor inputs that are open from the given file resource and emit a editor input state change event.
// We could do all of this within the file editor input but having all the file change listeners in
// one place is more elegant and keeps the logic together at once place.
let editors = this.editorService.getVisibleEditors();
editors.forEach((editor) => {
let input = editor.input;
let editors = arrays.flatten(this.editorService.getStacksModel().groups.map(g => g.getEditors()));
editors.forEach(input => {
// Diff Editor Input
if (input instanceof DiffEditorInput) {
input = (<DiffEditorInput>input).getModifiedInput();
}
......@@ -172,9 +169,9 @@ export class FileTracker implements IWorkbenchContribution {
if (input instanceof FileEditorInput) {
let fileInput = <FileEditorInput>input;
if (fileInput.getResource().toString() === resource.toString()) {
let inputEvent = editor.input instanceof DiffEditorInput ? <DiffEditorInput>editor.input : fileInput; // make sure to still send around the input from the diff editor if given
let inputEvent = input instanceof DiffEditorInput ? input : fileInput; // make sure to still send around the input from the diff editor if given
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_STATE_CHANGED, new EditorInputEvent(inputEvent));
this.eventService.emit(WorkbenchEventType.EDITOR_INPUT_DIRTY_STATE_CHANGED, new EditorInputEvent(inputEvent));
}
}
});
......
......@@ -202,35 +202,6 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
this.editorPart.unpinEditor(position, input);
}
private findEditor(editor?: IEditor): BaseEditor;
private findEditor(position?: Position): BaseEditor;
private findEditor(arg?: any): BaseEditor {
// Editor provided
if (arg instanceof BaseEditor) {
return <BaseEditor>arg;
}
// Find active editor
if (types.isUndefinedOrNull(arg)) {
return this.editorPart.getActiveEditor();
}
// Target position provided
if (types.isNumber(arg)) {
let position = <Position>arg;
let visibleEditors = this.editorPart.getVisibleEditors();
for (let i = 0; i < visibleEditors.length; i++) {
let editor = <BaseEditor>visibleEditors[i];
if (editor.position === position) {
return editor;
}
}
}
return null;
}
public resolveEditorModel(input: IEditorInput, refresh?: boolean): TPromise<IEditorModel>;
public resolveEditorModel(input: IResourceInput, refresh?: boolean): TPromise<ITextEditorModel>;
public resolveEditorModel(input: any, refresh?: boolean): TPromise<IEditorModel> {
......
......@@ -84,13 +84,13 @@ export abstract class BaseHistoryService {
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_CHANGED, (e: EditorEvent) => this.onEditorInputChanged(e)));
// Editor Input State Changes
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_STATE_CHANGED, (e: EditorInputEvent) => this.onEditorInputStateChanged(e.editorInput)));
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_DIRTY_STATE_CHANGED, (e: EditorInputEvent) => this.onEditorInputDirtyStateChanged(e.editorInput)));
// Text Editor Selection Changes
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.TEXT_EDITOR_SELECTION_CHANGED, (event: TextEditorSelectionEvent) => this.onTextEditorSelectionChanged(event)));
}
private onEditorInputStateChanged(input: IEditorInput): void {
private onEditorInputDirtyStateChanged(input: IEditorInput): void {
// If an active editor is set, but is different from the one from the event, prevent update because the editor is not active.
let activeEditor = this.editorService.getActiveEditor();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册