]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIndices.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiIndices.cpp
index fa8d6d830954d6493d5b99237faa348515c236fb..a1198a68841d6f1d26a326bdbd9fddba09dadee1 100644 (file)
@@ -22,6 +22,7 @@
 #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 {
 
@@ -46,6 +51,14 @@ GuiIndices::GuiIndices(QWidget * parent)
        indicesTW->headerItem()->setText(0, qt_("Name"));
        indicesTW->headerItem()->setText(1, qt_("Label Color"));
        indicesTW->setSortingEnabled(true);
+
+       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);
+       }
 }
 
 void GuiIndices::update(BufferParams const & params)
@@ -60,6 +73,22 @@ void GuiIndices::update(BufferParams const & params)
        availableLA->setEnabled(state);
        removePB->setEnabled(state);
        colorPB->setEnabled(state);
+
+       string command;
+       string options =
+               split(params.index_command, command, ' ');
+
+       int const pos = indexCO->findData(toqstr(command));
+       if (pos != -1) {
+               indexCO->setCurrentIndex(pos);
+               indexOptionsED->setText(toqstr(options).trimmed());
+       } else {
+               indexCO->setCurrentIndex(0);
+               indexOptionsED->clear();
+       }
+       indexOptionsED->setEnabled(
+               indexCO->currentIndex() != 0);
+
        updateView();
 }
 
@@ -94,6 +123,12 @@ void GuiIndices::updateView()
                        indicesTW->setItemSelected(newItem, true);
                }
        }
+       indicesTW->resizeColumnToContents(0);
+       bool const have_sel =
+               !indicesTW->selectedItems().isEmpty();
+       removePB->setEnabled(have_sel);
+       renamePB->setEnabled(have_sel);
+       colorPB->setEnabled(have_sel);
        // emit signal
        changed();
 }
@@ -103,6 +138,28 @@ void GuiIndices::apply(BufferParams & params) const
 {
        params.use_indices = multipleIndicesCB->isChecked();
        params.indiceslist() = indiceslist_;
+
+       string const index_command =
+               fromqstr(indexCO->itemData(
+                       indexCO->currentIndex()).toString());
+       string const index_options = fromqstr(indexOptionsED->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 n)
+{
+       indexOptionsED->setEnabled(n != 0);
+       changed();
+}
+
+
+void GuiIndices::on_indexOptionsED_textChanged(QString)
+{
+       changed();
 }
 
 
@@ -145,16 +202,19 @@ void GuiIndices::on_renamePB_clicked()
                sel_index = selItem->text(0);
        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"))) {
+               if (Alert::askForText(newname, _("Enter new index name"), oldname)) {
+                       if (newname.empty() || oldname == newname)
+                               return;
                        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."));
        }
 }
 
@@ -165,6 +225,16 @@ 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);
+}
+
+
 void GuiIndices::on_colorPB_clicked()
 {
        toggleColor(indicesTW->currentItem());
@@ -173,13 +243,16 @@ void GuiIndices::on_colorPB_clicked()
 
 void GuiIndices::on_multipleIndicesCB_toggled(bool const state)
 {
+       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);
-       colorPB->setEnabled(state);
+       removePB->setEnabled(state && have_sel);
+       colorPB->setEnabled(state && have_sel);
+       renamePB->setEnabled(state && have_sel);
        // emit signal
        changed();
 }