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 memory address selection event (from MemorySearchResultsPage.java) the possibility to refocus on the Memory Browser/ Memory view.

Resolves: #515
  • Loading branch information
LizzMre committed Aug 17, 2023
1 parent abad4e0 commit 3c792b1
Showing 1 changed file with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.Page;

public class MemorySearchResultsPage extends Page implements ISearchResultPage, IQueryListener {
Expand Down Expand Up @@ -173,34 +174,48 @@ public Object[] getElements(Object inputElement) {

@Override
public void selectionChanged(final SelectionChangedEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
IMemoryRenderingContainer containers[] = ((IMemorySearchQuery) fQuery).getMemoryView()
.getMemoryRenderingContainers();
IMemoryRenderingContainer containers[] = ((IMemorySearchQuery) fQuery).getMemoryView()
.getMemoryRenderingContainers();
if (containers == null || containers.length == 0)
return;

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

MemoryMatch match = (MemoryMatch) ((StructuredSelection) event.getSelection()).getFirstElement();
if (match != null) {
for (int i = 0; i < containers.length; i++) {
IMemoryRendering rendering = containers[i].getActiveRendering();
if (rendering instanceof IRepositionableMemoryRendering) {
try {
((IRepositionableMemoryRendering) rendering).goToAddress(match.getStartAddress());
} catch (DebugException e) {
MemorySearchPlugin.logError(
Messages.getString("MemorySearchResultsPage.RepositioningMemoryViewFailed"), //$NON-NLS-1$
e);
}
}

if (rendering != null) {
// 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 (Exception e) {
// do nothing
}
}
if (match == null)
return;

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

try {
((IRepositionableMemoryRendering) rendering).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 (Exception e) {
MemorySearchPlugin.logError(
"Exception while invoking the setSelection method for the current rendering", //$NON-NLS-1$
e);
}
}
}
Expand Down Expand Up @@ -297,4 +312,4 @@ public void setActionBars(IActionBars actionBars) {
@Override
public void setFocus() {
}
}
}

0 comments on commit 3c792b1

Please sign in to comment.