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:
parent
fe2dfb7dd2
commit
a7e14187ea
2 changed files with 62 additions and 41 deletions
|
@ -106,52 +106,55 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the local terminal working directory.
|
// Initialize the local terminal working directory.
|
||||||
// By default, start the local terminal in the users home directory
|
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR)) {
|
||||||
String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
|
// By default, start the local terminal in the users home directory
|
||||||
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
|
String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
|
||||||
String cwd = null;
|
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
|
||||||
if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd)
|
String cwd = null;
|
||||||
|| "".equals(initialCwd.trim())) { //$NON-NLS-1$
|
if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd)
|
||||||
cwd = System.getProperty("user.home"); //$NON-NLS-1$
|
|| "".equals(initialCwd.trim())) { //$NON-NLS-1$
|
||||||
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd)) {
|
cwd = System.getProperty("user.home"); //$NON-NLS-1$
|
||||||
String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
|
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd)) {
|
||||||
if (eclipseHomeLocation != null) {
|
String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
|
||||||
|
if (eclipseHomeLocation != null) {
|
||||||
|
try {
|
||||||
|
URI uri = URIUtil.fromString(eclipseHomeLocation);
|
||||||
|
File f = URIUtil.toFile(uri);
|
||||||
|
cwd = f.getAbsolutePath();
|
||||||
|
} catch (URISyntaxException ex) {
|
||||||
|
/* ignored on purpose */ }
|
||||||
|
}
|
||||||
|
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd)) {
|
||||||
|
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
||||||
|
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) {
|
||||||
|
cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation()
|
||||||
|
.toOSString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
URI uri = URIUtil.fromString(eclipseHomeLocation);
|
// Resolve possible dynamic variables
|
||||||
File f = URIUtil.toFile(uri);
|
IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager();
|
||||||
cwd = f.getAbsolutePath();
|
String resolved = vm.performStringSubstitution(initialCwd);
|
||||||
} catch (URISyntaxException ex) {
|
|
||||||
/* ignored on purpose */ }
|
|
||||||
}
|
|
||||||
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd)) {
|
|
||||||
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
|
||||||
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) {
|
|
||||||
cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation()
|
|
||||||
.toOSString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
// Resolve possible dynamic variables
|
|
||||||
IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager();
|
|
||||||
String resolved = vm.performStringSubstitution(initialCwd);
|
|
||||||
|
|
||||||
IPath p = new Path(resolved);
|
IPath p = new Path(resolved);
|
||||||
if (p.toFile().canRead() && p.toFile().isDirectory()) {
|
if (p.toFile().canRead() && p.toFile().isDirectory()) {
|
||||||
cwd = p.toOSString();
|
cwd = p.toOSString();
|
||||||
}
|
}
|
||||||
} catch (CoreException ex) {
|
} catch (CoreException ex) {
|
||||||
if (Platform.inDebugMode()) {
|
if (Platform.inDebugMode()) {
|
||||||
UIPlugin.getDefault().getLog().log(ex.getStatus());
|
UIPlugin.getDefault().getLog().log(ex.getStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (cwd != null && !"".equals(cwd)) { //$NON-NLS-1$
|
if (cwd != null && !"".equals(cwd)) { //$NON-NLS-1$
|
||||||
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, cwd);
|
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, cwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current selection resolved to an folder, default the working directory
|
// If the current selection resolved to an folder, default the working directory
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Assert;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.swt.custom.CTabItem;
|
import org.eclipse.swt.custom.CTabItem;
|
||||||
|
@ -113,6 +114,17 @@ public class TerminalsViewMementoHandler {
|
||||||
connectionMemento.putString(ITerminalsConnectorConstants.PROP_ENCODING, encoding);
|
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
|
// Pass on to the memento handler
|
||||||
mementoHandler.saveState(connectionMemento, properties);
|
mementoHandler.saveState(connectionMemento, properties);
|
||||||
}
|
}
|
||||||
|
@ -164,6 +176,12 @@ public class TerminalsViewMementoHandler {
|
||||||
connection.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
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
|
// Get the terminal launcher delegate
|
||||||
String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID);
|
String delegateId = (String) properties.get(ITerminalsConnectorConstants.PROP_DELEGATE_ID);
|
||||||
ILauncherDelegate delegate = delegateId != null
|
ILauncherDelegate delegate = delegateId != null
|
||||||
|
|
Loading…
Add table
Reference in a new issue