]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / Text3.cpp
index ff2f7636af1f467fad6d2f8779c17076ae3c9009..1d3f0e30dff6d41d3ef1c8ceca73660ffbba5566 100644 (file)
@@ -396,10 +396,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                Paragraph & par = cur.paragraph();
                bool start = !par.params().startOfAppendix();
 
-#ifdef WITH_WARNINGS
-#warning The code below only makes sense at top level.
+// FIXME: The code below only makes sense at top level.
 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
-#endif
                // ensure that we have only one start_of_appendix in this document
                // FIXME: this don't work for multipart document!
                for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
@@ -655,9 +653,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_DELETE_BACKWARD_SKIP:
                // Reverse the effect of LFUN_BREAK_PARAGRAPH_SKIP.
                if (!cur.selection()) {
-#ifdef WITH_WARNINGS
-#warning look here
-#endif
+                       // FIXME: look here
                        //CursorSlice cur = cursor();
                        backspace(cur);
                        //anchor() = cur;
@@ -755,6 +751,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                dispatch(cur, fr);
                        }
                        */
+                       if (cur.selection())
+                               cutSelection(cur, true, false);
                        insertInset(cur, inset);
                        cur.posRight();
                }
@@ -985,14 +983,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_DATE_INSERT:
-               if (cmd.argument().empty())
-                       lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
-                               formatted_time(current_time())));
-               else
-                       lyx::dispatch(FuncRequest(LFUN_SELF_INSERT,
-                               formatted_time(current_time(), to_utf8(cmd.argument()))));
+       case LFUN_DATE_INSERT: {
+               string const format = cmd.argument().empty()
+                       ? lyxrc.date_insert_format : to_utf8(cmd.argument());
+               string const time = formatted_time(current_time(), format);
+               lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, time));
                break;
+       }
 
        case LFUN_MOUSE_TRIPLE:
                if (cmd.button() == mouse_button::button1) {
@@ -1017,38 +1014,30 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.button() == mouse_button::button3)
                        cur.clearSelection();
 
-               // Middle button press pastes if we have a selection
-               // We do this here as if the selection was inside an inset
-               // it could get cleared on the unlocking of the inset so
-               // we have to check this first
-               bool paste_internally = false;
-               if (cmd.button() == mouse_button::button2 && cap::selection()) {
-                       // Copy the selection buffer to the clipboard
-                       // stack, because we want it to appear in the
-                       // "Edit->Paste recent" menu.
-                       cap::copySelectionToStack();
-                       paste_internally = true;
-               }
+               // Set the cursor
+               bool update = bv->mouseSetCursor(cur);
 
                // Insert primary selection with middle mouse
                // if there is a local selection in the current buffer,
                // insert this
                if (cmd.button() == mouse_button::button2) {
-                       if (paste_internally) {
-                               cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
+                       if (cap::selection()) {
+                               // Copy the selection buffer to the clipboard
+                               // stack, because we want it to appear in the
+                               // "Edit->Paste recent" menu.
+                               cap::copySelectionToStack();
+
+                               cap::pasteSelection(bv->cursor(), 
+                                                   bv->buffer()->errorList("Paste"));
                                bv->buffer()->errors("Paste");
-                               cur.clearSelection(); // bug 393
                                bv->buffer()->markDirty();
                                finishUndo();
                        } else {
-                               bv->mouseSetCursor(cur);
                                lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
                        }
                }
 
-               // we have to update after dePM triggered
-               bool update = bv->mouseSetCursor(cur);
-
+               // we have to update after dEPM triggered
                if (!update && cmd.button() == mouse_button::button1) {
                        needsUpdate = false;
                        cur.noUpdate();
@@ -1157,15 +1146,39 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_URL_INSERT: {
                InsetCommandParams p("url");
+               docstring content;
+               if (cur.selection()) {
+                       content = cur.selectionAsString(false);
+                       cutSelection(cur, true, false);
+               }
+               p["target"] = (cmd.argument().empty()) ?
+                       content : cmd.argument();
                string const data = InsetCommandMailer::params2string("url", p);
-               bv->showInsetDialog("url", data, 0);
+               if (p["target"].empty()) {
+                       bv->showInsetDialog("url", data, 0);
+               } else {
+                       FuncRequest fr(LFUN_INSET_INSERT, data);
+                       dispatch(cur, fr);
+               }
                break;
        }
 
        case LFUN_HTML_INSERT: {
                InsetCommandParams p("htmlurl");
+               docstring content;
+               if (cur.selection()) {
+                       content = cur.selectionAsString(false);
+                       cutSelection(cur, true, false);
+               }
+               p["target"] = (cmd.argument().empty()) ?
+                       content : cmd.argument();
                string const data = InsetCommandMailer::params2string("url", p);
-               bv->showInsetDialog("url", data, 0);
+               if (p["target"].empty()) {
+                       bv->showInsetDialog("url", data, 0);
+               } else {
+                       FuncRequest fr(LFUN_INSET_INSERT, data);
+                       dispatch(cur, fr);
+               }
                break;
        }
 
@@ -1502,9 +1515,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FLOAT_LIST: {
                TextClass const & tclass = bv->buffer()->params().getTextClass();
                if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
-                       // not quite sure if we want this...
                        recordUndo(cur);
-                       cur.clearSelection();
+                       if (cur.selection())
+                               cutSelection(cur, true, false);
                        breakParagraph(cur);
 
                        if (cur.lastpos() != 0) {