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

📄 look-next.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    return win;}/* options */#define GETFILE_GET_DIRECTORY		1#define GETFILE_GET_EXISTING_FILE	2#define GETFILE_BROWSER			4void input_insert (CWidget * w, int c);#if 0static char *file_error (void){    if (errno) {	char *error_msg;#ifdef HAVE_STRERROR	error_msg = _ (strerror (errno));#else	extern int sys_nerr;	extern char *sys_errlist[];	if ((0 <= errno) && (errno < sys_nerr))	    error_msg = _ (sys_errlist[errno]);	else/* The returned value, 'errno' has an unknown meaning */	    error_msg = _ ("strange errno");#endif	return catstrs ("[", error_msg, "]", 0);    }    return "";}#endifstatic void run_cmd (const char *fmt,...){    signal (SIGCHLD, SIG_IGN);    if (!fork ()) {		/* child process */	va_list pa;	char *str;	va_start (pa, fmt);	str = vsprintf_alloc (fmt, pa);	va_end (pa);	execlp ("/bin/sh", "/bin/sh", "-c", str, (char *) NULL);	/* if all is fine then the thread will exit here */	/* so displaying error if not                    */	fprintf (stderr, "\nBad luck running command [%s].\n", str);	exit (0);		/*thread completed */    }}static char *empty_line = "";static char *item_selected (const char *identifier, NeXTFileBrowser * browser, NeXTDir * dir){    char *ptr = NULL;    CWidget *w;    if (!browser || !identifier)	return 0;		/* something terrible has happen ! */    if (dir == NULL) {	if ((w = CIdent (browser->name)) && w->text)	{	    strdup (ptr = w->text);	    if (strlen (w->text))		CAddToTextInputHistory (browser->name, w->text);	}    } else {	ptr = commit (browser->tree, dir);	if (browser->tree->dirty)	    link_browser_to_data (browser, 0);    }    if (ptr == NULL)	ptr = empty_line;    else if (strcmp (identifier, "browser") == 0) {	struct file_entry *item = &(dir->list[dir->cursor]);	if ((item->stat.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {	    run_cmd (ptr);	} else {	    static char *default_editor = "smalledit";	    static char *editor = NULL;	    if (editor == NULL) {		editor = getenv ("EDITOR");		if (editor == NULL)		    editor = default_editor;	    }	    run_cmd ("%s %s", editor, ptr);	}	free (ptr);	ptr = empty_line;    }    return ptr;}char *get_filelist_line_short (void *data, int line_number, char buffer[1024]);static void cursor_moved (NeXTFileBrowser * browser, NeXTDir * dir, CWidget * list_w){    if (browser && dir && list_w) {	dir_save_position (dir, list_w->cursor, list_w->current, list_w->firstline);	if (dir->cursor >= 0) {	    char buffer[512];#if 0	    struct file_entry *item = &(dir->list[dir->cursor]);	    char *tail;#endif	    if (get_filelist_line_short (dir->list, dir->cursor, buffer))		CRedrawDynText (browser->fileattr, buffer);	}    }}/*   Returns "" on no file entered and NULL on exit (i.e. Cancel button pushed)   else returns the file or directory. Result must be immediately copied.   Result must not be free'd. */static char *handle_browser (const char *identifier, CEvent * cwevent, int options){#if 0    int i;#endif    CWidget *w = CIdent (identifier);    NeXTFileBrowser *browser;    int flist = -1;    char *ptr;    if (!w)	return empty_line;    if (cwevent->command == CK_Cancel)	return 0;    if ((browser = (NeXTFileBrowser *) w->hook) == NULL)	return empty_line;    /* that will be our subwidget name : */    if ((ptr = strrchr (cwevent->ident, '.')) == NULL)	/* nothing to do here - messege for self */	return empty_line;    ptr++;    /* lets find out which one we have (starting from the shortest) */    if (strcmp (ptr, "ok") == 0)	/* we take text from text input and use it as filename */	return item_selected (identifier, browser, NULL);    else if (strncmp (ptr, "flist", 5) == 0)	/* all filelists ends with flistNNN */	flist = atoi (ptr + 5);	/* will process them later */    else if (strcmp (ptr, "cancel") == 0)	return 0;    else if (strcmp (ptr, "finp") == 0) {	if (cwevent->type == KeyPress && cwevent->command == CK_Enter)	    return item_selected (identifier, browser, NULL);	return empty_line;    } else if (strcmp (ptr, "filtinp") == 0) {	if (cwevent->type == KeyPress && cwevent->command == CK_Enter)	    filter_changed (browser, browser->tree->selected);	return empty_line;    }    if (flist >= 0 && flist < browser->numpanes) {	/* filelist event */	NeXTDir *dir = get_dir_by_num (browser->tree, flist + browser->tree->pos);	CWidget *list_w = CIdent (browser->lists[flist]);	/* saving status */	browser->focused = flist;	browser->tree->selected = dir;	switch (cwevent->type) {	case EnterNotify:	    CFocus (list_w);	    update_filter (browser, dir);	    break;/*          case LeaveNotify :    fprintf(stderr, "LeaveNotify\n");   browser->focused = -1 ;    CFocus( CIdent(browser->name));   break ; */	case ButtonPress:	case ButtonRelease:	case MotionNotify:	    cursor_moved (browser, dir, list_w);	    if (cwevent->type != ButtonRelease)		update_input (browser, dir);	    else if (cwevent->double_click)		return item_selected (identifier, browser, dir);	    break;	case KeyPress:	    {		int scroll = 0;		switch (cwevent->command) {		case CK_Enter:		    update_input (browser, dir);		    return item_selected (identifier, browser, dir);		case CK_Up:		case CK_Down:		case CK_Page_Up:		case CK_Page_Down:		    cursor_moved (browser, dir, list_w);		    break;		case CK_Left:		    if (browser->tree->pos > 0)			scroll = -1;		    break;		case CK_Right:		    if (browser->tree->pos < browser->tree->numdirs - browser->numpanes)			scroll = 1;		    break;		case CK_Home:		    scroll = -(browser->tree->pos);		    break;		case CK_End:		    scroll = (browser->tree->numdirs - browser->numpanes) - browser->tree->pos;		    break;		case CK_BackSpace:		    /* remove last typed partial filename char */		    goto_partial_file_name (browser, dir, 0);		    break;		default:		    if (cwevent->insert > 0) {			if (cwevent->key == ' ')			    update_input (browser, dir);			else if (isprint (cwevent->key)) {			    goto_partial_file_name (browser, dir, cwevent->key);			    cursor_moved (browser, dir, list_w);			}		    }		}		if (scroll != 0) {		    browser->tree->pos += scroll;		    link_browser_to_data (browser, 0);		    dir = get_dir_by_num (browser->tree, browser->tree->pos + flist);		    update_filter (browser, dir);		    update_scrollbar (w->hori_scrollbar, browser, 1);		}	    }	    break;	default:	    break;	}    }    return empty_line;}Window find_mapped_window (Window w);/* result must be free'd */static char *look_next_get_file_or_dir (Window parent, int x, int y,       const char *dir, const char *file, const char *label, int options){    CEvent cwevent;    XEvent xevent;    CState s;    CWidget *w;    CBackupState (&s);    CDisable ("*");    CEnable ("_cfileBr*");    parent = find_mapped_window (parent);    if (!(x | y)) {	x = 20;	y = 20;    }    draw_file_browser ("CGetFile", parent, x, y, dir, file, label);    CFocus (CIdent ("CGetFile.finp"));    file = "";    do {	CNextEvent (&xevent, &cwevent);	if (xevent.type == Expose || !xevent.type	    || xevent.type == InternalExpose || xevent.type == TickEvent)	    continue;	if (!CIdent ("CGetFile")) {	    file = 0;	    break;	}	if (xevent.type == Expose || !xevent.type || xevent.type == AlarmEvent	  || xevent.type == InternalExpose || xevent.type == TickEvent) {	    file = "";	    continue;	}	file = handle_browser ("CGetFile", &cwevent, options);	if (!file)	    break;    } while (!(*file));/* here we want to add the complete path to the text-input history: */    w = CIdent ("CGetFile.finp");    if (w) {	if (w->text) {	    free (w->text);	    w->text = 0;	}	if (file)	    w->text = (char *) strdup (file);    }    CDestroyWidget ("CGetFile");	/* text is added to history 					   when text-input widget is destroyed */    CRestoreState (&s);    if (file)	return (char *) ((*file) ? file : 0);    else	return 0;}/*    cb_browser():   1) if filelist has decided that browser should be notifyed about event   it sets CEvent.ident member, and we get into handle_browser.   That includes events external for filelist (Left, Right, Home,    End, Space, Enter, Esc) even thou filelist does no processing of it.   Note also that if user types in some characters while in filelist -    filelist will do search for filename, not the browser, as it was    happening in original version.   2) handle_browser do all the neccessary processing of received events -   updates edit boxes, updates NexTDirTree status, changes dir if needed,   scrolls left, right, home and end.   Sasha. */static char *get_browser_name (char *ident, char *buffer){    char *start = buffer;    while (*ident && *ident != '.')	*(buffer++) = *(ident++);    *buffer = '\0';    return start;}static int cb_browser (CWidget * w, XEvent * x, CEvent * c){    char id[32];    get_browser_name (w->ident, id);    if (!handle_browser (id, c, GETFILE_BROWSER)) {	w = CIdent (catstrs (id, ".finp", 0));	if (w)	    if (w->text) {		free (w->text);		w->text = 0;	    }	CDestroyWidget (id);    }    return 0;}static void look_next_draw_browser (const char *ident, Window parent, int x, int y,		   const char *dir, const char *file, const char *label){    CWidget *w;    if (!(parent | x | y)) {	parent = CFirstWindow;	x = 20;	y = 20;    }    draw_file_browser (ident, parent, x, y, dir, file, label);    if ((w = CIdent (ident))) {	NeXTFileBrowser *browser = w->hook;	int i;	if (browser) {	    for (i = 0; i < browser->numpanes; i++)		CAddCallback (browser->lists[i], cb_browser);	    CAddCallback (browser->name, cb_browser);	    CAddCallback (browser->filter, cb_browser);	    CAddCallback (catstrs (ident, ".ok", 0), cb_browser);	    CAddCallback (catstrs (ident, ".cancel", 0), cb_browser);	    CFocus (CIdent (catstrs (ident, ".finp", 0)));	}    }}/* }}} file browser stuff *//* {{{ scrollbar extras  */#define PURENEXT/*****************************************//* start NeXT scrollbar specific fetures *//* could be anything from 13 to 19  but the true NeXT is 17 */#define SB_WIDTH		17/* this will define somemore parameters for shaping NeXTish scrollbars *//* NEXT_SCROLL_CLEAN if defined removes shades of grey from buttons */#undef NEXT_SCROLL_CLEAN#define NEXT_SCROLL_SQUARE_ARROWS#define SB_BORDER_WIDTH 1/* this makes buttons thinner then scrollbar's base ( if more then 0 ) */#define SIDE_STEP_WIDTH 1/*  end NeXT scrollbar specific fetures  *//*****************************************//*****************************************//* scrollbarr configuration stuff        */#define Xdisplay CDisplay#define Xroot    CRoot#define Xdepth   CDepthstatic char *SCROLLER_DIMPLE[] ={    ".%###.",    "%#%%%%",    "#%%...",    "#%..  ",    "#%.   ",    ".%.  ."};#define SCROLLER_DIMPLE_WIDTH   6#define SCROLLER_DIMPLE_HEIGHT  6static char *SCROLLER_ARROW[4][13] ={    {".............",     ".............",     "......%......",     "......#......",     ".....%#%.....",     ".....###.....",     "....%###%....",     "....#####....",     "...%#####%...",     "...#######...",     "..%#######%..",     ".............",     "............."    },    {".............",     ".............",     "..%#######%..",     "...#######...",     "...%#####%...",     "....#####....",     "....%###%....",     ".....###.....",     ".....%#%.....",     "......#......",     "......%......",     ".............",     "............."    },    {"             ",     "             ",     "      %      ",     "      %      ",     "     %%%     ",     "     %%%     ",     "    %%%%%    ",     "    %%%%%    ",     "   %%%%%%%   ",     "   %%%%%%%   ",     "  %%%%%%%%%  ",     "             ",     "             "    },    {"             ",     "             ",     "  %%%%%%%%%  ",     "   %%%%%%%   ",     "

⌨️ 快捷键说明

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