CTRL+TAB tip
Probably the last tip is the IDE status bar that could help you in situation, where you have opened more files with the same name. The status bar displays full file path of the selected file in the popup window that is displayed during switching between opened files in the editor through CTRL+TAB short cut.
I have also created four issues, the issue #178090 that explains the problem and is basically umbrella for three issues:
- #178091 - Display in title bar path for the edited file
- #178093 - Display in the window with open file list (CTRL+TAB) path of the selected file
- #178094 - Provide file navigator bar
If you have any comment about this issues, please write the comment directly into the issue. It's much better if it looks like that the issue is a voice of our users, then it looks like an idea of a NetBeans developer:).
Select edited file in Project view, Files view or Favourite view
Yesterday I wrote about option Synchronize Editor with Views and Carlos imentioned the shortcut CTRL+SHIFT+1 in his comment. The shortcut is active, when you are in the editor and selects the edited file in Projects view that obtain also focus. So the difference between Synchronize Editor with Views and this shortcut is that the focus is changed.
In similar way shortcut CTRL+SHIFT+2 works too, but it opens the Files view and selects the edited file there.
And CTRL+SHIFT+3 selects the edited file in the Favourite view. If the file is not in the Favorite view yet, then Add to Favorites dialog is opened. Then you can put directly the file to favorites or a selected folder.
Synchronize Editor with Views
There is one requirement to see a part of file path as name of tab of opened editor to simply recognized the file that is opened. Sure there is a tooltip, which shows the full path of the file, but the mouse has to be used to display the tooltip. This is mainly needed, when there are opened many files with the same name.
Although there is not such functionality yet, there is Synchronize Editor with Views option that could help you. You can find it in View menu and if the item is checked, then in Project view and File view is automatically selected the file that is in the editor.

It doesn't correspond exactly to the requirement that is mentioned above, but it can help in some cases.
Removing Trailing Spaces
Last week, when I was at the IPC 2009 conference, a some user ask me whether NetBeans removes trailing spaces. It was one question from many and I would like to clarify how it works in NetBeans 6.0 - NetBeans 6.8.
Basically it works automatically on save. So when you invoke Save action then the trailing spaces should be removed from the file. There are two exceptions, when the spaces are not removed from a line:
- The line wasn't changed. The main reason for such behavior is that usually you don't want to have unnecessary changes in the diff, if the files comes from a VCS. So unchanged lines are not touched and if there is a space at the end of such line, then is not removed. When you edit the line then the spaces are removed on save as well.
- The line where the caret is located. When you invoke Save action, then the position of the caret is not changed. But all trailing spaces after caret are removed.
If you want remove all trailing spaces in the file, you have to invoke action Remove Trailing Spaces from Source menu by hand.
Flickr Slideshow with NetBeans IDE 6.5
Keyboard Shortcuts Learning
Keyboard shortcuts make your every day life easier, so it make sense to improve your key learnings.
PHP Magazine collected list of Netbeans keyboard shortcuts that could save you a lot of time.
Shortcuts for Mac OS X users.
The ultimate way how to learn keyboard shortcuts for your version of NetBeans is to check out the available shortcuts in Tools->Options->Keymap.
[Read More]
How to Include File
How to include file in PHP NB IDE? Two ways:
- file system code completion for include/require
- Fast Import Alt+Shift-I
How to change look and feel of NetBeans
If you want a different appearance of NetBeans than it is the native one you can simple change the look and feel (L&F). There can be also another reason for changing look and feel due to a bug in Windows L&F. When you are on Windows machine and you use the native Windows look and feel you can run into a problem with focus. Switching between NetBeans IDE and for example Firefox using Alt+TAB and sometimes when switching back to the IDE instead of being focused in the editor where you left it, the menu is focused instead.
Some L&Fs are available in Sun Java and many L&Fs are available on internet. Using L&Fs that are in Sun JDK is simple. You should know which Java you use and which version. For example Nimbus L&F is available from Sun JDK 1.6. You can run NetBeans with this L&F in two ways. The first one is running NetBeans from command line with --laf option. This way is sufficient, if you want to just try a L&F. So on *nix OS it's :
/path_where_netbans_are_installed/bin/netbeans --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
The second way is put the --laf option to the netbeans.conf file. The netbeans.conf file is located in etc folder in NetBeans installation folder. Open the netbeans.conf file and add the option into netbeans_default_options. When you do it in this way, then it's permanent and NetBeans will always start with this L&F.
There are a few screenshots of NetBeans with some L&F, which are available in Sun JDK 1.6.
Nimbus: --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel

Metal: --laf javax.swing.plaf.metal.MetalLookAndFeel

GTK: --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel

As I wrote above, we are not limited only with L&Fs, which are available in a JDK. You can dowload different L&Fs from net. Some of them are open source and free, but there are also commercial. If you want to use such L&F, you have to download a jar that contains the L&F definition and put it on NetBeans classpath. When you want to try a L&F on the command line, then you run NetBeans also with -cp:p path_to_L&F_jar option, which adds the jar on the NetBeans classpath. For example the command for using Liquid L&F will be:
/path_where_netbans_are_installed/bin/netbeans --laf com.birosoft.liquid.LiquidLookAndFeel -cp:p /path/to/liquidlnf.jar
You can put both options into default netbeans_default_options in netbeans.conf file, if you want to use command line.
There are a few examples. You can download the jar from the projects page and play with them.
Liquid: --laf com.birosoft.liquid.LiquidLookAndFeel -cp:p /path/to/liquidlnf.jar

Napkin: --laf net.sourceforge.napkinlaf.NapkinLookAndFeel -cp:p /path/to/napkinlaf.jar

NimROD: --laf com.nilo.plaf.nimrod.NimRODLookAndFeel -cp:p /path/to/nimrodlf.jar

Quaqua: --laf ch.randelshofer.quaqua.QuaquaLookAndFeel -cp:p /path/to/quaqua.jar

If you find a nice L&F, write me, I will add the screenshot here.
ANT support in PHP projects
A build tool can be used for automated actions. For example if you want to have continual build and run tests, building documentations, create a production builds, deploy on a staging or production server etc. One of such build tools is Apache Ant, which is a Java-based build tool. You can use this tool also together with your PHP projects. The NetBeans PHP distribution is probably only one distribution, which doesn't contain the Ant support by default.
Adding Ant into the IDE is very simple. Open the plugin manager (Tools->Plugins) and on the Available Plugins tab in the Search dialog write ant. After this, you should see similar picture to:

Check the Ant item and click on Install button. After accepting the license, the needed module are downloaded from the update center and installed. If you have already an ant file in your project it should be after the installation recognized.
Although the Ant files are xml files, they have a special icon in NetBeans. You can expand the node that represents the Ant file in explorer and the subnodes are the targets defined in the script. You can run single target and also you can assign a shortcut for a target through the context menu over the target node.

The editor offers code completion for Ant tags and also for their attributes. You can also validate and check whether the file is well formed.

There is one limitation in PHP distribution. The PHP project doesn't allow to create Ant files through a wizard. So you have to create new well-formed xml document. The root element has to be <project>.
Does someone from readers use Ant together with PHP projects? Do you use a building tool? Which one?
Generating PHP documentation from NetBeans 6.5
NetBeans 6.5 doesn't have direct support for generating PHP documentation. Here is a trick how to do it. Basically I use a new Run Configuration that calls a small script to generate the documentation. I did this on my Ubuntu machine, but Windows users should be able to reuse the steps.
At first I downloaded the PHPDocumentor itself from the project pages, unzipped the zip file and change the rights of phpdoc to be executable.
For the next step I created a new bash script which I call from NetBeans. You can write the script directly in NetBeans. NetBeans PHP distro includes very simple syntax coloring support for bash script and bat files as well. The picture below displays NetBeans PHP RC2, showing my phpdocNB.sh script that I use for generating the documentation.

The text form of the script:
#! /bin/bash # Script for generatig php documentation from NetBeans through run configuration PATH_TO_PHP_DOCUMENTOR=/space/php/phpdocumentor/PhpDocumentor $PATH_TO_PHP_DOCUMENTOR/phpdoc -d $2 -t $3 echo "Generating PHP Documentation finished ..." firefox $3/index.html
As you can see the script is very simple. If you want to use it, you should just change the value of PATH_TO_PHPDOCUMENTOR variable to pick up the phpdoc script from your location. Through the -d parameter you define which directory will be parsed (and subdirectories) and -t parameter says in which directory the PHPDocumentor should create the documentation files. When the generation of the documentation is finished than the result is opened in new Firefox tab to check the result.
Now, when the script is done, I need to call it from NetBeans. As I have mentioned we can use for this new Run Configuration. There are three ways how to display Project Properties dialog where you can create it. You can select the project node and in the context menu over this node invoke Properties item or from main File menu choose Project Properties item or in the main tool bar there is combobox with already existing configurations and the last item in the combo box is Configure... item. The combo box in the main tool bar is a way how to quickly switch between configurations.
So in the Project Properties dialog click on the Run Configuration category and create new configuration through the New... button. I have named the configuration PHPDocumentor. In the Run As combo box select Script (run in command line) item. Uncheck Use default PHP Interpreter and browse the created script. As the first argument put the path of your project sources. You can copy the path from the Source category panel, Source Folder text field. As the second parameter put a path, where you want to generate the documentation. The folder doesn't have to exist, the PHPDocumentor will create it. The picture below shows my PHPDocumentor configuration.

NetBeans will put for the script as the first argument the Index File, when you run project with this configuration or the file for which you invoke Run Single File action. This parameter is in my script simply ignored and always the documentation is generated for all sources.
Now when I choose the PHPDocumentor configuration in the combo box in the main tool bar and run the project, then the documentation is generated and the result is opened in new Firefox tab.

You can improve the script and add more parameters, it's all up to you. I know that this is not the ideal support of PHPDocumentor, but for the next verion I want to make the real integration. If a Windows user out there will write the bat file, could you please attach the file in a comment, and I will alter this post.
Install Apache on Windows Vista
This night I have tried to install Apache and PHP on a Windows machine with Vista. I thought that it will take just few minutes as it usually takes on Ubuntu, but it was not. I wanted to install the Apache to the default location (C:\Program Files/Apache Software Foundation/Apache...). The reason for this was that NetBeans is looking in the default instalation location and if exists, then it offers in new project wizards etc.
So I downloaded the msi installer of Apache and run it. The installation executed nice and correctly. The Apache was running and the url http://localhost shows known page It works! .
But when I tried to copy a file to the document root or create the project from NetBeans inside document root, then it failed. OK, it will be due to a rights permitions, I thouhgt. I noticed that htdocs folder is marked as read only. I opened the folder properties and uncheck the Read Only checkbox. Windows displayed nice progress bar that showed the progress of setting read only attribute to false for all files in the folder as fell. So I tried to copy a file into htdocs folder. It failed! The folder was still marked as read only. Hmmm, strange Windows didn't inform me that the previous action failed. So I tried to change the read only attribute for Program Files and all subfolders in Apache folder. The same result. Still were read only, even that Windows showed the progress bar, no failed message.
Now was the time to use Google:). It was surprising for me that many people had exactly the same problem as I. Some of them give up and recommend to install back Windows XP. But then I have found the solution. On Molecular Sieve blog is an entry with steps how to solve the problem. Big thanks to author for this.
After applying the steps I can copy files and create project in the document root of Apache, which is installed in the default location. Still the folders are marked read only, but write in the folder is possible :).
During this exercise I found a few interesting information. Like that the msi installers install the applications as SYSTEM user, which is something like root user in linux. After the installatin the Apache is running with all priviliges as SYSTEM user has and the php and other cgi scripts has also rights of SYSTEM user. Is not very save to expose such Apache publicly. You can find at internet steps how to solve it.
What is your experience with running Apache, XAMP under Vista?
Code completion for a class field
NetBeans are able to offer code completion for class fields of a PHP class. Because PHP is not a strict typed language, you can help to NetBeans to find out the type of a field.
Let's have a simple example:
The example doesn't show good practice, because the class fileds shouldn't be accessible outside the class, but for explanation it's enough.
One way how NetBeans are trying to find out the type of a field is that it looks through the class constructor. In our case in constructor there is expression that assigns new Address object to the $address field. So NetBeans supposes that the field is Address type and code completion for $this->address-> suggests $street and $city fields from Address object.

This functionality was added recently and works only in the file, where the class is defined and still there is a space for improvements.
The second way is to specify the type of a field through PHP Doc. It's more universal, the field doesn't have to be initialized in the constructur. As you can see on the picture, the type is also displayed in the code completion window. NetBeans helps to write the PHP Doc, write /** one line above the field and press ENTER. Then NetBeans will generate appropriate PHP Doc. Also you can use code completion after @var tag to obtain all available types from the project in the code completion.

How to create project for every WordPress plugin
In the previous entries about WordPress I have describe how to develop a WordPress plugin inside WordPress. This entry describes how to set up a project in NetBeans for every plugin separately.

Let say that I develop many WordPress plugin. The folder structure is displayed on the picture.
I have folder WordPressPlugins that contains all plugins which I develop. Also I have one copy of WordPress sources in WordPressSources folder jut only for development reason. I will explain the reason later.
Then there is wordpress folder under Apache document root, which is accessible through the URL http://localhost/wordpress.
Now create the next plugin. Open new PHP Application wizard and call the project for example AnotherWPPlugin. The source folder for the project will be under the folder, where all WordPress plugins are developed. NetBeans will create in WordPressPlugins folder AnotherWPPlugin folder with the sources and nbproject folder for NetBeans metadata. The second step in the wizard should look like on the picture.

Basically similar approach is if you want to create project for an already existing plugin.
In the next step you specify, how the project will be run. Run Configuration should be Local Web Site. The WodPress is reachable under http://localhost/wordpress URL. Also you have to say to NetBeans that the plugin sources has to be copied to the WordPress. So check the Copy files form Source Folder to another location and browse the plugins folder under the Apache's documented root.
So the third step of the wizard should look like:
After creating the project go to the Project properties and add the WordPressSources folder into Include Path. The reason is that we want to have the WordPress API in code completion. Sure we can put into Include Path the wordpress folder located under the Apache's document root, but then you will see the statements from the developed plugin in code completion twise. The first one from the sources folder and the second one from the plugins folder under document root.

NetBeans will create index.php file. You can use it and change the content to be an entry point for the plugin. More here.
How to make the default font size bigger
Sometimes I need to increase the default font used in NetBeans. For example for a presentaion. Fortunatelly it's simple to change the default font size used in editor, menus, dialogs, etc. You can run NetBeans with argument --fontsize xx, where xx is the required size. The --fontsize argument applies to fonts used in menus, dialogs and most components in the IDE.
You can run NetBeans with --fontsize from command line:
on Windows:netbeans.exe --fontsize 14on a linux machine:
netbeans --fontsize 14 Or you can set this option permanently in netbeans.conf file.
Gnome Specific
If you are running NetBeans under Gnome with the GTK L&F, then NetBeans uses the default Gnome settings including font size. If you want to change the font size for NetBeans you must change font size in Gnome Preferences -> Appearance -> Fonts. Alternatively you can use Metal L&F with --fontsize option. Use --laf jvax.swing.plaf.metal.MetalLookAndFeel to run with Metal.
Anti-Aliasing Font in the Editor
NetBeans editor follows the system setting of anti-aliasing font. On windows you have to set up ClearType method to smooth edges of screen fonts, which is not the default value on Windows XP. I think that Windows Vista uses ClearType method as the default one. Also the default value in both cases can depend on your hardware. To change the method go to the Display Properties and in Appearance tab open the Effects dialog.

When there is the default value Standard, then NetBeans doesn't provide anti-aliasing. The picture below shows the IDE without anti-aliasing or when the method to smooth edges of screen fonts is Standard on Windows XP.

The next picture shows the IDE, when anti-aliasing is switch on.

It's better to see the differences, when the picture is zoomed.

The native anti-aliasing on Windows is available from JDK 1.6 (Update 10). You can disable it, when you start NetBeans with -Dawt.useSystemAAFontSettings=false from command line (netbeans.exe -J-Dawt.useSystemAAFontSettings=false) or you can also add this property to the netbeans.conf file.
If you use Gnome, then the method of anti-aliasing you can set up in System -> Preferences -> Appearance.

If you don't like the NetBeans default font, you can change it in Option dialog -> Fonts & Colors tab. In the Category list select Default item and change the font.

For example this is Lucida Console 14.

