|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2006, 2019 IBM Corporation and others. |
| 2 | + * Copyright (c) 2006, 2025 IBM Corporation and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials |
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0 |
|
82 | 82 | import org.eclipse.swt.custom.StyledText; |
83 | 83 | import org.eclipse.swt.events.FocusAdapter; |
84 | 84 | import org.eclipse.swt.events.FocusEvent; |
| 85 | +import org.eclipse.swt.events.FocusListener; |
85 | 86 | import org.eclipse.swt.events.KeyEvent; |
86 | 87 | import org.eclipse.swt.events.KeyListener; |
87 | 88 | import org.eclipse.swt.events.MouseEvent; |
@@ -591,18 +592,46 @@ public void focusLost(FocusEvent e) { |
591 | 592 | * Creates the actions to add to the context menu |
592 | 593 | */ |
593 | 594 | 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); |
| 595 | + TextViewerAction contAssistTextViewer = new TextViewerAction(fSourceViewer, ISourceViewer.CONTENTASSIST_PROPOSALS); |
| 596 | + |
| 597 | + contAssistTextViewer.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); |
| 598 | + contAssistTextViewer.configureAction(DetailMessages.DefaultDetailPane_Co_ntent_Assist_3, |
| 599 | + IInternalDebugCoreConstants.EMPTY_STRING, IInternalDebugCoreConstants.EMPTY_STRING); |
| 600 | + contAssistTextViewer.setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_ELCL_CONTENT_ASSIST)); |
| 601 | + contAssistTextViewer.setDisabledImageDescriptor( |
| 602 | + DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_DLCL_CONTENT_ASSIST)); |
| 603 | + PlatformUI.getWorkbench().getHelpSystem().setHelp(contAssistTextViewer, |
| 604 | + IDebugHelpContextIds.DETAIL_PANE_CONTENT_ASSIST_ACTION); |
| 605 | + ActionHandler actionHandler = new ActionHandler(contAssistTextViewer); |
| 606 | + setAction(DETAIL_CONTENT_ASSIST_ACTION, contAssistTextViewer); |
| 607 | + |
| 608 | + StyledText text = fSourceViewer.getTextWidget(); |
| 609 | + |
| 610 | + text.addCaretListener(event -> { |
| 611 | + if (text.isFocusControl()) { |
| 612 | + if (fContentAssistActivation == null) { |
| 613 | + IHandlerService handlerService = getViewSite().getService(IHandlerService.class); |
| 614 | + fContentAssistActivation = handlerService.activateHandler(contAssistTextViewer.getActionDefinitionId(), |
| 615 | + actionHandler); |
| 616 | + } |
| 617 | + } |
| 618 | + }); |
| 619 | + |
| 620 | + text.addFocusListener(new FocusListener() { |
| 621 | + @Override |
| 622 | + public void focusLost(FocusEvent e) { |
| 623 | + if (fContentAssistActivation != null) { |
| 624 | + IHandlerService handlerService = getViewSite().getService(IHandlerService.class); |
| 625 | + handlerService.deactivateHandler(fContentAssistActivation); |
| 626 | + fContentAssistActivation = null; |
| 627 | + } |
| 628 | + } |
| 629 | + @Override |
| 630 | + public void focusGained(FocusEvent e) { |
| 631 | + } |
| 632 | + }); |
| 633 | + |
| 634 | + TextViewerAction textAction = new TextViewerAction(fSourceViewer, ITextOperationTarget.SELECT_ALL); |
606 | 635 | textAction.configureAction(DetailMessages.DefaultDetailPane_Select__All_5, IInternalDebugCoreConstants.EMPTY_STRING,IInternalDebugCoreConstants.EMPTY_STRING); |
607 | 636 | textAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_SELECT_ALL); |
608 | 637 | PlatformUI.getWorkbench().getHelpSystem().setHelp(textAction, IDebugHelpContextIds.DETAIL_PANE_SELECT_ALL_ACTION); |
|
0 commit comments