Skip to content

Commit

Permalink
Open dialogs on the same screen as Reshaper. Use new custom dialogs s…
Browse files Browse the repository at this point in the history
…ystem to fix blank dialogs opening on Mac OS.
  • Loading branch information
ddwightx committed Nov 10, 2024
1 parent 5925e59 commit a1be6b2
Show file tree
Hide file tree
Showing 51 changed files with 730 additions and 495 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Java CI with Gradle

on:
push:
branches: [ "release", "post_release" ]
branches: [ "release", "pre_release" ]
pull_request:
branches: [ "release" ]

Expand Down
2 changes: 1 addition & 1 deletion extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

group 'com.synfron.reshaper.burp'
archivesBaseName = 'reshaper-for-burp'
version '2.5.2'
version '2.5.3'

targetCompatibility = '21'
sourceCompatibility = '21'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import synfron.reshaper.burp.core.settings.Workspace;
import synfron.reshaper.burp.core.settings.Workspaces;
import synfron.reshaper.burp.ui.components.workspaces.WorkspaceComponent;
import synfron.reshaper.burp.ui.components.workspaces.WorkspaceNameOptionPane;
import synfron.reshaper.burp.ui.components.workspaces.WorkspaceNameComponent;
import synfron.reshaper.burp.ui.models.workspaces.WorkspaceNameModel;
import synfron.reshaper.burp.ui.utils.ModalPrompter;

Expand Down Expand Up @@ -224,8 +224,20 @@ private void onDisableWorkspaces(ActionEvent actionEvent) {

private void onAddNewWorkspace(ActionEvent actionEvent) {
Workspace workspace = new Workspace(UUID.randomUUID(), "");
WorkspaceNameModel model = new WorkspaceNameModel(workspace, ignored -> Workspaces.get().add(workspace));
ModalPrompter.open(model, ignored -> WorkspaceNameOptionPane.showDialog(model), true);
WorkspaceNameModel model = new WorkspaceNameModel(workspace);

IEventListener<PropertyChangedArgs> modelPropertyChanged = args -> {
if (args.getName().equals("dismissed") && model.isDismissed() && !model.isInvalidated()) {
Workspaces.get().add(workspace);
}
};
model.withListener(modelPropertyChanged);

ModalPrompter.open(model, new ModalPrompter.FormPromptArgs<>(
"Workspace",
model,
new WorkspaceNameComponent(model)
).dataBag(modelPropertyChanged));
}

private void onDefaultWorkspace(ActionEvent actionEvent) {
Expand All @@ -234,7 +246,12 @@ private void onDefaultWorkspace(ActionEvent actionEvent) {

private void onRename(ActionEvent actionEvent) {
WorkspaceNameModel model = new WorkspaceNameModel(workspace);
ModalPrompter.open(model, ignored -> WorkspaceNameOptionPane.showDialog(model), true);

ModalPrompter.open(model, new ModalPrompter.FormPromptArgs<>(
"Workspace",
model,
new WorkspaceNameComponent(model)
));
}

private void onDelete(ActionEvent actionEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package synfron.reshaper.burp.ui.components;

import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.TextPromptModel;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;

public class TextPromptComponent extends JPanel implements IFormComponent {

private final TextPromptModel model;
private JTextPane inputText;

public TextPromptComponent(TextPromptModel model) {
setLayout(new BorderLayout());
this.model = model;
initComponent();
}

private void initComponent() {
add(getBody(), BorderLayout.CENTER);
}

private Component getBody() {
JPanel container = new JPanel(new BorderLayout());

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new EmptyBorder(10,0,0,0));

inputText = IFormComponent.addUndo(new JTextPane());
inputText.setText(model.getText());

inputText.getDocument().addDocumentListener(new DocumentActionListener(this::onTextChanged));

scrollPane.setViewportView(inputText);

container.add(new JLabel(model.getDescription()), BorderLayout.PAGE_START);
container.add(scrollPane, BorderLayout.CENTER);

return container;
}

private void onTextChanged(ActionEvent actionEvent) {
model.setText(inputText.getText());
}

@Override
@SuppressWarnings("unchecked")
public <T extends Component & IFormComponent> T getComponent() {
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import synfron.reshaper.burp.core.events.PropertyChangedArgs;
import synfron.reshaper.burp.core.settings.Workspace;
import synfron.reshaper.burp.core.utils.Log;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.rules.wizard.matchreplace.MatchAndReplaceWizardOptionPane;
import synfron.reshaper.burp.ui.components.rules.wizard.matchreplace.MatchAndReplaceWizardComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.RuleModel;
import synfron.reshaper.burp.ui.models.rules.wizard.matchreplace.MatchAndReplaceWizardModel;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down Expand Up @@ -86,7 +86,11 @@ public Component getHeaderBar() {
private void onAddMatchAndReplace(ActionEvent actionEvent) {
try {
MatchAndReplaceWizardModel model = new MatchAndReplaceWizardModel(this.model);
ModalPrompter.open(model, ignored -> MatchAndReplaceWizardOptionPane.showDialog(model), true);
ModalPrompter.open(model, new ModalPrompter.FormPromptArgs<>(
"Match & Replace",
model,
new MatchAndReplaceWizardComponent(model)
));
} catch (Exception e) {
Log.get(workspace).withMessage("Failed to create rule from content menu").withException(e).logErr();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import synfron.reshaper.burp.core.ProtocolType;
import synfron.reshaper.burp.core.rules.IRuleOperation;
import synfron.reshaper.burp.core.settings.Workspace;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.components.workspaces.IWorkspaceDependentComponent;
import synfron.reshaper.burp.ui.models.rules.RuleOperationModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import synfron.reshaper.burp.core.rules.IRuleOperation;
import synfron.reshaper.burp.core.settings.Workspace;
import synfron.reshaper.burp.core.utils.CollectionUtils;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.components.workspaces.IWorkspaceDependentComponent;
import synfron.reshaper.burp.ui.components.workspaces.IWorkspaceHost;
import synfron.reshaper.burp.ui.models.rules.RuleModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import synfron.reshaper.burp.core.messages.HttpDataDirection;
import synfron.reshaper.burp.core.messages.MessageValue;
import synfron.reshaper.burp.core.rules.SetItemPlacement;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.buildhttpmessage.MessageValueSetterModel;
import synfron.reshaper.burp.ui.utils.ComponentVisibilityManager;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package synfron.reshaper.burp.ui.components.rules.thens.generate;

import synfron.reshaper.burp.core.messages.Encoder;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.generate.IBytesGeneratorModel;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class BytesGeneratorComponent extends GeneratorComponent<IBytesGeneratorModel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synfron.reshaper.burp.ui.components.rules.thens.generate;

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.generate.IGeneratorModel;

import javax.swing.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import synfron.reshaper.burp.core.rules.GetItemPlacement;
import synfron.reshaper.burp.core.vars.SetListItemPlacement;
import synfron.reshaper.burp.core.vars.VariableSource;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.parsehttpmessage.MessageValueGetterModel;
import synfron.reshaper.burp.ui.utils.ComponentVisibilityManager;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import synfron.reshaper.burp.core.messages.Encoder;
import synfron.reshaper.burp.core.rules.thens.entities.transform.Base64Variant;
import synfron.reshaper.burp.core.rules.thens.entities.transform.EncodeTransform;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.transform.Base64TransformerModel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class Base64TransformerComponent extends TransformerComponent<Base64TransformerModel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synfron.reshaper.burp.ui.components.rules.thens.transform;

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.thens.transform.TransformerModel;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package synfron.reshaper.burp.ui.components.rules.wizard.matchreplace;

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.core.events.IEventListener;
import synfron.reshaper.burp.core.events.PropertyChangedArgs;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.PromptTextField;
import synfron.reshaper.burp.ui.models.rules.wizard.matchreplace.MatchAndReplaceWizardModel;
import synfron.reshaper.burp.ui.models.rules.wizard.matchreplace.MatchType;
Expand All @@ -11,61 +13,36 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.beans.PropertyChangeEvent;
import java.util.Objects;

public class MatchAndReplaceWizardOptionPane extends JOptionPane implements IFormComponent {
public class MatchAndReplaceWizardComponent extends JPanel implements IFormComponent {

private final JPanel container;
private final MatchAndReplaceWizardModel model;
private JComboBox<MatchType> matchType;
private JTextField identifier;
private PromptTextField match;
private JLabel matchLabel;
private PromptTextField replace;
private JCheckBox regexMatch;
private final IEventListener<PropertyChangedArgs> modelChangedListener = this::onModelChanged;

private MatchAndReplaceWizardOptionPane(MatchAndReplaceWizardModel model) {
super(new JPanel(new BorderLayout()), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[]{ "OK", "Cancel" }, "OK");
container = (JPanel)message;
public MatchAndReplaceWizardComponent(MatchAndReplaceWizardModel model) {
this.model = model;
addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, this::onPropertyChanged);
initComponent();
}

private void onPropertyChanged(PropertyChangeEvent event) {
if (Objects.equals(getValue(), "OK")) {
if (!model.updateRule()) {
JOptionPane.showMessageDialog(this,
String.join("\n", model.validate()),
"Validation Error",
JOptionPane.ERROR_MESSAGE);
}
} else {
model.setDismissed(true);
}
model.withListener(modelChangedListener);
}

public static void showDialog(MatchAndReplaceWizardModel model) {
MatchAndReplaceWizardOptionPane optionPane = new MatchAndReplaceWizardOptionPane(model);
JDialog dialog = optionPane.createDialog("Match & Replace");
dialog.setResizable(true);

dialog.setModal(false);
dialog.setVisible(true);

optionPane.container.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
dialog.pack();
}
});
private void onModelChanged(PropertyChangedArgs propertyChangedArgs) {
if (propertyChangedArgs.getName().equals("invalidated") && model.isInvalidated()) {
JOptionPane.showMessageDialog(this,
String.join("\n", model.validate()),
"Validation Error",
JOptionPane.ERROR_MESSAGE);
}
}

private void initComponent() {
container.add(getBody(), BorderLayout.CENTER);
add(getBody(), BorderLayout.CENTER);
}

private Component getBody() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.messages.MessageAnnotation;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.AnnotationVariableTagWizardModel;

import javax.swing.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.events.PropertyChangedArgs;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.CookieJarVariableTagWizardModel;

import javax.swing.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synfron.reshaper.burp.ui.components.rules.wizard.vars;

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.CustomVariableTagWizardModel;

import javax.swing.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.messages.Encoder;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.FileVariableTagWizardModel;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.rules.thens.entities.generate.GenerateOption;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.components.rules.thens.generate.*;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.GeneratorVariableTagWizardModel;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.generator.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.ProtocolType;
import synfron.reshaper.burp.core.messages.MessageValue;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.MacroVariableTagWizardModel;
import synfron.reshaper.burp.ui.utils.ComponentVisibilityManager;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.core.ProtocolType;
import synfron.reshaper.burp.core.messages.MessageValue;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.MessageVariableTagWizardModel;
import synfron.reshaper.burp.ui.utils.ComponentVisibilityManager;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package synfron.reshaper.burp.ui.components.rules.wizard.vars;

import net.miginfocom.swing.MigLayout;
import synfron.reshaper.burp.ui.components.IFormComponent;
import synfron.reshaper.burp.ui.components.shared.IFormComponent;
import synfron.reshaper.burp.ui.models.rules.wizard.vars.SpecialVariableTagWizardModel;
import synfron.reshaper.burp.ui.utils.ComponentVisibilityManager;
import synfron.reshaper.burp.ui.utils.DocumentActionListener;
Expand Down
Loading

0 comments on commit a1be6b2

Please sign in to comment.