#include "kbmap.h"
#include "lyxrow.h"
#include "bufferlist.h"
+#include "buffer.h"
+#include "buffer_funcs.h"
#include "BufferView.h"
#include "lyxserver.h"
#include "intl.h"
#include "ParagraphParameters.h"
#include "insets/insetcommand.h"
+#include "insets/insetexternal.h"
#include "insets/insettabular.h"
#include "mathed/formulamacro.h"
#include <utility>
#include <algorithm>
+using namespace lyx::support;
+
using std::pair;
using std::make_pair;
using std::endl;
// encode this in the function itself.
bool disable = false;
switch (ev.action) {
- case LFUN_MENUPRINT:
- disable = !Exporter::IsExportable(buf, "dvi")
- || lyxrc.print_command == "none";
- break;
case LFUN_EXPORT:
disable = ev.argument != "custom"
&& !Exporter::IsExportable(buf, ev.argument);
disable = !Exporter::IsExportable(buf, "program");
break;
- case LFUN_LAYOUT_CHARACTER:
- disable = tli && tli->lyxCode() == Inset::ERT_CODE;
- break;
-
case LFUN_LAYOUT_TABULAR:
disable = !tli
|| (tli->lyxCode() != Inset::TABULAR_CODE
break;
case LFUN_VC_REVERT:
case LFUN_VC_UNDO:
- case LFUN_VC_HISTORY:
disable = !buf->lyxvc.inUse();
break;
case LFUN_MENURELOAD:
case LFUN_INSET_SETTINGS: {
disable = true;
UpdatableInset * inset = view()->theLockingInset();
-
+
if (!inset)
break;
// jump back to owner if an InsetText, so
// we get back to the InsetTabular or whatever
if (inset->lyxCode() == Inset::TEXT_CODE)
- inset = static_cast<UpdatableInset*>(inset->owner());
+ inset = inset->owner();
Inset::Code code = inset->lyxCode();
switch (code) {
break;
}
- case LFUN_LATEX_LOG:
- disable = !IsFileReadable(buf->getLogName().second);
- break;
-
case LFUN_MATH_MUTATE:
if (mathcursor)
//flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
disable = !mathcursor;
break;
+ case LFUN_DIALOG_SHOW: {
+ string const name = ev.getArg(0);
+ if (!buf) {
+ disable = !(name == "aboutlyx" ||
+ name == "file" ||
+ name == "forks" ||
+ name == "preferences" ||
+ name == "texinfo");
+ break;
+ }
+
+ if (name == "print") {
+ disable = !Exporter::IsExportable(buf, "dvi") ||
+ lyxrc.print_command == "none";
+ } else if (name == "character") {
+ UpdatableInset * tli = view()->theLockingInset();
+ disable = tli && tli->lyxCode() == Inset::ERT_CODE;
+ } else if (name == "vclog") {
+ disable = !buf->lyxvc.inUse();
+ } else if (name == "latexlog") {
+ disable = !IsFileReadable(buf->getLogName().second);
+ }
+ break;
+ }
+
default:
break;
}
case LFUN_TOC_INSERT:
code = Inset::TOC_CODE;
break;
- case LFUN_PARENTINSERT:
- code = Inset::PARENT_CODE;
- break;
case LFUN_HTMLURL:
case LFUN_URL:
code = Inset::URL_CODE;
case LFUN_END_OF_SENTENCE:
code = Inset::SPECIALCHAR_CODE;
break;
- case LFUN_PROTECTEDSPACE:
+ case LFUN_SPACE_INSERT:
// slight hack: we know this is allowed in math mode
if (!mathcursor)
- code = Inset::SPECIALCHAR_CODE;
+ code = Inset::SPACE_CODE;
break;
default:
break;
&& argument.empty()) {
argument = encoded_last_key;
}
+
+ // the insets can't try to handle this,
+ // a table cell in the dummy position will
+ // lock its insettext, the insettext will
+ // pass it the bufferview, and succeed,
+ // so it will stay not locked. Not good
+ // if we've just done LFUN_ESCAPE (which
+ // injects an LFUN_PARAGRAPH_UPDATE)
+ if (action == LFUN_PARAGRAPH_UPDATE) {
+ view()->dispatch(ev);
+ goto exit_with_message;
+ }
+
// Undo/Redo is a bit tricky for insets.
if (action == LFUN_UNDO) {
view()->undo();
}
goto exit_with_message;
case LFUN_DOWN:
- if (boost::next(TEXT()->cursor.row()) != TEXT()->rows().end())
+ if (boost::next(TEXT()->cursorRow()) != TEXT()->rows().end())
TEXT()->cursorDown(view());
else
TEXT()->cursorRight(view());
string const str = bformat(_("Saving document %1$s..."),
MakeDisplayPath(owner->buffer()->fileName()));
owner->message(str);
- MenuWrite(view(), owner->buffer());
+ MenuWrite(owner->buffer());
owner->message(str + _(" done."));
} else
- WriteAs(view(), owner->buffer());
+ WriteAs(owner->buffer());
break;
case LFUN_WRITEAS:
- WriteAs(view(), owner->buffer(), argument);
+ WriteAs(owner->buffer(), argument);
break;
case LFUN_MENURELOAD: {
case LFUN_UPDATE:
Exporter::Export(owner->buffer(), argument, true);
+ view()->showErrorList(BufferFormat(*owner->buffer()));
break;
case LFUN_PREVIEW:
Exporter::Preview(owner->buffer(), argument);
+ view()->showErrorList(BufferFormat(*owner->buffer()));
break;
case LFUN_BUILDPROG:
Exporter::Export(owner->buffer(), "program", true);
+ view()->showErrorList(_("Build"));
break;
case LFUN_RUNCHKTEX:
owner->buffer()->runChktex();
- break;
-
- case LFUN_MENUPRINT:
- owner->getDialogs().showPrint();
+ view()->showErrorList(_("ChkTeX"));
break;
case LFUN_EXPORT:
if (argument == "custom")
owner->getDialogs().showSendto();
- else
+ else {
Exporter::Export(owner->buffer(), argument, false);
+ view()->showErrorList(BufferFormat(*owner->buffer()));
+ }
break;
case LFUN_IMPORT:
view()->redo();
break;
- case LFUN_MENUSEARCH:
- owner->getDialogs().showSearch();
- break;
-
- case LFUN_REMOVEERRORS:
- if (view()->removeAutoInsets()) {
-#warning repaint() or update() or nothing ?
- view()->repaint();
- view()->fitCursor();
- }
- break;
-
case LFUN_DEPTH_MIN:
changeDepth(view(), TEXT(false), DEC_DEPTH, false);
owner->view_state_changed();
//#warning Find another implementation here (or another lyxfunc)!
#endif
#endif
- case LFUN_HELP_ABOUTLYX:
- owner->getDialogs().show("about");
- break;
-
- case LFUN_HELP_TEXINFO:
- owner->getDialogs().showTexinfo();
- break;
-
case LFUN_HELP_OPEN:
{
string const arg = argument;
}
owner->message(bformat(_("Opening help file %1$s..."),
MakeDisplayPath(fname)));
- view()->buffer(bufferlist.loadLyXFile(fname, false));
+ view()->loadLyXFile(fname, false);
break;
}
}
break;
- case LFUN_VC_HISTORY:
- {
- owner->getDialogs().show("vclog");
- break;
- }
-
// --- buffers ----------------------------------------
case LFUN_SWITCHBUFFER:
open(argument);
break;
- case LFUN_LATEX_LOG:
- owner->getDialogs().show("log");
- break;
-
- case LFUN_LAYOUT_DOCUMENT:
- owner->getDialogs().showDocument();
- break;
-
- case LFUN_LAYOUT_CHARACTER: {
- string data = freefont2string();
- if (!data.empty())
- owner->getDialogs().show("character", data);
- break;
- }
-
case LFUN_LAYOUT_TABULAR:
if (view()->theLockingInset()) {
if (view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
}
break;
- case LFUN_LAYOUT_PREAMBLE:
- owner->getDialogs().showPreamble();
- break;
-
case LFUN_DROP_LAYOUTS_CHOICE:
owner->getToolbar().openLayoutList();
break;
owner->getMenubar().openByName(argument);
break; // RVDK_PATCH_5
- case LFUN_SPELLCHECK:
- owner->getDialogs().showSpellchecker();
- break;
-
// --- lyxserver commands ----------------------------
if (bufferlist.exists(s)) {
view()->buffer(bufferlist.getBuffer(s));
} else {
- view()->buffer(bufferlist.loadLyXFile(s));
+ view()->loadLyXFile(s);
}
view()->setCursorFromRow(row);
<< id << ']' << endl;
break;
} else {
- lyxerr[Debug::INFO] << "Paragraph " << (*par)->id()
+ lyxerr[Debug::INFO] << "Paragraph " << par->id()
<< " found." << endl;
}
if (view()->theLockingInset())
view()->unlockInset(view()->theLockingInset());
- if ((*par)->inInset()) {
+ if (par->inInset()) {
FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
- (*par)->inInset()->localDispatch(cmd);
+ par->inInset()->localDispatch(cmd);
}
// Set the cursor
- view()->getLyXText()->setCursor(*par, 0);
+ view()->getLyXText()->setCursor(par.pit(), 0);
view()->switchKeyMap();
owner->view_state_changed();
dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
break;
- case LFUN_MATH_PANEL:
- owner->getDialogs().showMathPanel();
+ case LFUN_DIALOG_SHOW: {
+ string const name = ev.getArg(0);
+ string data = trim(ev.argument.substr(name.size()));
+
+ if (name == "character") {
+ data = freefont2string();
+ if (!data.empty())
+ owner->getDialogs().show("character", data);
+ } else if (name == "document")
+ owner->getDialogs().showDocument();
+ else if (name == "findreplace")
+ owner->getDialogs().showSearch();
+ else if (name == "forks")
+ owner->getDialogs().showForks();
+ else if (name == "preamble")
+ owner->getDialogs().showPreamble();
+ else if (name == "preferences")
+ owner->getDialogs().showPreferences();
+ else if (name == "print")
+ owner->getDialogs().showPrint();
+ else if (name == "spellchecker")
+ owner->getDialogs().showSpellchecker();
+ else
+ owner->getDialogs().show(name, data);
break;
+ }
case LFUN_DIALOG_SHOW_NEW_INSET: {
string const & name = argument;
if (bufferlist.exists(filename))
view()->buffer(bufferlist.getBuffer(filename));
else
- view()->buffer(bufferlist.loadLyXFile(filename));
+ view()->loadLyXFile(filename);
}
break;
}
break;
- case LFUN_DIALOG_PREFERENCES:
- owner->getDialogs().showPreferences();
- break;
-
case LFUN_SAVEPREFERENCES:
{
Path p(user_lyxdir);
owner->message(argument);
break;
- case LFUN_FORKS_SHOW:
- owner->getDialogs().showForks();
- break;
-
case LFUN_FORKS_KILL:
{
if (!isStrInt(argument))
owner->getDialogs().toggleTooltips();
break;
+ case LFUN_EXTERNAL_EDIT: {
+ InsetExternal()
+ .localDispatch(FuncRequest(view(), action, argument));
+ break;
+ }
+
default:
// Then if it was none of the above
// Trying the BufferView::pimpl dispatch:
templname = fname;
}
- view()->buffer(bufferlist.newFile(filename, templname, !name.empty()));
+ view()->buffer(newFile(filename, templname, !name.empty()));
}
FileInfo const f(filename, true);
if (!f.exist()) {
// the user specifically chose this name. Believe them.
- Buffer * buffer = bufferlist.newFile(filename, "", true);
+ Buffer * buffer = newFile(filename, "", true);
view()->buffer(buffer);
return;
}
owner->message(bformat(_("Opening document %1$s..."), disp_fn));
- Buffer * openbuf = bufferlist.loadLyXFile(filename);
string str2;
- if (openbuf) {
- view()->buffer(openbuf);
+ if (view()->loadLyXFile(filename)) {
str2 = bformat(_("Document %1$s opened."), disp_fn);
} else {
str2 = bformat(_("Could not open document %1$s"), disp_fn);
BufferView * LyXFunc::view() const
{
- lyx::Assert(owner);
+ Assert(owner);
return owner->view().get();
}