Fixes
This commit is contained in:
@@ -234,7 +234,6 @@ project(":desktop"){
|
|||||||
dependencies{
|
dependencies{
|
||||||
implementation project(":core")
|
implementation project(":core")
|
||||||
implementation arcModule("extensions:discord")
|
implementation arcModule("extensions:discord")
|
||||||
implementation arcModule("extensions:filedialogs")
|
|
||||||
implementation arcModule("natives:natives-filedialogs")
|
implementation arcModule("natives:natives-filedialogs")
|
||||||
implementation arcModule("natives:natives-desktop")
|
implementation arcModule("natives:natives-desktop")
|
||||||
implementation arcModule("natives:natives-freetype-desktop")
|
implementation arcModule("natives:natives-freetype-desktop")
|
||||||
@@ -322,6 +321,7 @@ project(":core"){
|
|||||||
api arcModule("extensions:g3d")
|
api arcModule("extensions:g3d")
|
||||||
api arcModule("extensions:fx")
|
api arcModule("extensions:fx")
|
||||||
api arcModule("extensions:arcnet")
|
api arcModule("extensions:arcnet")
|
||||||
|
implementation arcModule("extensions:filedialogs")
|
||||||
api "com.github.Anuken:rhino:$rhinoVersion"
|
api "com.github.Anuken:rhino:$rhinoVersion"
|
||||||
if(localArc && debugged()) api arcModule("extensions:recorder")
|
if(localArc && debugged()) api arcModule("extensions:recorder")
|
||||||
if(localArc) api arcModule(":extensions:packer")
|
if(localArc) api arcModule(":extensions:packer")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.core;
|
package mindustry.core;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.filedialogs.*;
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -141,7 +142,47 @@ public interface Platform{
|
|||||||
* @param title The title of the native dialog
|
* @param title The title of the native dialog
|
||||||
*/
|
*/
|
||||||
default void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
default void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
||||||
if(OS.isLinux && !OS.isAndroid){
|
if(OS.isWindows || OS.isMac){
|
||||||
|
//native file dialog
|
||||||
|
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(() -> defaultFileDialog(open, title, extension, cons));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else if(OS.isLinux && !OS.isAndroid){
|
||||||
showZenity(open, title, new String[]{extension}, cons, () -> defaultFileDialog(open, title, extension, cons));
|
showZenity(open, title, new String[]{extension}, cons, () -> defaultFileDialog(open, title, extension, cons));
|
||||||
}else{
|
}else{
|
||||||
defaultFileDialog(open, title, extension, cons);
|
defaultFileDialog(open, title, extension, cons);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import arc.backend.sdl.*;
|
|||||||
import arc.backend.sdl.jni.*;
|
import arc.backend.sdl.jni.*;
|
||||||
import arc.discord.*;
|
import arc.discord.*;
|
||||||
import arc.discord.DiscordRPC.*;
|
import arc.discord.DiscordRPC.*;
|
||||||
import arc.filedialogs.*;
|
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -24,7 +23,6 @@ import mindustry.net.*;
|
|||||||
import mindustry.net.Net.*;
|
import mindustry.net.Net.*;
|
||||||
import mindustry.service.*;
|
import mindustry.service.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.dialogs.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -38,55 +36,6 @@ public class DesktopLauncher extends ClientLauncher{
|
|||||||
public static void main(String[] arg){
|
public static void main(String[] arg){
|
||||||
try{
|
try{
|
||||||
Vars.loadLogger();
|
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(){{
|
new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{
|
||||||
title = "Mindustry";
|
title = "Mindustry";
|
||||||
maximized = true;
|
maximized = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user