Set parent component for Save/Open file dialogs

This commit is contained in:
Jindra Petřík
2021-03-27 10:16:28 +01:00
parent c7c66c55e5
commit a52a4206ca
9 changed files with 14 additions and 40 deletions

View File

@@ -291,9 +291,7 @@ public class AdvancedSettingsDialog extends AppDialog {
fc.setFileFilter(allSupportedFilter);
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
int returnVal = fc.showOpenDialog(f);
int returnVal = fc.showOpenDialog(Main.getDefaultMessagesComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
return Helper.fixDialogFile(fc.getSelectedFile()).getAbsolutePath();
} else {

View File

@@ -390,9 +390,7 @@ public class FontEmbedDialog extends AppDialog {
};
fc.setFileFilter(ttfFilter);
fc.setAcceptAllFileFilterUsed(true);
JFrame f = new JFrame();
View.setWindowIcon(f);
int returnVal = fc.showOpenDialog(f);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File selfile = Helper.fixDialogFile(fc.getSelectedFile());

View File

@@ -751,9 +751,7 @@ public class FontPanel extends JPanel {
fc.setFileFilter(ttfFilter);
fc.setAcceptAllFileFilterUsed(false);
JFrame fr = new JFrame();
View.setWindowIcon(fr);
int returnVal = fc.showOpenDialog(fr);
int returnVal = fc.showOpenDialog(Main.getDefaultMessagesComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File selfile = Helper.fixDialogFile(fc.getSelectedFile());

View File

@@ -262,9 +262,7 @@ public class LoadFromCacheFrame extends AppFrame {
});
}
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(LoadFromCacheFrame.this) == JFileChooser.APPROVE_OPTION) {
File file = Helper.fixDialogFile(fc.getSelectedFile());
try {
if (selected.size() == 1) {

View File

@@ -398,9 +398,7 @@ public class LoadFromMemoryFrame extends AppFrame {
});
}
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(LoadFromMemoryFrame.this) == JFileChooser.APPROVE_OPTION) {
File file = Helper.fixDialogFile(fc.getSelectedFile());
try {
if (selected.length == 1) {

View File

@@ -914,9 +914,7 @@ public class Main {
};
fc.addChoosableFileFilter(gfxFilter);
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
int returnVal = fc.showOpenDialog(f);
int returnVal = fc.showOpenDialog(getDefaultMessagesComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File selFile = Helper.fixDialogFile(fc.getSelectedFile());
@@ -1534,9 +1532,7 @@ public class Main {
}
final String extension = ext;
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(getDefaultMessagesComponent()) == JFileChooser.APPROVE_OPTION) {
File file = Helper.fixDialogFile(fc.getSelectedFile());
FileFilter selFilter = fc.getFileFilter();
try {
@@ -1706,9 +1702,7 @@ public class Main {
fc.addChoosableFileFilter(binaryFilter);
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
int returnVal = fc.showOpenDialog(f);
int returnVal = fc.showOpenDialog(getDefaultMessagesComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File[] selFiles = fc.getSelectedFiles();

View File

@@ -2349,9 +2349,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File sf = Helper.fixDialogFile(fc.getSelectedFile());
@@ -3267,9 +3265,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
first = false;
}
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showOpenDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File result = fc.getSelectedFile();
Configuration.lastOpenDir.set(Helper.fixDialogFile(result).getParentFile().getAbsolutePath());
return result;

View File

@@ -395,9 +395,7 @@ public class DumpTree extends JTree {
JFileChooser fc = new JFileChooser();
String selDir = Configuration.lastOpenDir.get();
fc.setCurrentDirectory(new File(selDir));
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
File sf = Helper.fixDialogFile(fc.getSelectedFile());
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(sf))) {
byte[] data = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().originalUncompressedData;

View File

@@ -414,9 +414,7 @@ public class ProxyFrame extends AppFrame implements CatchedListener, MouseListen
};
fc.setFileFilter(swfFilter);
fc.setAcceptAllFileFilterUsed(true);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
File file = Helper.fixDialogFile(fc.getSelectedFile());
try {
Files.copy(new File(r.targetFile).toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
@@ -485,15 +483,13 @@ public class ProxyFrame extends AppFrame implements CatchedListener, MouseListen
};
fc.setFileFilter(swfFilter);
fc.setAcceptAllFileFilterUsed(true);
JFrame f = new JFrame();
View.setWindowIcon(f);
if (fc.showOpenDialog(f) == JFileChooser.APPROVE_OPTION) {
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File file = Helper.fixDialogFile(fc.getSelectedFile());
try {
Files.copy(file.toPath(), new File(r.targetFile).toPath(), StandardCopyOption.REPLACE_EXISTING);
tableModel.fireTableCellUpdated(sel[0], 1/*size*/);
} catch (IOException ex) {
ViewMessages.showMessageDialog(f, translate("error.replace") + "\r\n" + ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
ViewMessages.showMessageDialog(this, translate("error.replace") + "\r\n" + ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
}
}
}