From 3e2abfdd78214ccf674665e197fa948b12ba1d1e Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Tue, 13 May 2003 21:15:48 +0000 Subject: [PATCH] the errorlist change git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6958 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 43 +----- src/BufferView.h | 4 +- src/ChangeLog | 6 + src/buffer.C | 2 +- src/converter.C | 60 +------- src/frontends/controllers/ChangeLog | 4 + src/frontends/controllers/ControlErrorList.C | 136 +++++++++++++++++++ src/frontends/controllers/ControlErrorList.h | 68 ++++++++++ src/frontends/controllers/Makefile.am | 2 + src/frontends/qt2/ChangeLog | 7 + src/frontends/qt2/Dialogs.C | 12 +- src/frontends/qt2/Makefile.am | 1 + src/frontends/qt2/Makefile.dialogs | 2 + src/frontends/qt2/QErrorList.C | 68 ++++++++++ src/frontends/qt2/QErrorList.h | 41 ++++++ src/frontends/qt2/QErrorListDialog.C | 47 +++++++ src/frontends/qt2/QErrorListDialog.h | 33 +++++ src/frontends/qt2/ui/QErrorListDialogBase.ui | 103 ++++++++++++++ src/frontends/xforms/ChangeLog | 7 + src/frontends/xforms/Dialogs.C | 11 +- src/frontends/xforms/FormErrorList.C | 107 +++++++++++++++ src/frontends/xforms/FormErrorList.h | 41 ++++++ src/frontends/xforms/Makefile.am | 2 + src/frontends/xforms/forms/Makefile.am | 1 + src/frontends/xforms/forms/form_errorlist.fd | 89 ++++++++++++ 25 files changed, 793 insertions(+), 104 deletions(-) create mode 100644 src/frontends/controllers/ControlErrorList.C create mode 100644 src/frontends/controllers/ControlErrorList.h create mode 100644 src/frontends/qt2/QErrorList.C create mode 100644 src/frontends/qt2/QErrorList.h create mode 100644 src/frontends/qt2/QErrorListDialog.C create mode 100644 src/frontends/qt2/QErrorListDialog.h create mode 100644 src/frontends/qt2/ui/QErrorListDialogBase.ui create mode 100644 src/frontends/xforms/FormErrorList.C create mode 100644 src/frontends/xforms/FormErrorList.h create mode 100644 src/frontends/xforms/forms/form_errorlist.fd diff --git a/src/BufferView.C b/src/BufferView.C index 49a2ed9341..7b2bece96e 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -467,48 +467,9 @@ bool BufferView::removeAutoInsets() } -void BufferView::insertErrors(TeXErrors & terr) +void BufferView::showErrorList() { - // Save the cursor position - LyXCursor cursor = text->cursor; - - TeXErrors::Errors::const_iterator cit = terr.begin(); - TeXErrors::Errors::const_iterator end = terr.end(); - for (; cit != end; ++cit) { - string const desctext(cit->error_desc); - string const errortext(cit->error_text); - string const msgtxt = desctext + '\n' + errortext; - int const errorrow = cit->error_in_line; - - // Insert error string for row number - int tmpid = -1; - int tmppos = -1; - - if (buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos)) { - buffer()->texrow.increasePos(tmpid, tmppos); - } - - Paragraph * texrowpar = 0; - - if (tmpid == -1) { - texrowpar = &*text->ownerParagraphs().begin(); - tmppos = 0; - } else { - texrowpar = &*buffer()->getParFromID(tmpid); - } - - if (texrowpar == 0) - continue; - - freezeUndo(); - InsetError * new_inset = new InsetError(msgtxt); - text->setCursorIntern(texrowpar, tmppos); - text->insertInset(new_inset); - text->fullRebreak(); - unFreezeUndo(); - } - // Restore the cursor position - text->setCursorIntern(cursor.par(), cursor.pos()); + owner()->getDialogs().show("errorlist"); } diff --git a/src/BufferView.h b/src/BufferView.h index 9a58625108..fe00dc9672 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -153,8 +153,8 @@ public: /// removes all autodeletable insets bool removeAutoInsets(); - /// insert all errors found when running latex - void insertErrors(TeXErrors & terr); + /// show the error list to the user + void showErrorList(); /// set the cursor based on the given TeX source row void setCursorFromRow(int row); diff --git a/src/ChangeLog b/src/ChangeLog index 3f4bdf4b62..7604030139 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-05-12 Alfredo Braunstein + + * BufferView.[Ch] (insertErrors): removed + * BufferView.[Ch] (showErrorList): added + * buffer.C (runChkTeX): + * converter.C (scanLog): call showErrorList instead of inserterrors 2003-05-13 André Pönitz diff --git a/src/buffer.C b/src/buffer.C index da63f13f66..07b9ccbf2c 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1977,7 +1977,7 @@ int Buffer::runChktex() _("Could not run chktex successfully.")); } else if (res > 0) { // Insert all errors as errors boxes - users->insertErrors(terr); + users->showErrorList(); } // if we removed error insets before we ran chktex or if we inserted diff --git a/src/converter.C b/src/converter.C index 6798b5a6a1..3577adb9c4 100644 --- a/src/converter.C +++ b/src/converter.C @@ -459,58 +459,19 @@ bool Converters::formatIsUsed(string const & format) } -namespace { - -void alertErrors(string const & prog, int nr_errors) -{ - string s; - if (nr_errors == 1) - s = bformat(_("One error detected when running %1$s.\n"), prog); - else - s = bformat(_("%1$s errors detected when running %2$s.\n"), - prog, tostr(nr_errors)); - Alert::error(_("Errors found"), s); -} - -} - - bool Converters::scanLog(Buffer const * buffer, string const & command, - string const & filename) + string const & filename) { if (!buffer) return false; BufferView * bv = buffer->getUser(); - if (bv) { - bv->owner()->busy(true); - // all error insets should have been removed by now - } - LaTeX latex("", filename, ""); TeXErrors terr; int result = latex.scanLogFile(terr); - if (bv) { - if ((result & LaTeX::ERRORS)) { - // Insert all errors as errors boxes - bv->insertErrors(terr); -#warning repaint() or update() or nothing ? - bv->repaint(); - bv->fitCursor(); - } - bv->owner()->busy(false); - } + if (bv && (result & LaTeX::ERRORS)) + bv->showErrorList(); - if ((result & LaTeX::ERRORS)) { - string head; - split(command, head, ' '); - alertErrors(head, latex.getNumErrors()); - return false; - } else if (result & LaTeX::NO_OUTPUT) { - Alert::warning(_("Output is empty"), - _("An empty output file was generated.")); - return false; - } return true; } @@ -535,14 +496,9 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command) int result = latex.run(terr, bv ? &bv->owner()->getLyXFunc() : 0); - if (bv) { - if ((result & LaTeX::ERRORS)) { - // Insert all errors as errors boxes - bv->insertErrors(terr); -#warning repaint() or update() or nothing ? - bv->repaint(); - bv->fitCursor(); - } + if (bv && (result & LaTeX::ERRORS)) { + //show errors + bv->showErrorList(); } // check return value from latex.run(). @@ -550,9 +506,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command) string str = bformat(_("LaTeX did not run successfully. Additionally, LyX " "could not locate the LaTeX log %1$s."), name); Alert::error(_("LaTeX failed"), str); - } else if ((result & LaTeX::ERRORS)) { - alertErrors("LaTeX", latex.getNumErrors()); - } else if (result & LaTeX::NO_OUTPUT) { + } else if (result & LaTeX::NO_OUTPUT) { Alert::warning(_("Output is empty"), _("An empty output file was generated.")); } diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index e628108f77..a56f2fad76 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2003-05-12 Alfredo Braunstein: + + * ControlErrorList.[Ch]: added + * Makefile.am: the above adittion 2003-05-13 André Pönitz diff --git a/src/frontends/controllers/ControlErrorList.C b/src/frontends/controllers/ControlErrorList.C new file mode 100644 index 0000000000..35e48ee3e0 --- /dev/null +++ b/src/frontends/controllers/ControlErrorList.C @@ -0,0 +1,136 @@ +/** + * \file ControlErrorList.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#include + +#include "ControlErrorList.h" +#include "support/lstrings.h" // tostr +#include "LaTeX.h" +#include "buffer.h" +#include "BufferView.h" +#include "lyxtext.h" + + + +ControlErrorList::ErrorItem::ErrorItem(string const & error, + string const & description, + int par_id, int pos_start, int pos_end) + : error(error), description(description), par_id(par_id), + pos_start(pos_start), pos_end(pos_end) +{} + +ControlErrorList::ControlErrorList(Dialog & d) + : Dialog::Controller(d), current_(0) +{} + + +void ControlErrorList::clearParams() +{ + logfilename_.clear(); + clearErrors(); +} + + +std::vector const & +ControlErrorList::ErrorList() const +{ + return ErrorList_; +} + + +int ControlErrorList::currentItem() const +{ + return current_; +} + + +bool ControlErrorList::initialiseParams(string const &) +{ + logfilename_ = kernel().buffer()->getLogName().second; + clearErrors(); + fillErrors(); + current_ = 0; + return true; +} + + +void ControlErrorList::clearErrors() +{ + ErrorList_.clear(); + current_ = 0; +} + + +void ControlErrorList::fillErrors() +{ + LaTeX latex("", logfilename_, ""); + TeXErrors terr; + latex.scanLogFile(terr); + + Buffer * const buf = kernel().buffer(); + + TeXErrors::Errors::const_iterator cit = terr.begin(); + TeXErrors::Errors::const_iterator end = terr.end(); + + for (; cit != end; ++cit) { + int par_id = -1; + int posstart = -1; + int const errorrow = cit->error_in_line; + buf->texrow.getIdFromRow(errorrow, par_id, posstart); + int posend = -1; + buf->texrow.getIdFromRow(errorrow + 1, par_id, posend); + ErrorList_.push_back(ErrorItem(cit->error_desc, + cit->error_text, + par_id, posstart, posend)); + } +} + + +string const & ControlErrorList::docName() +{ + return kernel().buffer()->fileName(); +} + + +void ControlErrorList::goTo(int item) +{ + BufferView * const bv = kernel().bufferview(); + Buffer * const buf = kernel().buffer(); + + current_ = item; + + ControlErrorList::ErrorItem const & err = ErrorList_[item]; + + + if (err.par_id == -1) + return; + + ParagraphList::iterator pit = buf->getParFromID(err.par_id); + + if (pit == bv->text->ownerParagraphs().end()) { + cout << "par id not found" << endl; + return; + } + + int range = err.pos_end - err.pos_start; + + if (err.pos_end > pit->size() || range <= 0) + range = pit->size() - err.pos_start; + + //now make the selection + bv->insetUnlock(); + bv->toggleSelection(); + bv->text->clearSelection(); + bv->text->setCursor(pit, err.pos_start); + bv->text->setSelectionRange(range); + bv->toggleSelection(false); + bv->fitCursor(); + bv->update(bv->text, BufferView::SELECT); +} diff --git a/src/frontends/controllers/ControlErrorList.h b/src/frontends/controllers/ControlErrorList.h new file mode 100644 index 0000000000..4ce577b37b --- /dev/null +++ b/src/frontends/controllers/ControlErrorList.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +/** + * \file ControlErrorList.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#ifndef CONTROLERRORLIST_H +#define CONTROLERRORLIST_H + + +#include "Dialog.h" +#include + + + +/** A controller for the ErrorList dialog. + */ + + +class ControlErrorList : public Dialog::Controller { +public: + /// A class to hold an error item + struct ErrorItem { + std::string error; + std::string description; + int par_id; + int pos_start; + int pos_end; + ErrorItem(string const &, string const &, int, int, int); + }; + /// + ControlErrorList(Dialog & parent); + /// + virtual bool isBufferDependent() const { return true; } + /// + virtual bool initialiseParams(const string & params); + /// + virtual void ControlErrorList::clearParams(); + /// + virtual void ControlErrorList::dispatchParams() {} + + /// get the current item + int currentItem() const; + /// goto this error in the parent bv + void goTo(int item); + /// return the parent document name + string const & docName(); + /// rescan the log file and rebuild the error list + void fillErrors(); + /// clear everything + void clearErrors(); + /// + std::vector const & ErrorList() const; +private: + /// + std::vector ErrorList_; + /// + string logfilename_; + /// + int current_; +}; + +#endif // CONTROLERRORLIST_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 8a2c5d828f..b827c7d611 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -50,6 +50,8 @@ libcontrollers_la_SOURCES= \ ControlDocument.h \ ControlError.C \ ControlError.h \ + ControlErrorList.C \ + ControlErrorList.h \ ControlERT.C \ ControlERT.h \ ControlExternal.C \ diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 478b52a4d2..b4f0c109eb 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2003-05-12 Alfredo Braunstein + + * QErrorList.[Ch]: + * QErrorListDialog.[Ch]: added + * Makefile.dialogs: + * Makefile.am: the above additions + * Dialogs.C: ditto 2003-05-13 André Pönitz diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 8cbc94a255..df632ca057 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -19,6 +19,7 @@ #include "ControlCharacter.h" #include "ControlCitation.h" #include "ControlError.h" +#include "ControlErrorList.h" #include "ControlERT.h" #include "ControlExternal.h" #include "ControlFloat.h" @@ -42,6 +43,7 @@ #include "QCharacter.h" #include "QCitation.h" #include "QError.h" +#include "QErrorList.h" #include "QERT.h" #include "QExternal.h" #include "QFloat.h" @@ -77,9 +79,9 @@ namespace { char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", -"character", "citation", "error", "ert", "external", "file", "float", -"graphics", "include", "index", "label", "log", "minipage", "paragraph", -"ref", "tabular", "tabularcreate", +"character", "citation", "error", "errorlist", "ert", "external", "file", +"float", "graphics", "include", "index", "label", "log", "minipage", +"paragraph", "ref", "tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -146,6 +148,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlError(*dialog)); dialog->setView(new QError(*dialog)); dialog->bc().bp(new OkCancelPolicy); + } else if (name == "errorlist") { + dialog->setController(new ControlErrorList(*dialog)); + dialog->setView(new QErrorList(*dialog)); + dialog->bc().bp(new OkCancelPolicy); } else if (name == "ert") { dialog->setController(new ControlERT(*dialog)); dialog->setView(new QERT(*dialog)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 61530c558c..ad56368790 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -35,6 +35,7 @@ libqt2_la_SOURCES = \ QCitation.C QCitation.h \ QDocument.C QDocument.h \ QError.C QError.h \ + QErrorList.C QErrorList.h \ QERT.C QERT.h \ QExternal.C QExternal.h \ QFloat.C QFloat.h \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 8e937a9688..8431af2b9d 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -23,6 +23,7 @@ UIFILES = \ QDelimiterDialogBase.ui \ QDocumentDialogBase.ui \ QErrorDialogBase.ui \ + QErrorListDialogBase.ui \ QERTDialogBase.ui \ QExternalDialogBase.ui \ QFloatDialogBase.ui \ @@ -87,6 +88,7 @@ MOCFILES = \ QDelimiterDialog.C QDelimiterDialog.h \ QDocumentDialog.C QDocumentDialog.h \ QErrorDialog.C QErrorDialog.h \ + QErrorListDialog.C QErrorListDialog.h \ QERTDialog.C QERTDialog.h \ QExternalDialog.C QExternalDialog.h \ QFloatDialog.C QFloatDialog.h \ diff --git a/src/frontends/qt2/QErrorList.C b/src/frontends/qt2/QErrorList.C new file mode 100644 index 0000000000..d0e6407114 --- /dev/null +++ b/src/frontends/qt2/QErrorList.C @@ -0,0 +1,68 @@ +/** + * \file QErrorList.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#include + +#include "LyXView.h" +#include "qt_helpers.h" +#include "support/lstrings.h" +#include "debug.h" + +#include "ControlErrorList.h" +#include "QErrorList.h" +#include "QErrorListDialog.h" +#include "Qt2BC.h" + +#include +#include +#include + +typedef QController > base_class; + +QErrorList::QErrorList(Dialog & parent) + : base_class(parent, qt_("LyX: LaTeX error list")) +{} + + +void QErrorList::build_dialog() +{ + dialog_.reset(new QErrorListDialog(this)); + bcview().setCancel(dialog_->closePB); +} + + +void QErrorList::select(int item) +{ + controller().goTo(item); + dialog_->descriptionTB->setText(controller().ErrorList()[item].description); +} + + +void QErrorList::update_contents() +{ + string const caption = string(_("LyX: LaTex error List")) + '(' + + controller().docName() + ')'; + + dialog_->setCaption(qt_(caption)); + dialog_->errorsLB->clear(); + dialog_->descriptionTB->clear(); + + std::vector::const_iterator + it = controller().ErrorList().begin(); + std::vector::const_iterator + end = controller().ErrorList().end(); + for(; it != end; ++it) { + QListBoxItem * error = new QListBoxText(dialog_->errorsLB, + toqstr(it->error)); + } + + dialog_->errorsLB->setSelected(controller().currentItem(), true); +} + diff --git a/src/frontends/qt2/QErrorList.h b/src/frontends/qt2/QErrorList.h new file mode 100644 index 0000000000..65b71cbcd1 --- /dev/null +++ b/src/frontends/qt2/QErrorList.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +/** + * \file QErrorList.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#ifndef QERRORLIST_H +#define QERRORLIST_H + + +#include "QDialogView.h" + +class ControlErrorList; +class QErrorListDialog; + +class QErrorList : + public QController > +{ +public: + friend class QErrorListDialog; + + QErrorList(Dialog &); +private: + /// select an entry + void select(int item); + /// required apply + virtual void apply() {} + /// build dialog + virtual void build_dialog(); + /// update contents + virtual void update_contents(); + /// run latex + void runLaTeX(); +}; + +#endif // QERRORLIST_H diff --git a/src/frontends/qt2/QErrorListDialog.C b/src/frontends/qt2/QErrorListDialog.C new file mode 100644 index 0000000000..2e08b9f253 --- /dev/null +++ b/src/frontends/qt2/QErrorListDialog.C @@ -0,0 +1,47 @@ +/** + * \file QErrorListDialog.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#include + + +#include "QErrorList.h" +#include "QErrorListDialog.h" +#include "qt_helpers.h" + +#include +#include +#include +#include + + +QErrorListDialog::QErrorListDialog(QErrorList * form) + : QErrorListDialogBase(0, 0, false, 0), + form_(form) +{ + connect(closePB, SIGNAL(clicked()), + form, SLOT(slotClose())); +} + + +QErrorListDialog::~QErrorListDialog() +{} + + +void QErrorListDialog::select_adaptor(int item) +{ + form_->select(item); +} + + +void QErrorListDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} diff --git a/src/frontends/qt2/QErrorListDialog.h b/src/frontends/qt2/QErrorListDialog.h new file mode 100644 index 0000000000..03f4c29190 --- /dev/null +++ b/src/frontends/qt2/QErrorListDialog.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +/** + * \file QErrorListDialog.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#ifndef QERRORLISTDIALOG_H +#define QERRORLISTDIALOG_H + + +#include "ui/QErrorListDialogBase.h" + +class QErrorList; + +class QErrorListDialog : public QErrorListDialogBase { + Q_OBJECT +public: + QErrorListDialog(QErrorList * form); + ~QErrorListDialog(); +public slots: + void select_adaptor(int); +protected: + void closeEvent(QCloseEvent * e); +private: + QErrorList * form_; +}; + +#endif // QTOCERRORLIST_H diff --git a/src/frontends/qt2/ui/QErrorListDialogBase.ui b/src/frontends/qt2/ui/QErrorListDialogBase.ui new file mode 100644 index 0000000000..4248ee0bb9 --- /dev/null +++ b/src/frontends/qt2/ui/QErrorListDialogBase.ui @@ -0,0 +1,103 @@ + +QErrorListDialogBase +config.h +qt_helpers.h + + QDialog + + name + QErrorListDialogBase + + + geometry + + 0 + 0 + 349 + 367 + + + + caption + Form1 + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QListBox + + + text + New Item + + + + name + errorsLB + + + + QPushButton + + name + closePB + + + text + &Close + + + + + name + Spacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QTextBrowser + + name + descriptionTB + + + + + + + errorsLB + highlighted(int) + QErrorListDialogBase + select_adaptor(int) + + + + close_adaptor() + select_adaptor(int) + + diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index be29a42d8f..7f06f7e880 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2003-05-12 Alfredo Braunstein + + * FormErrorList.[Ch]: + * forms/form_errorlist.fd: added + * forms/Makefile.am: + * Makefile.am: the above additions + * Dialogs.C: ditto 2003-05-13 André Pönitz diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 8d912149d5..07435c1e53 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -22,6 +22,7 @@ #include "ControlCitation.h" #include "ControlCommand.h" #include "ControlError.h" +#include "ControlErrorList.h" #include "ControlERT.h" #include "ControlExternal.h" #include "ControlFloat.h" @@ -45,6 +46,7 @@ #include "FormCharacter.h" #include "FormCitation.h" #include "FormError.h" +#include "FormErrorList.h" #include "FormERT.h" #include "FormExternal.h" #include "FormFloat.h" @@ -74,10 +76,7 @@ namespace { -char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", -"character", "citation", "error", "ert", "external", "file", "float", -"graphics", "include", "index", "label", "log", "minipage", "paragraph", -"ref", "tabular", "tabularcreate", +char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", "character", "citation", "error", "errorlist" , "ert", "external", "file", "float", "graphics", "include", "index", "label", "log", "minipage", "paragraph", "ref", "tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -144,6 +143,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlError(*dialog)); dialog->setView(new FormError(*dialog)); dialog->bc().bp(new OkCancelPolicy); + } else if (name == "errorlist") { + dialog->setController(new ControlErrorList(*dialog)); + dialog->setView(new FormErrorList(*dialog)); + dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "ert") { dialog->setController(new ControlERT(*dialog)); dialog->setView(new FormERT(*dialog)); diff --git a/src/frontends/xforms/FormErrorList.C b/src/frontends/xforms/FormErrorList.C new file mode 100644 index 0000000000..3b533c764d --- /dev/null +++ b/src/frontends/xforms/FormErrorList.C @@ -0,0 +1,107 @@ +/** + * \file FormErrorList.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#include + + +#include "FormErrorList.h" +#include "xformsBC.h" +#include "xforms_helpers.h" +#include "ControlErrorList.h" +#include "forms/form_errorlist.h" +#include "support/lstrings.h" // frontStrip, strip +#include "debug.h" +#include "gettext.h" +#include FORMS_H_LOCATION + +#include + +using std::vector; +using std::endl; + + +typedef FormController > base_class; + +FormErrorList::FormErrorList(Dialog & parent) + : base_class(parent, _("LaTeX error list")) +{} + + +void FormErrorList::build() +{ + dialog_.reset(build_errorlist(this)); + + // Manage the cancel/close button + bcview().setCancel(dialog_->button_close); + bcview().addReadOnly(dialog_->browser_errors); +} + + +void FormErrorList::update() +{ + updateContents(); +} + + +ButtonPolicy::SMInput FormErrorList::input(FL_OBJECT * ob, long) +{ + std::vector const & + Errors = controller().ErrorList(); + + if (ob == dialog_->browser_errors) { + //xforms return values 1..n + int const choice = int(fl_get_browser(dialog_->browser_errors)) - 1; + if (0 <= choice && choice < int(Errors.size())) { + controller().goTo(choice); + fl_set_input(dialog_->input_description, + Errors[choice].description.c_str()); + } + return ButtonPolicy::SMI_VALID; + } + + updateContents(); + + return ButtonPolicy::SMI_VALID; +} + + +void FormErrorList::updateContents() +{ + std::vector const & + Errors = controller().ErrorList(); + + if (Errors.empty()) { + fl_clear_browser(dialog_->browser_errors); + fl_add_browser_line(dialog_->browser_errors, + _("*** No Lists ***")); + setEnabled(dialog_->browser_errors, false); + return; + } + + unsigned int const topline = + fl_get_browser_topline(dialog_->browser_errors); + unsigned int const line = fl_get_browser(dialog_->browser_errors); + + fl_clear_browser(dialog_->browser_errors); + setEnabled(dialog_->browser_errors, true); + + std::vector::const_iterator + cit = Errors.begin(); + std::vector::const_iterator + end = Errors.end(); + + for (; cit != end; ++cit) { + fl_add_browser_line(dialog_->browser_errors, + cit->error.c_str()); + } + + fl_set_browser_topline(dialog_->browser_errors, topline); + fl_select_browser_line(dialog_->browser_errors, line); +} diff --git a/src/frontends/xforms/FormErrorList.h b/src/frontends/xforms/FormErrorList.h new file mode 100644 index 0000000000..9a544fbac0 --- /dev/null +++ b/src/frontends/xforms/FormErrorList.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +/** + * \file FormErrorList.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Alfredo Braunstein + * + * Full author contact details are available in file CREDITS + */ + +#ifndef FORMERRORLIST_H +#define FORMERRORLIST_H + + +#include "FormDialogView.h" + +class ControlErrorList; +struct FD_errorlist; + +/** This class provides an XForms implementation of the FormErrorList Dialog. + */ +class FormErrorList : public FormController > { +public: + /// + FormErrorList(Dialog &); +private: + /// not needed + virtual void apply() {} + /// Build the dialog + virtual void build(); + /// Update dialog before showing it + virtual void update(); + /// Filter the inputs on callback from xforms + virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); + + /// + void updateContents(); +}; + +#endif // FORMERRORLIST_H diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index fe3dd21d07..d93d94afeb 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -79,6 +79,8 @@ libxforms_la_SOURCES = \ FormDocument.h \ FormError.C \ FormError.h \ + FormErrorList.C \ + FormErrorList.h \ FormERT.C \ FormERT.h \ FormExternal.C \ diff --git a/src/frontends/xforms/forms/Makefile.am b/src/frontends/xforms/forms/Makefile.am index ad69367b1e..4c228b87bc 100644 --- a/src/frontends/xforms/forms/Makefile.am +++ b/src/frontends/xforms/forms/Makefile.am @@ -18,6 +18,7 @@ SRCS = form_aboutlyx.fd \ form_citation.fd \ form_document.fd \ form_error.fd \ + form_errorlist.fd \ form_ert.fd \ form_external.fd \ form_filedialog.fd \ diff --git a/src/frontends/xforms/forms/form_errorlist.fd b/src/frontends/xforms/forms/form_errorlist.fd new file mode 100644 index 0000000000..850308c7b0 --- /dev/null +++ b/src/frontends/xforms/forms/form_errorlist.fd @@ -0,0 +1,89 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL +SnapGrid: 5 + +=============== FORM =============== +Name: form_errorlist +Width: 380 +Height: 295 +Number of Objects: 4 + +-------------------- +class: FL_BOX +type: FLAT_BOX +box: 0 0 380 295 +boxtype: FL_FLAT_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_BROWSER +type: HOLD_BROWSER +box: 10 10 360 110 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_BOTTOM +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NorthWest FL_SouthEast +name: browser_errors +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 280 260 90 25 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Close|^[^M +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: button_close +callback: C_FormDialogView_CancelCB +argument: 0 + +-------------------- +class: FL_INPUT +type: MULTILINE_INPUT +box: 10 125 360 130 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: input_description +callback: +argument: + +============================== +create_the_forms