11/*******************************************************************************
2- * Copyright (c) 2006, 2019 IBM Corporation and others.
2+ * Copyright (c) 2006, 2026 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
@@ -423,6 +423,10 @@ private boolean containsLineDelimiter(String str) {
423423 private IPropertyChangeListener fPreferenceStorePropertyChangeListener ;
424424 private WhitespaceCharacterPainter fWhiteSpacePainter ;
425425
426+ private TextViewerAction contentAssistAction ;
427+
428+ private ActionHandler contentAssistActionHandler ;
429+
426430 @ Override
427431 public Control createControl (Composite parent ) {
428432
@@ -542,6 +546,8 @@ public void focusGained(FocusEvent e) {
542546
543547 updateAction (DETAIL_FIND_REPLACE_TEXT_ACTION );
544548 fHasFocus = true ;
549+ activateContentAssistHandler (contentAssistAction , contentAssistActionHandler );
550+
545551 }
546552
547553 @ Override
@@ -556,6 +562,7 @@ public void focusLost(FocusEvent e) {
556562
557563 getViewSite ().getActionBars ().updateActionBars ();
558564 fHasFocus = false ;
565+ deactivateContentAssistHandler ();
559566 }
560567 });
561568
@@ -591,18 +598,29 @@ public void focusLost(FocusEvent e) {
591598 * Creates the actions to add to the context menu
592599 */
593600 private void createActions () {
594- TextViewerAction textAction = new TextViewerAction (fSourceViewer , ISourceViewer .CONTENTASSIST_PROPOSALS );
595- textAction .setActionDefinitionId (ITextEditorActionDefinitionIds .CONTENT_ASSIST_PROPOSALS );
596- textAction .configureAction (DetailMessages .DefaultDetailPane_Co_ntent_Assist_3 , IInternalDebugCoreConstants .EMPTY_STRING ,IInternalDebugCoreConstants .EMPTY_STRING );
597- textAction .setImageDescriptor (DebugPluginImages .getImageDescriptor (IDebugUIConstants .IMG_ELCL_CONTENT_ASSIST ));
598- textAction .setDisabledImageDescriptor (DebugPluginImages .getImageDescriptor (IDebugUIConstants .IMG_DLCL_CONTENT_ASSIST ));
599- PlatformUI .getWorkbench ().getHelpSystem ().setHelp (textAction , IDebugHelpContextIds .DETAIL_PANE_CONTENT_ASSIST_ACTION );
600- ActionHandler actionHandler = new ActionHandler (textAction );
601- IHandlerService handlerService = getViewSite ().getService (IHandlerService .class );
602- fContentAssistActivation = handlerService .activateHandler (textAction .getActionDefinitionId (), actionHandler );
603- setAction (DETAIL_CONTENT_ASSIST_ACTION , textAction );
604-
605- textAction = new TextViewerAction (fSourceViewer , ITextOperationTarget .SELECT_ALL );
601+ contentAssistAction = new TextViewerAction (fSourceViewer , ISourceViewer .CONTENTASSIST_PROPOSALS );
602+
603+ contentAssistAction .setActionDefinitionId (ITextEditorActionDefinitionIds .CONTENT_ASSIST_PROPOSALS );
604+ contentAssistAction .configureAction (DetailMessages .DefaultDetailPane_Co_ntent_Assist_3 ,
605+ IInternalDebugCoreConstants .EMPTY_STRING , IInternalDebugCoreConstants .EMPTY_STRING );
606+ contentAssistAction
607+ .setImageDescriptor (DebugPluginImages .getImageDescriptor (IDebugUIConstants .IMG_ELCL_CONTENT_ASSIST ));
608+ contentAssistAction .setDisabledImageDescriptor (
609+ DebugPluginImages .getImageDescriptor (IDebugUIConstants .IMG_DLCL_CONTENT_ASSIST ));
610+ PlatformUI .getWorkbench ().getHelpSystem ().setHelp (contentAssistAction ,
611+ IDebugHelpContextIds .DETAIL_PANE_CONTENT_ASSIST_ACTION );
612+ contentAssistActionHandler = new ActionHandler (contentAssistAction );
613+ setAction (DETAIL_CONTENT_ASSIST_ACTION , contentAssistAction );
614+
615+ StyledText text = fSourceViewer .getTextWidget ();
616+
617+ text .addCaretListener (event -> {
618+ if (text .isFocusControl ()) {
619+ activateContentAssistHandler (contentAssistAction , contentAssistActionHandler );
620+ }
621+ });
622+
623+ TextViewerAction textAction = new TextViewerAction (fSourceViewer , ITextOperationTarget .SELECT_ALL );
606624 textAction .configureAction (DetailMessages .DefaultDetailPane_Select__All_5 , IInternalDebugCoreConstants .EMPTY_STRING ,IInternalDebugCoreConstants .EMPTY_STRING );
607625 textAction .setActionDefinitionId (IWorkbenchCommandConstants .EDIT_SELECT_ALL );
608626 PlatformUI .getWorkbench ().getHelpSystem ().setHelp (textAction , IDebugHelpContextIds .DETAIL_PANE_SELECT_ALL_ACTION );
@@ -650,10 +668,37 @@ private void createActions() {
650668 }
651669
652670 /**
653- * Create the context menu particular to the detail pane. Note that anyone
671+ * Activates the content assist handler for the specified viewer action.
672+ *
673+ * @param contAssistTextViewer the viewer action providing the action definition
674+ * ID
675+ * @param actionHandler the handler to activate
676+ */
677+ private void activateContentAssistHandler (TextViewerAction contAssistTextViewer , ActionHandler actionHandler ) {
678+ if (fContentAssistActivation == null ) {
679+ IHandlerService handlerService = getViewSite ().getService (IHandlerService .class );
680+ fContentAssistActivation = handlerService .activateHandler (contAssistTextViewer .getActionDefinitionId (),
681+ actionHandler );
682+ }
683+ }
684+
685+ /**
686+ * Deactivates the content assist handler.
687+ */
688+ private void deactivateContentAssistHandler () {
689+ if (fContentAssistActivation != null ) {
690+ IHandlerService handlerService = getViewSite ().getService (IHandlerService .class );
691+ handlerService .deactivateHandler (fContentAssistActivation );
692+ fContentAssistActivation = null ;
693+ }
694+ }
695+
696+ /**
697+ * Create the context menu particular to the detail pane. Note that anyone
654698 * wishing to contribute an action to this menu must use
655699 * <code>IDebugUIConstants.VARIABLE_VIEW_DETAIL_ID</code> as the
656700 * <code>targetID</code> in the extension XML.
701+ *
657702 * @param menuControl the control to create the context menu on
658703 */
659704 protected void createDetailContextMenu (Control menuControl ) {
0 commit comments