Skip to content

Commit 405366d

Browse files
authored
1 parent 5c20272 commit 405366d

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
900900
}
901901
}
902902

903+
isCollapsed(item: ITreeItem): boolean {
904+
return !!this.tree?.isCollapsed(item);
905+
}
906+
903907
setSelection(items: ITreeItem[]): void {
904908
this.tree?.setSelection(items);
905909
}

src/vs/workbench/common/views.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ export interface ITreeView extends IDisposable {
694694

695695
expand(itemOrItems: ITreeItem | ITreeItem[]): Promise<void>;
696696

697+
isCollapsed(item: ITreeItem): boolean;
698+
697699
setSelection(items: ITreeItem[]): void;
698700

699701
getSelection(): ITreeItem[];

src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -179,29 +179,12 @@ export class UserDataProfileImportExportService extends Disposable implements IU
179179
}
180180

181181
async exportProfile(): Promise<void> {
182-
const view = this.viewsService.getViewWithId(EXPORT_PROFILE_PREVIEW_VIEW);
183-
if (view) {
184-
this.viewsService.openView(view.id, true);
185-
return;
186-
}
187-
188182
if (this.isProfileExportInProgressContextKey.get()) {
189183
this.logService.warn('Profile export already in progress.');
190184
return;
191185
}
192186

193-
const disposables = new DisposableStore();
194-
try {
195-
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, this.userDataProfileService.currentProfile));
196-
const barrier = new Barrier();
197-
const exportAction = this.getExportAction(barrier, userDataProfilesExportState);
198-
const cancelAction = new BarrierAction(barrier, new Action('cancel', localize('cancel', "Cancel")));
199-
await this.showProfilePreviewView(EXPORT_PROFILE_PREVIEW_VIEW, userDataProfilesExportState.profile.name, [exportAction], cancelAction, true, userDataProfilesExportState);
200-
await barrier.wait();
201-
await this.hideProfilePreviewView(EXPORT_PROFILE_PREVIEW_VIEW);
202-
} finally {
203-
disposables.dispose();
204-
}
187+
return this.showProfileContents();
205188
}
206189

207190
async importProfile(uri: URI, options?: IProfileImportOptions): Promise<void> {
@@ -243,24 +226,20 @@ export class UserDataProfileImportExportService extends Disposable implements IU
243226
try {
244227
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, this.userDataProfileService.currentProfile));
245228
const barrier = new Barrier();
246-
const exportAction = this.getExportAction(barrier, userDataProfilesExportState);
229+
const exportAction = new BarrierAction(barrier, new Action('export', localize('export', "Export"), undefined, true, () => {
230+
exportAction.enabled = false;
231+
return this.doExportProfile(userDataProfilesExportState);
232+
}));
247233
const closeAction = new BarrierAction(barrier, new Action('close', localize('close', "Close")));
248234
await this.showProfilePreviewView(EXPORT_PROFILE_PREVIEW_VIEW, userDataProfilesExportState.profile.name, [exportAction], closeAction, true, userDataProfilesExportState);
235+
disposables.add(this.userDataProfileService.onDidChangeCurrentProfile(e => barrier.open()));
249236
await barrier.wait();
250237
await this.hideProfilePreviewView(EXPORT_PROFILE_PREVIEW_VIEW);
251238
} finally {
252239
disposables.dispose();
253240
}
254241
}
255242

256-
private getExportAction(barrier: Barrier, userDataProfilesExportState: UserDataProfileExportState) {
257-
const exportAction = new BarrierAction(barrier, new Action('export', localize('export', "Export"), undefined, true, () => {
258-
exportAction.enabled = false;
259-
return this.doExportProfile(userDataProfilesExportState);
260-
}));
261-
return exportAction;
262-
}
263-
264243
private async doExportProfile(userDataProfilesExportState: UserDataProfileExportState): Promise<void> {
265244
const profile = await userDataProfilesExportState.getProfileToExport();
266245
if (!profile) {
@@ -749,7 +728,6 @@ class UserDataProfilePreviewViewPane extends TreeViewPane {
749728
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, notificationService);
750729
}
751730

752-
753731
protected override renderTreeView(container: HTMLElement): void {
754732
this.treeView.dataProvider = this.userDataProfileData;
755733
super.renderTreeView(DOM.append(container, DOM.$('')));
@@ -759,13 +737,17 @@ class UserDataProfilePreviewViewPane extends TreeViewPane {
759737
this.updateConfirmButtonEnablement();
760738
}));
761739
this.computeAndLayout();
762-
this._register(this.userDataProfileData.onDidChangeRoots(() => this.computeAndLayout()));
740+
this._register(Event.any(this.userDataProfileData.onDidChangeRoots, this.treeView.onDidCollapseItem, this.treeView.onDidExpandItem)(() => this.computeAndLayout()));
763741
}
764742

765743
private async computeAndLayout() {
766744
const roots = await this.userDataProfileData.getRoots();
767745
const children = await Promise.all(roots.map(async (root) => {
768-
if (root.collapsibleState === TreeItemCollapsibleState.Expanded) {
746+
let expanded = root.collapsibleState === TreeItemCollapsibleState.Expanded;
747+
try {
748+
expanded = !this.treeView.isCollapsed(root);
749+
} catch (error) { /* Ignore because element might not be added yet */ }
750+
if (expanded) {
769751
const children = await root.getChildren();
770752
return children ?? [];
771753
}
@@ -806,14 +788,13 @@ class UserDataProfilePreviewViewPane extends TreeViewPane {
806788
}));
807789
}
808790

809-
810791
protected override layoutTreeView(height: number, width: number): void {
811792
this.dimension = new DOM.Dimension(width, height);
812793
const buttonContainerHeight = 108;
813794
this.buttonsContainer.style.height = `${buttonContainerHeight}px`;
814795
this.buttonsContainer.style.width = `${width}px`;
815796

816-
super.layoutTreeView(Math.min(height - buttonContainerHeight, 22 * (Math.max(this.totalTreeItemsCount, 6) || 12)), width);
797+
super.layoutTreeView(Math.min(height - buttonContainerHeight, 22 * this.totalTreeItemsCount), width);
817798
}
818799

819800
private updateConfirmButtonEnablement(): void {

0 commit comments

Comments
 (0)