How do I create a new file in a project?

Subject says it all. I have an action that needs to create a new file dynamically (based on some data on another server); can anyone walk me through the process? (Or point me to code for an example that works?)

Thanks in advance,

adam connor

0
4 comments
Avatar
Permanently deleted user

I have somehow the same question - open a fresh document and optionally load it with arbitray data( doesn't get indexed ).
Have searched the whole forum but have no clue yet. If the feature isn't there, I would degrade to ask for relative APIs to create such a feature.

0

Hello Garry,

I have the same question, searched the whole forum but have no clue
yet. Is the feature isn't there, I would degrade to ask relative APIs
to create such a feature.


Please refer to http://www.jetbrains.net/confluence/display/IDEADEV/IntelliJIDEAArchitectural+Overview

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

It's greate to see such dev doc out there, and I may got my rough answer from the document section:

If you need to create a document instance which isn't bound to anything, you can use EditorFactory.createDocument

But I also see the following worries for document, since I also want the new document to be able to work with PSI. It's different with e.g. a plain textfield, in short, it's a fully-functionaled editor just like the one where project startup without indices been build, is that possible?

Any operations which access or modify the file contents on "plain text" level(as a sequence of characters, not as a tree of Java elements)

0
Avatar
Permanently deleted user

Now I'm using the following lines to open an editor tab with an empty document:


var ef = EditorFactory.getInstance();
var fem = FileEditorManager.getInstance(project);
// An in-memory VF.
var vf = new LightVirtualFile('Untitled', 'new file content');
var fd = new OpenFileDescriptor(project, vf);
fem.openTextEditor(fd, true);





 



There's no exception thrown, but the editor is not opened, do I need implement any other interface on the VF to make this work?

0

Please sign in to leave a comment.