From 88adac7965814d2bb5774e4ade90660c29493c0f Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 26 Feb 2015 17:47:05 +0100 Subject: [PATCH] #805 Editor mode for Define*Texts improved --- .../flash/abc/types/traits/TraitClass.java | 1 + .../flash/helpers/GraphTextWriter.java | 2 +- .../flash/helpers/HighlightedTextWriter.java | 2 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 1 - .../decompiler/flash/gui/PreviewPanel.java | 4 -- .../jpexs/decompiler/flash/gui/TextPanel.java | 44 ++++++++++++------- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index cf239e5dc..049312d13 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -380,6 +380,7 @@ public class TraitClass extends Trait implements TraitWithSlot { } } + //imports List imports = new ArrayList<>(); List uses = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java index f101c8b4e..92aeefd97 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java @@ -120,7 +120,7 @@ public abstract class GraphTextWriter { return hilightSpecial(text, type, specialValue, new HighlightData()); } - public GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) { + protected GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) { return this; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java index ce525d936..e6063d58a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java @@ -155,7 +155,7 @@ public class HighlightedTextWriter extends GraphTextWriter { } @Override - public HighlightedTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) { + protected HighlightedTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) { HighlightData ndata = new HighlightData(); ndata.merge(data); ndata.subtype = type; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 7c3f74bc6..3791c1396 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2227,7 +2227,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec updateUi(); } - previewPanel.setEditText(Configuration.editorMode.get()); reload(false); } diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 56c3de277..a178dda8c 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -458,10 +458,6 @@ public class PreviewPanel extends JSplitPane implements ActionListener { textPanel.setText(textTag.getFormattedText()); } - public void setEditText(boolean edit) { - textPanel.setEditText(edit); - } - public void clear() { imagePanel.stop(); if (media != null) { diff --git a/src/com/jpexs/decompiler/flash/gui/TextPanel.java b/src/com/jpexs/decompiler/flash/gui/TextPanel.java index e047570a6..409e5560c 100644 --- a/src/com/jpexs/decompiler/flash/gui/TextPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TextPanel.java @@ -56,10 +56,10 @@ public class TextPanel extends JPanel { private final LineMarkedEditorPane textValue; - private final JButton textSaveButton; - private final JButton textEditButton; + private final JButton textSaveButton; + private final JButton textCancelButton; private final JButton textAlignLeftButton; @@ -76,6 +76,8 @@ public class TextPanel extends JPanel { private final JButton undoChangesButton; + private boolean modified = false; + public TextPanel(final MainPanel mainPanel) { super(new BorderLayout()); @@ -88,7 +90,6 @@ public class TextPanel extends JPanel { topPanel.add(textSearchPanel); textValue = new LineMarkedEditorPane(); add(new JScrollPane(textValue), BorderLayout.CENTER); - textValue.setEditable(false); textValue.setFont(new Font("Monospaced", Font.PLAIN, textValue.getFont().getSize())); textValue.setContentType("text/swftext"); textValue.getDocument().addDocumentListener(new DocumentListener() { @@ -133,13 +134,10 @@ public class TextPanel extends JPanel { add(topPanel, BorderLayout.NORTH); JPanel buttonsPanel = new JPanel(new FlowLayout()); - textSaveButton = createButton("button.save", "save16", null, e -> saveText()); textEditButton = createButton("button.edit", "edit16", null, e -> editText()); + textSaveButton = createButton("button.save", "save16", null, e -> saveText()); textCancelButton = createButton("button.cancel", "cancel16", null, e -> cancelText()); - textSaveButton.setVisible(false); - textCancelButton.setVisible(false); - buttonsPanel.add(textEditButton); buttonsPanel.add(textSaveButton); buttonsPanel.add(textCancelButton); @@ -165,22 +163,28 @@ public class TextPanel extends JPanel { public void setText(String text) { textValue.setText(text); textValue.setCaretPosition(0); + modified = false; + setEditText(false); } - public void setEditText(boolean edit) { - textValue.setEditable(edit); - updateButtonsVisibility(edit); + private void setEditText(boolean edit) { + textValue.setEditable(Configuration.editorMode.get() || edit); + updateButtonsVisibility(); } - private void updateButtonsVisibility(boolean edit) { - textSaveButton.setVisible(edit); + private void updateButtonsVisibility() { + boolean edit = textValue.isEditable(); + boolean editorMode = Configuration.editorMode.get(); textEditButton.setVisible(!edit); + textSaveButton.setVisible(edit); + textSaveButton.setEnabled(modified); textCancelButton.setVisible(edit); + textCancelButton.setEnabled(modified || !editorMode); TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); boolean alignable = false; if (item instanceof TextTag && !(item instanceof DefineEditTextTag)) { - alignable = !edit; + alignable = !edit || (editorMode && !modified); } textAlignLeftButton.setVisible(alignable); @@ -206,7 +210,7 @@ public class TextPanel extends JPanel { private void editText() { setEditText(true); - textChanged(); + showTextComparingPreview(); } private void cancelText() { @@ -220,6 +224,7 @@ public class TextPanel extends JPanel { TextTag textTag = (TextTag) item; if (mainPanel.saveText(textTag, textValue.getText(), null)) { setEditText(false); + modified = false; item.getSwf().clearImageCache(); mainPanel.refreshTree(); } @@ -231,7 +236,7 @@ public class TextPanel extends JPanel { if (item instanceof TextTag) { TextTag textTag = (TextTag) item; if (mainPanel.alignText(textTag, textAlign)) { - updateButtonsVisibility(textValue.isEditable()); + updateButtonsVisibility(); item.getSwf().clearImageCache(); mainPanel.refreshTree(); } @@ -243,7 +248,7 @@ public class TextPanel extends JPanel { if (item instanceof TextTag) { TextTag textTag = (TextTag) item; if (mainPanel.translateText(textTag, delta)) { - updateButtonsVisibility(textValue.isEditable()); + updateButtonsVisibility(); item.getSwf().clearImageCache(); mainPanel.refreshTree(); } @@ -265,6 +270,13 @@ public class TextPanel extends JPanel { } private void textChanged() { + modified = true; + updateButtonsVisibility(); + + showTextComparingPreview(); + } + + private void showTextComparingPreview() { if (!Configuration.showOldTextDuringTextEditing.get()) { return; }