diff --git a/src/main/kotlin/app/termora/HostDialog.kt b/src/main/kotlin/app/termora/HostDialog.kt index 8068950..ca5342e 100644 --- a/src/main/kotlin/app/termora/HostDialog.kt +++ b/src/main/kotlin/app/termora/HostDialog.kt @@ -25,6 +25,7 @@ class HostDialog(owner: Window, host: Host? = null) : DialogWrapper(owner) { isModal = true title = I18n.getString("termora.new-host.title") setLocationRelativeTo(null) + pane.setSelectedIndex(0) init() } diff --git a/src/main/kotlin/app/termora/OptionsPane.kt b/src/main/kotlin/app/termora/OptionsPane.kt index 0d5da1f..108c3b5 100644 --- a/src/main/kotlin/app/termora/OptionsPane.kt +++ b/src/main/kotlin/app/termora/OptionsPane.kt @@ -17,6 +17,7 @@ open class OptionsPane : JPanel(BorderLayout()) { } private val cardLayout = CardLayout() private val contentPanel = JPanel(cardLayout) + private val loadedComponents = mutableMapOf() init { initView() @@ -103,16 +104,15 @@ open class OptionsPane : JPanel(BorderLayout()) { throw UnsupportedOperationException("Title already exists") } } - contentPanel.add(option.getJComponent(), option.getTitle()) tabListModel.addElement(option) - - if (tabList.selectedIndex < 0) { - tabList.selectedIndex = 0 - } } fun removeOption(option: Option) { - contentPanel.remove(option.getJComponent()) + val title = option.getTitle() + loadedComponents[title]?.let { + contentPanel.remove(it) + loadedComponents.remove(title) + } tabListModel.removeElement(option) } @@ -123,7 +123,17 @@ open class OptionsPane : JPanel(BorderLayout()) { private fun initEvents() { tabList.addListSelectionListener { if (tabList.selectedIndex >= 0) { - cardLayout.show(contentPanel, tabListModel.get(tabList.selectedIndex).getTitle()) + val option = tabListModel.get(tabList.selectedIndex) + val title = option.getTitle() + + if (!loadedComponents.containsKey(title)) { + val component = option.getJComponent() + loadedComponents[title] = component + contentPanel.add(component, title) + SwingUtilities.updateComponentTreeUI(component) + } + + cardLayout.show(contentPanel, title) } } } diff --git a/src/main/kotlin/app/termora/SettingsDialog.kt b/src/main/kotlin/app/termora/SettingsDialog.kt index 8327a7e..0ad5f17 100644 --- a/src/main/kotlin/app/termora/SettingsDialog.kt +++ b/src/main/kotlin/app/termora/SettingsDialog.kt @@ -3,8 +3,6 @@ package app.termora import java.awt.BorderLayout import java.awt.Dimension import java.awt.Window -import java.awt.event.WindowAdapter -import java.awt.event.WindowEvent import javax.swing.BorderFactory import javax.swing.JComponent import javax.swing.JPanel @@ -20,8 +18,10 @@ class SettingsDialog(owner: Window) : DialogWrapper(owner) { title = I18n.getString("termora.setting") setLocationRelativeTo(null) - init() + val index = properties.getString("Settings-SelectedOption")?.toIntOrNull() ?: 0 + optionsPane.setSelectedIndex(index) + init() initEvents() } @@ -31,14 +31,6 @@ class SettingsDialog(owner: Window) : DialogWrapper(owner) { properties.putString("Settings-SelectedOption", optionsPane.getSelectedIndex().toString()) } }) - - addWindowListener(object : WindowAdapter() { - override fun windowActivated(e: WindowEvent) { - removeWindowListener(this) - val index = properties.getString("Settings-SelectedOption")?.toIntOrNull() ?: return - optionsPane.setSelectedIndex(index) - } - }) } override fun createCenterPanel(): JComponent { diff --git a/src/main/kotlin/app/termora/SettingsOptionsPane.kt b/src/main/kotlin/app/termora/SettingsOptionsPane.kt index d4fe45e..34b4b0b 100644 --- a/src/main/kotlin/app/termora/SettingsOptionsPane.kt +++ b/src/main/kotlin/app/termora/SettingsOptionsPane.kt @@ -604,16 +604,28 @@ class SettingsOptionsPane : OptionsPane() { shellComboBox.selectedItem = terminalSetting.localShell - val fonts = linkedSetOf("JetBrains Mono", "Source Code Pro", "Monospaced") - FontUtils.getAllFonts().forEach { - if (!fonts.contains(it.family)) { - fonts.addLast(it.family) - } - } + fontComboBox.addItem(terminalSetting.font) + var fontsLoaded = false - for (font in fonts) { - fontComboBox.addItem(font) - } + fontComboBox.addPopupMenuListener(object : PopupMenuListener { + override fun popupMenuWillBecomeVisible(e: PopupMenuEvent) { + if (!fontsLoaded) { + val selectedItem = fontComboBox.selectedItem + fontComboBox.removeAllItems(); + fontComboBox.addItem("JetBrains Mono") + fontComboBox.addItem("Source Code Pro") + fontComboBox.addItem("Monospaced") + FontUtils.getAvailableFontFamilyNames().forEach { + fontComboBox.addItem(it) + } + fontComboBox.selectedItem = selectedItem + fontsLoaded = true + } + } + + override fun popupMenuWillBecomeInvisible(e: PopupMenuEvent) {} + override fun popupMenuCanceled(e: PopupMenuEvent) {} + }) fontComboBox.selectedItem = terminalSetting.font debugComboBox.selectedItem = terminalSetting.debug