intellij plugin using TreeClassChooserFactory not show recommended class? - intellij-idea

I'm writing a intellij plugin to let people choose a class, I find the code the move method in intellij open source code.
The move method picture is like this which will show all project class.
but when I using the following code the pic is this
There is no recommend class, after I type some text, still nothing.
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createWithInnerClassesScopeChooser(
"choose serviceClass", GlobalSearchScope.projectScope(myProject), new ClassFilter() {
public boolean isAccepted(PsiClass aClass) {
return aClass.getParent() instanceof PsiFile && !aClass.isInterface();
}
}, srcClass);
chooser.selectDirectory(pojoClass.getContainingFile().getContainingDirectory());
chooser.showDialog();

That seems to be a bug in the IDE, fixed in the upcoming 2017.2 release.

Related

Intellij Plugin - How to color project view files background?

As seen in the picture. Color Notification is colored. This is done by creating a scope and adding that file in that scope.
However I want to mark files according to my need. For example I will click that color notification and mark that file green or yellow.
I only need to know how I can reach this project view and alter background color programmatically.
I know there arent so many intellij plugin creators but still I will try my luck.
From my investigation there are FileColorManager, ProjectView, UIManager etc but I couldnt find which one is responsible for these color handling changes...
Just a guess. Have you tried to implement the com.intellij.ide.projectView.ProjectViewNodeDecorator extension point? It seems like this lets you decorate the nodes in the project view.
As we found out, setting the background-color is not easily possible. But you can add a string (like a checkmark) at the end of each node that you want to highlight. Here is an example:
public class ProvectViewColorer implements ProjectViewNodeDecorator {
#Override
public void decorate(ProjectViewNode node, PresentationData data) {
final VirtualFile virtualFile = node.getVirtualFile();
if (virtualFile != null && virtualFile.getFileType().equals(MathematicaFileType.INSTANCE)) {
data.setLocationString("✓");
}
}
#Override
public void decorate(PackageDependenciesNode node, ColoredTreeCellRenderer cellRenderer) {
}
}

Eclipse Plugin Dev- Extracting IStackFrame object from selection in Debug View

So, I am developing an Eclipse plugin and trying to build a View similiar to the Variables View. Now, to get the selected StackFrame from the Debug View, I have registered an IDebugContextListener, which ultimately calls the method listed below in case of a selection.
The problem is that I ma unable to get a IStackFrame object from IStructuredSelection.getFirstElement().
I also tried to get an adapter for the IStackframe class. That too didn't work.
I would really appreciate if someone can point me the method of getting a IStackFrame object from a selection.
private void contextActivated(ISelection context) {
if (context instanceof StructuredSelection) {
System.out.println("a");
Object data = ((StructuredSelection) context).getFirstElement();
if (data instanceof IStackFrame) {
System.out.println("yes");
} else {
System.out.println("no" + data.getClass().getName());
}
}
}
The issue with this is that it always execute the else part (even when the selection is a StackFrame in the debug view). Also, the adapter approach didn't work.

How to display a warning at a specific line

Quick Intellij plugin Development question.
Can somebody show me a snippet of code on how to display a warning at a specific line?
I want to display a yellow bulb and be able to alt enter.
I don't know if the yellow bulb is part of a warning or just a hint but i would very much appreciate if somebody would show me how to do it.
I tried to find it on idea plugin development but didn't have any luck
private List<PsiFile> psiFiles = new ArrayList<PsiFile>();
public void actionPerformed(AnActionEvent e) {
PsiManager psiManager=PsiManager.getInstance(e.getProject());
Project project = e.getProject();
VirtualFile srcFile;
if(e.getProject().getBaseDir().findChild("src") == null)
return;
else
{
srcFile = e.getProject().getBaseDir().findChild("src");
}
//using the buildFilesList i get all the .java files
buildFilesList(psiManager,srcFile);
for(PsiFile file : psiFiles)
//here i would want for a psiFile a warning to be displayed at a specific line
System.out.println(file);
}
What you need to write is an inspection. You don't need to enumerate the files in the project; IntelliJ IDEA will take care of calling your API at the correct moment. You can find a simple example of a plugin that implements an inspection here.

Equivalent of CGRectInfinite & CGRectIsInfinite in MonoTouch/Xamarin

I am trying to convert an open source flyout menu from Objective-C to Xamarin. The current issue I have is that the Obj-C code creates a frame using CGRectInfinite. This does not appear to be available under MonoTouch, via the usual RectangleF class. Is there an alternative?
Similarly, there does not appear to be a CGRectIsInfinite equivalent in RectangleF. What, if any, is the alternative?
Add this using statement first:
using MonoTouch.CoreGraphics;
Then you can test it with this:
public static RectangleF GetInfinite()
{
var image = CIImage.EmptyImage;
if (image.Extent.IsInfinite ())
{
return image.Extent;
}
throw new Exception ("Unable to create infinite rect");
}

Dynamic label of a popup action in eclipse plugin development

I want to create a simple eclipse plugin, which does: When you right click a java project, it will show a popup menu which has a item has label "N java files found in this project", where "N" is the file count.
I have an idea that I can update the label in "selectionChanged":
public class CountAction implements IObjectActionDelegate {
public void selectionChanged(IAction action, ISelection selection) {
action.setText(countJavaFiles());
}
}
But it doesn't work if I don't click that menu item, since the CountAction has not been loaded, that selectionChanged won't be invoked when you right-click on the project.
I have spent a lot of time on this, but not solved. Please help me.
An alternative to the article suggested by #kett_chup, is to use IElementUpdater. Simply
your handler must implement IElementUpdater
the handler.updateElement((UIElement element, Map parameters) must set the wanted text using element.setText("new text") - this new text will show up in menus and toolbars
whenever you need/want to update the command text use ICommandService.refreshElements(String commandId, Map filter) with your particular command ID - the global command service usually is just fine
The IElementUpdater interface can also be used to change the checked state - for commands with style=toggle - as well as the icons and the tool tip.
At last, I found a very easy way to implement this:
I don't need to change my code(the sample code in question), but I need to add a small startup class:
import org.eclipse.ui.IStartup;
public class MyStartUp implements IStartup {
#Override
public void earlyStartup() {
// Initial the action
new CountAction();
}
}
And add following to plugin.xml:
<extension
point="org.eclipse.ui.startup">
<startup
class="myplugin.MyStartUp">
</startup>
This MyStartUp will load an instance of that action at startup, then selectionChanged will be invoked each time when I right-click the projects or files.