Geertjan's Blog

  • April 29, 2005

Save Demi Moore in NetBeans IDE 4.1!

Geertjan Wielenga
Product Manager
Let's say you've extended the IDE by creating a new menu, toolbar, menu item, or toolbar button. For example, you've created menu items that are hooked up to Ant scripts that start and stop JBoss, Tomcat 4, WebSphere, and JRun from the IDE. Or you've customized your window layouts and editor settings. Or maybe you've added a module to the IDE. Or maybe you've added some other customization... such as the Demi Moore macro. What happens when you delete your user directory without saving it beforehand? You lose all your customizations. So you've got to remember that you have, for example, hooked an Ant script to the menu bar and that therefore you've got to save the user directory before you delete it. Normally, you delete the user directory long after you've customized the IDE. Hence, you might forget that you've customized it, that you're very comfortable with the customizations, and that you therefore need to save the user directory in order to maintain your customizations. Wouldn't it be cool if you could save the user directory very quickly right after you've added some new customization? Wouldn't it be cool if you could click a menu item or button or keyboard shortcut from inside the IDE, and save your user directory to some safe place in your filesystem, seconds after customizing the IDE in some way? Well, you can. And it's really easy. Add this to the build.xml file:

  <target name="save-demi-moore" description="Save Demi Moore">
<copy todir="c:\\DemiMoore\\config">
<fileset dir="C:\\Documents and Settings\\${user.name}\\.netbeans\\${release.number}\\config"/>

Update 06/27/05: A better Ant script than the one above can be found here.

You'd need to set the user.name property and release.number property somewhere in a properties file and then, if either the user name or release number change, you'd only have to change the two properties to update the script. Note that this script copies everything in the user directory's config directory to a directory called c:\\DemiMoore\\config. Therefore, if you don't want to copy everything, you can append an excludes attribute to the dir attribute and then list all the directories or files you'd like to exclude. (Examples of the use of the excludes attribute can be found elsewhere in this blog.)

Then expand the build.xml node in the IDE (it's in the Files window if you're using a standard project and in the Projects window if you're using a free-form project). You'll see that each target has its own subnode within the build.xml node. Right-click the save-demi-moore node, choose Create Shortcut, and add the save-demi-moore target as a menu item, toolbar button, or keyboard shortcut. You could, for example, add it in the File menu. (When you add an Ant script to a menu, it is placed at the top of the list of menu items within the menu. To re-order the menu items, go to Tools > Options, then expand IDE Configuration, Look and Feel, and right-click Menu Bar or any of its nodes and then choose Reorder.) This is where I've placed it:

Now, whenever you customize the IDE in any way, you can copy all the configurations in one click to a safe place. And then, when you delete your user directory and the IDE creates a new one for you, you can reverse the procedure. If you create an Ant script to copy everything back to the user directory, and hook it up to a menu item in the IDE, you won't be able to use that menu item the first time you have a fresh and clean user directory, of course, because the menu item won't be in your clean user directory.

Therefore, why not add both the "Save Demi Moore" and the "Revert Demi Moore" Ant scripts to the IDE-wide-targets.xml file. (This is a build.xml file that I've been building over the past blog entries. It contains IDE-wide targets, such as starting and stopping JBoss, opening StarOffice in the IDE, and other things that are not related to a particular project. A target that relates to a particular project is, for example, one that deploys a particular project to a particular server. See previous blog entries for details on this subject.) This means that when I have a fresh user directory, I just need to open this IDE-wide-targets.xml file in the IDE as a free-form project, run the "Revert Demi Moore" script, and all my saved customizations are back in the user directory.

However, I then need to restart the IDE, so that it can load the new menus, menu items, etc. (And then I need to re-order the menus, because new menus end up on the extreme left of the menu bar, irrespective of where I've ordered them before. This means that the order of menus is not saved in my user directory, which is probably a bug.) Still, that's probably less work than digging through all my directories to find the place where I need to paste the saved config directory. And, on top of that, it's just a lot more fun to do it from the IDE, using an Ant script I made myself.

Join the discussion

Comments ( 1 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.