📄 look-cool.c
字号:
/* look-cool.c - look 'n feel type: COOL Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include <stdio.h>#include <my_string.h>#include <stdlib.h>#include <stdarg.h>#include <X11/Intrinsic.h>#include "lkeysym.h"#include "stringtools.h"#include "app_glob.c"#include "coolwidget.h"#include "coollocal.h"#include "mad.h"extern struct look *look;/* {{{ search replace dialog */extern int replace_scanf;extern int replace_regexp;extern int replace_all;extern int replace_prompt;extern int replace_whole;extern int replace_case;extern int replace_backwards;extern int search_create_bookmark;void look_cool_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option){ Window win; XEvent xev; CEvent cev; CState s; int xh, yh, h, xb, ys, yc, yb, yr; CWidget *m; int text_input_width ; CBackupState (&s); CDisable ("*"); win = CDrawHeadedDialog ("replace", parent, x, y, heading); CGetHintPos (&xh, &h);/* NLS hotkey ? */ CIdent ("replace")->position = WINDOW_ALWAYS_RAISED;/* An input line comes after the ':' */ (CDrawText ("replace.t1", win, xh, h, _(" Enter search text : ")))->hotkey = 'E'; CGetHintPos (0, &yh); (m = CDrawTextInput ("replace.sinp", win, xh, yh, 10, AUTO_HEIGHT, 8192, *search_text))->hotkey = 'E'; if (replace_text) { CGetHintPos (0, &yh); (CDrawText ("replace.t2", win, xh, yh, _(" Enter replace text : ")))->hotkey = 'n'; CGetHintPos (0, &yh); (CDrawTextInput ("replace.rinp", win, xh, yh, 10, AUTO_HEIGHT, 8192, *replace_text))->hotkey = 'n'; CSetToolHint ("replace.t2", _("You can enter regexp substrings with %s\n(not \\1, \\2 like sed) then use \"Enter...order\"")); CSetToolHint ("replace.rinp", _("You can enter regexp substrings with %s\n(not \\1, \\2 like sed) then use \"Enter...order\"")); CGetHintPos (0, &yh); (CDrawText ("replace.t3", win, xh, yh, _(" Enter argument (or substring) order : ")))->hotkey = 'o'; CGetHintPos (0, &yh); (CDrawTextInput ("replace.ainp", win, xh, yh, 10, AUTO_HEIGHT, 256, *arg_order))->hotkey = 'o';/* Tool hint */ CSetToolHint ("replace.ainp", _("Enter the order of replacement of your scanf\nformat specifiers or regexp substrings, eg 3,1,2")); CSetToolHint ("replace.t3", _("Enter the order of replacement of your scanf\nformat specifiers or regexp substrings, eg 3,1,2")); } CGetHintPos (0, &yh); ys = yh;/* The following are check boxes */ CDrawSwitch ("replace.ww", win, xh, yh, replace_whole, _(" Whole words only "), 0); CGetHintPos (0, &yh); CDrawSwitch ("replace.case", win, xh, yh, replace_case, _(" Case sensitive "), 0); yc = yh; CGetHintPos (0, &yh); CDrawSwitch ("replace.reg", win, xh, yh, replace_regexp, _(" Regular expression "), 1); CSetToolHint ("replace.reg", _("See the regex man page for how\nto compose a regular expression")); CSetToolHint ("replace.reg.label", _("See the regex man page for how\nto compose a regular expression")); yb = yh; CGetHintPos (0, &yh); CGetHintPos (&xb, 0); if (option & SEARCH_DIALOG_OPTION_BACKWARDS) { CDrawSwitch ("replace.bkwd", win, xh, yh, replace_backwards, _(" Backwards "), 0);/* Tool hint */ CSetToolHint ("replace.bkwd", _("Warning: Searching backward can be slow")); CSetToolHint ("replace.bkwd.label", _("Warning: Searching backward can be slow")); } if (replace_text) { yr = ys; if (option & SEARCH_DIALOG_OPTION_BACKWARDS) yr = yc; } else { if (option & SEARCH_DIALOG_OPTION_BACKWARDS) { if (option & SEARCH_DIALOG_OPTION_BOOKMARK) yr = yb; else yr = yh; } else { if (option & SEARCH_DIALOG_OPTION_BOOKMARK) yr = yc; else yr = yb; } } if (replace_text) { CDrawSwitch ("replace.pr", win, xb, yr, replace_prompt, _(" Prompt on replace "), 0);/* Tool hint */ CSetToolHint ("replace.pr", _("Ask before making each replacement")); CGetHintPos (0, &yr); CDrawSwitch ("replace.all", win, xb, yr, replace_all, _(" Replace all "), 0);/* Tool hint */ CSetToolHint ("replace.all", _("Replace repeatedly")); CGetHintPos (0, &yr); } if (option & SEARCH_DIALOG_OPTION_BOOKMARK) { CDrawSwitch ("replace.bkmk", win, xb, yr, search_create_bookmark, _(" Bookmarks "), 0);/* Tool hint */ CSetToolHint ("replace.bkmk", _("Create bookmarks at all lines found")); CSetToolHint ("replace.bkmk.label", _("Create bookmarks at all lines found")); CGetHintPos (0, &yr); } CDrawSwitch ("replace.scanf", win, xb, yr, replace_scanf, _(" Scanf expression "), 1);/* Tool hint */ CSetToolHint ("replace.scanf", _("Allows entering of a C format string,\nsee the scanf man page")); get_hint_limits (&x, &y); CDrawPixmapButton ("replace.ok", win, x - WIDGET_SPACING - TICK_BUTTON_WIDTH, h, PIXMAP_BUTTON_TICK); CDrawPixmapButton ("replace.cancel", win, x - WIDGET_SPACING - TICK_BUTTON_WIDTH, h + WIDGET_SPACING + TICK_BUTTON_WIDTH, PIXMAP_BUTTON_CROSS);/* Tool hint */ CSetToolHint ("replace.ok", _("Begin search, Enter")); CSetToolHint ("replace.cancel", _("Abort this dialog, Esc")); CSetSizeHintPos ("replace"); CMapDialog ("replace"); m = CIdent ("replace"); text_input_width = m->width - WIDGET_SPACING * 3 - 4 - TICK_BUTTON_WIDTH ; CSetWidgetSize ("replace.sinp", text_input_width, (CIdent ("replace.sinp"))->height); if (replace_text) { CSetWidgetSize ("replace.rinp", text_input_width, (CIdent ("replace.rinp"))->height); CSetWidgetSize ("replace.ainp", text_input_width, (CIdent ("replace.ainp"))->height); } CFocus (CIdent ("replace.sinp")); for (;;) { CNextEvent (&xev, &cev); if (!CIdent ("replace")) { *search_text = 0; break; } if (!strcmp (cev.ident, "replace.cancel") || cev.command == CK_Cancel) { *search_text = 0; break; } if (!strcmp (cev.ident, "replace.reg") || !strcmp (cev.ident, "replace.scanf")) { if (CIdent ("replace.reg")->keypressed || CIdent ("replace.scanf")->keypressed) { if (!(CIdent ("replace.case")->keypressed)) { CIdent ("replace.case")->keypressed = 1; CExpose ("replace.case"); } } } if (!strcmp (cev.ident, "replace.ok") || cev.command == CK_Enter) { if (replace_text) { replace_all = CIdent ("replace.all")->keypressed; replace_prompt = CIdent ("replace.pr")->keypressed; *replace_text = (char *) strdup (CIdent ("replace.rinp")->text); *arg_order = (char *) strdup (CIdent ("replace.ainp")->text); } *search_text = (char *) strdup (CIdent ("replace.sinp")->text); replace_whole = CIdent ("replace.ww")->keypressed; replace_case = CIdent ("replace.case")->keypressed; replace_scanf = CIdent ("replace.scanf")->keypressed; replace_regexp = CIdent ("replace.reg")->keypressed; if (option & SEARCH_DIALOG_OPTION_BACKWARDS) { replace_backwards = CIdent ("replace.bkwd")->keypressed; } else { replace_backwards = 0; } if (option & SEARCH_DIALOG_OPTION_BOOKMARK) { search_create_bookmark = CIdent ("replace.bkmk")->keypressed; } else { search_create_bookmark = 0; } break; } } CDestroyWidget ("replace"); CRestoreState (&s);}/* }}} search replace dialog *//* {{{ file list stuff */static void destroy_filelist (CWidget * w){ if (w->hook) { free (w->hook); w->hook = 0; }}/* This doesn't apply to solaris: *//* * struct dirent { * long d_ino; * __kernel_off_t d_off; * unsigned short d_reclen; * char d_name[256]; * }; *//* * * #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) * #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) * #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) * #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) * #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) * #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) * #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) * * #define S_IRWXU 00700 * #define S_IRUSR 00400 * #define S_IWUSR 00200 * #define S_IXUSR 00100 * * #define S_IRWXG 00070 * #define S_IRGRP 00040 * #define S_IWGRP 00020 * #define S_IXGRP 00010 * * #define S_IRWXO 00007 * #define S_IROTH 00004 * #define S_IWOTH 00002 * #define S_IXOTH 00001 */#if 0static char *dname (struct dirent *directentry);#endif#ifdef HAVE_STRFTIME/* We want our own dates for NLS */#undef HAVE_STRFTIME#endif#undef gettext_noop#define gettext_noop(x) xvoid get_file_time (char *timestr, time_t file_time, int l);static char **get_filelist_line (void *data, int line_number, int *num_fields, int *tagged){ struct file_entry *directentry; static char *fields[10], size[24], mode[12], timestr[32]; static char name[520], *n; mode_t m; *num_fields = 4; /* name, size, date, mode only (for the mean time) */ directentry = (struct file_entry *) data; if (directentry[line_number].options & FILELIST_LAST_ENTRY) return 0; n = name; strcpy (name, directentry[line_number].name); fields[0] = name; sprintf (size, "\t%u", (unsigned int) directentry[line_number].stat.st_size); fields[1] = size; get_file_time (timestr, directentry[line_number].stat.st_mtime, 0); fields[2] = timestr; memset (mode, ' ', 11); mode[11] = 0; mode[0] = '-'; m = directentry[line_number].stat.st_mode; switch ((int) m & S_IFMT) { case S_IFLNK: mode[0] = 'l'; break; case S_IFDIR: mode[0] = 'd'; break; case S_IFCHR: mode[0] = 'c'; break; case S_IFBLK: mode[0] = 'b'; break; case S_IFIFO: mode[0] = 'f'; break; case S_IFSOCK: mode[0] = 's'; break; } mode[1] = m & S_IRUSR ? 'r' : '-'; mode[2] = m & S_IWUSR ? 'w' : '-'; mode[3] = m & S_IXUSR ? 'x' : '-'; mode[4] = m & S_IRGRP ? 'r' : '-'; mode[5] = m & S_IWGRP ? 'w' : '-'; mode[6] = m & S_IXGRP ? 'x' : '-'; mode[7] = m & S_IROTH ? 'r' : '-'; mode[8] = m & S_IWOTH ? 'w' : '-'; mode[9] = m & S_IXOTH ? 'x' : '-'; if (S_ISLNK (m)) { int l, i; char *p; p = directentry[line_number].name; l = strlen (n); for (i = 0; i < l; i++) { *n++ = '\b'; *n++ = *p++; } *n++ = '\0'; } else if (m & (S_IXUSR | S_IXGRP | S_IXOTH)) { int l, i; char *p; p = directentry[line_number].name; l = strlen (n); for (i = 0; i < l; i++) { *n++ = '\r'; *n++ = *p++; } *n++ = '\0'; } fields[3] = mode; fields[*num_fields] = 0; if (directentry[line_number].options & FILELIST_TAGGED_ENTRY) *tagged = 1; return fields;}CWidget *look_cool_draw_file_list (const char *identifier, Window parent, int x, int y, int width, int height, int line, int column, struct file_entry *directentry, long options){ struct file_entry e; CWidget *w; int n; if (!directentry) { memset (&e, 0, sizeof(e)); e.options = FILELIST_LAST_ENTRY; directentry = &e; n = 0; } else { for (n = 0; !(directentry[n].options & FILELIST_LAST_ENTRY); n++); /* count entries */ } w = CDrawFieldedTextbox (identifier, parent, x, y, width, height, line, column, get_filelist_line, options, directentry); w->destroy = destroy_filelist; w->hook = CMalloc (sizeof (struct file_entry) * (n + 1)); memcpy (w->hook, directentry, sizeof (struct file_entry) * (n + 1)); return w;}CWidget *look_cool_redraw_file_list (const char *identifier, struct file_entry *directentry, int preserve){ struct file_entry e; CWidget *w; int n; if (!directentry) { e.options = FILELIST_LAST_ENTRY; directentry = &e; n = 0; } else { for (n = 0; !(directentry[n].options & FILELIST_LAST_ENTRY); n++); /* count entries */ } w = CIdent (identifier); if (w->hook) free (w->hook); w->hook = CMalloc (sizeof (struct file_entry) * (n + 1)); memcpy (w->hook, directentry, sizeof (struct file_entry) * (n + 1)); w = CRedrawFieldedTextbox (identifier, preserve); return w;}struct file_entry *look_cool_get_file_list_line (CWidget * w, int line){ struct file_entry *e; static struct file_entry r; memset (&r, 0, sizeof (r)); e = (struct file_entry *) w->hook; if (e[line].options & FILELIST_LAST_ENTRY) r.options = FILELIST_LAST_ENTRY; else r = e[line]; return &r;}/* }}} file list stuff *//* {{{ file browser stuff */extern int option_file_browser_width;extern int option_file_browser_height;static char *mime_majors[3] ={"url", "text", 0};static Window draw_file_browser (const char *identifier, Window parent, int x, int y, const char *directory, const char *file, const char *label){ CWidget * w; struct file_entry *filelist = 0, *directorylist = 0; char *dir; char *resolved_path, *p; int y2, x2, x3, y3; Window win; dir = (char *) strdup (directory); if (parent == CRoot) win = CDrawMainWindow (identifier, label); else win = CDrawHeadedDialog (identifier, parent, x, y, label); (CIdent (identifier))->options |= WINDOW_ALWAYS_RAISED; CHourGlass (CFirstWindow); for (;;) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -