1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Bug 453696: Save CWD in terminal to restore it

Change-Id: I6a432fcbd40f6b4e991e49ba582b8b9f7cae823e
This commit is contained in:
Jonah Graham 2021-05-19 12:13:46 -04:00
parent fe2dfb7dd2
commit a7e14187ea
2 changed files with 62 additions and 41 deletions

View file

@ -106,6 +106,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
}
// Initialize the local terminal working directory.
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR)) {
// By default, start the local terminal in the users home directory
String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
@ -128,7 +129,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) {
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot()
.getLocation() != null) {
cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation()
.toOSString();
}
@ -153,6 +155,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
if (cwd != null && !"".equals(cwd)) { //$NON-NLS-1$
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, cwd);
}
}
// If the current selection resolved to an folder, default the working directory
// to that folder and update the terminal title

View file

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.custom.CTabItem;
@ -113,6 +114,17 @@ public class TerminalsViewMementoHandler {
connectionMemento.putString(ITerminalsConnectorConstants.PROP_ENCODING, encoding);
}
// Store the current working directory, or if not available, the initial working directory
if (terminal != null) {
encoding = terminal.getEncoding();
Optional<String> workingDirectory = terminal.getTerminalConnector().getWorkingDirectory();
String cwd = workingDirectory
.orElse((String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR));
if (cwd != null) {
connectionMemento.putString(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, cwd);
}
}
// Pass on to the memento handler
mementoHandler.saveState(connectionMemento, properties);
}
@ -164,6 +176,12 @@ public class TerminalsViewMementoHandler {
connection.getString(ITerminalsConnectorConstants.PROP_ENCODING));
}
// Restore the working directory
if (connection.getString(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR) != null) {
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR,
connection.getString(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR));
}
// Get the terminal launcher delegate
String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID);
ILauncherDelegate delegate = delegateId != null