]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
I assume this was a c&p error
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 0a1b4ba15074eff00c65491f6d8f33ab0c48c5ae..569de58926a42788028d0e627c962fd9ef35efc1 100644 (file)
@@ -217,17 +217,17 @@ struct GuiView::GuiViewPrivate
 
                // TODO cleanup, remove the singleton, handle multiple Windows?
                progress_ = ProgressInterface::instance();
-               if (!dynamic_cast<GuiProgress*>(progress_)) {           
+               if (!dynamic_cast<GuiProgress*>(progress_)) {
                        progress_ = new GuiProgress();  // TODO who deletes it
-                       ProgressInterface::setInstance(progress_);                      
+                       ProgressInterface::setInstance(progress_);
                }
                QObject::connect(
-                               dynamic_cast<GuiProgress*>(progress_), 
-                               SIGNAL(updateStatusBarMessage(QString const&)), 
+                               dynamic_cast<GuiProgress*>(progress_),
+                               SIGNAL(updateStatusBarMessage(QString const&)),
                                gv, SLOT(updateStatusBarMessage(QString const&)));
                QObject::connect(
-                               dynamic_cast<GuiProgress*>(progress_), 
-                               SIGNAL(clearMessageText()), 
+                               dynamic_cast<GuiProgress*>(progress_),
+                               SIGNAL(clearMessageText()),
                                gv, SLOT(clearMessageText()));
        }
 
@@ -327,7 +327,7 @@ public:
        ToolbarMap toolbars_;
        ProgressInterface* progress_;
        /// The main layout box.
-       /** 
+       /**
         * \warning Don't Delete! The layout box is actually owned by
         * whichever toolbar contains it. All the GuiView class needs is a
         * means of accessing it.
@@ -360,7 +360,7 @@ public:
        ///
        string last_export_format;
 #else
-       struct DummyWatcher { bool isRunning(){return false;} }; 
+       struct DummyWatcher { bool isRunning(){return false;} };
        DummyWatcher preview_watcher_;
 #endif
 
@@ -385,7 +385,7 @@ GuiView::GuiView(int id)
        // filling, at least for the static special menu item on Mac. Otherwise
        // they are greyed out.
        guiApp->setCurrentView(this);
-       
+
        // Fill up the menu bar.
        guiApp->menus().fillMenuBar(menuBar(), this, true);
 
@@ -758,7 +758,7 @@ void GuiView::dropEvent(QDropEvent * event)
                vector<const Format *> found_formats;
 
                // Find all formats that have the correct extension.
-               vector<const Format *> const & import_formats 
+               vector<const Format *> const & import_formats
                        = theConverters().importableFormats();
                vector<const Format *>::const_iterator it = import_formats.begin();
                for (; it != import_formats.end(); ++it)
@@ -774,7 +774,7 @@ void GuiView::dropEvent(QDropEvent * event)
                        }
                        string const arg = found_formats[0]->name() + " " + file;
                        cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
-               } 
+               }
                else {
                        //FIXME: do we have to explicitly check whether it's a lyx file?
                        LYXERR(Debug::FILES,
@@ -795,7 +795,7 @@ void GuiView::message(docstring const & str)
 {
        if (ForkedProcess::iAmAChild())
                return;
-       
+
        // call is moved to GUI-thread by GuiProgress
        d.progress_->appendMessage(toqstr(str));
 }
@@ -1060,7 +1060,7 @@ GuiWorkArea * GuiView::workArea(Buffer & buffer)
 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
 {
        // Automatically create a TabWorkArea if there are none yet.
-       TabWorkArea * tab_widget = d.splitter_->count() 
+       TabWorkArea * tab_widget = d.splitter_->count()
                ? d.currentTabWorkArea() : addTabWorkArea();
        return tab_widget->addWorkArea(buffer, *this);
 }
@@ -1120,8 +1120,8 @@ void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
        // FIXME: I've no clue why this is here and why it accesses
        //  theGuiApp()->currentView, which might be 0 (bug 6464).
        //  See also 27525 (vfr).
-       if (theGuiApp()->currentView() == this 
-                 && theGuiApp()->currentView()->currentWorkArea() == wa) 
+       if (theGuiApp()->currentView() == this
+                 && theGuiApp()->currentView()->currentWorkArea() == wa)
                return;
 
        if (currentBufferView())
@@ -1330,7 +1330,7 @@ BufferView * GuiView::documentBufferView()
 }
 
 
-BufferView const * GuiView::documentBufferView() const 
+BufferView const * GuiView::documentBufferView() const
 {
        return currentMainWorkArea()
                ? &currentMainWorkArea()->bufferView()
@@ -1428,7 +1428,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                break;
 
        case LFUN_MASTER_BUFFER_UPDATE:
-       case LFUN_MASTER_BUFFER_VIEW: 
+       case LFUN_MASTER_BUFFER_VIEW:
                enable = doc_buffer && doc_buffer->parent() != 0
                        && !d.preview_watcher_.isRunning();
                break;
@@ -1476,7 +1476,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                                break;
                        }
                        b = theBufferList().next(b);
-               } while (b != first); 
+               } while (b != first);
                break;
        }
 
@@ -1511,7 +1511,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                        flag.setOnOff(t->isVisible());
                else {
                        enable = false;
-                       docstring const msg = 
+                       docstring const msg =
                                bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
                        flag.message(msg);
                }
@@ -1519,7 +1519,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        }
 
        case LFUN_DROP_LAYOUTS_CHOICE:
-               enable = buf; 
+               enable = buf;
                break;
 
        case LFUN_UI_TOGGLE:
@@ -1623,7 +1623,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        case LFUN_BUFFER_ZOOM_IN:
                enable = doc_buffer;
                break;
-       
+
        case LFUN_BUFFER_NEXT:
        case LFUN_BUFFER_PREVIOUS:
                // FIXME: should we check is there is an previous or next buffer?
@@ -1651,13 +1651,13 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setOnOff(enable && doc_buffer->lyxvc().locking());
                break;
        case LFUN_VC_REVERT:
-               enable = doc_buffer && doc_buffer->lyxvc().inUse();
+               enable = doc_buffer && doc_buffer->lyxvc().inUse() && !doc_buffer->isReadonly();
                break;
        case LFUN_VC_UNDO_LAST:
                enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
                break;
        case LFUN_VC_REPO_UPDATE:
-               enable = doc_buffer && doc_buffer->lyxvc().inUse();
+               enable = doc_buffer && doc_buffer->lyxvc().repoUpdateEnabled();
                break;
        case LFUN_VC_COMMAND: {
                if (cmd.argument().empty())
@@ -1667,8 +1667,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                break;
        }
        case LFUN_VC_COMPARE:
-               enable = doc_buffer && !cmd.argument().empty()
-                        && doc_buffer->lyxvc().prepareFileRevisionEnabled();
+               enable = doc_buffer && doc_buffer->lyxvc().prepareFileRevisionEnabled();
                break;
 
        case LFUN_SERVER_GOTO_FILE_ROW:
@@ -1692,7 +1691,7 @@ static FileName selectTemplateFile()
 {
        FileDialog dlg(qt_("Select template file"));
        dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
-       dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
+       dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
 
        FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
                                 QStringList(qt_("LyX Documents (*.lyx)")));
@@ -1716,7 +1715,7 @@ Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
                setBusy(false);
                return 0;
        }
-       
+
        setBuffer(newBuffer);
 
        // scroll to the position when the file was last closed
@@ -1775,8 +1774,8 @@ void GuiView::openDocument(string const & fname)
                filename = fname;
 
        // get absolute path of file and add ".lyx" to the filename if
-       // necessary. 
-       FileName const fullname = 
+       // necessary.
+       FileName const fullname =
                        fileSearch(string(), filename, "lyx", support::may_not_exist);
        if (!fullname.empty())
                filename = fullname.absFileName();
@@ -1788,7 +1787,7 @@ void GuiView::openDocument(string const & fname)
                return;
        }
 
-       // if the file doesn't exist and isn't already open (bug 6645), 
+       // if the file doesn't exist and isn't already open (bug 6645),
        // let the user create one
        if (!fullname.exists() && !theBufferList().exists(fullname)) {
                // the user specifically chose this name. Believe him.
@@ -1983,7 +1982,7 @@ void GuiView::newDocument(string const & filename, bool from_template)
                if (templatefile.empty())
                        return;
        }
-       
+
        Buffer * b;
        if (filename.empty())
                b = newUnnamedFile(initpath, to_utf8(_("newfile")), templatefile);
@@ -1993,7 +1992,7 @@ void GuiView::newDocument(string const & filename, bool from_template)
        if (b)
                setBuffer(b);
 
-       // If no new document could be created, it is unsure 
+       // If no new document could be created, it is unsure
        // whether there is a valid BufferView.
        if (currentBufferView())
                // Ensure the cursor is correctly positioned on screen.
@@ -2009,7 +2008,7 @@ void GuiView::insertLyXFile(docstring const & fname)
 
        // FIXME UNICODE
        FileName filename(to_utf8(fname));
-       
+
        if (!filename.empty()) {
                bv->insertLyXFile(filename);
                return;
@@ -2064,7 +2063,7 @@ void GuiView::insertPlaintextFile(docstring const & fname,
 
        // FIXME UNICODE
        FileName filename(to_utf8(fname));
-       
+
        if (!filename.empty()) {
                bv->insertPlaintextFile(filename, asParagraph);
                return;
@@ -2137,7 +2136,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                docstring const file = makeDisplayPath(fname.absFileName(), 30);
                docstring text = bformat(_("The document %1$s already "
                                           "exists.\n\nDo you want to "
-                                          "overwrite that document?"), 
+                                          "overwrite that document?"),
                                         file);
                int const ret = Alert::prompt(_("Overwrite document?"),
                        text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
@@ -2159,7 +2158,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
 
        // bring the autosave file with us, just in case.
        b.moveAutosaveFile(oldauto);
-       
+
        if (!saveBuffer(b)) {
                oldauto = b.getAutosaveFileName();
                b.setFileName(oldname.absFileName());
@@ -2276,7 +2275,7 @@ bool GuiView::closeWorkAreaAll()
        setCurrentWorkArea(currentMainWorkArea());
 
        // We might be in a situation that there is still a tabWorkArea, but
-       // there are no tabs anymore. This can happen when we get here after a 
+       // there are no tabs anymore. This can happen when we get here after a
        // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
        // many TabWorkArea's have no documents anymore.
        int empty_twa = 0;
@@ -2329,9 +2328,10 @@ bool GuiView::closeBuffer(Buffer & buf)
        // in the session file in the correct order. If we close the master
        // buffer, we can close or release the child buffers here too.
        if (!closing_) {
-               vector<Buffer *> clist = buf.getChildren(false);
-               for (vector<Buffer *>::const_iterator it = clist.begin();
-                        it != clist.end(); ++it) {
+               ListOfBuffers clist = buf.getChildren();
+               ListOfBuffers::const_iterator it = clist.begin();
+               ListOfBuffers::const_iterator const bend = clist.end();
+               for (; it != bend; ++it) {
                        // If a child is dirty, do not close
                        // without user intervention
                        //FIXME: should we look in other tabworkareas?
@@ -2370,7 +2370,7 @@ bool GuiView::closeTabWorkArea(TabWorkArea * twa)
                // We only want to close the buffer if the same buffer is not visible
                // in another view, and if this is not a child and if we are closing
                // a view (not a tabgroup).
-               bool const close_buffer = 
+               bool const close_buffer =
                        !inMultiViews(wa) && !b.parent() && closing_;
 
                if (!closeWorkArea(wa, close_buffer))
@@ -2404,7 +2404,7 @@ bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
                docstring const text = bformat(_("The document %1$s has not been "
                                                 "saved yet.\n\nDo you want to save "
                                                 "the document?"), file);
-               ret = Alert::prompt(_("Save new document?"), 
+               ret = Alert::prompt(_("Save new document?"),
                        text, 0, 1, _("&Save"), _("&Cancel"));
                if (ret == 1)
                        ++ret;
@@ -2460,7 +2460,7 @@ bool GuiView::inMultiViews(GuiWorkArea * wa)
        for (int i = 0; i != ids.size() && found_twa <= 1; ++i) {
                if (id_ == ids[i])
                        continue;
-               
+
                if (guiApp->view(ids[i]).workArea(buf))
                        return true;
        }
@@ -2506,7 +2506,7 @@ static bool ensureBufferClean(Buffer * buffer)
                                                 "changes.\n\nDo you want to save "
                                                 "the document?"), file);
                title = _("Save changed document?");
-               
+
        } else {
                text = bformat(_("The document %1$s has not been "
                                                 "saved yet.\n\nDo you want to save "
@@ -2522,10 +2522,10 @@ static bool ensureBufferClean(Buffer * buffer)
 }
 
 
-void GuiView::reloadBuffer()
+bool GuiView::reloadBuffer()
 {
        Buffer * buf = &documentBufferView()->buffer();
-       buf->reload();
+       return buf->reload();
 }
 
 
@@ -2548,11 +2548,8 @@ void GuiView::checkExternallyModifiedBuffers()
 }
 
 
-//FIXME use a DispatchResult object to transmit messages
-void GuiView::dispatchVC(FuncRequest const & cmd)
+void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
 {
-       // message for statusbar
-       string msg;
        Buffer * buffer = documentBufferView()
                ? &(documentBufferView()->buffer()) : 0;
 
@@ -2561,8 +2558,10 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (!buffer->lyxvc().inUse()) {
-                       if (buffer->lyxvc().registrer())
+                       if (buffer->lyxvc().registrer()) {
                                reloadBuffer();
+                               dr.suppressMessageUpdate();
+                       }
                }
                break;
 
@@ -2570,8 +2569,8 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
-                       msg = buffer->lyxvc().checkIn();
-                       if (!msg.empty())
+                       dr.setMessage(buffer->lyxvc().checkIn());
+                       if (!dr.message().empty())
                                reloadBuffer();
                }
                break;
@@ -2580,7 +2579,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (buffer->lyxvc().inUse()) {
-                       msg = buffer->lyxvc().checkOut();
+                       dr.setMessage(buffer->lyxvc().checkOut());
                        reloadBuffer();
                }
                break;
@@ -2595,7 +2594,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                                frontend::Alert::error(_("Revision control error."),
                                _("Error when setting the locking property."));
                        } else {
-                               msg = res;
+                               dr.setMessage(res);
                                reloadBuffer();
                        }
                }
@@ -2605,18 +2604,20 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                LASSERT(buffer, return);
                buffer->lyxvc().revert();
                reloadBuffer();
+               dr.suppressMessageUpdate();
                break;
 
        case LFUN_VC_UNDO_LAST:
                LASSERT(buffer, return);
                buffer->lyxvc().undoLast();
                reloadBuffer();
+               dr.suppressMessageUpdate();
                break;
 
        case LFUN_VC_REPO_UPDATE:
                LASSERT(buffer, return);
                if (ensureBufferClean(buffer)) {
-                       msg = buffer->lyxvc().repoUpdate();
+                       dr.setMessage(buffer->lyxvc().repoUpdate());
                        checkExternallyModifiedBuffers();
                }
                break;
@@ -2665,6 +2666,11 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
 
        case LFUN_VC_COMPARE: {
 
+               if (cmd.argument().empty()) {
+                       lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "comparehistory"));
+                       break;
+               }
+
                string rev1 = cmd.getArg(0);
                string f1, f2;
 
@@ -2682,29 +2688,17 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                        if (!buffer->lyxvc().prepareFileRevision(rev2, f2))
                                break;
                }
-               // FIXME We need to call comparison feature here.
-               // This is quick and dirty code for testing VC.
-               // We need that comparison feature has some LFUN_COMPARE <FLAG> file1 file1
-               // where <FLAG> specifies whether we want GUI dialog or just launch
-               // running with defaults.
-               /*
-               FileName initpath(lyxrc.document_path);
-               Buffer * dest = newUnnamedFile(initpath, to_utf8(_("differences")));
-               CompareOptions options;
-               Compare * compare = new Compare(loadIfNeeded(FileName(f1)), loadIfNeeded(FileName(f2)), dest, options);
-               compare->start(QThread::LowPriority);
-               Sleep::millisec(200);
-               lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest->absFileName()));
-               */
+
+               LYXERR(Debug::LYXVC, "Launching comparison for fetched revisions:\n" <<
+                                       f1 << "\n"  << f2 << "\n" );
+               string par = "compare run " + quoteName(f1) + " " + quoteName(f2);
+               lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, par));
                break;
        }
 
        default:
                break;
        }
-
-       if (!msg.empty())
-               message(from_utf8(msg));
 }
 
 
@@ -2732,7 +2726,7 @@ void GuiView::openChildDocument(string const & fname)
        // when the target is in the parent or another child document.
        child->setParent(&buffer);
 
-       // I don't think this is needed, since it will be called in 
+       // I don't think this is needed, since it will be called in
        // setBuffer().
        //      child->masterBuffer()->updateBuffer();
        setBuffer(child);
@@ -2831,11 +2825,12 @@ docstring GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer
 #endif
 
 
+
 void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 {
        BufferView * bv = currentBufferView();
        // By default we won't need any update.
-       dr.update(Update::None);
+       dr.screenUpdate(Update::None);
        // assume cmd will be dispatched
        dr.dispatched(true);
 
@@ -2865,7 +2860,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                break;
                        // GCC only sees strfwd.h when building merged
                        if (::lyx::operator==(cmd.argument(), "custom")) {
-                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"), 
+                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"),
                                         dr);
                                break;
                        }
@@ -2880,81 +2875,104 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_BUFFER_UPDATE: {
                        if (!doc_buffer)
                                break;
+                       docstring msg = _("Exporting ...");
+                       Buffer const * used_buffer = doc_buffer;
                        string format = argument;
-                       if (argument.empty())
-                               format = doc_buffer->getDefaultOutputFormat();
+                       if (format.empty())
+                               format = used_buffer->getDefaultOutputFormat();
 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
-                       d.progress_->clearMessages();
-                       message(_("Exporting ..."));
-                       GuiViewPrivate::busyBuffers.insert(doc_buffer);
-                       QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::exportAndDestroy,
-                               doc_buffer, doc_buffer->clone(), format);
+                       if (!msg.empty()) {
+                               d.progress_->clearMessages();
+                               message(msg);
+                       }
+                       GuiViewPrivate::busyBuffers.insert(used_buffer);
+                       QFuture<docstring> f = QtConcurrent::run(
+                                   GuiViewPrivate::exportAndDestroy,
+                                   used_buffer,
+                                   used_buffer->clone(),
+                                   format);
                        d.setPreviewFuture(f);
-                       d.last_export_format = doc_buffer->bufferFormat();
+                       d.last_export_format = used_buffer->bufferFormat();
 #else
                        bool const update_unincluded =
-                               doc_buffer->params().maintain_unincluded_children
-                               && !doc_buffer->params().getIncludedChildren().empty();
-                       doc_buffer->doExport(format, true, update_unincluded);
+                               used_buffer->params().maintain_unincluded_children &&
+                               !used_buffer->params().getIncludedChildren().empty();
+                       used_buffer->doExport(format, true, update_unincluded);
 #endif
                        break;
                }
                case LFUN_BUFFER_VIEW: {
                        if (!doc_buffer)
                                break;
+                       docstring msg = _("Previewing ...");
+                       Buffer const * used_buffer = doc_buffer;
                        string format = argument;
-                       if (argument.empty())
-                               format = doc_buffer->getDefaultOutputFormat();
+                       if (format.empty())
+                               format = used_buffer->getDefaultOutputFormat();
 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
-                       d.progress_->clearMessages();
-                       message(_("Previewing ..."));
-                       GuiViewPrivate::busyBuffers.insert(doc_buffer);
-                       QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::previewAndDestroy,
-                               doc_buffer, doc_buffer->clone(), format);
+                       if (!msg.empty()) {
+                               d.progress_->clearMessages();
+                               message(msg);
+                       }
+                       GuiViewPrivate::busyBuffers.insert(used_buffer);
+                       QFuture<docstring> f = QtConcurrent::run(
+                                   GuiViewPrivate::previewAndDestroy,
+                                   used_buffer,
+                                   used_buffer->clone(),
+                                   format);
                        d.setPreviewFuture(f);
-                       d.last_export_format = doc_buffer->bufferFormat();
+                       d.last_export_format = used_buffer->bufferFormat();
 #else
                        bool const update_unincluded =
-                               doc_buffer->params().maintain_unincluded_children
-                               && !doc_buffer->params().getIncludedChildren().empty();
-                       doc_buffer->preview(format, update_unincluded);
+                               used_buffer->params().maintain_unincluded_children &&
+                               !used_buffer->params().getIncludedChildren().empty();
+                       used_buffer->preview(format, update_unincluded);
 #endif
                        break;
                }
                case LFUN_MASTER_BUFFER_UPDATE: {
                        if (!doc_buffer)
                                break;
+                       Buffer const * used_buffer = doc_buffer->masterBuffer();
                        string format = argument;
-                       Buffer const * master = doc_buffer->masterBuffer();
-                       if (argument.empty())
-                               format = master->getDefaultOutputFormat();
+                       if (format.empty())
+                               format = used_buffer->getDefaultOutputFormat();
 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
-                       GuiViewPrivate::busyBuffers.insert(master);
-                       QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::exportAndDestroy,
-                               master, master->clone(), format);
+                       GuiViewPrivate::busyBuffers.insert(used_buffer);
+                       QFuture<docstring> f = QtConcurrent::run(
+                                   GuiViewPrivate::exportAndDestroy,
+                                   used_buffer,
+                                   used_buffer->clone(),
+                                   format);
                        d.setPreviewFuture(f);
-                       d.last_export_format = doc_buffer->bufferFormat();
+                       d.last_export_format = used_buffer->bufferFormat();
 #else
                        bool const update_unincluded =
-                               master->params().maintain_unincluded_children
-                               && !master->params().getIncludedChildren().empty();
-                       master->doExport(format, true);
+                               used_buffer->params().maintain_unincluded_children &&
+                               !used_buffer->params().getIncludedChildren().empty();
+                       used_buffer->doExport(format, update_unincluded);
 #endif
                        break;
                }
                case LFUN_MASTER_BUFFER_VIEW: {
+                       if (!doc_buffer)
+                               break;
+                       Buffer const * used_buffer = doc_buffer->masterBuffer();
                        string format = argument;
-                       Buffer const * master = doc_buffer->masterBuffer();
-                       if (argument.empty())
-                               format = master->getDefaultOutputFormat();
+                       if (format.empty())
+                               format = used_buffer->getDefaultOutputFormat();
 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
-                       GuiViewPrivate::busyBuffers.insert(master);
-                       QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::previewAndDestroy,
-                               master, master->clone(), format);
+                       GuiViewPrivate::busyBuffers.insert(used_buffer);
+                       QFuture<docstring> f = QtConcurrent::run(
+                                   GuiViewPrivate::previewAndDestroy,
+                                   used_buffer, 
+                                   used_buffer->clone(), 
+                                   format);
                        d.setPreviewFuture(f);
-                       d.last_export_format = doc_buffer->bufferFormat();
+                       // TODO doc_buffer was used used? Was this this a copy & paste error?
+                       d.last_export_format = used_buffer->bufferFormat();
 #else
-                       master->preview(format);
+                       used_buffer->preview(format);
 #endif
                        break;
                }
@@ -2971,15 +2989,15 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                dr.setError(true);
                                dr.setMessage(_("Document not loaded"));
                                break;
-                       } 
+                       }
 
                        // Do we open or switch to the buffer in this view ?
-                       if (workArea(*buffer) 
+                       if (workArea(*buffer)
                                  || lyxrc.open_buffers_in_tabs || !documentBufferView()) {
                                setBuffer(buffer);
                                break;
-                       } 
-                       
+                       }
+
                        // Look for the buffer in other views
                        QList<int> const ids = guiApp->viewIds();
                        int i = 0;
@@ -3078,7 +3096,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                        LYXERR(Debug::ACTION, "Saved " << b->absFileName());
                                }
                                b = theBufferList().next(b);
-                       } while (b != first); 
+                       } while (b != first);
                        dr.setMessage(_("All documents saved."));
                        break;
                }
@@ -3144,7 +3162,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                if (!data.empty())
                                        showDialog("character", data);
                        } else if (name == "latexlog") {
-                               Buffer::LogType type; 
+                               Buffer::LogType type;
                                string const logfile = doc_buffer->logName(&type);
                                switch (type) {
                                case Buffer::latexlog:
@@ -3212,7 +3230,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                }
                        }
                        break;
-                       
+
                case LFUN_COMPLETION_INLINE:
                        if (d.current_work_area_)
                                d.current_work_area_->completer().showInline();
@@ -3255,7 +3273,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
                        if (lyxrc.zoom < 10)
                                lyxrc.zoom = 10;
-                               
+
                        // The global QPixmapCache is used in GuiPainter to cache text
                        // painting so we must reset it.
                        QPixmapCache::clear();
@@ -3272,7 +3290,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_VC_UNDO_LAST:
                case LFUN_VC_COMMAND:
                case LFUN_VC_COMPARE:
-                       dispatchVC(cmd);
+                       dispatchVC(cmd, dr);
                        break;
 
                case LFUN_SERVER_GOTO_FILE_ROW:
@@ -3456,15 +3474,15 @@ namespace {
 // docs in LyXAction.cpp.
 
 char const * const dialognames[] = {
+
 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
-"citation", "compare", "document", "errorlist", "ert", "external",
-"file", "findreplace", "findreplaceadv", "float", "graphics", "href",
-"include", "index", "index_print", "info", "listings", "label", "line",
+"citation", "compare", "comparehistory", "document", "errorlist", "ert",
+"external", "file", "findreplace", "findreplaceadv", "float", "graphics",
+"href", "include", "index", "index_print", "info", "listings", "label", "line",
 "log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
 "nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref",
 "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
-"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap",
-"progress"};
+"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", "progress"};
 
 char const * const * const end_dialognames =
        dialognames + (sizeof(dialognames) / sizeof(char *));
@@ -3554,7 +3572,7 @@ void GuiView::doShowDialog(QString const & qname, QString const & qdata,
                                currentBufferView()->editInset(name, inset);
                        // We only set the focus to the new dialog if it was not yet
                        // visible in order not to change the existing previous behaviour
-                       if (visible) {  
+                       if (visible) {
                                // activateWindow is needed for floating dockviews
                                dialog->asQWidget()->raise();
                                dialog->asQWidget()->activateWindow();
@@ -3643,6 +3661,7 @@ Dialog * createGuiChanges(GuiView & lv);
 Dialog * createGuiCharacter(GuiView & lv);
 Dialog * createGuiCitation(GuiView & lv);
 Dialog * createGuiCompare(GuiView & lv);
+Dialog * createGuiCompareHistory(GuiView & lv);
 Dialog * createGuiDelimiter(GuiView & lv);
 Dialog * createGuiDocument(GuiView & lv);
 Dialog * createGuiErrorList(GuiView & lv);
@@ -3651,7 +3670,6 @@ Dialog * createGuiGraphics(GuiView & lv);
 Dialog * createGuiInclude(GuiView & lv);
 Dialog * createGuiIndex(GuiView & lv);
 Dialog * createGuiLabel(GuiView & lv);
-Dialog * createGuiLine(GuiView & lv);
 Dialog * createGuiListings(GuiView & lv);
 Dialog * createGuiLog(GuiView & lv);
 Dialog * createGuiMathMatrix(GuiView & lv);
@@ -3701,6 +3719,8 @@ Dialog * GuiView::build(string const & name)
                return createGuiCitation(*this);
        if (name == "compare")
                return createGuiCompare(*this);
+       if (name == "comparehistory")
+               return createGuiCompareHistory(*this);
        if (name == "document")
                return createGuiDocument(*this);
        if (name == "errorlist")
@@ -3725,8 +3745,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiPrintindex(*this);
        if (name == "label")
                return createGuiLabel(*this);
-       if (name == "line")
-               return createGuiLine(*this);
        if (name == "listings")
                return createGuiListings(*this);
        if (name == "log")