X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiIndices.cpp;h=a1198a68841d6f1d26a326bdbd9fddba09dadee1;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=969b86ad5d22b4e5ff58d1556d63696c74823146;hpb=6c7cbfa7a14879cae978cbb5340fb05b80cf84e9;p=lyx.git diff --git a/src/frontends/qt4/GuiIndices.cpp b/src/frontends/qt4/GuiIndices.cpp index 969b86ad5d..a1198a6884 100644 --- a/src/frontends/qt4/GuiIndices.cpp +++ b/src/frontends/qt4/GuiIndices.cpp @@ -54,7 +54,7 @@ GuiIndices::GuiIndices(QWidget * parent) indexCO->clear(); indexCO->addItem(qt_("Default"), QString("default")); - for (vector::const_iterator it = lyxrc.index_alternatives.begin(); + for (set::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); @@ -123,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(); } @@ -196,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.")); } } @@ -216,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()); @@ -224,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(); }