diff --git a/ChangeLog b/ChangeLog index 6e71b05fb8..241e1a5fb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,15 @@ (via an open call) are not requested to be named again on the first save! +2000-09-13 John Levon + + * src/frontends/kde/Makefile.am + * src/frontends/kde/FormRef.C + * src/frontends/kde/FormRef.h + * src/frontends/kde/formrefdialog.C + * src/frontends/kde/formrefdialog.h: implement + cross-ref dialog + 2000-09-13 John Levon * src/frontends/kde/formtocdialog.C diff --git a/src/frontends/kde/FormRef.C b/src/frontends/kde/FormRef.C new file mode 100644 index 0000000000..54cc417fba --- /dev/null +++ b/src/frontends/kde/FormRef.C @@ -0,0 +1,259 @@ +/* + * FormRef.C + * (C) 2000 LyX Team + * John Levon, moz@compsoc.man.ac.uk + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include + +#include "Dialogs.h" +#include "FormRef.h" +#include "gettext.h" +#include "buffer.h" +#include "LyXView.h" +#include "lyxfunc.h" +#include "formrefdialog.h" +#include "debug.h" + +FormRef::FormRef(LyXView *v, Dialogs *d) + : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0), + sort(0), gotowhere(GOTOREF), type(REF), refs(0) +{ + // let the dialog be shown + // This is a permanent connection so we won't bother + // storing a copy because we won't be disconnecting. + d->showRef.connect(slot(this, &FormRef::showRef)); + d->createRef.connect(slot(this, &FormRef::createRef)); +} + +FormRef::~FormRef() +{ + delete dialog_; +} + +void FormRef::showRef(InsetCommand * const inset) +{ + // FIXME: when could inset be 0 here ? + if (inset==0) + return; + + inset_ = inset; + readonly = lv_->buffer()->isReadonly(); + ih_ = inset_->hide.connect(slot(this,&FormRef::hide)); + params = inset->params(); + + show(); +} + +void FormRef::createRef(string const & arg) +{ + if (inset_) + close(); + + readonly = lv_->buffer()->isReadonly(); + params.setFromString(arg); + show(); +} + +void FormRef::select(const char *text) +{ + params.setContents(text); + lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + gotowhere = GOTOREF; + dialog_->buttonGoto->setText(_("&Goto reference")); + dialog_->buttonGoto->setEnabled(true); + if (!readonly) { + dialog_->type->setEnabled(true); + dialog_->reference->setText(text); + dialog_->buttonOk->setEnabled(true); + } +} + +void FormRef::set_sort(bool on) +{ + if (on!=sort) { + sort=on; + dialog_->refs->clear(); + updateRefs(); + } +} + +void FormRef::goto_ref() +{ + switch (gotowhere) { + case GOTOREF: + lv_->getLyXFunc()->Dispatch(LFUN_REF_GOTO, params.getContents().c_str()); + gotowhere=GOTOBACK; + dialog_->buttonGoto->setText(_("&Go back")); + break; + case GOTOBACK: + lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK, params.getContents().c_str()); + gotowhere=GOTOREF; + dialog_->buttonGoto->setText(_("&Goto reference")); + break; + } +} + +void FormRef::updateRefs() +{ + dialog_->refs->setAutoUpdate(false); + + for (vector< string >::const_iterator iter = refs.begin(); + iter != refs.end(); ++iter) { + if (sort) + dialog_->refs->inSort(iter->c_str()); + else + dialog_->refs->insertItem(iter->c_str()); + } + dialog_->refs->setAutoUpdate(true); + dialog_->refs->update(); +} + +void FormRef::update() +{ + dialog_->reference->setText(params.getContents().c_str()); + dialog_->refname->setText(params.getOptions().c_str()); + + if (params.getCmdName()=="prettyref") { + type = PRETTYREF; + dialog_->type->setCurrentItem(4); + } else if (params.getCmdName()=="pageref") { + type = PAGEREF; + dialog_->type->setCurrentItem(1); + } else if (params.getCmdName()=="vref") { + type = VREF; + dialog_->type->setCurrentItem(2); + } else if (params.getCmdName()=="vpageref") { + type = VPAGEREF; + dialog_->type->setCurrentItem(3); + } else { + type = REF; + dialog_->type->setCurrentItem(0); + } + + dialog_->buttonGoto->setText(_("&Goto reference")); + + gotowhere = GOTOREF; + + dialog_->sort->setChecked(sort); + + dialog_->refs->clear(); + dialog_->type->setEnabled(false); + + if (inset_) { + // FIXME: should totally remove and re-size dialog, + // but doesn't seem easily possible + dialog_->refs->hide(); + dialog_->labelrefs->hide(); + dialog_->sort->hide(); + dialog_->buttonUpdate->hide(); + dialog_->buttonGoto->setEnabled(true); + } else { + dialog_->refs->show(); + dialog_->labelrefs->show(); + dialog_->sort->show(); + dialog_->buttonUpdate->show(); + refs = lv_->buffer()->getLabelList(); + if (!refs.empty()) + dialog_->sort->setEnabled(true); + updateRefs(); + } + + if (params.getContents()=="") { + dialog_->buttonGoto->setEnabled(false); + dialog_->buttonOk->setEnabled(false); + } else { + dialog_->buttonGoto->setEnabled(true); + dialog_->buttonOk->setEnabled(true); + } + + if (readonly) { + dialog_->type->setEnabled(false); + dialog_->buttonOk->setEnabled(false); + dialog_->buttonUpdate->setEnabled(false); + dialog_->buttonCancel->setText(_("&Close")); + } else { + dialog_->type->setEnabled(true); + dialog_->buttonUpdate->setEnabled(true); + dialog_->buttonCancel->setText(_("&Cancel")); + } +} + +void FormRef::apply() +{ + if (readonly) + return; + + if (!lv_->view()->available()) + return; + + switch (dialog_->type->currentItem()) { + case 0: + params.setCmdName("ref"); + break; + case 1: + params.setCmdName("pageref"); + break; + case 2: + params.setCmdName("vref"); + break; + case 3: + params.setCmdName("vpageref"); + break; + case 4: + params.setCmdName("prettyref"); + break; + default: + lyxerr[Debug::GUI] << "Unknown Ref Type" << endl; + } + + params.setOptions(dialog_->refname->text()); + + if (inset_ != 0) { + if (params != inset_->params()) { + inset_->setParams(params); + lv_->view()->updateInset(inset_, true); + } + } else + lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT, params.getAsString().c_str()); +} + +void FormRef::show() +{ + if (!dialog_) + dialog_ = new FormRefDialog(this, 0, _("LyX: Cross Reference"), false); + + if (!dialog_->isVisible()) { + h_ = d_->hideBufferDependent.connect(slot(this, &FormRef::hide)); + u_ = d_->updateBufferDependent.connect(slot(this, &FormRef::update)); + } + + dialog_->raise(); + dialog_->setActiveWindow(); + + update(); + dialog_->show(); +} + +void FormRef::close() +{ + h_.disconnect(); + u_.disconnect(); + ih_.disconnect(); + inset_ = 0; +} + +void FormRef::hide() +{ + dialog_->hide(); + close(); +} diff --git a/src/frontends/kde/FormRef.h b/src/frontends/kde/FormRef.h new file mode 100644 index 0000000000..4c01b63212 --- /dev/null +++ b/src/frontends/kde/FormRef.h @@ -0,0 +1,109 @@ +/* FormRef.h + * (C) 2000 LyX Team + * John Levon, moz@compsoc.man.ac.uk + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef FORMREF_H +#define FORMREF_H + +#include "DialogBase.h" +#include "LString.h" +#include "support/utility.hpp" +#include "insets/insetcommand.h" + +class Dialogs; +class LyXView; +class FormRefDialog; + +class FormRef : public DialogBase, public noncopyable { +public: + /**@name Constructors and Destructors */ + //@{ + /// + FormRef(LyXView *, Dialogs *); + /// + ~FormRef(); + //@} + + /// select a ref + void select(const char *); + /// set sort + void set_sort(bool); + /// goto a ref (or back) + void goto_ref(); + /// update dialog + void update(); + /// Apply changes + void apply(); + /// close the connections + void close(); + +private: + enum Type { + REF, PAGEREF, VREF, VPAGEREF, PRETTYREF, + }; + + enum GotoType { + GOTOREF, GOTOBACK, + }; + + /// Create the dialog if necessary, update it and display it. + void show(); + /// Hide the dialog. + void hide(); + + /// create a Reference inset + void createRef(string const &); + /// edit a Reference inset + void showRef(InsetCommand * const); + + /// update the keys list + void updateRefs(void); + + /// Real GUI implementation. + FormRefDialog * dialog_; + + /// the LyXView we belong to + LyXView * lv_; + + /** Which Dialogs do we belong to? + Used so we can get at the signals we have to connect to. + */ + Dialogs * d_; + /// pointer to the inset if any + InsetCommand * inset_; + /// insets params + InsetCommandParams params; + /// is the inset we are reading from a readonly buffer ? + bool readonly; + + /// Hide connection. + Connection h_; + /// Update connection. + Connection u_; + /// Inset hide connection. + Connection ih_; + + /// to sort or not to sort + bool sort; + + /// where to go + GotoType gotowhere; + + /// current type + Type type; + + /// available references + std::vector< string > refs; +}; + +#endif diff --git a/src/frontends/kde/Makefile.am b/src/frontends/kde/Makefile.am index 8f955abb40..c98a3a331c 100644 --- a/src/frontends/kde/Makefile.am +++ b/src/frontends/kde/Makefile.am @@ -10,7 +10,8 @@ BUILTSOURCES = formcopyrightdialog_moc.C \ formurldialog_moc.C \ formindexdialog_moc.C \ formcitationdialog_moc.C \ - formtocdialog_moc.C + formtocdialog_moc.C \ + formrefdialog_moc.C DISTCLEANFILES = $(BUILTSOURCES) *.orig *.rej *~ *.bak core @@ -24,8 +25,6 @@ libkde_la_OBJADD = \ ../xforms/form_preferences.lo \ ../xforms/FormPrint.lo \ ../xforms/form_print.lo \ - ../xforms/FormRef.lo \ - ../xforms/form_ref.lo \ ../xforms/FormTabular.lo \ ../xforms/form_tabular.lo \ ../xforms/input_validators.lo \ @@ -61,6 +60,10 @@ libkde_la_SOURCES = \ FormToc.h \ formtocdialog.C \ formtocdialog.h \ + FormRef.C \ + FormRef.h \ + formrefdialog.C \ + formrefdialog.h \ $(BUILTSOURCES) # These still have to be added. Sooner or later. ARRae-20000129 @@ -106,3 +109,7 @@ formcitationdialog_moc.C: formcitationdialog.h formtocdialog.C: formtocdialog_moc.C formtocdialog_moc.C: formtocdialog.h $(MOC) formtocdialog.h -o formtocdialog_moc.C + +formrefdialog.C: formrefdialog_moc.C +formrefdialog_moc.C: formrefdialog.h + $(MOC) formrefdialog.h -o formrefdialog_moc.C diff --git a/src/frontends/kde/formrefdialog.C b/src/frontends/kde/formrefdialog.C new file mode 100644 index 0000000000..c3283602e2 --- /dev/null +++ b/src/frontends/kde/formrefdialog.C @@ -0,0 +1,174 @@ +/* + * formrefdialog.C + * (C) 2000 LyX Team + * John Levon, moz@compsoc.man.ac.uk + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "formrefdialog.h" + +FormRefDialog::FormRefDialog(FormRef *form, QWidget *parent, const char *name, bool, WFlags) + : QDialog(parent,name,false), form_(form) +{ + setCaption(name); + + // widgets + + refs = new QListBox(this); + refs->setMinimumSize(200,200); + + labelrefs = new QLabel(this); + labelrefs->setText(_("Available References")); + labelrefs->setMargin(5); + labelrefs->setMinimumSize(labelrefs->sizeHint()); + labelrefs->setMaximumSize(labelrefs->sizeHint()); + + refname = new QLineEdit(this); + refname->setMinimumSize(refname->sizeHint()); + // FIXME: should user be able to edit this ? what's it for ? - jbl + refname->setFocusPolicy(QWidget::NoFocus); + + reference = new QLineEdit(this); + reference->setMinimumSize(reference->sizeHint()); + reference->setFocusPolicy(QWidget::NoFocus); + + labelrefname = new QLabel(this); + labelrefname->setText(_("Name :")); + labelrefname->setMargin(5); + labelrefname->setMinimumSize(labelrefname->sizeHint()); + labelrefname->setMaximumSize(labelrefname->sizeHint()); + + labelreference = new QLabel(this); + labelreference->setText(_("Reference :")); + labelreference->setMargin(5); + labelreference->setMinimumSize(labelreference->sizeHint()); + labelreference->setMaximumSize(labelreference->sizeHint()); + + sort = new QCheckBox(this); + sort->setText(_("Sort")); + sort->setMinimumSize(sort->sizeHint()); + sort->setMaximumSize(sort->sizeHint()); + + type = new QComboBox(this); + type->insertItem(_("Reference")); + type->insertItem(_("Page number")); + type->insertItem(_("Ref on page xxx")); + type->insertItem(_("on page xxx")); + type->insertItem(_("Pretty reference")); + type->setMinimumSize(type->sizeHint()); + + labeltype = new QLabel(this); + labeltype->setText(_("Reference Type")); + labeltype->setMargin(5); + labeltype->setMinimumSize(labeltype->sizeHint()); + labeltype->setMaximumSize(labeltype->sizeHint()); + + buttonGoto = new QPushButton(this); + buttonGoto->setText(_("&Goto reference")); + buttonGoto->setMinimumSize(buttonGoto->sizeHint()); + buttonGoto->setMaximumSize(buttonGoto->sizeHint()); + + buttonUpdate = new QPushButton(this); + buttonUpdate->setText(_("&Update")); + buttonUpdate->setMinimumSize(buttonUpdate->sizeHint()); + buttonUpdate->setMaximumSize(buttonUpdate->sizeHint()); + + buttonOk = new QPushButton(this); + buttonOk->setText(_("&OK")); + buttonOk->setMinimumSize(buttonOk->sizeHint()); + buttonOk->setMaximumSize(buttonOk->sizeHint()); + buttonOk->setDefault(true); + + buttonCancel = new QPushButton(this); + buttonCancel->setText(_("&Cancel")); + buttonCancel->setMinimumSize(buttonCancel->sizeHint()); + buttonCancel->setMaximumSize(buttonCancel->sizeHint()); + + // tooltips + + QToolTip::add(type,_("Reference as it appears in output")); + QToolTip::add(sort,_("Sort references in alphabetical order ?")); + + // layouts + + topLayout = new QHBoxLayout(this,10); + + layout = new QVBoxLayout(); + topLayout->addLayout(layout); + layout->addSpacing(10); + + upperLayout = new QHBoxLayout(); + layout->addLayout(upperLayout, 1); + + browserLayout = new QVBoxLayout(); + upperLayout->addLayout(browserLayout, 1); + + browserLayout->addWidget(labelrefs, 0); + browserLayout->addWidget(refs, 1); + + rightLayout = new QVBoxLayout(); + upperLayout->addLayout(rightLayout, 1); + + nameLayout = new QHBoxLayout(); + rightLayout->addLayout(nameLayout, 0); + + nameLayout->addWidget(labelrefname, 0); + nameLayout->addWidget(refname, 1); + + rightLayout->addStretch(1); + + referenceLayout = new QHBoxLayout(); + rightLayout->addLayout(referenceLayout, 0); + + referenceLayout->addWidget(labelreference, 0); + referenceLayout->addWidget(reference, 1); + + rightLayout->addStretch(1); + + rightLayout->addWidget(labeltype, 0); + rightLayout->addWidget(type, 0); + + rightLayout->addStretch(1); + + rightLayout->addWidget(buttonGoto, 1); + + rightLayout->addStretch(1); + + buttonLayout = new QHBoxLayout(); + layout->addLayout(buttonLayout); + buttonLayout->addWidget(sort, 1); + buttonLayout->addStretch(1); + buttonLayout->addWidget(buttonUpdate, 1); + buttonLayout->addStretch(1); + buttonLayout->addWidget(buttonOk, 1); + buttonLayout->addStretch(2); + buttonLayout->addWidget(buttonCancel, 1); + buttonLayout->addStretch(1); + + // connections + + connect(refs, SIGNAL(highlighted(const char *)), this, SLOT(highlight_adaptor(const char *))); + connect(sort, SIGNAL(toggled(bool)), this, SLOT(sort_adaptor(bool))); + connect(buttonOk, SIGNAL(clicked()), this, SLOT(apply_adaptor())); + connect(buttonUpdate, SIGNAL(clicked()), this, SLOT(update_adaptor())); + connect(buttonGoto, SIGNAL(clicked()), this, SLOT(goto_adaptor())); + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(close_adaptor())); +} + +void FormRefDialog::closeEvent(QCloseEvent *e) +{ + form_->close(); + e->accept(); +} + +FormRefDialog::~FormRefDialog() +{ +} diff --git a/src/frontends/kde/formrefdialog.h b/src/frontends/kde/formrefdialog.h new file mode 100644 index 0000000000..d96d2267b0 --- /dev/null +++ b/src/frontends/kde/formrefdialog.h @@ -0,0 +1,109 @@ +/* + * formrefdialog.h + * (C) 2000 LyX Team + * John Levon, moz@compsoc.man.ac.uk + */ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef FORMREFDIALOG_H +#define FORMREFDIALOG_H + +#include +#include + +#include "FormRef.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class FormRefDialog : public QDialog { + Q_OBJECT +public: + FormRefDialog(FormRef *form, QWidget *parent=0, const char *name=0, + bool modal=false, WFlags f=0); + ~FormRefDialog(); + + // widgets + + QListBox *refs; + QLabel *labelrefs; + QLineEdit *refname; + QLineEdit *reference; + QLabel *labelrefname; + QLabel *labelreference; + QCheckBox *sort; + QComboBox *type; + QLabel *labeltype; + QPushButton *buttonGoto; + QPushButton *buttonUpdate; + QPushButton *buttonOk; + QPushButton *buttonCancel; + +protected: + void closeEvent(QCloseEvent *e); + +private: + FormRef *form_; + + // layouts + + QHBoxLayout *topLayout; + QVBoxLayout *layout; + QHBoxLayout *upperLayout; + QVBoxLayout *browserLayout; + QVBoxLayout *rightLayout; + QHBoxLayout *nameLayout; + QHBoxLayout *referenceLayout; + QHBoxLayout *buttonLayout; + +private slots: + /// adaptor to FormRef::select + void highlight_adaptor(const char *sel) { + form_->select(sel); + } + + /// adaptor to FormRef::set_sort + void sort_adaptor(bool sort) { + form_->set_sort(sort); + } + + /// adaptor to FormRef::gotoRef + void goto_adaptor(void) { + form_->goto_ref(); + } + + /// adaptor to FormRef::update + void update_adaptor(void) { + form_->update(); + } + + /// adaptor to FormRef::apply + void apply_adaptor(void) { + form_->apply(); + form_->close(); + hide(); + } + + /// adaptor to FormRef::close + void close_adaptor(void) { + form_->close(); + hide(); + } +}; + +#endif