mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
feat: support right click copy and paste
This commit is contained in:
@@ -404,6 +404,7 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
private val fontSizeTextField = IntSpinner(0, 9, 99)
|
||||
private val terminalSetting get() = DatabaseManager.getInstance().terminal
|
||||
private val selectCopyComboBox = YesOrNoComboBox()
|
||||
private val rightClickComboBox = OutlineComboBox<String>()
|
||||
private val autoCloseTabComboBox = YesOrNoComboBox()
|
||||
private val floatingToolbarComboBox = YesOrNoComboBox()
|
||||
private val hyperlinkComboBox = YesOrNoComboBox()
|
||||
@@ -417,6 +418,12 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
}
|
||||
}
|
||||
|
||||
rightClickComboBox.addItemListener {
|
||||
if (it.stateChange == ItemEvent.SELECTED) {
|
||||
terminalSetting.rightClick = rightClickComboBox.selectedItem as String
|
||||
}
|
||||
}
|
||||
|
||||
fallbackFontComboBox.addItemListener {
|
||||
if (it.stateChange == ItemEvent.SELECTED) {
|
||||
terminalSetting.fallbackFont = fallbackFontComboBox.selectedItem as String
|
||||
@@ -518,6 +525,10 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
fontSizeTextField.value = terminalSetting.fontSize
|
||||
maxRowsTextField.value = terminalSetting.maxRows
|
||||
|
||||
rightClickComboBox.addItem("Copy")
|
||||
rightClickComboBox.addItem("CopyAndPaste")
|
||||
|
||||
rightClickComboBox.selectedItem = terminalSetting.rightClick
|
||||
|
||||
cursorStyleComboBox.renderer = object : DefaultListCellRenderer() {
|
||||
override fun getListCellRendererComponent(
|
||||
@@ -532,6 +543,24 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
}
|
||||
}
|
||||
|
||||
rightClickComboBox.renderer = object : DefaultListCellRenderer() {
|
||||
override fun getListCellRendererComponent(
|
||||
list: JList<*>?,
|
||||
value: Any?,
|
||||
index: Int,
|
||||
isSelected: Boolean,
|
||||
cellHasFocus: Boolean
|
||||
): Component {
|
||||
var text = value?.toString()
|
||||
if (value == "Copy") {
|
||||
text = I18n.getString("termora.settings.terminal.right-click.copy")
|
||||
} else if (value == "CopyAndPaste") {
|
||||
text = I18n.getString("termora.settings.terminal.right-click.copy-and-paste")
|
||||
}
|
||||
return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus)
|
||||
}
|
||||
}
|
||||
|
||||
cursorStyleComboBox.addItem(CursorStyle.Block)
|
||||
cursorStyleComboBox.addItem(CursorStyle.Bar)
|
||||
cursorStyleComboBox.addItem(CursorStyle.Underline)
|
||||
@@ -595,7 +624,7 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
private fun getCenterComponent(): JComponent {
|
||||
val layout = FormLayout(
|
||||
"left:pref, $FORM_MARGIN, default:grow, $FORM_MARGIN, left:pref, $FORM_MARGIN, pref, default:grow",
|
||||
"pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref"
|
||||
"pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref"
|
||||
)
|
||||
|
||||
val beepBtn = JButton(Icons.run)
|
||||
@@ -624,6 +653,8 @@ class SettingsOptionsPane : OptionsPane() {
|
||||
.add(hyperlinkComboBox).xy(3, rows).apply { rows += step }
|
||||
.add("${I18n.getString("termora.settings.terminal.select-copy")}:").xy(1, rows)
|
||||
.add(selectCopyComboBox).xy(3, rows).apply { rows += step }
|
||||
.add("${I18n.getString("termora.settings.terminal.right-click")}:").xy(1, rows)
|
||||
.add(rightClickComboBox).xy(3, rows).apply { rows += step }
|
||||
.add("${I18n.getString("termora.settings.terminal.cursor-style")}:").xy(1, rows)
|
||||
.add(cursorStyleComboBox).xy(3, rows).apply { rows += step }
|
||||
.add("${I18n.getString("termora.settings.terminal.cursor-blink")}:").xy(1, rows)
|
||||
|
||||
@@ -666,6 +666,11 @@ class DatabaseManager private constructor() : Disposable {
|
||||
*/
|
||||
var selectCopy by BooleanPropertyDelegate(false)
|
||||
|
||||
/**
|
||||
* 右键点击:Copy、CopyAndPaste
|
||||
*/
|
||||
var rightClick by StringPropertyDelegate("Copy")
|
||||
|
||||
/**
|
||||
* 光标样式
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@ package app.termora.terminal.panel
|
||||
import app.termora.actions.AnActionEvent
|
||||
import app.termora.actions.TerminalCopyAction
|
||||
import app.termora.actions.TerminalPasteAction
|
||||
import app.termora.database.DatabaseManager
|
||||
import app.termora.terminal.*
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.jdesktop.swingx.action.ActionManager
|
||||
@@ -27,6 +28,7 @@ class TerminalPanelMouseSelectionAdapter(private val terminalPanel: TerminalPane
|
||||
private val isSelectCopy get() = terminalModel.getData(TerminalPanel.SelectCopy, false)
|
||||
private val selectionModel get() = terminal.getSelectionModel()
|
||||
private val wordBreakIterator = BreakIterator.getWordInstance()
|
||||
private val rightClickMode get() = DatabaseManager.getInstance().terminal.rightClick
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(TerminalPanelMouseSelectionAdapter::class.java)
|
||||
@@ -50,7 +52,7 @@ class TerminalPanelMouseSelectionAdapter(private val terminalPanel: TerminalPane
|
||||
|
||||
if (SwingUtilities.isRightMouseButton(e)) {
|
||||
// 如果有选中并且开启了选中复制,那么右键直接是粘贴
|
||||
if (selectionModel.hasSelection() && !isSelectCopy) {
|
||||
if (selectionModel.hasSelection() && isSelectCopy.not()) {
|
||||
triggerCopyAction(
|
||||
KeyEvent(
|
||||
e.component,
|
||||
@@ -61,6 +63,20 @@ class TerminalPanelMouseSelectionAdapter(private val terminalPanel: TerminalPane
|
||||
'C'
|
||||
)
|
||||
)
|
||||
|
||||
if (rightClickMode == "CopyAndPaste") {
|
||||
triggerPasteAction(
|
||||
KeyEvent(
|
||||
e.component,
|
||||
KeyEvent.KEY_PRESSED,
|
||||
e.`when`,
|
||||
e.modifiersEx,
|
||||
KeyEvent.VK_V,
|
||||
'V'
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
} else {
|
||||
// paste
|
||||
triggerPasteAction(
|
||||
|
||||
Reference in New Issue
Block a user