Skip to content

Commit

Permalink
Fixed AS3 - Select the trait after adding new
Browse files Browse the repository at this point in the history
Fixed #1955 AS3 - Exception during removing trait
  • Loading branch information
jindrapetrik committed Jan 30, 2023
1 parent 07df4a8 commit 29ed2cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ All notable changes to this project will be documented in this file.
- [#1944] Scroll position not retained on Ctrl+click in the tag tree
- [#1940] AS3 decompilation - wrong assignment
- AS3 - incorrect switching P-code causing empty text
- AS3 - Select the trait after adding new
- [#1955] AS3 - Exception during removing trait

## [18.3.3] - 2023-01-22
### Added
Expand Down Expand Up @@ -2931,6 +2933,7 @@ All notable changes to this project will be documented in this file.
[#1954]: https://www.free-decompiler.com/flash/issues/1954
[#1944]: https://www.free-decompiler.com/flash/issues/1944
[#1940]: https://www.free-decompiler.com/flash/issues/1940
[#1955]: https://www.free-decompiler.com/flash/issues/1955
[#1913]: https://www.free-decompiler.com/flash/issues/1913
[#1894]: https://www.free-decompiler.com/flash/issues/1894
[#1801]: https://www.free-decompiler.com/flash/issues/1801
Expand Down
16 changes: 12 additions & 4 deletions src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;
Expand Down Expand Up @@ -1781,7 +1782,7 @@ private void removeTraitButtonActionPerformed(ActionEvent evt) {
}

if (ViewMessages.showConfirmDialog(this, AppStrings.translate("message.confirm.removetrait"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {

navigator.setModel(new DefaultListModel<>());
if (scriptTraitsUsed) {
final int fTraitIndex = traitIndex;
final Traits fTraits = traits;
Expand All @@ -1802,7 +1803,7 @@ public void run() {
((Tag) abc.parentTag).setModified(true);
reload();
}

}
}

Expand Down Expand Up @@ -1857,6 +1858,7 @@ private void addTraitButtonActionPerformed(ActionEvent evt) {
}
}
} while (again);
navigator.setModel(new DefaultListModel<>());
switch (kind) {
case Trait.TRAIT_GETTER:
case Trait.TRAIT_SETTER:
Expand Down Expand Up @@ -1906,8 +1908,14 @@ private void addTraitButtonActionPerformed(ActionEvent evt) {
abc.script_info.get(scriptIndex).setModified(true);
}
((Tag) abc.parentTag).setModified(true);
reload();
decompiledTextArea.gotoTrait(traitId);
decompiledTextArea.addScriptListener(new Runnable() {
@Override
public void run() {
decompiledTextArea.gotoTrait(traitId);
decompiledTextArea.removeScriptListener(this);
}
});
reload();
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.jpexs.decompiler.flash.abc.types.ConvertData;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitType;
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.search.ABCSearchResult;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -99,14 +101,22 @@ public String toString() {
}
} else if (isStatic) {
ConvertData convertData = new ConvertData();
Trait trait = abc.class_info.get(classIndex).static_traits.traits.get(index);
List<Trait> traits = abc.class_info.get(classIndex).static_traits.traits;
if (index >= traits.size()) {
return "";
}
Trait trait = traits.get(index);
trait.convertHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
s = writer.toString();
} else {
ConvertData convertData = new ConvertData();
Trait trait = abc.instance_info.get(classIndex).instance_traits.traits.get(index);
List<Trait> traits = abc.instance_info.get(classIndex).instance_traits.traits;
if (index >= traits.size()) {
return "";
}
Trait trait = traits.get(index);
trait.convertHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
Expand Down

0 comments on commit 29ed2cc

Please sign in to comment.