]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Minimal fix needed to give Qt a label dialog again.
[lyx.git] / src / text3.C
index a24e28d625c444cbdc2cd17bf48c44eafda7ffa6..d7d588311745e93c0af9c17716cae87facd5355f 100644 (file)
@@ -31,7 +31,6 @@
 #include "frontends/Dialogs.h"
 #include "insets/insetspecialchar.h"
 #include "insets/insettext.h"
-#include "insets/insetbib.h"
 #include "insets/insetquotes.h"
 #include "insets/insetcommand.h"
 #include "undo_funcs.h"
@@ -59,12 +58,12 @@ namespace {
 
                if (selecting || lt->selection.mark()) {
                        lt->setSelection(bv);
-                       if (lt->bv_owner)
+                       if (lt->isTopLevel())
                                bv->toggleToggle();
                        else
                                bv->updateInset(lt->inset_owner, false);
                }
-               if (lt->bv_owner) {
+               if (lt->isTopLevel()) {
                        //if (fitcur)
                        //      bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
                        //else
@@ -362,6 +361,7 @@ void LyXText::update(BufferView * bv, bool changed)
                bv->update(this, c);
 }
 
+namespace {
 
 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 {
@@ -375,6 +375,31 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 }
 
 
+void doInsertInset(LyXText * lt, FuncRequest const & cmd,
+                  bool edit, bool pastesel)
+{
+       Inset * inset = createInset(cmd);
+       BufferView * bv = cmd.view();
+
+       if (inset) {
+               bool gotsel = false;
+               if (lt->selection.set()) {
+                       lt->cutSelection(bv, true, false);
+                       gotsel = true;
+               }
+               if (bv->insertInset(inset)) {
+                       if (edit)
+                               inset->edit(bv);
+                       if (gotsel && pastesel)
+                               bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
+               }
+               else
+                       delete inset;
+       }
+}
+
+}
+
 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
@@ -970,7 +995,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_UPCASE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_uppercase);
+               changeCase(*bv, LyXText::text_uppercase);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -978,7 +1003,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_LOWCASE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_lowercase);
+               changeCase(*bv, LyXText::text_lowercase);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -986,7 +1011,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_CAPITALIZE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_capitalization);
+               changeCase(*bv, LyXText::text_capitalization);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -1029,7 +1054,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BEGINNINGBUFSEL:
                if (inset_owner)
-                       return Inset::UNDISPATCHED;
+                       return UNDISPATCHED;
                update(bv, false);
                cursorTop(bv);
                finishChange(bv, true);
@@ -1037,7 +1062,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_ENDBUFSEL:
                if (inset_owner)
-                       return Inset::UNDISPATCHED;
+                       return UNDISPATCHED;
                update(bv, false);
                cursorBottom(bv);
                finishChange(bv, true);
@@ -1215,10 +1240,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_MOUSE_TRIPLE:
                if (!bv->buffer())
                        break;
-               if (bv_owner && bv->theLockingInset())
+               if (isTopLevel() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (bv_owner) {
+                       if (isTopLevel()) {
                                bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                        }
@@ -1226,7 +1251,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        selection.cursor = cursor;
                        cursorEnd(bv);
                        setSelection(bv);
-                       if (bv_owner)
+                       if (isTopLevel())
                                bv->screen().toggleSelection(this, bv, false);
                        update(bv, false);
                        bv->haveSelection(selection.set());
@@ -1236,10 +1261,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_MOUSE_DOUBLE:
                if (!bv->buffer())
                        break;
-               if (bv_owner && bv->theLockingInset())
+               if (isTopLevel() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (bv_owner) {
+                       if (isTopLevel()) {
                                bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                                selectWord(bv, LyXText::WHOLE_WORD_STRICT);
@@ -1512,7 +1537,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        } else {
                                FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
                                inset_hit->localDispatch(cmd1);
-                               // IMO this is a grosshack! Inset's should be changed so that
+                               // IMO this is a gross hack! Insets should be changed so that
                                // they call the actions they have to do with the insetButtonRel.
                                // function and not in the edit(). This should be changed
                                // (Jug 20020329)
@@ -1524,17 +1549,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               // Maybe we want to edit a bibitem ale970302
-               if (bv->text->cursor.par()->bibkey) {
-                       bool const is_rtl =
-                               bv->text->cursor.par()->isRightToLeftPar(bv->buffer()->params);
-                       int const width =
-                               bibitemMaxWidth(bv, bv->buffer()->params.getLyXTextClass().defaultfont());
-                       if ((is_rtl && x > bv->text->workWidth(bv)-20-width) ||
-                                       (!is_rtl && x < 20 + width)) {
-                               bv->text->cursor.par()->bibkey->edit(bv, 0, 0, mouse_button::none);
-                       }
-               }
                break;
        }
 
@@ -1578,13 +1592,15 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_HTMLURL: {
                InsetCommandParams p("htmlurl");
-               bv->owner()->getDialogs().createUrl(p.getAsString());
+               string const data = InsetCommandMailer::params2string("url", p);
+               bv->owner()->getDialogs().show("url", data, 0);
                break;
        }
 
        case LFUN_URL: {
                InsetCommandParams p("url");
-               bv->owner()->getDialogs().createUrl(p.getAsString());
+               string const data = InsetCommandMailer::params2string("url", p);
+               bv->owner()->getDialogs().show("url", data, 0);
                break;
        }
 
@@ -1592,12 +1608,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 #if 0
        case LFUN_INSET_LIST:
        case LFUN_INSET_THEOREM:
+       case LFUN_INSET_CAPTION:
 #endif
        case LFUN_INSERT_NOTE:
-       case LFUN_INSERT_URL:
-       case LFUN_INSET_CAPTION:
+       case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
-       case LFUN_INSET_EXTERNAL:
        case LFUN_INSET_FLOAT:
        case LFUN_INSET_FOOTNOTE:
        case LFUN_INSET_MARGINAL:
@@ -1606,33 +1621,28 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INSET_WIDE_FLOAT:
        case LFUN_INSET_WRAP:
        case LFUN_TABULAR_INSERT:
+               // Open the inset, and move the current selection
+               // inside it.
+               doInsertInset(this, cmd, true, true);
+               break;
+
+       case LFUN_INSERT_URL:
+       case LFUN_INSET_EXTERNAL:
        case LFUN_INDEX_INSERT:
+               // Just open the inset
+               doInsertInset(this, cmd, true, false);
+               break;
+
        case LFUN_INDEX_PRINT:
        case LFUN_PARENTINSERT:
        case LFUN_TOC_INSERT:
-       {
-               Inset * inset = createInset(cmd);
-               if (inset) {
-                       bool gotsel = false;
-                       if (selection.set()) {
-                               cutSelection(bv, true, false);
-                               gotsel = true;
-                       }
-                       if (bv->insertInset(inset)) {
-                               inset->edit(bv);
-                               if (gotsel)
-                                       bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
-                       }
-                       else
-                               delete inset;
-               }
+               // do nothing fancy
+               doInsertInset(this, cmd, false, false);
                break;
-       }
-
 
        default:
-               return Inset::UNDISPATCHED;
+               return UNDISPATCHED;
        }
 
-       return Inset::DISPATCHED;
+       return DISPATCHED;
 }