📄 cooledit.c
字号:
fprintf (stderr, "cooledit: calling mad_finalise(),\n"); mad_finalize (__FILE__, __LINE__);#endif exit (0);}/* number of 'Window' menu items */#define WLIST_ITEMS 9void add_to_focus_stack (Window w);/* a file was selected in the menu, so focus and raise it */void wlist_callback (unsigned long ignored){ current_edit = CIdent ("menu.wlist")->current - WLIST_ITEMS; current_to_top (); XRaiseWindow (CDisplay, edit[current_edit]->parentid); CRaiseWindows (); add_to_focus_stack (edit[current_edit]->winid);}void close_window_callback (unsigned long ignored){ CEditMenuCommand (CK_Exit);}void menu_browse_cmd (unsigned long ignored){ int l; for (l = 0;; l++) if (!CIdent (catstrs ("_cfileBr", itoa (l), 0))) break; CDrawBrowser (catstrs ("_cfileBr", itoa (l), 0), CRoot, 0, 0, current_dir, "", _(" File Browser ")); (CIdent (catstrs ("_cfileBr", itoa (l), 0)))->position |= WINDOW_UNMOVEABLE;}extern char *init_font;extern char *init_widget_font;extern char *init_bg_color;void run_main_callback (unsigned long ignored){ char lines[10], columns[10]; sprintf (lines, "%d", edit[current_edit]->editor->num_widget_lines); sprintf (columns, "%d", edit[current_edit]->editor->num_widget_columns); switch (fork()) { case 0: set_signal_handlers_to_default (); execlp (argv_nought, argv_nought, "-Smf", init_font, "--widget-font", init_widget_font, "-lines", lines, "-columns", columns, 0); exit (0); case -1: CErrorDialog (0, 0, 0, _(" Run 'cooledit' "), get_sys_error (_(" Error trying to fork process "))); return; default: return; }}/* }}} 'Window' menu call backs *//* {{{ 'Window' menu update */void init_usual_items (struct menu_item *m){ m[0].text = (char *) strdup (_(" New window\tC-F3 ")); m[0].hot_key = '~'; m[0].call_back = new_window_callback; m[1].text = (char *) strdup (_(" New main window\tF13 ")); m[1].hot_key = '~'; m[1].call_back = run_main_callback; m[2].text = (char *) strdup (_(" Window cycle\tC-F6/S-Tab ")); m[2].hot_key = '~'; m[2].call_back = window_cycle_callback; m[3].text = (char *) strdup (_(" Close window\tF10 ")); m[3].hot_key = '~'; m[3].call_back = close_window_callback; m[4].text = (char *) strdup (_(" Close all and exit\tC-F10 ")); m[4].hot_key = '~'; m[4].call_back = exit_app; m[4].data = 1; m[5].text = (char *) strdup (_(" Save all and exit\tM-x ")); m[5].hot_key = '~'; m[5].call_back = exit_app; m[5].data = 2; m[6].text = (char *) strdup (_(" Save desktop\tC-F2 ")); m[6].hot_key = '~'; m[6].call_back = save_desk_callback; m[7].text = (char *) strdup (_(" File browser...\t")); m[7].hot_key = '~'; m[7].call_back = menu_browse_cmd; m[WLIST_ITEMS - 1].text = (char *) strdup (" "); m[WLIST_ITEMS - 1].hot_key = 0; m[WLIST_ITEMS - 1].call_back = 0;}void update_wlist (void){ struct menu_item *m; CWidget *w; int i; w = CIdent ("menu.wlist"); destroy_menu (w); m = CMalloc ((last_edit + WLIST_ITEMS) * sizeof (struct menu_item)); init_usual_items (m); if (last_edit > 0) { for (i = 0; i < last_edit; i++) { m[i + WLIST_ITEMS].text = (char *) strdup (catstrs (" ", edit[i]->editor->filename, " ", 0)); m[i + WLIST_ITEMS].hot_key = 0; m[i + WLIST_ITEMS].call_back = wlist_callback; if (i == current_edit) m[i + WLIST_ITEMS].text[0] = '>'; } } w->numlines = last_edit + WLIST_ITEMS; w->current = current_edit + WLIST_ITEMS; while (w->current >= w->numlines) w->current--; w->menu = m; if (w->droppedmenu != 0) { w->droppedmenu->menu = m; w->droppedmenu->numlines = w->numlines; w->droppedmenu->current = w->current; render_menu (w->droppedmenu); } if (last_edit > 0) CSetEditMenu (edit[current_edit]->ident);}/* }}} 'Window' menu update *//* {{{ configuration file handler */void edit_about_cmd (void);/* open all the files listed in the configuration file returns 0 on success */int read_config (void){ char f[256]; char d[512]; char *s, *r; long w, h, c, l; float x, y; int n = 0, num_read = 0, i; DIR *dir; dir = opendir (catstrs (home_dir, EDIT_DIR, "/.t", 0)); s = get_options_section (editor_options_file, "[Files]"); if (!dir) { mkdir (catstrs (home_dir, EDIT_DIR, 0), 0700); mkdir (catstrs (home_dir, EDIT_DIR, "/.t", 0), 0700); } if (dir) closedir (dir); if (!s) return 1; r = s; for (;;) { n = 0; i = sscanf (s, "%[^ ] %[^ ] x=%f y=%f columns=%ld lines=%ld cursor=%ld topline=%ld %n", d, f, &x, &y, &w, &h, &c, &l, &n); s += n; if (i < 3) break; if (i != 8) { fprintf (stderr, _ ("cooledit: error in initialisation file %s: line %d\n"), editor_options_file, num_read + 1); CErrorDialog (main_window, 20, 20, _ (" Load Config "), _ (" Error in initialisation file %s: line %d "), editor_options_file, num_read + 1); free (r); return 1; } x = x * (float) FONT_MEAN_WIDTH + 0.5; y = y * (float) FONT_PIX_PER_LINE + 0.5; if (new_editor (num_read, (int) x, (int) y, w, h, f, d)) { edit_move_display (edit[num_read]->editor, l); edit_move_to_line (edit[num_read]->editor, c); num_read++; } if (!n) break; } current_edit = 0; for (i = last_edit - 1; i >= 0; i--) XRaiseWindow (CDisplay, edit[i]->parentid); CRaiseWindows (); update_wlist (); free (r); return 0;}/* format a line for the config file of the current editor */void print_stuff (char *s){ CWidget *w; w = CWidgetOfWindow (edit[current_edit]->parentid); *s = 0; if (edit[current_edit]) if (edit[current_edit]->editor->filename && edit[current_edit]->editor->dir) if (*(edit[current_edit]->editor->filename) && *(edit[current_edit]->editor->dir)) sprintf (s, "%s %s x=%f y=%f columns=%d lines=%d cursor=%ld topline=%ld\n", edit[current_edit]->editor->dir, edit[current_edit]->editor->filename, (float) w->x / (float) FONT_MEAN_WIDTH, (float) w->y / (float) FONT_PIX_PER_LINE, edit[current_edit]->editor->num_widget_columns, edit[current_edit]->editor->num_widget_lines, edit[current_edit]->editor->curs_line, edit[current_edit]->editor->start_line);}/* returns 0 on success. Returns 1 on fail and 2 on user cancel *//* write out the config file. clean = 1: also tries to exit each file. *//* clean = 2: saves every file before trying to exit. */int write_config (int clean){ char *f, *t; int result = 0; char s[1024]; t = f = CMalloc (65536); *f = 0; current_to_top (); current_edit = 0; do { print_stuff (s); if (clean) { if (edit[current_edit]->editor->modified) XRaiseWindow (CDisplay, edit[current_edit]->parentid); if (clean == 2 && edit[current_edit]->editor->modified) edit_execute_command (edit[current_edit]->editor, CK_Save, -1); edit_execute_command (edit[current_edit]->editor, CK_Exit, -1); if (edit[current_edit]->editor->stopped == 1) { int ce = current_edit; print_stuff (s); /* user may have changed the filename on exit */ remove_current (0); current_edit = ce; } else { result = 2; print_stuff (s); current_edit++; } } else { current_edit++; } if (*s) { sprintf (f, s); f += strlen (s); *f = 0; } } while (current_edit < last_edit);/* restack: */ current_edit = last_edit - 1; while (current_edit >= 0) { XRaiseWindow (CDisplay, edit[current_edit]->parentid); current_edit--; }; current_edit = 0; CRaiseWindows (); if (save_options_section (editor_options_file, "[Files]", t)) CErrorDialog (main_window, 20, 20, _(" Save desktop "), get_sys_error (_(" Error trying to save file "))); free (t); update_wlist (); return result;}/* }} configuration file handler */#ifdef HAVE_DND/* {{ *//* If a filename is dropped onto the main window, open an edit window with that file. */int open_drop_file (XEvent * xevent, CEvent * cwevent){ unsigned char *data; unsigned long size; int data_type, xs, ys; if (xevent->xany.type != ClientMessage) return 0; if (xevent->xany.window != main_window) return 0; data_type = CGetDrop (xevent, &data, &size, &xs, &ys); if (data_type == DndNotDnd) return 0; if (data_type == DndFile) { new_file_callback ((char *) data); } else { if (data_type == DndFiles) { unsigned long i = size; while (i--) data[i] = data[i] ? data[i] : '\n'; } else if (data_type != DndRawData && data_type != DndText) { /* we are going to allow nulls in DndText */ size = strnlen ((char *) data, size); } new_file_callback (NEW_WINDOW_FROM_TEXT, data, size); } if (data) free (data); return 1;}#elsestatic struct drop { unsigned char *data; int size; Atom type;} drop = { 0, 0, 0};static int handle_drop (CWidget * w, Window from, unsigned char *data, int size, int xs, int ys, Atom type, Atom action){ if (drop.data) free (drop.data); drop.data = CMalloc (size + 1); memcpy (drop.data, data, size); drop.size = size; drop.data[size] = '\0'; drop.type = type; return 0;}/* If a filename is dropped onto the main window, open an edit window with that file. */char *filename_from_url (char *data, int size, int i);static void open_drop_file (unsigned char *data, int size, Atom type){ if (type == XInternAtom (CDisplay, "url/url", False)) { if (!strncmp ((char *) data, "file:", 5)) { char *f; f = filename_from_url ((char *) data, size, strlen ("file:")); new_file_callback (f); free (f); } else { new_file_callback (NEW_WINDOW_FROM_TEXT, data, size); } } else { new_file_callback (NEW_WINDOW_FROM_TEXT, data, size); } return;}/* }} */#endifint editors_modified (void){ int i, r = 0; for (i = 0; i < last_edit; i++) r |= edit[i]->editor->modified; return r;}static void cooledit_init (void){ CInitData cooledit_startup; memset (&cooledit_startup, 0, sizeof (cooledit_startup)); cooledit_startup.name = argv_nought; cooledit_startup.geometry = option_geometry; cooledit_startup.display = option_display; cooledit_startup.font = option_font; cooledit_startup.widget_font = option_widget_font; cooledit_startup.bg = option_background_color; cooledit_startup.fg_red = option_foreground_red; cooledit_startup.fg_green = option_foreground_green; cooledit_startup.fg_blue = option_foreground_blue; cooledit_startup.look = option_look; if (option_verbose) cooledit_startup.options = CINIT_OPTION_VERBOSE;/* initialise: */ CInitialise (&cooledit_startup);}#define DEFAULT_INI_FILE home_dir, "/.cedit/.cooledit.ini"void get_home_dir (void);void CDrawCooleditMenuButtons (Window parent, int x, int y);extern int user_defined_key (unsigned int state, unsigned int keycode, KeySym keysym);extern void execute_script (WEdit * e, int i);#ifdef HAVE_PYTHONextern void coolpython_command (WEdit * e, int i);#endifint is_focus_prev_key (KeySym k, int command, unsigned int state);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -