Skip to content

Commit a44de9e

Browse files
committed
Update views on local file changes
Integrate change that allow text and binary local file changes to propogate to views.
1 parent 1127686 commit a44de9e

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/ide/project.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export class CodeProject {
118118

119119
callbackBuildResult: BuildResultCallback;
120120
callbackBuildStatus: BuildStatusCallback;
121+
onFileChanged: (path: string, data: FileData) => void;
121122

122123
constructor(worker, platform_id: string, platform, filesystem: ProjectFilesystem) {
123124
this.worker = worker;
@@ -128,6 +129,16 @@ export class CodeProject {
128129
worker.onmessage = (e) => {
129130
this.receiveWorkerMessage(e.data);
130131
};
132+
133+
filesystem.onFileSystemUpdate(async (path: string) => {
134+
if (path in this.filedata) {
135+
var data = await this.filesystem.getFileData(path);
136+
if (data) {
137+
this.updateFile(path, data);
138+
if (this.onFileChanged) this.onFileChanged(path, data);
139+
}
140+
}
141+
});
131142
}
132143

133144
receiveWorkerMessage(data: WorkerResult) {

src/ide/ui.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ async function initProject() {
261261
current_project.callbackBuildStatus = (busy: boolean) => {
262262
setBusyStatus(busy);
263263
};
264+
// Update views when file contents change.
265+
current_project.onFileChanged = (path: string, data: FileData) => {
266+
var wnd = projectWindows.id2window[path];
267+
if (wnd) {
268+
if (wnd instanceof SourceEditor && typeof data === 'string') {
269+
wnd.setText(data);
270+
} else if (wnd instanceof BinaryFileView && data instanceof Uint8Array) {
271+
wnd.setData(data);
272+
} else {
273+
console.warn('onFileChanged: unknown view or data type');
274+
}
275+
}
276+
};
264277
}
265278

266279
function setBusyStatus(busy: boolean) {

0 commit comments

Comments
 (0)