mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 15:10:45 +00:00
AS3: Exporting selected scripts
AS3: Search bar to the top
This commit is contained in:
@@ -522,7 +522,6 @@ public class ABC {
|
||||
for (int i = 0; i < script_info.length; i++) {
|
||||
String path = script_info[i].getPath(this);
|
||||
String packageName = path.substring(0, path.lastIndexOf("."));
|
||||
String className = path.substring(path.lastIndexOf(".") + 1);
|
||||
if (packageName.equals("")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
@@ -532,15 +531,7 @@ public class ABC {
|
||||
}
|
||||
String exStr = "Exporting " + abcStr + cnt + path + " ...";
|
||||
informListeners("export", exStr);
|
||||
logger.info(exStr);
|
||||
File outDir = new File(directory + File.separatorChar + packageName.replace('.', File.separatorChar));
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
String fileName = outDir.toString() + File.separator + className + ".as";
|
||||
FileOutputStream fos = new FileOutputStream(fileName);
|
||||
fos.write(script_info[i].convert(abcList, this, pcode, false).getBytes());
|
||||
fos.close();
|
||||
script_info[i].export(this, abcList, directory, pcode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||
import com.jpexs.asdec.abc.types.traits.TraitClass;
|
||||
import com.jpexs.asdec.tags.DoABCTag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import javax.swing.ImageIcon;
|
||||
@@ -28,6 +29,7 @@ import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
public class ClassesListTree extends JTree implements TreeSelectionListener {
|
||||
|
||||
@@ -55,6 +57,41 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
|
||||
setCellRenderer(treeRenderer);
|
||||
}
|
||||
|
||||
public List<TreeLeafScript> getSelectedScripts() {
|
||||
TreeSelectionModel tsm = getSelectionModel();
|
||||
final List<TreeLeafScript> selectedScripts = new ArrayList<TreeLeafScript>();
|
||||
TreePath tps[] = tsm.getSelectionPaths();
|
||||
if (tps == null) {
|
||||
return selectedScripts;
|
||||
}
|
||||
for (TreePath tp : tps) {
|
||||
TreeElement te = (TreeElement) tp.getLastPathComponent();
|
||||
if (te.isLeaf()) {
|
||||
Object item = te.getItem();
|
||||
if (item instanceof TreeLeafScript) {
|
||||
selectedScripts.add((TreeLeafScript) item);
|
||||
}
|
||||
} else {
|
||||
TreeVisitor tvi = new TreeVisitor() {
|
||||
@Override
|
||||
public void onBranch(TreeElement branch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaf(TreeElement leaf) {
|
||||
Object item = leaf.getItem();
|
||||
if (item instanceof TreeLeafScript) {
|
||||
selectedScripts.add((TreeLeafScript) item);
|
||||
}
|
||||
}
|
||||
};
|
||||
te.visitBranches(tvi);
|
||||
te.visitLeafs(tvi);
|
||||
}
|
||||
}
|
||||
return selectedScripts;
|
||||
}
|
||||
|
||||
public HashMap<String, TreeLeafScript> getTreeList(List<DoABCTag> list) {
|
||||
HashMap<String, TreeLeafScript> ret = new HashMap<String, TreeLeafScript>();
|
||||
for (DoABCTag tag : list) {
|
||||
|
||||
@@ -37,6 +37,8 @@ import javax.swing.border.BevelBorder;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import jsyntaxpane.DefaultSyntaxKit;
|
||||
|
||||
public class MainFrame extends JFrame implements ActionListener, ItemListener {
|
||||
@@ -254,7 +256,7 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
|
||||
searchPanel.add(filterField, BorderLayout.CENTER);
|
||||
JLabel picLabel = new JLabel(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/search.png")));
|
||||
searchPanel.add(picLabel, BorderLayout.EAST);
|
||||
treePanel.add(searchPanel, BorderLayout.SOUTH);
|
||||
treePanel.add(searchPanel, BorderLayout.NORTH);
|
||||
|
||||
splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
|
||||
treePanel,
|
||||
@@ -314,20 +316,41 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
|
||||
miSaveAs.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/save16.png")));
|
||||
miSaveAs.setActionCommand("SAVEAS");
|
||||
miSaveAs.addActionListener(this);
|
||||
JMenuItem miExport = new JMenuItem("Export as ActionScript...");
|
||||
miExport.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportas16.png")));
|
||||
miExport.setActionCommand("EXPORT");
|
||||
miExport.addActionListener(this);
|
||||
JMenu menuExportAll = new JMenu("Export all");
|
||||
JMenuItem miExportAllAS = new JMenuItem("ActionScript...");
|
||||
miExportAllAS.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportas16.png")));
|
||||
miExportAllAS.setActionCommand("EXPORT");
|
||||
miExportAllAS.addActionListener(this);
|
||||
|
||||
JMenuItem miExportAllPCode = new JMenuItem("PCode...");
|
||||
miExportAllPCode.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportpc16.png")));
|
||||
miExportAllPCode.setActionCommand("EXPORTPCODE");
|
||||
miExportAllPCode.addActionListener(this);
|
||||
|
||||
menuExportAll.add(miExportAllAS);
|
||||
menuExportAll.add(miExportAllPCode);
|
||||
|
||||
|
||||
JMenu menuExportSel = new JMenu("Export selection");
|
||||
JMenuItem miExportSelAS = new JMenuItem("ActionScript...");
|
||||
miExportSelAS.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportas16.png")));
|
||||
miExportSelAS.setActionCommand("EXPORTSEL");
|
||||
miExportSelAS.addActionListener(this);
|
||||
|
||||
JMenuItem miExportSelPCode = new JMenuItem("PCode...");
|
||||
miExportSelPCode.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportpc16.png")));
|
||||
miExportSelPCode.setActionCommand("EXPORTPCODESEL");
|
||||
miExportSelPCode.addActionListener(this);
|
||||
|
||||
menuExportSel.add(miExportSelAS);
|
||||
menuExportSel.add(miExportSelPCode);
|
||||
|
||||
|
||||
JMenuItem miExportPCode = new JMenuItem("Export as PCode...");
|
||||
miExportPCode.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exportpc16.png")));
|
||||
miExportPCode.setActionCommand("EXPORTPCODE");
|
||||
miExportPCode.addActionListener(this);
|
||||
menuFile.add(miOpen);
|
||||
menuFile.add(miSave);
|
||||
menuFile.add(miSaveAs);
|
||||
menuFile.add(miExport);
|
||||
menuFile.add(miExportPCode);
|
||||
menuFile.add(menuExportAll);
|
||||
menuFile.add(menuExportSel);
|
||||
menuFile.addSeparator();
|
||||
JMenuItem miClose = new JMenuItem("Exit");
|
||||
miClose.setIcon(new ImageIcon(View.loadImage("com/jpexs/asdec/gui/graphics/exit16.png")));
|
||||
@@ -470,7 +493,7 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
|
||||
|
||||
}
|
||||
|
||||
if (e.getActionCommand().equals("EXPORT") || e.getActionCommand().equals("EXPORTPCODE")) {
|
||||
if (e.getActionCommand().startsWith("EXPORT")) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(new java.io.File((String) Configuration.getConfig("lastExportDir", ".")));
|
||||
chooser.setDialogTitle("Select directory to export");
|
||||
@@ -480,12 +503,25 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
|
||||
Main.startWork("Exporting...");
|
||||
final String selFile = chooser.getSelectedFile().getAbsolutePath();
|
||||
Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath());
|
||||
final boolean isPcode = e.getActionCommand().equals("EXPORTPCODE");
|
||||
final boolean isPcode = e.getActionCommand().startsWith("EXPORTPCODE");
|
||||
final boolean onlySel = e.getActionCommand().endsWith("SEL");
|
||||
(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Main.swf.exportActionScript(selFile, isPcode);
|
||||
if (onlySel) {
|
||||
List<TreeLeafScript> tlsList = classTree.getSelectedScripts();
|
||||
if(tlsList.isEmpty()){
|
||||
JOptionPane.showMessageDialog(null, "No script selected!");
|
||||
}
|
||||
for (int i = 0; i < tlsList.size(); i++) {
|
||||
TreeLeafScript tls = tlsList.get(i);
|
||||
Main.startWork("Exporting " + (i + 1) + "/" + tlsList.size() + " " + tls.abc.script_info[tls.scriptIndex].getPath(tls.abc) + " ...");
|
||||
tls.abc.script_info[tls.scriptIndex].export(tls.abc, list, selFile, isPcode);
|
||||
}
|
||||
} else {
|
||||
Main.swf.exportActionScript(selFile, isPcode);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot write to the file");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.StringTokenizer;
|
||||
|
||||
public class Tree {
|
||||
|
||||
private final TreeElement ROOT = new TreeElement("", "", -1, null);
|
||||
private final TreeElement ROOT = new TreeElement("", "", null, null);
|
||||
|
||||
public void add(String name, String path, Object item) {
|
||||
StringTokenizer st = new StringTokenizer(path, ".");
|
||||
|
||||
@@ -20,6 +20,9 @@ import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||
import com.jpexs.asdec.abc.types.traits.Traits;
|
||||
import com.jpexs.asdec.tags.DoABCTag;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,4 +54,19 @@ public class ScriptInfo {
|
||||
public String convert(List<DoABCTag> abcTags, ABC abc, boolean pcode, boolean highlighting) {
|
||||
return traits.convert(abcTags, abc, false, pcode, true, -1, highlighting, new ArrayList<String>());
|
||||
}
|
||||
|
||||
public void export(ABC abc, List<DoABCTag> abcList, String directory, boolean pcode) throws IOException {
|
||||
String path = getPath(abc);
|
||||
String packageName = path.substring(0, path.lastIndexOf("."));
|
||||
String className = path.substring(path.lastIndexOf(".") + 1);
|
||||
File outDir = new File(directory + File.separatorChar + packageName.replace('.', File.separatorChar));
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
String fileName = outDir.toString() + File.separator + className + ".as";
|
||||
FileOutputStream fos = new FileOutputStream(fileName);
|
||||
fos.write(convert(abcList, abc, pcode, false).getBytes());
|
||||
fos.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user