diff --git a/src/com/jpexs/decompiler/flash/gui/HeaderInfoPanel.java b/src/com/jpexs/decompiler/flash/gui/HeaderInfoPanel.java index bc726ba68..674fd2ef8 100644 --- a/src/com/jpexs/decompiler/flash/gui/HeaderInfoPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/HeaderInfoPanel.java @@ -37,7 +37,7 @@ import layout.TableLayout; * * @author JPEXS */ -public class HeaderInfoPanel extends JPanel { +public class HeaderInfoPanel extends JPanel implements TagEditorPanel { private final JLabel signatureLabel = new JLabel(); @@ -229,10 +229,11 @@ public class HeaderInfoPanel extends JPanel { } private String fmtDouble(double d) { - String r = "" + d; + String r = Double.toString(d); if (r.endsWith(".0")) { r = r.substring(0, r.length() - 2); } + return r; } @@ -252,4 +253,15 @@ public class HeaderInfoPanel extends JPanel { saveButton.setVisible(edit); cancelButton.setVisible(edit); } + + @Override + public boolean tryAutoSave() { + // todo: implement + return false; + } + + @Override + public boolean isEditing() { + return saveButton.isVisible(); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index a6dffcc54..a1c382f59 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -200,7 +200,9 @@ import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.filechooser.FileFilter; import javax.swing.plaf.basic.BasicTreeUI; +import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreePath; +import jsyntaxpane.DefaultSyntaxKit; /** * @@ -212,10 +214,6 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se private final ObservableList swfs; - private ABCPanel abcPanel; - - private ActionPanel actionPanel; - private final JPanel welcomePanel; private final TimelineViewPanel timelineViewPanel; @@ -274,6 +272,10 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se private JPanel searchPanel; + private ABCPanel abcPanel; + + private ActionPanel actionPanel; + private final PreviewPanel previewPanel; private final HeaderInfoPanel headerPanel; @@ -418,6 +420,101 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se UIManager.getDefaults().put("TreeUI", BasicTreeUI.class.getName()); tagTree = new TagTree(null, this); tagTree.addTreeSelectionListener(this); + tagTree.setSelectionModel(new DefaultTreeSelectionModel() { + + private boolean isModified() { + if (abcPanel != null && abcPanel.isEditing()) { + abcPanel.tryAutoSave(); + } + + if (actionPanel != null && actionPanel.isEditing()) { + actionPanel.tryAutoSave(); + } + + if (previewPanel.isEditing()) { + previewPanel.tryAutoSave(); + } + + if (headerPanel.isEditing()) { + headerPanel.tryAutoSave(); + } + + return (abcPanel != null && abcPanel.isEditing()) + || (actionPanel != null && actionPanel.isEditing()) + || previewPanel.isEditing() || headerPanel.isEditing(); + } + + @Override + public void addSelectionPath(TreePath path) { + if (isModified()) { + return; + } + + super.addSelectionPath(path); + } + + @Override + public void addSelectionPaths(TreePath[] paths) { + if (isModified()) { + return; + } + + super.addSelectionPaths(paths); + } + + @Override + public void setSelectionPath(TreePath path) { + if (isModified()) { + return; + } + + super.setSelectionPath(path); + } + + @Override + public void setSelectionPaths(TreePath[] pPaths) { + if (isModified()) { + return; + } + + super.setSelectionPaths(pPaths); + } + + @Override + public void clearSelection() { + if (isModified()) { + return; + } + + super.clearSelection(); + } + + public void setSelection(TreePath[] selection) { + if (isModified()) { + return; + } + + this.selection = selection; + } + + @Override + public void removeSelectionPath(TreePath path) { + if (isModified()) { + return; + } + + super.removeSelectionPath(path); + } + + @Override + public void removeSelectionPaths(TreePath[] paths) { + if (isModified()) { + return; + } + + super.removeSelectionPaths(paths); + } + }); DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(tagTree, DnDConstants.ACTION_COPY_OR_MOVE, new DragGestureListener() { @@ -503,6 +600,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se displayPanel = new JPanel(new CardLayout()); + DefaultSyntaxKit.initKit(); previewPanel = new PreviewPanel(this, flashPanel); displayPanel.add(previewPanel, CARDPREVIEWPANEL); displayPanel.add(createFolderPreviewCard(), CARDFOLDERPREVIEWPANEL); diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 0d547a829..6d6bab7ab 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -108,13 +108,12 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import jsyntaxpane.DefaultSyntaxKit; /** * * @author JPEXS */ -public class PreviewPanel extends JPersistentSplitPane { +public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel { private static final String FLASH_VIEWER_CARD = "FLASHVIEWER"; @@ -372,7 +371,6 @@ public class PreviewPanel extends JPersistentSplitPane { } private JPanel createMetadataCard() { - DefaultSyntaxKit.initKit(); JPanel metadataCard = new JPanel(new BorderLayout()); metadataEditor = new LineMarkedEditorPane(); metadataCard.add(new JScrollPane(metadataEditor), BorderLayout.CENTER); @@ -1175,4 +1173,17 @@ public class PreviewPanel extends JPersistentSplitPane { imagePanel.setTimelined(MainPanel.makeTimelined(fontTag, fontPageNum), fontTag.getSwf(), 0); } } + + @Override + public boolean tryAutoSave() { + // todo: implement + return textPanel.tryAutoSave() && false; + } + + @Override + public boolean isEditing() { + return textPanel.isEditing() + || (genericSaveButton.isVisible() && genericSaveButton.isEnabled()) + || (metadataSaveButton.isVisible() && metadataSaveButton.isEnabled()); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/TagEditorPanel.java b/src/com/jpexs/decompiler/flash/gui/TagEditorPanel.java new file mode 100644 index 000000000..336121715 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/TagEditorPanel.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2015 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +/** + * + * @author JPEXS + */ +public interface TagEditorPanel { + + boolean tryAutoSave(); + + boolean isEditing(); +} diff --git a/src/com/jpexs/decompiler/flash/gui/TextPanel.java b/src/com/jpexs/decompiler/flash/gui/TextPanel.java index ce5515b06..451f779fe 100644 --- a/src/com/jpexs/decompiler/flash/gui/TextPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TextPanel.java @@ -46,13 +46,12 @@ import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; -import jsyntaxpane.DefaultSyntaxKit; /** * * @author JPEXS */ -public class TextPanel extends JPanel { +public class TextPanel extends JPanel implements TagEditorPanel { private final MainPanel mainPanel; @@ -93,7 +92,6 @@ public class TextPanel extends JPanel { public TextPanel(final MainPanel mainPanel) { super(new BorderLayout()); - DefaultSyntaxKit.initKit(); this.mainPanel = mainPanel; textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel); textSearchPanel.setAlignmentX(0); @@ -156,7 +154,7 @@ public class TextPanel extends JPanel { textEditButton = createButton("button.edit", "edit16", null, e -> editText()); textSaveButton = createButton("button.save", "save16", null, e -> saveText(true)); textCancelButton = createButton("button.cancel", "cancel16", null, e -> cancelText()); - + // hide the buttonts to aviod panel resize problems on other views textEditButton.setVisible(false); textSaveButton.setVisible(false); @@ -279,6 +277,7 @@ public class TextPanel extends JPanel { if (modified && Configuration.autoSaveTagModifications.get()) { try { saveText(false); + updateButtonsVisibility(); } catch (Exception ex) { Logger.getLogger(TextPanel.class.getName()).log(Level.SEVERE, "Cannot auto-save text tag.", ex); } @@ -408,4 +407,15 @@ public class TextPanel extends JPanel { } } } + + @Override + public boolean tryAutoSave() { + closeTag(); + return true; + } + + @Override + public boolean isEditing() { + return textSaveButton.isVisible() && textSaveButton.isEnabled(); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index cb68c181d..e8de4e8fe 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -48,6 +48,7 @@ import com.jpexs.decompiler.flash.gui.MainPanel; import com.jpexs.decompiler.flash.gui.SearchListener; import com.jpexs.decompiler.flash.gui.SearchPanel; import com.jpexs.decompiler.flash.gui.SearchResultsDialog; +import com.jpexs.decompiler.flash.gui.TagEditorPanel; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.abc.tablemodels.DecimalTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.DoubleTableModel; @@ -105,12 +106,11 @@ import javax.swing.border.BevelBorder; import javax.swing.table.DefaultTableModel; import javax.swing.text.Highlighter; import javax.swing.tree.TreePath; -import jsyntaxpane.DefaultSyntaxKit; import jsyntaxpane.SyntaxDocument; import jsyntaxpane.Token; import jsyntaxpane.TokenType; -public class ABCPanel extends JPanel implements ItemListener, SearchListener, Freed { +public class ABCPanel extends JPanel implements ItemListener, SearchListener, Freed, TagEditorPanel { private MainPanel mainPanel; @@ -154,7 +154,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener modifiedPacks = new ArrayList<>(); + public String lastDecompiled = null; public MainPanel getMainPanel() { return mainPanel; @@ -290,8 +290,6 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener { +public class ActionPanel extends JPanel implements SearchListener, TagEditorPanel { private MainPanel mainPanel; @@ -479,7 +479,6 @@ public class ActionPanel extends JPanel implements SearchListener