-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[StickyScrolling] Introduce enhancement point #2756
Open
Christopher-Hermann
wants to merge
2
commits into
eclipse-platform:master
Choose a base branch
from
Christopher-Hermann:stickyScrollingEnhancementPoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
bundles/org.eclipse.ui.editors/schema/stickyLinesProviders.exsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="org.eclipse.ui.editors" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appInfo> | ||
<meta.schema plugin="org.eclipse.ui.editors" id="stickyLinesProviders" name="Sticky Lines Providers"/> | ||
</appInfo> | ||
<documentation> | ||
This extension point is used to register sticky lines providers for editors. | ||
</documentation> | ||
</annotation> | ||
|
||
<include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appInfo> | ||
<meta.element /> | ||
</appInfo> | ||
</annotation> | ||
<complexType> | ||
<sequence> | ||
<element ref="stickyLinesProvider" minOccurs="1" maxOccurs="unbounded"/> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
a fully qualified identifier of the target extension point | ||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
an optional identifier of the extension instance | ||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
an optional name of the extension instance | ||
</documentation> | ||
<appInfo> | ||
<meta.attribute translatable="true"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="stickyLinesProvider"> | ||
<annotation> | ||
<documentation> | ||
A sticky lines provider. | ||
</documentation> | ||
</annotation> | ||
<complexType> | ||
<sequence> | ||
<element ref="enabledWhen" minOccurs="0" maxOccurs="1"/> | ||
</sequence> | ||
<attribute name="id" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
A string uniquely identifying this sticky line provider | ||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="class" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
The fully qualified class name implementing the interface <code>org.eclipse.ui.texteditor.stickyscroll.IStickyLinesProvider</code>. | ||
</documentation> | ||
<appInfo> | ||
<meta.attribute kind="java" basedOn=":org.eclipse.ui.texteditor.stickyscroll.IStickyLinesProvider"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="enabledWhen"> | ||
<annotation> | ||
<documentation> | ||
A core Expression that controls the enabled of the given sticky lines provider | ||
</documentation> | ||
</annotation> | ||
<complexType> | ||
<choice minOccurs="0" maxOccurs="1"> | ||
<element ref="not"/> | ||
<element ref="or"/> | ||
<element ref="and"/> | ||
<element ref="instanceof"/> | ||
<element ref="test"/> | ||
<element ref="systemTest"/> | ||
<element ref="equals"/> | ||
<element ref="count"/> | ||
<element ref="with"/> | ||
<element ref="resolve"/> | ||
<element ref="adapt"/> | ||
<element ref="iterate"/> | ||
<element ref="reference"/> | ||
</choice> | ||
</complexType> | ||
</element> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="since"/> | ||
</appInfo> | ||
<documentation> | ||
3.20 | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="examples"/> | ||
</appInfo> | ||
<documentation> | ||
The following is an example of a sticky line provider definition: | ||
<pre> | ||
<extension | ||
point="org.eclipse.ui.editors.stickyLinesProviders"> | ||
<stickyLinesProvider | ||
class="org.eclipse.ui.internal.texteditor.stickyscroll.DefaultStickyLinesProvider" | ||
id="org.eclipse.ui.editors.stickyLinesProviderExample" | ||
label="Example sticky lines provider registration"> | ||
<enabledWhen> | ||
<and> | ||
<with variable="editor"> | ||
<instanceof value="org.example.MyEditorWithStickyScrolling"/> | ||
</with> | ||
</and> | ||
</enabledWhen> | ||
</stickyLinesProvider> | ||
</extension> | ||
</pre> | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="apiInfo"/> | ||
</appInfo> | ||
<documentation> | ||
See the org.eclipse.ui.texteditor.stickyscroll.IStickyLinesProvider interface and the org.eclipse.ui.editors.stickyLinesProviders extension point. As default implementation for the IStickyLine, see org.eclipse.ui.texteditor.stickyscroll.StickyLine. | ||
</documentation> | ||
</annotation> | ||
|
||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="copyright"/> | ||
</appInfo> | ||
<documentation> | ||
Copyright (c) 2024 SAP SE.<br> | ||
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 <a href="https://www.eclipse.org/legal/epl-2.0">https://www.eclipse.org/legal/epl-v20.html</a>/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
SAP SE - initial API and implementation | ||
</documentation> | ||
</annotation> | ||
|
||
</schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...rs/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLinesProviderDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 SAP SE. | ||
* | ||
* 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: | ||
* SAP SE - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.ui.internal.texteditor.stickyscroll; | ||
|
||
import org.eclipse.core.expressions.ElementHandler; | ||
import org.eclipse.core.expressions.EvaluationContext; | ||
import org.eclipse.core.expressions.EvaluationResult; | ||
import org.eclipse.core.expressions.Expression; | ||
import org.eclipse.core.expressions.ExpressionConverter; | ||
|
||
import org.eclipse.core.runtime.Assert; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IConfigurationElement; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
import org.eclipse.jface.text.source.ISourceViewer; | ||
|
||
import org.eclipse.ui.internal.editors.text.EditorsPlugin; | ||
|
||
import org.eclipse.ui.texteditor.ITextEditor; | ||
import org.eclipse.ui.texteditor.stickyscroll.IStickyLinesProvider; | ||
|
||
import org.eclipse.ui.editors.text.EditorsUI; | ||
|
||
/** | ||
* Describes an extension to the <code>stickyLinesProviders</code> extension point. | ||
* | ||
* @noextend This class is not intended to be extended by clients. | ||
*/ | ||
class StickyLinesProviderDescriptor { | ||
/** Name of the <code>class</code> attribute. */ | ||
private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ | ||
|
||
/** Name of the <code>id</code> attribute. */ | ||
private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ | ||
|
||
/** Name of the <code>enabledWhen</code> attribute. **/ | ||
private static final String ENABLED_WHEN_ATTR= "enabledWhen"; //$NON-NLS-1$ | ||
|
||
/** The configuration element describing this extension. */ | ||
private IConfigurationElement configuration; | ||
|
||
/** The value of the <code>id</code> attribute, if read. */ | ||
private String id; | ||
|
||
/** The expression value of the <code>enabledWhen</code> attribute. */ | ||
private final Expression enabledWhen; | ||
|
||
/** | ||
* Creates a new descriptor for <code>element</code>. | ||
* <p> | ||
* This method is for internal use only. | ||
* </p> | ||
* | ||
* @param element the extension point element to be described. | ||
* @throws CoreException when <code>enabledWhen</code> expression is not valid. | ||
*/ | ||
public StickyLinesProviderDescriptor(IConfigurationElement element) throws CoreException { | ||
Assert.isLegal(element != null); | ||
configuration= element; | ||
enabledWhen= createEnabledWhen(configuration, getId()); | ||
} | ||
|
||
/** | ||
* Returns the expression {@link Expression} declared in the <code>enabledWhen</code> element. | ||
* | ||
* @param configElement the configuration element | ||
* @param id the id of the sticky lines provider. | ||
* @return the expression {@link Expression} declared in the enabledWhen element. | ||
* @throws CoreException when enabledWhen expression is not valid. | ||
*/ | ||
private static Expression createEnabledWhen(IConfigurationElement configElement, String id) throws CoreException { | ||
final IConfigurationElement[] children= configElement.getChildren(ENABLED_WHEN_ATTR); | ||
if (children.length > 0) { | ||
IConfigurationElement[] subChildren= children[0].getChildren(); | ||
if (subChildren.length != 1) { | ||
throw new CoreException(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, | ||
"One <enabledWhen> element is accepted. Disabling " + id)); //$NON-NLS-1$ | ||
} | ||
final ElementHandler elementHandler= ElementHandler.getDefault(); | ||
final ExpressionConverter converter= ExpressionConverter.getDefault(); | ||
return elementHandler.create(converter, subChildren[0]); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Reads (if needed) and returns the id of this extension. | ||
* | ||
* @return the id for this extension. | ||
*/ | ||
public String getId() { | ||
if (id == null) { | ||
id= configuration.getAttribute(ID_ATTRIBUTE); | ||
Assert.isNotNull(id); | ||
} | ||
return id; | ||
} | ||
|
||
/** | ||
* Creates a sticky lines provider as described in the extension's XML and null otherwise. | ||
* | ||
* @return the created sticky lines provider and null otherwise. | ||
*/ | ||
protected IStickyLinesProvider createStickyLinesProvider() { | ||
try { | ||
Object extension= configuration.createExecutableExtension(CLASS_ATTRIBUTE); | ||
if (extension instanceof IStickyLinesProvider stickyLinesProvider) { | ||
return stickyLinesProvider; | ||
} else { | ||
String message= "Invalid extension to stickyLinesProvider. Must extends IStickyLinesProvider: " //$NON-NLS-1$ | ||
+ getId(); | ||
EditorsPlugin.getDefault().getLog() | ||
.log(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, message)); | ||
return null; | ||
} | ||
} catch (CoreException e) { | ||
EditorsPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, | ||
"Error while creating stickyLinesProvider: " + getId(), e)); //$NON-NLS-1$ | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the given viewer, editor matches the enabledWhen expression and false | ||
* otherwise. | ||
* | ||
* @param viewer the viewer | ||
* @param editor the editor | ||
* @return true if the given viewer, editor matches the enabledWhen expression and false | ||
* otherwise. | ||
*/ | ||
public boolean matches(ISourceViewer viewer, ITextEditor editor) { | ||
if (enabledWhen == null) { | ||
return true; | ||
} | ||
EvaluationContext context= new EvaluationContext(null, editor); | ||
context.setAllowPluginActivation(true); | ||
context.addVariable("viewer", viewer); //$NON-NLS-1$ | ||
context.addVariable("editor", editor); //$NON-NLS-1$ | ||
context.addVariable("editorInput", editor.getEditorInput()); //$NON-NLS-1$ | ||
try { | ||
return enabledWhen.evaluate(context) == EvaluationResult.TRUE; | ||
} catch (CoreException e) { | ||
EditorsPlugin.getDefault().getLog().log( | ||
new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, "Error while 'enabledWhen' evaluation", e)); //$NON-NLS-1$ | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we would remove the "x-internal:=true" part to make this "real" API once we are confident enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be the idea. But I'm not sure if this is the right approach or if this is a good idea.