]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Fix bug 4166: Crash when middle button click on inset label
[lyx.git] / src / Text3.cpp
index 13e3669e8a1dd27c65c876574ea8b56762ea4f77..a34dde66e6b76d00fc33c389b092b1a0ebfc6ec6 100644 (file)
@@ -225,7 +225,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
        cur.clearSelection(); // bug 393
        cur.finishUndo();
        InsetText * insetText = dynamic_cast<InsetText *>(inset);
-       if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
+       if (insetText && (!insetText->allowMultiPar() || cur.lastpit() == 0)) {
                // reset first par to default
                cur.text()->paragraphs().begin()
                        ->setPlainOrDefaultLayout(bparams.documentClass());
@@ -238,9 +238,10 @@ static bool doInsertInset(Cursor & cur, Text * text,
        } else {
                cur.leaveInset(*inset);
                // reset surrounding par to default
-               docstring const layoutname = insetText->usePlainLayout()
-                       ? bparams.documentClass().plainLayoutName()
-                       : bparams.documentClass().defaultLayoutName();
+               DocumentClass const & dc = bparams.documentClass();
+               docstring const layoutname = inset->usePlainLayout()
+                       ? dc.plainLayoutName()
+                       : dc.defaultLayoutName();
                text->setLayout(cur, layoutname);
        }
 
@@ -1178,23 +1179,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        bv->cursor().finishUndo();
                        break;
 
-               case mouse_button::button3:
-                       if (cur.selection()) {
-                               DocIterator const selbeg = cur.selectionBegin();
-                               DocIterator const selend = cur.selectionEnd();
-                               Cursor tmpcur = cur;
-                               tm.setCursorFromCoordinates(tmpcur, cmd.x, cmd.y);
-                               // Don't do anything if we right-click a selection, a selection
-                               // context menu should popup instead.
-                               if (tmpcur < selbeg || tmpcur >= selend) {
-                                       cur.noUpdate();
-                                       return;
-                               }
+               case mouse_button::button3: {
+                       Cursor const & bvcur = cur.bv().cursor();
+                       // Don't do anything if we right-click a
+                       // selection, a context menu will popup.
+                       if (bvcur.selection() && cur >= bvcur.selectionBegin()
+                           && cur <= bvcur.selectionEnd()) {
+                               cur.noUpdate();
+                               return;
                        }
-                       if (!bv->mouseSetCursor(cur, false)) {
+                       if (!bv->mouseSetCursor(cur, false))
                                cur.updateFlags(Update::SinglePar | Update::FitCursor);
-                               break;                  
-                       }
+                       break;                  
+               }
+
                default:
                        break;
                } // switch (cmd.button())
@@ -1432,21 +1430,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_NOMENCL_INSERT: {
                InsetCommandParams p(NOMENCL_CODE);
-               if (cmd.argument().empty()) {
+               if (cmd.argument().empty())
                        p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
-                       string const data = InsetCommand::params2string("nomenclature", p);
-                       bv->showDialog("nomenclature", data);
-                       break;
-               }
-               // this back and forth checks the validity of the data
-               InsetCommand::string2params("nomenclature", to_utf8(cmd.argument()), p);
+               else
+                       p["symbol"] = cmd.argument();
                string const data = InsetCommand::params2string("nomenclature", p);
-               if (p["symbol"].empty() || p["description"].empty())
-                       bv->showDialog("nomenclature", data);
-               else {
-                       FuncRequest fr(LFUN_INSET_INSERT, data);
-                       dispatch(cur, fr);
-               }
+               bv->showDialog("nomenclature", data);   
                break;
        }
 
@@ -1988,6 +1977,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                code = INDEX_PRINT_CODE;
                break;
        case LFUN_NOMENCL_INSERT:
+               if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
+                       enable = false;
+                       break;
+               }
                code = NOMENCL_CODE;
                break;
        case LFUN_NOMENCL_PRINT:
@@ -1997,10 +1990,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                code = TOC_CODE;
                break;
        case LFUN_HYPERLINK_INSERT:
-               if (cur.selection() && 
-                   (cur.isMultiCell() ||
-                   cur.selBegin().pit() != cur.selEnd().pit())
-                        ) {
+               if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
                        enable = false;
                        break;
                }