From 9e10ff7859feeae4afcf246d239c56c3aafac1c1 Mon Sep 17 00:00:00 2001 From: Honfika Date: Mon, 21 Apr 2014 20:16:12 +0200 Subject: [PATCH] text import: show more confirmation dialogs --- .../jpexs/decompiler/flash/gui/MainPanel.java | 176 ++++++++++-------- .../flash/gui/locales/MainFrame.properties | 2 +- .../flash/gui/locales/MainFrame_hu.properties | 2 +- 3 files changed, 104 insertions(+), 76 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 6b22a33c3..e5be9508b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1677,6 +1677,105 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return result; } + private void importTextsSingleFile(File textsFile, SWF swf) { + String texts = Helper.readTextFile(textsFile.getPath()); + Map records = splitTextRecords(texts); + if (records != null) { + for (int characterId : records.keySet()) { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String[] currentRecords = records.get(characterId); + String text = textTag.getFormattedText(); + if (!saveText(textTag, text, currentRecords)) { + if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + } + break; + } + } + } + } + } + } + + private void importTextsSingleFileFormatted(File textsFile, SWF swf) { + String texts = Helper.readTextFile(textsFile.getPath()); + Map records = splitTextRecords(texts); + if (records != null) { + for (int characterId : records.keySet()) { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String[] currentRecords = records.get(characterId); + if (!saveText(textTag, currentRecords[0], null)) { + if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + } + break; + } + } + } + } + } + } + + private void importTextsMultipleFiles(String folder, SWF swf) { + File textsFolder = new File(Path.combine(folder, TextExporter.TEXT_EXPORT_FOLDER)); + String[] files = textsFolder.list(new FilenameFilter() { + + private Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE); + + @Override + public boolean accept(File dir, String name) { + + return pat.matcher(name).matches(); + } + }); + + for (String fileName : files) { + String texts = Helper.readTextFile(Path.combine(textsFolder.getPath(), fileName)); + int characterId = Integer.parseInt(fileName.split("\\.")[0]); + String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; + boolean formatted = !texts.contains(recordSeparator) && texts.startsWith("[" + Helper.newLine); + if (!formatted) { + String[] records = texts.split(recordSeparator); + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String text = textTag.getFormattedText(); + if (!saveText(textTag, text, records)) { + if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + } + break; + } + } + } + } else { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + if (!saveText(textTag, texts, null)) { + if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + } + break; + } + } + } + } + } + } + public void importText(final SWF swf) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get())); @@ -1688,85 +1787,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec File textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_FORMATTED)); // try to import formatted texts if (textsFile.exists()) { - String texts = Helper.readTextFile(textsFile.getPath()); - Map records = splitTextRecords(texts); - if (records != null) { - for (int characterId : records.keySet()) { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String[] currentRecords = records.get(characterId); - saveText(textTag, currentRecords[0], null); - break; - } - } - } - } - } + importTextsSingleFileFormatted(textsFile, swf); } else { textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_PLAIN)); // try to import plain texts if (textsFile.exists()) { - String texts = Helper.readTextFile(textsFile.getPath()); - Map records = splitTextRecords(texts); - if (records != null) { - for (int characterId : records.keySet()) { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String[] currentRecords = records.get(characterId); - String text = textTag.getFormattedText(); - saveText(textTag, text, currentRecords); - break; - } - } - } - } - } + importTextsSingleFile(textsFile, swf); } else { - textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER)); - String[] files = textsFile.list(new FilenameFilter() { - - private Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE); - - @Override - public boolean accept(File dir, String name) { - - return pat.matcher(name).matches(); - } - }); - - for (String fileName : files) { - String texts = Helper.readTextFile(Path.combine(textsFile.getPath(), fileName)); - int characterId = Integer.parseInt(fileName.split("\\.")[0]); - String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; - boolean formatted = !texts.contains(recordSeparator) && texts.startsWith("[" + Helper.newLine); - if (!formatted) { - String[] records = texts.split(recordSeparator); - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String text = textTag.getFormattedText(); - saveText(textTag, text, records); - break; - } - } - } - } else { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - saveText(textTag, texts, null); - break; - } - } - } - } - } + importTextsMultipleFiles(selFile, swf); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 9d6f98d3c..f83d5b53c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -475,4 +475,4 @@ message.confirm.donotshowagain = Do not show again menu.import = Import menu.file.import.text = Import text import.select.directory = Select directory to import -error.text.import = Error during text import \ No newline at end of file +error.text.import = Error during text import. Do you want to continue? \ No newline at end of file diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index 609ab78f5..984bcd57b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -475,4 +475,4 @@ message.confirm.donotshowagain = Ne mutassa \u00fajra menu.import = Import\u00e1l\u00e1s menu.file.import.text = Sz\u00f6veg import\u00e1l\u00e1sa import.select.directory = V\u00e1lassza ki a mapp\u00e1t az import\u00e1l\u00e1shoz -error.text.import = Hiba sz\u00f6veg import\u00e1l\u00e1s k\u00f6zben \ No newline at end of file +error.text.import = Hiba sz\u00f6veg import\u00e1l\u00e1s k\u00f6zben. Folytatja? \ No newline at end of file