By Geertjan on Jan 09, 2013
You're creating a NetBeans Platform application and discover that your "New File" menu item (and toolbar button) are always disabled. Why? Because you haven't implemented the Project API in your application. The "New File" feature is part of the Project UI module. You could include that module in your application and then you'd have the "New File" feature available but it will never be enabled, unless you've created a project already. You can see this in the New File dialog in the IDE: you need to specify the project for which you're creating a new file, until you have a project, you can't create a file. In short, "New File" is part of the project infrastructure.
So, what to do in applications that don't have a Project implementation but that do need to have "New File" feature? In this sample that I created today, two solutions are available out of the box:
Here are the two solutions:
- An Action (same as the equivalent defined here in the PinkMatterPlatform) that creates a new file.
- An Action that pops up a dialog where the user can select a file to be created.
In both cases, the "Templates" folder in the filesystem is queried, a file (or multiple files, in the second case) is found, and then the selected file is created.
Therefore, if you need a "New File" feature in your application, look no further than the prepackaged solutions above!