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 {
|
||||
public:
|
||||
QStringList getAll(const std::map<QString, SCDef>&);
|
||||
std::map<QString, SCDef> scdefs;
|
||||
std::map<QString, SCDef> scvalues;
|
||||
QString scBaseSettingsKey() {
|
||||
return "/Recoll/prefs/sckeys";
|
||||
}
|
||||
@ -68,9 +70,10 @@ SCBase::SCBase()
|
||||
QString desc = u8s2qs(co_des_val[1]);
|
||||
QString val = u8s2qs(co_des_val[2]);
|
||||
QString key = mapkey(ctxt, desc);
|
||||
auto it = m->scdefs.find(key);
|
||||
if (it == m->scdefs.end()) {
|
||||
m->scdefs[key] = SCDef{ctxt, desc,QKeySequence(val), QKeySequence()};
|
||||
auto it = m->scvalues.find(key);
|
||||
if (it == m->scvalues.end()) {
|
||||
m->scvalues[key] =
|
||||
SCDef{ctxt, desc, QKeySequence(val), QKeySequence()};
|
||||
} else {
|
||||
it->second.val = QKeySequence(val);
|
||||
}
|
||||
@ -88,13 +91,14 @@ QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
|
||||
LOGDEB0("SCBase::get: [" << qs2utf8s(ctxt) << "]/[" <<
|
||||
qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n");
|
||||
QString key = mapkey(ctxt, desc);
|
||||
auto it = m->scdefs.find(key);
|
||||
if (it == m->scdefs.end()) {
|
||||
m->scdefs[key] = SCDef{ctxt, desc, QKeySequence(defks),QKeySequence(defks)};
|
||||
auto it = m->scvalues.find(key);
|
||||
if (it == m->scvalues.end()) {
|
||||
if (defks.isEmpty()) {
|
||||
return QKeySequence();
|
||||
}
|
||||
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) <<
|
||||
", " << qs2utf8s(defks) << ") -> " <<
|
||||
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) << "]/[" <<
|
||||
qs2utf8s(desc) << "], [" << qs2utf8s(newks) << "]\n");
|
||||
QString key = mapkey(ctxt, desc);
|
||||
auto it = m->scdefs.find(key);
|
||||
if (it == m->scdefs.end()) {
|
||||
auto it = m->scvalues.find(key);
|
||||
if (it == m->scvalues.end()) {
|
||||
QKeySequence qks(newks);
|
||||
m->scdefs[key] = SCDef{ctxt, desc, qks, QKeySequence()};
|
||||
m->scvalues[key] = SCDef{ctxt, desc, qks, QKeySequence()};
|
||||
return;
|
||||
}
|
||||
it->second.val = newks;
|
||||
}
|
||||
|
||||
QStringList SCBase::getAll()
|
||||
QStringList SCBase::Internal::getAll(const std::map<QString, SCDef>& mp)
|
||||
{
|
||||
QStringList result;
|
||||
for (const auto& entry : m->scdefs) {
|
||||
for (const auto& entry : mp) {
|
||||
result.push_back(entry.second.ctxt);
|
||||
result.push_back(entry.second.desc);
|
||||
result.push_back(entry.second.val.toString());
|
||||
@ -133,10 +137,20 @@ QStringList SCBase::getAll()
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList SCBase::getAll()
|
||||
{
|
||||
return m->getAll(m->scvalues);
|
||||
}
|
||||
|
||||
QStringList SCBase::getAllDefaults()
|
||||
{
|
||||
return m->getAll(m->scdefs);
|
||||
}
|
||||
|
||||
void SCBase::store()
|
||||
{
|
||||
QStringList slout;
|
||||
for (const auto& entry : m->scdefs) {
|
||||
for (const auto& entry : m->scvalues) {
|
||||
const SCDef& def = entry.second;
|
||||
if (def.val != def.dflt) {
|
||||
std::string e =
|
||||
|
||||
@ -70,6 +70,11 @@ public:
|
||||
* quadruplet: context, description, value, default */
|
||||
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
|
||||
* from the preferences accept() method. */
|
||||
void store();
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>542</width>
|
||||
<height>810</height>
|
||||
<height>837</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -495,9 +495,37 @@
|
||||
<attribute name="title">
|
||||
<string>Shortcuts</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@ -101,6 +101,8 @@ void UIPrefsDialog::init()
|
||||
replAbsCB, SLOT(setEnabled(bool)));
|
||||
connect(ssNoCompleteCB, SIGNAL(toggled(bool)),
|
||||
ssSearchOnCompleteCB, SLOT(setDisabled(bool)));
|
||||
connect(resetscPB, SIGNAL(clicked()), this, SLOT(resetShortcuts()));
|
||||
|
||||
setFromPrefs();
|
||||
}
|
||||
|
||||
@ -276,10 +278,9 @@ void UIPrefsDialog::setFromPrefs()
|
||||
readShortcuts();
|
||||
}
|
||||
|
||||
void UIPrefsDialog::readShortcuts()
|
||||
void UIPrefsDialog::readShortcutsInternal(const QStringList& sl)
|
||||
{
|
||||
shortcutsTB->setRowCount(0);
|
||||
SCBase& scbase = SCBase::scBase();
|
||||
shortcutsTB->setColumnCount(4);
|
||||
shortcutsTB->setHorizontalHeaderItem(
|
||||
0, new QTableWidgetItem(tr("Context")));
|
||||
@ -289,7 +290,6 @@ void UIPrefsDialog::readShortcuts()
|
||||
2, new QTableWidgetItem(tr("Shortcut")));
|
||||
shortcutsTB->setHorizontalHeaderItem(
|
||||
3, new QTableWidgetItem(tr("Default")));
|
||||
QStringList sl = scbase.getAll();
|
||||
int row = 0;
|
||||
for (int i = 0; i < sl.size();) {
|
||||
LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " <<
|
||||
@ -307,6 +307,16 @@ void UIPrefsDialog::readShortcuts()
|
||||
shortcutsTB->horizontalHeader()->setStretchLastSection(true);
|
||||
}
|
||||
|
||||
void UIPrefsDialog::readShortcuts()
|
||||
{
|
||||
readShortcutsInternal(SCBase::scBase().getAll());
|
||||
}
|
||||
|
||||
void UIPrefsDialog::resetShortcuts()
|
||||
{
|
||||
readShortcutsInternal(SCBase::scBase().getAllDefaults());
|
||||
}
|
||||
|
||||
void UIPrefsDialog::storeShortcuts()
|
||||
{
|
||||
SCBase& scbase = SCBase::scBase();
|
||||
|
||||
@ -67,6 +67,7 @@ public slots:
|
||||
virtual void editHeaderText();
|
||||
virtual void extradDbSelectChanged();
|
||||
virtual void extraDbEditPtrans();
|
||||
virtual void resetShortcuts();
|
||||
|
||||
signals:
|
||||
void uiprefsDone();
|
||||
@ -78,6 +79,8 @@ private:
|
||||
void setupReslistFontPB();
|
||||
void readShortcuts();
|
||||
void storeShortcuts();
|
||||
void readShortcutsInternal(const QStringList&);
|
||||
|
||||
// Locally stored data (pending ok/cancel)
|
||||
QString paraFormat;
|
||||
QString headerText;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user