Thursday Oct 20, 2011

Rectangular Selection

If you use development build, you probably noticed that NetBeans editor added Rectangular Selection action. I don't need this functionality every day, but it can be helpful in some case. One of such case is when you need to delete line numbers in a text  or code copied from  a tutorial. Like on the picture below.



You can select the rectangle after pressing Rectangular Selection toggle button in the editor toolbar or pressing CTRL+SHIFT+R shortcut. 



The selection can be easily done with mouse or keyboard. When you use keyboard, just place the caret on a corner, keep down SHIFT  and with the arrows keys you select what you need. 



When the selection is done, you can easily delete all the line numbers with pressing DELETE key. Then you have to exit from the rectangle selection mode (CTRL+SHIFT+R or toggle button in the editor toolbar).


If you write a text , then the text is placed on every line in the selected area. This can be useful for example for changing access modifiers of more fields in a class at once. 



Do you use the rectangular selection? For which cases? 

Thursday Jun 02, 2011

Adding a ShortCut for Generation PHP Documentation

This is a tip how to add a shortcut for generating PHP Doc for  a class or method / function. Probably every body who uses PHP editor in NetBeans knows that if you write start of PHP Documentation /** just before a class or method/function and hit ENTER, then NetBeans tries to finished the PHP Documentation and adds PHP Doc tag, if there are needed.

This feature is not implemented as an action, it's based on the code that checks what is written on the line after pressing ENTER key. And because it's not an action, it's not possible to assign shortcut for it. If you want to use a shortcut, you can use editor macros. An editor macro is sequence of pressed keys and actions in the source editor and you can assign a shortcut to the macro.

By default the editor toolbar contains buttons for recording macros.

Start the recording of new macro through pressing Start Macro Recording button. Press type in editor /**, press ENTER key and then stop the recording through Stop Macro Recording button.

In the New Macro Dialog place name of the macro. I have called it PHP Doc.

Through the Set Shortcut ... button assign a short cut. In my case I have used ALT+D combination. You don't have to write it in the Shortcut text field, it's enough to press the combination of keys. Close the dialog and you are done.

Now if you have cursor just before a class or method or function and press ALT+D shortcut the PHP Doc is generated. Like in the picture below.

If you want to change the shortcut, edit or delete a macro, you have to go to the Tools->Options dialog, Editor category and choose Macros tab.

The macros are more powerful, but this is a small example how can use it. Hope that it will be helpful for someone.

Tuesday May 24, 2011

Using Tabulator for Indentation

Yesterday I run into an issue that a user wants to use tabulator character for indentation level. Because I answer similar question often, I will try to explain it here. 

By default NetBeans editors use for indentation level 4 spaces and don't use tabulator character (\t). When you press Tab key, then NetBeans place caret on the column that corresponds to the next indentation level and the difference is filled with spaces. So by default pressing Tab key adds 4 spaces.  

If you want to use tabulator, you have to change the default behavior in Tools->Options->Editor->Formatting Tab. See the picture below, where are the default values.

Notice that by default the property Tab Size is setup to 8. This is because the standard size of tabulator is 8 characters wide. So when you want to use tabulator for every indent level you have to uncheck Expands Tabs to Spaces check box and you have to decrease the Tab Size property to 4 or increase Number of Spaces per Indent to 8. In other words the Tabs Size and Number of Spaces per Indent has to be the same.

I have to agree that from this point of view, the default values doesn't seem to be logical, but the terminals and many printers treat tabulator as 8 characters wide.


Wednesday Jun 23, 2010

Is the IDE Slow? Send a Profiling Snapshot

In NetBeans 6.9 is available Profile me Now! feature as well for PHP distribution. This feature generate a snapshot to understand what's going on if you think that the IDE is slow. By default the feature is not visible and you have to enable the IDE's self-profiling feature. Go to View main menu, then choose Toolbar and enable Memory toolbar.

Now you should see Memory toolbar and also Profile Me button.

Prepare the IDE for the operation that seems to be slow. Press the Profile Me button or use shortcut ALT+SHIFT+Y to start to collecting data. The icon of the button is change during profiling.

Perform the operation and when it's done, press the Profile Me button again or press the shortcut ALT+SHIFT+Y to stop profiling.

IDE creates a profiling snapshot and because there is not Profiler installed by default in PHP distribution, an information dialog is displayed with the path where the snapshot is saved.

If you don't use PHP distro or you installed the Java Profiler (the Java Profiler requires java support), then the snapshot is opened in NetBeans. In this case you have to save it via Export to ... button.

To provide a useful snapshot as much as possible, try to isolate the problematic operation so the snapshot doesn't contain other irrelevant data. For different problems create separate snapshots. Make sure there are no other CPU-heavy tasks running on your computer.

The CPU snapshot is in fact a set of thread dumps taken several times per second (sampling technique). It has a very low overhead, so almost does not affect the running IDE. It is not suitable for profiling very short operations (under 1 second). The snapshot contains no memory data. In case of problems with memory, see how to create a memory dump.

Check the memory bar to make sure the IDE does not run close to memory limits (click the bar to force garbage collection). In such case the slowness is caused by frequent garbage collections, and the whole problem is likely memory-related. You might see OutOfMemoryError too. In such case a memory dump is needed.

Wednesday Jun 02, 2010

Enable auto-scanning of sources - Scan for External Changes

NetBeans 6.9 contains a feature that automatically looks for external changes to keep informations about files up-to-date. We have some reports that it can slow down NetBeans mainly, when an open project has many folders. When NetBeans find out that files were externally changed, it re-scans the files to keep data up-to-date that are used with features like code completion, navigation etc. Unfortunately the notification and following re-scanning can take some time and during this time many mentioned features are waiting for the finishing of scanning. There is option Enable auto-scanning of sources that can switch off this behavior. The option you can find it in Options dialog, Miscellaneous category and Files tab.

The default behavior is that NetBeans also looks for external changes when the main window gets focus. This is can be during developing a web application very often when user switches between browser and IDE. The mentioned option also switch this off.

When you switch off  option Enable auto-scanning of sources you can still keep the information up-to-date, just invoke Scan for External Changes  action from Sources menu manually.



Friday Dec 04, 2009

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:).

Thursday Dec 03, 2009

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.

Wednesday Dec 02, 2009

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.

Tuesday Nov 24, 2009

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.

Thursday Oct 01, 2009

Flickr Slideshow with NetBeans IDE 6.5

Justin Bolter shows you how to build a PHP Flickr slideshow using NetBeans IDE 6.5. [Read More]

Wednesday Aug 12, 2009

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]

Thursday May 07, 2009

How to Include File

How to include file in PHP NB IDE? Two ways:

  1. file system code completion for include/require
  2. Fast Import Alt+Shift-I
[Read More]

Wednesday Dec 03, 2008

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.

Tuesday Dec 02, 2008

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?

Wednesday Nov 05, 2008

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.

About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today