Use the new InsetCommandParams interface (frontend part), from Ugras and me

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15408 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-10-20 13:53:43 +00:00
parent 0d1c89fe64
commit 3bbbc1437b
19 changed files with 106 additions and 107 deletions

View File

@ -125,7 +125,7 @@ bool ControlBibtex::usingBibtopic() const
bool ControlBibtex::bibtotoc() const
{
return prefixIs(params().getOptions(), "bibtotoc");
return prefixIs(lyx::to_utf8(params()["options"]), "bibtotoc");
}
@ -135,27 +135,27 @@ string const ControlBibtex::getStylefile() const
// own "plain" stylefiles
biblio::CiteEngine_enum const & engine =
biblio::getEngine(kernel().buffer());
string defaultstyle;
docstring defaultstyle;
switch (engine) {
case biblio::ENGINE_BASIC:
defaultstyle = "plain";
defaultstyle = lyx::from_ascii("plain");
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
defaultstyle = "plainnat";
defaultstyle = lyx::from_ascii("plainnat");
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
defaultstyle = "plainnat";
defaultstyle = lyx::from_ascii("plainnat");
break;
case biblio::ENGINE_JURABIB:
defaultstyle = "jurabib";
defaultstyle = lyx::from_ascii("jurabib");
break;
}
string bst = params().getOptions();
docstring bst = params()["btprint"];
if (bibtotoc()){
// bibstyle exists?
if (contains(bst,',')) {
string bibtotoc = "bibtotoc";
if (contains(bst, ',')) {
docstring bibtotoc = lyx::from_ascii("bibtotoc");
bst = split(bst, bibtotoc, ',');
} else
bst.erase();
@ -164,10 +164,11 @@ string const ControlBibtex::getStylefile() const
// propose default style file for new insets
// existing insets might have (legally) no bst files
// (if the class already provides a style)
if (bst.empty() && params().getContents().empty())
if (bst.empty() && params()["bibfiles"].empty())
bst = defaultstyle;
return bst;
// FIXME UNICODE
return lyx::to_utf8(bst);
}
} // namespace frontend

View File

@ -62,15 +62,15 @@ void GBibItem::update()
{
bc().refreshReadOnly();
keyentry_->set_text (controller().params().getContents());
labelentry_->set_text (controller().params().getOptions());
keyentry_->set_text (lyx::to_utf8(controller().params()["key"]));
labelentry_->set_text (lyx::to_utf8(controller().params()["label"]));
}
void GBibItem::apply()
{
controller().params().setContents(keyentry_->get_text());
controller().params().setOptions(labelentry_->get_text());
controller().params()["key"] = lyx::from_utf8(keyentry_->get_text());
controller().params()["label"] = lyx::from_utf8(labelentry_->get_text());
}
void GBibItem::changed()

View File

@ -95,7 +95,7 @@ void GBibtex::doBuild()
void GBibtex::update()
{
string bibs(controller().params().getContents());
string bibs(lyx::to_utf8(controller().params()["bibfiles"]));
string bib;
databasesstore_->clear();
@ -118,7 +118,7 @@ void GBibtex::update()
toccheck_->set_sensitive(!bibtopic);
string btprint(controller().params().getSecOptions());
string btprint(lyx::to_ascii(controller().params()["btprint"]));
int btp = 0;
if (btprint == "btPrintNotCited")
btp = 1;
@ -169,7 +169,7 @@ void GBibtex::apply()
dblist += ",";
}
controller().params().setContents(dblist);
controller().params()["bibfiles"] = lyx::from_utf8(dblist);
string const bibstyle = stylecombo_.get_active_text();
bool const bibtotoc = toccheck_->get_active();
@ -177,15 +177,15 @@ void GBibtex::apply()
if (!bibtopic && bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc," + bibstyle);
controller().params()["options"] = lyx::from_utf8("bibtotoc," + bibstyle);
} else if (!bibtopic && bibtotoc) {
// bibtotoc and no style
controller().params().setOptions("bibtotoc");
controller().params()["options"] = lyx::from_ascii("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
controller().params().setOptions(bibstyle);
controller().params()["options"] = lyx::from_utf8(bibstyle);
}
// bibtopic allows three kinds of sections:
@ -196,18 +196,20 @@ void GBibtex::apply()
switch (btp) {
case 0:
controller().params().setSecOptions("btPrintCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintCited");
break;
case 1:
controller().params().setSecOptions("btPrintNotCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintNotCited");
break;
case 2:
controller().params().setSecOptions("btPrintAll");
controller().params()["btprint"] = lyx::from_ascii("btPrintAll");
break;
}
if (!bibtopic)
controller().params().setSecOptions("");
controller().params()["btprint"] = docstring();
}

View File

@ -72,7 +72,7 @@ void GInclude::doBuild()
void GInclude::update()
{
string const filename = controller().params().getContents();
string const filename = lyx::to_utf8(controller().params()["filename"]);
fileentry_->set_text(filename);
string const cmdname = controller().params().getCmdName();
@ -113,7 +113,7 @@ void GInclude::apply()
InsetCommandParams params = controller().params();
params.preview(previewcheck_->get_active());
params.setContents(fileentry_->get_text());
params["filename"] = lyx::from_utf8(fileentry_->get_text());
if (includeradio_->get_active())
params.setCmdName("include");

View File

@ -168,8 +168,8 @@ void GRef::update()
bc().refreshReadOnly();
jumptobutton_->set_sensitive(true);
backbutton_->set_sensitive(false);
labelentry_->set_text(controller().params().getContents());
nameentry_->set_text(controller().params().getOptions());
labelentry_->set_text(lyx::to_utf8(controller().params()["reference"]));
nameentry_->set_text(lyx::to_utf8(controller().params()["name"]));
// Name is irrelevant to LaTeX/Literate documents
Kernel::DocType doctype = kernel().docType();
@ -240,8 +240,8 @@ void GRef::apply()
if (applylock_)
return;
controller().params().setContents(labelentry_->get_text());
controller().params().setOptions(nameentry_->get_text());
controller().params()["reference"] = lyx::from_utf8(labelentry_->get_text());
controller().params()["name"] = lyx::from_utf8(nameentry_->get_text());
int const type = formatcombo_->get_active_row_number();
controller().params().setCmdName(InsetRef::getName(type));
}

View File

@ -44,14 +44,14 @@ GText::GText(Dialog & parent, docstring const & title, docstring const & label)
void GText::apply()
{
controller().params().setContents(entry_->get_text());
controller().params()["name"] = lyx::from_utf8(entry_->get_text());
}
void GText::update()
{
string const contents = support::trim(
controller().params().getContents());
lyx::to_utf8(controller().params()["name"]));
entry_->set_text(contents);
}

View File

@ -77,10 +77,8 @@ void GUrl::onEntryChanged()
void GUrl::update()
{
url_->set_text(Glib::locale_to_utf8(
controller().params().getContents()));
name_->set_text(Glib::locale_to_utf8(
controller().params().getOptions()));
url_->set_text(lyx::to_utf8(controller().params()["target"]));
name_->set_text(lyx::to_utf8(controller().params()["name"]));
if (controller().params().getCmdName() == "url")
htmlType_->set_active(false);
else
@ -90,10 +88,8 @@ void GUrl::update()
void GUrl::apply()
{
controller().params().setContents(
Glib::locale_to_utf8(url_->get_text()));
controller().params().setOptions(
Glib::locale_to_utf8(name_->get_text()));
controller().params()["target"] = lyx::from_utf8(url_->get_text());
controller().params()["name"] = lyx::from_utf8(name_->get_text());
if (htmlType_->get_active())
controller().params().setCmdName("htmlurl");
else

View File

@ -46,15 +46,15 @@ void QBibitem::build_dialog()
void QBibitem::update_contents()
{
dialog_->keyED->setText(toqstr(controller().params().getContents()));
dialog_->labelED->setText(toqstr(controller().params().getOptions()));
dialog_->keyED->setText(toqstr(controller().params()["key"]));
dialog_->labelED->setText(toqstr(controller().params()["label"]));
}
void QBibitem::apply()
{
controller().params().setContents(fromqstr(dialog_->keyED->text()));
controller().params().setOptions(fromqstr(dialog_->labelED->text()));
controller().params()["key"] = qstring_to_ucs4(dialog_->keyED->text());
controller().params()["label"] = qstring_to_ucs4(dialog_->labelED->text());
}

View File

@ -76,8 +76,8 @@ void QBibtex::update_contents()
dialog_->databaseLB->clear();
string bibs(controller().params().getContents());
string bib;
docstring bibs(controller().params()["bibfiles"]);
docstring bib;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
@ -99,7 +99,7 @@ void QBibtex::update_contents()
dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
dialog_->bibtocCB->setEnabled(!bibtopic);
string btprint(controller().params().getSecOptions());
docstring btprint(controller().params()["bibfiles"]);
int btp = 0;
if (btprint == "btPrintNotCited")
btp = 1;
@ -138,30 +138,30 @@ void QBibtex::update_contents()
void QBibtex::apply()
{
string dbs(fromqstr(dialog_->databaseLB->text(0)));
docstring dbs(qstring_to_ucs4(dialog_->databaseLB->text(0)));
unsigned int maxCount = dialog_->databaseLB->count();
for (unsigned int i = 1; i < maxCount; i++) {
dbs += ',';
dbs += fromqstr(dialog_->databaseLB->text(i));
dbs += qstring_to_ucs4(dialog_->databaseLB->text(i));
}
controller().params().setContents(dbs);
controller().params()["bibfiles"] = dbs;
string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
bool const bibtotoc(dialog_->bibtocCB->isChecked());
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc," + bibstyle);
controller().params()["options"] = "bibtotoc," + bibstyle;
} else if (bibtotoc) {
// bibtotoc and no style
controller().params().setOptions("bibtotoc");
controller().params()["options"] = lyx::from_ascii("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
controller().params().setOptions(bibstyle);
controller().params()["options"] = bibstyle;
}
// bibtopic allows three kinds of sections:
@ -172,18 +172,18 @@ void QBibtex::apply()
switch (btp) {
case 0:
controller().params().setSecOptions("btPrintCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintCited");
break;
case 1:
controller().params().setSecOptions("btPrintNotCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintNotCited");
break;
case 2:
controller().params().setSecOptions("btPrintAll");
controller().params()["btprint"] = lyx::from_ascii("btPrintAll");
break;
}
if (!controller().usingBibtopic())
controller().params().setSecOptions("");
controller().params()["btprint"] = docstring();
}

View File

@ -63,7 +63,7 @@ void QInclude::update_contents()
InsetCommandParams const & params = controller().params();
dialog_->filenameED->setText(toqstr(params.getContents()));
dialog_->filenameED->setText(toqstr(params["filename"]));
dialog_->visiblespaceCB->setChecked(false);
dialog_->visiblespaceCB->setEnabled(false);
@ -100,7 +100,7 @@ void QInclude::apply()
{
InsetCommandParams params = controller().params();
params.setContents(fromqstr(dialog_->filenameED->text()));
params["filename"] = qstring_to_ucs4(dialog_->filenameED->text());
params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentItem();

View File

@ -50,16 +50,16 @@ void QIndex::build_dialog()
void QIndex::update_contents()
{
string const contents = controller().params().getContents();
dialog_->keywordED->setText(toqstr(contents));
docstring const & name = controller().params()["name"];
dialog_->keywordED->setText(toqstr(name));
bc().valid(!contents.empty());
bc().valid(!name.empty());
}
void QIndex::apply()
{
controller().params().setContents(fromqstr(dialog_->keywordED->text()));
controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text());
}

View File

@ -71,13 +71,13 @@ void QRef::update_contents()
int orig_type = dialog_->typeCO->currentItem();
dialog_->referenceED->setText(toqstr(params.getContents()));
dialog_->referenceED->setText(toqstr(params["reference"]));
dialog_->nameED->setText(toqstr(params.getOptions()));
dialog_->nameED->setText(toqstr(params["name"]));
dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
// restore type settings for new insets
if (params.getContents().empty())
if (params["reference"].empty())
dialog_->typeCO->setCurrentItem(orig_type);
else
dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
@ -95,7 +95,7 @@ void QRef::update_contents()
dialog_->bufferCO->insertItem(toqstr(*it));
}
// restore the buffer combo setting for new insets
if (params.getContents().empty() && restored_buffer_ != -1
if (params["reference"].empty() && restored_buffer_ != -1
&& restored_buffer_ < dialog_->bufferCO->count())
dialog_->bufferCO->setCurrentItem(restored_buffer_);
else
@ -111,8 +111,8 @@ void QRef::apply()
InsetCommandParams & params = controller().params();
params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
params.setContents(fromqstr(dialog_->referenceED->text()));
params.setOptions(fromqstr(dialog_->nameED->text()));
params["reference"] = qstring_to_ucs4(dialog_->referenceED->text());
params["name"] = qstring_to_ucs4(dialog_->nameED->text());
restored_buffer_ = dialog_->bufferCO->currentItem();
}

View File

@ -51,8 +51,8 @@ void QURL::update_contents()
{
InsetCommandParams const & params = controller().params();
dialog_->urlED->setText(toqstr(params.getContents()));
dialog_->nameED->setText(toqstr(params.getOptions()));
dialog_->urlED->setText(toqstr(params["target"]));
dialog_->nameED->setText(toqstr(params["name"]));
dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
bc().valid(isValid());
@ -63,8 +63,8 @@ void QURL::apply()
{
InsetCommandParams & params = controller().params();
params.setContents(fromqstr(dialog_->urlED->text()));
params.setOptions(fromqstr(dialog_->nameED->text()));
params["target"] = qstring_to_ucs4(dialog_->urlED->text());
params["name"] = qstring_to_ucs4(dialog_->nameED->text());
if (dialog_->hyperlinkCB->isChecked())
params.setCmdName("htmlurl");

View File

@ -46,15 +46,15 @@ void QBibitem::build_dialog()
void QBibitem::update_contents()
{
dialog_->keyED->setText(toqstr(controller().params().getContents()));
dialog_->labelED->setText(toqstr(controller().params().getOptions()));
dialog_->keyED->setText(toqstr(controller().params()["key"]));
dialog_->labelED->setText(toqstr(controller().params()["label"]));
}
void QBibitem::apply()
{
controller().params().setContents(fromqstr(dialog_->keyED->text()));
controller().params().setOptions(fromqstr(dialog_->labelED->text()));
controller().params()["key"] = qstring_to_ucs4(dialog_->keyED->text());
controller().params()["label"] = qstring_to_ucs4(dialog_->labelED->text());
}

View File

@ -75,8 +75,8 @@ void QBibtex::update_contents()
dialog_->databaseLW->clear();
string bibs(controller().params().getContents());
string bib;
docstring bibs(controller().params()["bibfiles"]);
docstring bib;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
@ -100,7 +100,7 @@ void QBibtex::update_contents()
dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
dialog_->bibtocCB->setEnabled(!bibtopic);
string btprint(controller().params().getSecOptions());
docstring btprint(controller().params()["btprint"]);
int btp = 0;
if (btprint == "btPrintNotCited")
btp = 1;
@ -138,30 +138,30 @@ void QBibtex::update_contents()
void QBibtex::apply()
{
string dbs(fromqstr(dialog_->databaseLW->item(0)->text()));
docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text()));
unsigned int maxCount = dialog_->databaseLW->count();
for (unsigned int i = 1; i < maxCount; i++) {
dbs += ',';
dbs += fromqstr(dialog_->databaseLW->item(i)->text());
dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text());
}
controller().params().setContents(dbs);
controller().params()["bibfiles"] = dbs;
string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
bool const bibtotoc(dialog_->bibtocCB->isChecked());
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc," + bibstyle);
controller().params()["options"] = "bibtotoc," + bibstyle;
} else if (bibtotoc) {
// bibtotoc and no style
controller().params().setOptions("bibtotoc");
controller().params()["options"] = lyx::from_ascii("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
controller().params().setOptions(bibstyle);
controller().params()["options"] = bibstyle;
}
// bibtopic allows three kinds of sections:
@ -172,18 +172,18 @@ void QBibtex::apply()
switch (btp) {
case 0:
controller().params().setSecOptions("btPrintCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintCited");
break;
case 1:
controller().params().setSecOptions("btPrintNotCited");
controller().params()["btprint"] = lyx::from_ascii("btPrintNotCited");
break;
case 2:
controller().params().setSecOptions("btPrintAll");
controller().params()["btprint"] = lyx::from_ascii("btPrintAll");
break;
}
if (!controller().usingBibtopic())
controller().params().setSecOptions("");
controller().params()["btprint"] = docstring();
}

View File

@ -62,7 +62,7 @@ void QInclude::update_contents()
InsetCommandParams const & params = controller().params();
dialog_->filenameED->setText(toqstr(params.getContents()));
dialog_->filenameED->setText(toqstr(params["filename"]));
dialog_->visiblespaceCB->setChecked(false);
dialog_->visiblespaceCB->setEnabled(false);
@ -99,7 +99,7 @@ void QInclude::apply()
{
InsetCommandParams params = controller().params();
params.setContents(fromqstr(dialog_->filenameED->text()));
params["filename"] = qstring_to_ucs4(dialog_->filenameED->text());
params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentIndex();

View File

@ -50,7 +50,7 @@ void QIndex::build_dialog()
void QIndex::update_contents()
{
string const contents = controller().params().getContents();
docstring const contents = controller().params()["name"];
dialog_->keywordED->setText(toqstr(contents));
bc().valid(!contents.empty());
@ -59,7 +59,7 @@ void QIndex::update_contents()
void QIndex::apply()
{
controller().params().setContents(fromqstr(dialog_->keywordED->text()));
controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text());
}

View File

@ -72,13 +72,13 @@ void QRef::update_contents()
int orig_type = dialog_->typeCO->currentIndex();
dialog_->referenceED->setText(toqstr(params.getContents()));
dialog_->referenceED->setText(toqstr(params["reference"]));
dialog_->nameED->setText(toqstr(params.getOptions()));
dialog_->nameED->setText(toqstr(params["name"]));
dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
// restore type settings for new insets
if (params.getContents().empty())
if (params["reference"].empty())
dialog_->typeCO->setCurrentIndex(orig_type);
else
dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
@ -96,7 +96,7 @@ void QRef::update_contents()
dialog_->bufferCO->addItem(toqstr(*it));
}
// restore the buffer combo setting for new insets
if (params.getContents().empty() && restored_buffer_ != -1
if (params["reference"].empty() && restored_buffer_ != -1
&& restored_buffer_ < dialog_->bufferCO->count())
dialog_->bufferCO->setCurrentIndex(restored_buffer_);
else
@ -112,8 +112,8 @@ void QRef::apply()
InsetCommandParams & params = controller().params();
params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
params.setContents(fromqstr(dialog_->referenceED->text()));
params.setOptions(fromqstr(dialog_->nameED->text()));
params["reference"] = qstring_to_ucs4(dialog_->referenceED->text());
params["name"] = qstring_to_ucs4(dialog_->nameED->text());
restored_buffer_ = dialog_->bufferCO->currentIndex();
}

View File

@ -51,8 +51,8 @@ void UrlView::update_contents()
{
InsetCommandParams const & params = controller().params();
dialog_->urlED->setText(toqstr(params.getContents()));
dialog_->nameED->setText(toqstr(params.getOptions()));
dialog_->urlED->setText(toqstr(params["target"]));
dialog_->nameED->setText(toqstr(params["name"]));
dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
bc().valid(isValid());
@ -63,8 +63,8 @@ void UrlView::apply()
{
InsetCommandParams & params = controller().params();
params.setContents(fromqstr(dialog_->urlED->text()));
params.setOptions(fromqstr(dialog_->nameED->text()));
params["target"] = qstring_to_ucs4(dialog_->urlED->text());
params["name"] = qstring_to_ucs4(dialog_->nameED->text());
if (dialog_->hyperlinkCB->isChecked())
params.setCmdName("htmlurl");