Skip to content

Commit 35cde0d

Browse files
committed
Add execute sequence shortcut
1 parent 75e8f9a commit 35cde0d

File tree

5 files changed

+65
-38
lines changed

5 files changed

+65
-38
lines changed

src/main/java/com/coreyd97/stepper/Globals.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public class Globals {
1414
public static final String PREF_VARS_IN_INTRUDER = "enableVarsInIntruder";
1515
public static final String PREF_VARS_IN_SPIDER = "enableVarsInSpider";
1616
public static final String PREF_UPDATE_REQUEST_LENGTH = "updateRequestLength";
17+
public static final String PREF_ENABLE_SHORTCUT = "enableShortcut";
1718
}

src/main/java/com/coreyd97/stepper/preferences/StepperPreferenceFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ protected void registerSettings() {
6363
prefs.registerSetting(Globals.PREF_VARS_IN_SPIDER, Boolean.class, true, Preferences.Visibility.GLOBAL);
6464
prefs.registerSetting(Globals.PREF_VARS_IN_SCANNER, Boolean.class, true, Preferences.Visibility.GLOBAL);
6565
prefs.registerSetting(Globals.PREF_UPDATE_REQUEST_LENGTH, Boolean.class, true, Preferences.Visibility.GLOBAL);
66+
prefs.registerSetting(Globals.PREF_ENABLE_SHORTCUT, Boolean.class, true, Preferences.Visibility.GLOBAL);
6667
}
6768
}

src/main/java/com/coreyd97/stepper/preferences/view/OptionsPanel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public OptionsPanel(SequenceManager sequenceManager){
3535
private void buildPanel() {
3636
ComponentGroup configGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Config");
3737
configGroup.addPreferenceComponent(preferences, Globals.PREF_UPDATE_REQUEST_LENGTH, "Automatically update the Content-Length header");
38+
configGroup.addPreferenceComponent(preferences, Globals.PREF_ENABLE_SHORTCUT, "Enable Shortcut (Ctrl+Shift+G)");
3839

3940
ComponentGroup toolEnabledGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Allow Variables Usage");
4041
JCheckBox allToolsCheckbox = toolEnabledGroup.addPreferenceComponent(preferences, Globals.PREF_VARS_IN_ALL_TOOLS, "All Tools");

src/main/java/com/coreyd97/stepper/sequence/StepSequence.java

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public class StepSequence
2525
{
2626
private String title;
27+
private boolean isExecuting; //Ew. Let's fix this later. Temp fix for shortcuts.
2728
private VariableManager globalVariablesManager;
2829
private Vector<Step> steps;
2930
private final ArrayList<StepListener> stepListeners;
@@ -42,50 +43,56 @@ public StepSequence(){
4243
}
4344

4445
public void executeBlocking(){
45-
synchronized (StepSequence.this) {
46-
StepSequenceTab tabUI = Stepper.getUI().getTabForStepManager(this);
47-
SequenceContainer sequenceContainer = tabUI.getStepsContainer();
48-
49-
for (SequenceExecutionListener stepListener : this.sequenceExecutionListeners) {
50-
stepListener.beforeSequenceStart(this.steps);
51-
}
52-
for (Step step : this.steps) {
53-
//Since we can't add a listener to the messageEditors, we must update
54-
//Our request content before executing instead :(
55-
StepPanel panel = sequenceContainer.getPanelForStep(step);
56-
step.setRequestBody(panel.getRequestEditor().getMessage());
57-
58-
if(!step.isReadyToExecute()){
59-
JOptionPane.showMessageDialog(null, "One or more steps are incomplete.");
60-
for (SequenceExecutionListener stepExecutionListener : this.sequenceExecutionListeners) {
61-
stepExecutionListener.afterSequenceEnd(false);
62-
}
63-
return;
46+
if(this.isExecuting) return; //Sequence already being executed.
47+
this.isExecuting = true;
48+
try {
49+
synchronized (StepSequence.this) {
50+
StepSequenceTab tabUI = Stepper.getUI().getTabForStepManager(this);
51+
SequenceContainer sequenceContainer = tabUI.getStepsContainer();
52+
53+
for (SequenceExecutionListener stepListener : this.sequenceExecutionListeners) {
54+
stepListener.beforeSequenceStart(this.steps);
6455
}
65-
}
66-
67-
boolean sequenceSuccess = false;
68-
try {
6956
for (Step step : this.steps) {
70-
//Set step panel as selected panel
57+
//Since we can't add a listener to the messageEditors, we must update
58+
//Our request content before executing instead :(
7159
StepPanel panel = sequenceContainer.getPanelForStep(step);
72-
sequenceContainer.setActivePanel(panel);
73-
List<StepVariable> rollingReplacements = this.getRollingVariablesUpToStep(step);
60+
step.setRequestBody(panel.getRequestEditor().getMessage());
61+
62+
if (!step.isReadyToExecute()) {
63+
JOptionPane.showMessageDialog(null, "One or more steps are incomplete.");
64+
for (SequenceExecutionListener stepExecutionListener : this.sequenceExecutionListeners) {
65+
stepExecutionListener.afterSequenceEnd(false);
66+
}
67+
return;
68+
}
69+
}
7470

75-
//Execute the step
76-
StepExecutionInfo stepExecutionInfo = step.executeStep(rollingReplacements);
77-
this.sequenceExecutionListeners.forEach(listener -> listener.sequenceStepExecuted(stepExecutionInfo));
71+
boolean sequenceSuccess = false;
72+
try {
73+
for (Step step : this.steps) {
74+
//Set step panel as selected panel
75+
StepPanel panel = sequenceContainer.getPanelForStep(step);
76+
sequenceContainer.setActivePanel(panel);
77+
List<StepVariable> rollingReplacements = this.getRollingVariablesUpToStep(step);
78+
79+
//Execute the step
80+
StepExecutionInfo stepExecutionInfo = step.executeStep(rollingReplacements);
81+
this.sequenceExecutionListeners.forEach(listener -> listener.sequenceStepExecuted(stepExecutionInfo));
82+
}
83+
sequenceSuccess = true;
84+
} catch (SequenceCancelledException e) {
85+
//User cancelled. Ignore it.
86+
} catch (SequenceExecutionException e) {
87+
JOptionPane.showMessageDialog(Stepper.getUI().getUiComponent(), e.getMessage(),
88+
"Sequence Stopped", JOptionPane.ERROR_MESSAGE);
89+
}
90+
for (SequenceExecutionListener stepLExecutionistener : sequenceExecutionListeners) {
91+
stepLExecutionistener.afterSequenceEnd(sequenceSuccess);
7892
}
79-
sequenceSuccess = true;
80-
}catch (SequenceCancelledException e){
81-
//User cancelled. Ignore it.
82-
}catch (SequenceExecutionException e){
83-
JOptionPane.showMessageDialog(Stepper.getUI().getUiComponent(), e.getMessage(),
84-
"Sequence Stopped", JOptionPane.ERROR_MESSAGE);
85-
}
86-
for (SequenceExecutionListener stepLExecutionistener : sequenceExecutionListeners) {
87-
stepLExecutionistener.afterSequenceEnd(sequenceSuccess);
8893
}
94+
}finally {
95+
this.isExecuting = false;
8996
}
9097
}
9198

src/main/java/com/coreyd97/stepper/sequence/view/StepSequenceTab.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.coreyd97.stepper.sequence.view;
22

3+
import com.coreyd97.stepper.Globals;
4+
import com.coreyd97.stepper.Stepper;
35
import com.coreyd97.stepper.sequence.StepSequence;
46
import com.coreyd97.stepper.step.view.StepPanel;
57

68
import javax.swing.*;
79
import java.awt.*;
10+
import java.awt.event.*;
811

912
public class StepSequenceTab extends JPanel {
1013
private final StepSequence stepSequence;
@@ -19,6 +22,20 @@ public StepSequenceTab(StepSequence stepSequence){
1922
this.controlPanel = new ControlPanel(this.stepSequence);
2023
add(this.stepsContainer, BorderLayout.CENTER);
2124
add(this.controlPanel, BorderLayout.SOUTH);
25+
26+
ActionMap actionMap = getActionMap();
27+
actionMap.put("ExecuteSequence", new AbstractAction() {
28+
@Override
29+
public void actionPerformed(ActionEvent actionEvent) {
30+
//Execute sequence
31+
if(Stepper.getPreferences().getSetting(Globals.PREF_ENABLE_SHORTCUT)){
32+
SwingUtilities.invokeLater(stepSequence::executeAsync);
33+
}
34+
}
35+
});
36+
37+
InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW);
38+
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), "ExecuteSequence");
2239
}
2340

2441
public SequenceContainer getStepsContainer() {

0 commit comments

Comments
 (0)