D
Version 3.2 and the File Chooser
The XView File Chooser is an implementation of the OPENLOOK Application File Choosing
Specification. The Application File Choosing Specification supercedes the traditional
OPEN LOOK Style Guide on the subject of opening and saving files from an application,
without the use of the File Manager. The file chooser also lets the user easily navigate
through the file system. Note that the file chooser is not intended to replace the File Man-
ager; any application supporting the file chooser is also required by the File Choosing Speci-
fication to support drag and drop with the File Manager, in accordance with the OPEN LOOK
Drag and Drop Specification.
File choosers provide a simple and consistent interface for opening and saving files to the
UNIX File System. File choosers also provide a Go To Menu for going to different direc-
tories which allows the user to easily select a directory from a predefined list, an application
defined list or a dynamicly created history list. Normally a file chooser will be presented
from an application’s File Menu. The user will then have selections for opening a document,
saving a document, or saving a document to a new name. Once one of these selections is
made, a file chooser object is presented.
D.1 Creating File Choosers
To use the FILE_CHOOSER package, include the header file <xview/file_chsr.h>. The object
type is File_chooser. The class hierarchy for the FILE_CHOOSER package is:
[Generic] -> [(Drawable)] -> [Window] -> [Frame_cmd] -> [File Chooser]
File choosers come in three types:
• FILE_CHOOSER_OPEN
• FILE_CHOOSER_SAVE
• FILE_CHOOSER_SAVEAS
Figure D-1 shows an example of an OPEN file chooser.
Version 3.2 and
the File Chooser
Version 3.2 and the File Chooser 677
Figure D-1. File chooser Save dialog
678 Version 3.2 and the File Chooser
Figure D-2 shows an example of a SAVE file chooser which is similar to a SAVE AS file
chooser.
Figure D-2. File chooser Open dialog
Version 3.2 and
the File Chooser
Version 3.2 and the File Chooser 679
These dialogs are presented from an application’s file pop-up menu. The user may select one
of the predefined package choices: “Open”, "Save”, “Save As”, or an application defined
choice such as “Import” or “Include”. Once the file chooser is open, the user is presented
with a frame containing several elements for navigating the folder hierarchy. These elements
include the Go To menu, the Current Folder field, the scrolling list, and the Open, Save or
Save As button area, which also includes a Cancel button. The Save and Save As file chooser
also include a type in field below the scrolling list where the saved file is named. Refer to the
figures for the relative layouts of these file chooser elements. Note: the packages that make
up these elements are public and include: FILE_LIST, PATH_NAME, HISTORY_LIST and HIS-
TORY_MENU
. You can uses these packages for applications that require functionality similar
to that provided by any of these file chooser components. Refer to Section A.13, “File
Chooser Components” for information on using these packages. File chooser types are speci-
fied at create time using the FILE_CHOOSER_TYPE attribute. Alternatively, convenience
macros allow you to create each of the specified file chooser types as shown below:
File_chooser open_chsr;
File_chooser save_chsr;
File_chooser saveas_chsr;
open_chsr = (File_chooser) xv_create(owner,
FILE_CHOOSER_OPEN_DIALOG, NULL);
save_chsr = (File_chooser) xv_create(owner,
FILE_CHOOSER_SAVE_DIALOG, NULL);
saveas_chsr = (File_chooser) xv_create(owner,
FILE_CHOOSER_SAVEAS_DIALOG, NULL);
The owner of a File_chooser should be a base frame, but it can also be the root window,
NULL, just as with a command frame.
D.2 Using a File Chooser
Given the information provided so far, we can demonstrate to how to install a file chooser for
a menu item. Example D-1 shows a portion of a program which installs a File chooser on a
menu item. The complete program is found in Appendix F, Example Programs.
Example D-1. Portion of file_chooser.c program
/*
* Demonstrate the XView File Chooser
*/
#include <stdio.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/textsw.h>
#include <xview/scrollbar.h>
#include <xview/file_chsr.h>
static Attr_attribute MY_KEY;
typedef struct {
Frame frame;
680 Version 3.2 and the File Chooser
Example D-1. Portion of file_chooser.c program (continued)
Panel panel;
Panel_button_item file_button;
Menu file_menu;
Textsw textsw;
File_chooser open;
File_chooser save;
File_chooser saveas;
File_chooser import;
char * doc_name;
} My_ui;
static void my_open_notify();
static void my_save_notify();
static void my_saveas_notify();
static void my_import_notify();
static int my_open_callback();
static int my_save_callback();
void
main( argc, argv )
int argc;
char **argv;
{
My_ui ui = {0};
(void) xv_init ( XV_INIT_ARGC_PTR_ARGV,
&argc, argv, NULL );
MY_KEY = xv_unique_key();
ui.file_menu
= xv_create(XV_NULL, MENU,
MENU_ITEM,
MENU_STRING, "Open...",
MENU_NOTIFY_PROC, my_open_notify,
NULL,
MENU_ITEM,
MENU_STRING, "Import...",
MENU_NOTIFY_PROC, my_import_notify,
NULL,
MENU_ITEM,
MENU_STRING, "Save...",
MENU_NOTIFY_PROC, my_save_notify,
NULL,
MENU_ITEM,
MENU_STRING, "Save As...",
MENU_NOTIFY_PROC, my_saveas_notify,
NULL,
XV_KEY_DATA, MY_KEY, &ui,
NULL);
ui.frame = xv_create(XV_NULL, FRAME,
XV_LABEL, "Demo Text Editor",
FRAME_SHOW_FOOTER, TRUE,
NULL );
Version 3.2 and
the File Chooser
Version 3.2 and the File Chooser 681
Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.