Skip to content

Commit

Permalink
Improve memory search results page
Browse files Browse the repository at this point in the history
The Memory Browser and Memory views will jump to the memory address after a user selects a value from the Memory Search Result list. If the views belong to the same tab group as the Search view, then it might not be very intuitive for the user to switch back to one of the Memory views and see the effect of the selection.

The current commit adds on the the double click listener(from MemorySearchResultsPage.java) the behavior to refocus on the Memory Browser/ Memory view.

Resolves: #515
  • Loading branch information
LizzMre committed Aug 18, 2023
1 parent a60e687 commit 79db048
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
Expand Down Expand Up @@ -176,42 +178,35 @@ public Object[] getElements(Object inputElement) {
public void selectionChanged(final SelectionChangedEvent event) {
IMemoryRenderingContainer containers[] = ((IMemorySearchQuery) fQuery).getMemoryView()
.getMemoryRenderingContainers();
if (containers == null || containers.length == 0)
return;
if (containers == null || containers.length == 0) return;

if (event.getSelection() instanceof StructuredSelection
&& ((StructuredSelection) event.getSelection()).getFirstElement() instanceof MemoryMatch) {
if (event.getSelection() instanceof StructuredSelection && ((StructuredSelection) event.getSelection())
.getFirstElement() instanceof MemoryMatch match) {

MemoryMatch match = (MemoryMatch) ((StructuredSelection) event.getSelection()).getFirstElement();
if (match == null)
return;
if (match == null) return;

for (int i = 0; i < containers.length; i++) {
IMemoryRendering rendering = containers[i].getActiveRendering();
if (rendering == null || !(rendering instanceof IRepositionableMemoryRendering))
continue;
if (!(rendering instanceof IRepositionableMemoryRendering repositionable)) continue;

try {
((IRepositionableMemoryRendering) rendering).goToAddress(match.getStartAddress());
repositionable.goToAddress(match.getStartAddress());
} catch (DebugException e) {
MemorySearchPlugin.logError(
Messages.getString("MemorySearchResultsPage.RepositioningMemoryViewFailed"), //$NON-NLS-1$
e);
}

// Open the memory view to emphasize the effect of the address selection in the search view
IWorkbenchPart wb = containers[i].getMemoryRenderingSite().getSite().getPart();
if (wb == null)
continue;

getSite().getPage().activate(wb);

// Temporary, until platform accepts/adds new interface for setting the selection
try {
Method m = rendering.getClass().getMethod("setSelection", //$NON-NLS-1$
new Class[] { BigInteger.class, BigInteger.class });
if (m != null)
m.invoke(rendering, match.getStartAddress(), match.getEndAddress());
} catch (NoSuchMethodException e) {
// Not all renderings have a compatible setSelection
// ideally this would be an interface we can check instead
// of using reflection!
} catch (Exception e) {
MemorySearchPlugin.logError(
"Exception while invoking the setSelection method for the current rendering", //$NON-NLS-1$
Expand All @@ -221,6 +216,20 @@ public void selectionChanged(final SelectionChangedEvent event) {
}
}
});
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

@Override
public void doubleClick(DoubleClickEvent event) {
// Open the memory view to emphasize the effect of the memory address selection in the search
if (event.getSelection() instanceof StructuredSelection
&& ((StructuredSelection) event.getSelection()).getFirstElement() instanceof MemoryMatch) {
IWorkbenchPart wb = ((IMemorySearchQuery) fQuery).getMemoryView().getSite().getPart();
if (wb == null) return;
getSite().getPage().activate(wb);
}
}

});

fTreeViewer.setLabelProvider(new ILabelProvider() {

Expand Down

0 comments on commit 79db048

Please sign in to comment.