@@ -10,20 +10,23 @@ import {EditorModel, IEncodingSupport} from 'vs/workbench/common/editor';
1010import { StringEditorModel } from 'vs/workbench/common/editor/stringEditorModel' ;
1111import URI from 'vs/base/common/uri' ;
1212import { EventType , EndOfLinePreference } from 'vs/editor/common/editorCommon' ;
13- import { EventType as WorkbenchEventType , UntitledEditorEvent , ResourceEvent } from 'vs/workbench/common/events' ;
13+ import { EventType as WorkbenchEventType , ResourceEvent } from 'vs/workbench/common/events' ;
1414import { IFilesConfiguration } from 'vs/platform/files/common/files' ;
1515import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1616import { IEventService } from 'vs/platform/event/common/event' ;
1717import { IModeService } from 'vs/editor/common/services/modeService' ;
1818import { IModelService } from 'vs/editor/common/services/modelService' ;
1919import { IMode } from 'vs/editor/common/modes' ;
2020import { isUnspecific } from 'vs/base/common/mime' ;
21+ import Event , { Emitter } from 'vs/base/common/event' ;
2122
2223export class UntitledEditorModel extends StringEditorModel implements IEncodingSupport {
2324 private textModelChangeListener : IDisposable ;
2425 private configurationChangeListener : IDisposable ;
2526
2627 private dirty : boolean ;
28+ private _onDidChangeDirty : Emitter < void > ;
29+
2730 private configuredEncoding : string ;
2831 private preferredEncoding : string ;
2932
@@ -41,9 +44,15 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
4144
4245 this . dirty = hasAssociatedFilePath ; // untitled associated to file path are dirty right away
4346
47+ this . _onDidChangeDirty = new Emitter < void > ( ) ;
48+
4449 this . registerListeners ( ) ;
4550 }
4651
52+ public get onDidChangeDirty ( ) : Event < void > {
53+ return this . _onDidChangeDirty . event ;
54+ }
55+
4756 protected getOrCreateMode ( modeService : IModeService , mime : string , firstLineText ?: string ) : TPromise < IMode > {
4857 if ( isUnspecific ( mime ) ) {
4958 return modeService . getOrCreateModeByFilenameOrFirstLine ( this . resource . fsPath , firstLineText ) ; // lookup mode via resource path if the provided mime is unspecific
@@ -99,7 +108,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
99108 public revert ( ) : void {
100109 this . dirty = false ;
101110
102- this . eventService . emit ( WorkbenchEventType . UNTITLED_FILE_SAVED , new UntitledEditorEvent ( this . resource ) ) ;
111+ this . _onDidChangeDirty . fire ( ) ;
103112 }
104113
105114 public load ( ) : TPromise < EditorModel > {
@@ -115,7 +124,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
115124 // Emit initial dirty event if we are
116125 if ( this . dirty ) {
117126 setTimeout ( ( ) => {
118- this . eventService . emit ( WorkbenchEventType . UNTITLED_FILE_DIRTY , new UntitledEditorEvent ( this . resource ) ) ;
127+ this . _onDidChangeDirty . fire ( ) ;
119128 } , 0 /* prevent race condition between creating model and emitting dirty event */ ) ;
120129 }
121130
@@ -126,7 +135,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
126135 private onModelContentChanged ( ) : void {
127136 if ( ! this . dirty ) {
128137 this . dirty = true ;
129- this . eventService . emit ( WorkbenchEventType . UNTITLED_FILE_DIRTY , new UntitledEditorEvent ( this . resource ) ) ;
138+ this . _onDidChangeDirty . fire ( ) ;
130139 }
131140 }
132141
0 commit comments