Files
openidea/src/platform/fileOps.ts
T

28 lines
730 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Files created / deleted by an explicit IDE action (New File, Copy, Delete,
* file templates), as opposed to changes seen by the file watcher. VCS uses
* this for Settings › Version Control › Confirmation.
*/
export interface FileOperation {
kind: "created" | "deleted";
paths: string[];
}
type Listener = (op: FileOperation) => void;
const listeners = new Set<Listener>();
export function notifyFileOperation(op: FileOperation) {
for (const l of listeners) {
try {
l(op);
} catch (e) {
console.warn("file operation listener failed", e);
}
}
}
export function onFileOperation(listener: Listener): () => void {
listeners.add(listener);
return () => listeners.delete(listener);
}