Implementing the “Reveal In Explorer” functionality

Update: I seems like Microsoft changed the behavior of the Explorer’s command line parameters in Vista and Windows 7. Below is the fixed version of my code that addresses the problem.

So, I was wondering the other day how to implement a functionality similar to Firefox’s “Open Containing Folder” or OS X’s “Reveal In Finder”.
It turned out to be extremely simple. Here is the Pascal/Delphi-Code:

uses
  ShellAPI;

function RevealInExplorer(const Filename: string; ShowExplorerWithFoldersBar: Boolean = True): Boolean;
var
  Params: string;
begin
  if FileExists(Filename) or DirectoryExists(Filename) then
  begin
    Params := Format('/select,"%s"', [Filename]);

    if ShowExplorerWithFoldersBar then
      Params := '/e,' + Params;

    ShellExecute(0, 'open', 'explorer.exe', PChar(Params), nil, SW_SHOWNORMAL);

    Result := True;
  end
  else
    Result := False;
end;

Lazy source code comment stunts

Double-Slash-Whole-Block-Commenting

Here is a simple way to disable or enable whole code blocks with just two slashes:

PHP / C++:

/*
  Block (commented block)
//*/
///*
  Block (active block)
//*/

Object Pascal/Delphi:

(*
  Block (commented block)
//*)
//(*
  Block (active block)
//*)

Alternatively you can use { and } in the Object Pascal/Delphi example.


Double-Slash-Whole-Block-Switching (Object Pascal/Delphi only)

The Object Pascal dialect used in Delphi supports three ways of commenting code, two for commenting whole blocks ( { } and (* *) ) and one for commenting lines ( // ).
We can exploit this feature to switch between two code blocks easily and fast:

Block 2 is in the enabled state:

{
  Block 1  (commented block)
(*}
  Block 2  (active block)
//*)

Note, I am just adding two slashes in front of the first comment block to activate it again – similar to Double-Slash-Whole-Block-Commenting trick above. This will also magically disable the second block due to the way the comment marks are arranged:

//{
  Block 1  (active block)
(*}
  Block 2  (commented block)
//*)

These tricks are probably applicable to other programming languages as well. Please let me know.

BDS / Delphi alike key bindings for Xcode

Lately, I’ve been using Apple’s Xcode to work on some C++ and ObjC code. The default key bindings in Xcode are really annoying if you come from a Borland background.
Luckily, there is a way to adjust these directly in Xcode. So, here is my first version of the Borland Developer Studio / Delphi / JBuilder / C++ Builder alike key bindings:

Xcode – BDS Similar.pbxkeys.zip

Simply place the included file “BDS Similar.pbxkeys” into:
~/Library/Application Support/Xcode/Key Bindings/
and activate it in the Xcode preferences.

Not every shortcut is available, but at least the basics are there. I see if I can improve it over time.

Docks…

I am lazy – very lazy. ;)
That’s also why I can’t stand the default Windows ways of starting applications, ie. Start -> Programs or Quicklaunch bar. Either too many clicks or extreme cluttering.

Having said that, I’ve been a long time user of Y’z Dock, an abandoned implementation of an OS X-like Dock for Windows. Of all the Windows Dock’s out there it came closest in terms of imitating the original behaviour. I guess that’s also the reason why Apple pulled it via DMCA/C’n’D. ;)
Anyway, since Y’z Dock is no longer maintained and there are still some bugs in that software, I was looking for alternatives. Here is what I found: MobyDock, ObjectDock, RK Launcher and RocketDock. There is also AquaDock, but that’s just a repack of Y’z Dock.

RK Launcher has some potential to it, but also way too many bugs. I wasn’t able to access the website, so perhaps the program is pulled, too.

I’ve tried both MobyDock and ObjectDock several times in the past and didn’t like them at that time. This hasn’t changed and I won’t go into detail as to why. It’s really way too subjetive and I don’t want to start a flame war. ;)

So, finally, I’ve settled with RocketDock. It’s faaast and provides instant access to my program shortcuts even under heavy load. That’s what I missed in Y’z Dock. When Y’z Dock was autohidden, it also reduced the process working set size via a nice trick. This is a good thing in low memory conditions since this tells the virtual memory manager it can swap out most parts of the app. However, it can also impose serious delays in feedback. And instant feedback is what I was looking for.
RocketDock offers this, but at the price of higher memory utilization – ~10 MB in my case. I think this is still acceptable for the performance and my Subjective Productivity Boost TM, therefore.
So, now what was left to do was to migrate the dock items from Y’z Dock to RocketDock. Sadly, there is no way to import the itemlist.ini into RocketDock – at least I didn’t see it. ;)

So, being lazy and not wanting to recreate each and every icon manually on several boxes (repitition is harmful TM), I had to come up with a better solution.

And here it is: YzDock2RocketDock (binary and Delphi sourcecode included)

Simply extract the binary to a new folder and copy your itemlist.ini file from your Y’z Dock program directory into that same folder. Make sure to quit RocketDock and backup the registry key \HKEY_CURRENT_USER\Software\RocketDock-v0.9.4 before.
Now, running the binary should import the contents of itemlist.ini into the registry. It will not overwrite any existing items. Instead it does append the imported ones to the existing items.
Finally, make sure to copy all icons over to your RocketDock program directory. Put them into the subdirectory “Icons”. That’s it. Enjoy! :)

OTA Wizards

While working on our new Graphics32 Testing framework I was looking for some simple framework that would simplify developing experts for the Delphi/BDS IDE.
Mattias told me about the OTAWizard framework over at CodeCentral:
http://codecentral.borland.com/Item.aspx?id=17106

There is also a nice article on that topic:
http://community.borland.com/article/0,1410,28050,00.html

Problem with the provided version is that it doesn’t work with BDS 2005 and 2006 due to multiple personalities in these IDEs.
So, here is my update:
http://www.katastrophos.net/downloads/OTAWizardsD2k5+.zip

Optimized GR32_Polygons.pas

As previously mentioned on the Graphics32 newsgroup I’ve made initial optimizations to the GR32_Polygons unit.
This version fixes several inefficiencies and a major performance issue mostly noticeable with the standard memory manager. Initial benchmarking shows a 2.2-fold performance increase.
If you want to give it a try, you can download the version here:

GR32_Polygons.pas

I’m still working on some other improvements not included in this file.
Please let me know, how it performed for you.