Bug 186943 - Creating new file without opened project
Creating new file without opened project
Product: projects
Classification: Unclassified
Component: Generic Projects UI
PC All
: P1 with 16 votes (vote)
: 7.4
Assigned To: Milos Kleint
: 51978 186944 (view as bug list)
Depends on:
Blocks: 214254
  Show dependency treegraph
Reported: 2010-05-29 19:28 UTC by rozwell
Modified: 2013-02-02 02:35 UTC (History)
7 users (show)

See Also:

Initial patch to demonstrate proposed new behavior (55.27 KB, patch)
2013-01-19 19:03 UTC, 280Z28
Details | Diff
Preparatory patch with common annotations (21.09 KB, patch)
2013-01-28 19:09 UTC, 280Z28
Details | Diff
Patch to fix this issue (47.91 KB, patch)
2013-01-28 19:10 UTC, 280Z28
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description rozwell 2010-05-29 19:28:48 UTC
When there is no project opened, creating new file option is inactive.

I was about to mark this as enhancement, but I noticed you can still open a file so it should be allowed to create new one.
Comment 1 rozwell 2010-05-29 20:28:30 UTC
It's pretty much connected with enhancement I reported:
Comment 2 Victor Vasilyev 2010-06-01 09:23:50 UTC
*** Bug 186944 has been marked as a duplicate of this bug. ***
Comment 3 Victor Vasilyev 2010-06-01 11:55:14 UTC
Seems this bug describes an area where we need have a reasonable agreement.

Power of an IDE is defined by ability to provide various services during development of projects. Opening of a project indirectly instructs IDE which services should be activated to help a user in development. Note, very different services may be useful for the same source if it will be used as a part of different projects, e.g. support of the php statements in an html file has not any sense if this file is a part of pure Java application that knows nothing about php. Moreover, in case of pure Java application the php support will give misleading results that should be considered as a bug. 

Also, the NetBeans IDE relies on MIME type of a file to provide development services for it. In many cases, recognizing of the MIME type is based on an extension of the file. MIME type of a file will be unknown until the file is not saved, i.e. a file name should be associated with the source text to know its MIME type. Hence, for unsaved files, in many cases, you will see only uncolored plain text without any support from IDE's side. I'm sure, it is not what you wish to see in the NetBeans IDE.

I think, a development pattern used in the NetBeans IDE, i.e. 
an idea -> project -> development of project's sources, is absolutely correct. Note, it encourages you to have clear development plan when you start new project. But, if you have clear development plan for your project the creating of the files outside of the project is never required!

I'll close this bug, but feel free to re-open it if you'll have valuable counterarguments or a brilliant idea how to avoid all problems described by me above.
Comment 4 rozwell 2010-06-01 15:15:51 UTC
About development, you're absolutely right.

I mostly work with projects but sometimes I need a simple structural code to type or paste somewhere (even without saving it).

These are just some of features I'm missing from Zend Studio.
Because I like NetBeans more, I wish it was 'the only editor you need'.
With that little improvement, it is possible.

What if we could choose file MIME during creation?
File -> New -> Choose MIME (this system already exists but forces to save a file and list is limited to project needs)
When no MIME is chosen, plain text will be used until file is saved and it's extension recognized (notice: even plain text has it's usability as temporary clipboard).

Here comes another feature - changing file MIME during edition. It's not something I personally need in NetBeans but maybe... Check this:

Kate (Kubuntu basic editor) has this ability already and it works well (but only for syntax highlight): when you create new file - it's plain text until you choose what type is it (from menu) or save so it's recognized automagically.

IMHO that way NetBeans will be able to support basic features like syntax highlight and native functions autocompletion.
Note it's only about those two features above. I'm not sure what else can work without a project but if someone needs more - he needs project.

About creating file without a project, I still don't understand why it's not possible (yet? ;) but opening file is. Now I need tu use other editor to create file just to open it in NetBeans...

What do you think?

I hope I didn't miss anything, did I?
Comment 5 tk_fhd_aui 2010-07-28 06:48:26 UTC
Some arguments for "New File" without project:
1.) It is already possible to create a "New File" (empty file, folder) without a project through the context menu of the favorites window. It is a bit inconsistent to not allow this through the menu bar when a DataFolder is selected in the favorites window.
2.) e.g. a XML, HTML, CSS, JavaScript, ... File does usually not require a project to be edited.
3.) There can be platform applications which require to create "New File"s, but do not require a project, e.g. because they e.g. only use the favorites window.


P.S.: BTW, should not Platform and OS be set to "All"?
Comment 6 tk_fhd_aui 2010-07-28 07:13:40 UTC
Wiki Article about this issue: http://wiki.netbeans.org/EditingFilesOutsideOfProject
Comment 7 rozwell 2010-07-28 12:00:48 UTC
I just selected my Platform and OS at first.
Comment 8 vincesheard 2011-09-02 02:18:59 UTC
There are often times I want to create some file which is in a different directory, using NetBeans as a generic text editor.  I do this in a proprietary IDE all of the time, but have never been able to do this in NetBeans.
I would not say that is has to support the syntax highlighting or IDE navigation features. 
It saves moving out of the editor to create a simple file.
Comment 9 johnd 2011-09-02 11:40:32 UTC
I often use a different IDE to create text or other file types outside of an existing project.   These files may be simulation stimulus or notes which exist in different directories which I need to create and read while debugging.   I have been struggling with Netbeans whenever this situation occurs since I can't seem to create files outside of my current project.

Please consider adding this capability. 

Comment 10 rozwell 2011-09-02 12:03:02 UTC
Guys, use the "vote" (next to Priority) please.
Comment 11 leetercola 2012-01-31 18:29:16 UTC
I will give you the single greatest use case of this feature. "FORMAT" there is no other free IDE that offers the ability to "pretty print" so to speak. This is vital for code that isn't yours or just got out of hand. Vital in finding mismatched tags, and seeing a visual nesting of code. Yes it can be done in other IDE's and text editors but not nearly as cleanly as in netbeans. I don't have to add a script, wade through settings, plain and simple I just right click format. My source code is now under control. 

The short version of that is, this has to be an easy action to add to the platform. Add new file, its so basic why not add it. Users want it, that should be reason enough. It saves me moving to another "anything" to create a file, only to turn around and open it with netbeans. This has been the only reason I've ever used another IDE, this singular missing feature.
Comment 12 thegame 2012-05-06 06:28:44 UTC
i think every other editor has the option to create a new file without a project for quick and simple testing purposes. It wouldn't hurt to simply add it on.
Comment 13 martez81 2012-06-09 15:19:34 UTC
I'm not a fan of using several code editors to do my job. I always tried to pick one and stick to it. After years of using dozens of editors I settled on Netbeans IDE. I work a lot with PHP where creating new projects is not always necessary. Many times I want to create one-off file to do some prototyping, testing etc. I actually tried convincing my co-workers to switch to Netbeans. They really loved the features but not being able to create a new file was something mind boggling to them (most of them stayed with Notepad++). I think adding this feature to the software would be not only a great addition but could potentially expand the user base.
Just my 2 cents.
Comment 14 Matchlighter 2012-09-20 05:12:21 UTC
I also agree that this would really make the IDE better. It dives me nuts to have to have the new file associated with a project in order to put something temporarily or create a file that isn't supposed to be associated.
Comment 15 Ondrej Vrabec 2012-12-19 12:33:04 UTC
I believe the relevant code is in projectui/src/org/netbeans/modules/project/ui/actions/NewFile.fillSubMenu called from NewFile$WithSubMenu
Comment 16 Ondrej Vrabec 2012-12-19 12:42:05 UTC
BTW, what's the problem with creating a php file the following way:
1) Open the folder in the Favorites
2) Select New -> Empty File... from the popup menu
3) Name it myFile.php ???
It is created outside any project without problems. True, you won't have the pretty cool wizard, but i don't think it's necessary here. So IMHO this is already a WORKSFORME
Comment 17 rozwell 2012-12-19 13:48:30 UTC
(In reply to comment #16)
> BTW, what's the problem with creating a php file the following way:
> 1) Open the folder in the Favorites
> 2) Select New -> Empty File... from the popup menu
> 3) Name it myFile.php ???
> It is created outside any project without problems. True, you won't have the
> pretty cool wizard, but i don't think it's necessary here. So IMHO this is
> already a WORKSFORME

There is none, except who knows about it? It's not intuitive.
I've been using NetBeans for a couple of years now and I never find out this method.

And sorry, I couldn't resist: (when the doors are locked and you someone suggest to fix them)

BTW, what's the problem with getting into a car the following way:
1) Find your car
2) Get your keys -> open the trunk
3) Crawl inside ???
It is doable without problems. True, you won't have the pretty cool entrance, but I don't think it's necessary here. So IMHO this is already a WORKSFORME
Comment 18 rozwell 2012-12-19 13:50:09 UTC
*and someone

Hate the non-editable posts...
Comment 19 vincesheard 2012-12-19 14:34:13 UTC
As you say there is a way. 
What is wrong with having other ways of doing the same thing. If it exists can you not provide the hook in another place?
If it is not intuitive, many customers will not find it, if ever.
Why create barriers for an engineer to do his work.
Comment 20 Milos Kleint 2012-12-19 15:28:42 UTC
NewFile.fillNonProjectSubMenu() is responsible for creating a non-project action submenu. New file and New Folder are hardcoded there. Also please note that both use a special UI (NoProjectNew.java) that is different from the regular project based UI.

I can imagine a solution where we somehow denote wizards that can be triggered outside of the project space and use them, it should be fairly straightforward on the general UI side, however the majority of work has to be done by the owners of the individual wizards (file types) making sure the wizard works both within and outside of projects.

Also please note that netbeans doesn't know the concept of file-less editing buffers and every document opened in editor is backed by a file. That's something that's unlikely to be changed in the future.
Comment 21 rozwell 2012-12-19 15:38:06 UTC
> Also please note that netbeans doesn't know the concept of file-less editing
> buffers and every document opened in editor is backed by a file. That's
> something that's unlikely to be changed in the future.

Shouldn't temp file do the job?
I guess acting like it wasn't saved would be enough.
Comment 22 David Konecny 2012-12-20 04:26:05 UTC
Could you help me please understand better the usecase? Is the usecase really #1) "allow user to create a new file anywhere on the disk via New File wizard" or is it rather #2) "allow user to create a blank NetBeans editor with customizable 'file type' and memory only data so that user can experiment with some code and later drop it or save it via Save As"? Or is there option #3? Many comments in this issue indicate that #2 is the usecase.

In usecase #1 I find the final workflow quite cumbersome. Or perhaps I do not understand how such feature is going to be used. Let say user created a file somewhere on the disk from NetBeans and saved it and closed it. Now, the only way to re-open this file later is via File Open or Recent Files but if user is going to work this way with multiple files then quickly this become very frustrating. Compared to that Favorites view has few advantages - it is not whole filesystem; and only "relevant folders" user works with are shown.

I personally need to experiment with code too but I always create a new project for it - it's three clicks in a wizard and I have a folder into which I put some more useful experiments for later reference; the throw away ones I create directly in /tmp folder. I prefer a project over Favorites view but then most of my experiments are Java classes.

Comment 23 280Z28 2013-01-07 13:51:55 UTC
(In reply to comment #16)
> BTW, what's the problem with creating a php file the following way:
> 1) Open the folder in the Favorites
> 2) Select New -> Empty File... from the popup menu
> 3) Name it myFile.php ???
> It is created outside any project without problems. True, you won't have the
> pretty cool wizard, but i don't think it's necessary here. So IMHO this is
> already a WORKSFORME

I'm using NetBeans as a text editor platform for a certain file type because it offers several features for plugin developers that make developing a cross-platform editor relatively straightforward.

1) You are not the user of my NetBeans platform application.

2) The actual users of my NetBeans platform application understand File -> Open File just fine, but about 10 seconds after launching the application for the first time they have to decide whether creating their files manually outside the IDE is acceptable.

I'm losing users at an alarming rate because there are actually people who question why the "New File" command should be enabled next to the existing (and already enabled) "Open File" command.
Comment 24 Milos Kleint 2013-01-09 13:43:21 UTC
I suppose we have multiple usecases here all mostly related to php development.
1. create a file-less buffer.  Not possible now, if ever supported, needs to be done by the editor team. Picking the right mime type for the buffer is part of the problem.
2. create a file outside of the project for experimentations.. 
I'm not entirely sure why adding such file to existing project is not an option. Since mostly one will have a project opened anyway.

Any non-project based file will be severely limited in features supported. Including completion, coloring, project formatting rules, generators etc. also execution/debugging will be limited/not supported. (I suppose even for stuff like php).

Can some of proponents of the feature experiment with the approach suggested by ovrabec in comment 16 and comment if the editor support and IDE support in general is actually on the level expected or below.
Comment 25 280Z28 2013-01-19 19:03:25 UTC
Created attachment 130402 [details]
Initial patch to demonstrate proposed new behavior

I created an initial patch to improve support for the New File command when no project is open. It involves the following primary changes.

* When one or more projects are open, this patch does not change the behavior from before.

All of the following apply only When no project is open:

* The same New File wizard from when projects are open is used, project selector combo box is empty and disabled.

* The preselected target folder is the user's home directory.

* The "Browse" button for selecting a target folder uses FileChooserBuilder instead of presenting a list of folders in the current project.

* An absolute path for the target folder is treated as an absolute path; otherwise it is evaluated relative to the user's home directory.

* Support a new file attribute "requireProject" for template registrations in the XML layer. Only templates with this value explicitly set to false are shown in the list of available templates when no project is selected. If this value is not specified, it is assumed to be true (i.e. the template is not shown when no project is open). This is the only safe default behavior since several custom wizard iterators assume a project is open.

* Add a new boolean element "requireProject" to @TemplateRegistration, default value true (non-breaking change).

* Update TemplateHinter (automates conversion XML Layer registration to @TemplateRegistration) to specify the requireProject element of the annotation if it's present in the XML Layer.

* Update the registration of several default templates which work without projects and might make sense as "loose" files. This includes "XML/XML Document", "XML/XML Schema (empty)", "XML/DTD Entity", "XML/XSL Stylesheet", "XML/XML Parsed Entity", "Other/HTML File", "Other/XHTML File", "Other/JavaScript File", "Other/JSON File", "Other/Properties File", "Other/Cascading Style Sheet", "Other/Empty File", "Other/Folder", "User Configuration Properties/User.properties"
Comment 26 Milos Kleint 2013-01-22 09:28:54 UTC
*** Bug 51978 has been marked as a duplicate of this bug. ***
Comment 27 Jesse Glick 2013-01-22 15:13:22 UTC
Nice, this is what I had in mind in bug #51978 comment #7.

[JG01] Additions of @org.netbeans.api.annotations.common.*, e.g. to projectapi, should ideally be a separate preparatory patch.

[JG02] The code

  requireProject != null && !Boolean.parseBoolean(requireProject.toString())

should rather be


since there is no reason to allow stringvalue="false" here.
Comment 28 280Z28 2013-01-22 15:49:27 UTC
Re [JG01]: I wanted to implement the annotations as a separate patch, but the majority of annotations in place after this patch actually changed as a result of the patch - many methods which required non-null arguments now support null arguments. If you still want the patch separated in light of this, I can do so and make sure the preparatory patch is adjusted to contain the proper preconditions from before this patch.

Re [JG02]: What is the expected workflow on this? Should I make/attach a new patch with this corrected, replacing the original patch?
Comment 29 Jesse Glick 2013-01-22 16:31:14 UTC
JG01: do not bother in this case I guess, just general advice.

JG02: yes it is customary to attach a complete corrected patch (marking the previous one as obsolete).
Comment 30 Jesse Glick 2013-01-22 16:32:13 UTC
BTW this is an API change (in @TemplateRegistration) so there are a few extra steps: new spec version in openide.loaders, @since in Javadoc, apichanges.xml entry.
Comment 31 Milos Kleint 2013-01-24 08:29:41 UTC
MK1: there's a few calls like this to FileUtil.toFileObject():
FileUtil.toFileObject(new File(gui.getTargetFolder()))
I believe it's necessary to include FileUtil.normalizeFile(new File) in the middle to ensure that the File instance is normalized, otherwise assert will be thrown.

MK2: when running in without projects a suspicious category/entry appears "User properties" or alike, I believe you have added the require project attribute to some wrong template..
Comment 32 280Z28 2013-01-24 08:36:48 UTC
Sorry I haven't had the chance to update the patch. I'm in the middle of a product release which should be done later today.

Re MK1: I'll take a look and fix this.

Re MK2: The User properties template works the same with or without a project open. If the user wants to use NetBeans as a quick text editor, it seems like a waste to hide working templates from them.
Comment 33 Milos Kleint 2013-01-24 08:39:52 UTC
MK3: 280Z28@netbeans.org, have you signed the contributor agreement? (see [1]). if so, how can I verify at [2]? if not, you will have to before I can apply the patch.

[1] http://wiki.netbeans.org/NetBeansDeveloperFAQ
[2] http://www.oracle.com/technetwork/community/oca-486395.html?
Comment 34 Milos Kleint 2013-01-24 08:48:35 UTC
(In reply to comment #32)
> Re MK2: The User properties template works the same with or without a project
> open. If the user wants to use NetBeans as a quick text editor, it seems like a
> waste to hide working templates from them.

See http://screencast.com/t/1MmzbwJ7X the given category and template is not present when project is opened and it should not be in this case either.
Comment 35 280Z28 2013-01-24 08:49:40 UTC
Re MK3: I have, my username (280Z28) is listed on [2].
Comment 36 280Z28 2013-01-24 08:54:53 UTC
Interesting. I see the User.properties template registered Layer.xml for the Favorites module. Do you know which part of the declaration of that entry indicates that the template should not have requireProject=false? My guess is the following line, but I'm not sure what the specific impact of it is:

<attr name="templateCategory" stringvalue="helper-files"/>
Comment 37 Jesse Glick 2013-01-24 16:11:33 UTC
MK2: this file exists only for the Settings button in Template Manager. It is not a real template and should not be shown as such; do not add requireProject=false to it.
Comment 38 280Z28 2013-01-25 23:46:14 UTC
I finished everything except for the update to apichanges.xml. Can you provide feedback on this entry? I am unsure of the api name, author login, and compatibility values.

<change id="TemplateRegistration.requireProject">
    <api name="awt"/>
    <summary>Allow registration of templates which do not require a Project instance</summary>
    <version major="7" minor="46"/>
    <date day="25" month="1" year="2013"/>
    <author login="280Z28"/>
    <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
        <p>Templates may be registered with <code>requireProject = false</code>
        in the annotation to indicate the template does not require a Project
        instance to be created. These templates show in the New File dialog
        even when no project is open in the IDE.
    <class package="org.netbeans.api.templates" name="TemplateRegistration"/>
    <issue number="186943"/>
Comment 39 Jesse Glick 2013-01-28 16:19:05 UTC
<api name="loaders"/> (I guess, this is barely used anyway).

<author> and <compatibility> are fine.

<date> would be actual date of commit; committer is responsible for updating that, as well as double-checking that the spec version is one more than the actual starting version just prior to commit (in case other API changes or updates are done in the meantime).
Comment 40 280Z28 2013-01-28 19:09:53 UTC
Created attachment 130743 [details]
Preparatory patch with common annotations

This patch uses annotations matching the original version of the code. Some of the annotations added in this patch are immediately changed by the next patch; the advantage of this is it's easy to see which preconditions are relaxed by allowing the New File command to execute without any projects open.
Comment 41 280Z28 2013-01-28 19:10:52 UTC
Created attachment 130744 [details]
Patch to fix this issue

The preparatory patch must be applied before this patch.
Comment 42 Milos Kleint 2013-01-29 10:10:08 UTC
thanks, looks good to me now.
Comment 43 Milos Kleint 2013-01-30 15:47:19 UTC
just for future patch submissions, the username should be Sam Harwell <280Z28@netbeans.org>, meaning an address from netbeans.org domain. See [1]. No need to update the patches, I've done it locally before applying the changeset however if you would try pushing with the old value, the server would reject it AFAIK.

I've applied the patches.


[1] - http://wiki.netbeans.org/HgHowTos
Comment 44 Quality Engineering 2013-02-02 02:35:32 UTC
Integrated into 'main-golden', will be available in build *201302020001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/fe4c239c02f7
User: Milos Kleint <mkleint@netbeans.org>
Log: #186943 remove assert, project can be null now

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo