Get your CTRL+ALT+Fx keyboard shortcuts back in Ubuntu 11.10

I’m now using Ubuntu on my work desktop (nice change). My favourite IDE, IntelliJ Idea has a very useful shortcut CTRL+ALT+F7 to Show Usages of anything under the cursor. Its one of the most simple yet powerful features of the app. The unfortunate problem is that X11 uses CTRL+ALT+F<1..6> to switch between consoles and CTRL+ALT+F<7..9> to switch between desktops and it wins, so IntelliJ doesn’t respond to that useful shortcut anymore.

Tucked away in the Keyboard Layout control panel is an Options… button which brings up an options dialog with various options to configure your keyboard strokes – different to the normal Keyboard bindings you find in the normal Keyboard settings. These are more how you want the keys to be mapped rather than mapping them to functions. Under Miscellaneous compatibility options you’ll find ‘Special keys (Ctrl+Alt+<key>) handled in a server‘ and ticking this gives your shortcuts back to the desktop apps.

Most *nix software wouldn’t assign shortcuts to the ctrl+alt+f<n> because its an accepted convention, but for software that works on multiple OS’, its nice to take this back.

Another great IDEA presentation

My favourite IDEA presenter, Vaclav Pech is talking about code analysis tools in IDEA.  He talks about

  • Code Inspections (live and on demand)
  • Abstract Syntax Tree
  • The structural code inspection – AST context helps understand the Structure search and replace dialog and how you can use its functionality to make an Idea warning with autofix
  • language analysis
  • the annotations like @NotNull, @Pattern in new JSRs and the IntelliJ specific annotations @Language for analysis of strings
  • stacktrace detection
  • dataflow to/from this
  • duplicate detection
  • dependency analysis

Sharing an IntelliJ project via VCS

I found this post Sharing IntelliJ IDEA Project Files in Version Control via the twitter-sphere. 

They talk of all the usual stuff like ignore the iws file, but they introduced a neat trick for project variables which I didn’t know about.

If you edit your ipr or iml files, you can replace values with the text $whatever_project_var_you_please$ and then when someone else checks out the project and doesn’t have the vars set, a Configure Path Variables dialog pops up and asks you to set them.

I’ll be keen to give this a try at work as we recently switched from .ipr to the .idea dir format to avoid some conflicts we’ve been having, but I suspect that doing so is not the silver bullet alone, the above tip may help – by replacing what varies and let the devs set variables locally.

The next questions to ask is how this gets handled by Teamcity (I presume there are some system properties that you set in the team city project) and how in Idea, you can change these project variables.  But otherwise its a very neat tip.

Edit: To change these vars, I believe you can simply go into the File->Settings->Path Variables … Simple

Netbeans JavaFX plugin experience – and what about IntelliJ Idea?

Warning: Many of the following criticisms are superficial, but I wanted to document my experience of learning a new IDE.  I’ll come back to this post in a year to see what’s changed.

I should also state, I’ve got nothing against the Netbeans editor itself, and respect how it is able to support all the new Java platforms and standards in line with their release to the public.  Because of this, it’s as easy to adopt a new sun-backed Java platform enhancement as it is in the .net world, and the support provided makes it easy to learn new Java technologies in both regular desktop and enterprise space.

So now for the whinge:

Trying out Netbeans 6.8 and its best of class JavaFx support left me a little disappointed.  Following the JFX tutorials was ok, but copying the code from the tutorial into the IDE was a little frustrating since the formatting would be all screwed up.  Organise Imports (CTRL+SHIFT+I) plus Format Source (ALT+SHIFT+F) become my new best friends.  Maybe its because I’m trying in a new IDE, but I dont remember having to do these things with Idea, imports would resolve (or prompt for resolve) on paste, and formatting would normally match the target source.  (I’m a spoilt IDE brat, lol)

The JavaFX palette left me wanting as well.  Sure I could drag and drop a template from the palette into my code, but like the copy and paste, it didn’t respect the formatting of my code.  Sure once the template was there, I could tab b/ween the fields within the object literal, but my first instinct is to make the code pretty and doing a Format Source.  Doing so meant that I could no longer tab between the elements.

It would be nice to have a visual guide as to where in the code you could drop a said palette template into (perhaps highlight code blocks yellow if it was within a content or def assignment, but orange if it was somewhere else in the scenegraph it didnt make sense).  This is because if you put the item in the wrong place, you have to spend a minute figuring out the order of ] and } in order to get a compiler fx class again.  The scenegraph should make it easy to identify which element belongs to what, but its easy to miss a line.

I’d also like to see elements which took a sequence (like content) but only had one element assigned to them (eg content: Rectangle { … }), become a group or a sequence automatically when items were dragged into them.  (eg: content: [ Rectange { … }, Circle { // i just added this } ]

I also found that CTRL+Space within an object literal to find the other properties didnt always seem to work.  As I got more experience with the IDE, I found this happening less.  I think the problem could have been to dragging and dropping in the wrong place, as soon as you have a syntax error in your code, the intellisense isn’t going to work, regardless if your CTRL+Space is just within the braces of the object literal.

Also in Netbeans, a lot of refactoring functions were neutered. Options like Move or Copy class or even create a variable (ALT+SHIFT+V) would prompt they didn’t work in the context of the file type.  Doing a block comment using the default comment keyboard shortcut (CTRL+SHIFT+C) didnt work, and its menu option under Format was greyed out, but you could press CTRL+I, type comment and select Toggle Comment for it to work there.  Strange.

End whinge

To Netbeans credit, the JavaFX preview is a great feature to help pick up the language, and of course the different profiles (Desktop, Common, Mobile) along with the integration with the the emulator is excellent.  The above things are pretty superficial and since Netbeans has the jump on the other IDE’s, will probably get around to addressing those other concerns later as the platform is adopted by more devs in future.

Many of the above criticisms are borne out of wanting more refactoring options and polyglot support like I’m used to in IntelliJ.  At present IntelliJ offers a mere syntax highlighting when opening Fx files, but thats about it.  What I’m really waiting for is the super refactoring options when working with a project that has Scala, Groovy and other facets.  As well as just being able to use the refactoring options that I’m used to (eg rename a var/class in java, and refs in the Groovy and scala get changed too).  However, those things aren’t automatic in IntelliJ, I appreciate those refactoring features would have to be developed specifically for JFX, just as they have been for Groovy and Scala.  The list of refactorings isn’t as wide as the java ones.

IntelliJ Idea

So what else can you do to get some java fx love in IntelliJ?  At present not much, you can compile & run JavaFX using Intellij using the External Tools function or by using the ant script as specified in the link.

There was a JavaFX plugin that was being developed by Brian Goetz back in 2008 but word on this has gone quiet.  In 2009 a blog was started by someone about writing a JFX plugin for idea but this too has gone quiet.

So its a case of watch this space.