Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ private SearchMessages() {
public static String ShowNextResultAction_tooltip;
public static String ShowPreviousResultAction_label;
public static String ShowPreviousResultAction_tooltip;
public static String GlobalNextSearchEntryAction_label;
public static String GlobalNextSearchEntryAction_tooltip;
public static String GlobalPreviousSearchEntryAction_label;
public static String GlobalPreviousSearchEntryAction_tooltip;
public static String RemoveMatchAction_label;
public static String RemoveMatchAction_tooltip;
public static String DefaultSearchViewPage_show_match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ShowNextResultAction_label=Next Match
ShowNextResultAction_tooltip=Show Next Match
ShowPreviousResultAction_label=Previous Match
ShowPreviousResultAction_tooltip=Show Previous Match
GlobalNextSearchEntryAction_label=Next Search Entry
GlobalNextSearchEntryAction_tooltip=Go to Next Search Result
GlobalPreviousSearchEntryAction_label=Previous Search Entry
GlobalPreviousSearchEntryAction_tooltip=Go to Previous Search Result
RemoveMatchAction_label=Remove Match
RemoveMatchAction_tooltip=Remove Currently Showing Match
DefaultSearchViewPage_show_match=Show Match
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2024 Eclipse Foundation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eclipse Foundation - initial API and implementation
*******************************************************************************/
package org.eclipse.search2.internal.ui.basic.views;

import java.util.HashMap;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.handlers.IHandlerService;

/**
* Global handler for navigating to next/previous search results without requiring
* focus on the Search view. This handler provides a seamless workflow for
* navigating through search results while editing.
*
* @since 3.17
*/
public class GlobalNextPrevSearchEntryHandler extends AbstractHandler implements IExecutableExtension {
private String searchCommand = IWorkbenchCommandConstants.NAVIGATE_NEXT;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ICommandService cs = window.getService(ICommandService.class);

// Show the Search view
Command showView = cs.getCommand(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW);
HashMap<String, Object> parms = new HashMap<String, Object>();
parms.put(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID, "org.eclipse.search.ui.views.SearchView");
ParameterizedCommand showSearchView = ParameterizedCommand.generateCommand(showView, parms);

IHandlerService hs = window.getService(IHandlerService.class);
try {
// Execute the sequence: show search view -> navigate -> activate editor
hs.executeCommand(showSearchView, (Event)event.getTrigger());
hs.executeCommand(searchCommand, (Event)event.getTrigger());
hs.executeCommand(IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR, (Event)event.getTrigger());
} catch (NotDefinedException e) {
throw new ExecutionException(e.getMessage(), e);
} catch (NotEnabledException e) {
throw new ExecutionException(e.getMessage(), e);
} catch (NotHandledException e) {
throw new ExecutionException(e.getMessage(), e);
}

return null;
}

@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
if ("previous".equals(data)) {
searchCommand = IWorkbenchCommandConstants.NAVIGATE_PREVIOUS;
}
}
}
26 changes: 26 additions & 0 deletions bundles/org.eclipse.search/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@
name="%command.performTextSearchFile.name"
description="%command.performTextSearchFile.description"
/>
<command
categoryId="org.eclipse.ui.category.navigate"
id="org.eclipse.search.ui.globalNextSearchEntry"
name="%GlobalNextSearchEntryAction_label"
description="%GlobalNextSearchEntryAction_tooltip"
defaultHandler="org.eclipse.search2.internal.ui.basic.views.GlobalNextPrevSearchEntryHandler:next"
/>
<command
categoryId="org.eclipse.ui.category.navigate"
id="org.eclipse.search.ui.globalPreviousSearchEntry"
name="%GlobalPreviousSearchEntryAction_label"
description="%GlobalPreviousSearchEntryAction_tooltip"
defaultHandler="org.eclipse.search2.internal.ui.basic.views.GlobalNextPrevSearchEntryHandler:previous"
/>

</extension>

Expand Down Expand Up @@ -162,6 +176,18 @@
commandId="org.eclipse.search.ui.performTextSearchWorkspace"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+M3+T"/>
<key
commandId="org.eclipse.search.ui.globalNextSearchEntry"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="ALT+.">
</key>
<key
commandId="org.eclipse.search.ui.globalPreviousSearchEntry"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="ALT+,">
</key>

</extension>

Expand Down
Loading