#include "frontends/alert.h"
#include "BufferParams.h"
+#include "LyXRC.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include <QColorDialog>
+using namespace std;
+using namespace lyx::support;
+
+
namespace lyx {
namespace frontend {
GuiIndices::GuiIndices(QWidget * parent)
- : QWidget(parent)
+ : QWidget(parent), readonly_(false),
+ use_indices_(false)
{
setupUi(this);
indicesTW->setColumnCount(2);
indicesTW->headerItem()->setText(0, qt_("Name"));
indicesTW->headerItem()->setText(1, qt_("Label Color"));
indicesTW->setSortingEnabled(true);
+
+ // NOTE: we do not provide "custom" here for security reasons!
+ indexCO->clear();
+ indexCO->addItem(qt_("Default"), QString("default"));
+ for (set<string>::const_iterator it = lyxrc.index_alternatives.begin();
+ it != lyxrc.index_alternatives.end(); ++it) {
+ QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
+ indexCO->addItem(command, command);
+ }
+
+ indexOptionsLE->setValidator(new NoNewLineValidator(indexOptionsLE));
+ newIndexLE->setValidator(new NoNewLineValidator(newIndexLE));
}
-void GuiIndices::update(BufferParams const & params)
+
+void GuiIndices::updateWidgets()
{
+ bool const have_sel =
+ !indicesTW->selectedItems().isEmpty();
+
+ indexCO->setEnabled(!readonly_);
+ indexOptionsLE->setEnabled(
+ indexCO->itemData(indexCO->currentIndex()).toString() != "default");
+ indexOptionsLE->setReadOnly(readonly_);
+
+ multipleIndicesCB->setEnabled(!readonly_);
+ indicesTW->setEnabled(use_indices_);
+ newIndexLE->setEnabled(use_indices_);
+ newIndexLE->setReadOnly(readonly_);
+ newIndexLA->setEnabled(use_indices_);
+ addIndexPB->setEnabled(use_indices_ && !readonly_
+ && !newIndexLE->text().isEmpty());
+ availableLA->setEnabled(use_indices_);
+ removePB->setEnabled(use_indices_ && have_sel && !readonly_);
+ colorPB->setEnabled(use_indices_ && have_sel && !readonly_);
+ renamePB->setEnabled(use_indices_ && have_sel && !readonly_);
+}
+
+
+void GuiIndices::update(BufferParams const & params, bool const readonly)
+{
+ use_indices_ = params.use_indices;
+ readonly_ = readonly;
indiceslist_ = params.indiceslist();
- multipleIndicesCB->setChecked(
- params.use_indices);
- bool const state = params.use_indices;
- indicesTW->setEnabled(state);
- newIndexLE->setEnabled(state);
- newIndexLA->setEnabled(state);
- addIndexPB->setEnabled(state);
- availableLA->setEnabled(state);
- removePB->setEnabled(state);
- colorPB->setEnabled(state);
+ multipleIndicesCB->setChecked(params.use_indices);
+
+ updateWidgets();
+
+ string command;
+ string options =
+ split(params.index_command, command, ' ');
+
+ int const pos = indexCO->findData(toqstr(command));
+ if (pos != -1) {
+ indexCO->setCurrentIndex(pos);
+ indexOptionsLE->setText(toqstr(options).trimmed());
+ } else {
+ // We reset to default if we do not know the specified compiler
+ // This is for security reasons
+ indexCO->setCurrentIndex(indexCO->findData(toqstr("default")));
+ indexOptionsLE->clear();
+ }
+
updateView();
}
indicesTW->setItemSelected(newItem, true);
}
}
+ indicesTW->resizeColumnToContents(0);
+
+ updateWidgets();
// emit signal
changed();
}
{
params.use_indices = multipleIndicesCB->isChecked();
params.indiceslist() = indiceslist_;
+
+ string const index_command =
+ fromqstr(indexCO->itemData(
+ indexCO->currentIndex()).toString());
+ string const index_options = fromqstr(indexOptionsLE->text());
+ if (index_command == "default" || index_options.empty())
+ params.index_command = index_command;
+ else
+ params.index_command = index_command + " " + index_options;
+}
+
+
+void GuiIndices::on_indexCO_activated(int)
+{
+ updateWidgets();
+ changed();
+}
+
+
+void GuiIndices::on_newIndexLE_textChanged(QString)
+{
+ updateWidgets();
+ changed();
+}
+
+
+void GuiIndices::on_indexOptionsLE_textChanged(QString)
+{
+ changed();
}
sel_index = selItem->text(0);
if (!sel_index.isEmpty()) {
docstring newname;
- bool success = false;
- if (Alert::askForText(newname, _("Enter new index name"))) {
- success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
+ docstring const oldname = qstring_to_ucs4(sel_index);
+ if (Alert::askForText(newname, _("Enter new index name"), oldname)) {
+ if (newname.empty() || oldname == newname)
+ return;
+ bool success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
newIndexLE->clear();
updateView();
+ if (!success)
+ Alert::error(_("Renaming failed"),
+ _("The index could not be renamed. "
+ "Check if the new name already exists."));
}
- if (!success)
- Alert::error(_("Renaming failed"),
- _("The index could not be renamed. "
- "Check if the new name already exists."));
}
}
}
+void GuiIndices::on_indicesTW_itemSelectionChanged()
+{
+ updateWidgets();
+}
+
+
void GuiIndices::on_colorPB_clicked()
{
toggleColor(indicesTW->currentItem());
}
-void GuiIndices::on_multipleIndicesCB_toggled(bool const state)
+void GuiIndices::on_multipleIndicesCB_toggled(bool const b)
{
- indicesTW->setEnabled(state);
- newIndexLE->setEnabled(state);
- newIndexLA->setEnabled(state);
- addIndexPB->setEnabled(state);
- availableLA->setEnabled(state);
- removePB->setEnabled(state);
- colorPB->setEnabled(state);
+ use_indices_ = b;
+ updateWidgets();
// emit signal
changed();
}