InsetInfo: Some fixes...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25154 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-06-06 08:45:58 +00:00
parent 062bec11d0
commit 81cc98a500
4 changed files with 87 additions and 35 deletions

View File

@ -47,70 +47,104 @@ char const * info_types_gui[] =
N_("menu"), N_("icon"), N_("buffer"), ""};
GuiInfo::GuiInfo(GuiView & lv)
: DialogView(lv, "info", qt_("Info"))
{
setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotApply()));
connect(typeCO, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(nameLE, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor()));
typeCO->blockSignals(true);
for (int n = 0; info_types[n][0]; ++n)
typeCO->addItem(qt_(info_types_gui[n]));
typeCO->blockSignals(false);
}
void GuiInfo::on_cancelPB_clicked()
void GuiInfo::on_newPB_clicked()
{
dialogToParams();
docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
dispatch(FuncRequest(LFUN_INFO_INSERT, argument));
}
void GuiInfo::on_closePB_clicked()
{
hide();
}
void GuiInfo::on_typeCO_currentIndexChanged(int)
{
applyView();
}
void GuiInfo::on_nameLE_textChanged(QString const &)
{
applyView();
}
void GuiInfo::applyView()
{
InsetInfo * ii = static_cast<InsetInfo *>(inset(INFO_CODE));
if (!ii)
InsetInfo const * ii = static_cast<InsetInfo const *>(inset(INFO_CODE));
if (!ii) {
return;
}
dialogToParams();
docstring const argument = qstring_to_ucs4(type_ + ' ' + name_);
if (!ii->validate(argument))
return;
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
// FIXME: update the inset contents
updateLabels(bufferview()->buffer());
bufferview()->updateMetrics();
bufferview()->buffer().changed();
hide();
}
void GuiInfo::updateView()
{
InsetInfo * ii = static_cast<InsetInfo *>(inset(INFO_CODE));
InsetInfo const * ii = static_cast<InsetInfo const *>(inset(INFO_CODE));
if (!ii) {
typeCO->setCurrentIndex(0);
nameLE->clear();
// FIXME: A New button to create an InsetInfo at the cursor location
// would be nice.
enableView(false);
return;
}
int type = findToken(info_types, ii->infoType());
type_ = toqstr(ii->infoType());
name_ = toqstr(ii->infoName());
paramsToDialog();
}
void GuiInfo::paramsToDialog()
{
typeCO->blockSignals(true);
nameLE->blockSignals(true);
int type = findToken(info_types, fromqstr(type_));
typeCO->setCurrentIndex(type >= 0 ? type : 0);
nameLE->setText(toqstr(ii->infoName()));
nameLE->setText(name_);
typeCO->blockSignals(false);
nameLE->blockSignals(false);
}
void GuiInfo::dialogToParams()
{
int type = typeCO->currentIndex();
if (type != -1)
type_ = info_types[type];
name_ = nameLE->text();
}
void GuiInfo::enableView(bool enable)
{
//FIXME: enable controls that need enabling.
}
void GuiInfo::dispatchParams()
{
typeCO->setEnabled(enable);
nameLE->setEnabled(enable);
newPB->setEnabled(!enable);
}

View File

@ -17,8 +17,6 @@
namespace lyx {
class InsetInfo;
namespace frontend {
class GuiInfo : public DialogView, public Ui::InfoUi
@ -32,13 +30,22 @@ public:
//@{
void applyView();
void updateView();
void dispatchParams();
void dispatchParams() {}
void enableView(bool enable);
bool isBufferDependent() const { return true; }
//@}
private Q_SLOTS:
void on_cancelPB_clicked();
void on_newPB_clicked();
void on_closePB_clicked();
void on_typeCO_currentIndexChanged(int);
void on_nameLE_textChanged(QString const &);
private:
void paramsToDialog();
void dialogToParams();
QString type_;
QString name_;
};
} // namespace frontend

View File

@ -147,10 +147,10 @@ void InsetInfo::write(ostream & os) const
}
bool InsetInfo::validate(string const & argument) const
bool InsetInfo::validate(docstring const & argument) const
{
// FIXME!
return false;
return true;
}
@ -165,13 +165,18 @@ bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
case LFUN_COPY:
case LFUN_INSET_SETTINGS:
return InsetText::getStatus(cur, cmd, flag);
case LFUN_INSET_MODIFY:
flag.setEnabled(true);
break;
//FIXME: do something.
/*
*/
default:
return false;
@ -194,6 +199,11 @@ void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
InsetText::doDispatch(cur, cmd);
break;
case LFUN_INSET_MODIFY:
setInfo(to_utf8(cmd.argument()));
cur.pos() = 0;
break;
default:
break;
}
@ -208,6 +218,7 @@ void InsetInfo::setInfo(string const & name)
string type;
name_ = trim(split(name, type, ' '));
type_ = nameTranslator().find(type);
updateInfo();
}

View File

@ -109,7 +109,7 @@ public:
///
std::string infoName() const { return name_; }
///
bool validate(std::string const & argument) const;
bool validate(docstring const & argument) const;
///
bool showInsetDialog(BufferView * bv) const;
///