]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Alfredo's second patch
[lyx.git] / src / text3.C
index df443501783cf32cd925ed1d6fe95c9f5070b7c3..3aa80b5bbdf3dd98cea6f4ed2102a5ed3faceda2 100644 (file)
@@ -43,6 +43,7 @@
 using std::endl;
 using std::find;
 using std::vector;
+using lyx::pos_type;
 
 extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
@@ -170,28 +171,29 @@ Inset * LyXText::checkInsetHit(int & x, int & y)
 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
                            string const & contents)
 {
-       LyXCursor res = cursor;
+       ParagraphList::iterator end = ownerParagraphs().end();
+       ParagraphList::iterator pit = cursor.par();
+       pos_type pos = cursor.pos();
+
        Inset * inset;
        do {
-               if (res.pos() < res.par()->size() - 1) {
-                       res.pos(res.pos() + 1);
+               if (pos + 1 < pit->size()) {
+                       ++pos;
                } else  {
-                       res.par(boost::next(res.par()));
-                       res.pos(0);
+                       ++pit;
+                       pos = 0;
                }
 
-       } while (res.par() != ownerParagraphs().end()&&
-                !(res.par()->isInset(res.pos())
-                  && (inset = res.par()->getInset(res.pos())) != 0
-                  && find(codes.begin(), codes.end(), inset->lyxCode())
-                  != codes.end()
-                  && (contents.empty() ||
-                      static_cast<InsetCommand *>(
-                                                       res.par()->getInset(res.pos()))->getContents()
-                      == contents)));
-
-       if (res.par() != ownerParagraphs().end()) {
-               setCursor(res.par(), res.pos(), false);
+       } while (pit != end &&
+                !(pit->isInset(pos) &&
+                  (inset = pit->getInset(pos)) != 0 &&
+                  find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
+                  (contents.empty() ||
+                   static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
+                   == contents)));
+
+       if (pit != end) {
+               setCursor(pit, pos, false);
                return true;
        }
        return false;
@@ -199,14 +201,15 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
 
 
 void LyXText::gotoInset(vector<Inset::Code> const & codes,
-                                 bool same_content)
+                       bool same_content)
 {
        bv()->hideCursor();
        bv()->beforeChange(this);
        update();
 
        string contents;
-       if (same_content && cursor.par()->isInset(cursor.pos())) {
+       if (same_content && cursor.pos() < cursor.par()->size()
+           && cursor.par()->isInset(cursor.pos())) {
                Inset const * inset = cursor.par()->getInset(cursor.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
@@ -216,7 +219,7 @@ void LyXText::gotoInset(vector<Inset::Code> const & codes,
        if (!gotoNextInset(codes, contents)) {
                if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
                        LyXCursor tmp = cursor;
-                       cursor.par(&*ownerParagraphs().begin());
+                       cursor.par(ownerParagraphs().begin());
                        cursor.pos(0);
                        if (!gotoNextInset(codes, contents)) {
                                cursor = tmp;
@@ -282,7 +285,7 @@ void LyXText::cursorPrevious()
        bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
        if (cursor.row() != rows().begin()) {
                LyXCursor cur;
-               setCursor(cur, &*boost::prior(cursor.row())->par(),
+               setCursor(cur, boost::prior(cursor.row())->par(),
                          boost::prior(cursor.row())->pos(), false);
                if (cur.y() > top_y()) {
                        cursorUp(true);
@@ -343,7 +346,7 @@ void LyXText::cursorNext()
        bv()->screen().draw(bv()->text, bv(), new_y);
        if (boost::next(cursor.row()) != rows().end()) {
                LyXCursor cur;
-               setCursor(cur, &*boost::next(cursor.row())->par(),
+               setCursor(cur, boost::next(cursor.row())->par(),
                          boost::next(cursor.row())->pos(), false);
                if (cur.y() < top_y() + bv()->workHeight()) {
                        cursorDown(true);
@@ -416,15 +419,15 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               setUndo(bv, Undo::EDIT, &*tmp, &*boost::next(tmp));
+                               setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
                                tmp->params().startOfAppendix(false);
                                int tmpy;
-                               setHeightOfRow(getRow(&*tmp, 0, tmpy));
+                               setHeightOfRow(getRow(tmp, 0, tmpy));
                                break;
                        }
                }
 
-               setUndo(bv, Undo::EDIT, &*pit, &*boost::next(pit));
+               setUndo(bv, Undo::EDIT, pit, boost::next(pit));
                pit->params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
@@ -915,6 +918,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_INSET_SETTINGS:
+               lyx::Assert(bv->theLockingInset());
+               bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
+               break;
+
        case LFUN_INSET_TOGGLE:
                bv->hideCursor();
                bv->beforeChange(this);
@@ -1279,7 +1287,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        Inset * tli = bv->theLockingInset();
                        LyXCursor cursor = bv->text->cursor;
                        LyXFont font = bv->text->getFont(bv->buffer(),
-                                                        &*cursor.par(), cursor.pos());
+                                                        cursor.par(), cursor.pos());
                        int width = tli->width(bv, font);
                        int inset_x = font.isVisibleRightToLeft()
                                ? cursor.ix() - width : cursor.ix();
@@ -1396,9 +1404,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
                        selection_possible = false;
                        bv->owner()->message(inset->editMessage());
-                       //inset->edit(bv, x, y, cmd.button());
                        // We just have to lock the inset before calling a PressEvent on it!
-                       // we don't need the edit() call here! (Jug20020329)
                        if (!bv->lockInset(inset))
                                lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
                        FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());