I have been partially successful at removing almost all the popUp menus from the Commons Navigator Framework simply by configuring the plugin.xml file.
There are 2 menus that refuse to go:
group.edit and
group.reorganize.
My plugin.xml config looks like this:
<extension
point="org.eclipse.ui.navigator.viewer">
<viewer
viewerId="org.eclipse.ui.example.navigator.view">
<popupMenu allowsPlatformContributions="false">
<insertionPoint
name="group.edit" />
<insertionPoint
name="group.reorganize" />
</popupMenu>
</viewer>
<viewerContentBinding
viewerId="org.eclipse.ui.thermo.navigator.view">
<includes>
<contentExtension
pattern="org.eclipse.ui.navigator.resourceContent"/>
</includes>
</viewerContentBinding>
</extension>
Setting the allowsPlatformContribution to false DOES stop contributions to be added to the context menu except for group.edit and group.reorganize... this is starting to look like a bug to me.
The obvious solution is to remove the insertion points from my <popUpMenu> but without them the application throws an exception:
Throwable: java.lang.IllegalArgumentException: Group not found: group.edit
java.lang.IllegalArgumentException: Group not found: group.edit
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup.fillContextMenu(EditActionGroup.java:74)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider.fillContextMenu(EditActionProvider.java:50)
at org.eclipse.ui.navigator.NavigatorActionService.addCommonActionProviderMenu(NavigatorActionService.java:205)
at org.eclipse.ui.navigator.NavigatorActionService.fillContextMenu(NavigatorActionService.java:172)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager.fillContextMenu(CommonNavigatorManager.java:258)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager$4.menuAboutToShow(CommonNavigatorManager.java:273)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:335)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:463)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:459)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:485)
It throws the same exception for the reorganize group.
I succeeded in removing the "group.edit" actions (Copy/Paste) and I've done it that way, using the Common Navigator extension points :
<extension
point="org.eclipse.ui.navigator.viewer">
<viewerActionBinding
viewerId="org.eclipse.ui.navigator.ProjectExplorer">
<includes>
<actionExtension
pattern="my.app.client.actions.MyAppEditActionExtension">
</actionExtension>
</includes>
</viewerActionBinding>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
<actionProvider
class="my.app.client.workshop.MyPasteActionProvider"
id="my.app.client.actions.MyAppEditActionExtension"
overrides="org.eclipse.ui.navigator.resources.actions.EditActions"
priority="highest">
<enablement>
<!-- A hack to allways be enabled -->
<not>
<systemTest
property="MyApp"
value="WONT-EVER-BE-SET">
</systemTest>
</not>
</enablement>
</actionProvider>
</extension>
And, with addition of "org.eclipse.ui.navigator.resources" in my plugin dependencies, I implemented "MyPasteActionProvider" like this :
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider;
/**
* Create the Edit actions (Cut/Copy/Paste)
* and register then globally in the workbench using EditActionProvider.
* <p/>
* Then, removes the Copy/Paste contributions in the pop-up menu.
*/
public class MyPasteActionProvider extends EditActionProvider {
public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu);
// remove Copy/Paste contributions
IContributionItem copyItemRemoved = menu.remove("org.eclipse.ui.CopyAction");
IContributionItem pasteItemRemoved = menu.remove("org.eclipse.ui.PasteAction");
}
}
Well, that's a "discouraged access" but I was getting myself discouraged ;-)
JM.D
Generally you should be using the Command Framework with any recent version of Eclipse (3.3 or higher), this replaces the mechanism for providing popup menus in the Common Navigator.
This thread suggests to remove the things that are causing the menu items to appear in the first place:
They are probably in action sets, so if you can identify the action set that's causing the offensive contribution, you can do something like this in your WorkbenchAdvisor:
ActionSetRegistry reg = WorkbenchPlugin.getDefault()
.getActionSetRegistry();
IActionSetDescriptor[] actionSets = reg.getActionSets();
String[] removeActionSets = new String[] {
"org.eclipse.ui.cheatsheets.actionSet",
"org.eclipse.ui.edit.text.actionSet.annotationNavigation",
"org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
"org.eclipse.ui.WorkingSetActionSet",
"org.eclipse.update.ui.softwareUpdates", };
for (int i = 0; i < actionSets.length; i++)
{
boolean found = false;
for (int j = 0; j < removeActionSets.length; j++)
{
if (removeActionSets[j].equals(actionSets[i].getId()))
found = true;
}
if (!found)
continue;
IExtension ext = actionSets[i].getConfigurationElement()
.getDeclaringExtension();
reg.removeExtension(ext, new Object[] { actionSets[i] });
}
The closest bug I have found is the 145233: Make more obvious way to specify input (for RCP apps), with a similar hack.
Bug 143430 (CommonNavigator requires initialInput to be Adaptable) is a more general one, and would indicate that then CNF has been improved with eclipse3.5 (Galileo).
So do you also have this issue with 3.5 and a custom CNF class?
As mentioned in the article "Eclipse CNF: Navigator Content Extensions", CNF has evolved with eclipse3.5, and this article seems to have some tree with true custom contextual menu entries.
Related
The Open Perspective View shows a list of perspectives to which a user can switch. My custom perspective is there, too. Can I have it not listed or greyed out, if a certain condition bis not met?
The second best alternative that comes to my mind is to have it listed, but the actual switch is not carried out, if b == false.
The best way for me was to use the extension point org.eclipse.ui.activities, as greg-449 suggested, and add a propertyTester. In order to hide perspective related UI elements and not every UI element from the same plugin, one can use isEqualityPattern="true".
<extension point="org.eclipse.ui.activities">
<activity
description="Remove some UI Elements"
id="com.my.plugin.ui.hideUI"
name="HideUI">
<enabledWhen>
<test
forcePluginActivation="false"
property="com.my.plugin.ui.PlanningPropertyTester">
</test>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="com.btc.edm.hidePlanning"
isEqualityPattern="true"
pattern="com.my.plugin.ui/id.of.the.perspective.to.hide">
</activityPatternBinding>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.my.plugin.ui.MyPropertyTester"
id="com.my.plugin.ui.propertyTester"
namespace="com.my.plugin.ui"
properties="MyPropertyTester"
type="java.lang.Object">
</propertyTester>
</extension>
It is important to have a fully qualified name for type.
The MyPropertyTester class extends org.eclipse.core.expressions.PropertyTester and overrides the test method.
public class MyPropertyTester extends PropertyTester {
#Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (goodWeather()) {
return true;
return false;
}
}
I define my own editor and have completion proposals like this
public IContentAssistant getContentAssistant(ISourceViewer sv) {
ContentAssistant ca = new ContentAssistant();
IContentAssistProcessor pr = new TagCompletionProcessor();
ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
return ca;
}
#Override
public char[] getCompletionProposalAutoActivationCharacters() {
String str = "._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return str.toCharArray();
}
So when I am pressing ctrl-space enter it will work, but I want it should always trigger computeCompletionProposals when any of the above characters are entered.
<extension
point="org.eclipse.ui.editors">
<editor
id="testingpluginproject.editors.XMLEditor"
name="Sample XML Editor"
icon="icons/sample.png"
extensions="xxml"
class="testingpluginproject.editors.XMLEditor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor">
</editor>
</extension>
So what I am missing?
You must call the ContentAssistant enableAutoActivation method to enable auto activation:
ca.enableAutoActivation(true);
You might also want to look at implementing IContentAssistProcessorExtension rather than just IContentAssistProcessor as it provides a better isCompletionProposalAutoActivation method.
I am quite new to Eclipse RCP development.
In my Eclipse RCP application there are different perspectives. I want them to have different ToolBarItems. According to the official documentation the contents of this toolbar change based on the active perspective. But after tons of googling I still have no idea how.
My best idea is as follows:
First I create the items and I add them to toolbar and coolbar
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
ActionContributionItem saveItem = new ActionContributionItem(saveAction);
saveItem.setId(ApplicationActionBarAdvisor.SAVE);
toolbar.add(saveItem);
ActionContributionItem saveAllItem = new ActionContributionItem(saveAllAction);
saveAllItem.setId("saveAllItem");
toolbar.add(saveAllItem);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
}
and then, in the Perspective class I override the createInitialLayout() method and I just hide the unnecessary item.
#Override
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
PageLayout pl = (PageLayout) layout;
pl.addHiddenToolBarItemId(ApplicationActionBarAdvisor.SAVE);
pl.setEditorAreaVisible(false);
pl.addStandaloneView(View.ID, false, IPageLayout.LEFT, 0.25f, editorArea);
pl.getViewLayout(View.ID).setCloseable(false);
}
It does not work, but I have no idea what I am missing. Any help is highly appreciated.
Use the org.eclipse.ui.perspectiveExtensions extension point and contriubte an actionSet to the perspective.
For example, this is part of the JDT plugin:
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="org.eclipse.debug.ui.DebugPerspective">
<perspectiveShortcut id="org.eclipse.jdt.ui.JavaPerspective"/>
<perspectiveShortcut id="org.eclipse.jdt.ui.JavaBrowsingPerspective"/>
<actionSet id="org.eclipse.jdt.ui.JavaActionSet"/>
<showInPart id="org.eclipse.jdt.ui.PackageExplorer"/>
</perspectiveExtension>
Note: Do not use internal classes such as PageLayout they may change at any time and in fact this class was in Eclipse 3 but has been deleted in Eclipse 4.
Im trying to create a lightweight C++ Editor with the help of libclang.
I use a new problemmarker type to mark the compiler warnings and errors given by clang and the token ranges to do syntax coloring.
As you can see in the picture above, the squiggly lines of the error markers overwrite the syntax coloring. Is there a PresentationReconciler that takes into account that some marked lines could still have other style information?
I added some code snippets that might be relevant to solve the problem:
my plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
name="CXX Editor"
extensions="cpp"
icon="icons/sample.gif"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="cppeditor.editors.CppEditor"
id="cppeditor.editors.CppEditor">
</editor>
</extension>
<extension
id="cppeditor.problemmarker"
name="clang Error"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<super
type="org.eclipse.core.resources.textmarker">
</super>
<persistent
value="true">
</persistent>
</extension>
</plugin>
The method to add markers to the IFile resource:
public void addMarkerToFile(IFile file, IDocument fileDocument) throws CoreException, BadLocationException{
IMarker marker = file.createMarker("cppeditor.problemmarker");
marker.setAttribute(IMarker.SEVERITY, this.severity);
marker.setAttribute(IMarker.MESSAGE, this.message);
marker.setAttribute(IMarker.LINE_NUMBER, this.line);
int startOffset = fileDocument.getLineOffset(this.line-1);
int endOffset = fileDocument.getNumberOfLines() > this.line ?
fileDocument.getLineOffset(this.line) : fileDocument.getLength()-1;
marker.setAttribute(IMarker.CHAR_START, startOffset);
marker.setAttribute(IMarker.CHAR_END, endOffset);
}
The "createPresentation" method of the PresentationRepairer
#Override
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
CppDocument doc = (CppDocument) this.fDocument;
Token[] newTokens = doc.getTokens();
if(newTokens != oldTokens){
for(Token t : newTokens){
addRange(
presentation,
t.getStart(),
t.getEnd() - t.getStart(),
attributeMap.get(t.getKind()));
}
oldTokens = newTokens;
}
}
note: I already asked this question in the eclipse forums but nobody answered it... (see here)
I found the answer myself. After adding markers to the file, the "createPresentation" method is called again, this time because the marker region was invalidated.
This is why the if(newTokens != oldTokens) broke the syntax highlighting at the invalidated areas. I removed the if to fix the problem.
Many people are using Consolas for their primary programming font but unfortunately there is no way to change line height in Eclipse so it looks kinda ugly as it is shown below:
I was wondering if there is anyone who solved this by adding some extra space between lines or simply changing the font itself which has longer height now.
It would be nice to share it with us here on Stackoverflow.
There are some topics I've found while searching for this but none of them were what I am looking for:
How can I change line height / line spacing in Eclipse?
https://stackoverflow.com/questions/15153938/improved-line-spacing-for-eclipse?lq=1
and so on...
Some of them designed their own fonts (such as Meslo Font) by modifying the existing ones so it would be nice if you could share your modified Consolas font.
As mentioned in one of the answers you reference the underlying StyledText control does have a setLineSpacing method, but the existing editors do not use it.
The CSS styling code in Eclipse 4.3 does provide a way to access this but it requires writing a plugin to extend the CSS in order to do so.
The plugin.xml for the plugin would look like this:
<plugin>
<extension
point="org.eclipse.e4.ui.css.core.elementProvider">
<provider
class="linespacing.LineSpacingElementProvider">
<widget
class="org.eclipse.swt.custom.StyledText"></widget>
</provider>
</extension>
<extension
point="org.eclipse.e4.ui.css.core.propertyHandler">
<handler
adapter="linespacing.StyledTextElement"
composite="false"
handler="linespacing.LineSpacingPropertyHandler">
<property-name
name="line-spacing">
</property-name>
</handler>
</extension>
</plugin>
which declares a CSS element provider LineSpacingElementProvider which would be:
public class LineSpacingElementProvider implements IElementProvider
{
#Override
public Element getElement(final Object element, final CSSEngine engine)
{
if (element instanceof StyledText)
return new StyledTextElement((StyledText)element, engine);
return null;
}
}
The StyledTextElement this provides is just:
public class StyledTextElement extends ControlElement
{
public StyledTextElement(StyledText control, CSSEngine theEngine)
{
super(control, theEngine);
}
}
The second declaration in the plugin.xml is a CSS property handler for a property called line-spacing
public class LineSpacingPropertyHandler extends AbstractCSSPropertySWTHandler implements ICSSPropertyHandler
{
#Override
protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception
{
if (!(control instanceof StyledText))
return;
StyledText text = (StyledText)control;
if ("line-spacing".equals(property))
{
int pixelValue = (int)((CSSPrimitiveValue)value).getFloatValue(CSSPrimitiveValue.CSS_PX);
text.setLineSpacing(pixelValue);
}
}
#Override
protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception
{
return null;
}
}
With a plugin containing this installed you can then modify one of the existing CSS style sheets to contain:
StyledText {
line-spacing: 2px;
}
You better choose different fonts. Don't just stick to things. Try new things and accept them. :D I was also using Consolas. But now I am using Courier New and they are pretty fine. If you have 21" or larger display you can use Courier New at 12 or 14 size. Once you use this you will get used to it as you are with Consolas now :P
You could try Fira Mono. See some screenshots here. Small sizes look good too.