]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
fix "make check" with gcc 4.3
[lyx.git] / src / LyXFunc.cpp
index b577b65a7624757ca1b479e2f7b5f70fcb036519..5fc04c1eac542e861f685f56a625e552266337ca 100644 (file)
@@ -66,6 +66,7 @@
 #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"
@@ -256,15 +257,27 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
        if (!theBufferList().exists(bm.filename))
                return;
 
+       // bm can be changed when saving
+       BookmarksSection::Bookmark tmp = bm;
+
+       // Special case idx == 0 used for back-from-back jump navigation
+       if (idx == 0)
+               dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
+
        // if the current buffer is not that one, switch to it.
-       if (lyx_view_->buffer()->fileName() != bm.filename) {
+       if (lyx_view_->buffer()->fileName() != tmp.filename) {
                if (!switchToBuffer)
                        return;
                dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
        }
+
        // moveToPosition try paragraph id first and then paragraph (pit, pos).
-       if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
-               bm.top_id, bm.top_pos))
+       if (!view()->moveToPosition(tmp.bottom_pit, tmp.bottom_pos,
+               tmp.top_id, tmp.top_pos))
+               return;
+
+       // bm changed
+       if (idx == 0)
                return;
 
        // Cursor jump succeeded!
@@ -458,7 +471,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
 
        case LFUN_VC_REGISTER:
-               enable = !buf->lyxvc().inUse() && !buf->isUnnamed();
+               enable = !buf->lyxvc().inUse();
                break;
        case LFUN_VC_CHECK_IN:
                enable = buf->lyxvc().checkInEnabled();
@@ -519,7 +532,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        }
 
        case LFUN_BOOKMARK_CLEAR:
-               enable = theSession().bookmarks().size() > 0;
+               enable = theSession().bookmarks().hasValid();
                break;
 
        // this one is difficult to get right. As a half-baked
@@ -566,6 +579,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
+       case LFUN_VC_COMMAND: {
+               if (cmd.argument().empty())
+                       enable = false;
+
+               if (!buf && contains(cmd.getArg(0), 'D'))
+                       enable = false;
+               break;
+       }
+
        case LFUN_WORD_FIND_FORWARD:
        case LFUN_WORD_FIND_BACKWARD:
        case LFUN_WORD_FINDADV:
@@ -672,21 +694,30 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 bool LyXFunc::ensureBufferClean(BufferView * bv)
 {
        Buffer & buf = bv->buffer();
-       if (buf.isClean())
+       if (buf.isClean() && !buf.isUnnamed())
                return true;
 
        docstring const file = buf.fileName().displayName(30);
-       docstring text = bformat(_("The document %1$s has unsaved "
+       docstring title;
+       docstring text;
+       if (!buf.isUnnamed()) {
+               text = bformat(_("The document %1$s has unsaved "
                                             "changes.\n\nDo you want to save "
                                             "the document?"), file);
-       int const ret = Alert::prompt(_("Save changed document?"),
-                                     text, 0, 1, _("&Save"),
-                                     _("&Cancel"));
+               title = _("Save changed document?");
+               
+       } else {
+               text = bformat(_("The document %1$s has not been "
+                                            "saved yet.\n\nDo you want to save "
+                                            "the document?"), file);
+               title = _("Save new document?");
+       }
+       int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
 
        if (ret == 0)
-               dispatch(FuncRequest(LFUN_BUFFER_WRITE));
+               lyx_view_->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
 
-       return buf.isClean();
+       return buf.isClean() && !buf.isUnnamed();
 }
 
 
@@ -1031,10 +1062,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
                        string const arg = argument;
                        if (arg.empty()) {
-                               setErrorMessage(from_ascii(N_("Missing argument")));
+                               setErrorMessage(from_utf8(N_("Missing argument")));
                                break;
                        }
-                       FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
+                       FileName fname = i18nLibFileSearch("doc", arg, "lyx");
+                       if (fname.empty()) 
+                               fname = i18nLibFileSearch("examples", arg, "lyx");
+
                        if (fname.empty()) {
                                lyxerr << "LyX: unable to find documentation file `"
                                                         << arg << "'. Bad installation?" << endl;
@@ -1055,11 +1089,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                // --- version control -------------------------------
                case LFUN_VC_REGISTER:
                        LASSERT(lyx_view_ && buffer, /**/);
-                       if (!ensureBufferClean(view()) || buffer->isUnnamed())
+                       if (!ensureBufferClean(view()))
                                break;
                        if (!buffer->lyxvc().inUse()) {
-                               buffer->lyxvc().registrer();
-                               reloadBuffer();
+                               if (buffer->lyxvc().registrer())
+                                       reloadBuffer();
                        }
                        updateFlags = Update::Force;
                        break;
@@ -1168,7 +1202,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                InsetCommandParams p(code);
                                data = InsetCommand::params2string(name, p);
                                break;
-                       } 
+                       }
                        case INCLUDE_CODE: {
                                // data is the include type: one of "include",
                                // "input", "verbatiminput" or "verbatiminput*"
@@ -1178,62 +1212,67 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                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);
@@ -1349,6 +1388,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_COMMAND_SEQUENCE: {
                        // argument contains ';'-terminated commands
                        string arg = argument;
+                       if (theBufferList().isLoaded(buffer))
+                               buffer->undo().beginUndoGroup();
                        while (!arg.empty()) {
                                string first;
                                arg = split(arg, first, ';');
@@ -1356,6 +1397,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                func.origin = cmd.origin;
                                dispatch(func);
                        }
+                       if (theBufferList().isLoaded(buffer))
+                               buffer->undo().endUndoGroup();
                        break;
                }
 
@@ -1583,6 +1626,48 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        theSession().bookmarks().clear();
                        break;
 
+               case LFUN_VC_COMMAND: {
+                       string flag = cmd.getArg(0);
+                       if (buffer && contains(flag, 'R') && !ensureBufferClean(view()))
+                               break;
+                       docstring message;
+                       if (contains(flag, 'M'))
+                               if (!Alert::askForText(message, _("LyX VC: Log Message")))
+                                       break;
+
+                       string path = cmd.getArg(1);
+                       if (contains(path, "$$p") && buffer)
+                               path = subst(path, "$$p", buffer->filePath());
+                       LYXERR(Debug::LYXVC, "Directory: " << path);
+                       FileName pp(path);
+                       if (!pp.isReadableDirectory()) {
+                               lyxerr << _("Directory is not accessible.") << endl;
+                               break;
+                       }
+                       support::PathChanger p(pp);
+
+                       string command = cmd.getArg(2);
+                       if (command.empty())
+                               break;
+                       if (buffer) {
+                               command = subst(command, "$$i", buffer->absFileName());
+                               command = subst(command, "$$p", buffer->filePath());
+                       }
+                       command = subst(command, "$$m", to_utf8(message));
+                       LYXERR(Debug::LYXVC, "Command: " << command);
+                       Systemcall one;
+                       one.startscript(Systemcall::Wait, command);
+
+                       if (!buffer)
+                               break;
+                       if (contains(flag, 'I'))
+                               buffer->markDirty();
+                       if (contains(flag, 'R'))
+                               reloadBuffer();
+
+                       break;
+               }
+
                default:
                        LASSERT(theApp(), /**/);
                        // Let the frontend dispatch its own actions.
@@ -1731,6 +1816,9 @@ void LyXFunc::reloadBuffer()
        // The user has already confirmed that the changes, if any, should
        // be discarded. So we just release the Buffer and don't call closeBuffer();
        theBufferList().release(lyx_view_->buffer());
+       // if the lyx_view_ has been destroyed, create a new one
+       if (!lyx_view_)
+               theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
        Buffer * buf = lyx_view_->loadDocument(filename);
        docstring const disp_fn = makeDisplayPath(filename.absFilename());
        docstring str;
@@ -1828,6 +1916,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_ALT_LANG:
        case LyXRC::RC_PLAINTEXT_LINELEN:
        case LyXRC::RC_PLAINTEXT_ROFF_COMMAND:
+       case LyXRC::RC_AUTOCORRECTION_MATH:
        case LyXRC::RC_AUTOREGIONDELETE:
        case LyXRC::RC_AUTORESET_OPTIONS:
        case LyXRC::RC_AUTOSAVE: