-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Key-combinations to improve usability. CTRL + W closes the curr…
…ent tab, CTRL + T opens a new tab, CTRL + S saves the current tab, CTRL + LSHIFT + S saves all tabs, CTRL + L opens the file selection for loading, CTRL + G generates the current tab.
- Loading branch information
Showing
9 changed files
with
219 additions
and
71 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
...ackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/KeyComboManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* Copyright (C) 2023 Griefed | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
* USA | ||
* | ||
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE | ||
*/ | ||
package de.griefed.serverpackcreator.gui.window | ||
|
||
import de.griefed.serverpackcreator.api.ApiWrapper | ||
import de.griefed.serverpackcreator.gui.GuiProps | ||
import de.griefed.serverpackcreator.gui.window.menu.MainMenuBar | ||
import de.griefed.serverpackcreator.updater.MigrationManager | ||
import de.griefed.serverpackcreator.updater.UpdateChecker | ||
import java.awt.AWTEvent | ||
import java.awt.Toolkit | ||
import java.awt.event.KeyEvent | ||
import javax.swing.JFrame | ||
|
||
/** | ||
* Common key-combinations usable across ServerPackCreator, like loading and saving configs, generating | ||
* a server pack, opening a new tab, closing a tab, etc. etc. | ||
* | ||
* * CTRL + W closes the current tab | ||
* * CTRL + T opens a new tab | ||
* * CTRL + S saves the current tab | ||
* * CTRL + LSHIFT + S saves all tabs | ||
* * CTRL + L opens the file selection for loading | ||
* * CTRL + G generates the current tab | ||
* | ||
* @author Griefed | ||
*/ | ||
class KeyComboManager( | ||
private val guiProps: GuiProps, | ||
private val apiWrapper: ApiWrapper, | ||
private val updateChecker: UpdateChecker, | ||
private val updateDialogs: UpdateDialogs, | ||
private val migrationManager: MigrationManager, | ||
private val frame: JFrame, | ||
private val mainPanel: MainPanel, | ||
Check warning on line 52 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/KeyComboManager.kt GitHub Actions / Qodana Community for JVMConstructor parameter is never used as a property
|
||
private val menu: MainMenuBar | ||
) { | ||
|
||
private val configs = mainPanel.tabbedConfigsTab | ||
private val control = mainPanel.controlPanel | ||
|
||
init { | ||
addCloseTabCombo() | ||
addNewTabCombo() | ||
addSaveCurrentTabCombo() | ||
addSaveAllTabsCombo() | ||
addLoadConfigsCombo() | ||
addStartGenerationCombo() | ||
} | ||
|
||
private fun addCloseTabCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_W && event.isControlDown -> { | ||
configs.selectedEditor!!.editorTitle.close() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
|
||
private fun addNewTabCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_T && event.isControlDown -> { | ||
configs.addTab() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
|
||
private fun addSaveCurrentTabCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_S && event.isControlDown && !event.isShiftDown -> { | ||
configs.selectedEditor!!.saveCurrentConfiguration() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
|
||
private fun addSaveAllTabsCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_S && event.isControlDown && event.isShiftDown -> { | ||
configs.saveAll() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
|
||
private fun addLoadConfigsCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_L && event.isControlDown -> { | ||
configs.loadConfigFile() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
|
||
private fun addStartGenerationCombo() { | ||
Toolkit.getDefaultToolkit().addAWTEventListener({ e: AWTEvent -> | ||
val event = e as KeyEvent | ||
if (event.id == KeyEvent.KEY_RELEASED) { | ||
when { | ||
event.keyCode == KeyEvent.VK_G && event.isControlDown -> { | ||
control.generate() | ||
} | ||
} | ||
} | ||
}, AWTEvent.KEY_EVENT_MASK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.