From c12190b5e53f856906fc70ce1b3bed1ddc73c3ed Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 30 Mar 2019 11:37:28 +0100 Subject: [PATCH] GuiBibtex: add button to edit individual databases externally This complements the inset context menu function, which only allows for editing all databases externally --- src/frontends/qt4/GuiBibtex.cpp | 20 ++++++++++++++++++-- src/frontends/qt4/GuiBibtex.h | 1 + src/frontends/qt4/ui/BibtexUi.ui | 29 ++++++++++++++++++++++++++++- src/insets/InsetBibtex.cpp | 8 +++++--- src/insets/InsetBibtex.h | 2 +- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp index a6aa95a703..d9c19051fb 100644 --- a/src/frontends/qt4/GuiBibtex.cpp +++ b/src/frontends/qt4/GuiBibtex.cpp @@ -185,6 +185,7 @@ void GuiBibtex::setButtons() void GuiBibtex::selUpdated() { selectionManager->update(); + editPB->setEnabled(deletePB->isEnabled()); changed(); } @@ -240,6 +241,19 @@ void GuiBibtex::browseBibPressed() } +void GuiBibtex::on_editPB_clicked() +{ + QModelIndexList selIdx = + selectedLV->selectionModel()->selectedIndexes(); + if (selIdx.isEmpty()) + return; + QModelIndex idx = selIdx.first(); + QString sel = idx.data().toString(); + FuncRequest fr(LFUN_INSET_EDIT, fromqstr(sel)); + dispatch(fr); +} + + void GuiBibtex::rescanClicked() { rescanBibStyles(); @@ -297,6 +311,7 @@ void GuiBibtex::setSelectedBibs(QStringList const sl) "encoding than specified below, set it here")); selectedLV->setIndexWidget(selected_model_.index(i, 1), cb); } + editPB->setEnabled(deletePB->isEnabled()); } @@ -392,6 +407,7 @@ void GuiBibtex::updateContents() biblatexOptsLE->setText(toqstr(params_["biblatexopts"])); setFileEncodings(getVectorFromString(params_["file_encodings"], from_ascii("\t"))); + editPB->setEnabled(deletePB->isEnabled()); } @@ -399,8 +415,8 @@ void GuiBibtex::applyView() { docstring dbs; - unsigned int maxCount = selected_bibs_.count(); - for (unsigned int i = 0; i < maxCount; i++) { + int maxCount = selected_bibs_.count(); + for (int i = 0; i < maxCount; i++) { if (i != 0) dbs += ','; QString item = selected_bibs_.at(i); diff --git a/src/frontends/qt4/GuiBibtex.h b/src/frontends/qt4/GuiBibtex.h index 9cbd0d61a4..997902e4ab 100644 --- a/src/frontends/qt4/GuiBibtex.h +++ b/src/frontends/qt4/GuiBibtex.h @@ -39,6 +39,7 @@ private Q_SLOTS: void on_buttonBox_accepted(); void browseBstPressed(); void browseBibPressed(); + void on_editPB_clicked(); void databaseChanged(); void rescanClicked(); void selUpdated(); diff --git a/src/frontends/qt4/ui/BibtexUi.ui b/src/frontends/qt4/ui/BibtexUi.ui index b66bffde24..1439e1864e 100644 --- a/src/frontends/qt4/ui/BibtexUi.ui +++ b/src/frontends/qt4/ui/BibtexUi.ui @@ -7,7 +7,7 @@ 0 0 523 - 576 + 617 @@ -141,6 +141,33 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Edit selected database externally + + + &Edit... + + + + .. + + + diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 0b879e1c50..a8965566fb 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -85,7 +85,7 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd) switch (cmd.action()) { case LFUN_INSET_EDIT: - editDatabases(); + editDatabases(cmd.argument()); break; case LFUN_INSET_MODIFY: { @@ -132,7 +132,7 @@ bool InsetBibtex::getStatus(Cursor & cur, FuncRequest const & cmd, } -void InsetBibtex::editDatabases() const +void InsetBibtex::editDatabases(docstring const db) const { vector bibfilelist = getVectorFromString(getParam("bibfiles")); @@ -140,7 +140,7 @@ void InsetBibtex::editDatabases() const return; size_t nr_databases = bibfilelist.size(); - if (nr_databases > 1) { + if (nr_databases > 1 && db.empty()) { docstring const engine = usingBiblatex() ? _("Biblatex") : _("BibTeX"); docstring message = bformat(_("The %1$s[[BibTeX/Biblatex]] inset includes %2$s databases.\n" "If you proceed, all of them will be opened."), @@ -155,6 +155,8 @@ void InsetBibtex::editDatabases() const vector::const_iterator it = bibfilelist.begin(); vector::const_iterator en = bibfilelist.end(); for (; it != en; ++it) { + if (!db.empty() && db != *it) + continue; FileName const bibfile = buffer().getBibfilePath(*it); theFormats().edit(buffer(), bibfile, theFormats().getFormatFromFile(bibfile)); diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index 4f38d84070..e6345b8566 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -82,7 +82,7 @@ public: private: /// - void editDatabases() const; + void editDatabases(docstring const db = docstring()) const; /// void parseBibTeXFiles(support::FileNameList &) const; /// -- 2.39.2