]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIndices.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiIndices.cpp
index 02d021014b6c08efd0a5d10de41adbfd99a05b13..7c7a61014af6decd03a700daf2174ba882a99d86 100644 (file)
@@ -44,7 +44,8 @@ namespace frontend {
 
 
 GuiIndices::GuiIndices(QWidget * parent)
-       : QWidget(parent)
+       : QWidget(parent), readonly_(false),
+         use_indices_(false)
 {
        setupUi(this);
        indicesTW->setColumnCount(2);
@@ -60,20 +61,44 @@ GuiIndices::GuiIndices(QWidget * parent)
                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);
+
+       updateWidgets();
 
        string command;
        string options =
@@ -89,8 +114,6 @@ void GuiIndices::update(BufferParams const & params)
                indexCO->setCurrentIndex(indexCO->findData(toqstr("default")));
                indexOptionsLE->clear();
        }
-       indexOptionsLE->setEnabled(
-               indexCO->currentIndex() != 0);
 
        updateView();
 }
@@ -127,11 +150,8 @@ void GuiIndices::updateView()
                }
        }
        indicesTW->resizeColumnToContents(0);
-       bool const have_sel =
-               !indicesTW->selectedItems().isEmpty();
-       removePB->setEnabled(have_sel);
-       renamePB->setEnabled(have_sel);
-       colorPB->setEnabled(have_sel);
+
+       updateWidgets();
        // emit signal
        changed();
 }
@@ -153,10 +173,16 @@ void GuiIndices::apply(BufferParams & params) const
 }
 
 
-void GuiIndices::on_indexCO_activated(int n)
+void GuiIndices::on_indexCO_activated(int)
 {
-       indexOptionsLE->setEnabled(
-               indexCO->itemData(n).toString() != "default");
+       updateWidgets();
+       changed();
+}
+
+
+void GuiIndices::on_newIndexLE_textChanged(QString)
+{
+       updateWidgets();
        changed();
 }
 
@@ -185,9 +211,9 @@ void GuiIndices::on_removePB_pressed()
        if (selItem != 0)
                sel_index = selItem->text(0);
        if (!sel_index.isEmpty()) {
-               if (indiceslist_.find(qstring_to_ucs4(sel_index)) == 
+               if (indiceslist_.find(qstring_to_ucs4(sel_index)) ==
                    indiceslist_.findShortcut(from_ascii("idx"))) {
-                       Alert::error(_("Cannot remove standard index"), 
+                       Alert::error(_("Cannot remove standard index"),
                              _("The default index cannot be removed."));
                              return;
                }
@@ -207,15 +233,14 @@ void GuiIndices::on_renamePB_clicked()
        if (!sel_index.isEmpty()) {
                docstring newname;
                docstring const oldname = qstring_to_ucs4(sel_index);
-               bool success = false;
                if (Alert::askForText(newname, _("Enter new index name"), oldname)) {
                        if (newname.empty() || oldname == newname)
                                return;
-                       success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
+                       bool success = indiceslist_.rename(qstring_to_ucs4(sel_index), newname);
                        newIndexLE->clear();
                        updateView();
                        if (!success)
-                               Alert::error(_("Renaming failed"), 
+                               Alert::error(_("Renaming failed"),
                                      _("The index could not be renamed. "
                                        "Check if the new name already exists."));
                }
@@ -231,11 +256,7 @@ void GuiIndices::on_indicesTW_itemDoubleClicked(QTreeWidgetItem * item, int /*co
 
 void GuiIndices::on_indicesTW_itemSelectionChanged()
 {
-       bool const have_sel =
-               !indicesTW->selectedItems().isEmpty();
-       removePB->setEnabled(have_sel);
-       renamePB->setEnabled(have_sel);
-       colorPB->setEnabled(have_sel);
+       updateWidgets();
 }
 
 
@@ -245,18 +266,10 @@ void GuiIndices::on_colorPB_clicked()
 }
 
 
-void GuiIndices::on_multipleIndicesCB_toggled(bool const state)
+void GuiIndices::on_multipleIndicesCB_toggled(bool const b)
 {
-       bool const have_sel =
-               !indicesTW->selectedItems().isEmpty();
-       indicesTW->setEnabled(state);
-       newIndexLE->setEnabled(state);
-       newIndexLA->setEnabled(state);
-       addIndexPB->setEnabled(state);
-       availableLA->setEnabled(state);
-       removePB->setEnabled(state && have_sel);
-       colorPB->setEnabled(state && have_sel);
-       renamePB->setEnabled(state && have_sel);
+       use_indices_ = b;
+       updateWidgets();
        // emit signal
        changed();
 }