]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
EmbeddedObjects.lyx, Math.lyx, UserGuide.lyx: Spanish translation updates by Ignacio
[lyx.git] / src / BufferView.cpp
index b463778ef31567e31ec08a0b7a50da8be749f9be..06a677c64a94f078591849ba0873487018f228a6 100644 (file)
@@ -150,11 +150,13 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
 
        if (!findNextInset(tmpdit, codes, contents)) {
                if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
-                       tmpdit  = doc_iterator_begin(tmpdit.bottom().inset());
+                       Inset * inset = &tmpdit.bottom().inset();
+                       tmpdit = doc_iterator_begin(&inset->buffer(), inset);
                        if (!findNextInset(tmpdit, codes, contents))
                                return false;
-               } else
+               } else {
                        return false;
+               }
        }
 
        dit = tmpdit;
@@ -272,11 +274,13 @@ struct BufferView::Private
 
 
 BufferView::BufferView(Buffer & buf)
-       : width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this))
+       : width_(0), height_(0), full_screen_(false), buffer_(buf),
+      d(new Private(*this))
 {
        d->xsel_cache_.set = false;
        d->intl_.initKeyMapper(lyxrc.use_kbmap);
 
+       d->cursor_.setBuffer(&buf);
        d->cursor_.push(buffer_.inset());
        d->cursor_.resetAnchor();
        d->cursor_.setCurrentFont();
@@ -564,7 +568,7 @@ void BufferView::scrollDocView(int value)
 
        // cut off at the top
        if (value <= d->scrollbarParameters_.min) {
-               DocIterator dit = doc_iterator_begin(buffer_.inset());
+               DocIterator dit = doc_iterator_begin(&buffer_);
                showCursor(dit);
                LYXERR(Debug::SCROLLING, "scroll to top");
                return;
@@ -572,7 +576,7 @@ void BufferView::scrollDocView(int value)
 
        // cut off at the bottom
        if (value >= d->scrollbarParameters_.max) {
-               DocIterator dit = doc_iterator_end(buffer_.inset());
+               DocIterator dit = doc_iterator_end(&buffer_);
                dit.backwardPos();
                showCursor(dit);
                LYXERR(Debug::SCROLLING, "scroll to bottom");
@@ -596,7 +600,7 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-       DocIterator dit = doc_iterator_begin(buffer_.inset());
+       DocIterator dit = doc_iterator_begin(&buffer_);
        dit.pit() = i;
        LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
        showCursor(dit);
@@ -724,7 +728,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
        // it will be restored to the left of the outmost inset that contains
        // the bookmark.
        if (bottom_pit < int(buffer_.paragraphs().size())) {
-               dit = doc_iterator_begin(buffer_.inset());
+               dit = doc_iterator_begin(&buffer_);
                                
                dit.pit() = bottom_pit;
                dit.pos() = min(bottom_pos, dit.paragraph().size());
@@ -897,6 +901,15 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                flag.setEnabled(! this->cursor().inRegexped());
                break;
 
+       case LFUN_COPY_LABEL_AS_REF: {
+               // if there is an inset at cursor, see whether it
+               // handles the lfun, other start from scratch
+               Inset * inset = cur.nextInset();
+               if (!inset || !inset->getStatus(cur, cmd, flag))
+                       flag = lyx::getStatus(cmd);
+               break;
+       }
+
        case LFUN_NEXT_INSET_TOGGLE: 
        case LFUN_NEXT_INSET_MODIFY: {
                // this is the real function we want to invoke
@@ -1065,16 +1078,14 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                docstring label = cmd.argument();
                if (label.empty()) {
                        InsetRef * inset =
-                               getInsetByCode<InsetRef>(d->cursor_,
-                                                        REF_CODE);
+                               getInsetByCode<InsetRef>(d->cursor_, REF_CODE);
                        if (inset) {
                                label = inset->getParam("reference");
                                // persistent=false: use temp_bookmark
                                saveBookmark(0);
                        }
                }
-
-               if (!label.empty())
+               if (!label.empty())
                        gotoLabel(label);
                break;
        }
@@ -1301,8 +1312,8 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                        from = cur.selectionBegin();
                        to = cur.selectionEnd();
                } else {
-                       from = doc_iterator_begin(buffer_.inset());
-                       to = doc_iterator_end(buffer_.inset());
+                       from = doc_iterator_begin(&buffer_);
+                       to = doc_iterator_end(&buffer_);
                }
                int const words = countWords(from, to);
                int const chars = countChars(from, to, false);
@@ -1338,7 +1349,20 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // turn compression on/off
                buffer_.params().compressed = !buffer_.params().compressed;
                break;
-       
+       case LFUN_COPY_LABEL_AS_REF: {
+               // if there is an inset at cursor, try to copy it
+               Inset * inset = cur.nextInset();
+               if (inset) {
+                       FuncRequest tmpcmd = cmd;
+                       inset->dispatch(cur, tmpcmd);
+               }
+               if (!cur.result().dispatched())
+                       // It did not work too; no action needed.
+                       break;
+               cur.clearSelection();
+               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               break;
+       }
        case LFUN_NEXT_INSET_TOGGLE: {
                // create the the real function we want to invoke
                FuncRequest tmpcmd = cmd;
@@ -1475,7 +1499,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
                FuncRequest fr(LFUN_INSET_TOGGLE, action);
 
-               Inset & inset = cur.buffer().inset();
+               Inset & inset = cur.buffer()->inset();
                InsetIterator it  = inset_iterator_begin(inset);
                InsetIterator const end = inset_iterator_end(inset);
                for (; it != end; ++it) {
@@ -1787,15 +1811,22 @@ bool BufferView::setCursorFromInset(Inset const * inset)
 
 void BufferView::gotoLabel(docstring const & label)
 {
-       Toc & toc = buffer().tocBackend().toc("label");
-       TocIterator toc_it = toc.begin();
-       TocIterator end = toc.end();
-       for (; toc_it != end; ++toc_it) {
-               if (label == toc_it->str())
-                       dispatch(toc_it->action());
+       std::vector<Buffer const *> bufs = buffer().allRelatives();
+       std::vector<Buffer const *>::iterator it = bufs.begin();
+       for (; it != bufs.end(); ++it) {
+               Buffer const * buf = *it;
+
+               // find label
+               Toc & toc = buf->tocBackend().toc("label");
+               TocIterator toc_it = toc.begin();
+               TocIterator end = toc.end();
+               for (; toc_it != end; ++toc_it) {
+                       if (label == toc_it->str()) {
+                               dispatch(toc_it->action());
+                               return;
+                       }
+               }
        }
-       //FIXME: We could do a bit more searching thanks to this:
-       //InsetLabel const * inset = buffer_.insetLabel(label);
 }
 
 
@@ -2191,10 +2222,11 @@ Point BufferView::coordOffset(DocIterator const & dit, bool boundary) const
 
 Point BufferView::getPos(DocIterator const & dit, bool boundary) const
 {
+       if (!paragraphVisible(dit))
+               return Point(-1, -1);
+
        CursorSlice const & bot = dit.bottom();
        TextMetrics const & tm = textMetrics(bot.text());
-       if (!tm.contains(bot.pit()))
-               return Point(-1, -1);
 
        Point p = coordOffset(dit, boundary); // offset from outer paragraph
        p.y_ += tm.parMetrics(bot.pit()).position();
@@ -2202,6 +2234,15 @@ Point BufferView::getPos(DocIterator const & dit, bool boundary) const
 }
 
 
+bool BufferView::paragraphVisible(DocIterator const & dit) const
+{
+       CursorSlice const & bot = dit.bottom();
+       TextMetrics const & tm = textMetrics(bot.text());
+
+       return tm.contains(bot.pit());
+}
+
+
 void BufferView::draw(frontend::Painter & pain)
 {
        if (height_ == 0 || width_ == 0)