]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / lyx_cb.C
index 7a1325803b89afcb6cddd49389aff03d624a048c..885055cda35bc490e1b147628de500943b339ad4 100644 (file)
@@ -351,11 +351,35 @@ Buffer * NewLyxFile(string const & filename)
 // Insert ascii file (if filename is empty, prompt for one)
 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
 {
-       string fname = f;
-
        if (!bv->available()) 
                return;
-     
+
+       string const tmpstr = getContentsOfAsciiFile(bv, f, asParagraph);
+       if (tmpstr.empty())
+               return;
+
+       // insert the string
+       bv->hideCursor();
+       
+       // clear the selection
+       bool flag = (bv->text == bv->getLyXText());
+       if (flag)
+               bv->beforeChange(bv->text);
+       if (!asParagraph)
+               bv->getLyXText()->insertStringAsLines(bv, tmpstr);
+       else
+               bv->getLyXText()->insertStringAsParagraphs(bv, tmpstr);
+       if (flag)
+               bv->update(bv->text,
+                          BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+}
+
+
+// Insert ascii file (if filename is empty, prompt for one)
+string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagraph)
+{
+       string fname = f;
+
        if (fname.empty()) {
                FileDialog fileDlg(bv->owner(), _("Select file to insert"),
                        (asParagraph) ? LFUN_FILE_INSERT_ASCII_PARA : LFUN_FILE_INSERT_ASCII);
@@ -363,12 +387,12 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
                FileDialog::Result result = fileDlg.Select(bv->owner()->buffer()->filePath());
 
                if (result.first == FileDialog::Later)
-                       return;
+                       return string();
 
                fname = result.second;
 
                if (fname.empty()) 
-                       return;
+                       return string();
        }
 
        FileInfo fi(fname);
@@ -376,14 +400,14 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        if (!fi.readable()) {
                Alert::err_alert(_("Error! Specified file is unreadable: "),
                             MakeDisplayPath(fname, 50));
-               return;
+               return string();
        }
 
        ifstream ifs(fname.c_str());
        if (!ifs) {
                Alert::err_alert(_("Error! Cannot open specified file: "),
                             MakeDisplayPath(fname, 50));
-               return;
+               return string();
        }
 
        ifs.unsetf(ios::skipws);
@@ -402,16 +426,8 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        string tmpstr;
        copy(ii, end, back_inserter(tmpstr));
 #endif
-       // insert the string
-       bv->hideCursor();
        
-       // clear the selection
-       bv->beforeChange(bv->text);
-       if (!asParagraph)
-               bv->text->insertStringAsLines(bv, tmpstr);
-       else
-               bv->text->insertStringAsParagraphs(bv, tmpstr);
-       bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+       return tmpstr;
 }
 
 
@@ -421,15 +437,13 @@ void MenuInsertLabel(BufferView * bv, string const & arg)
        bv->owner()->prohibitInput();
        if (label.empty()) {
                Paragraph * par = bv->getLyXText()->cursor.par();
-               LyXLayout const * layout =
-                       &textclasslist.Style(bv->buffer()->params.textclass,
-                                            par->getLayout());
+               LyXTextClass const & tclass =
+                       textclasslist[bv->buffer()->params.textclass];
+               LyXLayout const * layout = &tclass[par->layout()];
 
                if (layout->latextype == LATEX_PARAGRAPH && par->previous()) {
                        Paragraph * par2 = par->previous();
-                       LyXLayout const * layout2 =
-                               &textclasslist.Style(bv->buffer()->params.textclass,
-                                                    par2->getLayout());
+                       LyXLayout const * layout2 = &tclass[par2->layout()];
                        if (layout2->latextype != LATEX_PARAGRAPH) {
                                par = par2;
                                layout = layout2;