[comp.windows.x.motif] XmFileSelectionBoxes in 1.1 & 1.0

hildjj@MODAL375.ME.VT.EDU (Joe Hildebrand) (03/24/91)

> Message-Id: <MONTNARO.91Mar22123217@spyder.crd.ge.com>

> I have a couple of problems with the FileSelectionBox that I can't seem to
> get around. Perhaps someone in-the-know can help me out.

>     2. Is there any way to get a CallBack invoked when a file or directory
>        is selected (as opposed to when the OK or Filter buttons are pressed,
>        or the file/directory is double-clicked)? I'd like to set some other
>        values in the user interface based upon the file the user is
>        "considering". 

I'm using Motif 1.0.? (since HP does not see fit to ship an upgrade until this
FALL!)  But this should work for your second question.

void create_file_box(parent)
   Widget parent;
{
   Widget text, file_box;

   file_box = XmCreateSelectionBox(parent, "File Box", NULL, 0);
   XtManageChild(file_box);
   XtAddCallback(file_box, XmNokCallback, validate_selection, parent);
   XtAddCallback(parent, XmNactivateCallback, show_file_box_CB, file_box);

   text = XmFileSelectionBoxGetChild(file_box, XmDIALOG_TEXT);
   XtAddCallback(text, XmNvalueChangedCallback, new_file_CB, NULL);
}

additionally, the FAQ says that file selection boxes don't work in 1.0.
I have a work-around.  Before popping up an XmFileSelectionDialog, change to
the directory you want.  When a file is selected, check if it is a directory,
so that we can change to it.  i.e.

static void show_file_box_CB(w, client_data, call_data)
   Widget 		w;
   Widget 		client_data;
   XmAnyCallbackStruct	*call_data;   
{   
   chdir("/users/hildjj/files");
   XtManageChild(client_data);
}

static void val_save(w, client_data, call_data)
   Widget 	w;
   Widget 	client_data;
   XmSelectionBoxCallbackStruct	*call_data;
{   
   struct stat buf;  /* struct stat is defined in stat.h */
   char *filename;
   
   /* get the file name from the FileSelectionBox */
   filename = SmX(call_data->value);
   
   /* get the status of the file named filename, and put it into buf */
   if (!stat(filename, &buf))
   {
      /* if it's a directory */
      if(S_ISDIR(buf.st_mode))
      {
	 /* change to that directory, and update the FileSelectionBox */
	chdir(filename);
	XmFileSelectionDoSearch(w, NULL);
      }
      else
	 /* if it's a regualr file */
	 if(S_ISREG(buf.st_mode))
	    /* ask if it should be overwritten */
	    XtManageChild(valbox);
	 else
	    /* it's another kind of file.  What type, i can't think of,
	       but it might happen */
	    pop_up_error_box(client_data, "Error saving file");
   }
   else  /* we couldn't get the file status */
   {
      /* if it's because the file doesn't exist, we're golden */
      if (errno == ENOENT)
	 save_file();
      else   /* there is some other problem getting the status.
		e.g. bad path */
	 pop_up_error_box(client_data, "Error saving file");
   }
}

this still doesn't implement the file masking stuff, but since HP obviously is
placing very low priority on their implementation of 1.1 (not to mention X11R4,
due this summer...), I'll have to make do.

Joe Hildebrand  [hildjj@modal375.me.vt.edu (128.173.5.186)]
Virginia Tech DepartMent of Mechanical Engineering
and
Babcock & Wilcox Nuclear Services, Lynchburg, VA

david@lta.lta.com (David B. Lewis) (03/25/91)

> >     2. Is there any way to get a CallBack invoked when a file or directory
> >        is selected (as opposed to when the OK or Filter buttons are pressed,

I think what Skip is asking for is solved by putting a callback on the internal
list so that the selected item is returned to the application.

> additionally, the FAQ says that file selection boxes don't work in 1.0.

The current version of Jan Newmarch's FAQ for comp.windows.x.motif reads:

-------------------------------------------------------------------------------

Subject: 42)+ What's wrong with the Motif 1.0 File Selection Box?  I can't set
the directory, change the directory or get the file mask to work.

Answer: The 1.0 File Selection Box is broken, and these don't work.  They
weren't fixed until Motif 1.04.  Switch to Motif 1.1 where it changed a lot.

-------------------------------------------------------------------------------


-- 
David B. Lewis  			Lewis, Trachtenberg & Associates (LTA)
Note new address!:  david@lta.com	+1 617 225 0366

	UNIX - some assembly required.

peterf@ima.isc.com (Peter Fischman) (03/29/91)

In article <9103251456.AA10679@lta.com> david@lta.lta.com (David B. Lewis) writes:
>> additionally, the FAQ says that file selection boxes don't work in 1.0.
>
>The current version of Jan Newmarch's FAQ for comp.windows.x.motif reads:
>
>-------------------------------------------------------------------------------
>
>Subject: 42)+ What's wrong with the Motif 1.0 File Selection Box?  I can't set
>the directory, change the directory or get the file mask to work.
>
>Answer: The 1.0 File Selection Box is broken, and these don't work.  They
>weren't fixed until Motif 1.04.  Switch to Motif 1.1 where it changed a lot.
>
>-------------------------------------------------------------------------------

I'm a tad confused.  I've been using File Selection Boxes with ISC X11R3
and Motif 1.0 for a while with all of the above functioning fine.

--

Peter Fischman		peterf@ima.isc.com		(617)661-7474x216