]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QPreambleDialog.C
better selection and scrolling behaviour
[lyx.git] / src / frontends / qt2 / QPreambleDialog.C
index d2fb4965aa6a84a7c042d7ac2dbe297f35eae8a7..44ffb0519c6b44f9fc60612a3247a79d55ff5d1b 100644 (file)
@@ -1,14 +1,20 @@
 /**
  * \file QPreambleDialog.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
-#include <fstream>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "Lsstream.h"
 #include "support/lyxlib.h"
 #include "support/forkedcall.h"
 #include "support/filetools.h"
@@ -23,6 +29,8 @@
 #include <qmultilineedit.h>
 #include <qinputdialog.h>
 
+#include <fstream>
+
 using std::getline;
 
 QPreambleDialog::QPreambleDialog(QPreamble * form)
@@ -56,7 +64,7 @@ void QPreambleDialog::editClicked()
        // find an editor
        string editor = GetEnv("EDITOR");
        if (editor.empty()) {
-               static string lastentry = "";
+               static string lastentry;
                editor = QInputDialog::getText(
                        _("Enter editor program"), _("Editor"), QLineEdit::Normal,
                        lastentry.c_str()).latin1();
@@ -77,7 +85,7 @@ void QPreambleDialog::editClicked()
 
        file.close();
 
-       editor += " " + filename;
+       editor += ' ' + filename;
 
        Forkedcall call;
 
@@ -94,14 +102,12 @@ void QPreambleDialog::editClicked()
                return;
        }
 
-       string newtext;
-       string line;
-
-       while (getline(in, line)) {
-               newtext += line + "\n";
-       }
+       ostringstream newtext;
+       newtext << in.rdbuf();
 
+       // close the files before we delete the file
        in.close();
+
        lyx::unlink(filename);
-       preambleLE->setText(newtext.c_str());
+       preambleLE->setText(newtext.str().c_str());
 }