]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
remove indirection from LyXView::viewStatusMessage().
[lyx.git] / src / LyXFunc.cpp
index 4e6cdda3e9db1bcf76cfb959506ef20ba3d95736..ef568b57e5471275cc567ac07110bcb026abd7d6 100644 (file)
@@ -43,6 +43,7 @@
 #include "Intl.h"
 #include "KeyMap.h"
 #include "Language.h"
+#include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "LyXAction.h"
 #include "lyxfind.h"
 #include "Session.h"
 #include "SpellChecker.h"
 
-#include "insets/InsetBox.h"
-#include "insets/InsetBranch.h"
-#include "insets/InsetCommand.h"
-#include "insets/InsetERT.h"
-#include "insets/InsetExternal.h"
-#include "insets/InsetFloat.h"
-#include "insets/InsetGraphics.h"
-#include "insets/InsetInclude.h"
-#include "insets/InsetListings.h"
-#include "insets/InsetNote.h"
-#include "insets/InsetPhantom.h"
-#include "insets/InsetSpace.h"
-#include "insets/InsetTabular.h"
-#include "insets/InsetVSpace.h"
-#include "insets/InsetWrap.h"
-
 #include "frontends/alert.h"
 #include "frontends/Application.h"
 #include "frontends/KeySymbol.h"
@@ -84,6 +69,7 @@
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/Path.h"
 #include "support/Package.h"
@@ -378,12 +364,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        bool enable = true;
        switch (cmd.action) {
 
-       case LFUN_CITATION_INSERT: {
-               FuncRequest fr(LFUN_INSET_INSERT, "citation");
-               enable = getStatus(fr).enabled();
-               break;
-       }
-       
        // This could be used for the no-GUI version. The GUI version is handled in
        // LyXView::getStatus(). See above.
        /*
@@ -458,7 +438,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_DROP_LAYOUTS_CHOICE:
        case LFUN_SERVER_GET_FILENAME:
        case LFUN_SERVER_NOTIFY:
-       case LFUN_SERVER_GOTO_FILE_ROW:
        case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
        case LFUN_REPEAT:
        case LFUN_PREFERENCES_SAVE:
@@ -548,21 +527,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                if (lv)
                        lv->restartCursor();
        } else {
-               Buffer * buffer = 0;
-               if (lv && lv->currentBufferView())
-                       buffer = &lv->currentBufferView()->buffer();
                switch (action) {
 
                case LFUN_COMMAND_PREFIX:
-                       LASSERT(lv, /**/);
-                       lv->message(keyseq.printOptions(true));
+                       dispatch(FuncRequest(LFUN_MESSAGE, keyseq.printOptions(true)));
                        break;
 
                case LFUN_CANCEL:
-                       LASSERT(lv && lv->currentBufferView(), /**/);
                        keyseq.reset();
                        meta_fake_bit = NoModifier;
-                       if (buffer)
+                       if (lv && lv->currentBufferView())
                                // cancel any selection
                                dispatch(FuncRequest(LFUN_MARK_OFF));
                        setMessage(from_ascii(N_("Cancel")));
@@ -580,205 +554,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                // --- lyxserver commands ----------------------------
-               case LFUN_SERVER_GET_FILENAME:
-                       LASSERT(lv && buffer, /**/);
-                       setMessage(from_utf8(buffer->absFileName()));
-                       LYXERR(Debug::INFO, "FNAME["
-                               << buffer->absFileName() << ']');
+               case LFUN_SERVER_GET_FILENAME: {
+                       LASSERT(lv && lv->documentBufferView(), return);
+                       docstring const fname = from_utf8(
+                               lv->documentBufferView()->buffer().absFileName());
+                       setMessage(fname);
+                       LYXERR(Debug::INFO, "FNAME[" << fname << ']');
                        break;
-
+               }
                case LFUN_SERVER_NOTIFY:
                        dispatch_buffer = keyseq.print(KeySequence::Portable);
                        theServer().notifyClient(to_utf8(dispatch_buffer));
                        break;
 
-               case LFUN_SERVER_GOTO_FILE_ROW: {
-                       LASSERT(lv, /**/);
-                       string file_name;
-                       int row;
-                       istringstream is(argument);
-                       is >> file_name >> row;
-                       file_name = os::internal_path(file_name);
-                       Buffer * buf = 0;
-                       bool loaded = false;
-                       string const abstmp = package().temp_dir().absFilename();
-                       string const realtmp = package().temp_dir().realPath();
-                       // We have to use os::path_prefix_is() here, instead of
-                       // simply prefixIs(), because the file name comes from
-                       // an external application and may need case adjustment.
-                       if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
-                           || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
-                               // Needed by inverse dvi search. If it is a file
-                               // in tmpdir, call the apropriated function.
-                               // If tmpdir is a symlink, we may have the real
-                               // path passed back, so we correct for that.
-                               if (!prefixIs(file_name, abstmp))
-                                       file_name = subst(file_name, realtmp, abstmp);
-                               buf = theBufferList().getBufferFromTmp(file_name);
-                       } else {
-                               // Must replace extension of the file to be .lyx
-                               // and get full path
-                               FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
-                               // Either change buffer or load the file
-                               if (theBufferList().exists(s))
-                                       buf = theBufferList().getBuffer(s);
-                               else if (s.exists()) {
-                                       buf = lv->loadDocument(s);
-                                       loaded = true;
-                               } else
-                                       lv->message(bformat(
-                                               _("File does not exist: %1$s"),
-                                               makeDisplayPath(file_name)));
-                       }
-
-                       if (!buf) {
-                               updateFlags = Update::None;
-                               break;
-                       }
-
-                       buf->updateLabels();
-                       lv->setBuffer(buf);
-                       lv->documentBufferView()->setCursorFromRow(row);
-                       if (loaded)
-                               buf->errors("Parse");
-                       updateFlags = Update::FitCursor;
-                       break;
-               }
-
-
-               case LFUN_DIALOG_SHOW_NEW_INSET: {
-                       LASSERT(lv, /**/);
-                       string const name = cmd.getArg(0);
-                       InsetCode code = insetCode(name);
-                       string data = trim(to_utf8(cmd.argument()).substr(name.size()));
-                       bool insetCodeOK = true;
-                       switch (code) {
-                       case BIBITEM_CODE:
-                       case BIBTEX_CODE:
-                       case INDEX_CODE:
-                       case LABEL_CODE:
-                       case NOMENCL_CODE:
-                       case NOMENCL_PRINT_CODE:
-                       case REF_CODE:
-                       case TOC_CODE:
-                       case HYPERLINK_CODE: {
-                               InsetCommandParams p(code);
-                               data = InsetCommand::params2string(name, p);
-                               break;
-                       }
-                       case INCLUDE_CODE: {
-                               // data is the include type: one of "include",
-                               // "input", "verbatiminput" or "verbatiminput*"
-                               if (data.empty())
-                                       // default type is requested
-                                       data = "include";
-                               InsetCommandParams p(INCLUDE_CODE, data);
-                               data = InsetCommand::params2string("include", p);
-                               break;
-                       }
-                       case BOX_CODE: {
-                               // \c data == "Boxed" || "Frameless" etc
-                               InsetBoxParams p(data);
-                               data = InsetBox::params2string(p);
-                               break;
-                       }
-                       case BRANCH_CODE: {
-                               InsetBranchParams p;
-                               data = InsetBranch::params2string(p);
-                               break;
-                       }
-                       case CITE_CODE: {
-                               InsetCommandParams p(CITE_CODE);
-                               data = InsetCommand::params2string(name, p);
-                               break;
-                       }
-                       case ERT_CODE: {
-                               data = InsetERT::params2string(InsetCollapsable::Open);
-                               break;
-                       }
-                       case EXTERNAL_CODE: {
-                               InsetExternalParams p;
-                               data = InsetExternal::params2string(p, *buffer);
-                               break;
-                       }
-                       case FLOAT_CODE:  {
-                               InsetFloatParams p;
-                               data = InsetFloat::params2string(p);
-                               break;
-                       }
-                       case LISTINGS_CODE: {
-                               InsetListingsParams p;
-                               data = InsetListings::params2string(p);
-                               break;
-                       }
-                       case GRAPHICS_CODE: {
-                               InsetGraphicsParams p;
-                               data = InsetGraphics::params2string(p, *buffer);
-                               break;
-                       }
-                       case NOTE_CODE: {
-                               InsetNoteParams p;
-                               data = InsetNote::params2string(p);
-                               break;
-                       }
-                       case PHANTOM_CODE: {
-                               InsetPhantomParams p;
-                               data = InsetPhantom::params2string(p);
-                               break;
-                       }
-                       case SPACE_CODE: {
-                               InsetSpaceParams p;
-                               data = InsetSpace::params2string(p);
-                               break;
-                       }
-                       case VSPACE_CODE: {
-                               VSpace space;
-                               data = InsetVSpace::params2string(space);
-                               break;
-                       }
-                       case WRAP_CODE: {
-                               InsetWrapParams p;
-                               data = InsetWrap::params2string(p);
-                               break;
-                       }
-                       default:
-                               lyxerr << "Inset type '" << name << 
-                                       "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" <<  endl;
-                               insetCodeOK = false;
-                               break;
-                       } // end switch(code)
-                       if (insetCodeOK)
-                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
-                       break;
-               }
-
-               case LFUN_CITATION_INSERT: {
-                       LASSERT(lv, /**/);
-                       if (!argument.empty()) {
-                               // we can have one optional argument, delimited by '|'
-                               // citation-insert <key>|<text_before>
-                               // this should be enhanced to also support text_after
-                               // and citation style
-                               string arg = argument;
-                               string opt1;
-                               if (contains(argument, "|")) {
-                                       arg = token(argument, '|', 0);
-                                       opt1 = token(argument, '|', 1);
-                               }
-                               InsetCommandParams icp(CITE_CODE);
-                               icp["key"] = from_utf8(arg);
-                               if (!opt1.empty())
-                                       icp["before"] = from_utf8(opt1);
-                               string icstr = InsetCommand::params2string("citation", icp);
-                               FuncRequest fr(LFUN_INSET_INSERT, icstr);
-                               dispatch(fr);
-                       } else
-                               dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
-                       break;
-               }
-
                case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
-                       LASSERT(lv, /**/);
                        lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
                        break;
 
@@ -798,7 +587,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_COMMAND_SEQUENCE: {
                        // argument contains ';'-terminated commands
                        string arg = argument;
-                       if (theBufferList().isLoaded(buffer))
+                       // FIXME: this LFUN should also work without any view.
+                       Buffer * buffer = (lv && lv->documentBufferView())
+                               ? &(lv->documentBufferView()->buffer()) : 0;
+                       buffer = &lv->currentBufferView()->buffer();
+                       if (buffer && !theBufferList().isLoaded(buffer))
+                               buffer = 0;
+                       if (buffer)
                                buffer->undo().beginUndoGroup();
                        while (!arg.empty()) {
                                string first;
@@ -807,7 +602,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                func.origin = cmd.origin;
                                dispatch(func);
                        }
-                       if (theBufferList().isLoaded(buffer))
+                       if (buffer)
                                buffer->undo().endUndoGroup();
                        break;
                }
@@ -935,18 +730,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (lv == 0)
                                break;
 
+                       Buffer * doc_buffer = (lv && lv->documentBufferView())
+                               ? &(lv->documentBufferView()->buffer()) : 0;
+                       if (doc_buffer && !theBufferList().isLoaded(doc_buffer))
+                               doc_buffer = 0;
                        // Start an undo group. This may be needed for
                        // some stuff like inset-apply on labels.
-                       if (theBufferList().isLoaded(buffer))
-                               buffer->undo().beginUndoGroup();
-                               
+                       if (doc_buffer)
+                               doc_buffer->undo().beginUndoGroup();
+
                        // Let the current LyXView dispatch its own actions.
                        if (lv->dispatch(cmd)) {
                                BufferView * bv = lv->currentBufferView();
                                if (bv) {
-                                       buffer = &(bv->buffer());
+                                       Buffer * buffer = &(bv->buffer());
                                        updateFlags = bv->cursor().result().update();
-                                       if (theBufferList().isLoaded(buffer))
+                                       if (buffer == doc_buffer && theBufferList().isLoaded(buffer))
                                                buffer->undo().endUndoGroup();
                                }
                                break;
@@ -958,9 +757,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // Let the current BufferView dispatch its own actions.
                        if (bv->dispatch(cmd)) {
                                // The BufferView took care of its own updates if needed.
-                               buffer = &(bv->buffer());
+                               Buffer * buffer = &(bv->buffer());
                                updateFlags = Update::None;
-                               if (theBufferList().isLoaded(buffer))
+                               if (buffer == doc_buffer && theBufferList().isLoaded(buffer))
                                        buffer->undo().endUndoGroup();
                                break;
                        }
@@ -969,9 +768,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // Try with the document BufferView dispatch if any.
                        if (doc_bv && doc_bv->dispatch(cmd)) {
                                // The BufferView took care of its own updates if needed.
-                               buffer = &(doc_bv->buffer());
+                               Buffer * buffer = &(doc_bv->buffer());
                                updateFlags = Update::None;
-                               if (theBufferList().isLoaded(buffer))
+                               if (buffer == doc_buffer && theBufferList().isLoaded(buffer))
                                        buffer->undo().endUndoGroup();
                                break;
                        }
@@ -1019,8 +818,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                if (badcursor)
                                        bv->cursor().fixIfBroken();
                        }
-
-                       if (theBufferList().isLoaded(buffer))
+                       Buffer * buffer = &(bv->buffer());
+                       if (buffer == doc_buffer && theBufferList().isLoaded(buffer))
                                buffer->undo().endUndoGroup();
 
                        // update completion. We do it here and not in
@@ -1040,10 +839,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                // if we executed a mutating lfun, mark the buffer as dirty
-               if (theBufferList().isLoaded(buffer) && flag.enabled()
+               Buffer * doc_buffer = (lv && lv->documentBufferView())
+                       ? &(lv->documentBufferView()->buffer()) : 0;
+               if (doc_buffer && theBufferList().isLoaded(doc_buffer)
+                       && flag.enabled()
                    && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
                    && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
-                       buffer->markDirty();                    
+                       doc_buffer->markDirty();                        
 
                if (lv && lv->currentBufferView()) {
                        // BufferView::update() updates the ViewMetricsInfo and
@@ -1144,12 +946,7 @@ docstring LyXFunc::viewStatusMessage()
        if (keyseq.length() > 0 && !keyseq.deleted())
                return keyseq.printOptions(true);
 
-       LyXView * lv = theApp()->currentWindow();
-       LASSERT(lv, /**/);
-       if (!lv->currentBufferView())
-               return _("Welcome to LyX!");
-
-       return lv->currentBufferView()->cursor().currentState();
+       return docstring();
 }