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