feat(gui): add an action to prettify json file in resources (PR #1880)
* feat(gui): add an action to prettify json file in resources * fix build --------- Co-authored-by: Skylot <skylot@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import jadx.gui.JadxWrapper;
|
||||
import jadx.gui.settings.JadxProject;
|
||||
import jadx.gui.treemodel.JClass;
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.treemodel.JResource;
|
||||
import jadx.gui.ui.MainWindow;
|
||||
import jadx.gui.ui.panel.ContentPanel;
|
||||
import jadx.gui.utils.CaretPositionFix;
|
||||
@@ -51,6 +52,10 @@ public final class CodeArea extends AbstractCodeArea {
|
||||
addMenuItems();
|
||||
}
|
||||
|
||||
if (node instanceof JResource && node.makeString().endsWith(".json")) {
|
||||
addMenuForJsonFile();
|
||||
}
|
||||
|
||||
setHyperlinksEnabled(true);
|
||||
setLinkScanningMask(InputEvent.CTRL_DOWN_MASK);
|
||||
CodeLinkGenerator codeLinkGenerator = new CodeLinkGenerator(this);
|
||||
@@ -137,6 +142,12 @@ public final class CodeArea extends AbstractCodeArea {
|
||||
});
|
||||
}
|
||||
|
||||
private void addMenuForJsonFile() {
|
||||
JNodePopupBuilder popup = new JNodePopupBuilder(this, getPopupMenu());
|
||||
popup.addSeparator();
|
||||
popup.add(new JsonPrettifyAction(this));
|
||||
}
|
||||
|
||||
public int adjustOffsetForToken(@Nullable Token token) {
|
||||
if (token == null) {
|
||||
return -1;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package jadx.gui.ui.codearea;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.utils.NLS;
|
||||
|
||||
public class JsonPrettifyAction extends JNodeAction {
|
||||
|
||||
private static final long serialVersionUID = -2682529369671695550L;
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public JsonPrettifyAction(CodeArea codeArea) {
|
||||
super(NLS.str("popup.json_prettify"), codeArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(JNode node) {
|
||||
String originString = getCodeArea().getCodeInfo().getCodeStr();
|
||||
JsonElement je = JsonParser.parseString(originString);
|
||||
String prettyString = GSON.toJson(je);
|
||||
getCodeArea().setText(prettyString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionEnabled(JNode node) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -255,6 +255,7 @@ popup.search_global=Globale Suche "%s"
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
#popup.json_prettify=JSON Prettify
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.remove=Remove
|
||||
popup.add_files=Add files
|
||||
popup.add_scripts=Add scripts
|
||||
popup.new_script=New script
|
||||
popup.json_prettify=JSON Prettify
|
||||
|
||||
script.run=Run
|
||||
script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.rename=Nimeta ümber
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
#popup.json_prettify=JSON Prettify
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.search_global="%s" 전역 검색
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
#popup.json_prettify=JSON Prettify
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.search_global=Busca global "%s"
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
#popup.json_prettify=JSON Prettify
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.search_global=Глобальный поиск "%s"
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
#popup.json_prettify=JSON Prettify
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.remove=移除
|
||||
popup.add_files=添加文件
|
||||
popup.add_scripts=添加脚本
|
||||
popup.new_script=新建脚本
|
||||
popup.json_prettify=JSON 格式化
|
||||
|
||||
script.run=运行
|
||||
script.save=保存
|
||||
|
||||
@@ -255,6 +255,7 @@ popup.search_global=全域搜尋 "%s"
|
||||
#popup.add_files=Add files
|
||||
#popup.add_scripts=Add scripts
|
||||
#popup.new_script=New script
|
||||
popup.json_prettify=JSON 格式化
|
||||
|
||||
#script.run=Run
|
||||
#script.save=Save
|
||||
|
||||
Reference in New Issue
Block a user