MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / InsertPath

Class InsertPath

src/main/java/fieldbox/boxes/plugins/InsertPath.kt:14–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import java.io.File
13import java.util.LinkedHashMap
14import java.util.function.Supplier
15
16class InsertPath : Box() {
17
18 init {
19 properties.put(Commands.commands, Supplier<Map<Pair<String, String>, Runnable>> {
20
21 val m = LinkedHashMap<Pair<String, String>, Runnable>()
22
23 m.put(Pair("Copy Path to Clipboard", "Select a path using a file dialog and put it on the clipboard"), Runnable {
24 getOpenFile()?.apply {
25 first(Boxes.window, both()).ifPresent {
26 it.currentClipboard = "\"" + this + "\""
27 }
28 }
29 })
30
31 m
32 })
33 }
34
35 fun getOpenFile(): String? {
36 return MemoryStack.stackPush().use {
37 val aFilterPatterns = it.mallocPointer(1)
38
39// aFilterPatterns.put(it.UTF8("*.field2"))
40
41 aFilterPatterns.flip()
42 var fn = TinyFileDialogs.tinyfd_openFileDialog("Open File(s)", FieldBox.workspace + "/", aFilterPatterns, ".field2 files", false)
43 if (fn != null) {
44 val ff = File(fn)
45 if (ff.exists()) {
46 return@use ff.absolutePath
47 }
48 }
49 null
50 }
51 }
52
53}

Callers

nothing calls this directly

Calls 5

PairClass · 0.85
firstFunction · 0.85
bothFunction · 0.85
applyMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected