]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
minimal effort implementation of:
[lyx.git] / src / text3.C
index 4a494ecd466867590e8a0f0eb46833f58adf02bf..8a7069b689ae78cb925f8af9fab2a61be65ea6d2 100644 (file)
@@ -29,6 +29,7 @@
 #include "CutAndPaste.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "errorlist.h"
 #include "factory.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -63,6 +64,7 @@
 #include "support/lyxlib.h"
 #include "support/convert.h"
 #include "support/lyxtime.h"
+#include "support/unicode.h"
 
 #include "mathed/math_hullinset.h"
 #include "mathed/math_macrotemplate.h"
 #include <clocale>
 #include <sstream>
 
+using lyx::char_type;
 using lyx::pos_type;
 
 using lyx::cap::copySelection;
 using lyx::cap::cutSelection;
+using lyx::cap::pasteParagraphList;
 using lyx::cap::pasteSelection;
 using lyx::cap::replaceSelection;
 
@@ -399,65 +403,21 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                finishChange(cur, false);
                break;
 
-       case LFUN_WORD_FORWARD:
-               if (!cur.mark())
-                       cur.clearSelection();
-               if (isRTL(cur.paragraph()))
-                       needsUpdate = cursorLeftOneWord(cur);
-               else
-                       needsUpdate = cursorRightOneWord(cur);
-               finishChange(cur, false);
-               break;
-
-       case LFUN_WORD_BACKWARD:
-               if (!cur.mark())
-                       cur.clearSelection();
-               if (isRTL(cur.paragraph()))
-                       needsUpdate = cursorRightOneWord(cur);
-               else
-                       needsUpdate = cursorLeftOneWord(cur);
-               finishChange(cur, false);
-               break;
-
        case LFUN_BUFFER_BEGIN:
-               if (cur.depth() == 1) {
-                       if (!cur.mark())
-                               cur.clearSelection();
-                       needsUpdate = cursorTop(cur);
-                       finishChange(cur, false);
-               } else {
-                       cur.undispatched();
-               }
-               break;
-
        case LFUN_BUFFER_BEGIN_SELECT:
+               cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
                if (cur.depth() == 1) {
-                       if (!cur.selection())
-                               cur.resetAnchor();
                        needsUpdate = cursorTop(cur);
-                       finishChange(cur, true);
                } else {
                        cur.undispatched();
                }
                break;
 
        case LFUN_BUFFER_END:
-               if (cur.depth() == 1) {
-                       if (!cur.mark())
-                               cur.clearSelection();
-                       needsUpdate = cursorBottom(cur);
-                       finishChange(cur, false);
-               } else {
-                       cur.undispatched();
-               }
-               break;
-
        case LFUN_BUFFER_END_SELECT:
+               cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
                if (cur.depth() == 1) {
-                       if (!cur.selection())
-                               cur.resetAnchor();
                        needsUpdate = cursorBottom(cur);
-                       finishChange(cur, true);
                } else {
                        cur.undispatched();
                }
@@ -525,83 +485,72 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_PARAGRAPH_UP:
-               if (!cur.mark())
-                       cur.clearSelection();
-               needsUpdate = cursorUpParagraph(cur);
-               finishChange(cur, false);
-               break;
-
        case LFUN_PARAGRAPH_UP_SELECT:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorUpParagraph(cur);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
+               needsUpdate = cursorUpParagraph(cur);
                break;
 
        case LFUN_PARAGRAPH_DOWN:
-               if (!cur.mark())
-                       cur.clearSelection();
-               needsUpdate = cursorDownParagraph(cur);
-               finishChange(cur, false);
-               break;
-
        case LFUN_PARAGRAPH_DOWN_SELECT:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorDownParagraph(cur);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
+               needsUpdate = cursorDownParagraph(cur);
                break;
 
+       case LFUN_SCREEN_UP:
        case LFUN_SCREEN_UP_SELECT:
                update(cur);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               needsUpdate = cursorPrevious(cur);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
+               if (cur.pit() == 0 && cur.textRow().pos() == 0) {
+                       cur.undispatched();
+                       cmd = FuncRequest(LFUN_FINISHED_UP);
+               } else {
+                       needsUpdate = cursorPrevious(cur);
+               }
                break;
 
+       case LFUN_SCREEN_DOWN:
        case LFUN_SCREEN_DOWN_SELECT:
                update(cur);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               needsUpdate = cursorNext(cur);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
+               if (cur.pit() == cur.lastpit()
+                         && cur.textRow().endpos() == cur.lastpos()) {
+                       cur.undispatched();
+                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
+               } else {
+                       needsUpdate = cursorNext(cur);
+               }
                break;
 
+       case LFUN_LINE_BEGIN:
        case LFUN_LINE_BEGIN_SELECT:
                update(cur);
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
                needsUpdate = cursorHome(cur);
-               finishChange(cur, true);
                break;
 
+       case LFUN_LINE_END:
        case LFUN_LINE_END_SELECT:
                update(cur);
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
                needsUpdate = cursorEnd(cur);
-               finishChange(cur, true);
                break;
 
+       case LFUN_WORD_FORWARD:
        case LFUN_WORD_FORWARD_SELECT:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
                if (isRTL(cur.paragraph()))
-                       cursorLeftOneWord(cur);
+                       needsUpdate = cursorLeftOneWord(cur);
                else
-                       cursorRightOneWord(cur);
-               finishChange(cur, true);
+                       needsUpdate = cursorRightOneWord(cur);
                break;
 
+       case LFUN_WORD_BACKWARD:
        case LFUN_WORD_BACKWARD_SELECT:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
                if (isRTL(cur.paragraph()))
-                       cursorRightOneWord(cur);
+                       needsUpdate = cursorRightOneWord(cur);
                else
-                       cursorLeftOneWord(cur);
-               finishChange(cur, true);
+                       needsUpdate = cursorLeftOneWord(cur);
                break;
 
        case LFUN_WORD_SELECT: {
@@ -610,47 +559,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_SCREEN_UP:
-               update(cur);
-               if (!cur.mark())
-                       cur.clearSelection();
-               finishChange(cur, false);
-               if (cur.pit() == 0 && cur.textRow().pos() == 0) {
-                       cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-               } else {
-                       needsUpdate = cursorPrevious(cur);
-               }
-               break;
-
-       case LFUN_SCREEN_DOWN:
-               update(cur);
-               if (!cur.mark())
-                       cur.clearSelection();
-               finishChange(cur, false);
-               if (cur.pit() == cur.lastpit()
-                         && cur.textRow().endpos() == cur.lastpos()) {
-                       cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               } else {
-                       needsUpdate = cursorNext(cur);
-               }
-               break;
-
-       case LFUN_LINE_BEGIN:
-               if (!cur.mark())
-                       cur.clearSelection();
-               needsUpdate = cursorHome(cur);
-               finishChange(cur, false);
-               break;
-
-       case LFUN_LINE_END:
-               if (!cur.mark())
-                       cur.clearSelection();
-               needsUpdate = cursorEnd(cur);
-               finishChange(cur, false);
-               break;
-
        case LFUN_BREAK_LINE: {
                // Not allowed by LaTeX (labels or empty par)
                if (cur.pos() > cur.paragraph().beginOfBody()) {
@@ -801,32 +709,39 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INSET_SETTINGS:
-               cur.inset().showInsetDialog(bv);
-               break;
-
-       case LFUN_NEXT_INSET_TOGGLE: {
-               InsetBase * inset = cur.nextInset();
-               // this is the real function we want to invoke
-               cmd = FuncRequest(LFUN_INSET_TOGGLE);
-               cur.undispatched();
-               // if there is an inset at cursor, see whether it
-               // wants to toggle.
-               if (inset) {
-                       LCursor tmpcur = cur;
-                       tmpcur.pushLeft(*inset);
-                       inset->dispatch(tmpcur, cmd);
-                       if (tmpcur.result().dispatched()) {
-                               cur.clearSelection();
-                               cur.dispatched();
-                       }
+       case LFUN_INSET_DISSOLVE: {
+               recordUndoInset(cur);
+               cur.selHandle(false);
+               // save position
+               lyx::pos_type spos = cur.pos();
+               lyx::pit_type spit = cur.pit();
+               ParagraphList plist;
+               if (cur.lastpit() != 0 || cur.lastpos() != 0) 
+                       plist = paragraphs();
+               cur.popLeft();
+               // store cursor offset
+               if (spit == 0)
+                       spos += cur.pos();
+               spit += cur.pit();
+               cur.paragraph().erase(cur.pos());
+               if (!plist.empty()) {
+                       Buffer * b = bv->buffer();
+                       pasteParagraphList(cur, plist, b->params().textclass, 
+                                          b->errorList("Paste"));
+                       // restore position
+                       cur.pit() = std::min(cur.lastpit(), spit);
+                       cur.pos() = std::min(cur.lastpos(), spos);
                }
-               // if it did not work, try the underlying inset.
-               if (!cur.result().dispatched())
-                       cur.inset().dispatch(cur, cmd);
+               cur.clearSelection();
+               cur.resetAnchor();
+               needsUpdate = true;
                break;
        }
 
+       case LFUN_INSET_SETTINGS:
+               cur.inset().showInsetDialog(bv);
+               break;
+
        case LFUN_SPACE_INSERT:
                if (cur.paragraph().layout()->free_spacing)
                        insertChar(cur, ' ');
@@ -877,9 +792,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.message(_("Paste"));
                lyx::cap::replaceSelection(cur);
                if (isStrUnsignedInt(cmd.argument))
-                       pasteSelection(cur, convert<unsigned int>(cmd.argument));
+                       pasteSelection(cur, bv->buffer()->errorList("Paste"),
+                       convert<unsigned int>(cmd.argument));
                else
-                       pasteSelection(cur, 0);
+                       pasteSelection(cur, bv->buffer()->errorList("Paste"),
+                       0);
+               bv->buffer()->errors("Paste");
                cur.clearSelection(); // bug 393
                bv->switchKeyMap();
                finishUndo();
@@ -1176,11 +1094,20 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.clearSelection();
                LyXFont const old_font = real_current_font;
 
+#if 0
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
                for (; cit != end; ++cit)
                        bv->owner()->getIntl().getTransManager().
                                translateAndInsert(*cit, this);
+#else
+               std::vector<char> in(cmd.argument.begin(), cmd.argument.end());
+               std::vector<boost::uint32_t> const res = utf8_to_ucs4(in);
+               std::vector<boost::uint32_t>::const_iterator cit = res.begin();
+               std::vector<boost::uint32_t>::const_iterator end = res.end();
+               for (; cit != end; ++cit)
+                       insertChar(bv->cursor(), *cit);
+#endif
 
                cur.resetAnchor();
                moveCursor(cur, false);
@@ -1558,15 +1485,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INSET_DIALOG_SHOW: {
-               InsetBase * inset = cur.nextInset();
-               if (inset) {
-                       FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
-                       inset->dispatch(cur, fr);
-               }
-               break;
-       }
-
        case LFUN_ESCAPE:
                if (cur.selection()) {
                        cur.selection() = false;
@@ -1765,25 +1683,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
                        code = InsetBase::SPACE_CODE;
                break;
 
-#ifdef WITH_WARNINGS
-#warning This LFUN is not used anymore and should be nuked (JMarc 29/10/2005)
-#endif
-#if 0
-       case LFUN_INSET_DIALOG_SHOW: {
-               InsetBase * inset = cur.nextInset();
-               enable = inset;
-               if (inset) {
-                       code = inset->lyxCode();
-                       if (!(code == InsetBase::INCLUDE_CODE
-                               || code == InsetBase::BIBTEX_CODE
-                               || code == InsetBase::FLOAT_LIST_CODE
-                               || code == InsetBase::TOC_CODE))
-                               enable = false;
-               }
-               break;
-       }
-#endif
-
        case LFUN_INSET_MODIFY:
                // We need to disable this, because we may get called for a
                // tabular cell via
@@ -1835,6 +1734,11 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
                break;
        }
 
+       case LFUN_INSET_DISSOLVE: {
+               enable = &cur.inset() && cur.inTexted();
+               break;
+       }
+
        case LFUN_WORD_DELETE_FORWARD:
        case LFUN_WORD_DELETE_BACKWARD:
        case LFUN_LINE_DELETE:
@@ -1873,7 +1777,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_BREAK_PARAGRAPH_SKIP:
        case LFUN_PARAGRAPH_SPACING:
        case LFUN_INSET_INSERT:
-       case LFUN_NEXT_INSET_TOGGLE:
        case LFUN_WORD_UPCASE:
        case LFUN_WORD_LOWCASE:
        case LFUN_WORD_CAPITALIZE: