mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
add (internal) api for onWillSave #43768
This commit is contained in:
@@ -4,23 +4,24 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { FileChangeType, IFileService, FileOperation } from 'vs/platform/files/common/files';
|
||||
import { extHostCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
import { ExtHostContext, ExtHostFileSystemEventServiceShape, FileSystemEvents, IExtHostContext } from '../node/extHost.protocol';
|
||||
import { ExtHostContext, FileSystemEvents, IExtHostContext } from '../node/extHost.protocol';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
|
||||
@extHostCustomer
|
||||
export class MainThreadFileSystemEventService {
|
||||
|
||||
private readonly _fileEventListener: IDisposable;
|
||||
private readonly _fileOperationListener: IDisposable;
|
||||
private readonly _listener = new Array<IDisposable>();
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IFileService fileService: IFileService
|
||||
@IFileService fileService: IFileService,
|
||||
@ITextFileService textfileService: ITextFileService,
|
||||
) {
|
||||
|
||||
const proxy: ExtHostFileSystemEventServiceShape = extHostContext.getProxy(ExtHostContext.ExtHostFileSystemEventService);
|
||||
const proxy = extHostContext.getProxy(ExtHostContext.ExtHostFileSystemEventService);
|
||||
|
||||
// file system events - (changes the editor and other make)
|
||||
const events: FileSystemEvents = {
|
||||
@@ -28,7 +29,7 @@ export class MainThreadFileSystemEventService {
|
||||
changed: [],
|
||||
deleted: []
|
||||
};
|
||||
this._fileEventListener = fileService.onFileChanges(event => {
|
||||
fileService.onFileChanges(event => {
|
||||
for (let change of event.changes) {
|
||||
switch (change.type) {
|
||||
case FileChangeType.ADDED:
|
||||
@@ -47,18 +48,22 @@ export class MainThreadFileSystemEventService {
|
||||
events.created.length = 0;
|
||||
events.changed.length = 0;
|
||||
events.deleted.length = 0;
|
||||
});
|
||||
}, undefined, this._listener);
|
||||
|
||||
// file operation events - (changes the editor makes)
|
||||
this._fileOperationListener = fileService.onAfterOperation(e => {
|
||||
fileService.onAfterOperation(e => {
|
||||
if (e.operation === FileOperation.MOVE) {
|
||||
proxy.$onFileRename(e.resource, e.target.resource);
|
||||
}
|
||||
});
|
||||
}, undefined, this._listener);
|
||||
|
||||
textfileService.onWillMove(e => {
|
||||
let promise = proxy.$onWillRename(e.oldResource, e.newResource);
|
||||
e.waitUntil(promise);
|
||||
}, undefined, this._listener);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._fileEventListener.dispose();
|
||||
this._fileOperationListener.dispose();
|
||||
dispose(this._listener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,6 +698,7 @@ export interface FileSystemEvents {
|
||||
export interface ExtHostFileSystemEventServiceShape {
|
||||
$onFileEvent(events: FileSystemEvents): void;
|
||||
$onFileRename(oldUri: UriComponents, newUri: UriComponents): void;
|
||||
$onWillRename(oldUri: UriComponents, newUri: UriComponents): TPromise<any>;
|
||||
}
|
||||
|
||||
export interface ObjectIdentifier {
|
||||
|
||||
@@ -10,6 +10,7 @@ import URI, { UriComponents } from 'vs/base/common/uri';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtHostFileSystemEventServiceShape, FileSystemEvents } from './extHost.protocol';
|
||||
import { Disposable } from './extHostTypes';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
class FileSystemWatcher implements vscode.FileSystemWatcher {
|
||||
|
||||
@@ -114,4 +115,8 @@ export class ExtHostFileSystemEventService implements ExtHostFileSystemEventServ
|
||||
$onFileRename(oldUri: UriComponents, newUri: UriComponents) {
|
||||
this._onDidRenameFile.fire(Object.freeze({ oldUri: URI.revive(oldUri), newUri: URI.revive(newUri) }));
|
||||
}
|
||||
|
||||
$onWillRename(oldUri: UriComponents, newUri: UriComponents): TPromise<any> {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user