Skip to content

Commit 0bce369

Browse files
committed
explorer: onDidChangeItem emit if refresh should be recursive
fixes microsoft#71588
1 parent 6510719 commit 0bce369

4 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/vs/workbench/contrib/files/browser/views/explorerDecorationsProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class ExplorerDecorationsProvider implements IDecorationsProvider {
2525
this.toDispose.push(contextService.onDidChangeWorkspaceFolders(e => {
2626
this._onDidChange.fire(e.changed.concat(e.added).map(wf => wf.uri));
2727
}));
28-
this.toDispose.push(explorerService.onDidChangeItem(item => {
29-
if (item) {
30-
this._onDidChange.fire([item.resource]);
28+
this.toDispose.push(explorerService.onDidChangeItem(change => {
29+
if (change.item) {
30+
this._onDidChange.fire([change.item.resource]);
3131
}
3232
}));
3333
}

src/vs/workbench/contrib/files/browser/views/explorerView.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ export class ExplorerView extends ViewletPanel {
167167

168168
this.disposables.push(this.labelService.onDidChangeFormatters(() => {
169169
this._onDidChangeTitleArea.fire();
170-
this.refresh();
170+
this.refresh(true);
171171
}));
172172

173173
this.disposables.push(this.explorerService.onDidChangeRoots(() => this.setTreeInput()));
174-
this.disposables.push(this.explorerService.onDidChangeItem(e => this.refresh(e)));
174+
this.disposables.push(this.explorerService.onDidChangeItem(e => this.refresh(e.recursive, e.item)));
175175
this.disposables.push(this.explorerService.onDidChangeEditable(async e => {
176176
const isEditing = !!this.explorerService.getEditableData(e);
177177

@@ -181,7 +181,7 @@ export class ExplorerView extends ViewletPanel {
181181
DOM.removeClass(treeContainer, 'highlight');
182182
}
183183

184-
await this.refresh(e.parent);
184+
await this.refresh(false, e.parent);
185185

186186
if (isEditing) {
187187
DOM.addClass(treeContainer, 'highlight');
@@ -365,7 +365,7 @@ export class ExplorerView extends ViewletPanel {
365365

366366
// Refresh viewer as needed if this originates from a config event
367367
if (event && needsRefresh) {
368-
this.refresh();
368+
this.refresh(true);
369369
}
370370
}
371371

@@ -421,7 +421,7 @@ export class ExplorerView extends ViewletPanel {
421421
* Refresh the contents of the explorer to get up to date data from the disk about the file structure.
422422
* If the item is passed we refresh only that level of the tree, otherwise we do a full refresh.
423423
*/
424-
private refresh(item?: ExplorerItem): Promise<void> {
424+
private refresh(recursive: boolean, item?: ExplorerItem): Promise<void> {
425425
if (!this.tree || !this.isBodyVisible()) {
426426
this.shouldRefresh = true;
427427
return Promise.resolve(undefined);
@@ -432,7 +432,6 @@ export class ExplorerView extends ViewletPanel {
432432
return Promise.resolve(undefined);
433433
}
434434

435-
const recursive = !item;
436435
const toRefresh = item || this.tree.getInput();
437436

438437
return this.tree.updateChildren(toRefresh, recursive);

src/vs/workbench/contrib/files/common/explorerService.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ExplorerService implements IExplorerService {
3232
private static readonly EXPLORER_FILE_CHANGES_REACT_DELAY = 500; // delay in ms to react to file changes to give our internal events a chance to react first
3333

3434
private _onDidChangeRoots = new Emitter<void>();
35-
private _onDidChangeItem = new Emitter<ExplorerItem | undefined>();
35+
private _onDidChangeItem = new Emitter<{ item?: ExplorerItem, recursive: boolean }>();
3636
private _onDidChangeEditable = new Emitter<ExplorerItem>();
3737
private _onDidSelectResource = new Emitter<{ resource?: URI, reveal?: boolean }>();
3838
private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>();
@@ -61,7 +61,7 @@ export class ExplorerService implements IExplorerService {
6161
return this._onDidChangeRoots.event;
6262
}
6363

64-
get onDidChangeItem(): Event<ExplorerItem | undefined> {
64+
get onDidChangeItem(): Event<{ item?: ExplorerItem, recursive: boolean }> {
6565
return this._onDidChangeItem.event;
6666
}
6767

@@ -102,7 +102,7 @@ export class ExplorerService implements IExplorerService {
102102
this.disposables.push(this.fileService.onDidChangeFileSystemProviderRegistrations(e => {
103103
if (e.added && this.fileSystemProviderSchemes.has(e.scheme)) {
104104
// A file system provider got re-registered, we should update all file stats since they might change (got read-only)
105-
this._onDidChangeItem.fire(undefined);
105+
this._onDidChangeItem.fire({ recursive: true });
106106
} else {
107107
this.fileSystemProviderSchemes.add(e.scheme);
108108
}
@@ -166,19 +166,19 @@ export class ExplorerService implements IExplorerService {
166166
// Update Input with disk Stat
167167
ExplorerItem.mergeLocalWithDisk(modelStat, root);
168168
const item = root.find(resource);
169-
this._onDidChangeItem.fire(item ? item.parent : undefined);
169+
this._onDidChangeItem.fire({ item: root, recursive: true });
170170

171171
// Select and Reveal
172172
this._onDidSelectResource.fire({ resource: item ? item.resource : undefined, reveal });
173173
}, () => {
174174
root.isError = true;
175-
this._onDidChangeItem.fire(root);
175+
this._onDidChangeItem.fire({ item: root, recursive: false });
176176
});
177177
}
178178

179179
refresh(): void {
180180
this.model.roots.forEach(r => r.forgetChildren());
181-
this._onDidChangeItem.fire(undefined);
181+
this._onDidChangeItem.fire({ recursive: true });
182182
const resource = this.editorService.activeEditor ? this.editorService.activeEditor.getResource() : undefined;
183183
if (resource) {
184184
// We did a top level refresh, reveal the active file #67118
@@ -213,7 +213,7 @@ export class ExplorerService implements IExplorerService {
213213
p.removeChild(childElement);
214214
p.addChild(childElement);
215215
// Refresh the Parent (View)
216-
this._onDidChangeItem.fire(p);
216+
this._onDidChangeItem.fire({ item: p, recursive: false });
217217
});
218218
});
219219
}
@@ -232,7 +232,7 @@ export class ExplorerService implements IExplorerService {
232232
modelElements.forEach(modelElement => {
233233
// Rename File (Model)
234234
modelElement.rename(newElement);
235-
this._onDidChangeItem.fire(modelElement.parent);
235+
this._onDidChangeItem.fire({ item: modelElement.parent, recursive: false });
236236
});
237237
}
238238

@@ -246,8 +246,8 @@ export class ExplorerService implements IExplorerService {
246246
modelElements.forEach((modelElement, index) => {
247247
const oldParent = modelElement.parent;
248248
modelElement.move(newParents[index]);
249-
this._onDidChangeItem.fire(oldParent);
250-
this._onDidChangeItem.fire(newParents[index]);
249+
this._onDidChangeItem.fire({ item: oldParent, recursive: false });
250+
this._onDidChangeItem.fire({ item: newParents[index], recursive: false });
251251
});
252252
}
253253
}
@@ -262,7 +262,7 @@ export class ExplorerService implements IExplorerService {
262262
// Remove Element from Parent (Model)
263263
parent.removeChild(element);
264264
// Refresh Parent (View)
265-
this._onDidChangeItem.fire(parent);
265+
this._onDidChangeItem.fire({ item: parent, recursive: false });
266266
}
267267
});
268268
}
@@ -340,7 +340,7 @@ export class ExplorerService implements IExplorerService {
340340

341341
if (shouldRefresh()) {
342342
this.roots.forEach(r => r.forgetChildren());
343-
this._onDidChangeItem.fire(undefined);
343+
this._onDidChangeItem.fire({ recursive: true });
344344
}
345345
}, ExplorerService.EXPLORER_FILE_CHANGES_REACT_DELAY);
346346
}

src/vs/workbench/contrib/files/common/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface IExplorerService {
4343
readonly roots: ExplorerItem[];
4444
readonly sortOrder: SortOrder;
4545
readonly onDidChangeRoots: Event<void>;
46-
readonly onDidChangeItem: Event<ExplorerItem | undefined>;
46+
readonly onDidChangeItem: Event<{ item?: ExplorerItem, recursive: boolean }>;
4747
readonly onDidChangeEditable: Event<ExplorerItem>;
4848
readonly onDidSelectResource: Event<{ resource?: URI, reveal?: boolean }>;
4949
readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>;

0 commit comments

Comments
 (0)