Bug 45017 - Enable Find Next, Find Previous in console

Provide actions for commands org.eclipse.ui.edit.findNext,
org.eclipse.ui.edit.findPrevious in text consoles.

Change-Id: Id4589100923241b85dc19c6d5afc3e33518ced9a
Signed-off-by: Christian Gabrisch <eclipse@cgabrisch.de>
diff --git a/org.eclipse.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.debug.tests/META-INF/MANIFEST.MF
index 6e30698..fe2881f 100644
--- a/org.eclipse.debug.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.debug.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.debug.tests;singleton:=true
-Bundle-Version: 3.12.0.qualifier
+Bundle-Version: 3.12.100.qualifier
 Bundle-Activator: org.eclipse.debug.tests.TestsPlugin
 Bundle-Localization: plugin
 Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
@@ -15,7 +15,8 @@
  org.eclipse.debug.core;bundle-version="[3.9.0,4.0.0)",
  org.eclipse.ui.externaltools;bundle-version="[3.3.0,4.0.0)",
  org.eclipse.ui.console;bundle-version="[3.7.0,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)"
+ org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
+ org.eclipse.ui.workbench.texteditor;bundle-version="[3.15.100,4.0.0)"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Bundle-Vendor: %providerName
diff --git a/org.eclipse.debug.tests/pom.xml b/org.eclipse.debug.tests/pom.xml
index ecd5d51..866d56d 100644
--- a/org.eclipse.debug.tests/pom.xml
+++ b/org.eclipse.debug.tests/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.debug</groupId>
   <artifactId>org.eclipse.debug.tests</artifactId>
-  <version>3.12.0-SNAPSHOT</version>
+  <version>3.12.100-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
   <properties>
     <code.ignoredWarnings>${tests.ignoredWarnings}</code.ignoredWarnings>
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
index 289efb7..a35d4d3 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2017, 2019 Andreas Loth and others.
+ * Copyright (c) 2017, 2020 Andreas Loth and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -38,6 +38,7 @@
 import org.eclipse.ui.console.IOConsole;
 import org.eclipse.ui.console.IOConsoleOutputStream;
 import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
 import org.junit.Test;
 
 
@@ -160,14 +161,14 @@
 	}
 
 	/**
-	 * Validate that we can use find and replace after opening a console in the
-	 * Console View.
+	 * Validate that we can use commands findReplace, findNext and findPrevious
+	 * after opening a console in the Console View.
 	 *
 	 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=268608">bug
 	 *      268608</a>
 	 */
 	@Test
-	public void testFindReplaceIsEnabledOnConsoleOpen() throws Exception {
+	public void testFindCommandsAreEnabledOnConsoleOpen() throws Exception {
 		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 		IViewPart consoleView = activePage.showView(IConsoleConstants.ID_CONSOLE_VIEW);
 
@@ -183,8 +184,12 @@
 			TestUtil.waitForJobs(name.getMethodName(), 100, 3000);
 
 			ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
-			Command command = commandService.getCommand(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE);
-			assertTrue("expected FindReplace command to be enabled after opening console", command.isEnabled());
+			Command commandFindReplace = commandService.getCommand(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE);
+			assertTrue("expected FindReplace command to be enabled after opening console", commandFindReplace.isEnabled());
+			Command commandFindNext = commandService.getCommand(IWorkbenchActionDefinitionIds.FIND_NEXT);
+			assertTrue("expected FindNext command to be enabled after opening console", commandFindNext.isEnabled());
+			Command commandFindPrevious = commandService.getCommand(IWorkbenchActionDefinitionIds.FIND_PREVIOUS);
+			assertTrue("expected FindPrevious command to be enabled after opening console", commandFindPrevious.isEnabled());
 		} finally {
 			consoleManager.removeConsoles(consoles);
 			activePage.hideView(consoleView);
diff --git a/org.eclipse.ui.console/META-INF/MANIFEST.MF b/org.eclipse.ui.console/META-INF/MANIFEST.MF
index 2de8914..cdf0ffb 100644
--- a/org.eclipse.ui.console/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.console/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.ui.console; singleton:=true
-Bundle-Version: 3.10.0.qualifier
+Bundle-Version: 3.10.100.qualifier
 Bundle-Activator: org.eclipse.ui.console.ConsolePlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/TextConsolePage.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/TextConsolePage.java
index f23572e..8483e9d 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/TextConsolePage.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/TextConsolePage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -18,7 +18,9 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.ResourceBundle;
+import java.util.stream.Stream;
 
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.action.IAction;
@@ -52,8 +54,11 @@
 import org.eclipse.ui.internal.console.IConsoleHelpContextIds;
 import org.eclipse.ui.part.IPageBookViewPage;
 import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.texteditor.FindNextAction;
 import org.eclipse.ui.texteditor.FindReplaceAction;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.ui.texteditor.IUpdate;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
 
 /**
  * A page for a text console.
@@ -82,12 +87,12 @@
 	// text selection listener, used to update selection dependent actions on selection changes
 	private ISelectionChangedListener selectionChangedListener =  event -> updateSelectionDependentActions();
 
-	// updates the find replace action and the clear action if the document length is > 0
+	// updates the find actions and the clear action if the document length is > 0
 	private ITextListener textListener = event -> {
-		IUpdate findReplace = (IUpdate)fGlobalActions.get(ActionFactory.FIND.getId());
-		if (findReplace != null) {
-			findReplace.update();
-		}
+		Stream.of(ActionFactory.FIND.getId(), ITextEditorActionConstants.FIND_NEXT,
+				ITextEditorActionConstants.FIND_PREVIOUS)
+				.map(id -> fGlobalActions.get(id)).filter(Objects::nonNull).map(IUpdate.class::cast)
+				.forEach(IUpdate::update);
 
 		if (fClearOutputAction != null) {
 			IDocument doc = fViewer.getDocument();
@@ -262,10 +267,23 @@
 		PlatformUI.getWorkbench().getHelpSystem().setHelp(fraction, IConsoleHelpContextIds.CONSOLE_FIND_REPLACE_ACTION);
 		setGlobalAction(actionBars, ActionFactory.FIND.getId(), fraction);
 
+		FindNextAction findNextAction = new FindNextAction(bundle, "find_next_action_", fConsoleView, true); //$NON-NLS-1$
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(findNextAction, IConsoleHelpContextIds.CONSOLE_FIND_NEXT_ACTION);
+		findNextAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_NEXT);
+		setGlobalAction(actionBars, ITextEditorActionConstants.FIND_NEXT, findNextAction);
+
+		FindNextAction findPreviousAction = new FindNextAction(bundle, "find_previous_action_", fConsoleView, false); //$NON-NLS-1$
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(findPreviousAction,
+				IConsoleHelpContextIds.CONSOLE_FIND_PREVIOUS_ACTION);
+		findPreviousAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_PREVIOUS);
+		setGlobalAction(actionBars, ITextEditorActionConstants.FIND_PREVIOUS, findPreviousAction);
+
 		fSelectionActions.add(ActionFactory.CUT.getId());
 		fSelectionActions.add(ActionFactory.COPY.getId());
 		fSelectionActions.add(ActionFactory.PASTE.getId());
 		fSelectionActions.add(ActionFactory.FIND.getId());
+		fSelectionActions.add(ITextEditorActionConstants.FIND_NEXT);
+		fSelectionActions.add(ITextEditorActionConstants.FIND_PREVIOUS);
 
 		actionBars.updateActionBars();
 	}
@@ -343,6 +361,8 @@
 
 		menuManager.add(new Separator("FIND")); //$NON-NLS-1$
 		menuManager.add(fGlobalActions.get(ActionFactory.FIND.getId()));
+		menuManager.add(fGlobalActions.get(ITextEditorActionConstants.FIND_NEXT));
+		menuManager.add(fGlobalActions.get(ITextEditorActionConstants.FIND_PREVIOUS));
 		menuManager.add(new FollowHyperlinkAction(fViewer.getHyperlink()));
 		menuManager.add(fClearOutputAction);
 
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleResourceBundleMessages.properties b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleResourceBundleMessages.properties
index 95a6613..7ac0b36 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleResourceBundleMessages.properties
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleResourceBundleMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2005 IBM Corporation and others.
+# Copyright (c) 2000, 2020 IBM Corporation and others.
 #
 # This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License 2.0
@@ -20,3 +20,13 @@
 find_replace_action_tooltip=Find/Replace
 find_replace_action_image=
 find_replace_action_description=Find/Replace
+
+find_next_action_label=Find Next
+find_next_action_tooltip=Find Next
+find_next_action_image=
+find_next_action_description=Find next item
+
+find_previous_action_label=Find Previous
+find_previous_action_tooltip=Find Previous
+find_previous_action_image=
+find_previous_action_description=Find previous item
\ No newline at end of file
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java
index 5574fb6..2c73446 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -37,6 +37,8 @@
 	String CONSOLE_CUT_ACTION = PREFIX + "console_cut_action_context"; //$NON-NLS-1$
 	String CONSOLE_PASTE_ACTION = PREFIX + "console_paste_action_context"; //$NON-NLS-1$
 	String CONSOLE_FIND_REPLACE_ACTION = PREFIX + "console_find_replace_action_context"; //$NON-NLS-1$
+	String CONSOLE_FIND_NEXT_ACTION = PREFIX + "console_find_next_action_context"; //$NON-NLS-1$
+	String CONSOLE_FIND_PREVIOUS_ACTION = PREFIX + "console_find_previous_action_context"; //$NON-NLS-1$
 	String CONSOLE_OPEN_LINK_ACTION = PREFIX + "console_open_link_action_context"; //$NON-NLS-1$
 	String CONSOLE_OPEN_CONSOLE_ACTION = PREFIX + "console_open_console_action_context"; //$NON-NLS-1$
 	String CONSOLE_DISPLAY_CONSOLE_ACTION = PREFIX + "console_display_console_action"; //$NON-NLS-1$