1313 *******************************************************************************/
1414package org .eclipse .ui .internal .findandreplace .overlay ;
1515
16- import java .util .ArrayList ;
1716import java .util .List ;
1817import java .util .concurrent .atomic .AtomicReference ;
1918
@@ -136,10 +135,6 @@ private static final class KeyboardShortcuts {
136135 private ToolItem replaceButton ;
137136 private ToolItem replaceAllButton ;
138137
139- private final List <FindReplaceOverlayAction > commonActions = new ArrayList <>();
140- private final List <FindReplaceOverlayAction > searchActions = new ArrayList <>();
141- private final List <FindReplaceOverlayAction > replaceActions = new ArrayList <>();
142-
143138 private Color widgetBackgroundColor ;
144139 private Color overlayBackgroundColor ;
145140 private Color normalTextForegroundColor ;
@@ -154,12 +149,16 @@ private static final class KeyboardShortcuts {
154149 private final FocusListener targetActionActivationHandling = new FocusListener () {
155150 @ Override
156151 public void focusGained (FocusEvent e ) {
157- commandSupport .overlayActivated ();
152+ if (e .widget == searchBar .getTextBar ()) {
153+ commandSupport .searchBarActivated ();
154+ } else if (replaceBar != null && e .widget == replaceBar .getTextBar ()) {
155+ commandSupport .replaceBarActivated ();
156+ }
158157 }
159158
160159 @ Override
161160 public void focusLost (FocusEvent e ) {
162- commandSupport .overlayDeactivated ();
161+ commandSupport .searchOrReplaceBarDeactivated ();
163162 }
164163 };
165164
@@ -415,14 +414,8 @@ private void createContainerAndSearchControls(Composite parent) {
415414 }
416415
417416 private void initializeSearchShortcutHandlers () {
418- registerActionShortcutsAtControl (commonActions , searchBar );
419- registerActionShortcutsAtControl (searchActions , searchBar );
420- }
421-
422- private void registerActionShortcutsAtControl (List <FindReplaceOverlayAction > actions , Control control ) {
423- for (FindReplaceOverlayAction action : actions ) {
424- FindReplaceShortcutUtil .registerActionShortcutsAtControl (action , control );
425- }
417+ commandSupport .registerCommonActionShortcutsAtControl (searchBar );
418+ commandSupport .registerSearchActionShortcutsAtControl (searchBar );
426419 }
427420
428421 /**
@@ -498,7 +491,7 @@ private void createReplaceToggle() {
498491
499492 FindReplaceOverlayAction replaceToggleAction = new FindReplaceOverlayAction (() -> setReplaceVisible (!replaceBarOpen ));
500493 replaceToggleAction .addShortcuts (KeyboardShortcuts .TOGGLE_REPLACE );
501- commonActions . add (replaceToggleAction );
494+ commandSupport . registerCommonAction (replaceToggleAction );
502495
503496 replaceToggle = new AccessibleToolItemBuilder (replaceToggleTools )
504497 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_OPEN_REPLACE_AREA ))
@@ -530,23 +523,23 @@ private void createSearchTools() {
530523
531524 FindReplaceOverlayAction searchBackwardAction = new FindReplaceOverlayAction (() -> performSearch (false ));
532525 searchBackwardAction .addShortcuts (KeyboardShortcuts .SEARCH_BACKWARD );
533- searchActions . add (searchBackwardAction );
526+ commandSupport . registerSearchAction (searchBackwardAction );
534527 searchBackwardButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .PUSH )
535528 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_FIND_PREV ))
536529 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_upSearchButton_toolTip )
537530 .withAction (searchBackwardAction ).build ();
538531
539532 FindReplaceOverlayAction searchForwardAction = new FindReplaceOverlayAction (() -> performSearch (true ));
540533 searchForwardAction .addShortcuts (KeyboardShortcuts .SEARCH_FORWARD );
541- searchActions . add (searchForwardAction );
534+ commandSupport . registerSearchAction (searchForwardAction );
542535 searchForwardButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .PUSH )
543536 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_FIND_NEXT ))
544537 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_downSearchButton_toolTip )
545538 .withAction (searchForwardAction ).build ();
546539
547540 FindReplaceOverlayAction selectAllAction = new FindReplaceOverlayAction (this ::performSelectAll );
548541 selectAllAction .addShortcuts (KeyboardShortcuts .SEARCH_ALL );
549- searchActions . add (selectAllAction );
542+ commandSupport . registerSearchAction (selectAllAction );
550543 selectAllButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .PUSH )
551544 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_SEARCH_ALL ))
552545 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_searchAllButton_toolTip )
@@ -559,7 +552,7 @@ private void createCloseTools() {
559552
560553 FindReplaceOverlayAction closeAction = new FindReplaceOverlayAction (this ::close );
561554 closeAction .addShortcuts (KeyboardShortcuts .CLOSE );
562- commonActions . add (closeAction );
555+ commandSupport . registerCommonAction (closeAction );
563556
564557 // Close button
565558 new AccessibleToolItemBuilder (closeTools ).withStyleBits (SWT .PUSH )
@@ -572,7 +565,7 @@ private void createAreaSearchButton() {
572565 FindReplaceOverlaySearchOptionAction searchInSelectionAction = new FindReplaceOverlaySearchOptionAction (SearchOptions .GLOBAL , findReplaceLogic );
573566 searchInSelectionAction .addExecutionListener (this ::updateIncrementalSearch );
574567 searchInSelectionAction .addShortcuts (KeyboardShortcuts .OPTION_SEARCH_IN_SELECTION );
575- commonActions . add (searchInSelectionAction );
568+ commandSupport . registerCommonAction (searchInSelectionAction );
576569 searchInSelectionButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
577570 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_SEARCH_IN_AREA ))
578571 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_searchInSelectionButton_toolTip )
@@ -584,7 +577,7 @@ private void createRegexSearchButton() {
584577 findReplaceLogic );
585578 regexAction .addExecutionListener (this ::updateIncrementalSearch );
586579 regexAction .addShortcuts (KeyboardShortcuts .OPTION_REGEX );
587- commonActions . add (regexAction );
580+ commandSupport . registerCommonAction (regexAction );
588581 regexSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
589582 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_FIND_REGEX ))
590583 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_regexSearchButton_toolTip )
@@ -600,7 +593,7 @@ private void createCaseSensitiveButton() {
600593 SearchOptions .CASE_SENSITIVE , findReplaceLogic );
601594 caseSensitiveAction .addExecutionListener (this ::updateIncrementalSearch );
602595 caseSensitiveAction .addShortcuts (KeyboardShortcuts .OPTION_CASE_SENSITIVE );
603- commonActions . add (caseSensitiveAction );
596+ commandSupport . registerCommonAction (caseSensitiveAction );
604597 caseSensitiveSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
605598 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_CASE_SENSITIVE ))
606599 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_caseSensitiveButton_toolTip )
@@ -612,7 +605,7 @@ private void createWholeWordsButton() {
612605 SearchOptions .WHOLE_WORD , findReplaceLogic );
613606 wholeWordAction .addExecutionListener (this ::updateIncrementalSearch );
614607 wholeWordAction .addShortcuts (KeyboardShortcuts .OPTION_WHOLE_WORD );
615- commonActions . add (wholeWordAction );
608+ commandSupport . registerCommonAction (wholeWordAction );
616609 wholeWordSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
617610 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_WHOLE_WORD ))
618611 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_wholeWordsButton_toolTip )
@@ -633,7 +626,7 @@ private void createReplaceTools() {
633626 performSingleReplace ();
634627 });
635628 replaceAction .addShortcuts (KeyboardShortcuts .SEARCH_FORWARD );
636- replaceActions . add (replaceAction );
629+ commandSupport . registerReplaceAction (replaceAction );
637630 replaceButton = new AccessibleToolItemBuilder (replaceTools ).withStyleBits (SWT .PUSH )
638631 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_REPLACE ))
639632 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceButton_toolTip )
@@ -647,7 +640,7 @@ private void createReplaceTools() {
647640 performReplaceAll ();
648641 });
649642 replaceAllAction .addShortcuts (KeyboardShortcuts .SEARCH_ALL );
650- replaceActions . add (replaceAllAction );
643+ commandSupport . registerReplaceAction (replaceAllAction );
651644 replaceAllButton = new AccessibleToolItemBuilder (replaceTools ).withStyleBits (SWT .PUSH )
652645 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_REPLACE_ALL ))
653646 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceAllButton_toolTip )
@@ -753,6 +746,7 @@ private void hideReplace() {
753746 return ;
754747 }
755748 customFocusOrder .dispose ();
749+ commandSupport .unregisterReplaceActions ();
756750 searchBar .forceFocus ();
757751 contentAssistReplaceField = null ;
758752 replaceBarOpen = false ;
@@ -775,8 +769,8 @@ private void createReplaceDialog() {
775769 }
776770
777771 private void initializeReplaceShortcutHandlers () {
778- registerActionShortcutsAtControl ( commonActions , replaceBar );
779- registerActionShortcutsAtControl ( replaceActions , replaceBar );
772+ commandSupport . registerCommonActionShortcutsAtControl ( replaceBar );
773+ commandSupport . registerReplaceActionShortcutsAtControl ( replaceBar );
780774 }
781775
782776 private void enableSearchTools (boolean enable ) {
0 commit comments