]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
typo
[lyx.git] / src / BufferView.cpp
index f4e47f4404079623fdb470f206311a85a12a2032..ca77d6969099011edb0d456d0451c750bed1d8bb 100644 (file)
@@ -413,6 +413,8 @@ void BufferView::processUpdateFlags(Update::flags flags)
                << ", singlepar = " << (flags & Update::SinglePar)
                << "]  buffer: " << &buffer_);
 
+       // FIXME Does this really need doing here? It's done in updateBuffer, and
+       // if the Buffer doesn't need updating, then do the macros?
        buffer_.updateMacros();
 
        // Now do the first drawing step if needed. This consists on updating
@@ -935,7 +937,6 @@ void BufferView::updateDocumentClass(DocumentClass const * const olddc)
        setCursor(backcur.asDocIterator(&buffer_));
 
        buffer_.errors("Class Switch");
-       buffer_.updateBuffer();
 }
 
 /** Return the change status at cursor position, taking in account the
@@ -992,8 +993,8 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        // FIXME: This is a bit problematic because we don't check if this is
        // a document BufferView or not for these LFUNs. We probably have to
        // dispatch both to currentBufferView() and, if that fails,
-       // to documentBufferView(); same as we do know for current Buffer and
-       // document Buffer. Ideally those LFUN should go to Buffer as they*
+       // to documentBufferView(); same as we do now for current Buffer and
+       // document Buffer. Ideally those LFUN should go to Buffer as they
        // operate on the full Buffer and the cursor is only needed either for
        // an Undo record or to restore a cursor position. But we don't know
        // how to do that inside Buffer of course.
@@ -1007,10 +1008,14 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                break;
 
        case LFUN_UNDO:
-               flag.setEnabled(buffer_.undo().hasUndoStack());
+               // We do not use the LyXAction flag for readonly because Undo sets the
+               // buffer clean/dirty status by itself.
+               flag.setEnabled(!buffer_.isReadonly() && buffer_.undo().hasUndoStack());
                break;
        case LFUN_REDO:
-               flag.setEnabled(buffer_.undo().hasRedoStack());
+               // We do not use the LyXAction flag for readonly because Redo sets the
+               // buffer clean/dirty status by itself.
+               flag.setEnabled(!buffer_.isReadonly() && buffer_.undo().hasRedoStack());
                break;
        case LFUN_FILE_INSERT:
        case LFUN_FILE_INSERT_PLAINTEXT_PARA:
@@ -1203,6 +1208,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // It is then better to make sure that all dialogs are in sync with
                // current document settings.
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
                
@@ -1214,6 +1220,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1231,13 +1238,22 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
        case LFUN_TEXTCLASS_APPLY: {
-               if (!LayoutFileList::get().load(argument, buffer_.temppath()) &&
-                       !LayoutFileList::get().load(argument, buffer_.filePath()))
+               // since this shortcircuits, the second call is made only if 
+               // the first fails
+               bool const success = 
+                       LayoutFileList::get().load(argument, buffer_.temppath()) ||
+                       LayoutFileList::get().load(argument, buffer_.filePath());
+               if (!success) {
+                       docstring s = bformat(_("The document class `%1$s' "
+                                                "could not be loaded."), from_utf8(argument));
+                       frontend::Alert::error(_("Could not load class"), s);
                        break;
+               }
 
                LayoutFile const * old_layout = buffer_.params().baseClass();
                LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
@@ -1246,7 +1262,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        // nothing to do
                        break;
 
-               //Save the old, possibly modular, layout for use in conversion.
+               // Save the old, possibly modular, layout for use in conversion.
                DocumentClass const * const oldDocClass =
                        buffer_.params().documentClassPtr();
                cur.recordUndoFullDocument();
@@ -1254,13 +1270,23 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldDocClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
-       case LFUN_TEXTCLASS_LOAD:
-               LayoutFileList::get().load(argument, buffer_.temppath()) ||
-               LayoutFileList::get().load(argument, buffer_.filePath());
+       case LFUN_TEXTCLASS_LOAD: {
+               // since this shortcircuits, the second call is made only if 
+               // the first fails
+               bool const success = 
+                       LayoutFileList::get().load(argument, buffer_.temppath()) ||
+                       LayoutFileList::get().load(argument, buffer_.filePath());
+               if (!success) {                 
+                       docstring s = bformat(_("The document class `%1$s' "
+                                                "could not be loaded."), from_utf8(argument));
+                       frontend::Alert::error(_("Could not load class"), s);
+               }
                break;
+       }
 
        case LFUN_LAYOUT_RELOAD: {
                DocumentClass const * const oldClass = buffer_.params().documentClassPtr();
@@ -1270,6 +1296,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.params().makeDocumentClass();
                updateDocumentClass(oldClass);
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1280,6 +1307,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.setMessage(_("No further undo information"));
                else
                        dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_REDO:
@@ -1289,6 +1317,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.setMessage(_("No further redo information"));
                else
                        dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_FONT_STATE:
@@ -1310,7 +1339,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                saveBookmark(0);
                        }
                }
-               if (!label.empty())
+               if (!label.empty())
                        gotoLabel(label);
                break;
        }
@@ -1402,6 +1431,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        case LFUN_CHANGES_MERGE:
                if (findNextChange(this) || findPreviousChange(this)) {
                        dr.update(Update::Force | Update::FitCursor);
+                       dr.forceBufferUpdate();
                        showDialog("changes");
                }
                break;
@@ -1415,6 +1445,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_ALL_CHANGES_REJECT:
@@ -1427,6 +1458,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
                dr.update(Update::Force | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_WORD_FIND_FORWARD:
@@ -1481,6 +1513,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        }
                }
                replace(this, cmd, has_deleted);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -1532,8 +1565,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
                                                BIBTEX_CODE);
                if (inset) {
-                       if (inset->addDatabase(cmd.argument()))
-                               buffer_.updateBibfilesCache();
+                       if (inset->addDatabase(cmd.argument())) {
+                               buffer_.invalidateBibfileCache();
+                               dr.forceBufferUpdate();
+                       }
                }
                break;
        }
@@ -1544,8 +1579,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
                                                BIBTEX_CODE);
                if (inset) {
-                       if (inset->delDatabase(cmd.argument()))
-                               buffer_.updateBibfilesCache();
+                       if (inset->delDatabase(cmd.argument())) {
+                               buffer_.invalidateBibfileCache();
+                               dr.forceBufferUpdate();
+                       }                               
                }
                break;
        }
@@ -1625,13 +1662,16 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                //FIXME: what to do with cur.x_target()?
                bool update = in_texted && cur.bv().checkDepm(cur, old);
                cur.finishUndo();
-               if (update)
+               if (update) {
                        dr.update(Update::Force | Update::FitCursor);
+                       dr.forceBufferUpdate();
+               }
                break;
        }
 
        case LFUN_SCROLL:
                lfunScroll(cmd);
+               dr.forceBufferUpdate();
                break;
 
        case LFUN_SCREEN_UP_SELECT: {
@@ -1708,6 +1748,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur = savecur;
                cur.fixIfBroken();
                dr.update(Update::Force);
+               dr.forceBufferUpdate();
 
                if (iterations >= max_iter) {
                        dr.setError(true);
@@ -1810,6 +1851,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
                inset->dispatch(cur, fr);
                dr.update(Update::SinglePar | Update::FitCursor);
+               dr.forceBufferUpdate();
                break;
        }
 
@@ -2148,8 +2190,8 @@ bool BufferView::setCursorFromInset(Inset const * inset)
 
 void BufferView::gotoLabel(docstring const & label)
 {
-       std::vector<Buffer const *> bufs = buffer().allRelatives();
-       std::vector<Buffer const *>::iterator it = bufs.begin();
+       ListOfBuffers bufs = buffer().allRelatives();
+       ListOfBuffers::iterator it = bufs.begin();
        for (; it != bufs.end(); ++it) {
                Buffer const * buf = *it;
 
@@ -2227,7 +2269,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
 
        d->cursor_ = cur;
 
-       buffer_.updateBuffer();
+       cur.forceBufferUpdate();
        buffer_.changed(true);
        return true;
 }
@@ -2271,6 +2313,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
 
        d->cursor_.finishUndo();
        d->cursor_.setCurrentFont();
+       if (update)
+               cur.forceBufferUpdate();
        return update;
 }