⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getfiles.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
static const char CVSID[] = "$Id: getfiles.c,v 1.25.2.1 2003/07/27 21:37:34 edg Exp $";/********************************************************************************                                                                              ** Getfiles.c -- File Interface Routines                                        **                                                                              ** Copyright (C) 1999 Mark Edel                                                 **                                                                              ** This is free software; you can redistribute it and/or modify it under the    ** terms of the GNU General Public License as published by the Free Software    ** Foundation; either version 2 of the License, or (at your option) any later   ** version.                                                                     **                                                                              ** This software is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        ** FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License        ** for more details.                                                            **                                                                              ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple     ** Place, Suite 330, Boston, MA  02111-1307 USA                                 **                                                                              ** Nirvana Text Editor                                                          ** May 23, 1991                                                                 **                                                                              ** Written by Donna Reid                                                        **                                                                              ** modified 11/5/91 by JMK: integrated changes made by M. Edel; updated for     **                          destroy widget problem (took out ManageModalDialog  **                          call; added comments.                               **          10/1/92 by MWE: Added help dialog and fixed a few bugs              **           4/7/93 by DR:  Port to VMS                                         **           6/1/93 by JMK: Integrate Port and changes by MWE to make           **                          directories "sticky" and a fix to prevent opening   **                          a directory when no filename was specified          **          6/24/92 by MWE: Made filename list and directory list typeable,     **                          set initial focus to filename list                  **          6/25/93 by JMK: Fix memory leaks found by Purify.                   **                                                                              ** Included are two routines written using Motif for accessing files:           **                                                                              ** GetExistingFilename  presents a FileSelectionBox dialog where users can      **                      choose an existing file to open.                        **                                                                              ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "getfiles.h"#include "fileUtils.h"#include "misc.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <sys/types.h>#ifdef VMS#include <unixio.h>#include <file.h>#include "VMSparam.h"#else#include <unistd.h>#include <fcntl.h>#include <dirent.h>#ifndef __MVS__#include <sys/param.h>#endif#endif /*VMS*/#include <sys/stat.h>#include <X11/keysym.h>#include <Xm/Xm.h>#include <Xm/PushBG.h>#include <Xm/FileSB.h>#include <Xm/Form.h>#include <Xm/Text.h>#include <Xm/MessageB.h>#include <Xm/List.h>#ifdef HAVE_DEBUG_H#include "../debug.h"#endif#define MAX_ARGS 20			/* Maximum number of X arguments */#define PERMS 0666     			/* UNIX file permission, RW for owner,					   group, world */#define MAX_LIST_KEYSTROKES 100		/* Max # of keys user can type to 					   a file list */#define MAX_LIST_KESTROKE_WAIT 2000	/* Allowable delay in milliseconds					   between characters typed to a list					   before starting over (throwing					   out the accumulated characters */#define SET_ONE_RSRC(widget, name, newValue) \{ \    static Arg tmpargs[1] = {{name, (XtArgVal)0}}; \    tmpargs[0].value = (XtArgVal)newValue; \    XtSetValues(widget, tmpargs, 1); \}	enum yesNoValues {ynNone, ynYes, ynNo};/* Saved default directory and pattern from last successful call */static XmString DefaultDirectory = NULL;static XmString DefaultPattern = NULL;/* User settable option for leaving the file name text field in   GetExistingFilename dialogs.  Off by default so new users will get   used to typing in the list rather than in the text field */static int RemoveRedundantTextField = True;/* Text for help button help display *//* ... needs variant for VMS */#ifndef SGI_CUSTOMstatic const char *HelpExist ="The file open dialog shows a list of directories on the left, and a list \of files on the right.  Double clicking on a file name in the list on the \right, or selecting it and pressing the OK button, will open that file.  \Double clicking on a directory name, or selecting \it and pressing \"Filter\", will move into that directory.  To move upwards in \the directory tree, double click on the directory entry ending in \"..\".  \You can also begin typing a file name to select from the file list, or \directly type in directory and file specifications in the \field labeled \"Filter\".\n\\n\If you use the filter field, remember to include \either a file name, \"*\" is acceptable, or a trailing \"/\".  If \you don't, the name after the last \"/\" is interpreted as the file name to \match.  When you leave off the file name or trailing \"/\", you won't see \any files to open in the list \because the filter specification matched the directory file itself, rather \than the files in the directory.";static const char *HelpNew = "This dialog allows you to create a new file, or to save the current file \under a new name.  To specify a file \name in the current directory, complete the name displayed in the \"Save File \As:\" field near the bottom of the dialog.  If you delete or change \the path shown in the field, the file will be saved using whatever path \you type, provided that it is a valid Unix file specification.\n\\n\To replace an existing file, select it from the Files list \and press \"OK\", or simply double click on the name.\n\\n\To save a file in another directory, use the Directories list \to move around in the file system hierarchy.  Double clicking on \directory names in the list, or selecting them and pressing the \\"Filter\" button will select that directory.  To move upwards \in the directory tree, double \click on the directory entry ending in \"..\".  You can also move directly \to a directory by typing the file specification of the path in the \"Filter\" \field and pressing the \"Filter\" button.";#else /* SGI_CUSTOM */static const char *HelpExist ="The \"File to Edit:\" field shows a list of directories and files in the \current directory.\n\\n\Double clicking on a file name in the list, or selecting it and pressing \the OK button, will open that file.\n\\n\Double clicking on a directory name, or selecting it and pressing the OK \button will move into that directory.  To navigate upwards in the file \system hierarchy you can use the buttons above the \"Selection\" field  \(each of these buttons represent a directory level). \n\\n\You can also enter a file or directory name to open in the field \labeled \"Selection\".  Pressing the space bar will complete a partial file \name, or beep if no files match.  The drop pocket to the right of the field \will accept icons dragged from the desktop, and the button with the circular \arrows, to the right, of the field recalls previously selected \directories.\n\\n\The \"Filter\" button allows you to narrow down the list of files and \directories shown in the \"File to Edit:\" field.  The default filter of \\"*\" allows all files to be listed.";static const char *HelpNew = "This dialog allows you to create a new file or to save the current file \under a new name.\n\\n\To specify a file name in the current directory, complete the name displayed \in the \"Save File As:\" field.  If you delete or change the path shown \in the field, the file will be saved using whatever path you type, provided \that it is a valid Unix file specification.\n\\n\To replace an existing file, select it from the \"Files\" list and press \\"OK\", or simply double click on the name in the \"Files\" list.\n\\n\To save a file in another directory, use the \"Files\" list to move around \in the file system hierarchy.  Double clicking on a directory name, or \selecting it and pressing the OK button, will move into that directory. \To navigate upwards in the file system hierarchy you can use the buttons \above the \"Selection\" field (each of these buttons represent a directory \level).\n\\n\You can also move directly to a directory by typing the file specification \of the path in the \"Save File As:\" field.  Pressing the space bar will \complete a partial directory or file \name, or beep if nothing matches.  The drop pocket to the right of the field \will accept icons dragged from the desktop, and the button with the circular \arrows, to the right, of the field recalls previously selected \directories.\n\\n\The \"Filter\" button allows you to narrow down the list of files and \directories shown in the \"Files\" field.  The default filter of \\"*\" allows all files to be listed.";#endif /* SGI_CUSTOM *//*                    Local Callback Routines and variables                */static void newFileOKCB(Widget w, Boolean *client_data,	       XmFileSelectionBoxCallbackStruct *call_data);static void newFileCancelCB(Widget w, Boolean *client_data, caddr_t                call_data);static void newHelpCB(Widget w, Widget helpPanel, caddr_t call_data);static void createYesNoDialog(Widget parent);static void createErrorDialog(Widget parent);static int  doYesNoDialog(const char *msg);static void doErrorDialog(const char *errorString, const char *filename);static void existOkCB(Widget w, Boolean * client_data,	              XmFileSelectionBoxCallbackStruct *call_data);static void existCancelCB(Widget w, Boolean * client_data, caddr_t call_data);static void existHelpCB(Widget w, Widget helpPanel, caddr_t call_data);static void errorOKCB(Widget w, caddr_t client_data, caddr_t call_data);static void yesNoOKCB(Widget w, caddr_t client_data, caddr_t call_data);static void yesNoCancelCB(Widget w, caddr_t client_data, caddr_t call_data);static Widget createPanelHelp(Widget parent, const char *text, const char *title);static void helpDismissCB(Widget w, Widget helpPanel, caddr_t call_data);static void makeListTypeable(Widget listW);static void listCharEH(Widget w, XtPointer callData, XEvent *event,	Boolean *continueDispatch);static void replacementDirSearchProc(Widget w, XtPointer searchData);static void replacementFileSearchProc(Widget w, XtPointer searchData);static void sortWidgetList(Widget listWidget);static int compareXmStrings(const void *string1, const void *string2);static int  SelectResult = GFN_CANCEL;  /*  Initialize results as cancel   */static Widget YesNoDialog;		/* "Overwrite?" dialog widget	   */static int YesNoResult;			/* Result of overwrite dialog	   */static Widget ErrorDialog;		/* Dialog widget for error msgs	   */static int ErrorDone;			/* Flag to mark dialog completed   */static void (*OrigDirSearchProc)();	/* Built in Motif directory search */static void (*OrigFileSearchProc)();	/* Built in Motif file search proc */		/*  GetExistingFilename				  	                   *//*									   *//*  This routine will popup a file selection box so that the user can      *//*  select an existing file from the scrollable list.  The user is         *//*  prevented from entering a new filename because the edittable text      *//*  area of the file selection box widget is unmanaged.  After the user    *//*  selects a file, GetExistingFilename returns the selected filename and  *//*  GFN_OK, indicating that the OK button was pressed.  If the user        *//*  pressed the cancel button, the return value is GFN_CANCEL, and the     *//*  filename character string supplied in the call is not altered.	   *//*									   *//*  Arguments:								   *//*									   *//*	Widget  parent	      - parent widget id			   *//*	char *  promptString  - prompt string				   *//*	char *  filename      - a string to receive the selected filename  *//*				(this string will not be altered if the    *//*				user pressed the cancel button)		   *//*									   *//*  Returns:	GFN_OK	      - file was selected and OK button pressed	   *//*		GFN_CANCEL    - Cancel button pressed and no returned file *//*									   */int GetExistingFilename (Widget parent, char *promptString, char *filename) {    int       n;                      /* number of arguments               */    Arg	      args[MAX_ARGS];	      /* arg list	                   */    Widget    existFileSB;	      /* widget file select box 	   */    XmString  titleString;	      /* compound string for dialog title  */    n = 0;    titleString = XmStringCreateSimple(promptString);    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;    XtSetArg(args[n], XmNdialogTitle, titleString); n++;    existFileSB = CreateFileSelectionDialog(parent,"FileSelect",args,n);    XmStringFree(titleString);#ifndef SGI_CUSTOM    if (RemoveRedundantTextField)        XtUnmanageChild(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_TEXT));     XtUnmanageChild(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_SELECTION_LABEL));    XtVaSetValues(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_FILTER_LABEL),            XmNmnemonic, 'l',            XmNuserData, XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_FILTER_TEXT),            NULL);    XtVaSetValues(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_DIR_LIST_LABEL),            XmNmnemonic, 'D',            XmNuserData, XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_DIR_LIST),            NULL);    XtVaSetValues(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST_LABEL),            XmNmnemonic, promptString[strspn(promptString, "lD")],            XmNuserData, XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST),            NULL);    AddDialogMnemonicHandler(existFileSB, FALSE);    RemapDeleteKey(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_FILTER_TEXT));    RemapDeleteKey(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_TEXT));#endif    return HandleCustomExistFileSB(existFileSB, filename);}/*** HandleCustomExistFileSB**** Manage a customized file selection box for opening existing files.** Use this if you want to change the standard file selection dialog** from the defaults provided in GetExistingFilename, but still** want take advantage of the button processing, help messages, and** file checking of GetExistingFilename.****  Arguments:****	Widget  existFileSB   - your custom file selection box widget id**	char *  filename      - a string to receive the selected filename**				(this string will not be altered if the**				user pressed the cancel button)	****  Returns:	GFN_OK	      - file was selected and OK button pressed	**		GFN_CANCEL    - Cancel button pressed and no returned file***/int HandleCustomExistFileSB(Widget existFileSB, char *filename){    Boolean   done_with_dialog=False; /* ok to destroy dialog flag	   */    char      *fileString;            /* C string for file selected        */    char      *dirString;             /* C string for dir of file selected */    XmString  cFileString;            /* compound string for file selected */    XmString  cDir;	              /* compound directory selected	   */    XmString  cPattern;               /* compound filter pattern	   */    Widget    help;		      /* help window form dialog	   */#if XmVersion < 1002    int       i;#endif    XtAddCallback(existFileSB, XmNokCallback, (XtCallbackProc)existOkCB,    	    &done_with_dialog);    XtAddCallback(existFileSB, XmNcancelCallback, (XtCallbackProc)existCancelCB,	    &done_with_dialog);    AddMotifCloseCallback(XtParent(existFileSB), (XtCallbackProc)existCancelCB,	    &done_with_dialog);    help = createPanelHelp(existFileSB, HelpExist, "Selecting Files to Open");    createErrorDialog(existFileSB);    XtAddCallback(existFileSB, XmNhelpCallback, (XtCallbackProc)existHelpCB,    	    (char *)help);    if (DefaultDirectory != NULL || DefaultPattern != NULL)    	XtVaSetValues(existFileSB, XmNdirectory, DefaultDirectory,    		XmNpattern, DefaultPattern, NULL);#ifndef SGI_CUSTOM    makeListTypeable(XmFileSelectionBoxGetChild(existFileSB,XmDIALOG_LIST));    makeListTypeable(XmFileSelectionBoxGetChild(existFileSB,XmDIALOG_DIR_LIST));#if XmVersion >= 1002    XtVaSetValues(existFileSB, XmNinitialFocus, XtParent(    	    XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST)), NULL);#endif#endif    ManageDialogCenteredOnPointer(existFileSB);#ifndef SGI_CUSTOM

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -