mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
feat: press and hold Shift to close Tab (#131)
This commit is contained in:
@@ -32,6 +32,25 @@ class MyTabbedPane : FlatTabbedPane() {
|
|||||||
addMouseMotionListener(dragMouseAdaptor)
|
addMouseMotionListener(dragMouseAdaptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun processMouseEvent(e: MouseEvent) {
|
||||||
|
// Shift + Click ===> close tab
|
||||||
|
if (e.id == MouseEvent.MOUSE_CLICKED && SwingUtilities.isLeftMouseButton(e) && isShiftPressedOnly(e.modifiersEx)) {
|
||||||
|
val index = indexAtLocation(e.x, e.y)
|
||||||
|
if (index >= 0) {
|
||||||
|
tabCloseCallback?.accept(this, index)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.processMouseEvent(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isShiftPressedOnly(modifiersEx: Int): Boolean {
|
||||||
|
return (modifiersEx and InputEvent.ALT_DOWN_MASK) == 0
|
||||||
|
&& (modifiersEx and InputEvent.ALT_GRAPH_DOWN_MASK) == 0
|
||||||
|
&& (modifiersEx and InputEvent.CTRL_DOWN_MASK) == 0
|
||||||
|
&& (modifiersEx and InputEvent.SHIFT_DOWN_MASK) != 0
|
||||||
|
}
|
||||||
|
|
||||||
override fun setSelectedIndex(index: Int) {
|
override fun setSelectedIndex(index: Int) {
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
super.setSelectedIndex(index)
|
super.setSelectedIndex(index)
|
||||||
|
|||||||
Reference in New Issue
Block a user