]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/GuiView.cpp
s/updateLabels/updateBuffer/g, per a suggestion of Abdel's.
[features.git] / src / frontends / qt4 / GuiView.cpp
index e5556b1beaea2cfa3b145b76269a9a10d3bdda49..a59284d2565a08dc8cb169613ee37e46dfa83d59 100644 (file)
@@ -39,6 +39,7 @@
 #include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "Compare.h"
 #include "Converter.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
@@ -51,7 +52,6 @@
 #include "Layout.h"
 #include "Lexer.h"
 #include "LyXAction.h"
-#include "LyXFunc.h"
 #include "LyX.h"
 #include "LyXRC.h"
 #include "LyXVC.h"
 
 #define EXPORT_in_THREAD 1
 
-
 // QtConcurrent was introduced in Qt 4.4
 #if (QT_VERSION >= 0x040400)
 #include <QFuture>
@@ -507,7 +506,6 @@ GuiToolbar * GuiView::toolbar(string const & name)
                return it->second;
 
        LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
-       message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name)));
        return 0;
 }
 
@@ -603,7 +601,7 @@ void GuiView::focusInEvent(QFocusEvent * e)
 {
        LYXERR(Debug::DEBUG, "GuiView::focusInEvent()" << this);
        QMainWindow::focusInEvent(e);
-       // Make sure LyXFunc points to the correct view.
+       // Make sure guiApp points to the correct view.
        guiApp->setCurrentView(this);
        if (currentMainWorkArea())
                currentMainWorkArea()->setFocus();
@@ -1034,16 +1032,16 @@ GuiWorkArea * GuiView::currentWorkArea()
 
 GuiWorkArea const * GuiView::currentMainWorkArea() const
 {
-       if (d.currentTabWorkArea() == NULL)
-               return NULL;
+       if (!d.currentTabWorkArea())
+               return 0;
        return d.currentTabWorkArea()->currentWorkArea();
 }
 
 
 GuiWorkArea * GuiView::currentMainWorkArea()
 {
-       if (d.currentTabWorkArea() == NULL)
-               return NULL;
+       if (!d.currentTabWorkArea())
+               return 0;
        return d.currentTabWorkArea()->currentWorkArea();
 }
 
@@ -1051,13 +1049,17 @@ GuiWorkArea * GuiView::currentMainWorkArea()
 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
 {
        LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
-       if (wa == NULL) {
-               d.current_work_area_ = NULL;
+       if (!wa) {
+               d.current_work_area_ = 0;
                d.setBackground();
                return;
        }
-       GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
-       if (old_gwa == 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) 
                return;
 
        if (currentBufferView())
@@ -1174,7 +1176,7 @@ void GuiView::setBuffer(Buffer * newBuffer)
 
        GuiWorkArea * wa = workArea(*newBuffer);
        if (wa == 0) {
-               newBuffer->masterBuffer()->updateLabels();
+               newBuffer->masterBuffer()->updateBuffer();
                wa = addWorkArea(*newBuffer);
        } else {
                //Disconnect the old buffer...there's no new one.
@@ -1441,10 +1443,18 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = d.currentTabWorkArea();
                break;
 
-       case LFUN_TOOLBAR_TOGGLE:
-               if (GuiToolbar * t = toolbar(cmd.getArg(0)))
+       case LFUN_TOOLBAR_TOGGLE: {
+               string const name = cmd.getArg(0);
+               if (GuiToolbar * t = toolbar(name))
                        flag.setOnOff(t->isVisible());
+               else {
+                       enable = false;
+                       docstring const msg = 
+                               bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
+                       flag.message(msg);
+               }
                break;
+       }
 
        case LFUN_DROP_LAYOUTS_CHOICE:
                enable = buf; 
@@ -1577,7 +1587,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        case LFUN_VC_LOCKING_TOGGLE:
                enable = doc_buffer && !doc_buffer->isReadonly()
                        && doc_buffer->lyxvc().lockingToggleEnabled();
-               flag.setOnOff(enable && !doc_buffer->lyxvc().locker().empty());
+               flag.setOnOff(enable && doc_buffer->lyxvc().locking());
                break;
        case LFUN_VC_REVERT:
                enable = doc_buffer && doc_buffer->lyxvc().inUse();
@@ -1595,6 +1605,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                        enable = false;
                break;
        }
+       case LFUN_VC_COMPARE:
+               enable = doc_buffer && !cmd.argument().empty()
+                        && doc_buffer->lyxvc().prepareFileRevisionEnabled();
+               break;
 
        case LFUN_SERVER_GOTO_FILE_ROW:
                break;
@@ -1724,7 +1738,7 @@ void GuiView::openDocument(string const & fname)
        docstring str2;
        Buffer * buf = loadDocument(fullname);
        if (buf) {
-               buf->updateLabels();
+               buf->updateBuffer();
                setBuffer(buf);
                buf->errors("Parse");
                str2 = bformat(_("Document %1$s opened."), disp_fn);
@@ -1773,7 +1787,7 @@ static bool import(GuiView * lv, FileName const & filename,
                Buffer * buf = lv->loadDocument(lyxfile);
                if (!buf)
                        return false;
-               buf->updateLabels();
+               buf->updateBuffer();
                lv->setBuffer(buf);
                buf->errors("Parse");
        } else {
@@ -2255,7 +2269,7 @@ bool GuiView::closeBuffer(Buffer & buf)
        //FIXME: we should update only the bookmarks related to this buffer!
        LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
        for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
-               theLyXFunc().gotoBookmark(i+1, false, false);
+               guiApp->gotoBookmark(i+1, false, false);
 
        if (saveBufferIfNeeded(buf, false)) {
                theBufferList().release(&buf);
@@ -2567,6 +2581,43 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
 
                break;
                }
+
+       case LFUN_VC_COMPARE: {
+
+               string rev1 = cmd.getArg(0);
+               string f1, f2;
+
+               // f1
+               if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
+                       break;
+
+               if (isStrInt(rev1) && convert<int>(rev1) <= 0) {
+                       f2 = buffer->absFileName();
+               } else {
+                       string rev2 = cmd.getArg(1);
+                       if (rev2.empty())
+                               break;
+                       // f2
+                       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()));
+               */
+               break;
+       }
+
        default:
                break;
        }
@@ -2599,7 +2650,7 @@ void GuiView::openChildDocument(string const & fname)
        // This makes insertion of citations and references in the child work,
        // when the target is in the parent or another child document.
        child->setParent(&buffer);
-       child->masterBuffer()->updateLabels();
+       child->masterBuffer()->updateBuffer();
        setBuffer(child);
        if (parsed)
                child->errors("Parse");
@@ -2647,7 +2698,7 @@ bool GuiView::goToFileRow(string const & argument)
                        buf = theBufferList().getBuffer(s);
                else if (s.exists()) {
                        buf = loadDocument(s);
-                       buf->updateLabels();
+                       buf->updateBuffer();
                        buf->errors("Parse");
                } else {
                        message(bformat(
@@ -2728,7 +2779,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                         dr);
                                break;
                        }
-                       if (doc_buffer->doExport(argument, false)) {
+                       if (!doc_buffer->doExport(argument, false)) {
                                dr.setError(true);
                                dr.setMessage(bformat(_("Error exporting to format: %1$s."),
                                        cmd.argument()));
@@ -2900,7 +2951,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                }
                                b = theBufferList().next(b);
                        } while (b != first); 
-                       message(_("All documents saved."));
+                       dr.setMessage(_("All documents saved."));
                        break;
                }
 
@@ -2987,8 +3038,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                        showDialog("symbols", data);
                        // bug 5274
                        } else if (name == "prefs" && isFullScreen()) {
-                               FuncRequest fr(LFUN_INSET_INSERT, "fullscreen");
-                               lfunUiToggle(fr);
+                               lfunUiToggle("fullscreen");
                                showDialog("prefs", data);
                        } else
                                showDialog(name, data);
@@ -2996,14 +3046,19 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                }
 
                case LFUN_MESSAGE:
-                       message(cmd.argument());
+                       dr.setMessage(cmd.argument());
                        break;
 
-               case LFUN_UI_TOGGLE:
-                       lfunUiToggle(cmd);
+               case LFUN_UI_TOGGLE: {
+                       string arg = cmd.getArg(0);
+                       if (!lfunUiToggle(arg)) {
+                               docstring const msg = "ui-toggle " + _("%1$s unknown command!");
+                               dr.setMessage(bformat(msg, from_utf8(arg)));
+                       }
                        // Make sure the keyboard focus stays in the work area.
                        setFocus();
                        break;
+               }
 
                case LFUN_SPLIT_VIEW: {
                        LASSERT(doc_buffer, break);
@@ -3088,6 +3143,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_VC_REVERT:
                case LFUN_VC_UNDO_LAST:
                case LFUN_VC_COMMAND:
+               case LFUN_VC_COMPARE:
                        dispatchVC(cmd);
                        break;
 
@@ -3112,10 +3168,9 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 }
 
 
-void GuiView::lfunUiToggle(FuncRequest const & cmd)
+bool GuiView::lfunUiToggle(string const & ui_component)
 {
-       string const arg = cmd.getArg(0);
-       if (arg == "scrollbar") {
+       if (ui_component == "scrollbar") {
                // hide() is of no help
                if (d.current_work_area_->verticalScrollBarPolicy() ==
                        Qt::ScrollBarAlwaysOff)
@@ -3125,18 +3180,13 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
                else
                        d.current_work_area_->setVerticalScrollBarPolicy(
                                Qt::ScrollBarAlwaysOff);
-               return;
-       }
-       if (arg == "statusbar") {
+       } else if (ui_component == "statusbar") {
                statusBar()->setVisible(!statusBar()->isVisible());
-               return;
-       }
-       if (arg == "menubar") {
+       } else if (ui_component == "menubar") {
                menuBar()->setVisible(!menuBar()->isVisible());
-               return;
-       }
+       } else
 #if QT_VERSION >= 0x040300
-       if (arg == "frame") {
+       if (ui_component == "frame") {
                int l, t, r, b;
                getContentsMargins(&l, &t, &r, &b);
                //are the frames in default state?
@@ -3146,15 +3196,13 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
                } else {
                        setContentsMargins(0, 0, 0, 0);
                }
-               return;
-       }
+       } else
 #endif
-       if (arg == "fullscreen") {
+       if (ui_component == "fullscreen") {
                toggleFullScreen();
-               return;
-       }
-
-       message(bformat("LFUN_UI_TOGGLE " + _("%1$s unknown command!"), from_utf8(arg)));
+       } else
+               return false;
+       return true;
 }
 
 
@@ -3270,7 +3318,7 @@ bool isValidName(string const & name)
 
 void GuiView::resetDialogs()
 {
-       // Make sure that no LFUN uses any LyXView.
+       // Make sure that no LFUN uses any GuiView.
        guiApp->setCurrentView(0);
        saveLayout();
        menuBar()->clear();
@@ -3404,13 +3452,11 @@ void GuiView::updateDialogs()
        updateLayoutList();
 }
 
+Dialog * createDialog(GuiView & lv, string const & name);
 
 // will be replaced by a proper factory...
 Dialog * createGuiAbout(GuiView & lv);
-Dialog * createGuiBibitem(GuiView & lv);
 Dialog * createGuiBibtex(GuiView & lv);
-Dialog * createGuiBox(GuiView & lv);
-Dialog * createGuiBranch(GuiView & lv);
 Dialog * createGuiChanges(GuiView & lv);
 Dialog * createGuiCharacter(GuiView & lv);
 Dialog * createGuiCitation(GuiView & lv);
@@ -3418,17 +3464,13 @@ Dialog * createGuiCompare(GuiView & lv);
 Dialog * createGuiDelimiter(GuiView & lv);
 Dialog * createGuiDocument(GuiView & lv);
 Dialog * createGuiErrorList(GuiView & lv);
-Dialog * createGuiERT(GuiView & lv);
 Dialog * createGuiExternal(GuiView & lv);
-Dialog * createGuiFloat(GuiView & lv);
 Dialog * createGuiGraphics(GuiView & lv);
 Dialog * createGuiInclude(GuiView & lv);
 Dialog * createGuiIndex(GuiView & lv);
-Dialog * createGuiInfo(GuiView & lv);
 Dialog * createGuiLabel(GuiView & lv);
 Dialog * createGuiListings(GuiView & lv);
 Dialog * createGuiLog(GuiView & lv);
-Dialog * createGuiMathHSpace(GuiView & lv);
 Dialog * createGuiMathMatrix(GuiView & lv);
 Dialog * createGuiNomenclature(GuiView & lv);
 Dialog * createGuiNote(GuiView & lv);
@@ -3446,13 +3488,10 @@ Dialog * createGuiShowFile(GuiView & lv);
 Dialog * createGuiSpellchecker(GuiView & lv);
 Dialog * createGuiSymbols(GuiView & lv);
 Dialog * createGuiTabularCreate(GuiView & lv);
-Dialog * createGuiTabular(GuiView & lv);
 Dialog * createGuiTexInfo(GuiView & lv);
-Dialog * createGuiTextHSpace(GuiView & lv);
 Dialog * createGuiToc(GuiView & lv);
 Dialog * createGuiThesaurus(GuiView & lv);
 Dialog * createGuiHyperlink(GuiView & lv);
-Dialog * createGuiVSpace(GuiView & lv);
 Dialog * createGuiViewSource(GuiView & lv);
 Dialog * createGuiWrap(GuiView & lv);
 Dialog * createGuiProgressView(GuiView & lv);
@@ -3463,16 +3502,14 @@ Dialog * GuiView::build(string const & name)
 {
        LASSERT(isValidName(name), return 0);
 
+       Dialog * dialog = createDialog(*this, name);
+       if (dialog)
+               return dialog;
+
        if (name == "aboutlyx")
                return createGuiAbout(*this);
-       if (name == "bibitem")
-               return createGuiBibitem(*this);
        if (name == "bibtex")
                return createGuiBibtex(*this);
-       if (name == "box")
-               return createGuiBox(*this);
-       if (name == "branch")
-               return createGuiBranch(*this);
        if (name == "changes")
                return createGuiChanges(*this);
        if (name == "character")
@@ -3485,8 +3522,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiDocument(*this);
        if (name == "errorlist")
                return createGuiErrorList(*this);
-       if (name == "ert")
-               return createGuiERT(*this);
        if (name == "external")
                return createGuiExternal(*this);
        if (name == "file")
@@ -3495,8 +3530,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiSearch(*this);
        if (name == "findreplaceadv")
                return createGuiSearchAdv(*this);
-       if (name == "float")
-               return createGuiFloat(*this);
        if (name == "graphics")
                return createGuiGraphics(*this);
        if (name == "href")
@@ -3507,8 +3540,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiIndex(*this);
        if (name == "index_print")
                return createGuiPrintindex(*this);
-       if (name == "info")
-               return createGuiInfo(*this);
        if (name == "label")
                return createGuiLabel(*this);
        if (name == "listings")
@@ -3517,8 +3548,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiLog(*this);
        if (name == "mathdelimiter")
                return createGuiDelimiter(*this);
-       if (name == "mathspace")
-               return createGuiMathHSpace(*this);
        if (name == "mathmatrix")
                return createGuiMathMatrix(*this);
        if (name == "nomenclature")
@@ -3539,14 +3568,10 @@ Dialog * GuiView::build(string const & name)
                return createGuiRef(*this);
        if (name == "sendto")
                return createGuiSendTo(*this);
-       if (name == "space")
-               return createGuiTextHSpace(*this);
        if (name == "spellchecker")
                return createGuiSpellchecker(*this);
        if (name == "symbols")
                return createGuiSymbols(*this);
-       if (name == "tabular")
-               return createGuiTabular(*this);
        if (name == "tabularcreate")
                return createGuiTabularCreate(*this);
        if (name == "texinfo")
@@ -3557,8 +3582,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiToc(*this);
        if (name == "view-source")
                return createGuiViewSource(*this);
-       if (name == "vspace")
-               return createGuiVSpace(*this);
        if (name == "wrap")
                return createGuiWrap(*this);
        if (name == "progress")