Merge remote-tracking branch 'origin/GP-5228_James_show_num_omitted_entries--SQUASHED'

This commit is contained in:
Ryan Kurtz
2025-01-03 19:59:27 -05:00
2 changed files with 34 additions and 8 deletions

View File

@@ -4,9 +4,9 @@
* 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.
@@ -118,6 +118,7 @@ public class SourceMapFieldFactory extends FieldFactory {
entriesToShow = entriesStartingWithinCu;
}
int entriesShown = 0;
for (SourceMapEntry entry : entriesToShow) {
StringBuilder sb = new StringBuilder();
if (showOnlyFileNames) {
@@ -149,10 +150,23 @@ public class SourceMapFieldFactory extends FieldFactory {
entry.getBaseAddress().compareTo(cuAddr) <= 0 ? Palette.BLACK : OFFCUT_COLOR;
AttributedString attrString = new AttributedString(sb.toString(), color, getMetrics());
fieldElements.add(new TextFieldElement(attrString, 0, 0));
entriesShown++;
if (entriesShown == maxEntries) {
int entriesLeft = entriesToShow.size() - maxEntries;
if (entriesLeft == 0) {
break;
}
String singularOrPlural = entriesLeft == 1 ? " entry " : " entries ";
AttributedString truncatedMessage = new AttributedString(
"-- " + entriesLeft + singularOrPlural + "omitted --",
OFFCUT_COLOR, getMetrics());
fieldElements.add(new TextFieldElement(truncatedMessage, 0, 0));
break;
}
}
return ListingTextField.createMultilineTextField(this, obj, fieldElements,
startX + varWidth, width, maxEntries, hlProvider);
startX + varWidth, width, maxEntries + 1, hlProvider);
}
@Override

View File

@@ -4,9 +4,9 @@
* 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.
@@ -179,20 +179,32 @@ public class SourceMapFieldFactoryTest extends AbstractGhidraHeadedIntegrationTe
try {
sourceManager.addSourceMapEntry(source1, 1, entryPoint, 1);
sourceManager.addSourceMapEntry(source2, 2, entryPoint, 1);
sourceManager.addSourceMapEntry(source2, 22, entryPoint, 1);
}
finally {
program.endTransaction(txID, true);
}
ListingTextField textField = getTextField(entryPoint);
assertEquals(2, textField.getNumRows());
assertEquals(3, textField.getNumRows());
SwingUtilities.invokeAndWait(() -> fieldOptions
runSwing(() -> fieldOptions
.setInt(SourceMapFieldFactory.MAX_ENTRIES_PER_ADDRESS_OPTION_NAME, 2));
waitForSwing();
cb.updateNow();
textField = getTextField(entryPoint);
assertEquals(3, textField.getNumRows());
assertTrue(textField.getText().contains("-- 1 entry omitted --"));
runSwing(() -> fieldOptions
.setInt(SourceMapFieldFactory.MAX_ENTRIES_PER_ADDRESS_OPTION_NAME, 1));
waitForSwing();
cb.updateNow();
textField = getTextField(entryPoint);
assertEquals(1, textField.getNumRows());
assertEquals(2, textField.getNumRows());
assertTrue(textField.getText().contains("-- 2 entries omitted --"));
}
@Test