From 5ed98393ee089136766b5f843a85b4b9f28a0465 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 7 Jan 2016 10:37:09 +0100 Subject: [PATCH] ask the user to update the texts if and only if any character was changed --- .../decompiler/flash/gui/FontEmbedDialog.java | 11 ----- .../jpexs/decompiler/flash/gui/FontPanel.java | 43 ++++++++++--------- src/com/jpexs/decompiler/flash/gui/Main.java | 4 +- .../flash/gui/locales/MainFrame.properties | 1 + 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/FontEmbedDialog.java b/src/com/jpexs/decompiler/flash/gui/FontEmbedDialog.java index f9e9880e4..42698e0f9 100644 --- a/src/com/jpexs/decompiler/flash/gui/FontEmbedDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/FontEmbedDialog.java @@ -79,8 +79,6 @@ public class FontEmbedDialog extends AppDialog { private final JCheckBox allCheckbox; - private final JCheckBox updateTextsCheckbox; - public Font getSelectedFont() { if (ttfFileRadio.isSelected() && customFont != null) { return customFont; @@ -88,10 +86,6 @@ public class FontEmbedDialog extends AppDialog { return ((FontFace) faceSelection.getSelectedItem()).font; } - public boolean hasUpdateTexts() { - return updateTextsCheckbox.isSelected(); - } - public Set getSelectedChars() { Set chars = new TreeSet<>(); Font f = getSelectedFont(); @@ -250,13 +244,8 @@ public class FontEmbedDialog extends AppDialog { individialSample = new JLabel(); specialPanel.add(individualCharsField); - updateTextsCheckbox = new JCheckBox(AppStrings.translate("font.updateTexts")); - - JPanel utPanel = new JPanel(new FlowLayout()); - utPanel.add(updateTextsCheckbox); cnt.add(specialPanel); cnt.add(individialSample); - cnt.add(utPanel); JPanel buttonsPanel = new JPanel(new FlowLayout()); JButton okButton = new JButton(AppStrings.translate("button.ok")); diff --git a/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/src/com/jpexs/decompiler/flash/gui/FontPanel.java index cd1777b6d..ca2b8b5b0 100644 --- a/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -151,6 +151,7 @@ public class FontPanel extends JPanel { String[] yesno = new String[]{translate("button.yes"), translate("button.no"), translate("button.yes.all"), translate("button.no.all")}; boolean yestoall = false; boolean notoall = false; + boolean replaced = false; for (int ic : selChars) { char c = (char) ic; if (oldchars.indexOf((int) c) > -1) { @@ -174,24 +175,30 @@ public class FontPanel extends JPanel { if (opt == 1) { continue; } + + replaced = true; } + f.addCharacter(c, font); oldchars += c; } - int fontId = ft.getFontId(); - if (updateTextsCheckBox.isSelected()) { - SWF swf = ft.getSwf(); - for (Tag tag : swf.getTags()) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getFontIds().contains(fontId)) { - String text = textTag.getFormattedText(true).text; - mainPanel.saveText(textTag, text, null); + if (replaced) { + if (View.showConfirmDialog(null, translate("message.font.replace.updateTexts"), translate("message.warning"), JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { + int fontId = ft.getFontId(); + SWF swf = ft.getSwf(); + for (Tag tag : swf.getTags()) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getFontIds().contains(fontId)) { + String text = textTag.getFormattedText(true).text; + mainPanel.saveText(textTag, text, null); + } } } } } + ft.setModified(true); ft.getSwf().clearImageCache(); } @@ -251,7 +258,6 @@ public class FontPanel extends JPanel { JLabel fontCharsAddLabel = new JLabel(); fontAddCharactersField = new JTextField(); fontAddCharsButton = new JButton(); - updateTextsCheckBox = new JCheckBox(); fontSourceLabel = new JLabel(); fontFamilyNameSelection = new JComboBox<>(); fontFaceSelection = new JComboBox<>(); @@ -381,8 +387,6 @@ public class FontPanel extends JPanel { fontAddCharsButton.setText(AppStrings.translate("button.ok")); fontAddCharsButton.addActionListener(this::fontAddCharsButtonActionPerformed); - updateTextsCheckBox.setText(AppStrings.translate("font.updateTexts")); - fontSourceLabel.setText(AppStrings.translate("font.source")); fontFamilyNameSelection.setPreferredSize(new Dimension(100, fontFamilyNameSelection.getMinimumSize().height)); @@ -443,8 +447,6 @@ public class FontPanel extends JPanel { addCharsPanel.add(buttonPreviewFont, "3,1"); addCharsPanel.add(buttonSetAdvanceValues, "4,1"); - addCharsPanel.add(updateTextsCheckBox, "0,2,2,2"); - JPanel buttonsPanel = new JPanel(new FlowLayout()); buttonsPanel.add(buttonEdit); buttonsPanel.add(buttonSave); @@ -484,13 +486,17 @@ public class FontPanel extends JPanel { TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); if (item instanceof FontTag) { + FontTag ft = (FontTag) item; Set selChars = new TreeSet<>(); for (int c = 0; c < newchars.length(); c++) { selChars.add(newchars.codePointAt(c)); } - fontAddChars((FontTag) item, selChars, ((FontFace) fontFaceSelection.getSelectedItem()).font); - fontAddCharactersField.setText(""); - mainPanel.reload(true); + + if (!selChars.isEmpty()) { + fontAddChars(ft, selChars, ((FontFace) fontFaceSelection.getSelectedItem()).font); + fontAddCharactersField.setText(""); + mainPanel.reload(true); + } } } @@ -503,7 +509,6 @@ public class FontPanel extends JPanel { Set selChars = fed.getSelectedChars(); if (!selChars.isEmpty()) { Font selFont = fed.getSelectedFont(); - updateTextsCheckBox.setSelected(fed.hasUpdateTexts()); fontFamilyNameSelection.setSelectedItem(new FontFamily(selFont)); fontFaceSelection.setSelectedItem(new FontFace(selFont)); fontAddChars(ft, selChars, selFont); @@ -674,8 +679,6 @@ public class FontPanel extends JPanel { private JPanel addCharsPanel; - private JCheckBox updateTextsCheckBox; - private JPanel contentPanel; private JScrollPane contentScrollPane; diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 41556a38c..672f09df2 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -82,8 +82,6 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -164,6 +162,7 @@ public class Main { private static boolean inited = false; private static File runTempFile; + private static List runTempFiles = new ArrayList<>(); public static void freeRun() { @@ -717,6 +716,7 @@ public class Main { CancellableWorker worker = new CancellableWorker() { private boolean yestoall = false; + private boolean notoall = false; private SWF open(InputStream is, String file, String fileTitle) throws IOException, InterruptedException { diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 4a0907630..4d81344ea 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -707,3 +707,4 @@ message.imported.swf = The SWF file uses assets from an imported SWF file:\n%url message.imported.swf.manually = Cannot load imported SWF\n%url%\nThe file or URL does not exist.\nDo you want to select local file? message.warning.hexViewNotUpToDate = Hex View is not up-to-date. Please save and reload the file to update Hex View. +message.font.replace.updateTexts = Some characters were replaced. Do you want to update the existing texts? \ No newline at end of file