2008-06-05 15:08:46 +00:00
|
|
|
/**
|
|
|
|
* \file GuiInfo.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Abdelrazak Younes
|
2018-08-01 09:28:03 +02:00
|
|
|
* \author Jürgen Spitzmüller
|
2008-06-05 15:08:46 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiInfo.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "buffer_funcs.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
|
|
|
|
#include "insets/InsetInfo.h"
|
|
|
|
|
2012-06-28 20:52:20 +02:00
|
|
|
#include "support/debug.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "support/gettext.h"
|
2008-06-06 04:10:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2008-06-05 15:08:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
2008-06-06 04:10:42 +00:00
|
|
|
using namespace lyx::support;
|
2008-06-05 15:08:46 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GuiInfo
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-06-06 04:10:42 +00:00
|
|
|
char const * info_types[] =
|
2018-08-01 16:51:38 +02:00
|
|
|
{ "buffer",
|
|
|
|
"vcs",
|
|
|
|
"package",
|
|
|
|
"textclass",
|
|
|
|
"shortcut",
|
|
|
|
"shortcuts",
|
|
|
|
"menu",
|
|
|
|
"icon",
|
|
|
|
"lyxrc",
|
|
|
|
"lyxinfo",
|
|
|
|
"unknown",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
// GUI names (in combo)
|
2008-06-06 04:10:42 +00:00
|
|
|
char const * info_types_gui[] =
|
2018-08-01 16:51:38 +02:00
|
|
|
{ N_("Document Information"),// buffer
|
|
|
|
N_("Version Control Information"),// vcs
|
|
|
|
N_("LaTeX Package Availability"),// package
|
|
|
|
N_("LaTeX Class Availability"),// textclass
|
|
|
|
N_("Last Assigned Keyboard Shortcut"),// shortcut
|
|
|
|
N_("All Keyboard Shortcuts"),// shortcuts
|
|
|
|
N_("LyX Menu Location"),// menu
|
|
|
|
N_("LyX Toolbar Icon"),// icon
|
|
|
|
N_("LyX Preferences Entry"),// lyxrc
|
|
|
|
N_("LyX Application Information"),// lyxinfo
|
|
|
|
N_("Unknown"),// unknown
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
// Line edit label
|
2018-07-26 16:02:03 +02:00
|
|
|
char const * info_name_gui[] =
|
2018-08-01 16:51:38 +02:00
|
|
|
{ N_("Not Applicable"),// buffer
|
|
|
|
N_("Not Applicable"),// vcs
|
|
|
|
N_("Package Name"),// package
|
|
|
|
N_("Class Name"),// textclass
|
|
|
|
N_("LyX Function"),// shortcut
|
|
|
|
N_("LyX Function"),// shortcuts
|
|
|
|
N_("LyX Function"),// menu
|
|
|
|
N_("LyX Function"),// icon
|
|
|
|
N_("Preferences Key"),// lyxrc
|
|
|
|
N_("Not Applicable"),// lyxinfo
|
|
|
|
N_("Not Applicable"),// unknown
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
// Line edit tooltip
|
2018-07-26 16:02:03 +02:00
|
|
|
char const * info_tooltip[] =
|
2018-08-01 16:51:38 +02:00
|
|
|
{ N_("Please select a valid type above"),// buffer
|
|
|
|
N_("Please select a valid type above"),// vcs
|
2018-07-26 16:02:03 +02:00
|
|
|
N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
|
2018-08-01 16:51:38 +02:00
|
|
|
"The output will be 'Yes' (package available) or 'No' (package unavailable)."),// package
|
2018-07-26 16:02:03 +02:00
|
|
|
N_("Enter a LaTeX class name such as 'article' (extension is optional). "
|
2018-08-01 16:51:38 +02:00
|
|
|
"The output will be 'Yes' (class available) or 'No' (class unavailable)."),// textclass
|
|
|
|
N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
|
|
|
|
"The output is the most recently assigned keyboard shortcut for this function"),// shortcut
|
2018-07-26 16:02:03 +02:00
|
|
|
N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
|
2018-08-01 16:51:38 +02:00
|
|
|
"The output lists all possible keyboard shortcuts for this function"),// shortcuts
|
2018-07-26 16:02:03 +02:00
|
|
|
N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
|
2018-08-01 16:51:38 +02:00
|
|
|
"The output is the path to the function in the menu (using the current localization)."),// menu
|
|
|
|
N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
|
|
|
|
"The output is the toolbar icon for this function (using the active icon theme)."),// icon
|
|
|
|
N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "
|
|
|
|
"The output is the current setting of this preference."),// lyxrc
|
|
|
|
N_("Please select a valid type above"),// lyxinfo
|
|
|
|
N_("Please select a valid type above"),// unknown
|
2018-07-26 16:02:03 +02:00
|
|
|
""};
|
2008-06-06 04:10:42 +00:00
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2008-06-06 04:10:42 +00:00
|
|
|
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(true);
|
2008-06-06 04:10:42 +00:00
|
|
|
for (int n = 0; info_types[n][0]; ++n)
|
2018-07-26 16:02:03 +02:00
|
|
|
typeCO->addItem(qt_(info_types_gui[n]), info_types[n]);
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(false);
|
|
|
|
|
2018-08-01 09:28:03 +02:00
|
|
|
connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(updateArguments(int)));
|
2010-02-15 23:17:45 +00:00
|
|
|
connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
2018-08-01 09:28:03 +02:00
|
|
|
connect(infoLW, SIGNAL(currentTextChanged(QString)), this, SIGNAL(changed()));
|
2008-06-06 08:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 11:15:05 +00:00
|
|
|
void GuiInfo::paramsToDialog(Inset const * inset)
|
2008-06-06 08:45:58 +00:00
|
|
|
{
|
2010-01-30 11:15:05 +00:00
|
|
|
InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
|
2018-08-01 09:28:03 +02:00
|
|
|
inset_ = const_cast<Inset*>(inset);
|
2010-01-30 11:15:05 +00:00
|
|
|
QString const type = toqstr(ii->infoType());
|
|
|
|
QString const name = toqstr(ii->infoName());
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(true);
|
|
|
|
nameLE->blockSignals(true);
|
2018-08-01 09:28:03 +02:00
|
|
|
nameLE->clear();
|
2018-07-26 16:02:03 +02:00
|
|
|
int const i = typeCO->findData(type);
|
|
|
|
typeCO->setCurrentIndex(i);
|
2018-08-01 09:28:03 +02:00
|
|
|
updateArguments(i);
|
|
|
|
int argindex = -1;
|
|
|
|
int customindex = 0;
|
|
|
|
for (int i = 0 ; i < infoLW->count() ; ++i) {
|
|
|
|
if (infoLW->item(i)->data(Qt::UserRole).toString() == name)
|
|
|
|
argindex = i;
|
|
|
|
else if (infoLW->item(i)->data(Qt::UserRole).toString() == "custom")
|
|
|
|
customindex = i;
|
|
|
|
}
|
|
|
|
if (argindex != -1)
|
|
|
|
infoLW->setCurrentRow(argindex);
|
|
|
|
else {
|
|
|
|
// Without this test, 'math-insert' (name) will replace 'math-insert '
|
|
|
|
// in nameLE and effectively disallow the input of spaces after a LFUN.
|
|
|
|
if (nameLE->text().trimmed() != name)
|
|
|
|
nameLE->setText(name);
|
|
|
|
infoLW->setCurrentRow(customindex);
|
|
|
|
}
|
2008-06-06 08:45:58 +00:00
|
|
|
typeCO->blockSignals(false);
|
|
|
|
nameLE->blockSignals(false);
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 11:15:05 +00:00
|
|
|
docstring GuiInfo::dialogToParams() const
|
2008-06-05 15:08:46 +00:00
|
|
|
{
|
2018-07-26 16:02:03 +02:00
|
|
|
QString type =
|
|
|
|
typeCO->itemData(typeCO->currentIndex()).toString();
|
2018-08-01 09:28:03 +02:00
|
|
|
QString name = infoLW->currentItem() ?
|
|
|
|
infoLW->currentItem()->data(Qt::UserRole).toString()
|
|
|
|
: QString();
|
|
|
|
if (name == "custom")
|
|
|
|
name = nameLE->text();
|
2010-01-30 11:15:05 +00:00
|
|
|
return qstring_to_ucs4(type + ' ' + name);
|
2008-06-05 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 09:28:03 +02:00
|
|
|
void GuiInfo::updateArguments(int i)
|
|
|
|
{
|
|
|
|
infoLW->clear();
|
|
|
|
if (inset_) {
|
|
|
|
InsetInfo const * ii = static_cast<InsetInfo const *>(inset_);
|
|
|
|
vector<pair<string,docstring>> args = ii->getArguments(info_types[i]);
|
|
|
|
for (auto const & p : args) {
|
|
|
|
QListWidgetItem * li = new QListWidgetItem(toqstr(p.second));
|
|
|
|
li->setData(Qt::UserRole, toqstr(p.first));
|
|
|
|
if (p.first == "invalid")
|
|
|
|
// non-selectable, disabled item!
|
|
|
|
li->setFlags(Qt::NoItemFlags);
|
|
|
|
if (p.first == "custom")
|
|
|
|
li->setData(Qt::ToolTipRole, qt_("Enter a valid value below"));
|
|
|
|
infoLW->addItem(li);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (infoLW->count() > 0)
|
|
|
|
infoLW->setCurrentRow(0);
|
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-01 10:07:20 +02:00
|
|
|
bool GuiInfo::checkWidgets(bool readonly) const
|
|
|
|
{
|
|
|
|
nameLE->setReadOnly(readonly);
|
|
|
|
typeCO->setEnabled(!readonly);
|
2018-07-26 16:02:03 +02:00
|
|
|
nameLA->setText(qt_(info_name_gui[typeCO->currentIndex()]) + toqstr(":"));
|
2018-08-01 09:28:03 +02:00
|
|
|
|
|
|
|
QString const arg = infoLW->currentItem() ?
|
|
|
|
infoLW->currentItem()->data(Qt::UserRole).toString()
|
|
|
|
: QString();
|
|
|
|
|
|
|
|
bool const type_enabled = (arg == "custom");
|
2018-07-26 16:02:03 +02:00
|
|
|
nameLA->setEnabled(type_enabled);
|
|
|
|
nameLE->setEnabled(type_enabled);
|
|
|
|
nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
|
|
|
|
|
2015-04-01 10:07:20 +02:00
|
|
|
if (!InsetParamsWidget::checkWidgets())
|
|
|
|
return false;
|
2018-08-01 09:28:03 +02:00
|
|
|
return !arg.isEmpty() && (arg != "custom" || !nameLE->text().isEmpty());
|
2015-04-01 10:07:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 09:28:03 +02:00
|
|
|
|
2008-06-05 15:08:46 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiInfo.cpp"
|