Fanning Software Consulting

Prevent Dialog_Pickfile From Clipping File Names

QUESTION: Whenever I put a long file name into Dialog_Pickfile with the File keyword, the name is clipped. Is there anything I can do to prevent this?

ANSWER: Yes. My understanding is that this problem stems from an underlying bug in some rather old Windows code that IDL is calling to create the dialog. Until IDL is updated with more recent Windows code, there is one interesting and simple work-around to this problem that you can use.

Here is the problem. Consider a file name like the one below, which is added to Dialog_Pickfile.

   fn = '1234567890abcdefg.txt'
   file = Dialog_Pickfile(File=fn)

You see in the figure below that the first six letters of the file name have been cut off. They are there. Simply interacting with the text in the dialog will expose all the letters, but it is not obvious to the user the letters are there.

The input file name is clipped in Dialog_Pickfile.
The input file name is clipped in Dialog_Pickfile.
 

As it happens, however, if you set the Write keyword in Dialog_Pickfile, then the underlying code knows perfectly well how to put the file name in the dialog!

   fn = '1234567890abcdefg.txt'
   file = Dialog_Pickfile(File=fn, /Write)

You see the results below.

The input file name is not clipped in Dialog_Pickfile if the Write keyword is set.
Setting the Write keyword in Dialog_Pickfile prevents the file name from being clipped.
 

Notice that the title of the window changes with the Write keyword being set from "Please Select a File" to "Please Select a File For Writing". This change can easily be overcome by simply using the Title keyword to select whatever window title you like. This call to Dialog_Pickfile, for example, will look exactly like the first figure above, except that the file name will not be clipped.

   file = Dialog_Pickfile(File=fn, /Write, Title='Please Select a File')

The Coyote Library routine, cgPickfile, which is how I routinely call Dialog_Pickfile, has been updated to always use this work-around. (I use cgPickfile because of its extremely useful ability to remember the last directory where I opened a file and start there.)

Version of IDL used to prepare this article: IDL 7.1.2

Written: 25 February 2012