| 12 | import java.io.File |
| 13 | import java.util.LinkedHashMap |
| 14 | import java.util.function.Supplier |
| 15 | |
| 16 | class 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 | } |