diff --git a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF index d3502adcfbc..756eac4697e 100644 --- a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface;singleton:=true -Bundle-Version: 3.37.100.qualifier +Bundle-Version: 3.38.0.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.jface, diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangeProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangeProvider.java new file mode 100644 index 00000000000..cfd615ca36c --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangeProvider.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +/** + * @since 3.38 + * + */ +public interface IScopeChangeProvider { + + /** + * Adds a listener for scope changes in this scope change provider. Has no + * effect if an identical listener is already registered. + * + * @param listener a scope changed listener + */ + void addScopeChangedListener(IScopeChangedListener listener); + + /** + * Removes the given scope change listener from this page change provider. Has + * no effect if an identical listener is not registered. + * + * @param listener a scope changed listener + */ + void removeScopeChangedListener(IScopeChangedListener listener); + +} diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangedListener.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangedListener.java new file mode 100644 index 00000000000..d6748a32ca9 --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IScopeChangedListener.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +/** + * A listener which is notified when the scope for the search page is changed. + * + * @see IScopeChangeProvider + * @see ScopeChangedEvent + * + * @since 3.38 + */ +public interface IScopeChangedListener { + /** + * Notifies that the selected scope has changed. + * + * @param event event object describing the change + */ + void scopeChanged(ScopeChangedEvent event); +} diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/ScopeChangedEvent.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/ScopeChangedEvent.java new file mode 100644 index 00000000000..c4326c18cdd --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/ScopeChangedEvent.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Red Hat Inc. - copied and modified from PageChangedEvent.java + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +import java.util.EventObject; + +/** + * Event object describing a page selection change. The source of these events + * is a page change provider. + * + * @see IPageChangeProvider + * @see IPageChangedListener + * + * @since 3.38 + */ +public class ScopeChangedEvent extends EventObject { + + private static final long serialVersionUID = -2652600407410991930L; + + /** + * The changed scope. + */ + private final int scope; + + /** + * Creates a new event for the given source and new scope. + * + * @param source the page change provider + * @param scope the new scope. In the JFace provided dialogs this will be an + * ISearchPageContainer constant. + */ + public ScopeChangedEvent(IPageChangeProvider source, + int scope) { + super(source); + this.scope = scope; + } + + /** + * Returns the new scope. + * + * @return the new scope. In dialogs implemented by JFace, this will be an + * ISearchPageContainer constant. + */ + public int getScope() { + return scope; + } + + /** + * Returns the scope change provider that is the source of this event. + * + * @return the originating scope change provider + */ + public IScopeChangeProvider getPageChangeProvider() { + return (IScopeChangeProvider) getSource(); + } +} diff --git a/bundles/org.eclipse.search/META-INF/MANIFEST.MF b/bundles/org.eclipse.search/META-INF/MANIFEST.MF index fcfd9d845d8..001a2b22bfb 100644 --- a/bundles/org.eclipse.search/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.search/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.search; singleton:=true -Bundle-Version: 3.17.200.qualifier +Bundle-Version: 3.17.300.qualifier Bundle-Activator: org.eclipse.search.internal.ui.SearchPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName diff --git a/bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java b/bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java index f00afb61d4b..3d2b82912dd 100644 --- a/bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java +++ b/bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -60,7 +60,10 @@ import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IPageChangeProvider; import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.IScopeChangeProvider; +import org.eclipse.jface.dialogs.IScopeChangedListener; import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.dialogs.ScopeChangedEvent; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.SafeRunnable; @@ -91,7 +94,8 @@ import org.eclipse.search.ui.ISearchPageScoreComputer; -public class SearchDialog extends ExtendedDialogWindow implements ISearchPageContainer, IPageChangeProvider { +public class SearchDialog extends ExtendedDialogWindow + implements ISearchPageContainer, IPageChangeProvider, IScopeChangeProvider { // Dialog store id constants private static final String DIALOG_NAME= "SearchDialog"; //$NON-NLS-1$ @@ -150,6 +154,7 @@ protected void layout(Composite composite, boolean flushCache) { private Button fCustomizeButton; private Button fReplaceButton; private ListenerList fPageChangeListeners; + private ListenerList fScopeChangeListeners; private final IWorkbenchWindow fWorkbenchWindow; private final ISelection fCurrentSelection; @@ -706,6 +711,13 @@ public void setPerformActionEnabled(boolean state) { */ public void notifyScopeSelectionChanged() { setPerformActionEnabled(fLastEnableState); + if (fScopeChangeListeners != null && !fScopeChangeListeners.isEmpty()) { + // Fires the scope change event + final ScopeChangedEvent event = new ScopeChangedEvent(this, getSelectedScope()); + for (IScopeChangedListener l : fScopeChangeListeners) { + SafeRunner.run(() -> l.scopeChanged(event)); + } + } } private Control createPageControl(Composite parent, final SearchPageDescriptor descriptor) { @@ -828,4 +840,19 @@ public void run() { } } } + + @Override + public void addScopeChangedListener(IScopeChangedListener listener) { + if (fScopeChangeListeners == null) { + fScopeChangeListeners = new ListenerList<>(); + } + fScopeChangeListeners.add(listener); + } + + @Override + public void removeScopeChangedListener(IScopeChangedListener listener) { + if (fScopeChangeListeners != null) { + fScopeChangeListeners.remove(listener); + } + } }