chore (gui): Add button in preferences dialog to copy the preference values in text form (json) to clipboard
This commit is contained in:
@@ -17,6 +17,7 @@ import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import jadx.gui.JadxGUI;
|
||||
import jadx.gui.utils.PathTypeAdapter;
|
||||
@@ -92,6 +93,10 @@ public class JadxSettingsAdapter {
|
||||
return GSON.toJson(settings);
|
||||
}
|
||||
|
||||
public static JsonObject makeJsonObject(JadxSettings settings) {
|
||||
return GSON.toJsonTree(settings).getAsJsonObject();
|
||||
}
|
||||
|
||||
public static void fill(JadxSettings settings, String jsonStr) {
|
||||
populate(GSON_BUILDER, jsonStr, JadxSettings.class, settings);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package jadx.gui.settings;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -13,6 +15,9 @@ import javax.swing.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import say.swing.JFontChooser;
|
||||
|
||||
import jadx.api.JadxArgs;
|
||||
@@ -113,10 +118,31 @@ public class JadxSettingsWindow extends JDialog {
|
||||
}
|
||||
});
|
||||
|
||||
JButton copyBtn = new JButton(NLS.str("preferences.copy"));
|
||||
copyBtn.addActionListener(event -> {
|
||||
|
||||
JsonObject settingsJson = JadxSettingsAdapter.makeJsonObject(this.settings);
|
||||
// remove irrelevant preferences
|
||||
settingsJson.remove("windowPos");
|
||||
settingsJson.remove("mainWindowExtendedState");
|
||||
settingsJson.remove("lastSaveProjectPath");
|
||||
settingsJson.remove("lastOpenFilePath");
|
||||
settingsJson.remove("lastSaveFilePath");
|
||||
settingsJson.remove("recentProjects");
|
||||
String settingsText = new GsonBuilder().setPrettyPrinting().create().toJson(settingsJson);
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
StringSelection selection = new StringSelection(settingsText);
|
||||
clipboard.setContents(selection, selection);
|
||||
JOptionPane.showMessageDialog(
|
||||
JadxSettingsWindow.this,
|
||||
NLS.str("preferences.copy_message"));
|
||||
});
|
||||
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
|
||||
buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
buttonPane.add(resetBtn);
|
||||
buttonPane.add(copyBtn);
|
||||
buttonPane.add(Box.createHorizontalGlue());
|
||||
buttonPane.add(saveBtn);
|
||||
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||
|
||||
@@ -124,6 +124,8 @@ preferences.cancel=Cancel
|
||||
preferences.reset=Reset
|
||||
preferences.reset_message=Reset settings to default values?
|
||||
preferences.reset_title=Reset settings
|
||||
preferences.copy=Copy to clipboard
|
||||
preferences.copy_message=All settings values has been copied to clipboard
|
||||
preferences.rename=Rename
|
||||
preferences.rename_case=System case sensitivity
|
||||
preferences.rename_valid=To be valid identifier
|
||||
|
||||
Reference in New Issue
Block a user