From 03b081fead75c27e6449f2b5ee3bc3d357b53054 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Sun, 1 Sep 2024 00:59:06 +0200 Subject: [PATCH] newWorkspace: fix switch workspace after finish now instead of doing an instant restart (which did not switch to the new workspace) we show the existing Eclipse Switch Workspace dialog but have the new workspace location pre-filled. Since this reuses existing Eclipse feature of OpenWorkspaceAction all the switch workspace logic can be reused. Signed-off-by: Christoph Rueger --- .../src/bndtools/wizards/newworkspace/Model.java | 15 +++++++++++++-- .../wizards/newworkspace/NewWorkspaceWizard.java | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bndtools.core/src/bndtools/wizards/newworkspace/Model.java b/bndtools.core/src/bndtools/wizards/newworkspace/Model.java index 001b8ba680..b0db87e725 100644 --- a/bndtools.core/src/bndtools/wizards/newworkspace/Model.java +++ b/bndtools.core/src/bndtools/wizards/newworkspace/Model.java @@ -14,7 +14,10 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.ide.ChooseWorkspaceData; +import org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,8 +119,16 @@ boolean execute(TemplateUpdater updater) { System.setProperty("osgi.instance.area", location.getAbsolutePath()); System.setProperty("osgi.instance.area.default", location.getAbsolutePath()); - PlatformUI.getWorkbench() - .restart(); + // show Eclipse Switch Workspace dialog with the new + // workspace location pre-filled + ChooseWorkspaceData launchData = new ChooseWorkspaceData(location.getAbsolutePath()); + launchData.workspaceSelected(location.getAbsolutePath()); + launchData.writePersistedData(); + + IWorkbenchWindow window = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + new OpenWorkspaceAction(window).run(); + }); } } catch (Exception e) { diff --git a/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java b/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java index fa89131c13..490eb38931 100644 --- a/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java +++ b/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java @@ -129,7 +129,7 @@ public void createControl(Composite parent) { clean.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 8, 1)); Button switchWorkspace = new Button(container, SWT.CHECK); - switchWorkspace.setText("Switch to new workspace after finish"); + switchWorkspace.setText("Show workspace select dialog to switch to new workspace after finish"); switchWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 8, 1)); CheckboxTableViewer selectedTemplates = CheckboxTableViewer.newCheckList(container,