]> git.lyx.org Git - lyx.git/commitdiff
more stuff (sorry no changelog)
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 15 Jun 2000 15:44:39 +0000 (15:44 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 15 Jun 2000 15:44:39 +0000 (15:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@815 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/insets/ExternalTemplate.C
src/insets/ExternalTemplate.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/lyxtext.h
src/text2.C

index ac40f726276e3f23ea41c54c4718cbcc0b94a541..61f26c0ead0ed88f77e78165c2d831ed8b32c0f7 100644 (file)
@@ -571,7 +571,7 @@ void BufferView::pasteEnvironment()
 void BufferView::copy()
 {
        if (available()) {
-               text->CopySelection(buffer());
+               text->CopySelection(this);
                // clear the selection, even if mark_set
                toggleSelection();
                text->ClearSelection();
index 9637544a7cf95ba57aa99c179baf58694a31eb3f..906cd9ad7913e025d2e230c903973f3f71ceab18 100644 (file)
@@ -35,6 +35,7 @@ ExternalTemplate::ExternalTemplate()
        : viewCommand("true"), editCommand("true")
 {}
 
+
 ExternalTemplate::FormatTemplate::FormatTemplate()
        : updateCommand("true") {}
 
@@ -97,6 +98,7 @@ void ExternalTemplate::dumpFormats(ostream & os) const
        for_each(formats.begin(), formats.end(), dumpFormat(os));
 }
 
+
 void ExternalTemplateManager::dumpTemplates() const 
 {
        for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
index 9b5566cb283091712f6506f5c0a21f3e195589cb..b9b0ae749a9cafecbd8964c2399cc20b1007220b 100644 (file)
@@ -65,6 +65,7 @@ struct ExternalTemplate {
                
 };
 
+
 /**
  * A singleton class that manages the external inset templates
  */
index 9e64a5e12721ca4d583676fdbc2ad6bbcb621265..1747cb6132f1e5b00a41927c0c2ee74e547e026d 100644 (file)
 
 using std::endl;
 
+
 InsetExternal::InsetExternal() 
        : form_external(0)
 {
        tempname = TmpFileName();
 }
 
-InsetExternal::~InsetExternal() {
+
+InsetExternal::~InsetExternal()
+{
        remove(tempname.c_str());
 }
 
 
-extern "C" void ExternalTemplateCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalTemplateCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::templateCB(ob, data);
 }
 
 
-extern "C" void ExternalBrowseCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalBrowseCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::browseCB(ob, data);
 }
 
 
-extern "C" void ExternalEditCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalEditCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::editCB(ob, data);
 }
 
 
-extern "C" void ExternalViewCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalViewCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::viewCB(ob, data);
 }
 
 
-extern "C" void ExternalUpdateCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalUpdateCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::updateCB(ob, data);
 }
 
 
-extern "C" void ExternalOKCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalOKCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::okCB(ob, data);
 }
 
 
-extern "C" void ExternalCancelCB(FL_OBJECT * ob, long data)
+extern "C"
+void ExternalCancelCB(FL_OBJECT * ob, long data)
 {
        InsetExternal::cancelCB(ob, data);
 }
@@ -200,21 +210,22 @@ void InsetExternal::doApply(BufferView * bufview)
 {
        bool update = false;
        if (templatename != getCurrentTemplate()) {
-       templatename = getCurrentTemplate();
+               templatename = getCurrentTemplate();
                update = true;
        }
        if (filename != fl_get_input(form_external->filename)) {
-       filename = fl_get_input(form_external->filename);
+               filename = fl_get_input(form_external->filename);
                update = true;
        }
        if (parameters != fl_get_input(form_external->parameters)) {
-       parameters = fl_get_input(form_external->parameters);
+               parameters = fl_get_input(form_external->parameters);
                update = true;
        }
 
        if (update) {
-               // The text might have change, so we should update the button look
-       bufview->updateInset(this, true);
+               // The text might have change,
+               // so we should update the button look
+               bufview->updateInset(this, true);
        }
 }
 
@@ -224,7 +235,7 @@ void InsetExternal::cancelCB(FL_OBJECT * ob, long)
        Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
 
        InsetExternal * inset = holder->inset;
-       //      BufferView * bv = holder->view;
+       // BufferView * bv = holder->view;
 
        if (inset->form_external) {
                fl_hide_form(inset->form_external->form_external);
@@ -234,7 +245,7 @@ void InsetExternal::cancelCB(FL_OBJECT * ob, long)
 }
 
 
-const char * InsetExternal::EditMessage() const
+char const * InsetExternal::EditMessage() const
 {
        ExternalTemplate const & et = getTemplate(templatename);
        return doSubstitution(0, et.guiName).c_str();
@@ -262,7 +273,8 @@ void InsetExternal::Edit(BufferView * bv,
        fl_set_input(form_external->filename, filename.c_str());
        fl_set_input(form_external->parameters, parameters.c_str());
        if (!templatename.empty()) {
-               fl_set_choice(form_external->templatechoice, getTemplateNumber(templatename));
+               fl_set_choice(form_external->templatechoice,
+                             getTemplateNumber(templatename));
        }
        // Update the help text
        templateCB(form_external->templatechoice, 0);
@@ -311,21 +323,33 @@ void InsetExternal::Read(Buffer const *, LyXLex & lex)
        lyxerr << templatename << " " << filename << " " << parameters << endl;
 }
 
-int InsetExternal::write(string const & format, Buffer const * buf, 
-                        std::ostream & os) const {
+
+int InsetExternal::write(string const & format,
+                        Buffer const * buf, std::ostream & os) const
+{
        ExternalTemplate const & et = getTemplate(templatename);
        ExternalTemplate::Formats::const_iterator cit =
                et.formats.find(format);
+       if (cit == et.formats.end()) {
+               lyxerr << "External template format '" << format
+                      << "' not specified in template " << templatename
+                      << endl;
+               return 0;
+       }
+       
        if (et.automaticProduction) {
-               executeCommand(doSubstitution(buf, (*cit).second.updateCommand), buf);
+               executeCommand(doSubstitution(buf,
+                                             (*cit).second.updateCommand),
+                              buf);
        }
        
        os << doSubstitution(buf, (*cit).second.product);
        return 0; // CHECK
-       
 }
 
-int InsetExternal::Latex(Buffer const * buf, std::ostream & os, bool, bool) const
+
+int InsetExternal::Latex(Buffer const * buf,
+                        std::ostream & os, bool, bool) const
 {
        return write("LaTeX", buf, os);
 }
@@ -354,6 +378,10 @@ void InsetExternal::Validate(LaTeXFeatures & features) const
        ExternalTemplate const & et = getTemplate(templatename);
        ExternalTemplate::Formats::const_iterator cit =
                et.formats.find("LaTeX");
+       if (cit == et.formats.end()) {
+               return;
+       }
+       
        if (!(*cit).second.requirement.empty()) {
                features.require((*cit).second.requirement);
        }
@@ -389,7 +417,12 @@ void InsetExternal::doUpdate(BufferView const * bv) const
        ExternalTemplate const & et = getTemplate(getCurrentTemplate());
        ExternalTemplate::Formats::const_iterator cit =
                et.formats.find("LaTeX");
-       executeCommand(doSubstitution(bv->buffer(), (*cit).second.updateCommand), bv->buffer());
+       if (cit == et.formats.end())
+               return;
+       
+       executeCommand(doSubstitution(bv->buffer(),
+                                     (*cit).second.updateCommand),
+                      bv->buffer());
 }
 
 
@@ -397,7 +430,8 @@ void InsetExternal::doView(BufferView const * bv) const
 {
        automaticUpdate(bv);
        ExternalTemplate const & et = getTemplate(getCurrentTemplate());
-       executeCommand(doSubstitution(bv->buffer(), et.viewCommand), bv->buffer());
+       executeCommand(doSubstitution(bv->buffer(), et.viewCommand),
+                      bv->buffer());
 }
 
 
@@ -405,18 +439,21 @@ void InsetExternal::doEdit(BufferView const * bv) const
 {
        automaticUpdate(bv);
        ExternalTemplate const & et = getTemplate(getCurrentTemplate());
-       executeCommand(doSubstitution(bv->buffer(),et.editCommand), bv->buffer());
+       executeCommand(doSubstitution(bv->buffer(), et.editCommand),
+                      bv->buffer());
 }
 
 
-void InsetExternal::executeCommand(string const & s, Buffer const * buffer) const
+void InsetExternal::executeCommand(string const & s,
+                                  Buffer const * buffer) const
 {
        string buf = MakeAbsPath(buffer->fileName());
        string path = OnlyPath(buf);
        Path p(path);
        Systemcalls one;
        if (lyxerr.debugging()) {
-               lyxerr << "Executing '" << s << "' in '" << path << "'" << endl;
+               lyxerr << "Executing '" << s << "' in '"
+                      << path << "'" << endl;
        }
        one.startscript(Systemcalls::Wait, s);
 }
@@ -431,7 +468,8 @@ void InsetExternal::automaticUpdate(BufferView const * bv) const
 }
 
 
-string InsetExternal::doSubstitution(Buffer const * buffer, string const & s) const
+string InsetExternal::doSubstitution(Buffer const * buffer,
+                                    string const & s) const
 {
        string result;
        string basename = ChangeExtension(filename, string());
@@ -458,7 +496,9 @@ string InsetExternal::doSubstitution(Buffer const * buffer, string const & s) co
                } else {
                        contents = GetFileContents(file);
                }
-               result = subst(result, ("$$Contents(\"" + file + "\")").c_str(), contents);
+               result = subst(result,
+                              ("$$Contents(\"" + file + "\")").c_str(),
+                              contents);
        }
 
        return result;
@@ -477,7 +517,8 @@ ExternalTemplate InsetExternal::getTemplate(string const & name) const
                ExternalTemplateManager::get().getTemplates().find(name);
        // Make sure that the template exists in the map
        if (i == ExternalTemplateManager::get().getTemplates().end()) {
-               lyxerr << "Unknown external material template!" << endl;
+               lyxerr << "Unknown external material template: "
+                      << name << endl;
                return ExternalTemplate();
        }
        return (*i).second;
index 3f1906ecc7f807e6c657611e0f27a3a042df1402..ea542c7574c1a1c398251b57fd2f5ac44b0c1473 100644 (file)
 #include "insetbutton.h"
 #include "LString.h"
 #include "../lyx.h"
+
 struct ExternalTemplate;
 
+///
 class InsetExternal : public InsetButton {
 public:
        InsetExternal();
        ///
        virtual ~InsetExternal();
        /// what appears in the minibuffer when opening
-       virtual const char * EditMessage() const;
+       virtual char const * EditMessage() const;
        ///
        virtual void Edit(BufferView *, int x, int y, unsigned int button);
        ///
index 8de309592cee36c7b4d7be789a0733a6ed9af1e2..d2ea4a6a86273352b58e9aebcdcc4d98788216c3 100644 (file)
@@ -351,7 +351,7 @@ public:
        ///
        void CutSelection(BufferView *, bool = true);
        ///
-       void CopySelection(Buffer const *);
+       void CopySelection(BufferView *);
        ///
        void PasteSelection(BufferView *);
        ///
index c119a12ebf8efc9129a225b268cbd8ab7ec46e9c..6ab5764b58f079b239606741ab5bcaf7902d072a 100644 (file)
@@ -1111,16 +1111,6 @@ void LyXText::SetSelection(BufferView * bview)
        if (sel_start_cursor.par() == sel_end_cursor.par() && 
            sel_start_cursor.pos() == sel_end_cursor.pos())
                selection = false;
-
-       // Stuff what we got on the clipboard. Even if there is no selection.
-
-       // There is a problem with having the stuffing here in that the
-       // larger the selection the slower LyX will get. This can be
-       // solved by running the line below only when the selection has
-       // finished. The solution used currently just works, to make it
-       // faster we need to be more clever and probably also have more
-       // calls to stuffClipboard. (Lgb)
-       bview->stuffClipboard(selectionAsString(bview->buffer()));
 }
 
 
@@ -2061,9 +2051,20 @@ void LyXText::pasteEnvironmentType(BufferView * bview)
        SetLayout(bview, copylayouttype);
 }
 
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::CutSelection(Buffer const * buf, bool doclear)
+
+void LyXText::CutSelection(BufferView * bview, bool doclear)
 {
+
+       // Stuff what we got on the clipboard. Even if there is no selection.
+
+       // There is a problem with having the stuffing here in that the
+       // larger the selection the slower LyX will get. This can be
+       // solved by running the line below only when the selection has
+       // finished. The solution used currently just works, to make it
+       // faster we need to be more clever and probably also have more
+       // calls to stuffClipboard. (Lgb)
+       bview->stuffClipboard(selectionAsString(bview->buffer()));
+
        // This doesn't make sense, if there is no selection
        if (!selection)
                return;
@@ -2071,7 +2072,7 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
        // OK, we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
        LyXParagraph * tmppar;
-   
+    
        // Check whether there are half footnotes in the selection
        if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
            || sel_end_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
@@ -2100,11 +2101,11 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
        }
        /* table stuff -- end */
 #endif
-       
+    
        // make sure that the depth behind the selection are restored, too
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
        LyXParagraph * undoendpar = endpar;
-
+    
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
                        endpar = endpar->LastPhysicalPar()->Next();
@@ -2113,362 +2114,63 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
        } else if (endpar) {
                endpar = endpar->Next(); // because of parindents etc.
        }
-   
-       SetUndo(bview->buffer(), Undo::DELETE, 
-               sel_start_cursor
-               .par->ParFromPos(sel_start_cursor.pos())->previous, 
-               undoendpar);
-   
-       // clear the simple_cut_buffer
-       DeleteSimpleCutBuffer();
-   
-       // set the textclass
-       simple_cut_buffer_textclass = buf->params.textclass;
-
-#ifdef WITH_WARNINGS
-#warning Asger: Make cut more intelligent here.
-#endif
-       /* 
-          White paper for "intelligent" cutting:
-          
-          Example: "This is our text."
-          Using " our " as selection, cutting will give "This istext.".
-          Using "our" as selection, cutting will give "This is text.".
-          Using " our" as selection, cutting will give "This is text.".
-          Using "our " as selection, cutting will give "This is text.".
-          
-          All those four selections will (however) paste identically:
-          Pasting with the cursor right after the "is" will give the
-          original text with all four selections.
-          
-          The rationale is to be intelligent such that words are copied,
-          cut and pasted in a functional manner.
-          
-          This is not implemented yet. (Asger)
-
-          The changes below sees to do a lot of what you want. However
-          I have not verified that all cases work as they should:
-                    - cut in single row
-                    - cut in multiple row
-                    - cut with insets
-                    - cut across footnotes and paragraph
-          My simplistic tests show that the idea are basically sound but
-          there are some items to fix up...we only need to find them
-          first.
-
-          As do redo Asger's example above (with | beeing the cursor in the
-          result after cutting.):
-          
-          Example: "This is our text."
-          Using " our " as selection, cutting will give "This is|text.".
-          Using "our"   as selection, cutting will give "This is | text.".
-          Using " our"  as selection, cutting will give "This is| text.".
-          Using "our "  as selection, cutting will give "This is |text.".
-
-          (Lgb)
-       */
+    
+       SetUndo(bview->buffer(), Undo::DELETE, sel_start_cursor
+               .par()->ParFromPos(sel_start_cursor.pos())->previous, undoendpar);
+    
+       CutAndPaste cap;
 
        // there are two cases: cut only within one paragraph or
        // more than one paragraph
-   
        if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
            == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
                // only within one paragraph
-               simple_cut_buffer = new LyXParagraph;
-               LyXParagraph::size_type i =
-                       sel_start_cursor.pos();
-               for (; i < sel_end_cursor.pos(); ++i) {
-#ifndef NEW_TABULAR
-                       /* table stuff -- begin */
-                       if (sel_start_cursor.par()->table
-                           && sel_start_cursor.par()->IsNewline(sel_start_cursor.pos())) {
-                               sel_start_cursor.par()->CopyIntoMinibuffer(sel_start_cursor.pos());
-                               sel_start_cursor.pos()++;
-                       } else {
-                               /* table stuff -- end */
-#endif
-                               sel_start_cursor.par()->CopyIntoMinibuffer(sel_start_cursor.pos());
-                               sel_start_cursor.par()->Erase(sel_start_cursor.pos());
-#ifndef NEW_TABULAR
-                       }
-#endif
-                       simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last());
-               }
-               endpar = sel_end_cursor.par()->Next();
+               endpar = sel_start_cursor.par();
+               int pos = sel_end_cursor.pos();
+               cap.cutSelection(sel_start_cursor.par(), &endpar,
+                                sel_start_cursor.pos(), pos,
+                                bview->buffer()->params.textclass, doclear);
+               sel_end_cursor.pos(pos);
        } else {
-               // cut more than one paragraph
-   
-               sel_end_cursor.par()
-                       ->BreakParagraphConservative(sel_end_cursor.pos());
-               sel_end_cursor.par() = sel_end_cursor.par()->Next();
-               sel_end_cursor.pos() = 0;
-   
-               cursor = sel_end_cursor;
-
-               sel_start_cursor.par()
-                       ->BreakParagraphConservative(sel_start_cursor.pos());
-               // store the endparagraph for redoing later
-               endpar = sel_end_cursor.par()->Next(); /* needed because
-                                                       the sel_end_
-                                                       cursor.par()
-                                                       will be pasted! */
-   
-               // store the selection
-               simple_cut_buffer = sel_start_cursor.par()
-                       ->ParFromPos(sel_start_cursor.pos())->next;
-               simple_cut_buffer->previous = 0;
-               sel_end_cursor.par()->previous->next = 0;
-
-               // cut the selection
-               sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->next 
-                       = sel_end_cursor.par();
-   
-               sel_end_cursor.par()->previous 
-                       = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
-
-               // care about footnotes
-               if (simple_cut_buffer->footnoteflag) {
-                       LyXParagraph * tmppar = simple_cut_buffer;
-                       while (tmppar){
-                               tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE;
-                               tmppar = tmppar->next;
-                       }
-               }
+               endpar = sel_end_cursor.par();
 
-               // the cut selection should begin with standard layout
-               simple_cut_buffer->Clear(); 
-   
-               // paste the paragraphs again, if possible
-               if (doclear)
-                       sel_start_cursor.par()->Next()->StripLeadingSpaces(simple_cut_buffer_textclass);
-               if (sel_start_cursor.par()->FirstPhysicalPar()->HasSameLayout(sel_start_cursor.par()->Next())
-                   || 
-                   !sel_start_cursor.par()->Next()->Last())
-                       sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->PasteParagraph();
+               int pos = sel_end_cursor.pos();
+               cap.cutSelection(sel_start_cursor.par(), &endpar,
+                                sel_start_cursor.pos(), pos,
+                                bview->buffer()->params.textclass, doclear);
+               cursor.par(endpar);
+               sel_end_cursor.par(endpar);
+               sel_end_cursor.pos(pos);
+               cursor.pos(sel_end_cursor.pos());
        }
+       endpar = endpar->Next();
 
        // sometimes necessary
        if (doclear)
-               sel_start_cursor.par()->StripLeadingSpaces(simple_cut_buffer_textclass);
+               sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass);
 
-       RedoParagraphs(sel_start_cursor, endpar);
+       RedoParagraphs(bview, sel_start_cursor, endpar);
    
        ClearSelection();
        cursor = sel_start_cursor;
-       SetCursor(cursor.par(), cursor.pos());
+       SetCursor(bview, cursor.par(), cursor.pos());
        sel_cursor = cursor;
-       UpdateCounters(cursor.row());
+       UpdateCounters(bview, cursor.row());
 }
-
-#else ///////////////////////////////////////////////////////////////////
-
-void LyXText::CutSelection(BufferView * bview, bool doclear)
-{
-    // This doesn't make sense, if there is no selection
-    if (!selection)
-       return;
-   
-    // OK, we have a selection. This is always between sel_start_cursor
-    // and sel_end cursor
-    LyXParagraph * tmppar;
     
-    // Check whether there are half footnotes in the selection
-    if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
-       || sel_end_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-       tmppar = sel_start_cursor.par();
-       while (tmppar != sel_end_cursor.par()){
-           if (tmppar->footnoteflag != sel_end_cursor.par()->footnoteflag) {
-               WriteAlert(_("Impossible operation"),
-                          _("Don't know what to do with half floats."),
-                          _("sorry."));
-               return;
-                       }
-           tmppar = tmppar->Next();
-       }
-    }
 
-#ifndef NEW_TABULAR
-    /* table stuff -- begin */
-    if (sel_start_cursor.par()->table || sel_end_cursor.par()->table) {
-       if ( sel_start_cursor.par() != sel_end_cursor.par()) {
-           WriteAlert(_("Impossible operation"),
-                      _("Don't know what to do with half tables."),
-                      _("sorry."));
-           return;
-       }
-       sel_start_cursor.par()->table->Reinit();
-    }
-    /* table stuff -- end */
-#endif
-    
-    // make sure that the depth behind the selection are restored, too
-    LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
-    LyXParagraph * undoendpar = endpar;
-    
-    if (endpar && endpar->GetDepth()) {
-       while (endpar && endpar->GetDepth()) {
-           endpar = endpar->LastPhysicalPar()->Next();
-           undoendpar = endpar;
-       }
-    } else if (endpar) {
-       endpar = endpar->Next(); // because of parindents etc.
-    }
-    
-    SetUndo(bview->buffer(), Undo::DELETE, sel_start_cursor
-           .par()->ParFromPos(sel_start_cursor.pos())->previous, undoendpar);
-    
-    CutAndPaste cap;
-
-    // there are two cases: cut only within one paragraph or
-    // more than one paragraph
-    if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
-       == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
-       // only within one paragraph
-       endpar = sel_start_cursor.par();
-       int pos = sel_end_cursor.pos();
-       cap.cutSelection(sel_start_cursor.par(), &endpar,
-                        sel_start_cursor.pos(), pos,
-                        bview->buffer()->params.textclass, doclear);
-       sel_end_cursor.pos(pos);
-    } else {
-       endpar = sel_end_cursor.par();
-
-       int pos = sel_end_cursor.pos();
-       cap.cutSelection(sel_start_cursor.par(), &endpar,
-                        sel_start_cursor.pos(), pos,
-                        bview->buffer()->params.textclass, doclear);
-       cursor.par(endpar);
-       sel_end_cursor.par(endpar);
-       sel_end_cursor.pos(pos);
-       cursor.pos(sel_end_cursor.pos());
-    }
-    endpar = endpar->Next();
-
-    // sometimes necessary
-    if (doclear)
-       sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass);
-
-    RedoParagraphs(bview, sel_start_cursor, endpar);
-   
-    ClearSelection();
-    cursor = sel_start_cursor;
-    SetCursor(bview, cursor.par(), cursor.pos());
-    sel_cursor = cursor;
-    UpdateCounters(bview, cursor.row());
-}
-#endif
-    
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::CopySelection(Buffer const * buf)
+void LyXText::CopySelection(BufferView * bview)
 {
-       // this doesnt make sense, if there is no selection
-       if (!selection)
-               return;
-
-       // ok we have a selection. This is always between sel_start_cursor
-       // and sel_end cursor
-       LyXParagraph * tmppar;
-   
-       /* check wether there are half footnotes in the selection */
-       if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
-           || sel_end_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-               tmppar = sel_start_cursor.par();
-               while (tmppar != sel_end_cursor.par()) {
-                       if (tmppar->footnoteflag !=
-                           sel_end_cursor.par()->footnoteflag) {
-                               WriteAlert(_("Impossible operation"),
-                                          _("Don't know what to do"
-                                            " with half floats."),
-                                          _("sorry."));
-                               return;
-                       }
-                       tmppar = tmppar->Next();
-               }
-       }
-
-#ifndef NEW_TABULAR
-       /* table stuff -- begin */
-       if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
-               if ( sel_start_cursor.par() != sel_end_cursor.par()){
-                       WriteAlert(_("Impossible operation"),
-                                  _("Don't know what to do with half tables."),
-                                  _("sorry."));
-                       return;
-               }
-       }
-       /* table stuff -- end */
-#endif
-       
-       // delete the simple_cut_buffer
-       DeleteSimpleCutBuffer();
-
-       // set the textclass
-       simple_cut_buffer_textclass = buf->params.textclass;
-
-       // copy behind a space if there is one
-       while (sel_start_cursor.par()->Last() > sel_start_cursor.pos()
-              && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())
-              && (sel_start_cursor.par() != sel_end_cursor.par()
-                  || sel_start_cursor.pos() < sel_end_cursor.pos()))
-               sel_start_cursor.pos()++; 
-
-       // there are two cases: copy only within one paragraph
-       // or more than one paragraph
-       if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
-           == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
-               // only within one paragraph
-               simple_cut_buffer = new LyXParagraph;
-               LyXParagraph::size_type i = 0;
-               for (i = sel_start_cursor.pos(); i < sel_end_cursor.pos(); ++i){
-                       sel_start_cursor.par()->CopyIntoMinibuffer(i);
-                       simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos());
-               }
-       } else {
-               // copy more than one paragraph
-               // clone the paragraphs within the selection
-               tmppar =
-                       sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
-               simple_cut_buffer = tmppar->Clone();
-               LyXParagraph *tmppar2 = simple_cut_buffer;
-     
-               while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
-                      && tmppar->next) {
-                       tmppar = tmppar->next;
-                       tmppar2->next = tmppar->Clone();
-                       tmppar2->next->previous = tmppar2;
-                       tmppar2 = tmppar2->next;
-               }
-               tmppar2->next = 0;
-
-               // care about footnotes
-               if (simple_cut_buffer->footnoteflag) {
-                       tmppar = simple_cut_buffer;
-                       while (tmppar){
-                               tmppar->footnoteflag =
-                                       LyXParagraph::NO_FOOTNOTE;
-                               tmppar = tmppar->next;
-                       }
-               }
-               
-               // the simple_cut_buffer paragraph is too big
-               LyXParagraph::size_type tmpi2 =
-                       sel_start_cursor.par()->PositionInParFromPos(sel_start_cursor.pos());
-               for (; tmpi2; --tmpi2)
-                       simple_cut_buffer->Erase(0);
-               
-               // now tmppar 2 is too big, delete all after sel_end_cursor.pos()
-     
-               tmpi2 = sel_end_cursor.par()->PositionInParFromPos(sel_end_cursor.pos());
-               while (tmppar2->size() > tmpi2) {
-                       tmppar2->Erase(tmppar2->size() - 1);
-               }
-       }
-}
+       // Stuff what we got on the clipboard. Even if there is no selection.
 
-#else //////////////////////////////////////////////////////////////////////
+       // There is a problem with having the stuffing here in that the
+       // larger the selection the slower LyX will get. This can be
+       // solved by running the line below only when the selection has
+       // finished. The solution used currently just works, to make it
+       // faster we need to be more clever and probably also have more
+       // calls to stuffClipboard. (Lgb)
+       bview->stuffClipboard(selectionAsString(bview->buffer()));
 
-void LyXText::CopySelection(Buffer const * buf)
-{
        // this doesnt make sense, if there is no selection
        if (!selection)
                return;
@@ -2518,222 +2220,9 @@ void LyXText::CopySelection(Buffer const * buf)
 
        cap.copySelection(sel_start_cursor.par(), sel_end_cursor.par(),
                          sel_start_cursor.pos(), sel_end_cursor.pos(),
-                         buf->params.textclass);
+                         bview->buffer()->params.textclass);
 }
-#endif          
-
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::PasteSelection(Buffer const * buf)
-{
-       // this does not make sense, if there is nothing to paste
-       if (!simple_cut_buffer)
-               return;
-
-       LyXParagraph * tmppar;
-       LyXParagraph * endpar;
-
-       LyXCursor tmpcursor;
 
-       // be carefull with footnotes in footnotes
-       if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-      
-               // check whether the cut_buffer includes a footnote
-               tmppar = simple_cut_buffer;
-               while (tmppar
-                      && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
-                       tmppar = tmppar->next;
-      
-               if (tmppar) {
-                       WriteAlert(_("Impossible operation"),
-                                  _("Can't paste float into float!"),
-                                  _("Sorry."));
-                       return;
-               }
-       }
-
-#ifndef NEW_TABULAR
-       /* table stuff -- begin */
-       if (cursor.par()->table) {
-               if (simple_cut_buffer->next) {
-                       WriteAlert(_("Impossible operation"),
-                                  _("Table cell cannot include more than one paragraph!"),
-                                  _("Sorry."));
-                       return;
-               }
-       }
-       /* table stuff -- end */
-#endif
-   
-       SetUndo(bview->buffer(), Undo::INSERT, 
-               cursor.par()->ParFromPos(cursor.pos())->previous, 
-               cursor.par()->ParFromPos(cursor.pos())->next); 
-
-       tmpcursor = cursor;
-
-       // There are two cases: cutbuffer only one paragraph or many
-       if (!simple_cut_buffer->next) {
-               // only within a paragraph
-
-               tmppar = simple_cut_buffer->Clone();
-#ifndef NEW_TABULAR
-               /* table stuff -- begin */
-               bool table_too_small = false;
-               if (tmpcursor.par()->table) {
-                       while (simple_cut_buffer->size()
-                              && !table_too_small) {
-                               if (simple_cut_buffer->IsNewline(0)){
-                                       while(tmpcursor.pos() < tmpcursor.par()->Last() && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
-                                               tmpcursor.pos()++;
-                                       simple_cut_buffer->Erase(0);
-                                       if (tmpcursor.pos() < tmpcursor.par()->Last())
-                                               tmpcursor.pos()++;
-                                       else
-                                               table_too_small = true;
-                               } else {
-                                       // This is an attempt to fix the
-                                       // "never insert a space at the
-                                       // beginning of a paragraph" problem.
-                                       if (tmpcursor.pos() == 0
-                                           && simple_cut_buffer->IsLineSeparator(0)) {
-                                               simple_cut_buffer->Erase(0);
-                                       } else {
-                                               simple_cut_buffer->CutIntoMinibuffer(0);
-                                               simple_cut_buffer->Erase(0);
-                                               tmpcursor.par()->InsertFromMinibuffer(tmpcursor.pos());
-                                               tmpcursor.pos()++;
-                                       }
-                               }
-                       }
-               } else {
-#endif
-                       /* table stuff -- end */
-                       // Some provisions should be done here for checking
-                       // if we are inserting at the beginning of a
-                       // paragraph. If there are a space at the beginning
-                       // of the text to insert and we are inserting at
-                       // the beginning of the paragraph the space should
-                       // be removed.
-                       while (simple_cut_buffer->size()) {
-                               // This is an attempt to fix the
-                               // "never insert a space at the
-                               // beginning of a paragraph" problem.
-                               if (tmpcursor.pos() == 0
-                                   && simple_cut_buffer->IsLineSeparator(0)) {
-                                       simple_cut_buffer->Erase(0);
-                               } else {
-                                       simple_cut_buffer->CutIntoMinibuffer(0);
-                                       simple_cut_buffer->Erase(0);
-                                       tmpcursor.par()->InsertFromMinibuffer(tmpcursor.pos());
-                                       tmpcursor.pos()++;
-                               }
-                       }
-#ifndef NEW_TABULAR
-               }
-#endif
-               delete simple_cut_buffer;
-               simple_cut_buffer = tmppar;
-               endpar = tmpcursor.par()->Next();
-       } else {
-               // many paragraphs
-               CutAndPaste cap;
-
-               // make a copy of the simple cut_buffer
-               tmppar = simple_cut_buffer;
-               LyXParagraph * simple_cut_clone = tmppar->Clone();
-               LyXParagraph * tmppar2 = simple_cut_clone;
-               if (cursor.par()->footnoteflag){
-                       tmppar->footnoteflag = cursor.par()->footnoteflag;
-                       tmppar->footnotekind = cursor.par()->footnotekind;
-               }
-               while (tmppar->next) {
-                       tmppar = tmppar->next;
-                       tmppar2->next = tmppar->Clone();
-                       tmppar2->next->previous = tmppar2;
-                       tmppar2 = tmppar2->next;
-                       if (cursor.par()->footnoteflag){
-                               tmppar->footnoteflag = cursor.par()->footnoteflag;
-                               tmppar->footnotekind = cursor.par()->footnotekind;
-                       }
-               }
-     
-               // make sure there is no class difference
-               cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
-                                               buf->params.textclass,
-                                               simple_cut_buffer);
-     
-               // make the simple_cut_buffer exactly the same layout than
-               // the cursor paragraph
-               simple_cut_buffer->MakeSameLayout(cursor.par());
-     
-               // find the end of the buffer
-               LyXParagraph * lastbuffer = simple_cut_buffer;
-               while (lastbuffer->Next())
-                       lastbuffer = lastbuffer->Next();
-     
-               bool paste_the_end = false;
-
-               // open the paragraph for inserting the simple_cut_buffer
-               // if necessary
-               if (cursor.par()->Last() > cursor.pos() || !cursor.par()->Next()){
-                       cursor.par()->BreakParagraphConservative(cursor.pos());
-                       paste_the_end = true;
-               }
-
-               // set the end for redoing later
-               endpar = cursor.par()->ParFromPos(cursor.pos())->next->Next();
-     
-               // paste it!
-               lastbuffer->ParFromPos(lastbuffer->Last())->next =
-                       cursor.par()->ParFromPos(cursor.pos())->next;
-               cursor.par()->ParFromPos(cursor.pos())->next->previous =
-                       lastbuffer->ParFromPos(lastbuffer->Last());
-     
-               cursor.par()->ParFromPos(cursor.pos())->next = simple_cut_buffer;
-               simple_cut_buffer->previous =
-                       cursor.par()->ParFromPos(cursor.pos());
-   
-               if (cursor.par()->ParFromPos(cursor.pos())->Next() == lastbuffer)
-                       lastbuffer = cursor.par();
-     
-               cursor.par()->ParFromPos(cursor.pos())->PasteParagraph();
-     
-               // store the new cursor position
-               tmpcursor.par() = lastbuffer;
-               tmpcursor.pos() = lastbuffer->Last();
-     
-               // maybe some pasting
-               if (lastbuffer->Next() && paste_the_end) {
-                       if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else if (!lastbuffer->Next()->Last()) {
-                               lastbuffer->Next()->MakeSameLayout(lastbuffer);
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else if (!lastbuffer->Last()) {
-                               lastbuffer->MakeSameLayout(lastbuffer->next);
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else
-                               lastbuffer->Next()->StripLeadingSpaces(buffer->params.textclass);
-               }
-
-               // restore the simple cut buffer
-               simple_cut_buffer = simple_cut_clone;
-       }
-
-       RedoParagraphs(cursor, endpar);
-    
-       SetCursor(cursor.par(), cursor.pos());
-       ClearSelection();
-   
-       sel_cursor = cursor;
-       SetCursor(tmpcursor.par(), tmpcursor.pos());
-       SetSelection();
-       UpdateCounters(cursor.row());
-}
-
-#else ////////////////////////////////////////////////////////////////////
 
 void LyXText::PasteSelection(BufferView * bview)
 {
@@ -2763,7 +2252,7 @@ void LyXText::PasteSelection(BufferView * bview)
        SetSelection(bview);
        UpdateCounters(bview, cursor.row());
 }
-#endif   
+
 
 // returns a pointer to the very first LyXParagraph
 LyXParagraph * LyXText::FirstParagraph() const