Intellij Plugin Develop: How to properly open a file after creation and loaded by IDE - indexing

I want to create a java file and open it immediately. I write:
PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, language, fileContent);
directory.add(file);
FileEditorManager.getInstance(project).openFile(file.getVirtualFile(), true, true);
It works but the opened file does not have any highlights, and the icon is gray. It seems that the IDE has not finished loading it.
So how to open file after IDE loaded it?
I try use CodeStyleManager.getInstance(project).reformat(file); to highlight the file, it works.
But the icon is still gray. And this file cannot use the "Select open file" button to navigate to the target file tree node.
I plan to use JavaDirectoryService.getInstance().createClass(dir, className, true); but I'm not sure how to use it correctly to open the created file ?

Related

View file in project view Intellij

I have started using Intellij and I am trying to find a feature that was in eclipse. I often navigate to a file either through the code or through a CTRL-N search. When I have the file I found open, I want to see which project and which folder of the project the file is in. I found a way to open the file in Windows Explorer which tells me what I want but I would rather stay in intellij and see the folders on the left expanded to the location of the file. Does this exist in intellij?
Thanks
On the heading of Project Explorer panel their will be a circle with 4 lines inside it.
Press that it will take you to the place where you file is inside the project
Image upload not working thats why explaination

How to stop files inside moved directories (and newly created files) from automatically opening in editor (PyCharm 2020.1)

I am using PyCharm 2020.1. When I create a new file, PyCharm automatically opens it in the editor. Also when I move a directory, PyCharm opens all the files inside the directory in the editor.
Sometimes it's tens of files opened at once. This behavior is frustrating and I would like to turn it off, but have not been able to find where in Preferences to do so.
Someone please help me figure out how to stop newly created files and files inside moved folders from automatically opening in editor. Thanks.
I don't think you can't open a new file via PyCharm, unless you create it via the Terminal tab on the bottom, for example:
touch test.py
When you move a directory into a new directory, there should be a checkmark on a popup saying "Open moved files in editor", so you probably have that checked.

How to open file with IntelliJ IDEA in new tab with command line?

How can I specify the file to open in new tab with IntelliJ IDEA via command line?
If I run in command line:
idea d:\Dropbox\Dropbox\featurea\featurea-common\src\com\featurea\common\util\FileManager.java
I get "No project found to open file in" error
Open file in new tab with opened project also fails.
Is there any way to manage IntelliJ IDEA to behave as I want?
Thanks.
You can't open individual files in the IDE from the command line when there is no open project and the IDE is not already running.
You can pass the project directory as an argument to open the project first, then you will be able to open individual files.

How to run .html File from WebStorm

We do unit tests via .html files so that we can interact in a web form also. We also just run the dojo test runner.
I have been able to run the .hml file from Aptana but when I try webstorm for the first time, never tried it, love this IDE, I see that when in my .html file the run button at the top is disabled.
So how do I run an .html file that's got markup and javascript from WebStorm and have it come back and hit my debug points inside Webstorm? Does webstorm scrape in what you see in FireFox also or do you have to keep toggling back and fourth such as when you step to the next debug point, tab back to the browser to see the results...or is there a nice way in webstorm to see the markup in runtime at the same time?
All in all I am just trying to get this .html file to run that's got javascript in it and some Dojo runner, etc. in it since I'm using Dojo in this .html file.
Either just open it manually or allow debug from localhost port.
So appearnetly it's not obvious to open a file in WebStorm there is a row of icons that appear in the top right corner of the text editor pane.
You have to hold SHIFT down when clicking the supported/installed browsers icons hidden there, or it will open in the deployment's location (via FTP server settings etc).
Try ALT-F2 for Preview file in... from "View" menu.

IntelliJ/WebStorm File search with Dart

The following line of Dart code shows true for existing files when run from the Terminal but false when run from IntelliJ or WebStorm. Can someone explain why and how to set up Idea editors so that it will return the same results as the Terminal run.
bool pathExists(String path) => new File(path).existsSync();
Update
After tinkering I've now found out that if I create the project in WebStorm 5 using 'open directory' it works fine for all(WebStorm, IntelliJ, and the Terminal). The problem is when I try to create the project in IntelliJ 12 as there seems to be no equivalent to open directory it seems to try to create a Java project. WebStorm seems to have better support for creating a Dart application from scratch at the moment. See answers below for instructions.
You really should show the whole program and how you run it, otherwise I can only guess. And my guess would be that you are passing a relative path to the function and you run the program from a different directory than IntelliJ.
Let's say I have this Dart program:
import 'dart:io';
bool pathExists(String path) => new File(path).existsSync();
main() {
print(pathExists('books.txt'));
}
This program will print true when the books.txt file exists in the current directory. I happen to have such file in my home directory, so when I do
ladicek#argondie:~$ dart check_file.dart
it will obviously print true. But if I run the same program from another directory, it will surely print false. And that's probably what happens in your case.
You should check the Run/Debug Configuration in IntelliJ, it lets you configure the directory where the program is started.
Following #CrazyCoder's comment: Selecting
Create New Project
then
Static Web/Web Module
and choose your folder at
Project Location
then expand
More Settings
and finally make sure that
Module File Location
is set to where your main() dart file is located. By default it is set to the content root.
Has the same effect as Open Directory. I've tried it and it works fine.