diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/fieldassist/ContentProposalAdapter.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/fieldassist/ContentProposalAdapter.java index b7640f92216..33b8386071e 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/fieldassist/ContentProposalAdapter.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/fieldassist/ContentProposalAdapter.java @@ -1732,7 +1732,7 @@ public void handleEvent(Event e) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; - openProposalPopup(false); + openProposalPopup0(false); return; } } @@ -1874,7 +1874,7 @@ private String hex(int i) { * a boolean indicating whether the popup was autoactivated. If * false, a beep will sound when no proposals can be shown. */ - private void openProposalPopup(boolean autoActivated) { + private void openProposalPopup0(boolean autoActivated) { if (isValid()) { if (popup == null) { // Check whether there are any proposals to be shown. @@ -1910,7 +1910,22 @@ private void openProposalPopup(boolean autoActivated) { * @since 3.22 */ public void openProposalPopup() { - openProposalPopup(false); + openProposalPopup(true); + } + + /** + * Open the proposal popup and display the proposals provided by the proposal + * provider. This method returns immediately. That is, it does not wait for a + * proposal to be selected. This method is used to explicitly invoke the opening + * of the popup. If there are no proposals to show, the popup will not open. If + * {@code beep} is true, a beep will be sounded when there are no proposals. + * + * @param beep + * a boolean indicating whether to beep if no proposals can be shown + * @since 3.23 + */ + public void openProposalPopup(boolean beep) { + openProposalPopup0(!beep); } /** @@ -2052,7 +2067,7 @@ private void autoActivate() { if (!isValid() || receivedKeyDown) { return; } - getControl().getDisplay().syncExec(() -> openProposalPopup(true)); + getControl().getDisplay().syncExec(() -> openProposalPopup0(true)); }; Thread t = new Thread(runnable); t.start(); @@ -2065,7 +2080,7 @@ private void autoActivate() { // event occurring. getControl().getDisplay().asyncExec(() -> { if (isValid()) { - openProposalPopup(true); + openProposalPopup0(true); } }); } diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java index d28a45f7067..eeb5f19285d 100644 --- a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertTrue; import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalProvider; import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; import org.eclipse.jface.fieldassist.TextContentAdapter; @@ -236,4 +237,31 @@ private void assertOneShellUp() { assertEquals("There should only be one shell up, the dialog", originalShellCount + 1, text.getDisplay().getShells().length); } + + /** + * Test that openProposalPopup(boolean beep) method is available and can be called + * to suppress the beep. This test verifies that the method accepts both true and false + * for the beep parameter. + */ + @Test + public void testOpenProposalPopupWithBeepParameter() { + // Create an adapter with an empty proposal provider to test the beep control + ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), + (contents, position) -> new IContentProposal[0], null, null); + + // Test calling with beep=false (should not beep) + adapter.openProposalPopup(false); + spinEventLoop(); + assertOneShellUp(); // No popup should open since there are no proposals + + // Test calling with beep=true (would beep, but we can't test the sound) + adapter.openProposalPopup(true); + spinEventLoop(); + assertOneShellUp(); // No popup should open since there are no proposals + + // Verify the parameterless method still works (should beep by default) + adapter.openProposalPopup(); + spinEventLoop(); + assertOneShellUp(); // No popup should open since there are no proposals + } }