Added interface to reset the shortcuts defaults. Esp. useful in case of language mixup
This commit is contained in:
parent
8099951b0f
commit
bab3365313
@ -38,7 +38,9 @@ struct SCDef {
|
|||||||
|
|
||||||
class SCBase::Internal {
|
class SCBase::Internal {
|
||||||
public:
|
public:
|
||||||
|
QStringList getAll(const std::map<QString, SCDef>&);
|
||||||
std::map<QString, SCDef> scdefs;
|
std::map<QString, SCDef> scdefs;
|
||||||
|
std::map<QString, SCDef> scvalues;
|
||||||
QString scBaseSettingsKey() {
|
QString scBaseSettingsKey() {
|
||||||
return "/Recoll/prefs/sckeys";
|
return "/Recoll/prefs/sckeys";
|
||||||
}
|
}
|
||||||
@ -68,9 +70,10 @@ SCBase::SCBase()
|
|||||||
QString desc = u8s2qs(co_des_val[1]);
|
QString desc = u8s2qs(co_des_val[1]);
|
||||||
QString val = u8s2qs(co_des_val[2]);
|
QString val = u8s2qs(co_des_val[2]);
|
||||||
QString key = mapkey(ctxt, desc);
|
QString key = mapkey(ctxt, desc);
|
||||||
auto it = m->scdefs.find(key);
|
auto it = m->scvalues.find(key);
|
||||||
if (it == m->scdefs.end()) {
|
if (it == m->scvalues.end()) {
|
||||||
m->scdefs[key] = SCDef{ctxt, desc,QKeySequence(val), QKeySequence()};
|
m->scvalues[key] =
|
||||||
|
SCDef{ctxt, desc, QKeySequence(val), QKeySequence()};
|
||||||
} else {
|
} else {
|
||||||
it->second.val = QKeySequence(val);
|
it->second.val = QKeySequence(val);
|
||||||
}
|
}
|
||||||
@ -88,13 +91,14 @@ QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
|
|||||||
LOGDEB0("SCBase::get: [" << qs2utf8s(ctxt) << "]/[" <<
|
LOGDEB0("SCBase::get: [" << qs2utf8s(ctxt) << "]/[" <<
|
||||||
qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n");
|
qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n");
|
||||||
QString key = mapkey(ctxt, desc);
|
QString key = mapkey(ctxt, desc);
|
||||||
auto it = m->scdefs.find(key);
|
m->scdefs[key] = SCDef{ctxt, desc, QKeySequence(defks),QKeySequence(defks)};
|
||||||
if (it == m->scdefs.end()) {
|
auto it = m->scvalues.find(key);
|
||||||
|
if (it == m->scvalues.end()) {
|
||||||
if (defks.isEmpty()) {
|
if (defks.isEmpty()) {
|
||||||
return QKeySequence();
|
return QKeySequence();
|
||||||
}
|
}
|
||||||
QKeySequence qks(defks);
|
QKeySequence qks(defks);
|
||||||
m->scdefs[key] = SCDef{ctxt, desc, qks, qks};
|
m->scvalues[key] = SCDef{ctxt, desc, qks, qks};
|
||||||
LOGDEB0("get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
|
LOGDEB0("get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
|
||||||
", " << qs2utf8s(defks) << ") -> " <<
|
", " << qs2utf8s(defks) << ") -> " <<
|
||||||
qs2utf8s(qks.toString()) << "\n");
|
qs2utf8s(qks.toString()) << "\n");
|
||||||
@ -112,19 +116,19 @@ void SCBase::set(const QString& ctxt, const QString& desc, const QString& newks)
|
|||||||
LOGDEB0("SCBase::set: [" << qs2utf8s(ctxt) << "]/[" <<
|
LOGDEB0("SCBase::set: [" << qs2utf8s(ctxt) << "]/[" <<
|
||||||
qs2utf8s(desc) << "], [" << qs2utf8s(newks) << "]\n");
|
qs2utf8s(desc) << "], [" << qs2utf8s(newks) << "]\n");
|
||||||
QString key = mapkey(ctxt, desc);
|
QString key = mapkey(ctxt, desc);
|
||||||
auto it = m->scdefs.find(key);
|
auto it = m->scvalues.find(key);
|
||||||
if (it == m->scdefs.end()) {
|
if (it == m->scvalues.end()) {
|
||||||
QKeySequence qks(newks);
|
QKeySequence qks(newks);
|
||||||
m->scdefs[key] = SCDef{ctxt, desc, qks, QKeySequence()};
|
m->scvalues[key] = SCDef{ctxt, desc, qks, QKeySequence()};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->second.val = newks;
|
it->second.val = newks;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SCBase::getAll()
|
QStringList SCBase::Internal::getAll(const std::map<QString, SCDef>& mp)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for (const auto& entry : m->scdefs) {
|
for (const auto& entry : mp) {
|
||||||
result.push_back(entry.second.ctxt);
|
result.push_back(entry.second.ctxt);
|
||||||
result.push_back(entry.second.desc);
|
result.push_back(entry.second.desc);
|
||||||
result.push_back(entry.second.val.toString());
|
result.push_back(entry.second.val.toString());
|
||||||
@ -133,10 +137,20 @@ QStringList SCBase::getAll()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList SCBase::getAll()
|
||||||
|
{
|
||||||
|
return m->getAll(m->scvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SCBase::getAllDefaults()
|
||||||
|
{
|
||||||
|
return m->getAll(m->scdefs);
|
||||||
|
}
|
||||||
|
|
||||||
void SCBase::store()
|
void SCBase::store()
|
||||||
{
|
{
|
||||||
QStringList slout;
|
QStringList slout;
|
||||||
for (const auto& entry : m->scdefs) {
|
for (const auto& entry : m->scvalues) {
|
||||||
const SCDef& def = entry.second;
|
const SCDef& def = entry.second;
|
||||||
if (def.val != def.dflt) {
|
if (def.val != def.dflt) {
|
||||||
std::string e =
|
std::string e =
|
||||||
|
|||||||
@ -70,6 +70,11 @@ public:
|
|||||||
* quadruplet: context, description, value, default */
|
* quadruplet: context, description, value, default */
|
||||||
QStringList getAll();
|
QStringList getAll();
|
||||||
|
|
||||||
|
/** Return a list of all shortcuts, with only default values (no settings).
|
||||||
|
* Used for resetting the defaults, especially if a lang changed
|
||||||
|
* has messed up the keys */
|
||||||
|
QStringList getAllDefaults();
|
||||||
|
|
||||||
/** Store the customised values to the settings storage. Called
|
/** Store the customised values to the settings storage. Called
|
||||||
* from the preferences accept() method. */
|
* from the preferences accept() method. */
|
||||||
void store();
|
void store();
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>542</width>
|
<width>542</width>
|
||||||
<height>810</height>
|
<height>837</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -495,9 +495,37 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Shortcuts</string>
|
<string>Shortcuts</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="shortcutsTB"/>
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableWidget" name="shortcutsTB"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="resetscPB">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reset shortcuts defaults</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@ -101,6 +101,8 @@ void UIPrefsDialog::init()
|
|||||||
replAbsCB, SLOT(setEnabled(bool)));
|
replAbsCB, SLOT(setEnabled(bool)));
|
||||||
connect(ssNoCompleteCB, SIGNAL(toggled(bool)),
|
connect(ssNoCompleteCB, SIGNAL(toggled(bool)),
|
||||||
ssSearchOnCompleteCB, SLOT(setDisabled(bool)));
|
ssSearchOnCompleteCB, SLOT(setDisabled(bool)));
|
||||||
|
connect(resetscPB, SIGNAL(clicked()), this, SLOT(resetShortcuts()));
|
||||||
|
|
||||||
setFromPrefs();
|
setFromPrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,10 +278,9 @@ void UIPrefsDialog::setFromPrefs()
|
|||||||
readShortcuts();
|
readShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIPrefsDialog::readShortcuts()
|
void UIPrefsDialog::readShortcutsInternal(const QStringList& sl)
|
||||||
{
|
{
|
||||||
shortcutsTB->setRowCount(0);
|
shortcutsTB->setRowCount(0);
|
||||||
SCBase& scbase = SCBase::scBase();
|
|
||||||
shortcutsTB->setColumnCount(4);
|
shortcutsTB->setColumnCount(4);
|
||||||
shortcutsTB->setHorizontalHeaderItem(
|
shortcutsTB->setHorizontalHeaderItem(
|
||||||
0, new QTableWidgetItem(tr("Context")));
|
0, new QTableWidgetItem(tr("Context")));
|
||||||
@ -289,7 +290,6 @@ void UIPrefsDialog::readShortcuts()
|
|||||||
2, new QTableWidgetItem(tr("Shortcut")));
|
2, new QTableWidgetItem(tr("Shortcut")));
|
||||||
shortcutsTB->setHorizontalHeaderItem(
|
shortcutsTB->setHorizontalHeaderItem(
|
||||||
3, new QTableWidgetItem(tr("Default")));
|
3, new QTableWidgetItem(tr("Default")));
|
||||||
QStringList sl = scbase.getAll();
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (int i = 0; i < sl.size();) {
|
for (int i = 0; i < sl.size();) {
|
||||||
LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " <<
|
LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " <<
|
||||||
@ -307,6 +307,16 @@ void UIPrefsDialog::readShortcuts()
|
|||||||
shortcutsTB->horizontalHeader()->setStretchLastSection(true);
|
shortcutsTB->horizontalHeader()->setStretchLastSection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIPrefsDialog::readShortcuts()
|
||||||
|
{
|
||||||
|
readShortcutsInternal(SCBase::scBase().getAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIPrefsDialog::resetShortcuts()
|
||||||
|
{
|
||||||
|
readShortcutsInternal(SCBase::scBase().getAllDefaults());
|
||||||
|
}
|
||||||
|
|
||||||
void UIPrefsDialog::storeShortcuts()
|
void UIPrefsDialog::storeShortcuts()
|
||||||
{
|
{
|
||||||
SCBase& scbase = SCBase::scBase();
|
SCBase& scbase = SCBase::scBase();
|
||||||
|
|||||||
@ -67,6 +67,7 @@ public slots:
|
|||||||
virtual void editHeaderText();
|
virtual void editHeaderText();
|
||||||
virtual void extradDbSelectChanged();
|
virtual void extradDbSelectChanged();
|
||||||
virtual void extraDbEditPtrans();
|
virtual void extraDbEditPtrans();
|
||||||
|
virtual void resetShortcuts();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void uiprefsDone();
|
void uiprefsDone();
|
||||||
@ -78,6 +79,8 @@ private:
|
|||||||
void setupReslistFontPB();
|
void setupReslistFontPB();
|
||||||
void readShortcuts();
|
void readShortcuts();
|
||||||
void storeShortcuts();
|
void storeShortcuts();
|
||||||
|
void readShortcutsInternal(const QStringList&);
|
||||||
|
|
||||||
// Locally stored data (pending ok/cancel)
|
// Locally stored data (pending ok/cancel)
|
||||||
QString paraFormat;
|
QString paraFormat;
|
||||||
QString headerText;
|
QString headerText;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user