]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Updates from Bennett and myself.
[lyx.git] / src / BufferView.C
index d1d768ac36b652dc994091710f066efa08d17265..7ef433cd14b1d5a91c0d30bf9e66f129cc89f7fb 100644 (file)
@@ -197,7 +197,8 @@ void BufferView::setBuffer(Buffer * b)
                }
        }
 
-       update();
+       if (buffer_)
+               updateMetrics(false);    
 
        if (buffer_ && graphics::Previews::status() != LyXRC::PREVIEW_OFF)
                graphics::Previews::get().generateBufferPreviews(*buffer_);
@@ -208,7 +209,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
 {
        // Get absolute path of file and add ".lyx"
        // to the filename if necessary
-       string s = fileSearch(string(), filename, "lyx");
+       string s = fileSearch(string(), filename, "lyx").absFilename();
 
        bool const found = !s.empty();
 
@@ -278,7 +279,9 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
                                if (it.pit() == pit) {
                                        // restored pos may be bigger than it->size
                                        setCursor(makeDocIterator(it, min(pos, it->size())));
-                                       update(Update::FitCursor);
+                                       // No need to update the metrics if fitCursor returns false.
+                                       if (fitCursor())
+                                               updateMetrics(false);
                                        break;
                                }
                }
@@ -367,25 +370,30 @@ std::pair<bool, bool> BufferView::update(Update::flags flags)
        // The second drawing step is done in WorkArea::redraw() if needed.
 
        // Case when no explicit update is requested.
-       if (!(flags & (Update::SinglePar | Update::Force))) {
-               if (fitCursor() || multiParSel()) {
-                       // a CoordCache update is needed
-                       updateMetrics(false);
-                       // tell the frontend to update the screen.
-                       return make_pair(true, false);
-               }
+       if (!flags) {
                // no need to do anything.
                return make_pair(false, false);
        }
 
-       // We are now in the case (Update::SinglePar | Update::Force)
-       bool single_par = flags & Update::SinglePar;
+       if (flags == Update::FitCursor) {
+               bool const fit_cursor = fitCursor();
+               if (fit_cursor)
+                       updateMetrics(false);
+               // tell the frontend to update the screen.
+               return make_pair(fit_cursor, false);
+       }
+
+       bool full_metrics = flags & Update::Force;
+       if (flags & Update::MultiParSel)
+               full_metrics |= multiParSel();
+
+       bool const single_par = !full_metrics;
        updateMetrics(single_par);
 
-       // Don't forget to do check for fitCursor() and multiParSel().
-       fitCursor();
-       multiParSel();
+       if (flags & Update::FitCursor && fitCursor())
+               updateMetrics(false);
 
+       // tell the frontend to update the screen.
        return make_pair(true, single_par);
 }
 
@@ -476,6 +484,7 @@ void BufferView::scrollDocView(int value)
        t.redoParagraph(*this, anchor_ref_);
        int const h = t.getPar(anchor_ref_).height();
        offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
+       updateMetrics(false);
 }
 
 
@@ -644,7 +653,11 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        case LFUN_CHANGE_NEXT:
        case LFUN_ALL_CHANGES_ACCEPT:
        case LFUN_ALL_CHANGES_REJECT:
-               flag.enabled(buffer_); // FIXME: Change tracking (MG)
+               // TODO: context-sensitive enabling of LFUNs
+               // In principle, these command should only be enabled if there
+               // is a change in the document. However, without proper
+               // optimizations, this will inevitably result in poor performance.
+               flag.enabled(buffer_);
                break;
 
        case LFUN_BUFFER_TOGGLE_COMPRESSION: {
@@ -1374,7 +1387,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
 
        // Get absolute path of file and add ".lyx"
        // to the filename if necessary
-       filename = fileSearch(string(), filename, "lyx");
+       filename = fileSearch(string(), filename, "lyx").absFilename();
 
        docstring const disp_fn = makeDisplayPath(filename);
        // emit message signal.