Add a Bibtex dialog with Herbert's spangly new things + some more.

Filedialogs are crashing with BadWindow X errors - NO idea why.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2588 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2001-08-26 03:20:52 +00:00
parent d459817dee
commit ef3a25c069
8 changed files with 604 additions and 127 deletions

View File

@ -1,3 +1,13 @@
2001-08-26 John Levon <moz@compsoc.man.ac.uk>
* Dialogs.C:
* Makefile.dialogs:
* QBibtex.[Ch]:
* QBibtexDialog.[Ch]:
* ui/QBibtexDialog.ui: added BibTeX dialog.
* README: update
2001-08-26 John Levon <moz@compsoc.man.ac.uk>
* Qt2BC.C: whoops, reversed sense of setReadOnly()

View File

@ -13,12 +13,14 @@
// the dialog definitions
#include "QAboutDialog.h"
#include "QBibtexDialog.h"
#include "QCitationDialog.h"
#include "QIndexDialog.h"
#include "QRefDialog.h"
#include "QURLDialog.h"
#include "QAbout.h"
#include "QBibtex.h"
#include "QCharacter.h"
#include "QCitation.h"
#include "QIndex.h"
@ -36,14 +38,9 @@
#include "buffer.h"
#include "Qt2BC.h"
// xforms implementations
#include "../xforms/FormError.h"
#include "../xforms/FormGraphics.h"
#include "../xforms/FormPreferences.h"
#include "../xforms/FormTabular.h"
// the controllers
#include "controllers/ControlAboutlyx.h"
#include "controllers/ControlBibtex.h"
#include "controllers/ControlCitation.h"
#include "controllers/ControlIndex.h"
#include "controllers/ControlRef.h"
@ -53,7 +50,6 @@
#include "controllers/ControlCopyright.h"
#include "controllers/ControlCredits.h"
#include "controllers/ControlBibitem.h"
#include "controllers/ControlBibtex.h"
#include "controllers/ControlButtons.h"
#include "controllers/ControlCharacter.h"
#include "controllers/ControlCitation.h"
@ -91,6 +87,7 @@ Dialogs::Dialogs(LyXView * lv)
// dialogs that have been converted to new scheme
add(new GUICitation<QCitation, Qt2BC>(*lv, *this));
add(new GUIAboutlyx<QAbout, Qt2BC>(*lv, *this));
add(new GUIBibtex<QBibtex, Qt2BC>(*lv, *this));
add(new GUIIndex<QIndex, Qt2BC>(*lv, *this));
add(new GUIRef<QRef, Qt2BC>(*lv, *this));
add(new GUIUrl<QURL, Qt2BC>(*lv, *this));

132
src/frontends/qt2/QBibtex.C Normal file
View File

@ -0,0 +1,132 @@
/**
* \file QBibtex.C
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#include <config.h>
#include "support/lstrings.h"
#include "QBibtexDialog.h"
#include "ControlBibtex.h"
#include "QBibtex.h"
#include "Qt2BC.h"
#include "gettext.h"
#include "debug.h"
#include <qlineedit.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qlistbox.h>
#include <qcheckbox.h>
typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
QBibtex::QBibtex(ControlBibtex & c)
: base_class(c, _("BibTeX"))
{
}
void QBibtex::build_dialog()
{
dialog_.reset(new QBibtexDialog(this));
bc().setOK(dialog_->okPB);
bc().setCancel(dialog_->closePB);
bc().addReadOnly(dialog_->databaseLB);
bc().addReadOnly(dialog_->databasePB);
bc().addReadOnly(dialog_->styleCO);
bc().addReadOnly(dialog_->styleED);
bc().addReadOnly(dialog_->stylePB);
bc().addReadOnly(dialog_->bibtocCB);
}
void QBibtex::update_contents()
{
dialog_->databaseLB->clear();
string bibs(controller().params().getContents());
string bib;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
dialog_->databaseLB->inSort(frontStrip(strip(bib)).c_str());
}
string bibtotoc = "bibtotoc";
string bibstyle(controller().params().getOptions().c_str());
// bibtotoc exists?
if (prefixIs(bibstyle,bibtotoc)) {
dialog_->bibtocCB->setChecked(true);
// bibstyle exists?
if (contains(bibstyle,','))
bibstyle = split(bibstyle, bibtotoc, ',');
else
bibstyle = "";
} else
dialog_->bibtocCB->setChecked(false);
dialog_->styleED->setEnabled(false);
dialog_->stylePB->setEnabled(false);
if (bibstyle == "plain")
dialog_->styleCO->setCurrentItem(0);
else if (bibstyle == "unsrt")
dialog_->styleCO->setCurrentItem(1);
else if (bibstyle == "alpha")
dialog_->styleCO->setCurrentItem(2);
else if (bibstyle == "abbrv")
dialog_->styleCO->setCurrentItem(3);
else {
dialog_->styleED->setEnabled(true);
dialog_->stylePB->setEnabled(true);
dialog_->styleED->setText(bibstyle.c_str());
if (bibstyle.empty())
dialog_->styleCO->setCurrentItem(0);
else
dialog_->styleCO->setCurrentItem(4);
}
}
void QBibtex::apply()
{
string dbs;
for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
dbs += dialog_->databaseLB->text(i).latin1();
if (i != dialog_->databaseLB->count())
dbs += ", ";
}
controller().params().setContents(dbs);
string bibstyle(dialog_->styleCO->currentText().latin1());
if (bibstyle == _("Other ..."))
bibstyle = dialog_->styleED->text().latin1();
bool const bibtotoc(dialog_->bibtocCB->isChecked());
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc," + bibstyle);
} else if (bibtotoc) {
// bibtotoc and no style
controller().params().setOptions("bibtotoc");
} else if (!bibstyle.empty()){
// only style
controller().params().setOptions(bibstyle);
}
}
bool QBibtex::isValid()
{
return dialog_->databaseLB->count() != 0;
}

View File

@ -0,0 +1,38 @@
// -*- C++ -*-
/**
* \file QBibtex.h
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QBIBTEX_H
#define QBIBTEX_H
#include "Qt2Base.h"
class ControlBibtex;
class QBibtexDialog;
class QBibtex :
public Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> >
{
friend class QBibtexDialog;
public:
QBibtex(ControlBibtex &);
protected:
virtual bool isValid();
private:
/// Apply changes
virtual void apply();
/// update
virtual void update_contents();
/// build the dialog
virtual void build_dialog();
};
#endif // QBIBTEX_H

View File

@ -0,0 +1,86 @@
/**
* \file QBibtexDialog.C
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#include <qwidget.h>
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qlistbox.h>
#include <qcheckbox.h>
#include <qfiledialog.h>
#include "QBibtexDialog.h"
#include "QBibtex.h"
#include "Dialogs.h"
#include "ControlBibtex.h"
#include "gettext.h"
#include "support/filetools.h"
QBibtexDialog::QBibtexDialog(QBibtex * form)
: QBibtexDialogBase(0, 0, false, 0),
form_(form)
{
connect(okPB, SIGNAL(clicked()),
form, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()),
form, SLOT(slotClose()));
}
QBibtexDialog::~QBibtexDialog()
{
}
void QBibtexDialog::change_adaptor()
{
form_->changed();
}
void QBibtexDialog::browsePressed()
{
string file(QFileDialog::getOpenFileName(QString::null,
_("BibTeX style files (*.bst)"), this, 0, _("Select a BibTeX style")).latin1());
if (!file.empty()) {
styleED->setText(ChangeExtension(OnlyFilename(file), "").c_str());
form_->changed();
}
}
void QBibtexDialog::addPressed()
{
string file(QFileDialog::getOpenFileName(QString::null,
_("BibTeX database files (*.bib)"), this, 0, _("Select a BibTeX database to add")).latin1());
if (!file.empty()) {
// FIXME: check duplicates
databaseLB->insertItem(ChangeExtension(file, "").c_str());
form_->changed();
}
}
void QBibtexDialog::styleChanged(const QString & sel)
{
if (string(_("Other ...")) == sel.latin1() && !form_->readOnly()) {
styleED->setEnabled(true);
stylePB->setEnabled(true);
} else {
styleED->setEnabled(false);
stylePB->setEnabled(false);
styleED->setText("");
}
}
void QBibtexDialog::closeEvent(QCloseEvent *e)
{
form_->slotWMHide();
e->accept();
}

View File

@ -0,0 +1,39 @@
/**
* \file QBibtexDialog.h
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QBIBTEXDIALOG_H
#define QBIBTEXDIALOG_H
#include <config.h>
#include "ui/QBibtexDialogBase.h"
class QBibtex;
class QBibtexDialog : public QBibtexDialogBase
{ Q_OBJECT
public:
QBibtexDialog(QBibtex * form);
~QBibtexDialog();
protected slots:
virtual void change_adaptor();
virtual void browsePressed();
virtual void addPressed();
virtual void styleChanged(const QString &);
protected:
virtual void closeEvent(QCloseEvent * e);
private:
QBibtex * form_;
};
#endif // QBIBTEXDIALOG_H

View File

@ -54,6 +54,8 @@ PB - push button
Dialog Maintainer MVC conversion
----------------------------------------------
About John Done
Bibtex John Done
Character Edwin
Citation Kalle Done
Document Kalle Waiting for MVC

View File

@ -11,8 +11,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>307</width>
<height>232</height>
<width>302</width>
<height>407</height>
</rect>
</property>
<property stdset="1">
@ -32,9 +32,9 @@
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout7</cstring>
<cstring>Layout13</cstring>
</property>
<hbox>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
@ -51,37 +51,128 @@
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Database</string>
<string>Databases</string>
</property>
<property>
<name>buddy</name>
<cstring>databaseED</cstring>
<cstring>databaseCO</cstring>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignTop|AlignLeft</set>
</property>
<property>
<name>toolTip</name>
<string>BibTeX database to use</string>
</property>
<property>
<name>vAlign</name>
</property>
</widget>
<widget>
<class>QLineEdit</class>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>databaseED</cstring>
</property>
<property>
<name>toolTip</name>
<string>BibTeX database to use</string>
<cstring>Layout12</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>QListBox</class>
<item>
<property>
<name>text</name>
<string>New Item</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>databaseLB</cstring>
</property>
<property stdset="1">
<name>enabled</name>
<bool>true</bool>
</property>
<property>
<name>toolTip</name>
<string>Available BibTeX databases</string>
</property>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout11</cstring>
</property>
<vbox>
<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>databasePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Add ...</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
<property>
<name>toolTip</name>
<string>Add a BibTeX database file</string>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Vertical</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>
</vbox>
</widget>
</hbox>
</widget>
</hbox>
</vbox>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout12</cstring>
<cstring>Layout16</cstring>
</property>
<hbox>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
@ -109,86 +200,157 @@
<string>The BibTeX style</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>QComboBox</class>
<item>
<property>
<name>text</name>
<string>plain</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>unsrt</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>alpha</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>abbrv</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Other ...</string>
</property>
</item>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>styleCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>The BibTeX style</string>
</property>
<property>
<name>whatsThis</name>
<string>FIXME !</string>
<cstring>Layout14</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>QComboBox</class>
<item>
<property>
<name>text</name>
<string>plain</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>unsrt</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>alpha</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>abbrv</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Other ...</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>styleCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>The BibTeX style</string>
</property>
<property>
<name>whatsThis</name>
<string>FIXME !</string>
</property>
</widget>
<widget>
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>styleED</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>The name of the style to use</string>
</property>
</widget>
</hbox>
</widget>
</hbox>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout15</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<spacer>
<property>
<name>name</name>
<cstring>Spacer1_2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>MinimumExpanding</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>stylePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Browse</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
<property>
<name>toolTip</name>
<string>Choose a style file</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout11</cstring>
<cstring>Layout8</cstring>
</property>
<hbox>
<property stdset="1">
@ -199,10 +361,25 @@
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>bibtocCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Add bibliography to &amp;TOC</string>
</property>
<property>
<name>toolTip</name>
<string>Add bibliography to the table of contents</string>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer2</cstring>
<cstring>Spacer1_3</cstring>
</property>
<property stdset="1">
<name>orientation</name>
@ -220,24 +397,6 @@
</size>
</property>
</spacer>
<widget>
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>styleED</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>The name of the style to use</string>
</property>
</widget>
</hbox>
</widget>
<widget>
@ -307,31 +466,45 @@
</vbox>
</widget>
<connections>
<connection>
<sender>databasePB</sender>
<signal>clicked()</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>addPressed()</slot>
</connection>
<connection>
<sender>stylePB</sender>
<signal>clicked()</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>browsePressed()</slot>
</connection>
<connection>
<sender>bibtocCB</sender>
<signal>toggled(bool)</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>styleCO</sender>
<signal>textChanged(const QString&amp;)</signal>
<signal>activated(int)</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>styleCO</sender>
<signal>activated(const QString&amp;)</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>styleChanged(const QString &amp;)</slot>
</connection>
<connection>
<sender>styleCO</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>changed_adaptor()</slot>
</connection>
<connection>
<sender>styleED</sender>
<signal>textChanged(const QString&amp;)</signal>
<signal>returnPressed()</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>changed_adaptor()</slot>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>databaseED</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QBibtexDialogBase</receiver>
<slot>changed_adaptor()</slot>
</connection>
<slot access="public">changed_adaptor()</slot>
<slot access="public">addPressed()</slot>
<slot access="public">browsePressed()</slot>
<slot access="public">change_adaptor()</slot>
<slot access="public">styleChanged(const QString &amp;)</slot>
</connections>
</UI>