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,15 +523,15 @@ 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 )
@@ -547,7 +540,7 @@ private void createSearchTools() {
547540
548541 FindReplaceOverlayAction selectAllAction = new FindReplaceOverlayAction (this ::performSelectAll );
549542 selectAllAction .addShortcuts (KeyboardShortcuts .SEARCH_ALL );
550- searchActions . add (selectAllAction );
543+ commandSupport . registerSearchAction (selectAllAction );
551544 selectAllButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .PUSH )
552545 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_SEARCH_ALL ))
553546 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_searchAllButton_toolTip )
@@ -560,7 +553,7 @@ private void createCloseTools() {
560553
561554 FindReplaceOverlayAction closeAction = new FindReplaceOverlayAction (this ::close );
562555 closeAction .addShortcuts (KeyboardShortcuts .CLOSE );
563- commonActions . add (closeAction );
556+ commandSupport . registerCommonAction (closeAction );
564557
565558 // Close button
566559 new AccessibleToolItemBuilder (closeTools ).withStyleBits (SWT .PUSH )
@@ -573,7 +566,7 @@ private void createAreaSearchButton() {
573566 FindReplaceOverlaySearchOptionAction searchInSelectionAction = new FindReplaceOverlaySearchOptionAction (SearchOptions .GLOBAL , findReplaceLogic );
574567 searchInSelectionAction .addExecutionListener (this ::updateIncrementalSearch );
575568 searchInSelectionAction .addShortcuts (KeyboardShortcuts .OPTION_SEARCH_IN_SELECTION );
576- commonActions . add (searchInSelectionAction );
569+ commandSupport . registerCommonAction (searchInSelectionAction );
577570 searchInSelectionButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
578571 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_SEARCH_IN_AREA ))
579572 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_searchInSelectionButton_toolTip )
@@ -585,7 +578,7 @@ private void createRegexSearchButton() {
585578 findReplaceLogic );
586579 regexAction .addExecutionListener (this ::updateIncrementalSearch );
587580 regexAction .addShortcuts (KeyboardShortcuts .OPTION_REGEX );
588- commonActions . add (regexAction );
581+ commandSupport . registerCommonAction (regexAction );
589582 regexSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
590583 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_FIND_REGEX ))
591584 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_regexSearchButton_toolTip )
@@ -601,7 +594,7 @@ private void createCaseSensitiveButton() {
601594 SearchOptions .CASE_SENSITIVE , findReplaceLogic );
602595 caseSensitiveAction .addExecutionListener (this ::updateIncrementalSearch );
603596 caseSensitiveAction .addShortcuts (KeyboardShortcuts .OPTION_CASE_SENSITIVE );
604- commonActions . add (caseSensitiveAction );
597+ commandSupport . registerCommonAction (caseSensitiveAction );
605598 caseSensitiveSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
606599 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_CASE_SENSITIVE ))
607600 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_caseSensitiveButton_toolTip )
@@ -613,7 +606,7 @@ private void createWholeWordsButton() {
613606 SearchOptions .WHOLE_WORD , findReplaceLogic );
614607 wholeWordAction .addExecutionListener (this ::updateIncrementalSearch );
615608 wholeWordAction .addShortcuts (KeyboardShortcuts .OPTION_WHOLE_WORD );
616- commonActions . add (wholeWordAction );
609+ commandSupport . registerCommonAction (wholeWordAction );
617610 wholeWordSearchButton = new AccessibleToolItemBuilder (searchTools ).withStyleBits (SWT .CHECK )
618611 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_WHOLE_WORD ))
619612 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_wholeWordsButton_toolTip )
@@ -634,7 +627,7 @@ private void createReplaceTools() {
634627 performSingleReplace ();
635628 });
636629 replaceAction .addShortcuts (KeyboardShortcuts .SEARCH_FORWARD );
637- replaceActions . add (replaceAction );
630+ commandSupport . registerReplaceAction (replaceAction );
638631 replaceButton = new AccessibleToolItemBuilder (replaceTools ).withStyleBits (SWT .PUSH )
639632 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_REPLACE ))
640633 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceButton_toolTip )
@@ -648,7 +641,7 @@ private void createReplaceTools() {
648641 performReplaceAll ();
649642 });
650643 replaceAllAction .addShortcuts (KeyboardShortcuts .SEARCH_ALL );
651- replaceActions . add (replaceAllAction );
644+ commandSupport . registerReplaceAction (replaceAllAction );
652645 replaceAllButton = new AccessibleToolItemBuilder (replaceTools ).withStyleBits (SWT .PUSH )
653646 .withImage (FindReplaceOverlayImages .get (FindReplaceOverlayImages .KEY_REPLACE_ALL ))
654647 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceAllButton_toolTip )
@@ -754,6 +747,7 @@ private void hideReplace() {
754747 return ;
755748 }
756749 customFocusOrder .dispose ();
750+ commandSupport .unregisterReplaceActions ();
757751 searchBar .forceFocus ();
758752 contentAssistReplaceField = null ;
759753 replaceBarOpen = false ;
@@ -776,8 +770,8 @@ private void createReplaceDialog() {
776770 }
777771
778772 private void initializeReplaceShortcutHandlers () {
779- registerActionShortcutsAtControl ( commonActions , replaceBar );
780- registerActionShortcutsAtControl ( replaceActions , replaceBar );
773+ commandSupport . registerCommonActionShortcutsAtControl ( replaceBar );
774+ commandSupport . registerReplaceActionShortcutsAtControl ( replaceBar );
781775 }
782776
783777 private void enableSearchTools (boolean enable ) {
0 commit comments