Skip to content

Commit

Permalink
Fixed #2337, #2339 Replace shape update bounds - allow selecting mult…
Browse files Browse the repository at this point in the history
…iple shapes
  • Loading branch information
jindrapetrik committed Oct 10, 2024
1 parent 7ff9eb2 commit 45bcfd7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ All notable changes to this project will be documented in this file.
- [#2334] AS1/2 P-code export - Do not export on(xxx) header
- [#2338] AS decompiling threads got stuck after cancelling / timeout
- [#2338] AS2 class detection in some minor cases
- [#2337], [#2339] Replace shape update bounds - allow selecting multiple shapes

## [21.1.0] - 2024-09-23
### Added
Expand Down Expand Up @@ -3618,6 +3619,8 @@ Major version of SWF to XML export changed to 2.
[#2335]: https://www.free-decompiler.com/flash/issues/2335
[#2334]: https://www.free-decompiler.com/flash/issues/2334
[#2338]: https://www.free-decompiler.com/flash/issues/2338
[#2337]: https://www.free-decompiler.com/flash/issues/2337
[#2339]: https://www.free-decompiler.com/flash/issues/2339
[#943]: https://www.free-decompiler.com/flash/issues/943
[#1812]: https://www.free-decompiler.com/flash/issues/1812
[#2287]: https://www.free-decompiler.com/flash/issues/2287
Expand Down
71 changes: 16 additions & 55 deletions src/com/jpexs/decompiler/flash/gui/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5006,6 +5006,9 @@ public boolean replaceMorphShape(MorphShapeTag morphShape, boolean create, boole
}

public boolean replace(List<TreeItem> items, boolean create) {
return replace(items, create, true);
}
public boolean replace(List<TreeItem> items, boolean create, boolean fill) {
if (items.isEmpty()) {
return false;
}
Expand Down Expand Up @@ -5037,12 +5040,12 @@ public boolean replace(List<TreeItem> items, boolean create) {
return false;
}
for (TreeItem ti : items) {
doReplaceAction(ti, file, create);
doReplaceAction(ti, file, create, fill);
}
return true;
}

private void doReplaceAction(TreeItem item, File selectedFile, boolean create) {
private void doReplaceAction(TreeItem item, File selectedFile, boolean create, boolean fill) {
if (selectedFile == null) {
return;
}
Expand Down Expand Up @@ -5118,16 +5121,16 @@ private void doReplaceAction(TreeItem item, File selectedFile, boolean create) {
Tag newTag = null;
if (st instanceof ShapeTag) {
if (svgText != null) {
newTag = new SvgImporter().importSvg((ShapeTag) st, svgText);
newTag = new SvgImporter().importSvg((ShapeTag) st, svgText, fill);
} else {
newTag = new ShapeImporter().importImage((ShapeTag) st, data);
newTag = new ShapeImporter().importImage((ShapeTag) st, data, 0, fill);
}
}
if (st instanceof MorphShapeTag) {
if (svgText != null) {
newTag = new SvgImporter().importSvg((MorphShapeTag) st, svgText);
newTag = new SvgImporter().importSvg((MorphShapeTag) st, svgText, fill);
} else {
newTag = new ShapeImporter().importImage((MorphShapeTag) st, data);
newTag = new ShapeImporter().importImage((MorphShapeTag) st, data, 0, fill);
}
}
SWF swf = st.getSwf();
Expand Down Expand Up @@ -5210,58 +5213,16 @@ public void replaceSpriteWithGifButtonActionPerformed(TreeItem item) {
replaceSpriteWithGif(item);
}

public void replaceNoFillButtonActionPerformed(TreeItem item) {
replaceNoFill(item);
}
public void replaceNoFillButtonActionPerformed(List<TreeItem> items) {
replace(items, false, false);
}

public boolean replaceNoFill(TreeItem item) {
if (item == null) {
return false;
}

if (item instanceof MorphShapeTag) {
return replaceMorphShape((MorphShapeTag) item, false, false);
}
if (item instanceof ShapeTag) {
ShapeTag st = (ShapeTag) item;
String filter = "filter.images|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.svg";
File selectedFile = showImportFileChooser(filter, true, "importshape");
if (selectedFile != null) {
File selfile = Helper.fixDialogFile(selectedFile);
byte[] data = null;
String svgText = null;
if (".svg".equals(Path.getExtension(selfile))) {
svgText = Helper.readTextFile(selfile.getAbsolutePath());
showSvgImportWarning();
} else {
data = Helper.readFile(selfile.getAbsolutePath());
}
try {
Tag newTag = null;
if (svgText != null) {
newTag = new SvgImporter().importSvg(st, svgText, false);
} else {
newTag = new ShapeImporter().importImage(st, data, 0, false);
}
SWF swf = st.getSwf();
if (newTag != null) {
refreshTree(swf);
setTagTreeSelectedNode(getCurrentTree(), newTag);
}

swf.clearImageCache();
swf.clearShapeCache();
} catch (IOException ex) {
logger.log(Level.SEVERE, "Invalid image", ex);
ViewMessages.showMessageDialog(this, translate("error.image.invalid"), translate("error"), JOptionPane.ERROR_MESSAGE);
}
reload(true);
return true;
}
}
return false;
List<TreeItem> items = new ArrayList<>();
items.add(item);
return replace(items, false, false);
}

private void showSvgImportWarning() {
ViewMessages.showMessageDialog(this, AppStrings.translate("message.warning.svgImportExperimental"), AppStrings.translate("message.warning"), JOptionPane.WARNING_MESSAGE, Configuration.warningSvgImport);
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/jpexs/decompiler/flash/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ public void actionPerformed(ActionEvent e) {
replaceShapeUpdateBoundsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainPanel.replaceNoFillButtonActionPerformed(mainPanel.getCurrentTree().getCurrentTreeItem());
mainPanel.replaceNoFill(mainPanel.getCurrentTree().getCurrentTreeItem());
}
});
replaceShapeUpdateBoundsButton.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void actionPerformed(ActionEvent e) {
replaceNoFillMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainPanel.replaceNoFillButtonActionPerformed(getCurrentItem());
mainPanel.replaceNoFillButtonActionPerformed(getSelectedItems());
}
});
replaceNoFillMenuItem.setIcon(View.getIcon("replaceitem16"));
Expand Down

0 comments on commit 45bcfd7

Please sign in to comment.