Intellij Plugin - How to color project view files background? - intellij-idea

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) {
}
}

Related

AndroidTV RecyclerView: Highlight entry when using DPAD

This subject is driving my nuts. I've read virtually a hundred posts about it, but none of them reflects my situation. I'm using a plain simple RecyclerView in an app running on AndroidTV. To enable navigation, I've set
android:focusable="true"
Now, I can use DPAD to scroll inside the RecyclerView, nicely. My goal is to animate the highlighting of the currently focused item in the list. However, I can't seem to find any event which indicates a focus change.
I would very much appreciate a hint, how my code could be informed about a focus changed inside the list, programaticaly, and how to figure out which list items have gained/lost focus.
Thanks!
Finally, it turned out that the solution is fairly easy. I don't know, why it was hidden in front of my eyes. All I had to do was to view.setOnFocusChangeListener() inside onBindViewHolder like this:
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
...
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
highlightEntry(view, b);
}
});
...
}

Disable copy/paste on Xamarin forms input field i.e. Entry

I am working on disabling copy/paste option menus on xamarin forms Entry, I am able to disable copy option using IsPassword=true attribute but this attribute also converts the normal input field to password field, which is not a requirement.
<Entry IsPassword="true" Placeholder="Password" TextColor="Green" BackgroundColor="#2c3e50" />
Thanks in advance.
This has to do with how Forms functions. Using iOS as the example here, the CanPerform override referred to in the other answer's Bugzilla issue is using the UIMenuController as the withSender and not the UITextField itself that might otherwise be expected. This is because the EntryRenderer class is a ViewRenderer<TView, TNativeView> type and subsequently is using whatever TNativeView (in this case, the UITextView) has in its CanPerform. Because nothing is going to be overridden by default, one still sees all of the cut/copy/paste options in the UIMenuController.
As a result, there would be a couple options. You could first make the modification where if you don't want copy/paste but are fine with getting rid of everything else, you can use UIMenuController.SharedMenuController.SetMenuVisible(false, false) in a custom renderer inheriting from EntryRenderer. If you look around on SO, there are similar questions where this is a possible route.
Alternatively, you can create a "true" custom renderer inheriting from ViewRenderer<TView, TNativeView> as ViewRenderer<Entry, YourNoCopyPasteUITextFieldClassName>. The class inheriting from UITextField can then override CanPerform as something like follows:
public override bool CanPerform(Selector action, NSObject withSender)
{
if(action.Name == "paste:" || action.Name == "copy:" || action.Name == "cut:")
return false;
return base.CanPerform(action, withSender);
}
This will require more effort because the custom renderer will not have the same behavior as the EntryRenderer, but as Xamarin.Forms is now open source, you could look to it for some ideas as to how the EntryRenderer functions normally. Something similar would likely have to be done for Android.
Edit: For Android, you can probably use this SO answer as a starting point: How to disable copy/paste from/to EditText
Another custom renderer, this time inheriting from ViewRenderer<Entry, EditText>, and create a class inside of it like this (in the most basic form):
class Callback : Java.Lang.Object, ActionMode.ICallback
{
public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
{
return false;
}
public bool OnCreateActionMode(ActionMode mode, IMenu menu)
{
return false;
}
public void OnDestroyActionMode(ActionMode mode)
{
}
public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
{
return false;
}
}
Then, in your OnElementChanged method, you can set the native control and the CustomSelectionActionModeCallback value:
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.CustomSelectionActionModeCallback = new Callback();
}
}
Doing something like the following appears to disable all of the copy/paste/cut functionality on the custom entry as far as the toolbar goes. However, you can still long click to show the paste button, to which I've poked around a bit hadn't found an answer yet beyond setting LongClickable to false. If I do find anything else in that regard, I'd make sure to update this.

JavaFX 8: How to automatically input a file on start-up?

I’m using JavaFX 8 and JDK 1.8.0_77 in IntelliJ with SceneBuilder. I created a basic pixel editor app. I have two windows(stages). One is a 32x128 matrix of Circle Objects placed in a Grid Pane and the other is a Message Center in Main.
You can see the Message Center window at: https://virtualartsite.wordpress.com/message-center/
I want to save messages using the Message Center app and scroll them on an RGB LED matrix that’s also 32x128. I save the messages in ArrayList<> of Message Objects and I write the ArrayList’s Message’s to a serialized file. I write the file calling writeObjArrayList () and input the file calling readObjArrayList().
I am able to write and read the file successfully and .add all the Message objects to the ArrayList on start-up so the user can edit or delete any message from the viewMessages ComboBox. BUT so far, I can only do so if I use a button event to call readObjArrayList(). This is the problem.
I want to read the file “behind the scenes”, when the app starts. I want to automatically read the file when the program starts up; the user shouldn’t have to click on a button.
My best idea was to use the following code which compiles but doesn’t appear to execute any code:
public void windowEvents(WindowEvent event){
if(event.getSource() == viewMessages) readObjArrayList();
}
I thought a WindowEvent would be fired with windowEvents=#OnShow for the ComboBox, viewMessages(FX:ID).
Please advise.
Thanks for your help.
According to the javadoc, the WindowEvent is related to Window showing/hiding actions. As Node classes aren't Windows, installing a WindowEvent handler on it won't have any effect.
Since you are using SceneBuilder, I assume that you must have an FXML file that has a fx:controller class defined. In any controller class, you can add a non-arg initialize() method which will be called right after the FXML file has been processed.
public class YourController {
#FXML
ComboBox viewMessages;
public void initialize() {
readObjArrayList();
}
private void readObjArrayList() {
...
}
}

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.

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.