@@ -104,78 +104,6 @@ object Studio {
104104 }
105105 }
106106
107- private fun getMainWindowTitle (): String {
108- val projectName = GlobalState .project.current?.directory?.name
109- val pageName = GlobalState .resource.active?.windowTitle
110- return Label .TYPEDB_STUDIO + ((pageName ? : projectName)?.let { " — $it " } ? : " " )
111- }
112-
113- @JvmStatic
114- fun main (args : Array <String >) {
115- try {
116- addShutdownHook()
117- setConfigurations()
118- Message .loadClasses()
119- GlobalState .appData.initialise()
120- while (! quit) {
121- application { MainWindow (::exitApplication) }
122- error?.let { exception ->
123- LOGGER .error(exception.message, exception)
124- application { ErrorWindow (exception) { error = null ; exitApplication() } }
125- }
126- }
127- exitProcess(0 )
128- } catch (exception: Exception ) {
129- LOGGER .error(exception.message, exception)
130- exitProcess(1 )
131- }
132- }
133-
134- private fun addShutdownHook () {
135- Runtime .getRuntime().addShutdownHook(object : Thread () {
136- override fun run (): Unit = runBlocking {
137- LOGGER .info { Label .CLOSING_TYPEDB_STUDIO }
138- GlobalState .client.closeBlocking()
139- }
140- })
141- }
142-
143- private fun setConfigurations () {
144- // Enable anti-aliasing
145- System .setProperty(" awt.useSystemAAFontSettings" , " on" )
146- System .setProperty(" swing.aatext" , " true" )
147- // Enable FileDialog to select "directories" on MacOS
148- System .setProperty(" apple.awt.fileDialogForDirectories" , " true" )
149- // Enable native Windows UI style
150- UIManager .setLookAndFeel(UIManager .getSystemLookAndFeelClassName()) // Set UI style for Windows
151- }
152-
153- @OptIn(ExperimentalComposeUiApi ::class )
154- private fun application (window : @Composable ApplicationScope .() -> Unit ) {
155- androidx.compose.ui.window.application(exitProcessOnExit = false ) {
156- Theme .Material {
157- CompositionLocalProvider (LocalWindowExceptionHandlerFactory provides ExceptionHandler ) {
158- window()
159- }
160- }
161- }
162- }
163-
164- private fun handleKeyEvent (event : KeyEvent , onClose : () -> Unit ): Boolean {
165- return if (event.type == KeyEventType .KeyUp ) false
166- else KeyMapper .CURRENT .map(event)?.let { executeCommand(it, onClose) } ? : false
167- }
168-
169- private fun executeCommand (command : KeyMapper .Command , onClose : () -> Unit ): Boolean {
170- return when (command) {
171- KeyMapper .Command .QUIT -> {
172- onClose()
173- true
174- }
175- else -> false
176- }
177- }
178-
179107 @Composable
180108 private fun MainWindow (exitApplicationFn : () -> Unit ) {
181109 fun confirmClose () = GlobalState .confirmation.submit(
@@ -225,6 +153,25 @@ object Studio {
225153 }
226154 }
227155
156+ private fun getMainWindowTitle (): String {
157+ val projectName = GlobalState .project.current?.directory?.name
158+ val pageName = GlobalState .resource.active?.windowTitle
159+ return Label .TYPEDB_STUDIO + ((pageName ? : projectName)?.let { " — $it " } ? : " " )
160+ }
161+
162+ private fun handleKeyEvent (event : KeyEvent , onClose : () -> Unit ): Boolean {
163+ return if (event.type == KeyEventType .KeyUp ) false
164+ else KeyMapper .CURRENT .map(event)?.let {
165+ when (it) {
166+ KeyMapper .Command .QUIT -> {
167+ onClose()
168+ true
169+ }
170+ else -> false
171+ }
172+ } ? : false
173+ }
174+
228175 @Composable
229176 private fun MayShowDialog (window : ComposeWindow ) {
230177 if (GlobalState .notification.queue.isNotEmpty()) NotificationArea .Layout ()
@@ -289,4 +236,55 @@ object Studio {
289236 }
290237 }
291238 }
239+
240+ private fun addShutdownHook () {
241+ Runtime .getRuntime().addShutdownHook(object : Thread () {
242+ override fun run (): Unit = runBlocking {
243+ LOGGER .info { Label .CLOSING_TYPEDB_STUDIO }
244+ GlobalState .client.closeBlocking()
245+ }
246+ })
247+ }
248+
249+ private fun setConfigurations () {
250+ // Enable anti-aliasing
251+ System .setProperty(" awt.useSystemAAFontSettings" , " on" )
252+ System .setProperty(" swing.aatext" , " true" )
253+ // Enable FileDialog to select "directories" on MacOS
254+ System .setProperty(" apple.awt.fileDialogForDirectories" , " true" )
255+ // Enable native Windows UI style
256+ UIManager .setLookAndFeel(UIManager .getSystemLookAndFeelClassName()) // Set UI style for Windows
257+ }
258+
259+ @OptIn(ExperimentalComposeUiApi ::class )
260+ private fun application (window : @Composable ApplicationScope .() -> Unit ) {
261+ androidx.compose.ui.window.application(exitProcessOnExit = false ) {
262+ Theme .Material {
263+ CompositionLocalProvider (
264+ LocalWindowExceptionHandlerFactory provides ExceptionHandler
265+ ) { window() }
266+ }
267+ }
268+ }
269+
270+ @JvmStatic
271+ fun main (args : Array <String >) {
272+ try {
273+ addShutdownHook()
274+ setConfigurations()
275+ Message .loadClasses()
276+ GlobalState .appData.initialise()
277+ while (! quit) {
278+ application { MainWindow (::exitApplication) }
279+ error?.let { exception ->
280+ LOGGER .error(exception.message, exception)
281+ application { ErrorWindow (exception) { error = null ; exitApplication() } }
282+ }
283+ }
284+ exitProcess(0 )
285+ } catch (exception: Exception ) {
286+ LOGGER .error(exception.message, exception)
287+ exitProcess(1 )
288+ }
289+ }
292290}
0 commit comments