X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfunc.C;h=b74ad0e369fee3580d5d2dcd0d38b8762fa5a2a8;hb=5d3718cad2a2ef6a4d6a495054ab0705ba27b6b5;hp=9f0327bc49025c28e6f47e396a84c0c8ab71661b;hpb=df03e5fc10cc60f8ad4c438b028ec86bdecef4a7;p=lyx.git diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9f0327bc49..b74ad0e369 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -10,10 +10,6 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "lyxfunc.h" #include "version.h" #include "kbmap.h" @@ -31,6 +27,7 @@ #include "gettext.h" #include "Lsstream.h" #include "trans_mgr.h" +#include "encoding.h" #include "layout.h" #include "bufferview_funcs.h" #include "frontends/LyXView.h" @@ -45,29 +42,8 @@ #include "undo_funcs.h" #include "ParagraphParameters.h" -#include "insets/inseturl.h" -#include "insets/insetlatexaccent.h" -#include "insets/insettoc.h" -#include "insets/insetref.h" -#include "insets/insetparent.h" -#include "insets/insetindex.h" -#include "insets/insetinclude.h" -#include "insets/insetbib.h" -#include "insets/insetcite.h" -#include "insets/insettext.h" -#include "insets/insetert.h" -#include "insets/insetexternal.h" -#include "insets/insetgraphics.h" -#include "insets/insetfoot.h" -#include "insets/insetmarginal.h" -#include "insets/insetminipage.h" -#include "insets/insetfloat.h" -#if 0 -#include "insets/insetlist.h" -#include "insets/insettheorem.h" -#endif +#include "insets/insetcommand.h" #include "insets/insettabular.h" -#include "insets/insetcaption.h" #include "mathed/formulamacro.h" #include "mathed/math_cursor.h" @@ -90,6 +66,8 @@ #include "support/path.h" #include "support/lyxfunctional.h" +#include "BoostFormat.h" + #include #include #include @@ -120,12 +98,11 @@ extern void ShowLatexLog(); LyXFunc::LyXFunc(LyXView * o) : owner(o), + encoded_last_key(0), keyseq(toplevel_keymap.get(), toplevel_keymap.get()), - cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()) + cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()), + meta_fake_bit(key_modifier::none) { - meta_fake_bit = key_modifier::none; - lyx_dead_action = LFUN_NOACTION; - lyx_calling_dead_action = LFUN_NOACTION; } @@ -143,7 +120,7 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting) { if (selecting || TEXT(flag)->selection.mark()) { TEXT(flag)->setSelection(view()); - if (TEXT(flag)->bv_owner) + if (TEXT(flag)->isTopLevel()) view()->toggleToggle(); } view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR); @@ -155,9 +132,9 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting) void LyXFunc::handleKeyFunc(kb_action action) { - char c = keyseq.getLastKeyEncoded(); + char c = encoded_last_key; - if (keyseq.length() > 1) { + if (keyseq.length()) { c = 0; } @@ -183,6 +160,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, << keysym->getSymbolName() << endl; } + // Do nothing if we have nothing (JMarc) if (!keysym->isOK()) { lyxerr[Debug::KEY] << "Empty kbd action (probably composing)" @@ -191,17 +169,20 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, } if (keysym->isModifier()) { + lyxerr[Debug::KEY] << "isModifier true" << endl; return; } + Encoding const * encoding = view()->getEncoding(); + + encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : ""); + // Do a one-deep top-level lookup for // cancel and meta-fake keys. RVDK_PATCH_5 cancel_meta_seq.reset(); int action = cancel_meta_seq.addkey(keysym, state); - if (lyxerr.debugging(Debug::KEY)) { - lyxerr << "action first set to [" << action << "]" << endl; - } + lyxerr[Debug::KEY] << "action first set to [" << action << ']' << endl; // When not cancel or meta-fake, do the normal lookup. // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards. @@ -210,7 +191,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, // remove Caps Lock and Mod2 as a modifiers action = keyseq.addkey(keysym, (state | meta_fake_bit)); lyxerr[Debug::KEY] << "action now set to [" - << action << "]" << endl; + << action << ']' << endl; } // Dont remove this unless you know what you are doing. @@ -224,7 +205,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, if (lyxerr.debugging(Debug::KEY)) { lyxerr << "Key [action=" << action << "][" - << keyseq.print() << "]" + << keyseq.print() << ']' << endl; } @@ -236,31 +217,39 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, owner->message(keyseq.print()); } - if (action == LFUN_UNKNOWN_ACTION) { - // It is unknown, but what if we remove all - // the modifiers? (Lgb) - action = keyseq.addkey(keysym, key_modifier::none); - lyxerr[Debug::KEY] << "Removing modifiers...\n" - << "Action now set to [" - << action << "]" << endl; + // Maybe user can only reach the key via holding down shift. + // Let's see. But only if shift is the only modifier + if (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) { + lyxerr[Debug::KEY] << "Trying without shift" << endl; + action = keyseq.addkey(keysym, key_modifier::none); + lyxerr[Debug::KEY] << "Action now " << action << endl; + } - if (action == LFUN_UNKNOWN_ACTION) { + if (action == LFUN_UNKNOWN_ACTION) { + // Hmm, we didn't match any of the keysequences. See + // if it's normal insertable text not already covered + // by a binding + if (keysym->isText() && keyseq.length() == 1) { + lyxerr[Debug::KEY] << "isText() is true, inserting." << endl; + action = LFUN_SELFINSERT; + } else { + lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl; owner->message(_("Unknown function.")); return; } } if (action == LFUN_SELFINSERT) { - char c = keysym->getISOEncoded(); - string argument; + if (encoded_last_key != 0) { + string arg; + arg += encoded_last_key; - if (c != 0) - argument = c; + dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg)); - dispatch(FuncRequest(view(), LFUN_SELFINSERT, argument)); - lyxerr[Debug::KEY] << "SelfInsert arg[`" + lyxerr[Debug::KEY] << "SelfInsert arg[`" << argument << "']" << endl; + } } else { dispatch(action); } @@ -283,9 +272,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const return flag.disabled(true); } - if (ev.action == LFUN_UNKNOWN_ACTION) { + switch (ev.action) { + case LFUN_UNKNOWN_ACTION: +#ifndef HAVE_LIBAIKSAURUS + case LFUN_THESAURUS_ENTRY: +#endif + flag.unknown(true); + break; + default: + flag |= lyx_gui::getStatus(ev); + } + + if (flag.unknown()) { setStatusMessage(N_("Unknown action")); - return flag.unknown(true); + return flag; } // the default error message if we disable the command @@ -323,8 +323,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const || lyxrc.print_command == "none"; break; case LFUN_EXPORT: - disable = ev.argument == "fax" && - !Exporter::IsExportable(buf, ev.argument); + disable = ev.argument != "custom" + && !Exporter::IsExportable(buf, ev.argument); break; case LFUN_UNDO: disable = buf->undostack.empty(); @@ -332,11 +332,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_REDO: disable = buf->redostack.empty(); break; -#ifndef HAVE_LIBAIKSAURUS - case LFUN_THESAURUS_ENTRY: - disable = true; + case LFUN_CUT: + case LFUN_COPY: + if (tli) { + UpdatableInset * in = tli; + if (in->lyxCode() != Inset::TABULAR_CODE) { + in = tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE); + } + if (in && static_cast(in)->hasSelection()) { + disable = false; + break; + } + } + disable = !mathcursor && !view()->getLyXText()->selection.set(); break; -#endif case LFUN_RUNCHKTEX: disable = lyxrc.chktex_command == "none"; break; @@ -361,6 +370,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; } + case LFUN_INSET_OPTARG: + disable = (TEXT(false)->cursor.par()->layout()->optionalargs == 0); + break; + case LFUN_TABULAR_FEATURE: if (mathcursor) { #if 0 @@ -445,6 +458,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = !view()-> isSavedPosition(strToUnsignedInt(ev.argument)); break; + case LFUN_MERGE_CHANGES: + case LFUN_ACCEPT_CHANGE: + case LFUN_REJECT_CHANGE: + case LFUN_ACCEPT_ALL_CHANGES: + case LFUN_REJECT_ALL_CHANGES: + disable = !buf->params.tracking_changes; + break; case LFUN_INSET_TOGGLE: { LyXText * lt = view()->getLyXText(); disable = !(isEditableInset(lt->getInset()) @@ -507,6 +527,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSET_WIDE_FLOAT: code = Inset::FLOAT_CODE; break; + case LFUN_INSET_WRAP: + code = Inset::WRAP_CODE; + break; case LFUN_FLOAT_LIST: code = Inset::FLOAT_LIST_CODE; break; @@ -527,6 +550,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSERT_LABEL: code = Inset::LABEL_CODE; break; + case LFUN_INSET_OPTARG: + code = Inset::OPTARG_CODE; + break; case LFUN_REF_INSERT: code = Inset::REF_CODE; break; @@ -577,9 +603,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const default: break; } - if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) { + if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) disable = true; - } if (disable) flag.disabled(true); @@ -602,6 +627,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const if (ev.argument == buf->fileName()) flag.setOnOff(true); break; + case LFUN_TRACK_CHANGES: + flag.setOnOff(buf->params.tracking_changes); + break; default: break; } @@ -676,9 +704,15 @@ void LyXFunc::dispatch(string const & s, bool verbose) int const action = lyxaction.LookupFunc(s); if (action == LFUN_UNKNOWN_ACTION) { +#if USE_BOOST_FORMAT +boost::format fmt(_("Unknown function (%1$s)")); +fmt % s; +owner->message(fmt.str()); +#else string const msg = string(_("Unknown function (")) - + s + ")"; + + s + ')'; owner->message(msg); +#endif return; } @@ -696,7 +730,7 @@ void LyXFunc::dispatch(int ac, bool verbose) void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) { lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action - <<"] arg[" << ev.argument << "]" << endl; + <<"] arg[" << ev.argument << ']' << endl; // we have not done anything wrong yet. errorstat = false; @@ -740,14 +774,14 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) #endif if ((action == LFUN_UNKNOWN_ACTION) && argument.empty()) { - argument = keyseq.getLastKeyEncoded(); + argument = encoded_last_key; } // Undo/Redo is a bit tricky for insets. if (action == LFUN_UNDO) { - view()->menuUndo(); + view()->undo(); goto exit_with_message; } else if (action == LFUN_REDO) { - view()->menuRedo(); + view()->redo(); goto exit_with_message; } else if (((result=inset-> // Hand-over to inset's own dispatch: @@ -882,7 +916,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) } else { searched_string = last_search; } - bool fw = (action == LFUN_WORDFINDBACKWARD); + bool fw = (action == LFUN_WORDFINDFORWARD); if (!searched_string.empty()) { lyxfind::LyXFind(view(), searched_string, fw); } @@ -950,12 +984,18 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) case LFUN_MENUWRITE: if (!owner->buffer()->isUnnamed()) { ostringstream s1; - s1 << _("Saving document") << ' ' - << MakeDisplayPath(owner->buffer()->fileName() + "..."); - owner->message(s1.str().c_str()); +#if USE_BOOST_FORMAT + s1 << boost::format(_("Saving document %1$s...")) + % MakeDisplayPath(owner->buffer()->fileName()); +#else + s1 << _("Saving document ") + << MakeDisplayPath(owner->buffer()->fileName()) + << _("..."); +#endif + owner->message(STRCONV(s1.str())); MenuWrite(view(), owner->buffer()); s1 << _(" done."); - owner->message(s1.str().c_str()); + owner->message(STRCONV(s1.str())); } else WriteAs(view(), owner->buffer()); break; @@ -1033,11 +1073,11 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) break; case LFUN_UNDO: - view()->menuUndo(); + view()->undo(); break; case LFUN_REDO: - view()->menuRedo(); + view()->redo(); break; case LFUN_MENUSEARCH: @@ -1099,20 +1139,22 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) setErrorMessage(N_("Missing argument")); break; } - owner->prohibitInput(); string const fname = i18nLibFileSearch("doc", arg, "lyx"); if (fname.empty()) { lyxerr << "LyX: unable to find documentation file `" << arg << "'. Bad installation?" << endl; - owner->allowInput(); break; } ostringstream str; - str << _("Opening help file") << ' ' - << MakeDisplayPath(fname) << "..."; - owner->message(str.str().c_str()); +#if USE_BOOST_FORMAT + str << boost::format(_("Opening help file %1$s...")) + % MakeDisplayPath(fname); +#else + str << _("Opening help file ") + << MakeDisplayPath(fname) << _("..."); +#endif + owner->message(STRCONV(str.str())); view()->buffer(bufferlist.loadLyXFile(fname, false)); - owner->allowInput(); break; } @@ -1274,7 +1316,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) Paragraph * par = owner->buffer()->getParFromID(id); if (par == 0) { lyxerr[Debug::INFO] << "No matching paragraph found! [" - << id << "]" << endl; + << id << ']' << endl; break; } else { lyxerr[Debug::INFO] << "Paragraph " << par->id() @@ -1369,19 +1411,19 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar; break; - case LFUN_KMAP_OFF: // keymap off + case LFUN_KMAP_OFF: owner->getIntl().KeyMapOn(false); break; - case LFUN_KMAP_PRIM: // primary keymap + case LFUN_KMAP_PRIM: owner->getIntl().KeyMapPrim(); break; - case LFUN_KMAP_SEC: // secondary keymap + case LFUN_KMAP_SEC: owner->getIntl().KeyMapSec(); break; - case LFUN_KMAP_TOGGLE: // toggle keymap + case LFUN_KMAP_TOGGLE: owner->getIntl().ToggleKeyMap(); break; @@ -1439,11 +1481,20 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) x11_name != lcolor.getX11Name(LColor::graphicsbg)); if (!lcolor.setColor(lyx_name, x11_name)) { - static string const err1 (N_("Set-color \"")); - static string const err2 ( - N_("\" failed - color is undefined " - "or may not be redefined")); - setErrorMessage(_(err1) + lyx_name + _(err2)); +#if USE_BOOST_FORMAT + setErrorMessage( + boost::io::str( + boost::format( + _("Set-color \"%1$s\" failed " + "- color is undefined or " + "may not be redefined")) + % lyx_name)); +#else + setErrorMessage(_("Set-color ") + lyx_name + + _(" failed - color is undefined" + " or may not be redefined")); +#endif + break; } @@ -1515,7 +1566,7 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bo string dispatch_msg = msg; if (!dispatch_msg.empty()) - dispatch_msg += " "; + dispatch_msg += ' '; string comname = lyxaction.getActionName(ev.action); @@ -1529,7 +1580,7 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bo if (pseudoaction == LFUN_UNKNOWN_ACTION) { pseudoaction = ev.action; } else { - comname += " " + ev.argument; + comname += ' ' + ev.argument; argsadded = true; } } @@ -1539,12 +1590,12 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bo if (!shortcuts.empty()) { comname += ": " + shortcuts; } else if (!argsadded && !ev.argument.empty()) { - comname += " " + ev.argument; + comname += ' ' + ev.argument; } if (!comname.empty()) { comname = rtrim(comname); - dispatch_msg += "(" + comname + ')'; + dispatch_msg += '(' + comname + ')'; } lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl; @@ -1598,8 +1649,8 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) string(lyxrc.template_path))); FileDialog::Result result = - fileDlg.Select(lyxrc.template_path, - _("*.lyx|LyX Documents (*.lyx)")); + fileDlg.open(lyxrc.template_path, + _("*.lyx| LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) return; @@ -1637,8 +1688,8 @@ void LyXFunc::open(string const & fname) string(AddPath(system_lyxdir, "examples")))); FileDialog::Result result = - fileDlg.Select(initpath, - "*.lyx|LyX Documents (*.lyx)"); + fileDlg.open(initpath, + _("*.lyx| LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) return; @@ -1667,7 +1718,7 @@ void LyXFunc::open(string const & fname) if (!f.exist()) { if (!Alert::askQuestion(_("No such file"), disp_fn, _("Start a new document with this filename ?"))) { - owner->message(_("Canceled")); + owner->message(_("Canceled.")); return; } // the user specifically chose this name. Believe them. @@ -1677,21 +1728,32 @@ void LyXFunc::open(string const & fname) } ostringstream str; - str << _("Opening document") << ' ' << disp_fn << "..."; +#if USE_BOOST_FORMAT + str << boost::format(_("Opening document %1$s...")) % disp_fn; +#else + str << _("Opening document ") << disp_fn << _("..."); +#endif - owner->message(str.str().c_str()); + owner->message(STRCONV(str.str())); Buffer * openbuf = bufferlist.loadLyXFile(filename); + ostringstream str2; if (openbuf) { view()->buffer(openbuf); - ostringstream str; - str << _("Document") << ' ' << disp_fn << ' ' << _("opened."); - owner->message(str.str().c_str()); +#if USE_BOOST_FORMAT + str2 << boost::format(_("Document %1$s opened.")) % disp_fn; +#else + str2 << _("Document ") << disp_fn << _(" opened."); +#endif } else { - ostringstream str; - str << _("Could not open document") << ' ' << disp_fn; - owner->message(str.str().c_str()); +#if USE_BOOST_FORMAT + str2 << boost::format(_("Could not open document %1$s")) + % disp_fn; +#else + str2 << _("Could not open document ") << disp_fn; +#endif } + owner->message(STRCONV(str2.str())); } @@ -1714,8 +1776,14 @@ void LyXFunc::doImport(string const & argument) initpath = trypath; } +#if USE_BOOST_FORMAT + boost::format fmt(_("Select %1$s file to import")); + fmt % formats.prettyName(format); + string const text = fmt.str(); +#else string const text = _("Select ") + formats.prettyName(format) - + _(" file to import"); + + _(" file to import");; +#endif FileDialog fileDlg(owner, text, LFUN_IMPORT, @@ -1726,9 +1794,9 @@ void LyXFunc::doImport(string const & argument) string const extension = "*." + formats.extension(format) + "| " + formats.prettyName(format) - + " (*." + formats.extension(format) + ")"; + + " (*." + formats.extension(format) + ')'; - FileDialog::Result result = fileDlg.Select(initpath, + FileDialog::Result result = fileDlg.open(initpath, extension); if (result.first == FileDialog::Later) @@ -1775,7 +1843,7 @@ void LyXFunc::doImport(string const & argument) if (FileInfo(lyxfile, true).exist() && filename != lyxfile) { if (!Alert::askQuestion(_("A document by the name"), MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) { - owner->message(_("Canceled")); + owner->message(_("Canceled.")); return; } }