]> git.lyx.org Git - features.git/commitdiff
added pre-amble dialog with icky $EDITOR support
authorJohn Levon <levon@movementarian.org>
Wed, 29 Aug 2001 03:35:45 +0000 (03:35 +0000)
committerJohn Levon <levon@movementarian.org>
Wed, 29 Aug 2001 03:35:45 +0000 (03:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2612 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/Dialogs.C
src/frontends/qt2/Makefile.am
src/frontends/qt2/Makefile.dialogs
src/frontends/qt2/QPreamble.C [new file with mode: 0644]
src/frontends/qt2/QPreamble.h [new file with mode: 0644]
src/frontends/qt2/QPreambleDialog.C [new file with mode: 0644]
src/frontends/qt2/QPreambleDialog.h [new file with mode: 0644]
src/frontends/qt2/ui/QPreambleDialog.ui [new file with mode: 0644]

index 1a28c7c139d93d40928ab68d02c89e59738516e6..5b8650134692b64b292bfe6f75852dc0a9c973a0 100644 (file)
@@ -1,3 +1,12 @@
+2001-08-29  John Levon  <moz@compsoc.man.ac.uk>
+
+       * QPreamble.[Ch]:
+       * QPreambleDialog.[Ch]:
+       * ui/QPreambleDialog.ui:
+       * Makefile.am:
+       * Makefile.dialogs:
+       * Dialogs.C: add pre-amble dialog
+
 2001-08-29  John Levon  <moz@compsoc.man.ac.uk>
 
        * ui/QIndexDialog.ui:
index f22d3db81e01da196848889fc22b77a2522cbc42..afbf87d3c5b5b4de0821af059302eec8b1d90a33 100644 (file)
@@ -25,6 +25,7 @@
 #include "QIndexDialog.h"
 #include "QLogDialog.h"
 #include "QMinipageDialog.h"
+#include "QPreambleDialog.h"
 #include "QRefDialog.h"
 #include "QTabularCreateDialog.h"
 #include "QThesaurusDialog.h"
@@ -45,6 +46,7 @@
 #include "QLog.h"
 #include "QMinipage.h"
 #include "QParagraph.h"
+#include "QPreamble.h"
 #include "QPrint.h"
 #include "QRef.h"
 #include "QSearch.h"
@@ -74,6 +76,7 @@
 #include "controllers/ControlIndex.h"
 #include "controllers/ControlLog.h"
 #include "controllers/ControlMinipage.h"
+#include "controllers/ControlPreamble.h"
 #include "controllers/ControlRef.h"
 #include "controllers/ControlSplash.h"
 #include "controllers/ControlTabularCreate.h"
@@ -85,7 +88,6 @@
 #include "controllers/ControlCitation.h"
 #include "controllers/ControlFloat.h"
 #include "controllers/ControlLabel.h"
-#include "controllers/ControlPreamble.h"
 #include "controllers/ControlPrint.h"
 #include "controllers/ControlRef.h"
 #include "controllers/ControlSearch.h"
@@ -117,6 +119,7 @@ Dialogs::Dialogs(LyXView * lv)
        add(new GUIIndex<QIndex, Qt2BC>(*lv, *this));
        add(new GUILog<QLog, Qt2BC>(*lv, *this));
        add(new GUIMinipage<QMinipage, Qt2BC>(*lv, *this));
+       add(new GUIPreamble<QPreamble, Qt2BC>(*lv, *this)); 
        add(new GUIRef<QRef, Qt2BC>(*lv, *this));
        add(new GUITabularCreate<QTabularCreate, Qt2BC>(*lv, *this));
        add(new GUIThesaurus<QThesaurus, Qt2BC>(*lv, *this));
index 1598ee106b109887e852528acafd1f9db0b02af0..5487f136da54ccb3242940947304df5557da80f2 100644 (file)
@@ -27,7 +27,6 @@ libqt2_la_OBJADD = \
        ../xforms/FormDocument.lo \
        ../xforms/FormIndex.lo \
        ../xforms/FormInset.lo \
-       ../xforms/FormPreamble.lo \
        ../xforms/FormPreferences.lo \
        ../xforms/FormRef.lo \
        ../xforms/FormTabular.lo \
index 733deae42da2c2c161c6d44a590ced6ddd3d6bf3..132c6bc4d0cbf5ca5d98995594e5fec5e6e3afc9 100644 (file)
@@ -16,6 +16,7 @@ DIALOGS = \
        QLog \
        QMinipage \
        QParagraph \
+       QPreamble \
        QPrint \
        QRef \
        QSearch \
@@ -57,6 +58,8 @@ DIALOGSOURCES = \
        QMinipage.C QMinipageDialog.C \
        QParagraph.h QParagraphDialog.h \
        QParagraph.C QParagraphDialog.C \
+       QPreamble.h QPreambleDialog.h \
+       QPreamble.C QPreambleDialog.C \
        QPrint.h QPrintDialog.h \
        QPrint.C QPrintDialog.C \
        QRef.h QRefDialog.h \
@@ -92,6 +95,7 @@ MOCDIALOGS = \
        QLogDialog_moc.C \
        QMinipageDialog_moc.C \
        QParagraphDialog_moc.C \
+       QPreambleDialog_moc.C \
        QPrintDialog_moc.C \
        QRefDialog_moc.C \
        QSearchDialog_moc.C \
@@ -133,6 +137,8 @@ UIDIALOGS = \
        QMinipageDialogBase.C \
        QParagraphDialogBase.h \
        QParagraphDialogBase.C \
+       QPreambleDialogBase.h \
+       QPreambleDialogBase.C \
        QPrintDialogBase.h \
        QPrintDialogBase.C \
        QRefDialogBase.h \
@@ -166,6 +172,7 @@ UIMOCDIALOGS = \
        QLogDialogBase_moc.C \
        QMinipageDialogBase_moc.C \
        QParagraphDialogBase_moc.C \
+       QPreambleDialogBase_moc.C \
        QPrintDialogBase_moc.C \
        QRefDialogBase_moc.C \
        QSearchDialogBase_moc.C \
diff --git a/src/frontends/qt2/QPreamble.C b/src/frontends/qt2/QPreamble.C
new file mode 100644 (file)
index 0000000..707425b
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * \file QPreamble.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#include <config.h>
+#include <fstream> 
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <qmultilineedit.h>
+#include <qpushbutton.h>
+#include "QPreambleDialog.h"
+#include "QPreamble.h"
+#include "Qt2BC.h"
+#include "gettext.h"
+#include "QtLyXView.h"
+#include "ControlPreamble.h"
+
+typedef Qt2CB<ControlPreamble, Qt2DB<QPreambleDialog> > base_class;
+
+QPreamble::QPreamble(ControlPreamble & c)
+       : base_class(c, _("LaTeX Preamble"))
+{
+}
+
+
+void QPreamble::build_dialog()
+{
+       dialog_.reset(new QPreambleDialog(this));
+
+       bc().setOK(dialog_->okPB);
+       bc().setApply(dialog_->applyPB);
+       bc().setCancel(dialog_->closePB);
+}
+
+
+void QPreamble::update_contents()
+{
+       dialog_->preambleLE->setText(controller().params().c_str());
+}
+
+
+void QPreamble::apply()
+{
+       controller().params() = dialog_->preambleLE->text().latin1();
+}
diff --git a/src/frontends/qt2/QPreamble.h b/src/frontends/qt2/QPreamble.h
new file mode 100644 (file)
index 0000000..1bb1c98
--- /dev/null
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+/**
+ * \file QPreamble.h
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#ifndef QPREAMBLE_H
+#define QPREAMBLE_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "Qt2Base.h"
+
+class ControlPreamble;
+class QPreambleDialog;
+
+///
+class QPreamble
+       : public Qt2CB<ControlPreamble, Qt2DB<QPreambleDialog> > 
+{
+public:
+       ///
+       friend class QPreambleDialog;
+       ///
+       QPreamble(ControlPreamble &);
+
+private:
+       /// Apply changes
+       virtual void apply();
+       /// update
+       virtual void update_contents();
+       /// build the dialog
+       virtual void build_dialog();
+};
+
+#endif // QPREAMBLE_H
diff --git a/src/frontends/qt2/QPreambleDialog.C b/src/frontends/qt2/QPreambleDialog.C
new file mode 100644 (file)
index 0000000..dddc086
--- /dev/null
@@ -0,0 +1,99 @@
+/**
+ * \file QPreambleDialog.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#include <config.h>
+#include <fstream>
+
+#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" 
+
+QPreambleDialog::QPreambleDialog(QPreamble * form)
+       : QPreambleDialogBase(0, 0, false, 0),
+       form_(form)
+{
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()),
+               form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+}
+
+void QPreambleDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QPreambleDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+void QPreambleDialog::editClicked()
+{
+       // find an editor
+       string editor = GetEnv("EDITOR");
+       if (editor.empty()) {
+               static string lastentry = "";
+               editor = QInputDialog::getText(
+                       _("Enter editor program"), _("Editor"), lastentry.c_str()).latin1();
+               if (editor.empty())
+                       return;
+               lastentry = editor; 
+       }
+
+       string const text(preambleLE->text().latin1());
+       string const filename(lyx::tempName("", "preamble"));
+       std::ofstream file(filename.c_str());
+
+       // FIXME ?
+       if (!file)
+               return;
+
+       file << text;
+
+       file.close();
+
+       editor += " " + filename;
+       // FIXME: synchronous, ugh. Make async when moved to controllers ?
+       Systemcalls sys(Systemcalls::Wait, editor);
+
+       std::ifstream in(filename.c_str());
+
+       if (!in)
+               return;
+
+       string newtext;
+       string line;
+       while (getline(in, line)) {
+               newtext += line + "\n"; 
+       }
+
+       in.close();
+       lyx::unlink(filename);
+       preambleLE->setText(newtext.c_str());
+}
diff --git a/src/frontends/qt2/QPreambleDialog.h b/src/frontends/qt2/QPreambleDialog.h
new file mode 100644 (file)
index 0000000..8365436
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * \file QPreambleDialog.h
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#ifndef QPreambleDIAPreamble_H
+#define QPreambleDIAPreamble_H
+#include <config.h>
+#include "ui/QPreambleDialogBase.h"
+
+class QPreamble;
+
+class QPreambleDialog : public QPreambleDialogBase
+{ Q_OBJECT
+
+public:
+       QPreambleDialog(QPreamble * form);
+
+protected slots:
+       virtual void editClicked();
+       virtual void change_adaptor(); 
+
+protected:
+       virtual void closeEvent(QCloseEvent * e);
+
+private:
+       QPreamble * form_;
+};
+
+#endif // QPreambleDIAPreamble_H
diff --git a/src/frontends/qt2/ui/QPreambleDialog.ui b/src/frontends/qt2/ui/QPreambleDialog.ui
new file mode 100644 (file)
index 0000000..799f5b4
--- /dev/null
@@ -0,0 +1,175 @@
+<!DOCTYPE UI><UI>
+<class>QPreambleDialogBase</class>
+<include location="global">config.h</include>
+<include location="local">gettext.h</include>
+<widget>
+    <class>QDialog</class>
+    <property stdset="1">
+        <name>name</name>
+        <cstring>QPreambleDialogBase</cstring>
+    </property>
+    <property stdset="1">
+        <name>geometry</name>
+        <rect>
+            <x>0</x>
+            <y>0</y>
+            <width>416</width>
+            <height>328</height>
+        </rect>
+    </property>
+    <property stdset="1">
+        <name>caption</name>
+        <string>LaTeX pre-amble</string>
+    </property>
+    <vbox>
+        <property stdset="1">
+            <name>margin</name>
+            <number>11</number>
+        </property>
+        <property stdset="1">
+            <name>spacing</name>
+            <number>6</number>
+        </property>
+        <widget>
+            <class>QMultiLineEdit</class>
+            <property stdset="1">
+                <name>name</name>
+                <cstring>preambleLE</cstring>
+            </property>
+            <property>
+                <name>toolTip</name>
+                <string>The LaTeX pre-amble</string>
+            </property>
+        </widget>
+        <widget>
+            <class>QLayoutWidget</class>
+            <property stdset="1">
+                <name>name</name>
+                <cstring>Layout2</cstring>
+            </property>
+            <hbox>
+                <property stdset="1">
+                    <name>margin</name>
+                    <number>0</number>
+                </property>
+                <property stdset="1">
+                    <name>spacing</name>
+                    <number>6</number>
+                </property>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>editPB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Edit ...</string>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>true</bool>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Edit the pre-amble in an external editor</string>
+                    </property>
+                </widget>
+                <spacer>
+                    <property>
+                        <name>name</name>
+                        <cstring>Spacer3</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>orientation</name>
+                        <enum>Horizontal</enum>
+                    </property>
+                    <property stdset="1">
+                        <name>sizeType</name>
+                        <enum>Expanding</enum>
+                    </property>
+                    <property>
+                        <name>sizeHint</name>
+                        <size>
+                            <width>20</width>
+                            <height>20</height>
+                        </size>
+                    </property>
+                </spacer>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>okPB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;OK</string>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>true</bool>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string></string>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>applyPB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Apply</string>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>true</bool>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string></string>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>closePB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Close</string>
+                    </property>
+                </widget>
+            </hbox>
+        </widget>
+    </vbox>
+</widget>
+<connections>
+    <connection>
+        <sender>preambleLE</sender>
+        <signal>textChanged()</signal>
+        <receiver>QPreambleDialogBase</receiver>
+        <slot>change_adaptor()</slot>
+    </connection>
+    <connection>
+        <sender>editPB</sender>
+        <signal>clicked()</signal>
+        <receiver>QPreambleDialogBase</receiver>
+        <slot>editClicked()</slot>
+    </connection>
+    <slot access="public">change_adaptor()</slot>
+    <slot access="public">editClicked()</slot>
+</connections>
+<tabstops>
+    <tabstop>preambleLE</tabstop>
+    <tabstop>editPB</tabstop>
+    <tabstop>okPB</tabstop>
+    <tabstop>applyPB</tabstop>
+    <tabstop>closePB</tabstop>
+</tabstops>
+</UI>