]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QPreambleDialog.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QPreambleDialog.C
index bd627cbb472eae777c40621c340d4a8ffa1cabe9..44ffb0519c6b44f9fc60612a3247a79d55ff5d1b 100644 (file)
@@ -1,29 +1,35 @@
 /**
  * \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"
+#include "gettext.h"
+#include "LyXView.h"
+#include "ControlPreamble.h"
+
+#include "QPreamble.h"
+#include "QPreambleDialog.h"
 
 #include <qpushbutton.h>
 #include <qmultilineedit.h>
 #include <qinputdialog.h>
 
-#include "QPreambleDialog.h"
-#include "Dialogs.h"
-#include "QPreamble.h"
-
-#include "support/lyxlib.h"
-#include "support/syscall.h"
-#include "support/filetools.h"
-#include "gettext.h" 
-#include "QtLyXView.h"
-#include "ControlPreamble.h" 
+#include <fstream>
 
 using std::getline;
 
@@ -39,7 +45,7 @@ QPreambleDialog::QPreambleDialog(QPreamble * form)
                form, SLOT(slotClose()));
 }
 
+
 void QPreambleDialog::closeEvent(QCloseEvent * e)
 {
        form_->slotWMHide();
@@ -52,19 +58,19 @@ void QPreambleDialog::change_adaptor()
        form_->changed();
 }
 
+
 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, 
+                       _("Enter editor program"), _("Editor"), QLineEdit::Normal,
                        lastentry.c_str()).latin1();
                if (editor.empty())
                        return;
-               lastentry = editor; 
+               lastentry = editor;
        }
 
        string const text(preambleLE->text().latin1());
@@ -79,24 +85,29 @@ void QPreambleDialog::editClicked()
 
        file.close();
 
-       editor += " " + filename;
-       // FIXME: synchronous, ugh. Make async when moved to controllers ?
-       Systemcalls sys(Systemcalls::Wait, editor);
+       editor += ' ' + filename;
 
-       std::ifstream in(filename.c_str());
+       Forkedcall call;
 
-       if (!in)
+       // FIXME: make async
+       if (call.startscript(Forkedcall::Wait, editor)) {
+               lyx::unlink(filename);
                return;
+       }
+
+       std::ifstream in(filename.c_str());
 
-       string newtext;
-       string line;
-       while (getline(in, line)) {
-               newtext += line + "\n"; 
+       if (!in) {
+               lyx::unlink(filename);
+               return;
        }
 
+       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());
 }