]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
last Friday's text*.C -> text_func shuffle
[lyx.git] / src / lyxfunc.C
index c97fa8bc82911e17ebf420c7b5a502ef4c86089e..9036b814eef0d7f0879bb5a2b4a4902832c22764 100644 (file)
@@ -16,6 +16,7 @@
 #include "lyxrow.h"
 #include "bufferlist.h"
 #include "buffer.h"
+#include "buffer_funcs.h"
 #include "BufferView.h"
 #include "lyxserver.h"
 #include "intl.h"
@@ -77,6 +78,8 @@
 #include <utility>
 #include <algorithm>
 
+using namespace lyx::support;
+
 using std::pair;
 using std::make_pair;
 using std::endl;
@@ -318,10 +321,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        // 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);
@@ -353,10 +352,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                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
@@ -463,7 +458,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        case LFUN_VC_REVERT:
        case LFUN_VC_UNDO:
-       case LFUN_VC_HISTORY:
                disable = !buf->lyxvc.inUse();
                break;
        case LFUN_MENURELOAD:
@@ -527,10 +521,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        }
 
-       case LFUN_LATEX_LOG:
-               disable = !IsFileReadable(buf->getLogName().second);
-               break;
-
        case LFUN_MATH_MUTATE:
                if (mathcursor)
                        //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
@@ -549,6 +539,31 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                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;
        }
@@ -935,7 +950,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                                        }
                                        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());
@@ -1081,29 +1096,31 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 
        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:
@@ -1134,10 +1151,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                view()->redo();
                break;
 
-       case LFUN_MENUSEARCH:
-               owner->getDialogs().showSearch();
-               break;
-
        case LFUN_DEPTH_MIN:
                changeDepth(view(), TEXT(false), DEC_DEPTH, false);
                owner->view_state_changed();
@@ -1176,14 +1189,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 //#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;
@@ -1199,7 +1204,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                }
                owner->message(bformat(_("Opening help file %1$s..."),
                        MakeDisplayPath(fname)));
-               view()->buffer(bufferlist.loadLyXFile(fname, false));
+               view()->loadLyXFile(fname, false);
                break;
        }
 
@@ -1239,12 +1244,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        }
        break;
 
-       case LFUN_VC_HISTORY:
-       {
-               owner->getDialogs().show("vclog");
-               break;
-       }
-
        // --- buffers ----------------------------------------
 
        case LFUN_SWITCHBUFFER:
@@ -1264,21 +1263,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                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) {
@@ -1294,10 +1278,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
            }
            break;
 
-       case LFUN_LAYOUT_PREAMBLE:
-               owner->getDialogs().showPreamble();
-               break;
-
        case LFUN_DROP_LAYOUTS_CHOICE:
                owner->getToolbar().openLayoutList();
                break;
@@ -1306,10 +1286,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                owner->getMenubar().openByName(argument);
                break; // RVDK_PATCH_5
 
-       case LFUN_SPELLCHECK:
-               owner->getDialogs().showSpellchecker();
-               break;
-
        // --- lyxserver commands ----------------------------
 
 
@@ -1340,7 +1316,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                if (bufferlist.exists(s)) {
                        view()->buffer(bufferlist.getBuffer(s));
                } else {
-                       view()->buffer(bufferlist.loadLyXFile(s));
+                       view()->loadLyXFile(s);
                }
 
                view()->setCursorFromRow(row);
@@ -1404,13 +1380,32 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
                break;
 
-       case LFUN_MATH_PANEL:
-               owner->getDialogs().showMathPanel();
-               break;
-
-       case LFUN_DIALOG_SHOW:
-               owner->getDialogs().show(argument);
+       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;
@@ -1469,7 +1464,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                if (bufferlist.exists(filename))
                        view()->buffer(bufferlist.getBuffer(filename));
                else
-                       view()->buffer(bufferlist.loadLyXFile(filename));
+                       view()->loadLyXFile(filename);
        }
        break;
 
@@ -1504,10 +1499,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        }
        break;
 
-       case LFUN_DIALOG_PREFERENCES:
-               owner->getDialogs().showPreferences();
-               break;
-
        case LFUN_SAVEPREFERENCES:
        {
                Path p(user_lyxdir);
@@ -1574,10 +1565,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                owner->message(argument);
                break;
 
-       case LFUN_FORKS_SHOW:
-               owner->getDialogs().showForks();
-               break;
-
        case LFUN_FORKS_KILL:
        {
                if (!isStrInt(argument))
@@ -1736,7 +1723,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
                templname = fname;
        }
 
-       view()->buffer(bufferlist.newFile(filename, templname, !name.empty()));
+       view()->buffer(newFile(filename, templname, !name.empty()));
 }
 
 
@@ -1791,17 +1778,15 @@ void LyXFunc::open(string const & fname)
        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);
@@ -1954,6 +1939,6 @@ string const LyXFunc::view_status_message()
 
 BufferView * LyXFunc::view() const
 {
-       lyx::Assert(owner);
+       Assert(owner);
        return owner->view().get();
 }