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

📄 cooledit.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "bitmap/toolbar.bitmap"int toolbar_cmd[NUM_TOOL_BUTTONS] ={    CK_Maximize,    CK_Exit,    CK_Util,    CK_Save,    CK_Load,    CK_XCut,    CK_XStore,    CK_XPaste,    CK_Find,    CK_Mail,    0};static char *toolbar_hints[NUM_TOOL_BUTTONS] ={/* Toolhint */    gettext_noop ("Maximise the window, Alt-F6"),    gettext_noop ("Close this edit window, F10"),    gettext_noop ("Filetype specific utilities menu, Meta-U, Alt-U"),    gettext_noop ("Save this edit buffer, F2"),    gettext_noop ("Load new file, Ctrl-O"),    gettext_noop ("Delete, and copy to X clipboard, Shift-Del"),    gettext_noop ("Copy to X clipboard, Ctrl-Ins"),    gettext_noop ("Paste from X clipboard, Shift-Ins"),    gettext_noop ("Search for text, F7"),    gettext_noop ("Mail edit buffer"),    gettext_noop ("Open the cooledit man page")};int tool_bar_callback (CWidget * w, XEvent * xe, CEvent * ce){    XEvent e;    char ident[32], *p;    strcpy (ident, ce->ident);    p = strchr (ident, '.');    *p = 0;    memset (&e, 0, sizeof (XEvent));    e.type = EditorCommand;    e.xkey.keycode = toolbar_cmd[w->cursor];    e.xkey.window = (CIdent (ident))->winid;    CSendEvent (&e);    return 1;}void edit_man_cooledit (unsigned long ignored);int help_callback (CWidget * w, XEvent * xe, CEvent * ce){    edit_man_cooledit (0);    return 1;}#define VERT_TEXT_OFFSET 7int render_vert_text (CWidget * w){    CWidget *wdt;    wdt = CIdent (w->ident + 3);    if (!wdt)	return 0;    if (!wdt->editor)	return 0;    if (!wdt->editor->syntax_type)	return 0;    CSetColor (color_palette (1));    XDrawVericalString8x16 (CDisplay, w->winid, CGC, VERT_TEXT_OFFSET, NUM_TOOL_BUTTONS * 25 + 12,	    wdt->editor->syntax_type, strlen (wdt->editor->syntax_type));    return 1;}void change_syntax_type (CWidget * edi){    CWidget *w;    char x[34];#ifdef HAVE_PYTHON    XEvent e;    memset (&e, 0, sizeof (XEvent));    e.type = EditorCommand;    e.xkey.keycode = CK_Type_Load_Python;    e.xkey.window = edi->winid;    CSendEvent (&e);#endif    strcpy (x, "win");    strcat (x, edi->ident);    w = CIdent (x);    if (!w)	return;    CSetColor (COLOR_FLAT);    CRectangle (w->winid, VERT_TEXT_OFFSET, NUM_TOOL_BUTTONS * 25 + 12, 16, 1024);    CSendExpose (w->winid, VERT_TEXT_OFFSET, NUM_TOOL_BUTTONS * 25 + 12, 16, 1024);}int draw_vert_text (CWidget * w, XEvent * xe, CEvent * ce){    if (xe->type == Expose) {	if (xe->xexpose.x > VERT_TEXT_OFFSET + 16)	    return 0;	return render_vert_text (w);    }    return 0;}#define NEW_WINDOW_FROM_TEXT ((char *) 1)/* creates a new editor at 'number' in the stack and shifts up the stack *//* returns one on success, 0 on error: usually file not found */int new_editor (int number, int x, int y, int columns, int lines, char *f, char *d,...){    static int edit_count = 0;    int xe, ye;    int i, modified = 0;    CWidget *new_edit;    Window win;    char *t = 0, *p, *q;    unsigned long size;    if (last_edit >= N_EDIT) {	CErrorDialog (0, 0, 0, _ (" Error "), _ (" You have opened the maximum number of possible edit windows "));	return 0;    }    edit_count++;    if (f == NEW_WINDOW_FROM_TEXT) {	va_list ap;	va_start (ap, d);	t = va_arg (ap, char *);	size = va_arg (ap, unsigned long);	f = 0;	va_end (ap);	modified = 1;    } else {	size = 0;	if (!d)	    d = "";	if (!f) {	    f = 0;	    t = "";	} else if (!*f) {	    f = 0;	    t = "";	} else if (!*d && *f != '/')	    d = catstrs (current_dir, "/", 0);    }    q = catstrs ("editor", itoa (edit_count), 0);    CPushFont ("editor", 0);    win = CDrawDialog (p = catstrs ("wineditor", itoa (edit_count), 0), main_window, x, y);    CPopFont ();    CGetHintPos (&xe, &ye);    if (option_toolbar) {	for (i = 0; i < NUM_TOOL_BUTTONS; i++) {	    CWidget *w;	    w = CDrawPixmapButton (catstrs (q, ".B", itoa (i), 0), win,			3, ye + i * 25, 25, 25, toolbar_buttons[i], '0');	    if (toolbar_cmd[i] == CK_Util) {		CDrawMenuButton (catstrs (q, ".util", 0), w->winid, main_window,		     25 + 10, -65, AUTO_SIZE, 0, _ (" Utility "), 0, 0, 0, 0);	    }	    w->takes_focus = 0;	    w->cursor = i;	/* just to easily identify the button */	    CAddCallback (w->ident, tool_bar_callback);	    CSetToolHint (w->ident, _ (toolbar_hints[i]));	}/* man page "help" */	CAddCallback (catstrs (q, ".B", itoa (NUM_TOOL_BUTTONS - 1), 0), help_callback);	CSetToolHint (catstrs (q, ".B", itoa (NUM_TOOL_BUTTONS - 1), 0), _ (toolbar_hints[NUM_TOOL_BUTTONS - 1]));	xe = 25 + 4;    }    edit_set_syntax_change_callback (change_syntax_type);    reset_hint_pos (0, 0);    CPushFont ("editor", 0);    new_edit = CDrawEditor (q, win, xe, ye, columns * FONT_MEAN_WIDTH,			    lines * FONT_PIX_PER_LINE, t, f, d, EDITOR_HORIZ_SCROLL, size);    if (!new_edit) {	CDestroyWidget (catstrs ("wineditor", itoa (edit_count), 0));	CPopFont ();	return 0;    }    new_edit->position |= (POSITION_WIDTH | POSITION_HEIGHT);    new_edit->editor->modified = modified;    CSetSizeHintPos (p);/* font height needed for resizing granularity - well, i guest thats why they call it hacking */    CSetWindowResizable (p, 150, 150, 1600, 1200);    CPopFont ();    CMapDialog (p);    CAddBeforeCallback (p, draw_vert_text);    x = x + (CIdent (p))->width;    y = y + (CIdent (p))->height;    extents_width = max (x, extents_width);    extents_height = max (y, extents_height);    (CIdent (catstrs (q, ".text", 0)))->position |= (POSITION_BOTTOM | POSITION_WIDTH);    (CIdent (catstrs (q, ".vsc", 0)))->position |= (POSITION_RIGHT | POSITION_HEIGHT);    (CIdent (catstrs (q, ".hsc", 0)))->position |= (POSITION_BOTTOM | POSITION_WIDTH);    memmove (&(edit[number + 1]), &(edit[number]), (last_edit - number) * sizeof (CWidget *));    last_edit++;    edit[last_edit] = 0;    edit[number] = new_edit;    update_wlist ();    return 1;}/* removes the editor at 'current_edit' */void remove_current (int do_raise){    CDestroyWidget (CWidgetOfWindow (edit[current_edit]->parentid)->ident);    /* close up the hole in the stack: */    memmove (&(edit[current_edit]), &(edit[current_edit + 1]), (last_edit - current_edit) * sizeof (CWidget *));    /* one less editor: */    last_edit--;    edit[last_edit] = 0;    if (last_edit) {	if (current_edit == last_edit)	    current_edit--;	CFocus (edit[current_edit]);	/* focus on the next */	if (do_raise) {	    XRaiseWindow (CDisplay, edit[current_edit]->parentid);	    CRaiseWindows ();	}    }    update_wlist ();}/* }}}  window stack manipulation */void get_main_window_size (unsigned int *width, unsigned int *height){    Window root;    int x, y;    unsigned int border, depth;    XGetGeometry (CDisplay, main_window, &root, \		  &x, &y, width, height, &border, &depth);}/* {{{  'Window' menu call backs */extern int (*edit_file_is_open) (char *);/* returns non-zero if alrady open */static int file_is_open (char *p){    char s[MAX_PATH_LEN], *t;    int r = 0, i;    p = pathdup (p);    for (i = 0; i < last_edit && !r; i++)	if (edit[i]->editor->dir && edit[i]->editor->filename && i != current_edit) {	    strcpy (s, edit[i]->editor->dir);	    strcat (s, "/");	    strcat (s, edit[i]->editor->filename);	    t = pathdup (s);	    if (!strcmp (t, p))		r = 1;	    free (t);	}    if (r) {	CPushFont ("widget", 0);	r = CQueryDialog (0, 0, 0, _ (" Warning "), catstrs (_ (" This file is already open. Open another? "), "\n", p, 0), _ ("Yes"), _ ("No"), 0);	CPopFont ();    }    free (p);    return r;}static int height_offset;void fit_into_main_window (int *lines, int *columns, int x, int y){    unsigned int width, height, f;    get_main_window_size (&width, &height);    CPushFont ("widget", 0);    f = FONT_PIX_PER_LINE;    CPopFont ();    CPushFont ("editor", 0);    while (*columns * FONT_MEAN_WIDTH + 25 + EDIT_FRAME_W + 4 + 2 + 20 + WIDGET_SPACING * 2 > width - x)	(*columns)--;    if (*columns * FONT_MEAN_WIDTH < 150)	(*columns) = 150 / FONT_MEAN_WIDTH;    while (*lines * FONT_PIX_PER_LINE + f + EDIT_FRAME_H + WIDGET_SPACING * 3 + 8 + TEXT_RELIEF * 2 + 3 + 3 + 3 + 2 > height - y)	(*lines)--;    if (*lines * FONT_PIX_PER_LINE < 250)	*lines = 250 / FONT_PIX_PER_LINE;    CPopFont ();}/* returns non-zero on error */int new_file_callback (char *full_file_name,...){    int x, y, columns, lines, result = 1;    char *d = 0;    if (!full_file_name || full_file_name == NEW_WINDOW_FROM_TEXT) {	if (last_edit)	    /* copy the current directory: */	    d = (char *) pathdup (edit[current_edit]->editor->dir);	else	    d = (char *) pathdup (home_dir);    }    CGetWindowPosition (edit[current_edit]->parentid, main_window, &x, &y);    if (last_edit) {	columns = edit[current_edit]->editor->num_widget_columns;	lines = edit[current_edit]->editor->num_widget_lines;    } else {	columns = 200;	lines = 100;    }    lines -= 2;    fit_into_main_window (&lines, &columns, x, y);    if (full_file_name == NEW_WINDOW_FROM_TEXT) {	char *t;	unsigned long size;	va_list ap;	va_start (ap, full_file_name);	t = va_arg (ap, char *);	size = va_arg (ap, unsigned long);	x = new_editor (0, x, y, columns, lines, NEW_WINDOW_FROM_TEXT, d, t, size);	va_end (ap);    } else {	x = new_editor (0, x, y, columns, lines, full_file_name, d);    }    if (x) {	current_edit = 0;	CFocus (edit[current_edit]);	result = 0;    }    if (d)	free (d);    return result;}void new_window_callback (unsigned long ignored){    char *f = 0;    if (option_new_window_ask_for_file)	f = CGetLoadFile (main_window, 20, 20, edit[current_edit]->editor->dir, "", _(" Open "));    new_file_callback (f);    if (f)	free (f);}void window_cycle_callback (unsigned long ignored){    current_edit = (current_edit + 1) % last_edit;    CFocus (edit[current_edit]);    XRaiseWindow (CDisplay, edit[current_edit]->parentid);    CRaiseWindows ();		/* brings ALWAYS_ON_TOP windows to the top */    update_wlist ();}void save_desk_callback (unsigned long ignored){    write_config (0);}char *get_all_lists (void);void free_all_lists (void);void free_all_scripts (void);void put_all_lists (char *list);void complete_command (CWidget * e);void exit_app (unsigned long save){    char *p;    switch ((int) save) {    case 0:	break;    case 1:	if (write_config (1))	    return;		/* saves all and tries to exit all editors */	break;    case 2:	if (write_config (2))	    return;		/* tries to exit all editors */	break;    }    if (option_save_setup_on_exit)	save_setup (editor_options_file);    save_options_section (editor_options_file, "[Input Histories]", p = get_all_lists ());    rxvtlib_shutall ();    free (p);    free_all_scripts ();    complete_command (0);    debug_shut ();#ifdef HAVE_PYTHON    coolpython_shut ();#endif    CShutdown ();    if (editor_options_file)	free (editor_options_file);    CDisable (0);    free (argv_nought);    free_all_lists ();    load_setup (0);    catstrs_clean ();    edit_free_cache_lines ();    postscript_clean ();#if HAVE_MAD/* NLS ? */

⌨️ 快捷键说明

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