提交 f8cce162 编写于 作者: S serge-rider

#7488 Save current workspace config


Former-commit-id: 58c3c124
上级 cf0f5786
......@@ -30,6 +30,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
import org.eclipse.ui.internal.ide.application.DelayedEventsProcessor;
import org.jkiss.code.NotNull;
......@@ -156,6 +157,8 @@ public class DBeaverApplication extends BaseApplicationImpl {
instance = this;
Location instanceLoc = Platform.getInstanceLocation();
boolean ideWorkspaceSet = setIDEWorkspace(instanceLoc);
CommandLine commandLine = DBeaverCommandLine.getCommandLine();
{
String defaultHomePath = getDefaultInstanceLocation();
......@@ -171,7 +174,7 @@ public class DBeaverApplication extends BaseApplicationImpl {
if (!setDefaultWorkspacePath(instanceLoc)) {
return IApplication.EXIT_OK;
}
} else if (instanceLoc.isLocked()) {
} else if (instanceLoc.isLocked() && !ideWorkspaceSet) {
// Check for locked workspace
if (!setDefaultWorkspacePath(instanceLoc)) {
return IApplication.EXIT_OK;
......@@ -265,6 +268,50 @@ public class DBeaverApplication extends BaseApplicationImpl {
}
}
private boolean setIDEWorkspace(Location instanceLoc) {
if (instanceLoc.isSet()) {
return false;
}
ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc.getDefault());
String[] recentWorkspaces = launchData.getRecentWorkspaces();
if (recentWorkspaces != null && recentWorkspaces.length > 1 && !ArrayUtils.contains(recentWorkspaces, WORKSPACE_DIR_CURRENT)) {
// Add default workspace in the recent list
boolean added = false;
for (int i = 0; i < recentWorkspaces.length; i++) {
if (recentWorkspaces[i] == null) {
recentWorkspaces[i] = WORKSPACE_DIR_CURRENT;
added = true;
break;
}
}
if (!added) {
recentWorkspaces[recentWorkspaces.length - 1] = WORKSPACE_DIR_CURRENT;
}
launchData.setRecentWorkspaces(recentWorkspaces);
launchData.writePersistedData();
}
if (!ArrayUtils.isEmpty(recentWorkspaces)) {
String lastWorkspace = recentWorkspaces[0];
if (!CommonUtils.isEmpty(lastWorkspace) && !WORKSPACE_DIR_CURRENT.equals(lastWorkspace)) {
try {
final URL selectedWorkspaceURL = new URL(
"file", //$NON-NLS-1$
null,
lastWorkspace);
instanceLoc.set(selectedWorkspaceURL, true);
return true;
} catch (Exception e) {
System.err.println("Can't set IDE workspace to '" + lastWorkspace + "'");
e.printStackTrace();
}
}
}
return false;
}
private String getDefaultInstanceLocation() {
String defaultHomePath = WORKSPACE_DIR_CURRENT;
Location instanceLoc = Platform.getInstanceLocation();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册