📄 coolpython.c
字号:
break; } free (d); free (f); return r;}static void close_window (long force){ if (force) edit[current_edit]->editor->stopped = 1; else edit_execute_command (edit[current_edit]->editor, CK_Exit, -1);}static void new_window (void){ new_window_callback (0);}static int load (char *filename){ return edit_load_file_from_filename (edit[current_edit]->editor, filename);}static void status (char *text){ char id[33]; CWidget *w; strcpy (id, CIdentOf (edit[current_edit])); strcat (id, ".text"); w = CIdent (id); free (w->text); w->text = (char *) strdup (text); render_status (w, 0);}static char *file (void){ return edit[current_edit]->editor->filename;}static char *directory (void){ return edit[current_edit]->editor->dir;}static long modified (void){ return (long) edit[current_edit]->editor->modified;}static char *input_dialog (char *title, char *prompt, char *def){ static char x[4096]; char *p; p = CInputDialog (title, 0, 0, 0, 60 * FONT_MEAN_WIDTH, def, title, "%s", prompt); if (!p) return 0; else strncpy (x, p, 4095); free (p); return x;}static char *load_file_dialog (char *title, char *dir, char *def){ static char x[4096]; char *p; p = CGetLoadFile (0, 0, 0, dir, def, title); if (!p) return 0; else strncpy (x, p, 4095); free (p); return x;}static char *save_file_dialog (char *title, char *dir, char *def){ static char x[4096]; char *p; p = CGetSaveFile (0, 0, 0, dir, def, title); if (!p) return 0; else strncpy (x, p, 4095); free (p); return x;}static char *status_input (char *prompt, char *def){ char id[33]; int width = 0; XEvent xevent; KeySym k; static char t[260]; char *r; CState s; CWidget *w, *p = 0, *i; r = 0; strcpy (id, CIdentOf (edit[current_edit])); strcat (id, ".text"); CBackupState (&s); CDisable ("*"); w = CIdent (id); if (*prompt) { p = CDrawText ("status_prompt", edit[current_edit]->parentid, CXof (w), CYof (w), "%s", prompt); width = CWidthOf (p); } i = CDrawTextInput ("status_input", edit[current_edit]->parentid, CXof (w) + width, CYof (w), CWidthOf (edit[current_edit]) - width, AUTO_HEIGHT, 256, def); CFocus (i); for (;;) { CNextEvent (&xevent, 0); if (xevent.type == KeyPress) { k = CKeySym (&xevent); if (k == XK_KP_Enter || k == XK_Return) { strcpy (t, i->text); r = t; break; } if (k == XK_Escape) break; } } if (p) CDestroyWidget (p->ident); CDestroyWidget (i->ident); CRestoreState (&s); return r;}static void message_dialog (char *title, char *message){ CMessageDialog (0, 0, 0, 0, title, "%s", message);}static void error_dialog (char *title, char *message){ CErrorDialog (0, 0, 0, title, "%s", message);}static long tab_width (void){ return (long) TAB_SIZE;}static long column_pixels (long i){ return 0;}static long buffer_size (void){ return edit[current_edit]->editor->last_byte;}static void key_press (void){ edit_push_key_press (edit[current_edit]->editor);}static void redraw_page (void){ edit[current_edit]->editor->force |= REDRAW_PAGE; edit_update_curs_row (edit[current_edit]->editor); edit_update_curs_col (edit[current_edit]->editor);}static int shell_output (char *title, char *s, char *name){ return execute_background_display_output (title, s, name);}PyObject *edit__get_editors (PyObject * self, PyObject * args){ PyObject *ret; int i; char *p; if (!PyArg_ParseTuple (args, ":get_editors")) return NULL; ret = PyTuple_New (last_edit); for (i = 0; i < last_edit; i++) { if (edit[i]->editor->filename && edit[i]->editor->dir) { p = malloc (strlen (edit[i]->editor->filename) + strlen (edit[i]->editor->dir) + 1); strcpy (p, edit[i]->editor->dir); strcat (p, edit[i]->editor->filename); PyTuple_SetItem (ret, i, PyString_FromString (p)); free (p); } else { PyTuple_SetItem (ret, i, Py_None); } } return ret;}PyObject *edit__indent (PyObject * self, PyObject * args){ int extra = 0; if (!PyArg_ParseTuple (args, "|i:indent", &extra)) return NULL; edit_auto_indent (edit[current_edit]->editor, extra, 0); Py_INCREF (Py_None); return Py_None;}PyObject *edit__file_type (PyObject * self, PyObject * args){ PyObject *ret; char *type = 0; if (!PyArg_ParseTuple (args, "|s:file_type", &type)) return NULL; ret = PyString_FromString (edit[current_edit]->editor->syntax_type ? edit[current_edit]->editor->syntax_type : ""); if (type) { edit_load_syntax (edit[current_edit]->editor, 0, type); edit[current_edit]->editor->explicit_syntax = 1; edit[current_edit]->editor->force |= REDRAW_PAGE; } return ret;}PyObject *edit__query_dialog (PyObject * self, PyObject * args){ char *heading, *text; char *b1 = 0, *b2 = 0, *b3 = 0, *b4 = 0, *b5 = 0, *b6 = 0, *b7 = 0, *b8 = 0, *b9 = 0, *b10 = 0; int i; if (!PyArg_ParseTuple (args, "ss|ssssssssss:query_dialog", &heading, &text, &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &b9, &b10)) return NULL; i = CQueryDialog (0, 0, 0, heading, text, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, 0); return PyInt_FromLong (i);}PyObject *edit__overwrite (PyObject * self, PyObject * args){ PyObject *ret; int i = -1; if (!PyArg_ParseTuple (args, "|i:overwrite", &i)) return NULL; ret = PyInt_FromLong (edit[current_edit]->editor->overwrite); if (i != -1) { edit[current_edit]->editor->overwrite = (i != 0); CSetCursorColor (edit[current_edit]->editor->overwrite ? color_palette (24) : color_palette (19)); } return ret;}PyObject *edit__generic_dialog (PyObject * self, PyObject * args){ PyObject *a1 = 0, *a2 = 0, *a3 = 0, *a4 = 0, *a5 = 0, *a6 = 0, *a7 = 0, *result = 0; char **inputs; char **input_labels; char **input_names; char **input_tool_hints; char ***inputs_result; char **check_labels; char **check_tool_hints; static int *check_values; int **check_values_result; int options = 0; char *heading = 0; int r, n_inputs, n_checks, width = -1, i; if (!PyArg_ParseTuple (args, "sO!O!O!O!O!O!O!|ii:gtk_dialog_cauldron", &heading, &PyTuple_Type, &a1, &PyTuple_Type, &a2, &PyTuple_Type, &a3, &PyTuple_Type, &a4, &PyTuple_Type, &a5, &PyTuple_Type, &a6, &PyTuple_Type, &a7, &width, &options )) return NULL; n_inputs = min (PyTuple_Size (a1), min (PyTuple_Size (a2), PyTuple_Size (a3))); n_checks = min (PyTuple_Size (a5), PyTuple_Size (a6)); inputs = malloc ((n_inputs + 1) * sizeof (char *)); input_labels = malloc ((n_inputs + 1) * sizeof (char *)); input_names = malloc ((n_inputs + 1) * sizeof (char *)); input_tool_hints = malloc ((n_inputs + 1) * sizeof (char *)); inputs_result = malloc ((n_inputs + 1) * sizeof (char **)); check_labels = malloc ((n_checks + 1) * sizeof (char *)); check_tool_hints = malloc ((n_checks + 1) * sizeof (char *)); check_values = malloc ((n_checks + 1) * sizeof (int)); check_values_result = malloc ((n_checks + 1) * sizeof (int *)); for (i = 0; i < n_inputs; i++) { PyObject *item; item = PyTuple_GetItem (a1, i); inputs[i] = PyString_Check (item) ? PyString_AsString (item) : ""; item = PyTuple_GetItem (a2, i); input_labels[i] = PyString_Check (item) ? PyString_AsString (item) : ""; item = PyTuple_GetItem (a3, i); input_names[i] = PyString_Check (item) ? PyString_AsString (item) : ""; input_tool_hints[i] = 0; if (i < PyTuple_Size (a4)) { item = PyTuple_GetItem (a4, i); if (PyString_Check (item)) input_tool_hints[i] = PyString_AsString (item); } inputs_result[i] = &inputs[i]; } inputs_result[i] = 0; for (i = 0; i < n_checks; i++) { PyObject *item; item = PyTuple_GetItem (a5, i); check_values[i] = PyInt_Check (item) ? PyInt_AsLong (item) : 0; item = PyTuple_GetItem (a6, i); check_labels[i] = PyString_Check (item) ? PyString_AsString (item) : ""; check_tool_hints[i] = 0; if (i < PyTuple_Size (a7)) { item = PyTuple_GetItem (a7, i); if (PyString_Check (item)) check_tool_hints[i] = PyString_AsString (item); } check_values_result[i] = &check_values[i]; } check_values_result[i] = 0; r = CInputsWithOptions (0, 0, 0, heading, inputs_result, input_labels, input_names, input_tool_hints, check_values_result, check_labels, check_tool_hints, options, max (width > 0 ? width : 60, 20)); if (!r) { result = PyTuple_New (2); PyTuple_SetItem (result, 0, PyTuple_New (n_inputs)); for (i = 0; i < n_inputs; i++) PyTuple_SetItem (PyTuple_GetItem (result, 0), i, PyString_FromString (inputs[i])); PyTuple_SetItem (result, 1, PyTuple_New (n_checks)); for (i = 0; i < n_checks; i++) PyTuple_SetItem (PyTuple_GetItem (result, 1), i, PyInt_FromLong ((long) check_values[i])); } else { result = Py_None; Py_INCREF (result); } free (inputs); free (input_labels); free (input_names); free (input_tool_hints); free (inputs_result); free (check_labels); free (check_tool_hints); free (check_values); free (check_values_result); return result;}extern int column_highlighting;PyObject *edit__markers (PyObject * self, PyObject * args){ PyObject *ret; long m1 = -1000000000, m2 = -1000000000; int c1 = -1000000000, c2 = -1000000000; int column = -1; long r1, r2; if (!PyArg_ParseTuple (args, "|lliii:markers", &m1, &m2, &column, &c1, &c2)) return NULL; if (eval_marks (edit[current_edit]->editor, &r1, &r2)) { Py_INCREF (Py_None); ret = Py_None; } else { ret = PyTuple_New (5); PyTuple_SetItem (ret, 0, PyInt_FromLong (r1)); PyTuple_SetItem (ret, 1, PyInt_FromLong (r2)); PyTuple_SetItem (ret, 3, PyInt_FromLong (column_highlighting)); PyTuple_SetItem (ret, 4, PyInt_FromLong (min (edit[current_edit]->editor->column1, edit[current_edit]->editor->column2))); PyTuple_SetItem (ret, 5, PyInt_FromLong (max (edit[current_edit]->editor->column1, edit[current_edit]->editor->column2))); } if (m1 != -1000000000) { edit[current_edit]->editor->mark1 = m1; edit[current_edit]->editor->mark2 = m2 < 0 ? -1 : m2; if (column == 0 || column == -1000000000 || c1 == -1000000000 || c2 == -1000000000) { if (column_highlighting) edit_push_action (edit[current_edit]->editor, COLUMN_ON); edit_push_markers (edit[current_edit]->editor); column_highlighting = 0; edit[current_edit]->editor->column1 = edit[current_edit]->editor->column2 = 0; } else { if (!column_highlighting) edit_push_action (edit[current_edit]->editor, COLUMN_OFF); edit_push_markers (edit[current_edit]->editor); column_highlighting = 1; edit[current_edit]->editor->column1 = c1; edit[current_edit]->editor->column2 = c2 < 0 ? -1 : c2; } } return ret;}PyObject *edit__get_key (PyObject * self, PyObject * args){ PyObject *ret; XEvent xevent; CState s; KeySym k = NoSymbol; char *t; if (!PyArg_ParseTuple (args, ":get_key")) return NULL; CBackupState (&s); CDisable ("*"); for (;;) { CNextEvent (&xevent, 0); if (xevent.type == KeyPress) { k = CKeySym (&xevent); if (k && !mod_type_key (k)) break; } } CRestoreState (&s); ret = PyTuple_New (2); t = XKeysymToString (k); if (t) PyTuple_SetItem (ret, 0, PyString_FromString (t)); else PyTuple_SetItem (ret, 0, Py_None); PyTuple_SetItem (ret, 1, PyInt_FromLong (xevent.xkey.state)); return ret;}PyObject *edit__key (PyObject * self, PyObject * args){ int i, found = 0; int modifiers; char *key = 0; KeySym keysym; char *statement = 0; if (!PyArg_ParseTuple (args, "si|s:key", &key, &modifiers, &statement)) return NULL; if (!strncmp (key, "XK_", 3)) key += 3; keysym = XStringToKeysym (key); if (keysym == NoSymbol) { char e[128]; sprintf (e, _ ("No such key \"%s\".\n\tCheck the header file keysymdef.h on your\n\tsystem for a list of valid keys."), key); PyErr_SetString (PyExc_ValueError, e); return NULL; }/* is the key already bound? */ for (i = 0; i < last_binding; i++) if (bindings[i].modifiers == modifiers && bindings[i].keysym == keysym) { found = 1; if (bindings[i].statement) free (bindings[i].statement); memset (&bindings[i], 0, sizeof (bindings[0])); if (i == last_binding - 1) last_binding--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -