Native file chooser, untested
This commit is contained in:
@@ -6,6 +6,7 @@ import arc.backend.sdl.*;
|
||||
import arc.backend.sdl.jni.*;
|
||||
import arc.discord.*;
|
||||
import arc.discord.DiscordRPC.*;
|
||||
import arc.filedialogs.*;
|
||||
import arc.files.*;
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
@@ -23,6 +24,7 @@ import mindustry.net.*;
|
||||
import mindustry.net.Net.*;
|
||||
import mindustry.service.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -36,6 +38,55 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
public static void main(String[] arg){
|
||||
try{
|
||||
Vars.loadLogger();
|
||||
Vars.platform = new Platform(){
|
||||
@Override
|
||||
public void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
||||
if(OS.isWindows || OS.isMac){
|
||||
Threads.daemon(() -> {
|
||||
try{
|
||||
FileDialogs.loadNatives();
|
||||
|
||||
String result;
|
||||
|
||||
if(open){
|
||||
result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false);
|
||||
}else{
|
||||
result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files");
|
||||
}
|
||||
|
||||
if(result == null) return;
|
||||
|
||||
if(result.length() > 1 && result.contains("\n")){
|
||||
result = result.split("\n")[0];
|
||||
}
|
||||
|
||||
//cancelled selection, ignore result
|
||||
if(result.isEmpty() || result.equals("\n")) return;
|
||||
if(result.endsWith("\n")) result = result.substring(0, result.length() - 1);
|
||||
if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\"");
|
||||
|
||||
Fi file = Core.files.absolute(result);
|
||||
Core.app.post(() -> {
|
||||
FileChooser.setLastDirectory(file.isDirectory() ? file : file.parent());
|
||||
|
||||
if(!open){
|
||||
cons.get(file.parent().child(file.nameWithoutExtension() + "." + extension));
|
||||
}else{
|
||||
cons.get(file);
|
||||
}
|
||||
});
|
||||
}catch(Throwable error){
|
||||
Log.err("Failure to execute native file chooser", error);
|
||||
Core.app.post(() -> {
|
||||
Platform.super.showFileChooser(open, title, extension, cons);
|
||||
});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
Platform.super.showFileChooser(open, title, extension, cons);
|
||||
}
|
||||
}
|
||||
};
|
||||
new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{
|
||||
title = "Mindustry";
|
||||
maximized = true;
|
||||
|
||||
Reference in New Issue
Block a user