Skip to content

Commit 21c7e00

Browse files
committed
✨ Add window size configuration to macOS file picker and update NSSize structure
1 parent ee1bbbc commit 21c7e00

5 files changed

Lines changed: 27 additions & 7 deletions

File tree

.run/SampleCore Jvm.run.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="SampleCore Jvm" type="GradleRunConfiguration" factoryName="Gradle">
33
<ExternalSystemSettings>
4+
<option name="env">
5+
<map>
6+
<entry key="DEVELOPER_DIR" value="/Applications/Xcode.app/Contents/Developer" />
7+
</map>
8+
</option>
49
<option name="executionName" />
510
<option name="externalProjectPath" value="$PROJECT_DIR$" />
611
<option name="externalSystemIdString" value="GRADLE" />

filekit-dialogs/src/jvmMain/kotlin/io/github/vinceglb/filekit/dialogs/FileKitDialogSettings.jvm.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public actual data class FileKitDialogSettings(
1414
public class FileKitMacOSSettings(
1515
public val resolvesAliases: Boolean? = null,
1616
public val canCreateDirectories: Boolean = true,
17+
public val windowSize: Pair<Int, Int>? = null,
1718
)

filekit-dialogs/src/jvmMain/kotlin/io/github/vinceglb/filekit/dialogs/platform/mac/MacOSFilePicker.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ internal class MacOSFilePicker : PlatformFilePicker {
101101
Foundation.invoke(openPanel, "setResolvesAliases:", resolvesAliases)
102102
}
103103

104+
// Set window size
105+
println("Setting window size: ${macOSSettings.windowSize}")
106+
macOSSettings.windowSize?.let { (width, height) ->
107+
// Create NSSize structure and set content size
108+
val nsSize = Foundation.NSSize(width.toDouble(), height.toDouble())
109+
Foundation.invoke(openPanel, "setContentSize:", nsSize)
110+
}
111+
104112
// Open the file picker
105113
val result = Foundation.invoke(openPanel, "runModal")
106114

filekit-dialogs/src/jvmMain/kotlin/io/github/vinceglb/filekit/dialogs/platform/mac/foundation/Foundation.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ internal object Foundation {
581581
// var y: CoreGraphics.CGFloat = CGFloat(y)
582582
// }
583583
//
584-
// @Structure.FieldOrder("width", "height")
585-
// class NSSize @JvmOverloads constructor(width: Double = 0.0, height: Double = 0.0) :
586-
// Structure(), Structure.ByValue {
587-
// var width: CoreGraphics.CGFloat = CGFloat(width)
588-
// var height: CoreGraphics.CGFloat = CGFloat(height)
589-
// }
584+
@com.sun.jna.Structure.FieldOrder("width", "height")
585+
class NSSize @JvmOverloads constructor(width: Double = 0.0, height: Double = 0.0) :
586+
com.sun.jna.Structure(), com.sun.jna.Structure.ByValue {
587+
@JvmField var width: Double = width
588+
@JvmField var height: Double = height
589+
}
590590
}

samples/sample-core/composeApp/src/desktopMain/kotlin/io/github/vinceglb/sample/core/compose/main.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ import androidx.compose.ui.window.Window
44
import androidx.compose.ui.window.application
55
import io.github.vinceglb.filekit.FileKit
66
import io.github.vinceglb.filekit.dialogs.FileKitDialogSettings
7+
import io.github.vinceglb.filekit.dialogs.FileKitMacOSSettings
78

89
fun main() = application {
910
FileKit.init(appId = "FileKitSampleCore")
1011
Window(onCloseRequest = ::exitApplication, title = "Picker Core Sample") {
11-
val dialogSettings = FileKitDialogSettings(this.window)
12+
val dialogSettings = FileKitDialogSettings(
13+
parentWindow = this.window,
14+
macOS = FileKitMacOSSettings(
15+
windowSize = Pair(500, 500)
16+
)
17+
)
1218
App(dialogSettings)
1319
}
1420
}

0 commit comments

Comments
 (0)