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