Make terminal shell path setting application level again (IDEA-164206)

This commit is contained in:
Dmitry Trofimov
2016-11-24 16:53:47 +01:00
parent 6719232f93
commit 3b96bd0885
10 changed files with 197 additions and 174 deletions
@@ -255,7 +255,7 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Ter
}
private void installKeyDispatcher() {
if (TerminalOptionsProvider.getInstance().overrideIdeShortcuts()) {
if (TerminalOptionsProvider.Companion.getInstance().overrideIdeShortcuts()) {
myActionsToSkip = setupActionsToSkip();
IdeEventQueue.getInstance().addDispatcher(this, this);
}
@@ -134,13 +134,13 @@ public class JBTerminalSystemSettingsProvider extends DefaultTabbedSettingsProvi
@Override
public boolean shouldCloseTabOnLogout(TtyConnector ttyConnector) {
return TerminalOptionsProvider.getInstance().closeSessionOnLogout();
return TerminalOptionsProvider.Companion.getInstance().closeSessionOnLogout();
}
@Override
public String tabName(TtyConnector ttyConnector, String sessionName) { //for local terminal use name from settings
if (ttyConnector instanceof PtyProcessTtyConnector) {
return TerminalOptionsProvider.getInstance().getTabName();
return TerminalOptionsProvider.Companion.getInstance().getTabName();
}
else {
return sessionName;
@@ -234,22 +234,22 @@ public class JBTerminalSystemSettingsProvider extends DefaultTabbedSettingsProvi
@Override
public boolean audibleBell() {
return TerminalOptionsProvider.getInstance().audibleBell();
return TerminalOptionsProvider.Companion.getInstance().audibleBell();
}
@Override
public boolean enableMouseReporting() {
return TerminalOptionsProvider.getInstance().enableMouseReporting();
return TerminalOptionsProvider.Companion.getInstance().enableMouseReporting();
}
@Override
public boolean copyOnSelect() {
return TerminalOptionsProvider.getInstance().copyOnSelection();
return TerminalOptionsProvider.Companion.getInstance().copyOnSelection();
}
@Override
public boolean pasteOnMiddleMouseClick() {
return TerminalOptionsProvider.getInstance().pasteOnMiddleMouseButton();
return TerminalOptionsProvider.Companion.getInstance().pasteOnMiddleMouseButton();
}
@NotNull
@@ -89,7 +89,7 @@ public class JBTerminalWidget extends JediTermWidget implements Disposable{
@Override
public List<TerminalAction> getActions() {
List<TerminalAction> actions = super.getActions();
if (!TerminalOptionsProvider.getInstance().overrideIdeShortcuts()) {
if (!TerminalOptionsProvider.Companion.getInstance().overrideIdeShortcuts()) {
actions
.add(new TerminalAction("EditorEscape", new KeyStroke[]{KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)}, new Predicate<KeyEvent>() {
@Override
@@ -84,7 +84,8 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
String rcfile = "jediterm-" + shellName + ".in";
if ("zsh".equals(shellName)) {
rcfile = ".zshrc";
} else if ("fish".equals(shellName)) {
}
else if ("fish".equals(shellName)) {
rcfile = "fish/config.fish";
}
URL resource = LocalTerminalDirectRunner.class.getClassLoader().getResource(rcfile);
@@ -169,11 +170,11 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
String shellPath = getShellPath();
return getCommand(shellPath, envs, TerminalOptionsProvider.getInstance().shellIntegration());
return getCommand(shellPath, envs, TerminalOptionsProvider.Companion.getInstance().shellIntegration());
}
private String getShellPath() {
return TerminalProjectOptionsProvider.Companion.getInstance(myProject).getShellPath();
private static String getShellPath() {
return TerminalOptionsProvider.Companion.getInstance().getShellPath();
}
@NotNull
@@ -37,7 +37,7 @@ public class TerminalOptionsConfigurable implements SearchableConfigurable, Conf
private final TerminalProjectOptionsProvider myProjectOptionsProvider;
public TerminalOptionsConfigurable(@NotNull Project project) {
myOptionsProvider = TerminalOptionsProvider.getInstance();
myOptionsProvider = TerminalOptionsProvider.Companion.getInstance();
myProjectOptionsProvider = TerminalProjectOptionsProvider.Companion.getInstance(project);
}
@@ -1,129 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.terminal;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
/**
* @author traff
*/
@State(
name = "TerminalOptionsProvider",
storages = @Storage("terminal.xml")
)
public class TerminalOptionsProvider implements PersistentStateComponent<TerminalOptionsProvider.State> {
private State myState = new State();
public static TerminalOptionsProvider getInstance() {
return ServiceManager.getService(TerminalOptionsProvider.class);
}
@Override
public State getState() {
return myState;
}
@Override
public void loadState(State state) {
myState.myCloseSessionOnLogout = state.myCloseSessionOnLogout;
myState.myReportMouse = state.myReportMouse;
myState.mySoundBell = state.mySoundBell;
myState.myTabName = state.myTabName;
myState.myCopyOnSelection = state.myCopyOnSelection;
myState.myPasteOnMiddleMouseButton = state.myPasteOnMiddleMouseButton;
myState.myOverrideIdeShortcuts = state.myOverrideIdeShortcuts;
myState.myShellIntegration = state.myShellIntegration;
}
public boolean closeSessionOnLogout() {
return myState.myCloseSessionOnLogout;
}
public boolean enableMouseReporting() {
return myState.myReportMouse;
}
public boolean audibleBell() {
return myState.mySoundBell;
}
public String getTabName() {
return myState.myTabName;
}
public boolean overrideIdeShortcuts() {
return myState.myOverrideIdeShortcuts;
}
public void setOverrideIdeShortcuts(boolean overrideIdeShortcuts) {
myState.myOverrideIdeShortcuts = overrideIdeShortcuts;
}
public boolean shellIntegration() {
return myState.myShellIntegration;
}
public void setShellIntegration(boolean shellIntegration) {
myState.myShellIntegration = shellIntegration;
}
public static class State {
public String myTabName = "Local";
public boolean myCloseSessionOnLogout = true;
public boolean myReportMouse = true;
public boolean mySoundBell = true;
public boolean myCopyOnSelection = true;
public boolean myPasteOnMiddleMouseButton = true;
public boolean myOverrideIdeShortcuts = true;
public boolean myShellIntegration = true;
}
public void setTabName(String tabName) {
myState.myTabName = tabName;
}
public void setCloseSessionOnLogout(boolean closeSessionOnLogout) {
myState.myCloseSessionOnLogout = closeSessionOnLogout;
}
public void setReportMouse(boolean reportMouse) {
myState.myReportMouse = reportMouse;
}
public void setSoundBell(boolean soundBell) {
myState.mySoundBell = soundBell;
}
public boolean copyOnSelection() {
return myState.myCopyOnSelection;
}
public void setCopyOnSelection(boolean copyOnSelection) {
myState.myCopyOnSelection = copyOnSelection;
}
public boolean pasteOnMiddleMouseButton() {
return myState.myPasteOnMiddleMouseButton;
}
public void setPasteOnMiddleMouseButton(boolean pasteOnMiddleMouseButton) {
myState.myPasteOnMiddleMouseButton = pasteOnMiddleMouseButton;
}
}
@@ -0,0 +1,155 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.terminal
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.util.SystemInfo
import java.io.File
/**
* @author traff
*/
@State(name = "TerminalOptionsProvider", storages = arrayOf(Storage("terminal.xml")))
class TerminalOptionsProvider : PersistentStateComponent<TerminalOptionsProvider.State> {
private val myState = State()
var shellPath: String? by ValueWithDefault(State::myShellPath, myState) { defaultShellPath }
override fun getState(): State? {
return myState
}
override fun loadState(state: State) {
myState.myCloseSessionOnLogout = state.myCloseSessionOnLogout
myState.myReportMouse = state.myReportMouse
myState.mySoundBell = state.mySoundBell
myState.myTabName = state.myTabName
myState.myCopyOnSelection = state.myCopyOnSelection
myState.myPasteOnMiddleMouseButton = state.myPasteOnMiddleMouseButton
myState.myOverrideIdeShortcuts = state.myOverrideIdeShortcuts
myState.myShellIntegration = state.myShellIntegration
myState.myShellPath = state.myShellPath
}
fun closeSessionOnLogout(): Boolean {
return myState.myCloseSessionOnLogout
}
fun enableMouseReporting(): Boolean {
return myState.myReportMouse
}
fun audibleBell(): Boolean {
return myState.mySoundBell
}
var tabName: String
get() = myState.myTabName
set(tabName) {
myState.myTabName = tabName
}
fun overrideIdeShortcuts(): Boolean {
return myState.myOverrideIdeShortcuts
}
fun setOverrideIdeShortcuts(overrideIdeShortcuts: Boolean) {
myState.myOverrideIdeShortcuts = overrideIdeShortcuts
}
fun shellIntegration(): Boolean {
return myState.myShellIntegration
}
fun setShellIntegration(shellIntegration: Boolean) {
myState.myShellIntegration = shellIntegration
}
class State {
var myShellPath: String? = null
var myTabName = "Local"
var myCloseSessionOnLogout = true
var myReportMouse = true
var mySoundBell = true
var myCopyOnSelection = true
var myPasteOnMiddleMouseButton = true
var myOverrideIdeShortcuts = true
var myShellIntegration = true
}
fun setCloseSessionOnLogout(closeSessionOnLogout: Boolean) {
myState.myCloseSessionOnLogout = closeSessionOnLogout
}
fun setReportMouse(reportMouse: Boolean) {
myState.myReportMouse = reportMouse
}
fun setSoundBell(soundBell: Boolean) {
myState.mySoundBell = soundBell
}
fun copyOnSelection(): Boolean {
return myState.myCopyOnSelection
}
fun setCopyOnSelection(copyOnSelection: Boolean) {
myState.myCopyOnSelection = copyOnSelection
}
fun pasteOnMiddleMouseButton(): Boolean {
return myState.myPasteOnMiddleMouseButton
}
fun setPasteOnMiddleMouseButton(pasteOnMiddleMouseButton: Boolean) {
myState.myPasteOnMiddleMouseButton = pasteOnMiddleMouseButton
}
val defaultShellPath: String
get() {
val shell = System.getenv("SHELL")
if (shell != null && File(shell).canExecute()) {
return shell
}
if (SystemInfo.isUnix) {
if (File("/bin/bash").exists()) {
return "/bin/bash"
}
else {
return "/bin/sh"
}
}
else {
return "cmd.exe"
}
}
companion object {
val instance: TerminalOptionsProvider
get() = ServiceManager.getService(TerminalOptionsProvider::class.java)
}
}
@@ -24,7 +24,8 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.SystemInfo
import java.io.File
import kotlin.reflect.*
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
/**
* @author traff
@@ -39,18 +40,13 @@ class TerminalProjectOptionsProvider(val project: Project) : PersistentStateComp
}
override fun loadState(state: State) {
myState.myShellPath = state.myShellPath
myState.myStartingDirectory = state.myStartingDirectory
}
class State {
var myShellPath: String? = null
var myStartingDirectory: String? = null
}
var shellPath: String? by ValueWithDefault(State::myShellPath, myState) { defaultShellPath }
var startingDirectory: String? by ValueWithDefault(State::myStartingDirectory, myState) { defaultStartingDirectory }
val defaultStartingDirectory: String?
@@ -117,7 +113,7 @@ class TerminalProjectOptionsProvider(val project: Project) : PersistentStateComp
// TODO: In Kotlin 1.1 it will be possible to pass references to instance properties. Until then we need 'state' argument as a reciever for
// to property to apply
class ValueWithDefault(val prop: KMutableProperty1<TerminalProjectOptionsProvider.State, String?>, val state: TerminalProjectOptionsProvider.State, val default: () -> String?) {
class ValueWithDefault<S>(val prop: KMutableProperty1<S, String?>, val state: S, val default: () -> String?) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String? {
return if (prop.get(state) !== null) prop.get(state) else default()
}
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="482"/>
<xy x="20" y="20" width="500" height="496"/>
</constraints>
<properties/>
<border type="none"/>
@@ -24,7 +24,7 @@
<grid row="2" column="0" row-span="7" col-span="4" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="871ca" binding="myProjectSettingsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="871ca" binding="myProjectSettingsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -32,24 +32,9 @@
<properties/>
<border type="none"/>
<children>
<component id="b854b" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="2"/>
<text value="Shell path"/>
</properties>
</component>
<component id="aad87" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myShellPathField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="40fca" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="2"/>
@@ -58,7 +43,7 @@
</component>
<component id="16cd7" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myStartDirectoryField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
@@ -72,7 +57,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="57ec0" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="57ec0" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -82,7 +67,7 @@
<children>
<component id="f633a" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="2"/>
@@ -91,12 +76,27 @@
</component>
<component id="5495b" class="javax.swing.JTextField" binding="myTabNameTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b854b" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="2"/>
<text value="Shell path"/>
</properties>
</component>
<component id="aad87" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myShellPathField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="b4260" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -115,7 +115,7 @@ public class TerminalSettingsPanel {
}
public boolean isModified() {
return !Comparing.equal(myShellPathField.getText(), myProjectOptionsProvider.getShellPath())
return !Comparing.equal(myShellPathField.getText(), myOptionsProvider.getShellPath())
|| !Comparing.equal(myStartDirectoryField.getText(), myProjectOptionsProvider.getStartingDirectory())
|| !Comparing.equal(myTabNameTextField.getText(), myOptionsProvider.getTabName())
|| (myCloseSessionCheckBox.isSelected() != myOptionsProvider.closeSessionOnLogout())
@@ -129,8 +129,8 @@ public class TerminalSettingsPanel {
}
public void apply() {
myProjectOptionsProvider.setShellPath(myShellPathField.getText());
myProjectOptionsProvider.setStartingDirectory(myStartDirectoryField.getText());
myOptionsProvider.setShellPath(myShellPathField.getText());
myOptionsProvider.setTabName(myTabNameTextField.getText());
myOptionsProvider.setCloseSessionOnLogout(myCloseSessionCheckBox.isSelected());
myOptionsProvider.setReportMouse(myMouseReportCheckBox.isSelected());
@@ -150,7 +150,7 @@ public class TerminalSettingsPanel {
}
public void reset() {
myShellPathField.setText(myProjectOptionsProvider.getShellPath());
myShellPathField.setText(myOptionsProvider.getShellPath());
myStartDirectoryField.setText(myProjectOptionsProvider.getStartingDirectory());
myTabNameTextField.setText(myOptionsProvider.getTabName());
myCloseSessionCheckBox.setSelected(myOptionsProvider.closeSessionOnLogout());