Skip to content

Ghidra is a software reverse engineering (SRE) framework

Added double click listener to marker margin

ghidravore95b47d5c3688
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java
index 3c0cc457b4..dbfb4d407c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java
@@ -99,6 +99,7 @@ public class MarkerManager implements MarkerService {
private PopupWindow popupWindow;
private List<ChangeListener> listeners = new ArrayList<>();
+ private MarkerClickedListener markerClickedListener = null;
public MarkerManager(Plugin ownerPlugin) {
this(ownerPlugin.getName(), ownerPlugin.getTool());
@@ -128,6 +129,23 @@ public class MarkerManager implements MarkerService {
markerPanel.setPreferredSize(new Dimension(16, 1));
marginProvider = new MyMarginProvider();
+ markerPanel.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() != 2 || markerClickedListener == null) {
+ return;
+ }
+ Address addr = getAddress(e.getY());
+ if (addr == null) {
+ return;
+ }
+ MarkerSet marker = getMarkerSet(addr);
+ MarkerLocation location =
+ new MarkerLocation(marker, currentProgram, addr, e.getX(), e.getY());
+ markerClickedListener.markerDoubleClicked(location);
+ }
+ });
+
actionList = new MarkerActionList();
}
@@ -865,4 +883,12 @@ public class MarkerManager implements MarkerService {
}
}
+ @Override
+ public void setMarkerClickedListener(MarkerClickedListener listener) {
+ if (listener != null && markerClickedListener != null) {
+ throw new IllegalStateException(
+ "Attempted to assign more than one MarkerClickedListener!");
+ }
+ markerClickedListener = listener;
+ }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java
index f7b09551fa..b330e76524 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java
@@ -21,6 +21,7 @@ import javax.swing.ImageIcon;
import javax.swing.event.ChangeListener;
import ghidra.app.plugin.core.marker.MarkerManagerPlugin;
+import ghidra.app.util.viewer.listingpanel.MarkerClickedListener;
import ghidra.framework.plugintool.ServiceInfo;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
@@ -258,4 +259,15 @@ public interface MarkerService {
* @param listener the listener
*/
public void removeChangeListener(ChangeListener listener);
+
+ /**
+ * Sets the listener to be notified when the user double-clicks in the Marker Margin area. Note
+ * that only one listener is allowed to be set at a time. If an attempt to set a second listener
+ * occurs, then an IllegalStateException is thrown.
+ *
+ * @param listener the listener to be notified or null to remove the current listener
+ * @throws IllegalStateException if a listener is already set.
+ */
+ public void setMarkerClickedListener(MarkerClickedListener listener);
+
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/MarkerClickedListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/MarkerClickedListener.java
new file mode 100644
index 0000000000..415beaebf8
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/MarkerClickedListener.java
@@ -0,0 +1,30 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.viewer.listingpanel;
+
+import ghidra.program.util.MarkerLocation;
+
+/**
+ * Interface for notifications when the user double-clicks in the marker margin
+ */
+public interface MarkerClickedListener {
+
+ /**
+ * Notification that the user double-clicked in the marker margin
+ * @param location the MarkerLocation where the user double-clicked
+ */
+ public void markerDoubleClicked(MarkerLocation location);
+}