]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.C
Remove test code in the LFUN_QUIT handler as it leads to a crash when no
[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) && !buf) {
291                 // no, exit directly
292                 setStatusMessage(N_("Command not allowed with"
293                                     "out any document open"));
294                 flag.enabled(false);
295                 return flag;
296         }
297
298         // I would really like to avoid having this switch and rather try to
299         // encode this in the function itself.
300         // -- And I'd rather let an inset decide which LFUNs it is willing
301         // to handle (Andre')
302         bool enable = true;
303         switch (cmd.action) {
304         case LFUN_TOOLTIPS_TOGGLE:
305                 flag.setOnOff(owner->getDialogs().tooltipsEnabled());
306                 break;
307
308         case LFUN_READ_ONLY_TOGGLE:
309                 flag.setOnOff(buf->isReadonly());
310                 break;
311
312         case LFUN_SWITCHBUFFER:
313                 // toggle on the current buffer, but do not toggle off
314                 // the other ones (is that a good idea?)
315                 if (cmd.argument == buf->fileName())
316                         flag.setOnOff(true);
317                 break;
318
319         case LFUN_TRACK_CHANGES:
320                 flag.setOnOff(buf->params().tracking_changes);
321                 break;
322
323         case LFUN_EXPORT:
324                 enable = cmd.argument == "custom"
325                         || Exporter::IsExportable(*buf, cmd.argument);
326                 break;
327         case LFUN_UNDO:
328                 enable = !buf->undostack().empty();
329                 break;
330         case LFUN_REDO:
331                 enable = !buf->redostack().empty();
332                 break;
333         case LFUN_CUT:
334         case LFUN_COPY:
335                 enable = cur.selection();
336                 break;
337
338         case LFUN_RUNCHKTEX:
339                 enable = buf->isLatex() && lyxrc.chktex_command != "none";
340                 break;
341
342         case LFUN_BUILDPROG:
343                 enable = Exporter::IsExportable(*buf, "program");
344                 break;
345
346         case LFUN_LAYOUT_TABULAR:
347                 enable = cur.innerInsetOfType(InsetBase::TABULAR_CODE);
348                 break;
349
350         case LFUN_LAYOUT:
351         case LFUN_LAYOUT_PARAGRAPH:
352                 enable = !cur.inset().forceDefaultParagraphs(&cur.inset());
353                 break;
354
355         case LFUN_VC_REGISTER:
356                 enable = !buf->lyxvc().inUse();
357                 break;
358         case LFUN_VC_CHECKIN:
359                 enable = buf->lyxvc().inUse() && !buf->isReadonly();
360                 break;
361         case LFUN_VC_CHECKOUT:
362                 enable = buf->lyxvc().inUse() && buf->isReadonly();
363                 break;
364         case LFUN_VC_REVERT:
365         case LFUN_VC_UNDO:
366                 enable = buf->lyxvc().inUse();
367                 break;
368         case LFUN_MENURELOAD:
369                 enable = !buf->isUnnamed() && !buf->isClean();
370                 break;
371         case LFUN_BOOKMARK_GOTO:
372                 enable = view()->isSavedPosition(strToUnsignedInt(cmd.argument));
373                 break;
374
375         case LFUN_MERGE_CHANGES:
376         case LFUN_ACCEPT_CHANGE:
377         case LFUN_REJECT_CHANGE:
378         case LFUN_ACCEPT_ALL_CHANGES:
379         case LFUN_REJECT_ALL_CHANGES:
380                 enable = buf && buf->params().tracking_changes;
381                 break;
382
383         case LFUN_INSET_SETTINGS: {
384                 enable = false;
385                 if (!cur.size())
386                         break;
387                 UpdatableInset * inset = cur.inset().asUpdatableInset();
388                 lyxerr << "inset: " << inset << endl;
389                 if (!inset)
390                         break;
391
392                 InsetOld::Code code = inset->lyxCode();
393                 switch (code) {
394                         case InsetOld::TABULAR_CODE:
395                                 enable = cmd.argument == "tabular";
396                                 break;
397                         case InsetOld::ERT_CODE:
398                                 enable = cmd.argument == "ert";
399                                 break;
400                         case InsetOld::FLOAT_CODE:
401                                 enable = cmd.argument == "float";
402                                 break;
403                         case InsetOld::WRAP_CODE:
404                                 enable = cmd.argument == "wrap";
405                                 break;
406                         case InsetOld::NOTE_CODE:
407                                 enable = cmd.argument == "note";
408                                 break;
409                         case InsetOld::BRANCH_CODE:
410                                 enable = cmd.argument == "branch";
411                                 break;
412                         case InsetOld::BOX_CODE:
413                                 enable = cmd.argument == "box";
414                                 break;
415                         default:
416                                 break;
417                 }
418                 break;
419         }
420
421         case LFUN_DIALOG_SHOW: {
422                 string const name = cmd.getArg(0);
423                 if (!buf)
424                         enable = name == "aboutlyx"
425                                 || name == "file"
426                                 || name == "forks"
427                                 || name == "preferences"
428                                 || name == "texinfo";
429                 else if (name == "print")
430                         enable = Exporter::IsExportable(*buf, "dvi")
431                                 && lyxrc.print_command != "none";
432                 else if (name == "character")
433                         enable = cur.inset().lyxCode() != InsetOld::ERT_CODE;
434                 else if (name == "vclog")
435                         enable = buf->lyxvc().inUse();
436                 else if (name == "latexlog")
437                         enable = IsFileReadable(buf->getLogName().second);
438                 break;
439         }
440
441         case LFUN_MENUNEW:
442         case LFUN_MENUNEWTMPLT:
443         case LFUN_WORDFINDFORWARD:
444         case LFUN_WORDFINDBACKWARD:
445         case LFUN_PREFIX:
446         case LFUN_EXEC_COMMAND:
447         case LFUN_CANCEL:
448         case LFUN_META_FAKE:
449         case LFUN_CLOSEBUFFER:
450         case LFUN_MENUWRITE:
451         case LFUN_WRITEAS:
452         case LFUN_UPDATE:
453         case LFUN_PREVIEW:
454         case LFUN_IMPORT:
455         case LFUN_QUIT:
456         case LFUN_TOCVIEW:
457         case LFUN_AUTOSAVE:
458         case LFUN_RECONFIGURE:
459         case LFUN_HELP_OPEN:
460         case LFUN_FILE_NEW:
461         case LFUN_FILE_OPEN:
462         case LFUN_DROP_LAYOUTS_CHOICE:
463         case LFUN_MENU_OPEN_BY_NAME:
464         case LFUN_GETNAME:
465         case LFUN_NOTIFY:
466         case LFUN_GOTOFILEROW:
467         case LFUN_GOTO_PARAGRAPH:
468         case LFUN_DIALOG_SHOW_NEW_INSET:
469         case LFUN_DIALOG_SHOW_NEXT_INSET:
470         case LFUN_DIALOG_UPDATE:
471         case LFUN_DIALOG_HIDE:
472         case LFUN_DIALOG_DISCONNECT_INSET:
473         case LFUN_CHILDOPEN:
474         case LFUN_TOGGLECURSORFOLLOW:
475         case LFUN_KMAP_OFF:
476         case LFUN_KMAP_PRIM:
477         case LFUN_KMAP_SEC:
478         case LFUN_KMAP_TOGGLE:
479         case LFUN_REPEAT:
480         case LFUN_SEQUENCE:
481         case LFUN_SAVEPREFERENCES:
482         case LFUN_SCREEN_FONT_UPDATE:
483         case LFUN_SET_COLOR:
484         case LFUN_MESSAGE:
485         case LFUN_EXTERNAL_EDIT:
486         case LFUN_FILE_INSERT:
487         case LFUN_FILE_INSERT_ASCII:
488         case LFUN_FILE_INSERT_ASCII_PARA:
489                 // these are handled in our dispatch()
490                 break;
491
492         default:
493                 cur.getStatus(cmd, flag);
494         }
495
496         if (!enable)
497                 flag.enabled(false);
498
499         // Can we use a readonly buffer?
500         if (buf && buf->isReadonly() 
501             && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
502             && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
503                 setStatusMessage(N_("Document is read-only"));
504                 flag.enabled(false);
505         }
506
507         return flag;
508 }
509
510
511 namespace {
512
513 bool ensureBufferClean(BufferView * bv)
514 {
515         Buffer & buf = *bv->buffer();
516         if (buf.isClean())
517                 return true;
518
519         string const file = MakeDisplayPath(buf.fileName(), 30);
520         string text = bformat(_("The document %1$s has unsaved "
521                                 "changes.\n\nDo you want to save "
522                                 "the document?"), file);
523         int const ret = Alert::prompt(_("Save changed document?"),
524                                       text, 0, 1, _("&Save"),
525                                       _("&Cancel"));
526
527         if (ret == 0)
528                 bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
529
530         return buf.isClean();
531 }
532
533 } //namespace anon
534
535
536 void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
537 {
538         string const argument = cmd.argument;
539         kb_action const action = cmd.action;
540
541         lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
542         //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
543
544         // we have not done anything wrong yet.
545         errorstat = false;
546         dispatch_buffer.erase();
547         selection_possible = false;
548
549         // We cannot use this function here
550         if (!getStatus(cmd).enabled()) {
551                 lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
552                        << lyxaction.getActionName(action)
553                        << " [" << action << "] is disabled at this location"
554                        << endl;
555                 setErrorMessage(getStatusMessage());
556
557         } else {
558
559                 if (view()->available())
560                         view()->hideCursor();
561
562                 switch (action) {
563
564                 case LFUN_WORDFINDFORWARD:
565                 case LFUN_WORDFINDBACKWARD: {
566                         static string last_search;
567                         string searched_string;
568
569                         if (!argument.empty()) {
570                                 last_search = argument;
571                                 searched_string = argument;
572                         } else {
573                                 searched_string = last_search;
574                         }
575
576                         if (searched_string.empty())
577                                 break;
578
579                         bool const fw = action == LFUN_WORDFINDFORWARD;
580                         string const data =
581                                 lyx::find::find2string(searched_string, true, false, fw);
582                         lyx::find::find(view(), FuncRequest(LFUN_WORD_FIND, data));
583                         break;
584                 }
585
586                 case LFUN_PREFIX:
587                         owner->message(keyseq.printOptions());
588                         break;
589
590                 case LFUN_EXEC_COMMAND:
591                         owner->focus_command_buffer();
592                         break;
593
594                 case LFUN_CANCEL:
595                         keyseq.reset();
596                         meta_fake_bit = key_modifier::none;
597                         if (view()->available())
598                                 // cancel any selection
599                                 dispatch(FuncRequest(LFUN_MARK_OFF));
600                         setMessage(N_("Cancel"));
601                         break;
602
603                 case LFUN_META_FAKE:
604                         meta_fake_bit = key_modifier::alt;
605                         setMessage(keyseq.print());
606                         break;
607
608                 case LFUN_READ_ONLY_TOGGLE:
609                         if (owner->buffer()->lyxvc().inUse())
610                                 owner->buffer()->lyxvc().toggleReadOnly();
611                         else
612                                 owner->buffer()->setReadonly(
613                                         !owner->buffer()->isReadonly());
614                         break;
615
616                 // --- Menus -----------------------------------------------
617                 case LFUN_MENUNEW:
618                         menuNew(argument, false);
619                         break;
620
621                 case LFUN_MENUNEWTMPLT:
622                         menuNew(argument, true);
623                         break;
624
625                 case LFUN_CLOSEBUFFER:
626                         closeBuffer();
627                         break;
628
629                 case LFUN_MENUWRITE:
630                         if (!owner->buffer()->isUnnamed()) {
631                                 string const str = bformat(_("Saving document %1$s..."),
632                                          MakeDisplayPath(owner->buffer()->fileName()));
633                                 owner->message(str);
634                                 MenuWrite(owner->buffer());
635                                 owner->message(str + _(" done."));
636                         } else
637                                 WriteAs(owner->buffer());
638                         break;
639
640                 case LFUN_WRITEAS:
641                         WriteAs(owner->buffer(), argument);
642                         break;
643
644                 case LFUN_MENURELOAD: {
645                         string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
646                         string text = bformat(_("Any changes will be lost. Are you sure "
647                                 "you want to revert to the saved version of the document %1$s?"), file);
648                         int const ret = Alert::prompt(_("Revert to saved document?"),
649                                 text, 0, 1, _("&Revert"), _("&Cancel"));
650
651                         if (ret == 0)
652                                 view()->reload();
653                         break;
654                 }
655
656                 case LFUN_UPDATE:
657                         Exporter::Export(owner->buffer(), argument, true);
658                         view()->showErrorList(BufferFormat(*owner->buffer()));
659                         break;
660
661                 case LFUN_PREVIEW:
662                         Exporter::Preview(owner->buffer(), argument);
663                         view()->showErrorList(BufferFormat(*owner->buffer()));
664                         break;
665
666                 case LFUN_BUILDPROG:
667                         Exporter::Export(owner->buffer(), "program", true);
668                         view()->showErrorList(_("Build"));
669                         break;
670
671                 case LFUN_RUNCHKTEX:
672                         owner->buffer()->runChktex();
673                         view()->showErrorList(_("ChkTeX"));
674                         break;
675
676                 case LFUN_EXPORT:
677                         if (argument == "custom")
678                                 owner->getDialogs().showSendto();
679                         else {
680                                 Exporter::Export(owner->buffer(), argument, false);
681                                 view()->showErrorList(BufferFormat(*owner->buffer()));
682                         }
683                         break;
684
685                 case LFUN_IMPORT:
686                         doImport(argument);
687                         break;
688
689                 case LFUN_QUIT:
690                         QuitLyX();
691                         break;
692
693                 case LFUN_TOCVIEW: {
694                         InsetCommandParams p("tableofcontents");
695                         string const data = InsetCommandMailer::params2string("toc", p);
696                         owner->getDialogs().show("toc", data, 0);
697                         break;
698                 }
699
700                 case LFUN_AUTOSAVE:
701                         AutoSave(view());
702                         break;
703
704                 case LFUN_RECONFIGURE:
705                         Reconfigure(view());
706                         break;
707
708                 case LFUN_HELP_OPEN: {
709                         string const arg = argument;
710                         if (arg.empty()) {
711                                 setErrorMessage(N_("Missing argument"));
712                                 break;
713                         }
714                         string const fname = i18nLibFileSearch("doc", arg, "lyx");
715                         if (fname.empty()) {
716                                 lyxerr << "LyX: unable to find documentation file `"
717                                                          << arg << "'. Bad installation?" << endl;
718                                 break;
719                         }
720                         owner->message(bformat(_("Opening help file %1$s..."),
721                                 MakeDisplayPath(fname)));
722                         view()->loadLyXFile(fname, false);
723                         break;
724                 }
725
726                 // --- version control -------------------------------
727                 case LFUN_VC_REGISTER:
728                         if (!ensureBufferClean(view()))
729                                 break;
730                         if (!owner->buffer()->lyxvc().inUse()) {
731                                 owner->buffer()->lyxvc().registrer();
732                                 view()->reload();
733                         }
734                         break;
735
736                 case LFUN_VC_CHECKIN:
737                         if (!ensureBufferClean(view()))
738                                 break;
739                         if (owner->buffer()->lyxvc().inUse()
740                                         && !owner->buffer()->isReadonly()) {
741                                 owner->buffer()->lyxvc().checkIn();
742                                 view()->reload();
743                         }
744                         break;
745
746                 case LFUN_VC_CHECKOUT:
747                         if (!ensureBufferClean(view()))
748                                 break;
749                         if (owner->buffer()->lyxvc().inUse()
750                                         && owner->buffer()->isReadonly()) {
751                                 owner->buffer()->lyxvc().checkOut();
752                                 view()->reload();
753                         }
754                         break;
755
756                 case LFUN_VC_REVERT:
757                         owner->buffer()->lyxvc().revert();
758                         view()->reload();
759                         break;
760
761                 case LFUN_VC_UNDO:
762                         owner->buffer()->lyxvc().undoLast();
763                         view()->reload();
764                         break;
765
766                 // --- buffers ----------------------------------------
767                 case LFUN_SWITCHBUFFER:
768                         view()->setBuffer(bufferlist.getBuffer(argument));
769                         break;
770
771                 case LFUN_FILE_NEW:
772                         NewFile(view(), argument);
773                         break;
774
775                 case LFUN_FILE_OPEN:
776                         open(argument);
777                         break;
778
779                 case LFUN_DROP_LAYOUTS_CHOICE:
780                         owner->getToolbar().openLayoutList();
781                         break;
782
783                 case LFUN_MENU_OPEN_BY_NAME:
784                         owner->getMenubar().openByName(argument);
785                         break;
786
787                 // --- lyxserver commands ----------------------------
788                 case LFUN_GETNAME:
789                         setMessage(owner->buffer()->fileName());
790                         lyxerr[Debug::INFO] << "FNAME["
791                                                          << owner->buffer()->fileName()
792                                                          << "] " << endl;
793                         break;
794
795                 case LFUN_NOTIFY:
796                         dispatch_buffer = keyseq.print();
797                         lyxserver->notifyClient(dispatch_buffer);
798                         break;
799
800                 case LFUN_GOTOFILEROW: {
801                         string file_name;
802                         int row;
803                         istringstream is(argument);
804                         is >> file_name >> row;
805                         if (prefixIs(file_name, getTmpDir())) {
806                                 // Needed by inverse dvi search. If it is a file
807                                 // in tmpdir, call the apropriated function
808                                 view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
809                         } else {
810                                 // Must replace extension of the file to be .lyx
811                                 // and get full path
812                                 string const s = ChangeExtension(file_name, ".lyx");
813                                 // Either change buffer or load the file
814                                 if (bufferlist.exists(s)) {
815                                         view()->setBuffer(bufferlist.getBuffer(s));
816                                 } else {
817                                         view()->loadLyXFile(s);
818                                 }
819                         }
820
821                         view()->setCursorFromRow(row);
822
823                         view()->center();
824                         // see BufferView_pimpl::center()
825                         view()->updateScrollbar();
826                         break;
827                 }
828
829                 case LFUN_GOTO_PARAGRAPH: {
830                         istringstream is(argument);
831                         int id;
832                         is >> id;
833                         ParIterator par = owner->buffer()->getParFromID(id);
834                         if (par == owner->buffer()->par_iterator_end()) {
835                                 lyxerr[Debug::INFO] << "No matching paragraph found! ["
836                                                                 << id << ']' << endl;
837                                 break;
838                         } else {
839                                 lyxerr[Debug::INFO] << "Paragraph " << par->id()
840                                                                 << " found." << endl;
841                         }
842
843                         // Set the cursor
844                         view()->setCursor(par, 0);
845
846                         view()->switchKeyMap();
847                         owner->view_state_changed();
848
849                         view()->center();
850                         // see BufferView_pimpl::center()
851                         view()->updateScrollbar();
852                         break;
853                 }
854
855                 case LFUN_DIALOG_SHOW: {
856                         string const name = cmd.getArg(0);
857                         string data = trim(cmd.argument.substr(name.size()));
858
859                         if (name == "character") {
860                                 data = freefont2string();
861                                 if (!data.empty())
862                                         owner->getDialogs().show("character", data);
863                         }
864                         else if (name == "document")
865                                 owner->getDialogs().showDocument();
866                         else if (name == "preamble")
867                                 owner->getDialogs().showPreamble();
868                         else if (name == "preferences")
869                                 owner->getDialogs().showPreferences();
870                         else if (name == "print")
871                                 owner->getDialogs().showPrint();
872                         else if (name == "spellchecker")
873                                 owner->getDialogs().showSpellchecker();
874
875                         else if (name == "latexlog") {
876                                 pair<Buffer::LogType, string> const logfile =
877                                         owner->buffer()->getLogName();
878                                 switch (logfile.first) {
879                                 case Buffer::latexlog:
880                                         data = "latex ";
881                                         break;
882                                 case Buffer::buildlog:
883                                         data = "literate ";
884                                         break;
885                                 }
886                                 data += logfile.second;
887                                 owner->getDialogs().show("log", data);
888                         }
889                         else if (name == "vclog") {
890                                 string const data = "vc " +
891                                         owner->buffer()->lyxvc().getLogFile();
892                                 owner->getDialogs().show("log", data);
893                         }
894                         else
895                                 owner->getDialogs().show(name, data);
896                         break;
897                 }
898
899                 case LFUN_DIALOG_SHOW_NEW_INSET: {
900                         string const name = cmd.getArg(0);
901                         string data = trim(cmd.argument.substr(name.size()));
902                         if (name == "bibitem" ||
903                             name == "bibtex" ||
904                             name == "include" ||
905                             name == "index" ||
906                             name == "label" ||
907                             name == "ref" ||
908                             name == "toc" ||
909                             name == "url") {
910                                 InsetCommandParams p(name);
911                                 data = InsetCommandMailer::params2string(name, p);
912                         } else if (name == "box") {
913                                 // \c data == "Boxed" || "Frameless" etc
914                                 InsetBoxParams p(data);
915                                 data = InsetBoxMailer::params2string(p);
916                         } else if (name == "branch") {
917                                 InsetBranchParams p;
918                                 data = InsetBranchMailer::params2string(p);
919                         } else if (name == "citation") {
920                                 InsetCommandParams p("cite");
921                                 data = InsetCommandMailer::params2string(name, p);
922                         } else if (name == "ert") {
923                                 data = InsetERTMailer::params2string(InsetCollapsable::Open);
924                         } else if (name == "external") {
925                                 InsetExternalParams p;
926                                 Buffer const & buffer = *owner->buffer();
927                                 data = InsetExternalMailer::params2string(p, buffer);
928                         } else if (name == "float") {
929                                 InsetFloatParams p;
930                                 data = InsetFloatMailer::params2string(p);
931                         } else if (name == "graphics") {
932                                 InsetGraphicsParams p;
933                                 Buffer const & buffer = *owner->buffer();
934                                 data = InsetGraphicsMailer::params2string(p, buffer);
935                         } else if (name == "note") {
936                                 InsetNoteParams p;
937                                 data = InsetNoteMailer::params2string(p);
938                         } else if (name == "vspace") {
939                                 VSpace space;
940                                 data = InsetVSpaceMailer::params2string(space);
941                         } else if (name == "wrap") {
942                                 InsetWrapParams p;
943                                 data = InsetWrapMailer::params2string(p);
944                         }
945                         owner->getDialogs().show(name, data, 0);
946                         break;
947                 }
948
949                 case LFUN_DIALOG_SHOW_NEXT_INSET:
950                         break;
951
952                 case LFUN_DIALOG_UPDATE: {
953                         string const & name = argument;
954                         // Can only update a dialog connected to an existing inset
955                         InsetBase * inset = owner->getDialogs().getOpenInset(name);
956                         if (inset) {
957                                 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument);
958                                 inset->dispatch(view()->cursor(), fr);
959                         } else if (name == "paragraph") {
960                                 dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
961                         }
962                         break;
963                 }
964
965                 case LFUN_DIALOG_HIDE:
966                         Dialogs::hide(argument, 0);
967                         break;
968
969                 case LFUN_DIALOG_DISCONNECT_INSET:
970                         owner->getDialogs().disconnect(argument);
971                         break;
972
973                 case LFUN_CHILDOPEN: {
974                         string const filename =
975                                 MakeAbsPath(argument, owner->buffer()->filePath());
976                         setMessage(N_("Opening child document ") +
977                                          MakeDisplayPath(filename) + "...");
978                         view()->savePosition(0);
979                         string const parentfilename = owner->buffer()->fileName();
980                         if (bufferlist.exists(filename))
981                                 view()->setBuffer(bufferlist.getBuffer(filename));
982                         else
983                                 view()->loadLyXFile(filename);
984                         // Set the parent name of the child document.
985                         // This makes insertion of citations and references in the child work,
986                         // when the target is in the parent or another child document.
987                         owner->buffer()->setParentName(parentfilename);
988                         break;
989                 }
990
991                 case LFUN_TOGGLECURSORFOLLOW:
992                         lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
993                         break;
994
995                 case LFUN_KMAP_OFF:
996                         owner->getIntl().KeyMapOn(false);
997                         break;
998
999                 case LFUN_KMAP_PRIM:
1000                         owner->getIntl().KeyMapPrim();
1001                         break;
1002
1003                 case LFUN_KMAP_SEC:
1004                         owner->getIntl().KeyMapSec();
1005                         break;
1006
1007                 case LFUN_KMAP_TOGGLE:
1008                         owner->getIntl().ToggleKeyMap();
1009                         break;
1010
1011                 case LFUN_REPEAT: {
1012                         // repeat command
1013                         string countstr;
1014                         string rest = split(argument, countstr, ' ');
1015                         istringstream is(countstr);
1016                         int count = 0;
1017                         is >> count;
1018                         lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
1019                         for (int i = 0; i < count; ++i)
1020                                 dispatch(lyxaction.lookupFunc(rest));
1021                         break;
1022                 }
1023
1024                 case LFUN_SEQUENCE:
1025                         // argument contains ';'-terminated commands
1026                         while (!argument.empty()) {
1027                                 string first;
1028                                 string rest = split(argument, first, ';');
1029                                 dispatch(lyxaction.lookupFunc(rest));
1030                         }
1031                         break;
1032
1033                 case LFUN_SAVEPREFERENCES: {
1034                         Path p(user_lyxdir());
1035                         lyxrc.write("preferences");
1036                         break;
1037                 }
1038
1039                 case LFUN_SCREEN_FONT_UPDATE:
1040                         // handle the screen font changes.
1041                         lyxrc.set_font_norm_type();
1042                         lyx_gui::update_fonts();
1043                         // All visible buffers will need resize
1044                         view()->resize();
1045                         break;
1046
1047                 case LFUN_SET_COLOR: {
1048                         string lyx_name;
1049                         string const x11_name = split(argument, lyx_name, ' ');
1050                         if (lyx_name.empty() || x11_name.empty()) {
1051                                 setErrorMessage(N_("Syntax: set-color <lyx_name>"
1052                                                         " <x11_name>"));
1053                                 break;
1054                         }
1055
1056                         bool const graphicsbg_changed =
1057                                 (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
1058                                  x11_name != lcolor.getX11Name(LColor::graphicsbg));
1059
1060                         if (!lcolor.setColor(lyx_name, x11_name)) {
1061                                 setErrorMessage(
1062                                         bformat(_("Set-color \"%1$s\" failed "
1063                                                                 "- color is undefined or "
1064                                                                 "may not be redefined"), lyx_name));
1065                                 break;
1066                         }
1067
1068                         lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
1069
1070                         if (graphicsbg_changed) {
1071 #ifdef WITH_WARNINGS
1072 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1073 #endif
1074 #if 0
1075                                 lyx::graphics::GCache::get().changeDisplay(true);
1076 #endif
1077                         }
1078                         break;
1079                 }
1080
1081                 case LFUN_MESSAGE:
1082                         owner->message(argument);
1083                         break;
1084
1085                 case LFUN_TOOLTIPS_TOGGLE:
1086                         owner->getDialogs().toggleTooltips();
1087                         break;
1088
1089                 case LFUN_EXTERNAL_EDIT: {
1090                         FuncRequest fr(action, argument);
1091                         InsetExternal().dispatch(view()->cursor(), fr);
1092                         break;
1093                 }
1094
1095                 case LFUN_BREAKLINE: {
1096 #warning swallow 'Return' if the minibuffer is focused. But how?
1097                 }
1098
1099                 default: {
1100                         DispatchResult res = view()->cursor().dispatch(cmd);
1101                         if (!res.dispatched());
1102                                 view()->dispatch(cmd);
1103                         break;
1104                 }
1105                 }
1106
1107                 if (view()->available()) {
1108                         view()->fitCursor();
1109                         view()->update();
1110                         view()->cursor().updatePos();
1111                         // if we executed a mutating lfun, mark the buffer as dirty
1112                         if (getStatus(cmd).enabled()
1113                                         && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
1114                                         && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
1115                                 view()->buffer()->markDirty();
1116                 }
1117
1118                 if (view()->cursor().inTexted()) {
1119                         view()->owner()->updateLayoutChoice();
1120                         sendDispatchMessage(getMessage(), cmd, verbose);
1121                 }
1122         }
1123 }
1124
1125
1126 void LyXFunc::sendDispatchMessage(string const & msg,
1127                                   FuncRequest const & cmd, bool verbose)
1128 {
1129         owner->updateMenubar();
1130         owner->updateToolbar();
1131
1132         if (cmd.action == LFUN_SELFINSERT || !verbose) {
1133                 lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
1134                 if (!msg.empty())
1135                         owner->message(msg);
1136                 return;
1137         }
1138
1139         string dispatch_msg = msg;
1140         if (!dispatch_msg.empty())
1141                 dispatch_msg += ' ';
1142
1143         string comname = lyxaction.getActionName(cmd.action);
1144
1145         bool argsadded = false;
1146
1147         if (!cmd.argument.empty()) {
1148                 if (cmd.action != LFUN_UNKNOWN_ACTION) {
1149                         comname += ' ' + cmd.argument;
1150                         argsadded = true;
1151                 }
1152         }
1153
1154         string const shortcuts = toplevel_keymap->findbinding(cmd);
1155
1156         if (!shortcuts.empty()) {
1157                 comname += ": " + shortcuts;
1158         } else if (!argsadded && !cmd.argument.empty()) {
1159                 comname += ' ' + cmd.argument;
1160         }
1161
1162         if (!comname.empty()) {
1163                 comname = rtrim(comname);
1164                 dispatch_msg += '(' + comname + ')';
1165         }
1166
1167         lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
1168         if (!dispatch_msg.empty())
1169                 owner->message(dispatch_msg);
1170 }
1171
1172
1173 void LyXFunc::setupLocalKeymap()
1174 {
1175         keyseq.stdmap = toplevel_keymap.get();
1176         keyseq.curmap = toplevel_keymap.get();
1177         cancel_meta_seq.stdmap = toplevel_keymap.get();
1178         cancel_meta_seq.curmap = toplevel_keymap.get();
1179 }
1180
1181
1182 void LyXFunc::menuNew(string const & name, bool fromTemplate)
1183 {
1184         string initpath = lyxrc.document_path;
1185         string filename(name);
1186
1187         if (view()->available()) {
1188                 string const trypath = owner->buffer()->filePath();
1189                 // If directory is writeable, use this as default.
1190                 if (IsDirWriteable(trypath))
1191                         initpath = trypath;
1192         }
1193
1194         static int newfile_number;
1195
1196         if (filename.empty()) {
1197                 filename = AddName(lyxrc.document_path,
1198                             "newfile" + tostr(++newfile_number) + ".lyx");
1199                 FileInfo fi(filename);
1200                 while (bufferlist.exists(filename) || fi.readable()) {
1201                         ++newfile_number;
1202                         filename = AddName(lyxrc.document_path,
1203                                     "newfile" + tostr(newfile_number) +
1204                                     ".lyx");
1205                         fi.newFile(filename);
1206                 }
1207         }
1208
1209         // The template stuff
1210         string templname;
1211         if (fromTemplate) {
1212                 FileDialog fileDlg(_("Select template file"),
1213                         LFUN_SELECT_FILE_SYNC,
1214                         make_pair(string(_("Documents|#o#O")),
1215                                   string(lyxrc.document_path)),
1216                         make_pair(string(_("Templates|#T#t")),
1217                                   string(lyxrc.template_path)));
1218
1219                 FileDialog::Result result =
1220                         fileDlg.open(lyxrc.template_path,
1221                                      FileFilterList(_("LyX Documents (*.lyx)")),
1222                                      string());
1223
1224                 if (result.first == FileDialog::Later)
1225                         return;
1226                 if (result.second.empty())
1227                         return;
1228                 templname = result.second;
1229         }
1230
1231         view()->newFile(filename, templname, !name.empty());
1232 }
1233
1234
1235 void LyXFunc::open(string const & fname)
1236 {
1237         string initpath = lyxrc.document_path;
1238
1239         if (view()->available()) {
1240                 string const trypath = owner->buffer()->filePath();
1241                 // If directory is writeable, use this as default.
1242                 if (IsDirWriteable(trypath))
1243                         initpath = trypath;
1244         }
1245
1246         string filename;
1247
1248         if (fname.empty()) {
1249                 FileDialog fileDlg(_("Select document to open"),
1250                         LFUN_FILE_OPEN,
1251                         make_pair(string(_("Documents|#o#O")),
1252                                   string(lyxrc.document_path)),
1253                         make_pair(string(_("Examples|#E#e")),
1254                                   string(AddPath(system_lyxdir(), "examples"))));
1255
1256                 FileDialog::Result result =
1257                         fileDlg.open(initpath,
1258                                      FileFilterList(_("LyX Documents (*.lyx)")),
1259                                      string());
1260
1261                 if (result.first == FileDialog::Later)
1262                         return;
1263
1264                 filename = result.second;
1265
1266                 // check selected filename
1267                 if (filename.empty()) {
1268                         owner->message(_("Canceled."));
1269                         return;
1270                 }
1271         } else
1272                 filename = fname;
1273
1274         // get absolute path of file and add ".lyx" to the filename if
1275         // necessary
1276         string const fullpath = FileSearch(string(), filename, "lyx");
1277         if (!fullpath.empty()) {
1278                 filename = fullpath;
1279         }
1280
1281         string const disp_fn(MakeDisplayPath(filename));
1282
1283         // if the file doesn't exist, let the user create one
1284         FileInfo const f(filename, true);
1285         if (!f.exist()) {
1286                 // the user specifically chose this name. Believe them.
1287                 view()->newFile(filename, "", true);
1288                 return;
1289         }
1290
1291         owner->message(bformat(_("Opening document %1$s..."), disp_fn));
1292
1293         string str2;
1294         if (view()->loadLyXFile(filename)) {
1295                 str2 = bformat(_("Document %1$s opened."), disp_fn);
1296         } else {
1297                 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1298         }
1299         owner->message(str2);
1300 }
1301
1302
1303 void LyXFunc::doImport(string const & argument)
1304 {
1305         string format;
1306         string filename = split(argument, format, ' ');
1307
1308         lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
1309                             << " file: " << filename << endl;
1310
1311         // need user interaction
1312         if (filename.empty()) {
1313                 string initpath = lyxrc.document_path;
1314
1315                 if (view()->available()) {
1316                         string const trypath = owner->buffer()->filePath();
1317                         // If directory is writeable, use this as default.
1318                         if (IsDirWriteable(trypath))
1319                                 initpath = trypath;
1320                 }
1321
1322                 string const text = bformat(_("Select %1$s file to import"),
1323                         formats.prettyName(format));
1324
1325                 FileDialog fileDlg(text,
1326                         LFUN_IMPORT,
1327                         make_pair(string(_("Documents|#o#O")),
1328                                   string(lyxrc.document_path)),
1329                         make_pair(string(_("Examples|#E#e")),
1330                                   string(AddPath(system_lyxdir(), "examples"))));
1331
1332                 string const filter = formats.prettyName(format)
1333                         + " (*." + formats.extension(format) + ')';
1334
1335                 FileDialog::Result result =
1336                         fileDlg.open(initpath,
1337                                      FileFilterList(filter),
1338                                      string());
1339
1340                 if (result.first == FileDialog::Later)
1341                         return;
1342
1343                 filename = result.second;
1344
1345                 // check selected filename
1346                 if (filename.empty())
1347                         owner->message(_("Canceled."));
1348         }
1349
1350         if (filename.empty())
1351                 return;
1352
1353         // get absolute path of file
1354         filename = MakeAbsPath(filename);
1355
1356         string const lyxfile = ChangeExtension(filename, ".lyx");
1357
1358         // Check if the document already is open
1359         if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
1360                 if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
1361                         owner->message(_("Canceled."));
1362                         return;
1363                 }
1364         }
1365
1366         // if the file exists already, and we didn't do
1367         // -i lyx thefile.lyx, warn
1368         if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
1369                 string const file = MakeDisplayPath(lyxfile, 30);
1370
1371                 string text = bformat(_("The document %1$s already exists.\n\n"
1372                         "Do you want to over-write that document?"), file);
1373                 int const ret = Alert::prompt(_("Over-write document?"),
1374                         text, 0, 1, _("&Over-write"), _("&Cancel"));
1375
1376                 if (ret == 1) {
1377                         owner->message(_("Canceled."));
1378                         return;
1379                 }
1380         }
1381
1382         Importer::Import(owner, filename, format);
1383 }
1384
1385
1386 void LyXFunc::closeBuffer()
1387 {
1388         if (bufferlist.close(owner->buffer(), true) && !quitting) {
1389                 if (bufferlist.empty()) {
1390                         // need this otherwise SEGV may occur while
1391                         // trying to set variables that don't exist
1392                         // since there's no current buffer
1393                         owner->getDialogs().hideBufferDependent();
1394                 } else {
1395                         view()->setBuffer(bufferlist.first());
1396                 }
1397         }
1398 }
1399
1400
1401 // Each "owner" should have it's own message method. lyxview and
1402 // the minibuffer would use the minibuffer, but lyxserver would
1403 // send an ERROR signal to its client.  Alejandro 970603
1404 // This function is bit problematic when it comes to NLS, to make the
1405 // lyx servers client be language indepenent we must not translate
1406 // strings sent to this func.
1407 void LyXFunc::setErrorMessage(string const & m) const
1408 {
1409         dispatch_buffer = m;
1410         errorstat = true;
1411 }
1412
1413
1414 void LyXFunc::setMessage(string const & m) const
1415 {
1416         dispatch_buffer = m;
1417 }
1418
1419
1420 void LyXFunc::setStatusMessage(string const & m) const
1421 {
1422         status_buffer = m;
1423 }
1424
1425
1426 string const LyXFunc::viewStatusMessage()
1427 {
1428         // When meta-fake key is pressed, show the key sequence so far + "M-".
1429         if (wasMetaKey())
1430                 return keyseq.print() + "M-";
1431
1432         // Else, when a non-complete key sequence is pressed,
1433         // show the available options.
1434         if (keyseq.length() > 0 && !keyseq.deleted())
1435                 return keyseq.printOptions();
1436
1437         if (!view()->available())
1438                 return _("Welcome to LyX!");
1439
1440         return view()->cursor().currentState();
1441 }
1442
1443
1444 BufferView * LyXFunc::view() const
1445 {
1446         BOOST_ASSERT(owner);
1447         return owner->view().get();
1448 }
1449
1450
1451 bool LyXFunc::wasMetaKey() const
1452 {
1453         return (meta_fake_bit != key_modifier::none);
1454 }