mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 09:31:09 +00:00
Added AS3 P-code editing class trait
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2023 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui.abc;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.ASM3Parser;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.gui.AppStrings;
|
||||
import com.jpexs.decompiler.flash.gui.FasterScrollPane;
|
||||
import com.jpexs.decompiler.flash.gui.ViewMessages;
|
||||
import com.jpexs.decompiler.flash.gui.editor.LineMarkedEditorPane;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ClassTraitDetailPanel extends JPanel implements TraitDetail {
|
||||
|
||||
public LineMarkedEditorPane classEditor;
|
||||
|
||||
private ABC abc;
|
||||
|
||||
private TraitClass trait;
|
||||
|
||||
private List<Highlighting> specialHilights;
|
||||
|
||||
private boolean ignoreCaret = false;
|
||||
|
||||
public ClassTraitDetailPanel(final DecompiledEditorPane editor) {
|
||||
classEditor = new LineMarkedEditorPane();
|
||||
setLayout(new BorderLayout());
|
||||
add(new FasterScrollPane(classEditor), BorderLayout.CENTER);
|
||||
classEditor.setFont(Configuration.getSourceFont());
|
||||
classEditor.changeContentType("text/flasm3");
|
||||
classEditor.addCaretListener(new CaretListener() {
|
||||
@Override
|
||||
public void caretUpdate(CaretEvent e) {
|
||||
if (ignoreCaret) {
|
||||
return;
|
||||
}
|
||||
Highlighting spec = Highlighting.searchPos(specialHilights, classEditor.getCaretPosition());
|
||||
if (spec != null) {
|
||||
editor.hilightSpecial(spec.getProperties().subtype, (int) spec.getProperties().index);
|
||||
classEditor.getCaret().setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void hilightSpecial(Highlighting special) {
|
||||
Highlighting sel = null;
|
||||
for (Highlighting h : specialHilights) {
|
||||
if (h.getProperties().subtype.equals(special.getProperties().subtype)) {
|
||||
if (h.getProperties().index == special.getProperties().index) {
|
||||
sel = h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sel != null) {
|
||||
ignoreCaret = true;
|
||||
classEditor.setCaretPosition(sel.startPos);
|
||||
classEditor.getCaret().setVisible(true);
|
||||
ignoreCaret = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void load(TraitClass trait, ABC abc, boolean isStatic) {
|
||||
this.abc = abc;
|
||||
this.trait = trait;
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
trait.convertTraitHeader(abc, writer);
|
||||
if (Configuration.indentAs3PCode.get()) {
|
||||
writer.unindent();
|
||||
}
|
||||
writer.appendNoHilight("end ; trait");
|
||||
String s = writer.toString();
|
||||
specialHilights = writer.specialHilights;
|
||||
classEditor.setText(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save() {
|
||||
try {
|
||||
if (!ASM3Parser.parseClass(abc, new StringReader(classEditor.getText()), abc.constants, trait)) {
|
||||
return false;
|
||||
}
|
||||
} catch (AVM2ParseException ex) {
|
||||
ViewMessages.showMessageDialog(classEditor, ex.text, AppStrings.translate("error.class"), JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ClassTraitDetailPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
abc.refreshMultinameNamespaceSuffixes();
|
||||
((Tag) abc.parentTag).setModified(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditMode(boolean val) {
|
||||
if (val && active) {
|
||||
ViewMessages.showMessageDialog(this, AppStrings.translate("warning.initializers.class"), AppStrings.translate("message.warning"), JOptionPane.WARNING_MESSAGE, Configuration.warningInitializersClass);
|
||||
}
|
||||
classEditor.setEditable(val);
|
||||
if (val) {
|
||||
classEditor.requestFocusInWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean active = false;
|
||||
|
||||
@Override
|
||||
public void setActive(boolean val) {
|
||||
this.active = val;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
|
||||
@@ -674,7 +675,21 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
lastTraitIndex = (int) currentTraitHighlight.getProperties().index;
|
||||
currentTrait = getCurrentTrait();
|
||||
if (currentTrait != null) {
|
||||
if (currentTrait instanceof TraitSlotConst) {
|
||||
if (currentTrait instanceof TraitClass) {
|
||||
abcPanel.detailPanel.classTraitPanel.load((TraitClass)currentTrait, abc, true);
|
||||
final Trait ftrait = currentTrait;
|
||||
final int ftraitIndex = lastTraitIndex;
|
||||
View.execInEventDispatch(() -> {
|
||||
abcPanel.detailPanel.showCard(DetailPanel.CLASS_TRAIT_CARD, ftrait, ftraitIndex, abc);
|
||||
});
|
||||
abcPanel.detailPanel.setEditMode(false);
|
||||
currentMethodHighlight = null;
|
||||
Highlighting spec = Highlighting.searchPos(highlightedText.getSpecialHighlights(), pos, currentTraitHighlight.startPos, currentTraitHighlight.startPos + currentTraitHighlight.len);
|
||||
if (spec != null) {
|
||||
abcPanel.detailPanel.classTraitPanel.hilightSpecial(spec);
|
||||
}
|
||||
return;
|
||||
} else if (currentTrait instanceof TraitSlotConst) {
|
||||
abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) currentTrait, abc,
|
||||
abc.isStaticTraitId(classIndex, lastTraitIndex));
|
||||
final Trait ftrait = currentTrait;
|
||||
@@ -759,6 +774,31 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
boolean isScriptInit = traitId == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER;
|
||||
|
||||
Highlighting tc = Highlighting.searchIndex(highlightedText.getClassHighlights(), classIndex);
|
||||
|
||||
if (!isScriptInit && tc == null) {
|
||||
List<Highlighting> traitHighlights = highlightedText.getTraitHighlights();
|
||||
List<Highlighting> classHighlights = highlightedText.getClassHighlights();
|
||||
looph: for (Highlighting th:traitHighlights) {
|
||||
if (th.getProperties().index == traitId) {
|
||||
for (Highlighting tc2:classHighlights) {
|
||||
if (tc2.startPos <= th.startPos && tc2.startPos + tc2.len >= th.startPos+th.len) {
|
||||
continue looph;
|
||||
}
|
||||
}
|
||||
final int fpos = th.startPos;
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (fpos <= getDocument().getLength()) {
|
||||
setCaretPosition(fpos);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tc != null || isScriptInit) {
|
||||
Highlighting th = Highlighting.searchIndex(highlightedText.getTraitHighlights(), traitId, isScriptInit ? 0 : tc.startPos, isScriptInit ? -1 : tc.startPos + tc.len);
|
||||
int pos = 0;
|
||||
|
||||
@@ -56,12 +56,16 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
|
||||
public JPanel unsupportedTraitPanel;
|
||||
|
||||
public SlotConstTraitDetailPanel slotConstTraitPanel;
|
||||
|
||||
public ClassTraitDetailPanel classTraitPanel;
|
||||
|
||||
public static final String METHOD_GETTER_SETTER_TRAIT_CARD = "abc.detail.methodtrait";
|
||||
|
||||
public static final String UNSUPPORTED_TRAIT_CARD = "abc.detail.unsupported";
|
||||
|
||||
public static final String SLOT_CONST_TRAIT_CARD = "abc.detail.slotconsttrait";
|
||||
|
||||
public static final String CLASS_TRAIT_CARD = "abc.detail.classstrait";
|
||||
|
||||
private final JPanel innerPanel;
|
||||
|
||||
@@ -108,6 +112,9 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
|
||||
|
||||
slotConstTraitPanel = new SlotConstTraitDetailPanel(abcPanel.decompiledTextArea);
|
||||
cardMap.put(SLOT_CONST_TRAIT_CARD, slotConstTraitPanel);
|
||||
|
||||
classTraitPanel = new ClassTraitDetailPanel(abcPanel.decompiledTextArea);
|
||||
cardMap.put(CLASS_TRAIT_CARD, classTraitPanel);
|
||||
|
||||
for (String key : cardMap.keySet()) {
|
||||
innerPanel.add(cardMap.get(key), key);
|
||||
@@ -181,6 +188,7 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
|
||||
topPanel.add(traitInfoPanel, BorderLayout.CENTER);
|
||||
methodTraitPanel.methodCodePanel.getSourceTextArea().addTextChangedListener(this::editorTextChanged);
|
||||
slotConstTraitPanel.slotConstEditor.addTextChangedListener(this::editorTextChanged);
|
||||
classTraitPanel.classEditor.addTextChangedListener(this::editorTextChanged);
|
||||
add(topPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
@@ -212,6 +220,7 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
|
||||
{
|
||||
slotConstTraitPanel.setEditMode(val);
|
||||
methodTraitPanel.setEditMode(val);
|
||||
classTraitPanel.setEditMode(val);
|
||||
saveButton.setVisible(val);
|
||||
saveButton.setEnabled(false);
|
||||
editButton.setVisible(!val);
|
||||
@@ -343,11 +352,13 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
|
||||
return;
|
||||
}
|
||||
int lastTrait = decompiledTextArea.lastTraitIndex;
|
||||
int lastClassIndex = decompiledTextArea.getClassIndex();
|
||||
|
||||
Runnable reloadComplete = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
decompiledTextArea.removeScriptListener(this);
|
||||
decompiledTextArea.setClassIndex(lastClassIndex); //reload resets caret to first class
|
||||
if (lastTrait == GraphTextWriter.TRAIT_UNKNOWN) {
|
||||
decompiledTextArea.gotoLastMethod();
|
||||
} else {
|
||||
|
||||
@@ -683,3 +683,7 @@ config.description.rememberScriptsScrollPos = The script scroll/caret position i
|
||||
|
||||
config.name.rememberFoldersScrollPos = Remember folders scroll position
|
||||
config.description.rememberFoldersScrollPos = Folders scroll position is retained when switching items and saved for pinned items.
|
||||
|
||||
#after 18.3.6
|
||||
config.name.warning.initializers.class = Warn on AS3 class trait editation about script initializer
|
||||
config.description.warning.initializers.class = Show warning on AS3 class trait editation about initializer
|
||||
|
||||
@@ -673,3 +673,7 @@ config.description.rememberScriptsScrollPos = Pozice odskrolov\u00e1n\u00ed/kurz
|
||||
|
||||
config.name.rememberFoldersScrollPos = Zapamatovat pozici odskrolov\u00e1n\u00ed u slo\u017eek
|
||||
config.description.rememberFoldersScrollPos = Pozice odskrolov\u00e1n\u00ed u slo\u017eek je zachov\u00e1na p\u0159i p\u0159ep\u00edn\u00e1n\u00ed mezi polo\u017ekami a ukl\u00e1d\u00e1na pro p\u0159ipnut\u00e9 polo\u017eky.
|
||||
|
||||
#after 18.3.6
|
||||
config.name.warning.initializers.class = Varovat p\u0159i AS3 class editaci o inicializ\u00e1toru
|
||||
config.description.warning.initializers.class = Zobrazovat varov\u00e1n\u00ed p\u0159i editaci AS3 class o inicializ\u00e1toru
|
||||
|
||||
@@ -1126,4 +1126,8 @@ header.displayrect.unit.twips = twips
|
||||
#after 18.3.6
|
||||
button.abc.linkedSwfs.hint = Other SWF dependencies
|
||||
abc.linkedSwfs.one = +1 swf
|
||||
abc.linkedSwfs.more = +%num% swfs
|
||||
abc.linkedSwfs.more = +%num% swfs
|
||||
|
||||
#class trait P-code editor
|
||||
error.class = Class error
|
||||
warning.initializers.class = Class fields like extends and/or implements are also used in script initializer.\nEditing these values here in class trait is not enough!
|
||||
|
||||
@@ -1111,4 +1111,8 @@ header.displayrect.unit.twips = twipy
|
||||
#after 18.3.6
|
||||
button.abc.linkedSwfs.hint = Z\u00e1vislosti na dal\u0161\u00edch SWF
|
||||
abc.linkedSwfs.one = +1 swf
|
||||
abc.linkedSwfs.more = +%num% swf
|
||||
abc.linkedSwfs.more = +%num% swf
|
||||
|
||||
#class trait P-code editor
|
||||
error.class = Class chyba
|
||||
warning.initializers.class = Polo\u017eky class jako extends a/nebo implements jsou tak\u00e9 pou\u017e\u00edv\u00e1ny v inicializ\u00e9ru skriptu.\nUpravit tyto hodnoty pouze zde v class vlastnosti nesta\u010d\u00ed!
|
||||
|
||||
Reference in New Issue
Block a user