diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index d4db1f40bd..bd27a601e6 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -669,6 +669,13 @@ Menuset Item "Settings...|S" "inset-settings" End +# +# InsetCounter context menu +# + Menu "context-counter" + Item "Settings...|S" "inset-settings" + End + # # Toolbar context menu # diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index b6071b8902..29fdcef9d1 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -398,6 +398,7 @@ Menuset Item "URL|U" "flex-insert URL" Item "Hyperlink...|k" "href-insert" Item "Footnote|F" "footnote-insert" + Item "Counter" "dialog-show-new-inset counter" Item "Marginal Note|M" "marginalnote-insert" Item "Program Listing[[Menu]]" "listing-insert" Separator diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index c9f76258f8..3de816a68f 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1461,7 +1461,7 @@ void LyXAction::init() * \li Action: Shows hidden dialog or creates new one for a given function/inset settings etc. * \li Syntax: dialog-show [] * \li Params: : aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n - compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n + compare|counter|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n graphics|href|include|index|index_print|info|label|line|listings|log|mathdelimiter|\n mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp new file mode 100644 index 0000000000..a4a5c4ac21 --- /dev/null +++ b/src/frontends/qt/GuiCounter.cpp @@ -0,0 +1,174 @@ +/** + * \file GuiCounter.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Richard Kimberly Heck + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GuiCounter.h" + +#include "qt_helpers.h" + +#include "Buffer.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "TextClass.h" +#include "insets/InsetCounter.h" +#include "insets/InsetCommandParams.h" + +#include "support/convert.h" +#include "support/gettext.h" +#include "support/lstrings.h" + +#include +//#include + +namespace lyx { +namespace frontend { + +GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) : + InsetParamsWidget(parent), guiview(lv) +{ + setupUi(this); + + connect(counterCB, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(changed())); + connect(actionCB, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(changed())); + connect(valueSB, SIGNAL(valueChanged(int)), + this, SIGNAL(changed())); + connect(vtypeCB, SIGNAL(clicked()), + this, SIGNAL(changed())); + connect(lyxonlyXB, SIGNAL(clicked()), + this, SIGNAL(changed())); + + // These are hardcoded and do not change + std::map const & ct = + InsetCounter::counterTable; + actionCB->clear(); + for (auto const & c : ct) { + docstring guistring = translateIfPossible(from_ascii(c.second)); + actionCB->addItem(toqstr(guistring), toqstr(c.first)); + } + + std::map const & vt = + InsetCounter::valueTable; + vtypeCB->clear(); + vtypeCB->addItem("", ""); + for (auto const & v : vt) { + docstring guistring = translateIfPossible(from_ascii(v.second)); + vtypeCB->addItem(toqstr(guistring), toqstr(v.first)); + } +} + + +void GuiCounter::processParams(InsetCommandParams const & params) +{ + QString const & counter = toqstr(params["counter"]); + int c = counterCB->findText(counter); + counterCB->setCurrentIndex(c); + + QString cmd = toqstr(params.getCmdName()); + c = actionCB->findData(cmd); + if (c < 0) { + c = 0; + LYXERR0("Unable to find " << cmd << " in GuiCounter!"); + } + actionCB->setCurrentIndex(c); + + int val = convert(params["value"]); + valueSB->setValue(val); + + cmd = toqstr(params["vtype"]); + c = cmd.isEmpty() ? 0 : vtypeCB->findData(cmd); + if (c < 0) { + c = 0; + LYXERR0("Unable to find " << cmd << " in GuiCounter!"); + } + vtypeCB->setCurrentIndex(c); + lyxonlyXB->setChecked(support::lowercase(params["lyxonly"]) == "true"); +} + + +void GuiCounter::fillCombos() +{ + counterCB->clear(); + BufferView * bv = guiview.documentBufferView(); + // should not happen, but... + if (!bv) + return; + + std::vector counts = + bv->buffer().params().documentClass().counters().listOfCounters(); + for (auto const & c : counts) + counterCB->addItem(toqstr(c)); +} + + +void GuiCounter::paramsToDialog(Inset const * ip) +{ + InsetCounter const * inset = static_cast(ip); + InsetCommandParams const & params = inset->params(); + + fillCombos(); + processParams(params); +} + + +bool GuiCounter::initialiseParams(std::string const & data) +{ + InsetCommandParams params(insetCode()); + if (!InsetCommand::string2params(data, params)) + return false; + + fillCombos(); + processParams(params); + return true; +} + + +docstring GuiCounter::dialogToParams() const +{ + InsetCommandParams params(insetCode()); + + params["counter"] = qstring_to_ucs4(counterCB->currentText()); + params["value"] = convert(valueSB->value()); + params.setCmdName(fromqstr(actionCB->currentData().toString())); + params["vtype"] = qstring_to_ucs4(vtypeCB->currentData().toString()); + params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false"); + return from_utf8(InsetCounter::params2string(params)); +} + + +bool GuiCounter::checkWidgets(bool readonly) const +{ + bool const cmdIsValue = actionCB->currentData().toString() == "value"; + bool const cmdIsSet = actionCB->currentData().toString() == "set"; + bool const cmdIsAddTo = actionCB->currentData().toString() == "addto"; + counterCB->setEnabled(!readonly); + actionCB->setEnabled(!readonly); + valueSB->setEnabled(!readonly && (cmdIsSet || cmdIsAddTo)); + if (cmdIsAddTo) + valueSB->setRange(-10000, 10000); + else + valueSB->setRange(0, 10000); + vtypeCB->setEnabled(!readonly && cmdIsValue); + if (!InsetParamsWidget::checkWidgets()) + return false; + return !readonly && + !counterCB->currentText().isEmpty() && + !actionCB->currentText().isEmpty() && + !(cmdIsValue && vtypeCB->currentText().isEmpty()); +} + + +} // namespace frontend +} // namespace lyx + + +#include "moc_GuiCounter.cpp" diff --git a/src/frontends/qt/GuiCounter.h b/src/frontends/qt/GuiCounter.h new file mode 100644 index 0000000000..7b13256039 --- /dev/null +++ b/src/frontends/qt/GuiCounter.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +/** + * \file GuiCounter.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Richard Kimberly Heck + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GUICOUNTER_H +#define GUICOUNTER_H + +#include "InsetParamsWidget.h" +#include "ui_CounterUi.h" +#include "GuiView.h" + +namespace lyx { +class InsetCommandParams; + +namespace frontend { + +class GuiCounter : public InsetParamsWidget, public Ui::CounterUi +{ + Q_OBJECT + +public: + /// + GuiCounter(GuiView & lv, QWidget * parent = nullptr); + +private: + /// \name InsetParamsWidget inherited methods + //@{ + InsetCode insetCode() const { return COUNTER_CODE; } + FuncCode creationCode() const { return LFUN_INSET_INSERT; } + QString dialogTitle() const { return qt_("Counters"); } + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + bool checkWidgets(bool readonly) const; + bool initialiseParams(std::string const & data); + //@} + void processParams(InsetCommandParams const & icp); + /// + void fillCombos(); + /// + GuiView & guiview; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GUICOUNTER_H diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index 382496e3e5..ba2951e4a6 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -4715,7 +4715,7 @@ namespace { char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", -"citation", "compare", "comparehistory", "document", "errorlist", "ert", +"citation", "compare", "comparehistory", "counter", "document", "errorlist", "ert", "external", "file", "findreplace", "findreplaceadv", "float", "graphics", "href", "include", "index", "index_print", "info", "listings", "label", "line", "log", "lyxfiles", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature", diff --git a/src/frontends/qt/InsetParamsDialog.cpp b/src/frontends/qt/InsetParamsDialog.cpp index a36de56988..5cb25ac060 100644 --- a/src/frontends/qt/InsetParamsDialog.cpp +++ b/src/frontends/qt/InsetParamsDialog.cpp @@ -15,6 +15,7 @@ #include "GuiBox.h" #include "GuiBranch.h" #include "GuiBibitem.h" +#include "GuiCounter.h" #include "GuiERT.h" #include "GuiHSpace.h" #include "GuiHyperlink.h" @@ -281,6 +282,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case HYPERLINK_CODE: widget = new GuiHyperlink; break; + case COUNTER_CODE: + widget = new GuiCounter(lv, nullptr); + break; case INFO_CODE: widget = new GuiInfo; break; diff --git a/src/frontends/qt/InsetParamsDialog.h b/src/frontends/qt/InsetParamsDialog.h index 2d876ba431..48385e2345 100644 --- a/src/frontends/qt/InsetParamsDialog.h +++ b/src/frontends/qt/InsetParamsDialog.h @@ -25,6 +25,10 @@ namespace frontend { class InsetParamsWidget; +/// An InsetParamsDialog wraps an InsetParamsWidget, which is what +/// will contain all the specific dialog parts for a given inset. +/// This class manages the OK, etc, buttons and immediate apply +/// checkbox, etc. class InsetParamsDialog : public DialogView, public Ui::InsetParamsUi { Q_OBJECT diff --git a/src/frontends/qt/Makefile.am b/src/frontends/qt/Makefile.am index f5f75cb19d..eb933c7173 100644 --- a/src/frontends/qt/Makefile.am +++ b/src/frontends/qt/Makefile.am @@ -87,6 +87,7 @@ SOURCEFILES = \ GuiCompare.cpp \ GuiCompareHistory.cpp \ GuiCompleter.cpp \ + GuiCounter.cpp \ GuiDelimiter.cpp \ GuiDialog.cpp \ GuiDocument.cpp \ @@ -205,6 +206,7 @@ MOCHEADER = \ GuiCompare.h \ GuiCompareHistory.h \ GuiCompleter.h \ + GuiCounter.h \ GuiDelimiter.h \ GuiDialog.h \ GuiDocument.h \ @@ -285,6 +287,7 @@ UIFILES = \ ColorUi.ui \ CompareUi.ui \ CompareHistoryUi.ui \ + CounterUi.ui \ DelimiterUi.ui \ DocumentUi.ui \ ErrorListUi.ui \ diff --git a/src/frontends/qt/ui/CounterUi.ui b/src/frontends/qt/ui/CounterUi.ui new file mode 100644 index 0000000000..93298e44eb --- /dev/null +++ b/src/frontends/qt/ui/CounterUi.ui @@ -0,0 +1,81 @@ + + + CounterUi + + + + 0 + 0 + 290 + 197 + + + + + + + + + + Value Type + + + + + + + Value + + + + + + + + + + Counter + + + + + + + + + + 10000 + + + + + + + Action + + + + + + + + + + Affect counters only in LyX, not in output + + + Qt::RightToLeft + + + LyX Only + + + + + + + qt_i18n.h + + + +