mirror of
https://github.com/processing/processing4.git
synced 2026-05-03 17:35:00 +02:00
Refactor beta welcome window handling
Replaces custom JFrame setup in WelcomeToBeta with PDESwingWindow and PDEComposeWindow, centralizing window logic and close handling. Adds onClose callback to PDESwingWindow for improved lifecycle management. Also ensures beta welcome preference is reset on forced update check.
This commit is contained in:
@@ -1057,6 +1057,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
var updateTrigger = new JMenuItem(Language.text("menu.develop.check_for_updates"));
|
||||
updateTrigger.addActionListener(e -> {
|
||||
Preferences.unset("update.last");
|
||||
Preferences.setInteger("update.beta_welcome", 0);
|
||||
new UpdateCheck(base);
|
||||
});
|
||||
developMenu.add(updateTrigger);
|
||||
|
||||
@@ -41,6 +41,8 @@ import processing.app.Base.getVersionName
|
||||
import processing.app.ui.theme.LocalLocale
|
||||
import processing.app.ui.theme.LocalTheme
|
||||
import processing.app.ui.theme.Locale
|
||||
import processing.app.ui.theme.PDEComposeWindow
|
||||
import processing.app.ui.theme.PDESwingWindow
|
||||
import processing.app.ui.theme.ProcessingTheme
|
||||
import java.awt.Cursor
|
||||
import java.awt.Dimension
|
||||
@@ -54,46 +56,20 @@ import javax.swing.SwingUtilities
|
||||
|
||||
class WelcomeToBeta {
|
||||
companion object{
|
||||
val windowSize = Dimension(400, 200)
|
||||
val windowTitle = Locale()["beta.window.title"]
|
||||
|
||||
@JvmStatic
|
||||
fun showWelcomeToBeta() {
|
||||
val mac = SystemInfo.isMacFullWindowContentSupported
|
||||
SwingUtilities.invokeLater {
|
||||
JFrame(windowTitle).apply {
|
||||
val close = {
|
||||
Preferences.set("update.beta_welcome", getRevision().toString())
|
||||
dispose()
|
||||
}
|
||||
rootPane.putClientProperty("apple.awt.transparentTitleBar", mac)
|
||||
rootPane.putClientProperty("apple.awt.fullWindowContent", mac)
|
||||
defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE
|
||||
contentPane.add(ComposePanel().apply {
|
||||
size = windowSize
|
||||
setContent {
|
||||
ProcessingTheme {
|
||||
Box(modifier = Modifier.padding(top = if (mac) 22.dp else 0.dp)) {
|
||||
welcomeToBeta(close)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
pack()
|
||||
background = java.awt.Color.white
|
||||
setLocationRelativeTo(null)
|
||||
addKeyListener(object : KeyAdapter() {
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_ESCAPE) close()
|
||||
}
|
||||
})
|
||||
isResizable = false
|
||||
isVisible = true
|
||||
requestFocus()
|
||||
val close = {
|
||||
Preferences.set("update.beta_welcome", getRevision().toString())
|
||||
}
|
||||
|
||||
PDESwingWindow("beta.window.title", onClose = close) {
|
||||
welcomeToBeta(close)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val windowSize = Dimension(400, 200)
|
||||
@Composable
|
||||
fun welcomeToBeta(close: () -> Unit = {}) {
|
||||
Row(
|
||||
@@ -194,18 +170,9 @@ class WelcomeToBeta {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
application {
|
||||
val windowState = rememberWindowState(
|
||||
size = DpSize.Unspecified,
|
||||
position = WindowPosition(Alignment.Center)
|
||||
)
|
||||
|
||||
Window(onCloseRequest = ::exitApplication, state = windowState, title = windowTitle) {
|
||||
ProcessingTheme {
|
||||
Surface(color = colors.background) {
|
||||
welcomeToBeta {
|
||||
exitApplication()
|
||||
}
|
||||
}
|
||||
PDEComposeWindow(titleKey = "beta.window.title", onClose = ::exitApplication){
|
||||
welcomeToBeta {
|
||||
exitApplication()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ val LocalWindow = compositionLocalOf<JFrame> { error("No Window Set") }
|
||||
* @param fullWindowContent If true, the content will extend into the title bar area on macOS.
|
||||
* @param content The composable content to be displayed in the window.
|
||||
*/
|
||||
class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false, content: @Composable BoxScope.() -> Unit): JFrame(){
|
||||
class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false, onClose: () -> Unit = {}, content: @Composable BoxScope.() -> Unit): JFrame(){
|
||||
init{
|
||||
val window = this
|
||||
defaultCloseOperation = DISPOSE_ON_CLOSE
|
||||
@@ -54,7 +54,10 @@ class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false,
|
||||
setLocationRelativeTo(null)
|
||||
addKeyListener(object : KeyAdapter() {
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_ESCAPE) window.dispose()
|
||||
if (e.keyCode != KeyEvent.VK_ESCAPE) return
|
||||
|
||||
window.dispose()
|
||||
onClose()
|
||||
}
|
||||
})
|
||||
isResizable = false
|
||||
|
||||
Reference in New Issue
Block a user