mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 10:22:58 +08:00
fix: custom toolbar action missing (#630)
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package app.termora
|
package app.termora
|
||||||
|
|
||||||
import app.termora.Application.ohMyJson
|
import app.termora.Application.ohMyJson
|
||||||
|
import app.termora.actions.MultipleAction
|
||||||
import com.jgoodies.forms.builder.FormBuilder
|
import com.jgoodies.forms.builder.FormBuilder
|
||||||
import com.jgoodies.forms.layout.FormLayout
|
import com.jgoodies.forms.layout.FormLayout
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import org.jdesktop.swingx.action.ActionManager
|
import org.jdesktop.swingx.action.ActionManager
|
||||||
import java.awt.Component
|
import java.awt.Component
|
||||||
@@ -20,6 +19,7 @@ import kotlin.math.min
|
|||||||
|
|
||||||
class CustomizeToolBarDialog(
|
class CustomizeToolBarDialog(
|
||||||
owner: Window,
|
owner: Window,
|
||||||
|
private val windowScope: WindowScope,
|
||||||
private val toolbar: TermoraToolBar
|
private val toolbar: TermoraToolBar
|
||||||
) : DialogWrapper(owner) {
|
) : DialogWrapper(owner) {
|
||||||
|
|
||||||
@@ -147,9 +147,7 @@ class CustomizeToolBarDialog(
|
|||||||
leftList.model.removeAllElements()
|
leftList.model.removeAllElements()
|
||||||
rightList.model.removeAllElements()
|
rightList.model.removeAllElements()
|
||||||
for (action in toolbar.getAllActions()) {
|
for (action in toolbar.getAllActions()) {
|
||||||
actionManager.getAction(action.id)?.let {
|
getActionHolder(action.id)?.let { rightList.model.addElement(it) }
|
||||||
rightList.model.addElement(ActionHolder(action.id, it))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,14 +257,11 @@ class CustomizeToolBarDialog(
|
|||||||
override fun windowOpened(e: WindowEvent) {
|
override fun windowOpened(e: WindowEvent) {
|
||||||
removeWindowListener(this)
|
removeWindowListener(this)
|
||||||
|
|
||||||
|
|
||||||
for (action in toolbar.getActions()) {
|
for (action in toolbar.getActions()) {
|
||||||
if (action.visible) {
|
if (action.visible) {
|
||||||
actionManager.getAction(action.id)
|
getActionHolder(action.id)?.let { rightList.model.addElement(it) }
|
||||||
?.let { rightList.model.addElement(ActionHolder(action.id, it)) }
|
|
||||||
} else {
|
} else {
|
||||||
actionManager.getAction(action.id)
|
getActionHolder(action.id)?.let { leftList.model.addElement(it) }
|
||||||
?.let { leftList.model.addElement(ActionHolder(action.id, it)) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +269,17 @@ class CustomizeToolBarDialog(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getActionHolder(actionId: String): ActionHolder? {
|
||||||
|
var action = actionManager.getAction(actionId)
|
||||||
|
if (action == null) {
|
||||||
|
if (actionId == MultipleAction.MULTIPLE) {
|
||||||
|
action = MultipleAction.getInstance(windowScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (action == null) return null
|
||||||
|
return ActionHolder(actionId, action)
|
||||||
|
}
|
||||||
|
|
||||||
private fun resetMoveButtons() {
|
private fun resetMoveButtons() {
|
||||||
val indices = rightList.selectedIndices
|
val indices = rightList.selectedIndices
|
||||||
if (indices.isEmpty()) {
|
if (indices.isEmpty()) {
|
||||||
|
|||||||
@@ -423,13 +423,10 @@ class TerminalTabbed(
|
|||||||
val popupMenu = FlatPopupMenu()
|
val popupMenu = FlatPopupMenu()
|
||||||
popupMenu.add(I18n.getString("termora.toolbar.customize-toolbar")).addActionListener {
|
popupMenu.add(I18n.getString("termora.toolbar.customize-toolbar")).addActionListener {
|
||||||
val owner = SwingUtilities.getWindowAncestor(this@TerminalTabbed)
|
val owner = SwingUtilities.getWindowAncestor(this@TerminalTabbed)
|
||||||
val dialog = CustomizeToolBarDialog(
|
val dialog = CustomizeToolBarDialog(owner, windowScope, termoraToolBar)
|
||||||
owner,
|
|
||||||
termoraToolBar
|
|
||||||
)
|
|
||||||
dialog.setLocationRelativeTo(owner)
|
dialog.setLocationRelativeTo(owner)
|
||||||
if (dialog.open()) {
|
if (dialog.open()) {
|
||||||
termoraToolBar.rebuild()
|
TermoraToolBar.rebuild()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
popupMenu.show(event.component, event.x, event.y)
|
popupMenu.show(event.component, event.x, event.y)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class TermoraFrame : JFrame(), DataProvider {
|
|||||||
private val id = UUID.randomUUID().toString()
|
private val id = UUID.randomUUID().toString()
|
||||||
private val windowScope = ApplicationScope.forWindowScope(this)
|
private val windowScope = ApplicationScope.forWindowScope(this)
|
||||||
private val tabbedPane = MyTabbedPane()
|
private val tabbedPane = MyTabbedPane()
|
||||||
private val toolbar = TermoraToolBar(windowScope, this, tabbedPane)
|
private val toolbar = TermoraToolBar(windowScope, this)
|
||||||
private val terminalTabbed = TerminalTabbed(windowScope, toolbar, tabbedPane)
|
private val terminalTabbed = TerminalTabbed(windowScope, toolbar, tabbedPane)
|
||||||
private val dataProviderSupport = DataProviderSupport()
|
private val dataProviderSupport = DataProviderSupport()
|
||||||
private val welcomePanel = WelcomePanel(windowScope)
|
private val welcomePanel = WelcomePanel(windowScope)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import app.termora.actions.*
|
|||||||
import app.termora.findeverywhere.FindEverywhereAction
|
import app.termora.findeverywhere.FindEverywhereAction
|
||||||
import app.termora.snippet.SnippetAction
|
import app.termora.snippet.SnippetAction
|
||||||
import com.formdev.flatlaf.FlatClientProperties
|
import com.formdev.flatlaf.FlatClientProperties
|
||||||
import com.formdev.flatlaf.extras.components.FlatTabbedPane
|
|
||||||
import com.formdev.flatlaf.util.SystemInfo
|
import com.formdev.flatlaf.util.SystemInfo
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
@@ -26,10 +25,21 @@ data class ToolBarAction(
|
|||||||
class TermoraToolBar(
|
class TermoraToolBar(
|
||||||
private val windowScope: WindowScope,
|
private val windowScope: WindowScope,
|
||||||
private val frame: TermoraFrame,
|
private val frame: TermoraFrame,
|
||||||
private val tabbedPane: FlatTabbedPane
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun rebuild() {
|
||||||
|
for (frame in TermoraFrameManager.getInstance().getWindows()) {
|
||||||
|
val toolbars = SwingUtils.getDescendantsOfClass(MyToolBar::class.java, frame)
|
||||||
|
for (toolbar in toolbars) {
|
||||||
|
toolbar.rebuild()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val properties by lazy { Database.getDatabase().properties }
|
private val properties by lazy { Database.getDatabase().properties }
|
||||||
private val toolbar by lazy { MyToolBar().apply { rebuild(this) } }
|
private val toolbar by lazy { MyToolBar().apply { rebuild() } }
|
||||||
|
|
||||||
|
|
||||||
fun getJToolBar(): JToolBar {
|
fun getJToolBar(): JToolBar {
|
||||||
@@ -87,63 +97,6 @@ class TermoraToolBar(
|
|||||||
return storageActions
|
return storageActions
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rebuild() {
|
|
||||||
rebuild(this.toolbar)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun rebuild(toolbar: JToolBar) {
|
|
||||||
val actionManager = ActionManager.getInstance()
|
|
||||||
val actionContainerFactory = ActionContainerFactory(actionManager)
|
|
||||||
|
|
||||||
toolbar.removeAll()
|
|
||||||
|
|
||||||
toolbar.add(actionContainerFactory.createButton(object : AnAction(StringUtils.EMPTY, Icons.add) {
|
|
||||||
override fun actionPerformed(evt: AnActionEvent) {
|
|
||||||
actionManager.getAction(FindEverywhereAction.FIND_EVERYWHERE)?.actionPerformed(evt)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isEnabled(): Boolean {
|
|
||||||
return actionManager.getAction(FindEverywhereAction.FIND_EVERYWHERE)?.isEnabled ?: false
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
toolbar.add(Box.createHorizontalGlue())
|
|
||||||
|
|
||||||
if (SystemInfo.isLinux || SystemInfo.isWindows) {
|
|
||||||
toolbar.add(Box.createHorizontalStrut(16))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update btn
|
|
||||||
val updateBtn = actionContainerFactory.createButton(actionManager.getAction(Actions.APP_UPDATE))
|
|
||||||
updateBtn.isVisible = updateBtn.isEnabled
|
|
||||||
updateBtn.addChangeListener { updateBtn.isVisible = updateBtn.isEnabled }
|
|
||||||
toolbar.add(updateBtn)
|
|
||||||
|
|
||||||
|
|
||||||
// 获取显示的Action,如果不是 false 那么就是显示出来
|
|
||||||
for (action in getActions()) {
|
|
||||||
if (action.visible) {
|
|
||||||
val ac = actionManager.getAction(action.id)
|
|
||||||
if (ac == null) {
|
|
||||||
if (action.id == MultipleAction.MULTIPLE) {
|
|
||||||
toolbar.add(actionContainerFactory.createButton(MultipleAction.getInstance(windowScope)))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toolbar.add(actionContainerFactory.createButton(ac))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (toolbar is MyToolBar) {
|
|
||||||
toolbar.adjust()
|
|
||||||
}
|
|
||||||
|
|
||||||
toolbar.revalidate()
|
|
||||||
toolbar.repaint()
|
|
||||||
}
|
|
||||||
|
|
||||||
private inner class MyToolBar : JToolBar() {
|
private inner class MyToolBar : JToolBar() {
|
||||||
init {
|
init {
|
||||||
// 监听窗口大小变动,然后修改边距避开控制按钮
|
// 监听窗口大小变动,然后修改边距避开控制按钮
|
||||||
@@ -179,5 +132,60 @@ class TermoraToolBar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun rebuild() {
|
||||||
|
val toolbar: JToolBar = this
|
||||||
|
val actionManager = ActionManager.getInstance()
|
||||||
|
val actionContainerFactory = ActionContainerFactory(actionManager)
|
||||||
|
|
||||||
|
toolbar.removeAll()
|
||||||
|
|
||||||
|
toolbar.add(actionContainerFactory.createButton(object : AnAction(StringUtils.EMPTY, Icons.add) {
|
||||||
|
override fun actionPerformed(evt: AnActionEvent) {
|
||||||
|
actionManager.getAction(FindEverywhereAction.FIND_EVERYWHERE)?.actionPerformed(evt)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEnabled(): Boolean {
|
||||||
|
return actionManager.getAction(FindEverywhereAction.FIND_EVERYWHERE)?.isEnabled ?: false
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
toolbar.add(Box.createHorizontalGlue())
|
||||||
|
|
||||||
|
if (SystemInfo.isLinux || SystemInfo.isWindows) {
|
||||||
|
toolbar.add(Box.createHorizontalStrut(16))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update btn
|
||||||
|
val updateBtn = actionContainerFactory.createButton(actionManager.getAction(Actions.APP_UPDATE))
|
||||||
|
updateBtn.isVisible = updateBtn.isEnabled
|
||||||
|
updateBtn.addChangeListener { updateBtn.isVisible = updateBtn.isEnabled }
|
||||||
|
toolbar.add(updateBtn)
|
||||||
|
|
||||||
|
|
||||||
|
// 获取显示的Action,如果不是 false 那么就是显示出来
|
||||||
|
for (action in getActions()) {
|
||||||
|
if (action.visible) {
|
||||||
|
val ac = actionManager.getAction(action.id)
|
||||||
|
if (ac == null) {
|
||||||
|
if (action.id == MultipleAction.MULTIPLE) {
|
||||||
|
toolbar.add(actionContainerFactory.createButton(MultipleAction.getInstance(windowScope)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toolbar.add(actionContainerFactory.createButton(ac))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (toolbar is MyToolBar) {
|
||||||
|
toolbar.adjust()
|
||||||
|
}
|
||||||
|
|
||||||
|
toolbar.revalidate()
|
||||||
|
toolbar.repaint()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user