📄 options.c
字号:
for (i = 0; string_options[i].name; i++) { if (*string_options[i].value) { sprintf (p, "%s = %s\n%n", string_options[i].name, *string_options[i].value, &r); p += r; } } for (i = 0; integer_options[i].name; i++) { if (integer_options[i].type == TYPE_HIDDEN_HEX_VALUE) sprintf (p, "%s = 0x%X\n%n", integer_options[i].name, *integer_options[i].value, &r); else sprintf (p, "%s = %d\n%n", integer_options[i].name, *integer_options[i].value, &r); p += r; } for (i = 0; color_options[i].name; i++) { if (color_options[i].cname) sprintf (p, "%s = %s\n%n", color_options[i].name, color_options[i].cname, &r); else sprintf (p, "%s = %d\n%n", color_options[i].name, *color_options[i].value, &r); p += r; } *p = 0; r = save_options_section (file, "[Options]", s); free (s); return r;}void save_options (void){ if (save_setup (editor_options_file) < 0) CErrorDialog (main_window, 20, 20, _(" Save Options "), "%s", get_sys_error ( catstrs (_(" Error trying to save : "), editor_options_file, " ", 0)));}static char *short_name (char *a, char *b){ static char r[128]; strcpy (r, a); strcat (r, b); r[30] = 0; return r;}#define WHICH_SWITCHES 1#define WHICH_GENERAL 2static void assign_options (int which){ int i = 0; static char whole_chars_search[128]; static char whole_chars_move[128]; static char alternate_dictionary[MAX_PATH_LEN]; while (integer_options[i].value) { if (integer_options[i].prompt) { if (which == WHICH_SWITCHES) { if (integer_options[i].type == TYPE_ON_OFF) *integer_options[i].value = (CIdent (short_name (integer_options[i].name, "")))->keypressed; } if (which == WHICH_GENERAL) { if (integer_options[i].type == TYPE_VALUE) *integer_options[i].value = atoi ((CIdent (short_name (integer_options[i].name, "")))->text); } } i++; } if (which == WHICH_SWITCHES) {#ifdef HAVE_DND option_dnd_version = (CIdent ("dnd_version"))->keypressed;#endif option_auto_para_formatting = (CIdent ("para_form"))->keypressed; option_typewriter_wrap = (CIdent ("typew_wrap"))->keypressed; option_auto_spellcheck = (CIdent ("auto_spell"))->keypressed; option_syntax_highlighting = (CIdent ("syntax_high"))->keypressed; } if (which == WHICH_GENERAL) { strncpy (alternate_dictionary, (CIdent ("options.a_dict"))->text, MAX_PATH_LEN - 1); option_alternate_dictionary = alternate_dictionary; alternate_dictionary[MAX_PATH_LEN - 1] = '\0'; strncpy (whole_chars_search, (CIdent ("options.wc_search"))->text, 127); option_whole_chars_search = whole_chars_search; whole_chars_search[127] = '\0'; strncpy (whole_chars_move, (CIdent ("options.wc_move"))->text, 127); option_chars_move_whole_word = whole_chars_move; whole_chars_move[127] = '\0'; }}void draw_options_dialog (Window parent, int x, int y){ Window win; XEvent xev; CEvent cev; int xh, i; CState s; CWidget *w, *wdt; CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("options", parent, x, y, _(" Options ")); CGetHintPos (&x, &y); i = 0; xh = x; while (integer_options[i].value) { if (integer_options[i].prompt && integer_options[i].type == TYPE_VALUE) { wdt = CDrawText (short_name ("T", integer_options[i].name), win, xh, y, _(integer_options[i].prompt)); CGetHintPos (&x, 0); w = CDrawTextInput (short_name (integer_options[i].name, ""), win, x, y, FONT_MEAN_WIDTH * 8 + FONT_PIX_PER_LINE + 4, AUTO_HEIGHT, 8, itoa (*integer_options[i].value)); w->position |= POSITION_FILL; w->label = _(integer_options[i].prompt); w->hotkey = find_hotkey (w); w->label = 0; wdt->hotkey = w->hotkey; CGetHintPos (0, &y); } i++; } CGetHintPos (0, &y); CDrawText ("options.twc_search", win, xh, y, _(" Whole chars search: ")); CGetHintPos (&x, 0); (CDrawTextInput ("options.wc_search", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_whole_chars_search)->position) |= POSITION_FILL; CGetHintPos (0, &y); CDrawText ("options.twc_move", win, xh, y, _(" Whole chars move: ")); CGetHintPos (&x, 0); (CDrawTextInput ("options.wc_move", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_chars_move_whole_word)->position) |= POSITION_FILL; CGetHintPos (0, &y); CDrawText ("options.ta_dict", win, xh, y, _(" Ispell alternate dict: ")); CGetHintPos (&x, 0); (CDrawTextInput ("options.a_dict", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_alternate_dictionary)->position) |= POSITION_FILL; CGetHintPos (0, &y); CDrawPixmapButton ("options.ok", win, xh, y, PIXMAP_BUTTON_TICK);/* Toolhint */ CSetToolHint ("options.ok", _("Apply options, Enter")); CGetHintPos (&xh, 0); CDrawPixmapButton ("options.cancel", win, xh, y, PIXMAP_BUTTON_CROSS);/* Toolhint */ CSetToolHint ("options.cancel", _("Abort dialog, Escape")); CGetHintPos (&xh, 0); CDrawPixmapButton ("options.save", win, xh, y, PIXMAP_BUTTON_SAVE);/* Toolhint */ CSetToolHint ("options.save", _("Save options")); CSetSizeHintPos ("options"); CMapDialog ("options"); CFocus (CIdent ("options.ok")); for (;;) { CNextEvent (&xev, &cev); if (!CIdent("options")) break; if (!strcmp (cev.ident, "options.cancel") || cev.command == CK_Cancel) break; if (!strcmp (cev.ident, "options.ok") || cev.command == CK_Enter) {/* keypressed holds the whether switch is on or off */ assign_options (WHICH_GENERAL); break; } if (!strcmp (cev.ident, "options.save")) {/* keypressed holds the whether switch is on or off */ assign_options (WHICH_GENERAL); save_options (); } } w = CGetEditMenu (); if (w) CExpose (w->ident); CDestroyWidget ("options"); CRestoreState (&s);}void draw_switches_dialog (Window parent, int x, int y){ Window win; XEvent xev; CEvent cev; int xh, yh; int i, n; CState s; CWidget *w; CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("options", parent, x, y, _ (" Options ")); CGetHintPos (&x, &y); n = i = 0; while (integer_options[i].value) { if (integer_options[i].prompt && integer_options[i].type == TYPE_ON_OFF) n++; i++; } i = 0; xh = x; yh = y; while (integer_options[i].value) { if (integer_options[i].prompt && integer_options[i].type == TYPE_ON_OFF) { if (n <= 0) { get_hint_limits (&xh, 0); /* half on the left, half on the right */ n = 9999; yh = y; } CDrawSwitch (short_name (integer_options[i].name, ""), win, xh, yh, *integer_options[i].value, _ (integer_options[i].prompt), 0); CGetHintPos (0, &yh); n -= 2; } i++; }#ifdef HAVE_DND get_hint_limits (0, &y); CDrawSwitch ("dnd_version_not", win, x, y, !option_dnd_version, _ (" Dnd version 0 "), 1 | RADIO_INVERT_GROUP); CDrawSwitch ("dnd_version", win, xh, y, option_dnd_version, _ (" Dnd version 1 "), 1 | RADIO_INVERT_GROUP);#endif get_hint_limits (0, &y); CDrawSwitch ("para_form", win, x, y, option_auto_para_formatting, _ (" Auto paragraph formatting "), 2); CDrawSwitch ("typew_wrap", win, xh, y, option_typewriter_wrap, _ (" Type-writer wrap "), 2); CGetHintPos (0, &y); get_hint_limits (0, &y); CDrawSwitch ("syntax_high", win, x, y, option_syntax_highlighting, _ (" Syntax highlighting "), 0); CDrawSwitch ("auto_spell", win, xh, y, option_auto_spellcheck, _ (" Spellcheck as you type "), 0); CGetHintPos (0, &y); CDrawPixmapButton ("options.ok", win, x, y, PIXMAP_BUTTON_TICK);/* Toolhint */ CSetToolHint ("options.ok", _ ("Apply options, Enter")); CGetHintPos (&xh, 0); CDrawPixmapButton ("options.cancel", win, xh, y, PIXMAP_BUTTON_CROSS);/* Toolhint */ CSetToolHint ("options.cancel", _ ("Abort dialog, Escape")); CGetHintPos (&xh, 0); CDrawPixmapButton ("options.save", win, xh, y, PIXMAP_BUTTON_SAVE);/* Toolhint */ CSetToolHint ("options.save", _ ("Save options")); CSetSizeHintPos ("options"); CMapDialog ("options"); CFocus (CIdent ("options.ok")); for (;;) { CNextEvent (&xev, &cev); if (!CIdent ("options")) break; if (!strcmp (cev.ident, "syntax_high")) {/* turn off spell checkig if syntax high is on */ if ((CIdent ("auto_spell"))->keypressed && !(CIdent ("syntax_high"))->keypressed) { (CIdent ("auto_spell"))->keypressed = 0; render_switch (CIdent ("auto_spell")); } } if (!strcmp (cev.ident, "auto_spell")) {/* turn on syntax highlighting if spellchecking is on */ if ((CIdent ("auto_spell"))->keypressed && !(CIdent ("syntax_high"))->keypressed) { (CIdent ("syntax_high"))->keypressed = 1; render_switch (CIdent ("syntax_high")); } } if (!strcmp (cev.ident, "options.cancel") || cev.command == CK_Cancel) break; if (!strcmp (cev.ident, "options.ok") || cev.command == CK_Enter) {/* keypressed holds the whether switch is on or off */ assign_options (WHICH_SWITCHES); break; } if (!strcmp (cev.ident, "options.save")) {/* keypressed holds the whether switch is on or off */ assign_options (WHICH_SWITCHES); save_options (); } } w = CGetEditMenu (); if (w) CExpose (w->ident); CDestroyWidget ("options"); CRestoreState (&s);}void save_mode_options_dialog (Window parent, int x, int y){ Window win; XEvent xev; CEvent cev; int x2, y2; CState s; CWidget *quick, *safe, *backup; CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("saving", parent, x, y, _(" Options ")); CGetHintPos (&x, &y); quick = CDrawSwitch ("saving.Rquick", win, x, y, option_save_mode == 0, _(" Quick save "), 1 | RADIO_ONE_ALWAYS_ON);/* Toolhint */ CSetToolHint ("saving.Rquick", _("Truncates file then writes contents of editor")); CSetToolHint ("saving.Rquick.label", _("Truncates file then writes contents of editor")); CGetHintPos (0, &y2); safe = CDrawSwitch ("saving.Rsafe", win, x, y2, option_save_mode == 1, _(" Safe save "), 1 | RADIO_ONE_ALWAYS_ON);/* Toolhint */ CSetToolHint ("saving.Rsafe", _("Writes to temporary file, then renames if succesful")); CSetToolHint ("saving.Rsafe.label", _("Writes to temporary file, then renames if succesful")); CGetHintPos (0, &y); backup = CDrawSwitch ("saving.Rbackup", win, x, y, option_save_mode == 2, _(" Create backups "), 1 | RADIO_ONE_ALWAYS_ON);/* Toolhint */ CSetToolHint ("saving.Rbackup", _("Creates a backup file first")); CSetToolHint ("saving.Rbackup.label", _("Creates a backup file first")); CGetHintPos (0, &y2); CDrawText ("saving.ext", win, x, y2, _(" Backup file extension: ")); CGetHintPos (&x2, 0); CDrawTextInput ("saving.extti", win, x2, y2, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 16, option_backup_ext); CGetHintPos (0, &y); CDrawPixmapButton ("saving.ok", win, x, y, PIXMAP_BUTTON_TICK); CGetHintPos (&x2, 0); CDrawPixmapButton ("saving.cancel", win, x2, y, PIXMAP_BUTTON_CROSS); CGetHintPos (&x2, 0); CDrawPixmapButton ("saving.save", win, x2, y, PIXMAP_BUTTON_SAVE); CSetSizeHintPos ("saving"); CMapDialog ("saving"); CFocus (CIdent ("saving.ok")); for (;;) { CNextEvent (&xev, &cev); if (!CIdent("saving")) break; if (!strcmp (cev.ident, "saving.cancel") || cev.command == CK_Cancel) break; if (!strcmp (cev.ident, "saving.ok") || cev.command == CK_Enter || !strcmp (cev.ident, "saving.save")) {/* keypressed holds the whether switch is on or off */ if (CIdent ("saving.extti")) option_backup_ext = (char *) strdup ((CIdent ("saving.extti"))->text); if (quick->keypressed) option_save_mode = 0; else if (safe->keypressed) option_save_mode = 1; else if (backup->keypressed) option_save_mode = 2; if (!strcmp (cev.ident, "saving.save")) { save_options (); } else break; } } CDestroyWidget ("saving"); CRestoreState (&s);}static char *syntax_get_line (void *data, int line){ char **names; names = (char **) data; return names[line];}void menu_syntax_highlighting_dialog (Window parent, int x, int y){ char *names[1024] = {"None", 0}; int i, n; CWidget *w; w = CGetEditMenu (); if (!w) return; if (!w->editor) return; edit_load_syntax (0, names + 1, 0); for (n = 0; names[n]; n++); i = CListboxDialog (parent, x, y, 50, 20, _ (" Syntax Highlighting "), 0, 0, n, syntax_get_line, (void *) names); if (i >= 0) { if (!i) { edit_free_syntax_rules (w->editor); } else { edit_load_syntax (w->editor, 0, names[i]); } w->editor->explicit_syntax = 1; } for (n = 1; names[n]; n++) free (names[n]); CExpose (w->ident);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -