]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.C
2394391649eb3a0f02a077d5674a4ce482aca910
[lyx.git] / src / lyxfunc.C
1 /**
2  * \file lyxfunc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  * \author Allan Rae
13  * \author Dekel Tsur
14  * \author Martin Vermeer
15  * \author Jürgen Vigna
16  *
17  * Full author contact details are available in file CREDITS.
18  */
19
20 #include <config.h>
21
22 #include "lyxfunc.h"
23
24 #include "BranchList.h"
25 #include "buffer.h"
26 #include "buffer_funcs.h"
27 #include "bufferlist.h"
28 #include "bufferparams.h"
29 #include "BufferView.h"
30 #include "cursor.h"
31 #include "debug.h"
32 #include "dispatchresult.h"
33 #include "encoding.h"
34 #include "exporter.h"
35 #include "format.h"
36 #include "funcrequest.h"
37 #include "gettext.h"
38 #include "importer.h"
39 #include "intl.h"
40 #include "iterators.h"
41 #include "kbmap.h"
42 #include "LColor.h"
43 #include "lyx_cb.h"
44 #include "LyXAction.h"
45 #include "lyxfind.h"
46 #include "lyxrc.h"
47 #include "lyxrow.h"
48 #include "lyxserver.h"
49 #include "lyxvc.h"
50 #include "paragraph.h"
51 #include "ParagraphParameters.h"
52 #include "undo.h"
53
54 #include "insets/insetbox.h"
55 #include "insets/insetbranch.h"
56 #include "insets/insetcommand.h"
57 #include "insets/insetert.h"
58 #include "insets/insetexternal.h"
59 #include "insets/insetfloat.h"
60 #include "insets/insetgraphics.h"
61 #include "insets/insetnote.h"
62 #include "insets/insettabular.h"
63 #include "insets/insetvspace.h"
64 #include "insets/insetwrap.h"
65
66 #include "frontends/Alert.h"
67 #include "frontends/Dialogs.h"
68 #include "frontends/FileDialog.h"
69 #include "frontends/lyx_gui.h"
70 #include "frontends/LyXKeySym.h"
71 #include "frontends/LyXView.h"
72 #include "frontends/Menubar.h"
73 #include "frontends/Toolbar.h"
74
75 #include "support/FileInfo.h"
76 #include "support/filetools.h"
77 #include "support/forkedcontr.h"
78 #include "support/globbing.h"
79 #include "support/path.h"
80 #include "support/path_defines.h"
81 #include "support/tostr.h"
82 #include "support/std_sstream.h"
83 #include "support/os.h"
84
85 using bv_funcs::freefont2string;
86
87 using lyx::support::AddName;
88 using lyx::support::AddPath;
89 using lyx::support::bformat;
90 using lyx::support::ChangeExtension;
91 using lyx::support::FileFilterList;
92 using lyx::support::FileInfo;
93 using lyx::support::FileSearch;
94 using lyx::support::ForkedcallsController;
95 using lyx::support::i18nLibFileSearch;
96 using lyx::support::IsDirWriteable;
97 using lyx::support::IsFileReadable;
98 using lyx::support::isStrInt;
99 using lyx::support::MakeAbsPath;
100 using lyx::support::MakeDisplayPath;
101 using lyx::support::Path;
102 using lyx::support::rtrim;
103 using lyx::support::split;
104 using lyx::support::strToInt;
105 using lyx::support::strToUnsignedInt;
106 using lyx::support::system_lyxdir;
107 using lyx::support::token;
108 using lyx::support::trim;
109 using lyx::support::user_lyxdir;
110 using lyx::support::prefixIs;
111 using lyx::support::os::getTmpDir;
112
113 using std::endl;
114 using std::make_pair;
115 using std::pair;
116 using std::string;
117 using std::istringstream;
118
119
120 extern BufferList bufferlist;
121 extern LyXServer * lyxserver;
122 extern bool selection_possible;
123
124 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
125
126 // (alkis)
127 extern tex_accent_struct get_accent(kb_action action);
128
129
130 LyXFunc::LyXFunc(LyXView * lv)
131         : owner(lv),
132         encoded_last_key(0),
133         keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
134         cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
135         meta_fake_bit(key_modifier::none)
136 {
137 }
138
139
140 void LyXFunc::handleKeyFunc(kb_action action)
141 {
142         char c = encoded_last_key;
143
144         if (keyseq.length()) {
145                 c = 0;
146         }
147
148         owner->getIntl().getTransManager()
149                 .deadkey(c, get_accent(action).accent, view()->getLyXText());
150         // Need to clear, in case the minibuffer calls these
151         // actions
152         keyseq.clear();
153         // copied verbatim from do_accent_char
154         view()->cursor().resetAnchor();
155         view()->update();
156 }
157
158
159 void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
160 {
161         lyxerr[Debug::KEY] << "KeySym is " << keysym->getSymbolName() << endl;
162
163         // Do nothing if we have nothing (JMarc)
164         if (!keysym->isOK()) {
165                 lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
166                                    << endl;
167                 return;
168         }
169
170         if (keysym->isModifier()) {
171                 lyxerr[Debug::KEY] << "isModifier true" << endl;
172                 return;
173         }
174
175         Encoding const * encoding = view()->cursor().getEncoding();
176
177         encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
178
179         // Do a one-deep top-level lookup for
180         // cancel and meta-fake keys. RVDK_PATCH_5
181         cancel_meta_seq.reset();
182
183         FuncRequest func = cancel_meta_seq.addkey(keysym, state);
184         lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
185
186         // When not cancel or meta-fake, do the normal lookup.
187         // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
188         // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
189         if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
190                 // remove Caps Lock and Mod2 as a modifiers
191                 func = keyseq.addkey(keysym, (state | meta_fake_bit));
192                 lyxerr[Debug::KEY] << "action now set to ["
193                         << func.action << ']' << endl;
194         }
195
196         // Dont remove this unless you know what you are doing.
197         meta_fake_bit = key_modifier::none;
198
199         // can this happen now ?
200         if (func.action == LFUN_NOACTION) {
201                 func = FuncRequest(LFUN_PREFIX);
202         }
203
204         if (lyxerr.debugging(Debug::KEY)) {
205                 lyxerr << "Key [action="
206                        << func.action << "]["
207                        << keyseq.print() << ']'
208                        << endl;
209         }
210
211         // already here we know if it any point in going further
212         // why not return already here if action == -1 and
213         // num_bytes == 0? (Lgb)
214
215         if (keyseq.length() > 1) {
216                 owner->message(keyseq.print());
217         }
218
219
220         // Maybe user can only reach the key via holding down shift.
221         // Let's see. But only if shift is the only modifier
222         if (func.action == LFUN_UNKNOWN_ACTION &&
223             state == key_modifier::shift) {
224                 lyxerr[Debug::KEY] << "Trying without shift" << endl;
225                 func = keyseq.addkey(keysym, key_modifier::none);
226                 lyxerr[Debug::KEY] << "Action now " << func.action << endl;
227         }
228
229         if (func.action == LFUN_UNKNOWN_ACTION) {
230                 // Hmm, we didn't match any of the keysequences. See
231                 // if it's normal insertable text not already covered
232                 // by a binding
233                 if (keysym->isText() && keyseq.length() == 1) {
234                         lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
235                         func = FuncRequest(LFUN_SELFINSERT);
236                 } else {
237                         lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
238                         owner->message(_("Unknown function."));
239                         return;
240                 }
241         }
242
243         if (func.action == LFUN_SELFINSERT) {
244                 if (encoded_last_key != 0) {
245                         string arg(1, encoded_last_key);
246                         dispatch(FuncRequest(LFUN_SELFINSERT, arg));
247                         lyxerr[Debug::KEY]
248                                 << "SelfInsert arg[`" << arg << "']" << endl;
249                 }
250         } else {
251                 dispatch(func);
252         }
253 }
254
255
256 FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
257 {
258         //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
259         FuncStatus flag;
260         Buffer * buf = owner->buffer();
261         LCursor & cur = view()->cursor();
262
263         if (cmd.action == LFUN_NOACTION) {
264                 setStatusMessage(N_("Nothing to do"));
265                 flag.enabled(false);
266                 return flag;
267         }
268
269         switch (cmd.action) {
270         case LFUN_UNKNOWN_ACTION:
271 #ifndef HAVE_LIBAIKSAURUS
272         case LFUN_THESAURUS_ENTRY:
273 #endif
274                 flag.unknown(true);
275                 flag.enabled(false);
276                 break;
277         default:
278                 flag |= lyx_gui::getStatus(cmd);
279         }
280
281         if (flag.unknown()) {
282                 setStatusMessage(N_("Unknown action"));
283                 return flag;
284         }
285
286         // the default error message if we disable the command
287         setStatusMessage(N_("Command disabled"));
288
289         // Check whether we need a buffer
290         if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
291                 // Yes we need a buffer, do we have one?
292                 if (buf) {
293                         // yes
294                         // Can we use a readonly buffer?
295                         if (buf->isReadonly() &&
296                             !lyxaction.funcHasFlag(cmd.action,
297                                                    LyXAction::ReadOnly)) {
298                                 // no
299                                 setStatusMessage(N_("Document is read-only"));
300                                 flag.enabled(false);
301                         }
302                 } else {
303                         // no
304                         setStatusMessage(N_("Command not allowed with"
305                                             "out any document open"));
306                         flag.enabled(false);
307                         return flag;
308                 }
309         }
310
311         // I would really like to avoid having this switch and rather try to
312         // encode this in the function itself.
313         // -- And I'd rather let an inset decide which LFUNs it is willing
314         // to handle (Andre')
315         bool enable = true;
316         switch (cmd.action) {
317         case LFUN_TOOLTIPS_TOGGLE:
318                 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
319                 break;
320
321         case LFUN_READ_ONLY_TOGGLE:
322                 flag.setOnOff(buf->isReadonly());
323                 break;
324
325         case LFUN_SWITCHBUFFER:
326                 // toggle on the current buffer, but do not toggle off
327                 // the other ones (is that a good idea?)
328                 if (cmd.argument == buf->fileName())
329                         flag.setOnOff(true);
330                 break;
331
332         case LFUN_TRACK_CHANGES:
333                 flag.setOnOff(buf->params().tracking_changes);
334                 break;
335
336         case LFUN_EXPORT:
337                 enable = cmd.argument == "custom"
338                         || Exporter::IsExportable(*buf, cmd.argument);
339                 break;
340         case LFUN_UNDO:
341                 enable = !buf->undostack().empty();
342                 break;
343         case LFUN_REDO:
344                 enable = !buf->redostack().empty();
345                 break;
346         case LFUN_CUT:
347         case LFUN_COPY:
348                 enable = cur.selection();
349                 break;
350
351         case LFUN_RUNCHKTEX:
352                 enable = buf->isLatex() && lyxrc.chktex_command != "none";
353                 break;
354
355         case LFUN_BUILDPROG:
356                 enable = Exporter::IsExportable(*buf, "program");
357                 break;
358
359         case LFUN_LAYOUT_TABULAR:
360                 enable = cur.innerInsetOfType(InsetBase::TABULAR_CODE);
361                 break;
362
363         case LFUN_LAYOUT:
364         case LFUN_LAYOUT_PARAGRAPH:
365                 enable = !cur.inset().forceDefaultParagraphs(&cur.inset());
366                 break;
367
368         case LFUN_VC_REGISTER:
369                 enable = !buf->lyxvc().inUse();
370                 break;
371         case LFUN_VC_CHECKIN:
372                 enable = buf->lyxvc().inUse() && !buf->isReadonly();
373                 break;
374         case LFUN_VC_CHECKOUT:
375                 enable = buf->lyxvc().inUse() && buf->isReadonly();
376                 break;
377         case LFUN_VC_REVERT:
378         case LFUN_VC_UNDO:
379                 enable = buf->lyxvc().inUse();
380                 break;
381         case LFUN_MENURELOAD:
382                 enable = !buf->isUnnamed() && !buf->isClean();
383                 break;
384         case LFUN_BOOKMARK_GOTO:
385                 enable = view()->isSavedPosition(strToUnsignedInt(cmd.argument));
386                 break;
387
388         case LFUN_MERGE_CHANGES:
389         case LFUN_ACCEPT_CHANGE:
390         case LFUN_REJECT_CHANGE:
391         case LFUN_ACCEPT_ALL_CHANGES:
392         case LFUN_REJECT_ALL_CHANGES:
393                 enable = buf && buf->params().tracking_changes;
394                 break;
395
396         case LFUN_INSET_SETTINGS: {
397                 enable = false;
398                 if (!cur.size())
399                         break;
400                 UpdatableInset * inset = cur.inset().asUpdatableInset();
401                 lyxerr << "inset: " << inset << endl;
402                 if (!inset)
403                         break;
404
405                 // jump back to owner if an InsetText, so
406                 // we get back to the InsetTabular or whatever
407                 if (inset->lyxCode() == InsetOld::TEXT_CODE)
408                         inset = inset->owner();
409                 lyxerr << "inset 2: " << inset << endl;
410                 if (!inset)
411                         break;
412
413                 InsetOld::Code code = inset->lyxCode();
414                 switch (code) {
415                         case InsetOld::TABULAR_CODE:
416                                 enable = cmd.argument == "tabular";
417                                 break;
418                         case InsetOld::ERT_CODE:
419                                 enable = cmd.argument == "ert";
420                                 break;
421                         case InsetOld::FLOAT_CODE:
422                                 enable = cmd.argument == "float";
423                                 break;
424                         case InsetOld::WRAP_CODE:
425                                 enable = cmd.argument == "wrap";
426                                 break;
427                         case InsetOld::NOTE_CODE:
428                                 enable = cmd.argument == "note";
429                                 break;
430                         case InsetOld::BRANCH_CODE:
431                                 enable = cmd.argument == "branch";
432                                 break;
433                         case InsetOld::BOX_CODE:
434                                 enable = cmd.argument == "box";
435                                 break;
436                         default:
437                                 break;
438                 }
439                 break;
440         }
441
442         case LFUN_DIALOG_SHOW: {
443                 string const name = cmd.getArg(0);
444                 if (!buf)
445                         enable = name == "aboutlyx"
446                                 || name == "file"
447                                 || name == "preferences"
448                                 || name == "texinfo";
449                 else if (name == "print")
450                         enable = Exporter::IsExportable(*buf, "dvi")
451                                 && lyxrc.print_command != "none";
452                 else if (name == "character")
453                         enable = cur.inset().lyxCode() != InsetOld::ERT_CODE;
454                 else if (name == "vclog")
455                         enable = buf->lyxvc().inUse();
456                 else if (name == "latexlog")
457                         enable = IsFileReadable(buf->getLogName().second);
458                 break;
459         }
460
461         case LFUN_MENUNEW:
462         case LFUN_MENUNEWTMPLT:
463         case LFUN_WORDFINDFORWARD:
464         case LFUN_WORDFINDBACKWARD:
465         case LFUN_PREFIX:
466         case LFUN_EXEC_COMMAND:
467         case LFUN_CANCEL:
468         case LFUN_META_FAKE:
469         case LFUN_CLOSEBUFFER:
470         case LFUN_MENUWRITE:
471         case LFUN_WRITEAS:
472         case LFUN_UPDATE:
473         case LFUN_PREVIEW:
474         case LFUN_IMPORT:
475         case LFUN_QUIT:
476         case LFUN_TOCVIEW:
477         case LFUN_AUTOSAVE:
478         case LFUN_RECONFIGURE:
479         case LFUN_HELP_OPEN:
480         case LFUN_FILE_NEW:
481         case LFUN_FILE_OPEN:
482         case LFUN_DROP_LAYOUTS_CHOICE:
483         case LFUN_MENU_OPEN_BY_NAME:
484         case LFUN_GETNAME:
485         case LFUN_NOTIFY:
486         case LFUN_GOTOFILEROW:
487         case LFUN_GOTO_PARAGRAPH:
488         case LFUN_DIALOG_SHOW_NEW_INSET:
489         case LFUN_DIALOG_SHOW_NEXT_INSET:
490         case LFUN_DIALOG_UPDATE:
491         case LFUN_DIALOG_HIDE:
492         case LFUN_DIALOG_DISCONNECT_INSET:
493         case LFUN_CHILDOPEN:
494         case LFUN_TOGGLECURSORFOLLOW:
495         case LFUN_KMAP_OFF:
496         case LFUN_KMAP_PRIM:
497         case LFUN_KMAP_SEC:
498         case LFUN_KMAP_TOGGLE:
499         case LFUN_REPEAT:
500         case LFUN_SEQUENCE:
501         case LFUN_SAVEPREFERENCES:
502         case LFUN_SCREEN_FONT_UPDATE:
503         case LFUN_SET_COLOR:
504         case LFUN_MESSAGE:
505         case LFUN_EXTERNAL_EDIT:
506                 // these are handled in our dispatch()
507                 break;
508
509         default:
510                 cur.getStatus(cmd, flag);
511                 return flag;
512         }
513
514         flag.enabled(enable);
515         return flag;
516 }
517
518
519 namespace {
520
521 bool ensureBufferClean(BufferView * bv)
522 {
523         Buffer & buf = *bv->buffer();
524         if (buf.isClean())
525                 return true;
526
527         string const file = MakeDisplayPath(buf.fileName(), 30);
528         string text = bformat(_("The document %1$s has unsaved "
529                                 "changes.\n\nDo you want to save "
530                                 "the document?"), file);
531         int const ret = Alert::prompt(_("Save changed document?"),
532                                       text, 0, 1, _("&Save"),
533                                       _("&Cancel"));
534
535         if (ret == 0)
536                 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
537
538         return buf.isClean();
539 }
540
541 } //namespace anon
542
543
544 void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
545 {
546         string const argument = cmd.argument;
547         kb_action const action = cmd.action;
548
549         lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
550         //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
551
552         // we have not done anything wrong yet.
553         errorstat = false;
554         dispatch_buffer.erase();
555         selection_possible = false;
556
557         // We cannot use this function here
558         if (!getStatus(cmd).enabled()) {
559                 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
560                        << lyxaction.getActionName(action)
561                        << " [" << action << "] is disabled at this location"
562                        << endl;
563                 setErrorMessage(getStatusMessage());
564
565         } else {
566
567                 if (view()->available())
568                         view()->hideCursor();
569
570                 switch (action) {
571
572                 case LFUN_WORDFINDFORWARD:
573                 case LFUN_WORDFINDBACKWARD: {
574                         static string last_search;
575                         string searched_string;
576
577                         if (!argument.empty()) {
578                                 last_search = argument;
579                                 searched_string = argument;
580                         } else {
581                                 searched_string = last_search;
582                         }
583
584                         if (searched_string.empty())
585                                 break;
586
587                         bool const fw = action == LFUN_WORDFINDFORWARD;
588                         string const data =
589                                 lyx::find::find2string(searched_string, true, false, fw);
590                         view()->dispatch(FuncRequest(LFUN_WORD_FIND, data));
591                         break;
592                 }
593
594                 case LFUN_PREFIX:
595                         owner->message(keyseq.printOptions());
596                         break;
597
598                 case LFUN_EXEC_COMMAND:
599                         owner->focus_command_buffer();
600                         break;
601
602                 case LFUN_CANCEL:
603                         keyseq.reset();
604                         meta_fake_bit = key_modifier::none;
605                         if (view()->available())
606                                 // cancel any selection
607                                 dispatch(FuncRequest(LFUN_MARK_OFF));
608                         setMessage(N_("Cancel"));
609                         break;
610
611                 case LFUN_META_FAKE:
612                         meta_fake_bit = key_modifier::alt;
613                         setMessage(keyseq.print());
614                         break;
615
616                 case LFUN_READ_ONLY_TOGGLE:
617                         if (owner->buffer()->lyxvc().inUse())
618                                 owner->buffer()->lyxvc().toggleReadOnly();
619                         else
620                                 owner->buffer()->setReadonly(
621                                         !owner->buffer()->isReadonly());
622                         break;
623
624                 // --- Menus -----------------------------------------------
625                 case LFUN_MENUNEW:
626                         menuNew(argument, false);
627                         break;
628
629                 case LFUN_MENUNEWTMPLT:
630                         menuNew(argument, true);
631                         break;
632
633                 case LFUN_CLOSEBUFFER:
634                         closeBuffer();
635                         break;
636
637                 case LFUN_MENUWRITE:
638                         if (!owner->buffer()->isUnnamed()) {
639                                 string const str = bformat(_("Saving document %1$s..."),
640                                          MakeDisplayPath(owner->buffer()->fileName()));
641                                 owner->message(str);
642                                 MenuWrite(owner->buffer());
643                                 owner->message(str + _(" done."));
644                         } else
645                                 WriteAs(owner->buffer());
646                         break;
647
648                 case LFUN_WRITEAS:
649                         WriteAs(owner->buffer(), argument);
650                         break;
651
652                 case LFUN_MENURELOAD: {
653                         string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
654                         string text = bformat(_("Any changes will be lost. Are you sure "
655                                 "you want to revert to the saved version of the document %1$s?"), file);
656                         int const ret = Alert::prompt(_("Revert to saved document?"),
657                                 text, 0, 1, _("&Revert"), _("&Cancel"));
658
659                         if (ret == 0)
660                                 view()->reload();
661                         break;
662                 }
663
664                 case LFUN_UPDATE:
665                         Exporter::Export(owner->buffer(), argument, true);
666                         view()->showErrorList(BufferFormat(*owner->buffer()));
667                         break;
668
669                 case LFUN_PREVIEW:
670                         Exporter::Preview(owner->buffer(), argument);
671                         view()->showErrorList(BufferFormat(*owner->buffer()));
672                         break;
673
674                 case LFUN_BUILDPROG:
675                         Exporter::Export(owner->buffer(), "program", true);
676                         view()->showErrorList(_("Build"));
677                         break;
678
679                 case LFUN_RUNCHKTEX:
680                         owner->buffer()->runChktex();
681                         view()->showErrorList(_("ChkTeX"));
682                         break;
683
684                 case LFUN_EXPORT:
685                         if (argument == "custom")
686                                 owner->getDialogs().showSendto();
687                         else {
688                                 Exporter::Export(owner->buffer(), argument, false);
689                                 view()->showErrorList(BufferFormat(*owner->buffer()));
690                         }
691                         break;
692
693                 case LFUN_IMPORT:
694                         doImport(argument);
695                         break;
696
697                 case LFUN_QUIT:
698                         QuitLyX();
699                         break;
700
701                 case LFUN_TOCVIEW: {
702                         InsetCommandParams p("tableofcontents");
703                         string const data = InsetCommandMailer::params2string("toc", p);
704                         owner->getDialogs().show("toc", data, 0);
705                         break;
706                 }
707
708                 case LFUN_AUTOSAVE:
709                         AutoSave(view());
710                         break;
711
712                 case LFUN_RECONFIGURE:
713                         Reconfigure(view());
714                         break;
715
716                 case LFUN_HELP_OPEN: {
717                         string const arg = argument;
718                         if (arg.empty()) {
719                                 setErrorMessage(N_("Missing argument"));
720                                 break;
721                         }
722                         string const fname = i18nLibFileSearch("doc", arg, "lyx");
723                         if (fname.empty()) {
724                                 lyxerr << "LyX: unable to find documentation file `"
725                                                          << arg << "'. Bad installation?" << endl;
726                                 break;
727                         }
728                         owner->message(bformat(_("Opening help file %1$s..."),
729                                 MakeDisplayPath(fname)));
730                         view()->loadLyXFile(fname, false);
731                         break;
732                 }
733
734                 // --- version control -------------------------------
735                 case LFUN_VC_REGISTER:
736                         if (!ensureBufferClean(view()))
737                                 break;
738                         if (!owner->buffer()->lyxvc().inUse()) {
739                                 owner->buffer()->lyxvc().registrer();
740                                 view()->reload();
741                         }
742                         break;
743
744                 case LFUN_VC_CHECKIN:
745                         if (!ensureBufferClean(view()))
746                                 break;
747                         if (owner->buffer()->lyxvc().inUse()
748                                         && !owner->buffer()->isReadonly()) {
749                                 owner->buffer()->lyxvc().checkIn();
750                                 view()->reload();
751                         }
752                         break;
753
754                 case LFUN_VC_CHECKOUT:
755                         if (!ensureBufferClean(view()))
756                                 break;
757                         if (owner->buffer()->lyxvc().inUse()
758                                         && owner->buffer()->isReadonly()) {
759                                 owner->buffer()->lyxvc().checkOut();
760                                 view()->reload();
761                         }
762                         break;
763
764                 case LFUN_VC_REVERT:
765                         owner->buffer()->lyxvc().revert();
766                         view()->reload();
767                         break;
768
769                 case LFUN_VC_UNDO:
770                         owner->buffer()->lyxvc().undoLast();
771                         view()->reload();
772                         break;
773
774                 // --- buffers ----------------------------------------
775                 case LFUN_SWITCHBUFFER:
776                         view()->setBuffer(bufferlist.getBuffer(argument));
777                         break;
778
779                 case LFUN_FILE_NEW:
780                         NewFile(view(), argument);
781                         break;
782
783                 case LFUN_FILE_OPEN:
784                         open(argument);
785                         break;
786
787                 case LFUN_DROP_LAYOUTS_CHOICE:
788                         owner->getToolbar().openLayoutList();
789                         break;
790
791                 case LFUN_MENU_OPEN_BY_NAME:
792                         owner->getMenubar().openByName(argument);
793                         break;
794
795                 // --- lyxserver commands ----------------------------
796                 case LFUN_GETNAME:
797                         setMessage(owner->buffer()->fileName());
798                         lyxerr[Debug::INFO] << "FNAME["
799                                                          << owner->buffer()->fileName()
800                                                          << "] " << endl;
801                         break;
802
803                 case LFUN_NOTIFY:
804                         dispatch_buffer = keyseq.print();
805                         lyxserver->notifyClient(dispatch_buffer);
806                         break;
807
808                 case LFUN_GOTOFILEROW: {
809                         string file_name;
810                         int row;
811                         istringstream is(argument);
812                         is >> file_name >> row;
813                         if (prefixIs(file_name, getTmpDir())) {
814                                 // Needed by inverse dvi search. If it is a file
815                                 // in tmpdir, call the apropriated function
816                                 view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
817                         } else {
818                                 // Must replace extension of the file to be .lyx
819                                 // and get full path
820                                 string const s = ChangeExtension(file_name, ".lyx");
821                                 // Either change buffer or load the file
822                                 if (bufferlist.exists(s)) {
823                                         view()->setBuffer(bufferlist.getBuffer(s));
824                                 } else {
825                                         view()->loadLyXFile(s);
826                                 }
827                         }
828
829                         view()->setCursorFromRow(row);
830
831                         view()->center();
832                         // see BufferView_pimpl::center()
833                         view()->updateScrollbar();
834                         break;
835                 }
836
837                 case LFUN_GOTO_PARAGRAPH: {
838                         istringstream is(argument);
839                         int id;
840                         is >> id;
841                         ParIterator par = owner->buffer()->getParFromID(id);
842                         if (par == owner->buffer()->par_iterator_end()) {
843                                 lyxerr[Debug::INFO] << "No matching paragraph found! ["
844                                                                 << id << ']' << endl;
845                                 break;
846                         } else {
847                                 lyxerr[Debug::INFO] << "Paragraph " << par->id()
848                                                                 << " found." << endl;
849                         }
850
851                         // Set the cursor
852                         view()->setCursor(par, 0);
853
854                         view()->switchKeyMap();
855                         owner->view_state_changed();
856
857                         view()->center();
858                         // see BufferView_pimpl::center()
859                         view()->updateScrollbar();
860                         break;
861                 }
862
863                 case LFUN_DIALOG_SHOW: {
864                         string const name = cmd.getArg(0);
865                         string data = trim(cmd.argument.substr(name.size()));
866
867                         if (name == "character") {
868                                 data = freefont2string();
869                                 if (!data.empty())
870                                         owner->getDialogs().show("character", data);
871                         }
872                         else if (name == "document")
873                                 owner->getDialogs().showDocument();
874                         else if (name == "preamble")
875                                 owner->getDialogs().showPreamble();
876                         else if (name == "preferences")
877                                 owner->getDialogs().showPreferences();
878                         else if (name == "print")
879                                 owner->getDialogs().showPrint();
880                         else if (name == "spellchecker")
881                                 owner->getDialogs().showSpellchecker();
882
883                         else if (name == "latexlog") {
884                                 pair<Buffer::LogType, string> const logfile =
885                                         owner->buffer()->getLogName();
886                                 switch (logfile.first) {
887                                 case Buffer::latexlog:
888                                         data = "latex ";
889                                         break;
890                                 case Buffer::buildlog:
891                                         data = "literate ";
892                                         break;
893                                 }
894                                 data += logfile.second;
895                                 owner->getDialogs().show("log", data);
896                         }
897                         else if (name == "vclog") {
898                                 string const data = "vc " +
899                                         owner->buffer()->lyxvc().getLogFile();
900                                 owner->getDialogs().show("log", data);
901                         }
902                         else
903                                 owner->getDialogs().show(name, data);
904                         break;
905                 }
906
907                 case LFUN_DIALOG_SHOW_NEW_INSET: {
908                         string const name = cmd.getArg(0);
909                         string data = trim(cmd.argument.substr(name.size()));
910                         if (name == "bibitem" ||
911                             name == "bibtex" ||
912                             name == "include" ||
913                             name == "index" ||
914                             name == "label" ||
915                             name == "ref" ||
916                             name == "toc" ||
917                             name == "url") {
918                                 InsetCommandParams p(name);
919                                 data = InsetCommandMailer::params2string(name, p);
920                         } else if (name == "box") {
921                                 // \c data == "Boxed" || "Frameless" etc
922                                 InsetBoxParams p(data);
923                                 data = InsetBoxMailer::params2string(p);
924                         } else if (name == "branch") {
925                                 InsetBranchParams p;
926                                 data = InsetBranchMailer::params2string(p);
927                         } else if (name == "citation") {
928                                 InsetCommandParams p("cite");
929                                 data = InsetCommandMailer::params2string(name, p);
930                         } else if (name == "ert") {
931                                 data = InsetERTMailer::params2string(InsetCollapsable::Open);
932                         } else if (name == "external") {
933                                 InsetExternalParams p;
934                                 Buffer const & buffer = *owner->buffer();
935                                 data = InsetExternalMailer::params2string(p, buffer);
936                         } else if (name == "float") {
937                                 InsetFloatParams p;
938                                 data = InsetFloatMailer::params2string(p);
939                         } else if (name == "graphics") {
940                                 InsetGraphicsParams p;
941                                 Buffer const & buffer = *owner->buffer();
942                                 data = InsetGraphicsMailer::params2string(p, buffer);
943                         } else if (name == "note") {
944                                 InsetNoteParams p;
945                                 data = InsetNoteMailer::params2string(p);
946                         } else if (name == "vspace") {
947                                 VSpace space;
948                                 data = InsetVSpaceMailer::params2string(space);
949                         } else if (name == "wrap") {
950                                 InsetWrapParams p;
951                                 data = InsetWrapMailer::params2string(p);
952                         }
953                         owner->getDialogs().show(name, data, 0);
954                         break;
955                 }
956
957                 case LFUN_DIALOG_SHOW_NEXT_INSET:
958                         break;
959
960                 case LFUN_DIALOG_UPDATE: {
961                         string const & name = argument;
962                         // Can only update a dialog connected to an existing inset
963                         InsetBase * inset = owner->getDialogs().getOpenInset(name);
964                         if (inset) {
965                                 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument);
966                                 inset->dispatch(view()->cursor(), fr);
967                         } else if (name == "paragraph") {
968                                 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
969                         }
970                         break;
971                 }
972
973                 case LFUN_DIALOG_HIDE:
974                         Dialogs::hide(argument, 0);
975                         break;
976
977                 case LFUN_DIALOG_DISCONNECT_INSET:
978                         owner->getDialogs().disconnect(argument);
979                         break;
980
981                 case LFUN_CHILDOPEN: {
982                         string const filename =
983                                 MakeAbsPath(argument, owner->buffer()->filePath());
984                         setMessage(N_("Opening child document ") +
985                                          MakeDisplayPath(filename) + "...");
986                         view()->savePosition(0);
987                         string const parentfilename = owner->buffer()->fileName();
988                         if (bufferlist.exists(filename))
989                                 view()->setBuffer(bufferlist.getBuffer(filename));
990                         else
991                                 view()->loadLyXFile(filename);
992                         // Set the parent name of the child document.
993                         // This makes insertion of citations and references in the child work,
994                         // when the target is in the parent or another child document.
995                         owner->buffer()->setParentName(parentfilename);
996                         break;
997                 }
998
999                 case LFUN_TOGGLECURSORFOLLOW:
1000                         lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
1001                         break;
1002
1003                 case LFUN_KMAP_OFF:
1004                         owner->getIntl().KeyMapOn(false);
1005                         break;
1006
1007                 case LFUN_KMAP_PRIM:
1008                         owner->getIntl().KeyMapPrim();
1009                         break;
1010
1011                 case LFUN_KMAP_SEC:
1012                         owner->getIntl().KeyMapSec();
1013                         break;
1014
1015                 case LFUN_KMAP_TOGGLE:
1016                         owner->getIntl().ToggleKeyMap();
1017                         break;
1018
1019                 case LFUN_REPEAT: {
1020                         // repeat command
1021                         string countstr;
1022                         string rest = split(argument, countstr, ' ');
1023                         istringstream is(countstr);
1024                         int count = 0;
1025                         is >> count;
1026                         lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1027                         for (int i = 0; i < count; ++i)
1028                                 dispatch(lyxaction.lookupFunc(rest));
1029                         break;
1030                 }
1031
1032                 case LFUN_SEQUENCE:
1033                         // argument contains ';'-terminated commands
1034                         while (!argument.empty()) {
1035                                 string first;
1036                                 string rest = split(argument, first, ';');
1037                                 dispatch(lyxaction.lookupFunc(rest));
1038                         }
1039                         break;
1040
1041                 case LFUN_SAVEPREFERENCES: {
1042                         Path p(user_lyxdir());
1043                         lyxrc.write("preferences");
1044                         break;
1045                 }
1046
1047                 case LFUN_SCREEN_FONT_UPDATE:
1048                         // handle the screen font changes.
1049                         lyxrc.set_font_norm_type();
1050                         lyx_gui::update_fonts();
1051                         // All visible buffers will need resize
1052                         view()->resize();
1053                         break;
1054
1055                 case LFUN_SET_COLOR: {
1056                         string lyx_name;
1057                         string const x11_name = split(argument, lyx_name, ' ');
1058                         if (lyx_name.empty() || x11_name.empty()) {
1059                                 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1060                                                         " <x11_name>"));
1061                                 break;
1062                         }
1063
1064                         bool const graphicsbg_changed =
1065                                 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1066                                  x11_name != lcolor.getX11Name(LColor::graphicsbg));
1067
1068                         LColor::color col = lcolor.getFromLyXName(lyx_name);
1069                         if (!lcolor.setColor(col, x11_name)) {
1070                                 setErrorMessage(
1071                                         bformat(_("Set-color \"%1$s\" failed "
1072                                                                 "- color is undefined or "
1073                                                                 "may not be redefined"), lyx_name));
1074                                 break;
1075                         }
1076
1077                         lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1078
1079                         if (graphicsbg_changed) {
1080 #ifdef WITH_WARNINGS
1081 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1082 #endif
1083 #if 0
1084                                 lyx::graphics::GCache::get().changeDisplay(true);
1085 #endif
1086                         }
1087                         break;
1088                 }
1089
1090                 case LFUN_MESSAGE:
1091                         owner->message(argument);
1092                         break;
1093
1094                 case LFUN_TOOLTIPS_TOGGLE:
1095                         owner->getDialogs().toggleTooltips();
1096                         break;
1097
1098                 case LFUN_EXTERNAL_EDIT: {
1099                         FuncRequest fr(action, argument);
1100                         InsetExternal().dispatch(view()->cursor(), fr);
1101                         break;
1102                 }
1103
1104                 default: {
1105                         DispatchResult res = view()->cursor().dispatch(cmd);
1106                         if (!res.dispatched());
1107                                 view()->dispatch(cmd);
1108                         break;
1109                 }
1110                 }
1111         }
1112
1113         if (view()->available()) {
1114                 view()->fitCursor();
1115                 view()->update();
1116                 view()->cursor().updatePos();
1117                 // if we executed a mutating lfun, mark the buffer as dirty
1118                 if (getStatus(cmd).enabled()
1119                     && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
1120                     && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
1121                         view()->buffer()->markDirty();
1122         }
1123
1124         if (view()->cursor().inTexted()) {
1125                 view()->owner()->updateLayoutChoice();
1126                 sendDispatchMessage(getMessage(), cmd, verbose);
1127         }
1128 }
1129
1130
1131 void LyXFunc::sendDispatchMessage(string const & msg,
1132                                   FuncRequest const & cmd, bool verbose)
1133 {
1134         owner->updateMenubar();
1135         owner->updateToolbar();
1136
1137         if (cmd.action == LFUN_SELFINSERT || !verbose) {
1138                 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1139                 if (!msg.empty())
1140                         owner->message(msg);
1141                 return;
1142         }
1143
1144         string dispatch_msg = msg;
1145         if (!dispatch_msg.empty())
1146                 dispatch_msg += ' ';
1147
1148         string comname = lyxaction.getActionName(cmd.action);
1149
1150         bool argsadded = false;
1151
1152         if (!cmd.argument.empty()) {
1153                 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1154                         comname += ' ' + cmd.argument;
1155                         argsadded = true;
1156                 }
1157         }
1158
1159         string const shortcuts = toplevel_keymap->findbinding(cmd);
1160
1161         if (!shortcuts.empty()) {
1162                 comname += ": " + shortcuts;
1163         } else if (!argsadded && !cmd.argument.empty()) {
1164                 comname += ' ' + cmd.argument;
1165         }
1166
1167         if (!comname.empty()) {
1168                 comname = rtrim(comname);
1169                 dispatch_msg += '(' + comname + ')';
1170         }
1171
1172         lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1173         if (!dispatch_msg.empty())
1174                 owner->message(dispatch_msg);
1175 }
1176
1177
1178 void LyXFunc::setupLocalKeymap()
1179 {
1180         keyseq.stdmap = toplevel_keymap.get();
1181         keyseq.curmap = toplevel_keymap.get();
1182         cancel_meta_seq.stdmap = toplevel_keymap.get();
1183         cancel_meta_seq.curmap = toplevel_keymap.get();
1184 }
1185
1186
1187 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1188 {
1189         string initpath = lyxrc.document_path;
1190         string filename(name);
1191
1192         if (view()->available()) {
1193                 string const trypath = owner->buffer()->filePath();
1194                 // If directory is writeable, use this as default.
1195                 if (IsDirWriteable(trypath))
1196                         initpath = trypath;
1197         }
1198
1199         static int newfile_number;
1200
1201         if (filename.empty()) {
1202                 filename = AddName(lyxrc.document_path,
1203                             "newfile" + tostr(++newfile_number) + ".lyx");
1204                 FileInfo fi(filename);
1205                 while (bufferlist.exists(filename) || fi.readable()) {
1206                         ++newfile_number;
1207                         filename = AddName(lyxrc.document_path,
1208                                     "newfile" + tostr(newfile_number) +
1209                                     ".lyx");
1210                         fi.newFile(filename);
1211                 }
1212         }
1213
1214         // The template stuff
1215         string templname;
1216         if (fromTemplate) {
1217                 FileDialog fileDlg(_("Select template file"),
1218                         LFUN_SELECT_FILE_SYNC,
1219                         make_pair(string(_("Documents|#o#O")),
1220                                   string(lyxrc.document_path)),
1221                         make_pair(string(_("Templates|#T#t")),
1222                                   string(lyxrc.template_path)));
1223
1224                 FileDialog::Result result =
1225                         fileDlg.open(lyxrc.template_path,
1226                                      FileFilterList(_("LyX Documents (*.lyx)")),
1227                                      string());
1228
1229                 if (result.first == FileDialog::Later)
1230                         return;
1231                 if (result.second.empty())
1232                         return;
1233                 templname = result.second;
1234         }
1235
1236         view()->newFile(filename, templname, !name.empty());
1237 }
1238
1239
1240 void LyXFunc::open(string const & fname)
1241 {
1242         string initpath = lyxrc.document_path;
1243
1244         if (view()->available()) {
1245                 string const trypath = owner->buffer()->filePath();
1246                 // If directory is writeable, use this as default.
1247                 if (IsDirWriteable(trypath))
1248                         initpath = trypath;
1249         }
1250
1251         string filename;
1252
1253         if (fname.empty()) {
1254                 FileDialog fileDlg(_("Select document to open"),
1255                         LFUN_FILE_OPEN,
1256                         make_pair(string(_("Documents|#o#O")),
1257                                   string(lyxrc.document_path)),
1258                         make_pair(string(_("Examples|#E#e")),
1259                                   string(AddPath(system_lyxdir(), "examples"))));
1260
1261                 FileDialog::Result result =
1262                         fileDlg.open(initpath,
1263                                      FileFilterList(_("LyX Documents (*.lyx)")),
1264                                      string());
1265
1266                 if (result.first == FileDialog::Later)
1267                         return;
1268
1269                 filename = result.second;
1270
1271                 // check selected filename
1272                 if (filename.empty()) {
1273                         owner->message(_("Canceled."));
1274                         return;
1275                 }
1276         } else
1277                 filename = fname;
1278
1279         // get absolute path of file and add ".lyx" to the filename if
1280         // necessary
1281         string const fullpath = FileSearch(string(), filename, "lyx");
1282         if (!fullpath.empty()) {
1283                 filename = fullpath;
1284         }
1285
1286         string const disp_fn(MakeDisplayPath(filename));
1287
1288         // if the file doesn't exist, let the user create one
1289         FileInfo const f(filename, true);
1290         if (!f.exist()) {
1291                 // the user specifically chose this name. Believe them.
1292                 view()->newFile(filename, "", true);
1293                 return;
1294         }
1295
1296         owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1297
1298         string str2;
1299         if (view()->loadLyXFile(filename)) {
1300                 str2 = bformat(_("Document %1$s opened."), disp_fn);
1301         } else {
1302                 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1303         }
1304         owner->message(str2);
1305 }
1306
1307
1308 void LyXFunc::doImport(string const & argument)
1309 {
1310         string format;
1311         string filename = split(argument, format, ' ');
1312
1313         lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1314                             << " file: " << filename << endl;
1315
1316         // need user interaction
1317         if (filename.empty()) {
1318                 string initpath = lyxrc.document_path;
1319
1320                 if (view()->available()) {
1321                         string const trypath = owner->buffer()->filePath();
1322                         // If directory is writeable, use this as default.
1323                         if (IsDirWriteable(trypath))
1324                                 initpath = trypath;
1325                 }
1326
1327                 string const text = bformat(_("Select %1$s file to import"),
1328                         formats.prettyName(format));
1329
1330                 FileDialog fileDlg(text,
1331                         LFUN_IMPORT,
1332                         make_pair(string(_("Documents|#o#O")),
1333                                   string(lyxrc.document_path)),
1334                         make_pair(string(_("Examples|#E#e")),
1335                                   string(AddPath(system_lyxdir(), "examples"))));
1336
1337                 string const filter = formats.prettyName(format)
1338                         + " (*." + formats.extension(format) + ')';
1339
1340                 FileDialog::Result result =
1341                         fileDlg.open(initpath,
1342                                      FileFilterList(filter),
1343                                      string());
1344
1345                 if (result.first == FileDialog::Later)
1346                         return;
1347
1348                 filename = result.second;
1349
1350                 // check selected filename
1351                 if (filename.empty())
1352                         owner->message(_("Canceled."));
1353         }
1354
1355         if (filename.empty())
1356                 return;
1357
1358         // get absolute path of file
1359         filename = MakeAbsPath(filename);
1360
1361         string const lyxfile = ChangeExtension(filename, ".lyx");
1362
1363         // Check if the document already is open
1364         if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1365                 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1366                         owner->message(_("Canceled."));
1367                         return;
1368                 }
1369         }
1370
1371         // if the file exists already, and we didn't do
1372         // -i lyx thefile.lyx, warn
1373         if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1374                 string const file = MakeDisplayPath(lyxfile, 30);
1375
1376                 string text = bformat(_("The document %1$s already exists.\n\n"
1377                         "Do you want to over-write that document?"), file);
1378                 int const ret = Alert::prompt(_("Over-write document?"),
1379                         text, 0, 1, _("&Over-write"), _("&Cancel"));
1380
1381                 if (ret == 1) {
1382                         owner->message(_("Canceled."));
1383                         return;
1384                 }
1385         }
1386
1387         Importer::Import(owner, filename, format);
1388 }
1389
1390
1391 void LyXFunc::closeBuffer()
1392 {
1393         if (bufferlist.close(owner->buffer(), true) && !quitting) {
1394                 if (bufferlist.empty()) {
1395                         // need this otherwise SEGV may occur while
1396                         // trying to set variables that don't exist
1397                         // since there's no current buffer
1398                         owner->getDialogs().hideBufferDependent();
1399                 } else {
1400                         view()->setBuffer(bufferlist.first());
1401                 }
1402         }
1403 }
1404
1405
1406 // Each "owner" should have it's own message method. lyxview and
1407 // the minibuffer would use the minibuffer, but lyxserver would
1408 // send an ERROR signal to its client.  Alejandro 970603
1409 // This function is bit problematic when it comes to NLS, to make the
1410 // lyx servers client be language indepenent we must not translate
1411 // strings sent to this func.
1412 void LyXFunc::setErrorMessage(string const & m) const
1413 {
1414         dispatch_buffer = m;
1415         errorstat = true;
1416 }
1417
1418
1419 void LyXFunc::setMessage(string const & m) const
1420 {
1421         dispatch_buffer = m;
1422 }
1423
1424
1425 void LyXFunc::setStatusMessage(string const & m) const
1426 {
1427         status_buffer = m;
1428 }
1429
1430
1431 string const LyXFunc::viewStatusMessage()
1432 {
1433         // When meta-fake key is pressed, show the key sequence so far + "M-".
1434         if (wasMetaKey())
1435                 return keyseq.print() + "M-";
1436
1437         // Else, when a non-complete key sequence is pressed,
1438         // show the available options.
1439         if (keyseq.length() > 0 && !keyseq.deleted())
1440                 return keyseq.printOptions();
1441
1442         if (!view()->available())
1443                 return _("Welcome to LyX!");
1444
1445         return view()->cursor().currentState();
1446 }
1447
1448
1449 BufferView * LyXFunc::view() const
1450 {
1451         BOOST_ASSERT(owner);
1452         return owner->view().get();
1453 }
1454
1455
1456 bool LyXFunc::wasMetaKey() const
1457 {
1458         return (meta_fake_bit != key_modifier::none);
1459 }