/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1998 The LyX Team. *
*======================================================*/
/* NAMING RULES FOR USER-COMMANDS Here's the set of rules to apply when a new command name is introduced: 1) Use the object.event order. That is, use `word-forward' instead of `forward-word'. 2) Don't introduce an alias for an already named object. Same for events. 3) Forward movement or focus is called `forward' (not `right'). 4) Backward movement or focus is called `backward' (not `left'). 5) Upward movement of focus is called `up'. 6) Downward movement is called `down'. 7) The begin of an object is called `begin' (not `start'). 8) The end of an object is called `end'. (May 19 1996, 12:04, RvdK)
*/
/* This table contains the actions that modify a buffer and therefore are not allowed for RO files. Do you think we have too much tables? Each single integer in this table replaces 5 lines of code in lyxfunc that include at least 3 function calls (several integers in the code segment). The table could in the near future be expanded adding a second integer field with attributes using these tags:
enum FUNC_ATTRIB { LFAT_NONE=0, // Nothing special LFAT_ISRO=1, // Is readonly (does not modify a buffer) LFAT_ISIA=2, // Is interactive (requires a GUI) LFAT_REQARG=4, // Requires argument LFAT_ISMO=8, // Only math mode LFAT_ETCETC };
/* This routines allow binding actions with argument. * Provisionally a fixed size array and global functions are used. * [asierra 20Jan96]
*/ #define MAX_PSEUDO_ACTION 128
LyXAction::~LyXAction()
{ if (lyx_func_args) { // This is wrong, so I'll just disable it for now. // The problem is that we might free memory twice in some situations... // It's better to leak a bit that to crash. (Asger) // for (int i=0; i < psd_idx; i++) { // free(lyx_func_args[i].name); // } delete[] lyx_func_args;
lyx_func_args = 0;
}
}
// Search for an existent pseudoaction, return -1 if it doesn't exist. int LyXAction::searchActionArg(kb_action action, charconst *arg)
{
kb_func_table *tb = &lyx_func_args[0]; for (int i=0; i<psd_idx; i++) { if (action==tb->action && !strcmp(tb->name, arg)) {
// Returns a pseudo-action given an action and its argument. int LyXAction::getPseudoAction(kb_action action, charconst *arg)
{ // Check if the pseudo-action already exist. int psdaction = searchActionArg(action, arg);
if (psdaction >= 0) return psdaction;
if (psd_idx>=MAX_PSEUDO_ACTION) {
lyxerr.print("Lyx Error: No more pseudo-actions allowed");
lyxerr.print(" Tell the developers."); return -1;
}
lyx_func_args[psd_idx].name = strdup(arg);
lyx_func_args[psd_idx].action = action;
psd_idx++; return LFUN_LASTACTION+psd_idx-1;
}
// Retrieves the real action and its argument. int LyXAction::retrieveActionArg(int i, charconst** arg)
{
i -= LFUN_LASTACTION; if (i >= 0 && i <psd_idx) {
*arg = lyx_func_args[i].name; return (int)lyx_func_args[i].action;
} else {
lyxerr.print("Lyx Error: Unrecognized pseudo-action"); return -1;
}
}
// Returns an action tag from a string. int LyXAction::LookupFunc(charconst *func)
{ if (!func) return LFUN_UNKNOWN_ACTION; if (func[0] == '\0') return LFUN_NOACTION;
/* In the scan loop below, l can never become r, so set r one past the last
valid func table slot. RVDK_PATCH_5 */ int k, l= 0, r = funcCount; int action = LFUN_UNKNOWN_ACTION; char *arg = strchr(func, ' ');
if (arg) *(arg++) = '\0';
while (l < r) {
last_action_idx = (l+r)/2;
k = strcmp(lyx_func_table[last_action_idx].name, func); if (k==0) {
action = lyx_func_table[last_action_idx].action; break;
} else if (k<0) l = last_action_idx+1; else r = last_action_idx;
} if (arg && action >= 0) {
action = getPseudoAction((kb_action)action, arg);
lyxerr.debug(LString("Pseudo action_arg[")
+ int(action) + '|'
+ PTR_AS_INT(arg) + ']',Error::KEY);
} return action;
}
int LyXAction::getApproxFunc(charconst *func)
{ int action = LookupFunc(func); if (action<0) { int k = strncmp(lyx_func_table[last_action_idx].name,
func, strlen(func)); if (k<0 && last_action_idx<funcCount-1)
last_action_idx++; elseif (k>0 && last_action_idx>0)
last_action_idx--;
charconst *LyXAction::getActionName(int action) const
{ // why LFUN_LASTACTION -1? Because LFUN_LASTACTION is too // large an because there is one internal command, hence // lyx_func_table is 2 less then LFUN_LASTACTION (Lgb) for (int i=0; i < funcCount; i++) { if (lyx_func_table[i].action==action) return lyx_func_table[i].name;
}
// Hmm.. let's see whether this is a pseudoaction
action -= LFUN_LASTACTION; if (action>=0 && action<psd_idx) { return lyx_func_args[action].name;
}
return"";
}
// Returns one line help associated with function // Now the missing strings are replaced by the command names. (Alejandro) charconst *LyXAction::helpText(kb_action action) const
{ staticbool is_sorted = false; static kb_func_table helpTexts[LFUN_LASTACTION] =
{
{ _("Describe command"), LFUN_APROPOS },
{ _("Select previous char"), LFUN_LEFTSEL },
{ _("Insert bibtex"), LFUN_INSERT_BIBTEX },
{ _("Autosave"), LFUN_AUTOSAVE },
{ _("Go to beginning of document"), LFUN_BEGINNINGBUF },
{ _("Select to beginning of document"), LFUN_BEGINNINGBUFSEL },
{ _("Close"), LFUN_CLOSEBUFFER },
{ _("Go to end of document"), LFUN_ENDBUF },
{ _("Select to end of document"), LFUN_ENDBUFSEL },
{ _("Fax"), LFUN_FAX },
{ _("New document"), LFUN_MENUNEW },
{ _("New document from template"), LFUN_MENUNEWTMPLT },
{ _("Open"), LFUN_MENUOPEN },
{ _("Switch to previous document"), LFUN_PREVBUFFER },
{ _("Print"), LFUN_MENUPRINT },
{ _("Revert to saved"), LFUN_MENURELOAD },
{ _("Update DVI"), LFUN_RUNLATEX },
{ _("Update PostScript"), LFUN_RUNDVIPS },
{ _("View DVI"), LFUN_PREVIEW },
{ _("View PostScript"), LFUN_PREVIEWPS },
{ _("Check TeX"), LFUN_RUNCHKTEX },
{ _("Save"), LFUN_MENUWRITE },
{ _("Save As"), LFUN_MENUWRITEAS },
{ _("Cancel"), LFUN_CANCEL },
{ _("Go one char back"), LFUN_LEFT },
{ _("Go one char forward"), LFUN_RIGHT },
{ _("Insert citation"), LFUN_INSERT_CITATION },
{ _("Execute command"), LFUN_EXEC_COMMAND },
{ _("Copy"), LFUN_COPY },
{ _("Cut"), LFUN_CUT },
{ _("Decrement environment depth"), LFUN_DEPTH_MIN },
{ _("Increment environment depth"), LFUN_DEPTH_PLUS },
{ _("Change environment depth"), LFUN_DEPTH },
{ _("Change itemize bullet settings"), LFUN_BUFFERBULLETSSELECT },
{ _("Go down"), LFUN_DOWN },
{ _("Select next line"), LFUN_DOWNSEL },
{ _("Choose Paragraph Environment"), LFUN_DROP_LAYOUTS_CHOICE },
{ _("Go to next error"), LFUN_GOTOERROR },
{ _("Insert Figure"), LFUN_FIGURE },
{ _("Find & Replace"), LFUN_MENUSEARCH },
{ _("Toggle cursor does/doesn't follow the scrollbar"), LFUN_TOGGLECURSORFOLLOW },
{ _("Toggle bold"), LFUN_BOLD },
{ _("Toggle code style"), LFUN_CODE },
{ _("Default font style"), LFUN_DEFAULT },
{ _("Toggle emphasize"), LFUN_EMPH },
{ _("Toggle user defined style"), LFUN_FREE },
{ _("Toggle noun style"), LFUN_NOUN },
{ _("Toggle roman font style"), LFUN_ROMAN },
{ _("Toggle sans font style"), LFUN_SANS },
{ _("Set font size"), LFUN_FONT_SIZE },
{ _("Show font state"), LFUN_FONT_STATE },
{ _("Toggle font underline"), LFUN_UNDERLINE },
{ _("Insert Footnote"), LFUN_FOOTMELT },
{ _("Select next char"), LFUN_RIGHTSEL },
{ _("Insert horizontal fill"), LFUN_HFILL },
{ _("Insert hyphenation point"), LFUN_HYPHENATION },
{ _("Insert ... dots"), LFUN_LDOTS },
{ _("Insert end of sentence period"), LFUN_END_OF_SENTENCE },
{ _("Turn off keymap"), LFUN_KMAP_OFF },
{ _("Use primary keymap"), LFUN_KMAP_PRIM },
{ _("Use secondary keymap"), LFUN_KMAP_SEC },
{ _("Toggle keymap"), LFUN_KMAP_TOGGLE },
{ _("Insert Label"), LFUN_INSERT_LABEL },
{ _("Copy paragraph environment type"), LFUN_LAYOUT_COPY },
{ _("Paste paragraph environment type"), LFUN_LAYOUT_PASTE },
{ _("Specify paper size and margins"), LFUN_LAYOUT_PAPER },
{ _("Go to beginning of line"), LFUN_HOME },
{ _("Select to beginning of line"), LFUN_HOMESEL },
{ _("Go to end of line"), LFUN_END },
{ _("Select to end of line"), LFUN_ENDSEL },
{ _("Exit"), LFUN_QUIT },
{ _("Insert Margin note"), LFUN_MARGINMELT },
{ _("Math Greek"), LFUN_GREEK },
{ _("Math mode"), LFUN_MATH_MODE },
{ _("Go one paragraph down"), LFUN_DOWN_PARAGRAPH },
{ _("Select next paragraph"), LFUN_DOWN_PARAGRAPHSEL },
{ _("Go one paragraph up"), LFUN_UP_PARAGRAPH },
{ _("Select previous paragraph"), LFUN_UP_PARAGRAPHSEL },
{ _("Paste"), LFUN_PASTE },
{ _("Insert protected space"), LFUN_PROTECTEDSPACE },
{ _("Insert quote"), LFUN_QUOTE },
{ _("Reconfigure"), LFUN_RECONFIGURE },
{ _("Redo"), LFUN_REDO },
{ _("Insert cross reference"), LFUN_INSERT_REF },
{ _("Insert Table"), LFUN_TABLE },
{ _("Toggle TeX style"), LFUN_TEX },
{ _("Undo"), LFUN_UNDO },
{ _("Melt"), LFUN_MELT },
{ _("Import document"), LFUN_IMPORT },
{ _("Remove all error boxes"), LFUN_REMOVEERRORS } // { "reference-back", LFUN_REFBACK }, // { "reference-goto", LFUN_REFGOTO },
};
// Sort to make it faster if (!is_sorted) { int i=0; while (i < LFUN_LASTACTION-1) { if (helpTexts[i].action == 0) {
helpTexts[i].action = (kb_action)i;
helpTexts[i].name = getActionName(i);
i++;
} elseif (helpTexts[i].action != i) { int k = helpTexts[i].action;
kb_func_table tmp = helpTexts[k];
helpTexts[k] = helpTexts[i];
helpTexts[i] = tmp; if (k < i) i++;
} else {
i++;
}
}
is_sorted = true;
}
if (action <=1 || action >=funcCount) goto no_desc;
if (helpTexts[action].action == action) { return helpTexts[action].name;
} // + LString(' ') + int(is_ro) + LString(']'));
no_desc: // In an ideal world, this never happens: return _("No description available!");
}
// Function to compare items from the attrib table. int actioncomp(constvoid *a, constvoid *b)
{ intconst *ia=(intconst*)a, *ib=(intconst*)b; return (*ia)-(*ib);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.