From: John Levon Date: Wed, 29 Aug 2001 03:35:45 +0000 (+0000) Subject: added pre-amble dialog with icky $EDITOR support X-Git-Tag: 1.6.10~20733 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=621c0624346bde90df3f0e57d5a9e46002bd56e5;p=features.git added pre-amble dialog with icky $EDITOR support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2612 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 1a28c7c139..5b86501346 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,12 @@ +2001-08-29 John Levon + + * QPreamble.[Ch]: + * QPreambleDialog.[Ch]: + * ui/QPreambleDialog.ui: + * Makefile.am: + * Makefile.dialogs: + * Dialogs.C: add pre-amble dialog + 2001-08-29 John Levon * ui/QIndexDialog.ui: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index f22d3db81e..afbf87d3c5 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -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(*lv, *this)); add(new GUILog(*lv, *this)); add(new GUIMinipage(*lv, *this)); + add(new GUIPreamble(*lv, *this)); add(new GUIRef(*lv, *this)); add(new GUITabularCreate(*lv, *this)); add(new GUIThesaurus(*lv, *this)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 1598ee106b..5487f136da 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -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 \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 733deae42d..132c6bc4d0 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -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 index 0000000000..707425be5d --- /dev/null +++ b/src/frontends/qt2/QPreamble.C @@ -0,0 +1,54 @@ +/** + * \file QPreamble.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#include +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include + +#include "QPreambleDialog.h" +#include "QPreamble.h" +#include "Qt2BC.h" +#include "gettext.h" + +#include "QtLyXView.h" +#include "ControlPreamble.h" + +typedef Qt2CB > 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 index 0000000000..1bb1c98196 --- /dev/null +++ b/src/frontends/qt2/QPreamble.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +/** + * \file QPreamble.h + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifndef QPREAMBLE_H +#define QPREAMBLE_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "Qt2Base.h" + +class ControlPreamble; +class QPreambleDialog; + +/// +class QPreamble + : public Qt2CB > +{ +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 index 0000000000..dddc08635a --- /dev/null +++ b/src/frontends/qt2/QPreambleDialog.C @@ -0,0 +1,99 @@ +/** + * \file QPreambleDialog.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#include +#include + +#include +#include +#include + +#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 index 0000000000..8365436bf4 --- /dev/null +++ b/src/frontends/qt2/QPreambleDialog.h @@ -0,0 +1,35 @@ +/** + * \file QPreambleDialog.h + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifndef QPreambleDIAPreamble_H +#define QPreambleDIAPreamble_H + +#include + +#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 index 0000000000..799f5b4e1d --- /dev/null +++ b/src/frontends/qt2/ui/QPreambleDialog.ui @@ -0,0 +1,175 @@ + +QPreambleDialogBase +config.h +gettext.h + + QDialog + + name + QPreambleDialogBase + + + geometry + + 0 + 0 + 416 + 328 + + + + caption + LaTeX pre-amble + + + + margin + 11 + + + spacing + 6 + + + QMultiLineEdit + + name + preambleLE + + + toolTip + The LaTeX pre-amble + + + + QLayoutWidget + + name + Layout2 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + editPB + + + text + &Edit ... + + + default + true + + + toolTip + Edit the pre-amble in an external editor + + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + okPB + + + text + &OK + + + default + true + + + toolTip + + + + + QPushButton + + name + applyPB + + + text + &Apply + + + default + true + + + toolTip + + + + + QPushButton + + name + closePB + + + text + &Close + + + + + + + + + preambleLE + textChanged() + QPreambleDialogBase + change_adaptor() + + + editPB + clicked() + QPreambleDialogBase + editClicked() + + change_adaptor() + editClicked() + + + preambleLE + editPB + okPB + applyPB + closePB + +