📄 cooledit.c
字号:
static int initial_columns, initial_lines;static CEvent cooledit_cevent;static XEvent cooledit_xevent;#define approx_equ(a,b) (((a) < (b) + FONT_HEIGHT) && (a) > (b) - FONT_HEIGHT)static int similar_size_to_main_window (CWidget * w){ if (approx_equ (w->width, CIdent ("cooledit")->width) && approx_equ (w->height, CIdent ("cooledit")->height - height_offset) && approx_equ (w->x, 0) && approx_equ (w->y, height_offset)) return 1; return 0;}static void maximise_window (char *ident){ CWidget *w; int lines, columns, f; unsigned int wm, hm; char x[34]; strcpy (x, "win"); strcat (x, ident); get_main_window_size (&wm, &hm); CPushFont ("widget", 0); f = FONT_PIX_PER_LINE; CPopFont (); CPushFont ("editor", 0); lines = hm / FONT_PIX_PER_LINE; columns = wm / FONT_MEAN_WIDTH; fit_into_main_window (&lines, &columns, 0, height_offset); CSetWidgetSize (x, columns * FONT_MEAN_WIDTH + 25 + EDIT_FRAME_W + 4 + 2 + 20 + WIDGET_SPACING * 2, lines * FONT_PIX_PER_LINE + f + EDIT_FRAME_H + WIDGET_SPACING * 3 + 8 + TEXT_RELIEF * 2 + 3 + 3 + 3 + 2); w = CIdent (x); CSetWidgetPosition (x, (wm - w->width) / 2, height_offset + (hm - height_offset - w->height) / 2); CPopFont ();}void debug_key_command (int command);void edit_insert_shell_output (WEdit * edit);/* ----main_loop()--------------------------------------------------------- */static void main_loop (void){ for (;;) { CNextEvent (&cooledit_xevent, &cooledit_cevent); if (cooledit_xevent.type == TickEvent) { debug_callback (); continue; } if (cooledit_xevent.type == Expose || !cooledit_xevent.type || cooledit_xevent.type == InternalExpose) continue; switch (cooledit_xevent.type) { case AlarmEvent:{ static int hint_count = 0; if (option_hint_messages) if (!((hint_count++) % (CGetCursorBlinkRate () * option_hint_messages))) get_next_hint_message (); break; } case EditorCommand: /* send by us to the library */ case KeyPress: if (cooledit_cevent.handled) break; if (cooledit_cevent.kind == C_EDITOR_WIDGET || cooledit_cevent.kind == C_MENU_BUTTON_WIDGET || !last_edit) { switch ((int) cooledit_cevent.command) { case CK_Insert_Unicode: { long c; if ((c = CUnicodeDialog (main_window, 20, 20, 0)) >= 0) { edit_insert_wide (edit[current_edit]->editor, c); edit[current_edit]->editor->force |= REDRAW_PAGE; } } break; case CK_Terminal: rxvt_start (CRoot, 0, 0); break; case CK_Complete: complete_command (edit[current_edit]); break; case CK_Find_File: find_file (); break; case CK_Ctags: ctags (); break; case CK_Mail: do_mail (edit[current_edit]); break; case CK_Save_Desktop: save_desk_callback (0); write_config (0); /* tries to exit all editors */ if (option_pull_down_window_list) CPullDown (CIdent ("menu.wlist")); break; case CK_New_Window: new_window_callback (0); if (option_pull_down_window_list) CPullDown (CIdent ("menu.wlist")); break; case CK_Menu: break; default: if (cooledit_cevent.command >= 350 && cooledit_cevent.command < 400) debug_key_command (cooledit_cevent.command); else if (is_focus_prev_key (cooledit_cevent.key, cooledit_cevent.command, cooledit_xevent.xkey.state) || cooledit_cevent.command == CK_Cycle) { window_cycle_callback (0); if (option_pull_down_window_list) { CPullDown (CIdent ("menu.wlist")); XSync (CDisplay, 0); } } else if (cooledit_cevent.command == CK_Cancel) { edit_insert_shell_output (edit[current_edit]->editor); } else { CPullUp (CIdent ("menu.wlist")); } break; } if (cooledit_cevent.kind != C_MENU_BUTTON_WIDGET) { switch ((int) cooledit_cevent.command) { case CK_Menu: /* pull down the menu */ CMenuSelectionDialog (CGetLastMenu ()); break; case CK_Check_Save_And_Quit: /* save desktop and quit all */ exit_app (1); break; case CK_Run_Another: /* new editor window */ run_main_callback (0); break; case CK_Save_And_Quit: exit_app (2); break; } break; } } break; /* when you release the ctrl key, the window must go to the top of the list */#ifdef HAVE_DND case ClientMessage: open_drop_file (&cooledit_xevent, &cooledit_cevent); break;#endif case KeyRelease: if (cooledit_cevent.handled) break; if (cooledit_cevent.kind == C_EDITOR_WIDGET) if (mod_type_key (CKeySym (&cooledit_xevent))) { current_to_top (); CPullUp (CIdent ("menu.wlist")); } break; /* if you click on an edit window, it must go to the top, so... */ case ButtonRelease: if (cooledit_cevent.kind == C_WINDOW_WIDGET) { CWidget *w; w = CIdent (cooledit_cevent.ident); if (!w) break; if (similar_size_to_main_window(w)) w->position |= POSITION_HEIGHT | POSITION_WIDTH; else w->position &= ~(POSITION_HEIGHT | POSITION_WIDTH); } break; case ButtonPress: if (cooledit_cevent.kind == C_EDITOR_WIDGET) { int i; /* find which one was clicked on: */ for (i = 0; i < last_edit; i++) if (edit[i]->winid == cooledit_cevent.window) { current_edit = i; break; } XRaiseWindow (CDisplay, edit[current_edit]->parentid); CRaiseWindows (); current_to_top (); } break; } if (cooledit_xevent.type == QuitApplication) { if (!editors_modified ()) { exit_app (0); } else { int i; i = CQueryDialog (0, 0, 0, _ (" Quit "), _ (" Quit Cooledit ? "), _ (" Cancel quit "), _ (" Quit and save all "), _ (" Quit, do not save "), 0); switch (i) { case 0: break; case 1: exit_app (2); break; case 2: exit_app (0); break; } } continue; } if (cooledit_cevent.command) { switch ((int) cooledit_cevent.command) {#ifdef HAVE_PYTHON case CK_Type_Load_Python: coolpython_typechange (cooledit_cevent.window); break;#endif case CK_Util: CMenuSelectionDialog (CIdent (catstrs (edit[current_edit]->ident, ".util", 0))); break; case CK_Load: case CK_New: case CK_Save_As: update_wlist (); break; case CK_Man_Page: edit_man_page_cmd (CGetEditMenu ()->editor); break; case CK_Maximize: maximise_window (cooledit_cevent.ident); break; } } /* if an editor has been exitted out of, it must be destroyed: */ if (last_edit) { if (edit[current_edit]->editor->stopped == 1) { char *d; d = (char *) strdup (edit[current_edit]->editor->dir); remove_current (1); if (!last_edit) { initial_lines = 100; initial_columns = 200; fit_into_main_window (&initial_lines, &initial_columns, 0, height_offset); new_editor (0, 0, height_offset, initial_columns, initial_lines, 0, d); CFocus (edit[current_edit]); } update_wlist (); free (d); } } if (CDndClass->stage == XDND_DROP_STAGE_IDLE && drop.data) { open_drop_file (drop.data, drop.size, drop.type); free (drop.data); drop.data = 0; } }}static void custom_keys (WEdit * e, int i){ if (i < MAX_NUM_SCRIPTS) execute_script (e, i);#ifdef HAVE_PYTHON else coolpython_command (e, i - MAX_NUM_SCRIPTS);#endif}static char *mime_majors[3] ={"url", "text", 0};/* main window only recieves drops, so... */static struct mouse_funcs main_mouse_funcs ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (int (*)(void *, Window, unsigned char *, int, int, int, Atom, Atom)) handle_drop, 0, DndText, mime_majors};extern int (*global_callback) (XEvent *x);int rxvt_event (XEvent * xevent);/* ----main()-------------------------------------------------------------- */int main (int argc, char **argv){ Window buttonwin; CWidget *w; char *s; int x, y, setsize = 0; char *example_fonts[] = { "-misc-fixed-bold-r-normal--13-120-75-75-c-80", "-*-courier-medium-r-normal--13-120-75-75-m-60", "-*-times-medium-r-*--14-*-*-*-p-*", "-*-helvetica-bold-r-*--14-*-*-*-p-*", "-*-charter-bold-r-*--14-*-*-*-p-*", "-*-times-medium-r-*--20-*-*-*-p-*", "-*-helvetica-bold-r-*--20-*-*-*-p-*", "-*-charter-bold-r-*--20-*-*-*-p-*", "-*-*-bold-*-normal--10-100-75-75-c-80", "-*-*-bold-r-normal--12-120-75-75-c-80", "-*-*-bold-r-normal-*-15-*-*-*-c-*", "-winfonts-arial-bold-r-*-*-45-*-*-*-*-*-*-*" }; int n; if (argc > 1) if (!strcmp (argv[1], "--mad")) option_debug_malloc++; if (argc > 2) if (!strcmp (argv[2], "--mad")) option_debug_malloc++; command_line_files = (char **) malloc ((argc + 1) * sizeof (char *)); memset (command_line_files, 0, (argc + 1) * sizeof (char *)); cooledit_options[0].strs = command_line_files; edit_file_is_open = file_is_open; argv_nought = (char *) strdup (argv[0]); if (!setlocale (LC_CTYPE, "")) fprintf (stderr, _ ("%s: cannot set locale, see setlocale(3), current locale is %s\n"), argv_nought, setlocale (LC_MESSAGES, 0)); setlocale (LC_TIME, ""); setlocale (LC_MESSAGES, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); if ((s = getenv ("LC_ALL")) || (s = getenv ("LC_CTYPE")) || (s = getenv ("LANG"))) { if (strstr (s, "UTF-8")) option_utf_interpretation = 1; }#if defined (HAVE_NL_LANGINFO) && defined (HAVE_LANGINFO_H) && defined (CODESET) if (!strcmp (nl_langinfo (CODESET), "UTF-8")) option_utf_interpretation = 1;#endif n = sizeof (example_fonts) / sizeof (char *); process_command_line (argc, argv); if (option_aa_font != -1) { fprintf (stderr, "cooledit: --[no-]anti-aliasing is depreciated, use <fontname>/3 instead\n"); exit (1); } if (option_font) if (!strcmp (option_font, "?") || !strcmp (option_font, "h") || !strcmp (option_font, "-?") || !strcmp (option_font, "-h")) { int i; printf (_ ("Examples: \n")); for (i = 0; i < n; i++) printf ("cooledit -font '%s'\n", example_fonts[i]); printf ("cooledit -font default\n" \ "cooledit -font 8x13bold\n" \ "cooledit -font 1-%d\n", n); exit (1); } get_home_dir (); if (!editor_options_file) editor_options_file = (char *) strdup (catstrs (DEFAULT_INI_FILE, 0)); if (!option_suppress_load_options) { char *p; load_setup (editor_options_file); put_all_lists (p = get_options_section (editor_options_file, "[Input Histories]")); if (p) free (p); } if (option_minimal_main_window) option_geometry = 0; if (!option_command_line_doesnt_override) process_command_line (argc, argv); if (option_font) if (!strcmp (option_font, "default")) option_font = (char *) strdup ("-*-fixed-bold-r-*--13-*-*-*-*-80-*"); if (option_widget_font) if (!strcmp (option_widget_font, "default")) option_widget_font = (char *) strdup ("-*-helvetica-bold-r-*--13-*-*-*-*-*-*"); if (option_font) if (strspn (option_font, "0123456789") == strlen (option_font)) { int i; i = atoi (option_font); if (i < 1 |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -