next ones

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20819 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-07 14:41:49 +00:00
parent b352c78905
commit 99c9b0fbcf
7 changed files with 100 additions and 66 deletions

View File

@ -19,7 +19,6 @@
#include "GuiDelimiter.h"
#include "GuiIndex.h"
#include "GuiMathMatrix.h"
#include "GuiNomencl.h"
#include "GuiView.h"
// Uncomment this if you prefer dock widget
@ -92,7 +91,7 @@ Dialog * createGuiLabel(LyXView & lv);
Dialog * createGuiListings(LyXView & lv);
Dialog * createGuiLog(LyXView & lv);
Dialog * createGuiMath(LyXView & lv);
Dialog * createGuiNomencl(LyXView & lv);
Dialog * createGuiNomenclature(LyXView & lv);
Dialog * createGuiNote(LyXView & lv);
Dialog * createGuiParagraph(LyXView & lv);
Dialog * createGuiPreferences(LyXView & lv);
@ -163,7 +162,7 @@ Dialog * Dialogs::build(string const & name)
if (name == "index")
return new GuiIndexDialog(lyxview_);
if (name == "nomenclature")
return new GuiNomenclDialog(lyxview_);
return createGuiNomenclature(lyxview_);
if (name == "label")
return new GuiLabelDialog(lyxview_);
if (name == "log")

View File

@ -267,4 +267,49 @@ void GuiDialog::closeEvent(QCloseEvent * e)
} // namespace frontend
} // namespace lyx
/////////////////////////////////////////////////////////////////////
//
// Command based dialogs
//
/////////////////////////////////////////////////////////////////////
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
using std::string;
namespace lyx {
namespace frontend {
GuiCommand::GuiCommand(LyXView & lv, string const & name)
: GuiDialog(lv, name), Controller(this), params_(name), lfun_name_(name)
{
setController(this, false);
}
bool GuiCommand::initialiseParams(string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommandMailer::string2params(lfun_name_, data, params_);
return true;
}
void GuiCommand::dispatchParams()
{
if (lfun_name_.empty())
return;
string const lfun =
InsetCommandMailer::params2string(lfun_name_, params_);
dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
} // namespace lyx
#include "GuiDialog_moc.cpp"

View File

@ -15,6 +15,8 @@
#include "Dialog.h"
#include "ButtonController.h"
#include "insets/InsetCommandParams.h"
#include <QDialog>
#include <QObject>
@ -164,6 +166,31 @@ private:
LyXView * lyxview_; // FIXME: replace by moving to constructor
};
class GuiCommand : public GuiDialog, public Controller
{
public:
/// We need to know with what sort of inset we're associated.
GuiCommand(LyXView &, std::string const & name);
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
protected:
///
InsetCommandParams params_;
//FIXME It should be possible to eliminate lfun_name_
//now and recover that information from params().insetType().
//But let's not do that quite yet.
/// Flags what action is taken by Kernel::dispatch()
std::string const lfun_name_;
};
} // namespace frontend
} // namespace lyx

View File

@ -14,7 +14,6 @@
#include "GuiNomencl.h"
#include "debug.h"
#include "ControlCommand.h"
#include "qt_helpers.h"
#include <QLabel>
@ -29,15 +28,14 @@ using std::string;
namespace lyx {
namespace frontend {
GuiNomenclDialog::GuiNomenclDialog(LyXView & lv)
: GuiDialog(lv, "nomenclature")
GuiNomenclature::GuiNomenclature(LyXView & lv)
: GuiCommand(lv, "nomenclature")
{
setupUi(this);
setController(new ControlCommand(*this, "nomenclature"));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(symbolED, SIGNAL(textChanged(const QString&)),
connect(symbolED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(descriptionTE, SIGNAL(textChanged()),
this, SLOT(change_adaptor()));
@ -53,36 +51,30 @@ GuiNomenclDialog::GuiNomenclDialog(LyXView & lv)
}
ControlCommand & GuiNomenclDialog::controller()
{
return static_cast<ControlCommand &>(GuiDialog::controller());
}
void GuiNomenclDialog::change_adaptor()
void GuiNomenclature::change_adaptor()
{
changed();
}
void GuiNomenclDialog::reject()
void GuiNomenclature::reject()
{
slotClose();
}
void GuiNomenclDialog::closeEvent(QCloseEvent * e)
void GuiNomenclature::closeEvent(QCloseEvent * e)
{
slotClose();
e->accept();
}
void GuiNomenclDialog::updateContents()
void GuiNomenclature::updateContents()
{
prefixED->setText(toqstr(controller().params()["prefix"]));
symbolED->setText(toqstr(controller().params()["symbol"]));
QString description = toqstr(controller().params()["description"]);
prefixED->setText(toqstr(params_["prefix"]));
symbolED->setText(toqstr(params_["symbol"]));
QString description = toqstr(params_["description"]);
description.replace("\\\\","\n");
descriptionTE->setPlainText(description);
@ -90,22 +82,29 @@ void GuiNomenclDialog::updateContents()
}
void GuiNomenclDialog::applyView()
void GuiNomenclature::applyView()
{
controller().params()["prefix"] = qstring_to_ucs4(prefixED->text());
controller().params()["symbol"] = qstring_to_ucs4(symbolED->text());
params_["prefix"] = qstring_to_ucs4(prefixED->text());
params_["symbol"] = qstring_to_ucs4(symbolED->text());
QString description = descriptionTE->toPlainText();
description.replace('\n',"\\\\");
controller().params()["description"] = qstring_to_ucs4(description);
params_["description"] = qstring_to_ucs4(description);
}
bool GuiNomenclDialog::isValid()
bool GuiNomenclature::isValid()
{
QString const description = descriptionTE->toPlainText();
return !symbolED->text().isEmpty() && !description.isEmpty();
}
Dialog * createGuiNomenclature(LyXView & lv)
{
return new GuiNomenclature(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -15,18 +15,17 @@
#define GUINOMENCL_H
#include "GuiDialog.h"
#include "ControlCommand.h"
#include "ui_NomenclUi.h"
namespace lyx {
namespace frontend {
class GuiNomenclDialog : public GuiDialog, public Ui::NomenclUi
class GuiNomenclature : public GuiCommand, public Ui::NomenclUi
{
Q_OBJECT
public:
GuiNomenclDialog(LyXView & lv);
GuiNomenclature(LyXView & lv);
private Q_SLOTS:
void change_adaptor();
@ -35,8 +34,6 @@ private Q_SLOTS:
private:
///
void closeEvent(QCloseEvent * e);
/// parent controller
ControlCommand & controller();
///
bool isValid();
/// Apply changes

View File

@ -28,11 +28,10 @@ namespace lyx {
namespace frontend {
GuiURL::GuiURL(LyXView & lv)
: GuiDialog(lv, "url"), Controller(this), params_("url")
: GuiCommand(lv, "url")
{
setupUi(this);
setViewTitle( _("URL"));
setController(this, false);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
@ -99,23 +98,6 @@ bool GuiURL::isValid()
}
bool GuiURL::initialiseParams(std::string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommandMailer::string2params("name", data, params_);
return true;
}
void GuiURL::dispatchParams()
{
std::string const lfun =
InsetCommandMailer::params2string("url", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiURL(LyXView & lv) { return new GuiURL(lv); }

View File

@ -14,14 +14,13 @@
#define GUIURL_H
#include "GuiDialog.h"
#include "ControlCommand.h"
#include "ui_URLUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiURL : public GuiDialog, public Ui::URLUi, public Controller
class GuiURL : public GuiCommand, public Ui::URLUi
{
Q_OBJECT
@ -33,26 +32,12 @@ public Q_SLOTS:
private:
void closeEvent(QCloseEvent *);
/// parent controller
Controller & controller() { return *this; }
///
bool isValid();
/// apply dialog
void applyView();
/// update dialog
void updateContents();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
};
} // namespace frontend