X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfunc.C;h=b74ad0e369fee3580d5d2dcd0d38b8762fa5a2a8;hb=5d3718cad2a2ef6a4d6a495054ab0705ba27b6b5;hp=179156e15761c28ba5735176425277b9ef40f521;hpb=53274e31ec1cc715c0b48921ee67818790c2e99a;p=lyx.git diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 179156e157..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" @@ -101,6 +98,7 @@ 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()), meta_fake_bit(key_modifier::none) @@ -122,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); @@ -134,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; } @@ -171,9 +169,14 @@ 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(); @@ -214,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); } @@ -261,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 @@ -301,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(); @@ -312,20 +334,18 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_CUT: case LFUN_COPY: - if (tli && tli->lyxCode() == Inset::TABULAR_CODE) { - InsetTabular * t(static_cast(tli)); - if (t->hasSelection()) { + 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; -#ifndef HAVE_LIBAIKSAURUS - case LFUN_THESAURUS_ENTRY: - disable = true; - break; -#endif case LFUN_RUNCHKTEX: disable = lyxrc.chktex_command == "none"; break; @@ -438,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()) @@ -600,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; } @@ -744,7 +774,7 @@ 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) { @@ -886,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); } @@ -1109,12 +1139,10 @@ 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; @@ -1127,7 +1155,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) #endif owner->message(STRCONV(str.str())); view()->buffer(bufferlist.loadLyXFile(fname, false)); - owner->allowInput(); break; } @@ -1623,7 +1650,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) FileDialog::Result result = fileDlg.open(lyxrc.template_path, - _("*.lyx|LyX Documents (*.lyx)")); + _("*.lyx| LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) return; @@ -1662,7 +1689,7 @@ void LyXFunc::open(string const & fname) FileDialog::Result result = fileDlg.open(initpath, - "*.lyx|LyX Documents (*.lyx)"); + _("*.lyx| LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) return; @@ -1691,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. @@ -1816,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; } }