Fixed file select sppearing behind the window when experimental skin drop is disabled

This commit is contained in:
Sollace 2018-07-10 18:30:18 +02:00
parent 0597d2b02c
commit 2b1ef25f96
3 changed files with 47 additions and 11 deletions

View file

@ -269,7 +269,7 @@ public class GuiSkins extends GuiScreen implements FutureCallback<SkinUploadResp
this.selectedSkin = null; this.selectedSkin = null;
this.localPlayer.releaseTextures(); this.localPlayer.releaseTextures();
this.openFileThread = new ThreadOpenFilePNG(this.mc, I18n.format("hdskins.open.title"), this::onFileOpenDialogClosed); this.openFileThread = new ThreadOpenFilePNG(this.mc, I18n.format("hdskins.open.title"), this::onFileOpenDialogClosed);
this.openFileThread.setParent(GLWindow.current().getFrame()).start(); this.openFileThread.start();
guiButton.enabled = false; guiButton.enabled = false;
} }

View file

@ -0,0 +1,40 @@
package com.voxelmodpack.hdskins.upload.awt;
import javax.swing.JFrame;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.voxelmodpack.hdskins.gui.GLWindow;
final class InternalDialog {
private static final Logger LOGGER = LogManager.getLogger();
private static JFrame hiddenFrame;
public static JFrame getAWTContext() {
JFrame context = GLWindow.current().getFrame();
if (context != null) {
return context;
}
if (hiddenFrame == null) {
hiddenFrame = new JFrame("InternalDialogue");
hiddenFrame.setVisible(false);
hiddenFrame.requestFocusInWindow();
hiddenFrame.requestFocus();
try {
if (hiddenFrame.isAlwaysOnTopSupported()) {
hiddenFrame.setAlwaysOnTop(true);
}
} catch (SecurityException e) {
LOGGER.fatal("Could not set window on top state. This is probably Forge's fault.", e);
}
}
return hiddenFrame;
}
}

View file

@ -5,7 +5,6 @@ import net.minecraft.client.Minecraft;
import java.io.File; import java.io.File;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
/** /**
@ -24,8 +23,6 @@ public abstract class ThreadOpenFile extends Thread {
private JFileChooser fileDialog; private JFileChooser fileDialog;
private JFrame parent = null;
private static String lastChosenFile = null; private static String lastChosenFile = null;
protected ThreadOpenFile(Minecraft minecraft, String dialogTitle, IOpenFileCallback callback) protected ThreadOpenFile(Minecraft minecraft, String dialogTitle, IOpenFileCallback callback)
@ -38,11 +35,6 @@ public abstract class ThreadOpenFile extends Thread {
this.dialogTitle = dialogTitle; this.dialogTitle = dialogTitle;
} }
public ThreadOpenFile setParent(JFrame parent) {
this.parent = parent;
return this;
}
@Override @Override
public void run() { public void run() {
fileDialog = new JFileChooser(); fileDialog = new JFileChooser();
@ -53,9 +45,13 @@ public abstract class ThreadOpenFile extends Thread {
} }
fileDialog.setFileFilter(this.getFileFilter()); fileDialog.setFileFilter(this.getFileFilter());
int dialogResult = fileDialog.showOpenDialog(parent); int dialogResult = fileDialog.showOpenDialog(InternalDialog.getAWTContext());
lastChosenFile = fileDialog.getSelectedFile().getAbsolutePath(); File f = fileDialog.getSelectedFile();
if (f != null) {
lastChosenFile = f.getAbsolutePath();
}
this.parentScreen.onFileOpenDialogClosed(fileDialog, dialogResult); this.parentScreen.onFileOpenDialogClosed(fileDialog, dialogResult);
} }