From 414bef0ce19c172fdfd5e72310bf7877acb480b3 Mon Sep 17 00:00:00 2001
From: Anciety
The following key mappings are used by the Listing:
@@ -198,6 +198,39 @@Move the cursor to the right one position. If at the end of a line, move the cursor to first position of the next line. + ++ + diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java index 084d6ec6e4..395014e116 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java @@ -101,6 +101,7 @@ public class CodeBrowserPlugin extends Plugin private static final String CURSOR_COLOR = "Cursor.Cursor Color - Focused"; private static final String UNFOCUSED_CURSOR_COLOR = "Cursor.Cursor Color - Unfocused"; private static final String BLINK_CURSOR = "Cursor.Blink Cursor"; + private static final String MOUSE_WHEEL_HORIZONTAL_SCROLLING = "Mouse.Horizontal Scrolling"; // - Icon - private ImageIcon CURSOR_LOC_ICON = @@ -621,16 +622,19 @@ public class CodeBrowserPlugin extends Plugin public void optionsChanged(ToolOptions options, String optionName, Object oldValue, Object newValue) { + ListingPanel listingPanel = connectedProvider.getListingPanel(); if (options.getName().equals(GhidraOptions.CATEGORY_BROWSER_DISPLAY)) { if (optionName.equals(OptionsGui.BACKGROUND.getColorOptionName())) { Color c = (Color) newValue; - connectedProvider.getListingPanel().setTextBackgroundColor(c); + listingPanel.setTextBackgroundColor(c); } } else if (options.getName().equals(GhidraOptions.CATEGORY_BROWSER_FIELDS)) { + + FieldPanel fieldPanel = listingPanel.getFieldPanel(); if (optionName.equals(GhidraOptions.OPTION_SELECTION_COLOR)) { Color color = ((Color) newValue); - connectedProvider.getListingPanel().getFieldPanel().setSelectionColor(color); + fieldPanel.setSelectionColor(color); MarkerSet selectionMarkers = getSelectionMarkers(currentProgram); if (selectionMarkers != null) { selectionMarkers.setMarkerColor(color); @@ -642,7 +646,7 @@ public class CodeBrowserPlugin extends Plugin } else if (optionName.equals(GhidraOptions.OPTION_HIGHLIGHT_COLOR)) { Color color = ((Color) newValue); - connectedProvider.getListingPanel().getFieldPanel().setHighlightColor(color); + fieldPanel.setHighlightColor(color); MarkerSet highlightMarkers = getHighlightMarkers(currentProgram); if (highlightMarkers != null) { highlightMarkers.setMarkerColor(color); @@ -650,15 +654,15 @@ public class CodeBrowserPlugin extends Plugin } else if (optionName.equals(CURSOR_COLOR)) { Color color = ((Color) newValue); - connectedProvider.getListingPanel().getFieldPanel().setFocusedCursorColor(color); + fieldPanel.setFocusedCursorColor(color); } else if (optionName.equals(UNFOCUSED_CURSOR_COLOR)) { Color color = ((Color) newValue); - connectedProvider.getListingPanel().getFieldPanel().setNonFocusCursorColor(color); + fieldPanel.setNonFocusCursorColor(color); } else if (optionName.equals(BLINK_CURSOR)) { Boolean isBlinkCursor = ((Boolean) newValue); - connectedProvider.getListingPanel().getFieldPanel().setBlinkCursor(isBlinkCursor); + fieldPanel.setBlinkCursor(isBlinkCursor); } else if (optionName.equals(GhidraOptions.HIGHLIGHT_CURSOR_LINE_COLOR)) { cursorHighlightColor = (Color) newValue; @@ -672,6 +676,10 @@ public class CodeBrowserPlugin extends Plugin currentCursorMarkers.setColoringBackground(isHighlightCursorLine); } } + else if (optionName.equals(MOUSE_WHEEL_HORIZONTAL_SCROLLING)) { + fieldPanel.setHorizontalScrollingEnabled((Boolean) newValue); + } + connectedProvider.fieldOptionChanged(optionName, newValue); } @@ -833,6 +841,11 @@ public class CodeBrowserPlugin extends Plugin fieldOptions.registerOption(GhidraOptions.HIGHLIGHT_CURSOR_LINE, true, helpLocation, "Toggles highlighting background color of line containing the cursor"); + helpLocation = new HelpLocation(getName(), "Keyboard_Controls_Shift"); + fieldOptions.registerOption(MOUSE_WHEEL_HORIZONTAL_SCROLLING, true, helpLocation, + "Enables horizontal scrolling by holding the Shift key while " + + "using the mouse scroll wheel"); + Color color = fieldOptions.getColor(GhidraOptions.OPTION_SELECTION_COLOR, GhidraOptions.DEFAULT_SELECTION_COLOR); @@ -860,6 +873,10 @@ public class CodeBrowserPlugin extends Plugin Boolean isBlinkCursor = fieldOptions.getBoolean(BLINK_CURSOR, true); fieldPanel.setBlinkCursor(isBlinkCursor); + boolean horizontalScrollingEnabled = + fieldOptions.getBoolean(MOUSE_WHEEL_HORIZONTAL_SCROLLING, true); + fieldPanel.setHorizontalScrollingEnabled(horizontalScrollingEnabled); + cursorHighlightColor = fieldOptions.getColor(GhidraOptions.HIGHLIGHT_CURSOR_LINE_COLOR, CURSOR_LINE_COLOR); @@ -919,8 +936,8 @@ public class CodeBrowserPlugin extends Plugin tableFromSelectionAction.setMenuBarData(new MenuData( new String[] { ToolConstants.MENU_SELECTION, "Create Table From Selection" }, null, "SelectUtils")); - tableFromSelectionAction - .setHelpLocation(new HelpLocation("CodeBrowserPlugin", "Selection_Table")); + tableFromSelectionAction.setHelpLocation( + new HelpLocation("CodeBrowserPlugin", "Selection_Table")); // don't add the actions initially if the service isn't there TableService tableService = tool.getService(TableService.class); @@ -1001,8 +1018,8 @@ public class CodeBrowserPlugin extends Plugin public boolean goToField(Address a, String fieldName, int occurrence, int row, int col, boolean scroll) { - boolean result = SystemUtilities - .runSwingNow(() -> doGoToField(a, fieldName, occurrence, row, col, scroll)); + boolean result = SystemUtilities.runSwingNow( + () -> doGoToField(a, fieldName, occurrence, row, col, scroll)); return result; } diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java index 00d4d5ddf3..38885a27db 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java @@ -15,7 +15,7 @@ */ package docking.widgets.fieldpanel; -import static docking.widgets.EventTrigger.INTERNAL_ONLY; +import static docking.widgets.EventTrigger.*; import java.awt.*; import java.awt.event.*; @@ -58,6 +58,7 @@ public class FieldPanel extends JPanel private KeyHandler keyHandler = new KeyHandler(); private HoverHandler hoverHandler; private SelectionHandler selectionHandler = new SelectionHandler(); + private boolean horizontalScrollingEnabled = true; private FieldLocation cursorPosition = new FieldLocation(); private FieldSelection selection = new FieldSelection(); @@ -335,6 +336,14 @@ public class FieldPanel extends JPanel cursorHandler.setBlinkCursor(blinkCursor); } + public void enableSelection(boolean b) { + selectionHandler.enableSelection(b); + } + + public void setHorizontalScrollingEnabled(boolean enabled) { + horizontalScrollingEnabled = enabled; + } + /** * Returns the default background color. */ @@ -1171,15 +1180,11 @@ public class FieldPanel extends JPanel private JViewport getViewport() { Container c = getParent(); - if (c == null) { - return null; - } - if (c instanceof JViewport) { - return (JViewport) c; - } - c = c.getParent(); - if (c instanceof JViewport) { - return (JViewport) c; + while (c != null) { + if (c instanceof JViewport) { + return (JViewport) c; + } + c = c.getParent(); } return null; } @@ -1429,13 +1434,8 @@ public class FieldPanel extends JPanel else { hoverHandler.stopHover(); - if (e.isShiftDown()) { - // horizontal scroll (only move viewport) - if (viewport != null) { - Point pos = viewport.getViewPosition(); - viewport.setViewPosition( - new Point(Math.max(0, pos.x + scrollAmount), pos.y)); - } + if (e.isShiftDown() && horizontalScrollingEnabled) { + scrollViewHorizontally(scrollAmount); } else { scrollView(scrollAmount); @@ -1443,6 +1443,19 @@ public class FieldPanel extends JPanel } e.consume(); } + + private void scrollViewHorizontally(int scrollAmount) { + + JViewport vp = getViewport(); + if (vp == null) { + // this will happen for Field Panels not placed inside of scroll panes + return; + } + + // horizontal scroll (only move viewport) + Point pos = vp.getViewPosition(); + vp.setViewPosition(new Point(Math.max(0, pos.x + scrollAmount), pos.y)); + } } public class MouseHandler implements ActionListener { @@ -2061,8 +2074,4 @@ public class FieldPanel extends JPanel } } } - - public void enableSelection(boolean b) { - selectionHandler.enableSelection(b); - } }<Shift> + +Press shift when using the mouse scroll wheel to perform + horizontal scrolling. This will only work when the horizontal scroll + bar is visible. + + + ++ ++ ++
++ + You can disable horizontal scrolling in the Listing (and all other + Field Panels) via the Tool Options at + Edit +
+ Tool Options... +
+ Listing Fields +
+ Mouse +
+ Horizontal Scrolling + + +