diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/plugin.properties b/plugins/org.eclipse.tcf.te.ui.terminals.local/plugin.properties index be513782cda..ceb5be00523 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/plugin.properties +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/plugin.properties @@ -20,4 +20,4 @@ menu.showIn.localterminal.label = Terminals # ----- Preference Pages ----- -preference.page.name=Terminals View +preference.page.name=Local Terminal diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java index 533be9359b8..1baa6bf4e31 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java @@ -257,10 +257,13 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { } } if (shell == null) { - if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - shell = System.getenv("SHELL").trim(); //$NON-NLS-1$ - } else { - shell = "/bin/sh"; //$NON-NLS-1$ + shell = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + if (shell == null || "".equals(shell)) { //$NON-NLS-1$ + if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + shell = System.getenv("SHELL").trim(); //$NON-NLS-1$ + } else { + shell = "/bin/sh"; //$NON-NLS-1$ + } } } @@ -288,6 +291,11 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH); } + String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); + if (arguments == null && !Platform.OS_WIN32.equals(Platform.getOS())) { + arguments = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); + } + // Determine if a PTY will be used boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null && PTY.isSupported(PTY.Mode.TERMINAL)) || properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ) instanceof PTY; @@ -314,7 +322,6 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR); } - String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS); Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ); PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ); ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS); diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.java b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.java index 515c37d6ad9..aff56bf5b6a 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.java +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.java @@ -46,6 +46,13 @@ public class Messages extends NLS { public static String PreferencePage_workingDir_note_label; public static String PreferencePage_workingDir_note_text; public static String PreferencePage_workingDir_button_variables; + public static String PreferencePage_workingDir_invalid; + public static String PreferencePage_command_label; + public static String PreferencePage_command_button_browse; + public static String PreferencePage_command_invalid; + public static String PreferencePage_command_note_label; + public static String PreferencePage_command_note_text; + public static String PreferencePage_command_arguments_label; public static String ExternalExecutablesDialog_title_add; public static String ExternalExecutablesDialog_title_edit; diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.properties b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.properties index aa446624e9a..8bc8c292ae5 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.properties +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/nls/Messages.properties @@ -22,18 +22,25 @@ ExternalExecutablesDialog_field_translate=Translate Backslashes on Paste # ----- Preference Pages ----- -PreferencePage_label=General Terminals view settings: +PreferencePage_label=Local Terminal Settings: PreferencePage_executables_label="Show In ..." Custom Entries PreferencePage_executables_column_name_label=Name PreferencePage_executables_column_path_label=Path PreferencePage_executables_button_add_label=Add... PreferencePage_executables_button_edit_label=Edit... PreferencePage_executables_button_remove_label=Remove -PreferencePage_workingDir_label=Local Terminal Initial Working Directory +PreferencePage_workingDir_label=Initial Working Directory PreferencePage_workingDir_userhome_label=User home PreferencePage_workingDir_eclipsehome_label=Eclipse home PreferencePage_workingDir_eclipsews_label=Eclipse workspace PreferencePage_workingDir_button_browse=&Browse... PreferencePage_workingDir_note_label=Note: PreferencePage_workingDir_note_text=The chosen initial working directory might be overwritten by the current selection of the active view. -PreferencePage_workingDir_button_variables=&Variables... +PreferencePage_workingDir_button_variables=&Variables... +PreferencePage_workingDir_invalid=Selected initial working directory is not a directory or is not readable. +PreferencePage_command_label=Shell Command +PreferencePage_command_button_browse=&Browse... +PreferencePage_command_invalid=Selected shell command is not a file or is not readable or executable. +PreferencePage_command_note_label=Note: +PreferencePage_command_note_text=Leave the shell command empty to fallback to the SHELL environment variable or if not set, to /bin/sh. +PreferencePage_command_arguments_label=Arguments: diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/interfaces/IPreferenceKeys.java b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/interfaces/IPreferenceKeys.java index 6bf6c3444cf..631ac16c159 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/interfaces/IPreferenceKeys.java +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/interfaces/IPreferenceKeys.java @@ -19,7 +19,7 @@ public interface IPreferenceKeys { public final String PREF_TERMINAL = "terminals"; //$NON-NLS-1$ /** - * Preference key: Remove terminated terminals when a new terminal is created. + * Preference key: Local terminal initial working directory. */ public final String PREF_LOCAL_TERMINAL_INITIAL_CWD = PREF_TERMINAL + ".localTerminalInitialCwd"; //$NON-NLS-1$ @@ -37,4 +37,14 @@ public interface IPreferenceKeys { * Preference value: Local terminal initial working directory is "Eclipse workspace" */ public final String PREF_INITIAL_CWD_ECLIPSE_WS = "eclipsews"; //$NON-NLS-1$ + + /** + * Preference key: Local terminal default shell command on Unix hosts. + */ + public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX = PREF_TERMINAL + ".localTerminalDefaultShellUnix"; //$NON-NLS-1$ + + /** + * Preference key: Local terminal default shell command arguments on Unix hosts. + */ + public final String PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS = PREF_TERMINAL + ".localTerminalDefaultShellUnixArgs"; //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencePage.java b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencePage.java index 8a3e9d140b8..c47135dd48f 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencePage.java +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencePage.java @@ -56,10 +56,12 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; import org.eclipse.tcf.te.ui.terminals.controls.NoteCompositeHelper; import org.eclipse.tcf.te.ui.terminals.local.activator.UIPlugin; import org.eclipse.tcf.te.ui.terminals.local.nls.Messages; @@ -85,6 +87,10 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage private Button variablesButton; private boolean hasVariablesButton = false; + /* default */ Text command; + private Button commandBrowseButton; + private Text arguments; + /* default */ final List> executables = new ArrayList>(); /* default */ final Map images = new HashMap(); @@ -118,6 +124,89 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage label.setText(Messages.PreferencePage_label); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (!Platform.OS_WIN32.equals(Platform.getOS())) { + Group group = new Group(panel, SWT.NONE); + group.setText(Messages.PreferencePage_command_label); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + + command = new Text(group, SWT.SINGLE | SWT.BORDER); + command.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + command.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + boolean valid = true; + String message = null; + + String text = command.getText(); + if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ + IPath p = new Path(text.trim()); + valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute(); + if (!valid) message = Messages.PreferencePage_command_invalid; + } + + setValid(valid); + setErrorMessage(message); + } + }); + + commandBrowseButton = new Button(group, SWT.PUSH); + commandBrowseButton.setText(Messages.PreferencePage_command_button_browse); + layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); + layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); + commandBrowseButton.setLayoutData(layoutData); + commandBrowseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); + + String text = command.getText(); + if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ + IPath p = new Path(text); + + if (p.toFile().isFile() || !p.toFile().exists()) { + dialog.setFilterPath(p.removeLastSegments(1).toOSString()); + dialog.setFileName(p.lastSegment()); + } else if (p.toFile().isDirectory()) { + dialog.setFilterPath(p.toOSString()); + } + } + + String selected = dialog.open(); + if (selected != null) { + IPath sp = new Path(selected); + command.setText(sp.toOSString()); + } + } + }); + + String cmd = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); + if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$ + command.setText(new Path(cmd).toOSString()); + } + + Composite argsPanel = new Composite(group, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; layout.marginWidth = 0; + argsPanel.setLayout(layout); + layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + layoutData.horizontalSpan = 2; + argsPanel.setLayoutData(layoutData); + + label = new Label(argsPanel, SWT.NONE); + label.setText(Messages.PreferencePage_command_arguments_label); + + arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER); + arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + String args = UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); + if (args != null && !"".equals(args)) { //$NON-NLS-1$ + arguments.setText(args); + } + + NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, Messages.PreferencePage_command_note_text); + } + Group group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_workingDir_label); group.setLayout(new GridLayout(hasVariablesButton ? 3 : 2, false)); @@ -150,6 +239,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage IPath p = new Path(resolved); valid = p.toFile().canRead() && p.toFile().isDirectory(); + if (!valid) message = Messages.PreferencePage_workingDir_invalid; } catch (CoreException ex) { valid = false; message = ex.getLocalizedMessage(); @@ -509,6 +599,11 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage */ @Override protected void performDefaults() { + if (!Platform.OS_WIN32.equals(Platform.getOS())) { + command.setText(""); //$NON-NLS-1$ + arguments.setText(""); //$NON-NLS-1$ + } + String initialCwd = UIPlugin.getScopedPreferences().getDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$ workingDir.select(0); @@ -533,6 +628,15 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage */ @Override public boolean performOk() { + if (!Platform.OS_WIN32.equals(Platform.getOS())) { + String text = command.getText(); + IPath p = new Path(text.trim()); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute() ? p.toOSString() : null); + + text = arguments.getText(); + UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS, !"".equals(text.trim()) ? text.trim() : null); //$NON-NLS-1$ + } + String text = workingDir.getText(); if (text == null || Messages.PreferencePage_workingDir_userhome_label.equals(text) || "".equals(text.trim())) { //$NON-NLS-1$ UIPlugin.getScopedPreferences().putString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, null); diff --git a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencesInitializer.java b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencesInitializer.java index 11d7d9d1b64..036e3e34e31 100644 --- a/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencesInitializer.java +++ b/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/showin/preferences/PreferencesInitializer.java @@ -33,5 +33,6 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer { ScopedEclipsePreferences prefs = UIPlugin.getScopedPreferences(); prefs.putDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD, IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME); + prefs.putDefaultString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX, null); } }