shortcuts prefs: use an arbitrary string as key instead of the textual description

This commit is contained in:
Jean-Francois Dockes 2021-03-09 10:07:46 +01:00
parent 88239c2ddd
commit 4814d57a85
9 changed files with 95 additions and 77 deletions

View File

@ -168,17 +168,21 @@ void AdvSearch::saveCnf()
void AdvSearch::onNewShortcuts() void AdvSearch::onNewShortcuts()
{ {
SETSHORTCUT(this, tr("Advanced Search"), tr("Load next stored search"), SETSHORTCUT(this, "advsearch:171",
tr("Advanced Search"), tr("Load next stored search"),
"Up", m_histnextsc, slotHistoryNext); "Up", m_histnextsc, slotHistoryNext);
SETSHORTCUT(this, tr("Advanced Search"), tr("Load previous stored search"), SETSHORTCUT(this, "advsearch:174",
tr("Advanced Search"), tr("Load previous stored search"),
"Down", m_histprevsc, slotHistoryPrev); "Down", m_histprevsc, slotHistoryPrev);
} }
void AdvSearch::listShortcuts() void AdvSearch::listShortcuts()
{ {
LISTSHORTCUT(this, tr("Advanced Search"), tr("Load next stored search"), LISTSHORTCUT(this, "advsearch:171",
tr("Advanced Search"), tr("Load next stored search"),
"Up", m_histnextsc, slotHistoryNext); "Up", m_histnextsc, slotHistoryNext);
LISTSHORTCUT(this, tr("Advanced Search"), tr("Load previous stored search"), LISTSHORTCUT(this, "advsearch:174",
tr("Advanced Search"), tr("Load previous stored search"),
"Down", m_histprevsc, slotHistoryPrev); "Down", m_histprevsc, slotHistoryPrev);
} }

View File

@ -148,16 +148,19 @@ void Preview::init()
void Preview::onNewShortcuts() void Preview::onNewShortcuts()
{ {
SETSHORTCUT(this, tr("Preview Window"), tr("Close preview window"), SETSHORTCUT(this, "preview:151", tr("Preview Window"),
tr("Close preview window"),
"Esc", m_closewinsc, close); "Esc", m_closewinsc, close);
SETSHORTCUT(this, tr("Preview Window"), tr("Show next result"), SETSHORTCUT(this, "preview:153",tr("Preview Window"), tr("Show next result"),
"Shift+Down", m_nextdocsc, emitShowNext); "Shift+Down", m_nextdocsc, emitShowNext);
SETSHORTCUT(this, tr("Preview Window"), tr("Show previous result"), SETSHORTCUT(this, "preview:155", tr("Preview Window"),
tr("Show previous result"),
"Shift+Up", m_prevdocsc, emitShowPrev); "Shift+Up", m_prevdocsc, emitShowPrev);
SETSHORTCUT(this, tr("Preview Window"), tr("Close tab"), SETSHORTCUT(this, "preview:159", tr("Preview Window"), tr("Close tab"),
"Ctrl+W", m_closetabsc, closeCurrentTab); "Ctrl+W", m_closetabsc, closeCurrentTab);
QKeySequence ks = QKeySequence ks =
SCBase::scBase().get(tr("Preview Window"),tr("Print"), "Ctrl+P"); SCBase::scBase().get("preview:162", tr("Preview Window"),
tr("Print"), "Ctrl+P");
if (!ks.isEmpty()) { if (!ks.isEmpty()) {
delete m_printtabsc; delete m_printtabsc;
m_printtabsc = new QShortcut( m_printtabsc = new QShortcut(
@ -167,16 +170,20 @@ void Preview::onNewShortcuts()
void Preview::listShortcuts() void Preview::listShortcuts()
{ {
LISTSHORTCUT(null, tr("Preview Window"), tr("Close preview window"), LISTSHORTCUT(null, "preview:151", tr("Preview Window"),
tr("Close preview window"),
"Esc", m_closewinsc, close); "Esc", m_closewinsc, close);
LISTSHORTCUT(null, tr("Preview Window"), tr("Show next result"), LISTSHORTCUT(null, "preview:153", tr("Preview Window"),
tr("Show next result"),
"Shift+Down", m_nextdocsc, emitShowNext); "Shift+Down", m_nextdocsc, emitShowNext);
LISTSHORTCUT(null, tr("Preview Window"), tr("Show previous result"), LISTSHORTCUT(null, "preview:155", tr("Preview Window"),
tr("Show previous result"),
"Shift+Up",m_prevdocsc, emitShowPrev); "Shift+Up",m_prevdocsc, emitShowPrev);
LISTSHORTCUT(null, tr("Preview Window"), tr("Close tab"), "Ctrl+W", LISTSHORTCUT(null, "preview:159",
m_closetabsc, closeCurrentTab); tr("Preview Window"), tr("Close tab"),
LISTSHORTCUT(null, tr("Preview Window"), tr("Print"), "Ctrl+P", "Ctrl+W", m_closetabsc, closeCurrentTab);
m_printtabsc, print); LISTSHORTCUT(null, "preview:162", tr("Preview Window"),
tr("Print"), "Ctrl+P", m_printtabsc, print);
} }
void Preview::emitShowNext() void Preview::emitShowNext()

View File

@ -344,20 +344,22 @@ void RclMain::onNewShortcuts()
SCBase& scb = SCBase::scBase(); SCBase& scb = SCBase::scBase();
QKeySequence ks; QKeySequence ks;
SETSHORTCUT(sSearch, tr("Main Window"), tr("Clear search"), SETSHORTCUT(sSearch, "main:347", tr("Main Window"), tr("Clear search"),
"Ctrl+S", m_clearsearchsc, clearAll); "Ctrl+S", m_clearsearchsc, clearAll);
SETSHORTCUT(sSearch, tr("Main Window"), SETSHORTCUT(sSearch, "main:349", tr("Main Window"),
tr("Move keyboard focus to search entry"), tr("Move keyboard focus to search entry"),
"Ctrl+L", m_focustosearchsc, takeFocus); "Ctrl+L", m_focustosearchsc, takeFocus);
SETSHORTCUT(sSearch, tr("Main Window"), SETSHORTCUT(sSearch, "main:352", tr("Main Window"),
tr("Move keyboard focus to search, alt."), tr("Move keyboard focus to search, alt."),
"Ctrl+Shift+S", m_focustosearcholdsc, takeFocus); "Ctrl+Shift+S", m_focustosearcholdsc, takeFocus);
// We could set this as an action shortcut, but then, it would not // We could set this as an action shortcut, but then, it would not
// be editable // be editable
SETSHORTCUT(this, tr("Main Window"), tr("Toggle tabular display"), SETSHORTCUT(this, "main:357",
tr("Main Window"), tr("Toggle tabular display"),
"Ctrl+T", m_toggletablesc, toggleTable); "Ctrl+T", m_toggletablesc, toggleTable);
ks = scb.get(tr("Main Window"), tr("Move keyboard focus to table"),"Ctrl+R"); ks = scb.get("rclmain:361", tr("Main Window"),
tr("Move keyboard focus to table"), "Ctrl+R");
if (!ks.isEmpty()) { if (!ks.isEmpty()) {
delete m_focustotablesc; delete m_focustotablesc;
m_focustotablesc = new QShortcut(ks, this); m_focustotablesc = new QShortcut(ks, this);

View File

@ -701,19 +701,21 @@ void ResTable::onNewShortcuts()
connect(sc, SIGNAL(activated()),m_rowlinks.back(),SLOT(activate())); connect(sc, SIGNAL(activated()),m_rowlinks.back(),SLOT(activate()));
} }
} }
SETSHORTCUT(this, tr("Result Table"), tr("Open current result document"), SETSHORTCUT(this, "restable:704", tr("Result Table"),
"Ctrl+O", m_opensc, menuEdit); tr("Open current result document"),"Ctrl+O", m_opensc, menuEdit);
SETSHORTCUT(this, tr("Result Table"), tr("Open current result and quit"), SETSHORTCUT(this, "restable:706", tr("Result Table"),
tr("Open current result and quit"),
"Ctrl+Shift+O", m_openquitsc, menuEditAndQuit); "Ctrl+Shift+O", m_openquitsc, menuEditAndQuit);
SETSHORTCUT(this, tr("Result Table"), tr("Preview"), SETSHORTCUT(this, "restable:709", tr("Result Table"), tr("Preview"),
"Ctrl+D", m_previewsc, menuPreview); "Ctrl+D", m_previewsc, menuPreview);
SETSHORTCUT(this, tr("Result Table"), tr("Show snippets"), SETSHORTCUT(this, "restable:711", tr("Result Table"), tr("Show snippets"),
"Ctrl+E", m_showsnipssc, menuShowSnippets); "Ctrl+E", m_showsnipssc, menuShowSnippets);
SETSHORTCUT(this, tr("Result Table"), tr("Show header"), SETSHORTCUT(this, "restable:713", tr("Result Table"), tr("Show header"),
"Ctrl+H", m_showheadersc, toggleHeader); "Ctrl+H", m_showheadersc, toggleHeader);
SETSHORTCUT(this, tr("Result Table"), tr("Show vertical header"), SETSHORTCUT(this, "restable:715", tr("Result Table"),
tr("Show vertical header"),
"Ctrl+V", m_showvheadersc, toggleVHeader); "Ctrl+V", m_showvheadersc, toggleVHeader);
SETSHORTCUT(this, tr("Result Table"), SETSHORTCUT(this, "restable:718", tr("Result Table"),
tr("Copy current result text to clipboard"), tr("Copy current result text to clipboard"),
"Ctrl+G", m_copycurtextsc, copyCurrentRowText); "Ctrl+G", m_copycurtextsc, copyCurrentRowText);
std::vector<QShortcut*> scps={ std::vector<QShortcut*> scps={

View File

@ -30,6 +30,7 @@
#include "log.h" #include "log.h"
struct SCDef { struct SCDef {
QString id;
QString ctxt; QString ctxt;
QString desc; QString desc;
QKeySequence val; QKeySequence val;
@ -46,11 +47,6 @@ public:
} }
}; };
static QString mapkey(const QString& ctxt, const QString& desc)
{
return ctxt + "/" + desc;
}
SCBase::SCBase() SCBase::SCBase()
{ {
m = new Internal(); m = new Internal();
@ -66,14 +62,14 @@ SCBase::SCBase()
LOGERR("Bad shortcut def in prefs: [" << ssc << "]\n"); LOGERR("Bad shortcut def in prefs: [" << ssc << "]\n");
continue; continue;
} }
QString ctxt = u8s2qs(co_des_val[0]); QString id = u8s2qs(co_des_val[0]);
QString desc = u8s2qs(co_des_val[1]); QString ctxt = u8s2qs(co_des_val[1]);
QString val = u8s2qs(co_des_val[2]); QString desc = u8s2qs(co_des_val[2]);
QString key = mapkey(ctxt, desc); QString val = u8s2qs(co_des_val[3]);
auto it = m->scvalues.find(key); auto it = m->scvalues.find(id);
if (it == m->scvalues.end()) { if (it == m->scvalues.end()) {
m->scvalues[key] = m->scvalues[id] =
SCDef{ctxt, desc, QKeySequence(val), QKeySequence()}; SCDef{id, ctxt, desc, QKeySequence(val), QKeySequence()};
} else { } else {
it->second.val = QKeySequence(val); it->second.val = QKeySequence(val);
} }
@ -85,20 +81,20 @@ SCBase::~SCBase()
delete m; delete m;
} }
QKeySequence SCBase::get(const QString& ctxt, const QString& desc, QKeySequence SCBase::get(const QString& id, const QString& ctxt,
const QString& defks) const QString& desc, const QString& defks)
{ {
LOGDEB0("SCBase::get: [" << qs2utf8s(ctxt) << "]/[" << LOGDEB0("SCBase::get: id "<< qs2utf8s(id) << " ["<<qs2utf8s(ctxt) << "]/[" <<
qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n"); qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n");
QString key = mapkey(ctxt, desc); m->scdefs[id] = SCDef{id, ctxt, desc, QKeySequence(defks),
m->scdefs[key] = SCDef{ctxt, desc, QKeySequence(defks),QKeySequence(defks)}; QKeySequence(defks)};
auto it = m->scvalues.find(key); auto it = m->scvalues.find(id);
if (it == m->scvalues.end()) { if (it == m->scvalues.end()) {
if (defks.isEmpty()) { if (defks.isEmpty()) {
return QKeySequence(); return QKeySequence();
} }
QKeySequence qks(defks); QKeySequence qks(defks);
m->scvalues[key] = SCDef{ctxt, desc, qks, qks}; m->scvalues[id] = SCDef{id, 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");
@ -111,15 +107,15 @@ QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
return it->second.val; return it->second.val;
} }
void SCBase::set(const QString& ctxt, const QString& desc, const QString& newks) void SCBase::set(const QString& id, const QString& ctxt, const QString& desc,
const QString& newks)
{ {
LOGDEB0("SCBase::set: [" << qs2utf8s(ctxt) << "]/[" << LOGDEB0("SCBase::set: id "<< qs2utf8s(id) << "["<< qs2utf8s(ctxt) << "]/[" <<
qs2utf8s(desc) << "], [" << qs2utf8s(newks) << "]\n"); qs2utf8s(desc) << "], [" << qs2utf8s(newks) << "]\n");
QString key = mapkey(ctxt, desc); auto it = m->scvalues.find(id);
auto it = m->scvalues.find(key);
if (it == m->scvalues.end()) { if (it == m->scvalues.end()) {
QKeySequence qks(newks); QKeySequence qks(newks);
m->scvalues[key] = SCDef{ctxt, desc, qks, QKeySequence()}; m->scvalues[id] = SCDef{id, ctxt, desc, qks, QKeySequence()};
return; return;
} }
it->second.val = newks; it->second.val = newks;
@ -129,6 +125,7 @@ QStringList SCBase::Internal::getAll(const std::map<QString, SCDef>& mp)
{ {
QStringList result; QStringList result;
for (const auto& entry : mp) { for (const auto& entry : mp) {
result.push_back(entry.second.id);
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());
@ -155,7 +152,7 @@ void SCBase::store()
if (def.val != def.dflt) { if (def.val != def.dflt) {
std::string e = std::string e =
stringsToString(std::vector<std::string>{ stringsToString(std::vector<std::string>{
qs2utf8s(def.ctxt), qs2utf8s(def.desc), qs2utf8s(def.id), qs2utf8s(def.ctxt), qs2utf8s(def.desc),
qs2utf8s(def.val.toString())}); qs2utf8s(def.val.toString())});
LOGDEB0("SCBase::store: storing: [" << e << "]\n"); LOGDEB0("SCBase::store: storing: [" << e << "]\n");
slout.append(u8s2qs(e)); slout.append(u8s2qs(e));

View File

@ -57,17 +57,17 @@ public:
* created from the settings, create it with the default * created from the settings, create it with the default
* sequence. This is called from the context classes and returns * sequence. This is called from the context classes and returns
* either the default or the customised sequence. */ * either the default or the customised sequence. */
QKeySequence get(const QString& context, const QString& description, QKeySequence get(const QString& id, const QString& context,
const QString& defkeyseq); const QString& description, const QString& defkeyseq);
/** Set a customised value for the designated shortcut. Called /** Set a customised value for the designated shortcut. Called
* from the preference code. */ * from the preference code. */
void set(const QString& context, const QString& description, void set(const QString& id, const QString& context,
const QString& keyseq); const QString& description, const QString& keyseq);
/** Return a list of all shortcuts. This is used to create the /** Return a list of all shortcuts. This is used to create the
* preferences table. Each entry in the list is a string * preferences table. Each entry in the list is a string
* quadruplet: context, description, value, default */ * tuple: id, context, description, value, default */
QStringList getAll(); QStringList getAll();
/** Return a list of all shortcuts, with only default values (no settings). /** Return a list of all shortcuts, with only default values (no settings).
@ -94,9 +94,9 @@ private:
/** This can be used in the client class init method, to actually /** This can be used in the client class init method, to actually
* create and connect the shortcuts. */ * create and connect the shortcuts. */
#define SETSHORTCUT(OBJ, CTXT, DESCR, SEQ, FLD, SLTFUNC) \ #define SETSHORTCUT(OBJ, ID, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
do { \ do { \
QKeySequence ks = SCBase::scBase().get(CTXT, DESCR, SEQ); \ QKeySequence ks = SCBase::scBase().get(ID, CTXT, DESCR, SEQ); \
if (!ks.isEmpty()) { \ if (!ks.isEmpty()) { \
delete FLD; \ delete FLD; \
FLD = new QShortcut(ks, OBJ, SLOT(SLTFUNC())); \ FLD = new QShortcut(ks, OBJ, SLOT(SLTFUNC())); \
@ -109,9 +109,9 @@ private:
* customisation screen. Same param list as SETSHORTCUT to make it * customisation screen. Same param list as SETSHORTCUT to make it
* easy to duplicate a list of ones into the other, even if some * easy to duplicate a list of ones into the other, even if some
* parameters are not used here. */ * parameters are not used here. */
#define LISTSHORTCUT(OBJ, CTXT, DESCR, SEQ, FLD, SLTFUNC) \ #define LISTSHORTCUT(OBJ, ID, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
do { \ do { \
SCBase::scBase().get(CTXT, DESCR, SEQ); \ SCBase::scBase().get(ID, CTXT, DESCR, SEQ); \
} while (false); } while (false);

View File

@ -153,29 +153,29 @@ void SnippetsW::init()
void SnippetsW::onNewShortcuts() void SnippetsW::onNewShortcuts()
{ {
SETSHORTCUT(this, tr("Snippets Window"), tr("Find"), SETSHORTCUT(this, "snippets:156", tr("Snippets Window"), tr("Find"),
"Ctrl+F", m_find1sc, slotEditFind); "Ctrl+F", m_find1sc, slotEditFind);
SETSHORTCUT(this, tr("Snippets Window"), tr("Find (alt)"), SETSHORTCUT(this, "snippets:158", tr("Snippets Window"), tr("Find (alt)"),
"/", m_find2sc, slotEditFind); "/", m_find2sc, slotEditFind);
SETSHORTCUT(this, tr("Snippets Window"), tr("Find next"), SETSHORTCUT(this, "snippets:160", tr("Snippets Window"), tr("Find next"),
"F3", m_findnextsc, slotEditFindNext); "F3", m_findnextsc, slotEditFindNext);
SETSHORTCUT(this, tr("Snippets Window"), tr("Find previous"), SETSHORTCUT(this, "snippets:162", tr("Snippets Window"), tr("Find previous"),
"Shift+F3", m_findprevsc, slotEditFindPrevious); "Shift+F3", m_findprevsc, slotEditFindPrevious);
SETSHORTCUT(this, tr("Snippets Window"), tr("Close window"), SETSHORTCUT(this, "snippets:164", tr("Snippets Window"), tr("Close window"),
"Esc", m_hidesc, hide); "Esc", m_hidesc, hide);
} }
void SnippetsW::listShortcuts() void SnippetsW::listShortcuts()
{ {
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find"), "Ctrl+F", LISTSHORTCUT(this, "snippets:156", tr("Snippets Window"), tr("Find"),
m_find1sc, slotEditFind); "Ctrl+F", m_find1sc, slotEditFind);
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find (alt)"), "/", LISTSHORTCUT(this, "snippets:158", tr("Snippets Window"), tr("Find (alt)"),
m_find2sc, slotEditFind); "/", m_find2sc, slotEditFind);
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find next"), "F3", LISTSHORTCUT(this, "snippets:160",tr("Snippets Window"), tr("Find next"),
m_find2sc, slotEditFindNext); "F3", m_find2sc, slotEditFindNext);
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find previous"), LISTSHORTCUT(this, "snippets:162",tr("Snippets Window"), tr("Find previous"),
"Shift+F3", m_find2sc, slotEditFindPrevious); "Shift+F3", m_find2sc, slotEditFindPrevious);
LISTSHORTCUT(this, tr("Snippets Window"), tr("Close window"), LISTSHORTCUT(this, "snippets:164", tr("Snippets Window"), tr("Close window"),
"Esc", m_hidesc, hide); "Esc", m_hidesc, hide);
} }

View File

@ -304,11 +304,13 @@ void UIPrefsDialog::readShortcutsInternal(const QStringList& sl)
shortcutsTB->setHorizontalHeaderItem( shortcutsTB->setHorizontalHeaderItem(
3, new QTableWidgetItem(tr("Default"))); 3, new QTableWidgetItem(tr("Default")));
int row = 0; int row = 0;
m_scids.clear();
for (int i = 0; i < sl.size();) { for (int i = 0; i < sl.size();) {
LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " << LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " <<
qs2utf8s(sl.at(i)) << " " << qs2utf8s(sl.at(i+1)) << " " << qs2utf8s(sl.at(i)) << " " << qs2utf8s(sl.at(i+1)) << " " <<
qs2utf8s(sl.at(i+2)) << " " << qs2utf8s(sl.at(i+3)) << "\n"); qs2utf8s(sl.at(i+2)) << " " << qs2utf8s(sl.at(i+3)) << "\n");
shortcutsTB->insertRow(row); shortcutsTB->insertRow(row);
m_scids.push_back(sl.at(i++));
shortcutsTB->setItem(row, 0, new QTableWidgetItem(sl.at(i++))); shortcutsTB->setItem(row, 0, new QTableWidgetItem(sl.at(i++)));
shortcutsTB->setItem(row, 1, new QTableWidgetItem(sl.at(i++))); shortcutsTB->setItem(row, 1, new QTableWidgetItem(sl.at(i++)));
auto ed = new QKeySequenceEdit(QKeySequence(sl.at(i++))); auto ed = new QKeySequenceEdit(QKeySequence(sl.at(i++)));
@ -339,7 +341,7 @@ void UIPrefsDialog::storeShortcuts()
QString ctxt = shortcutsTB->item(row, 1)->text(); QString ctxt = shortcutsTB->item(row, 1)->text();
auto qsce = (QKeySequenceEdit*)(shortcutsTB->cellWidget(row, 2)); auto qsce = (QKeySequenceEdit*)(shortcutsTB->cellWidget(row, 2));
QString val = qsce->keySequence().toString(); QString val = qsce->keySequence().toString();
scbase.set(dflt, ctxt, val); scbase.set(m_scids[row], dflt, ctxt, val);
} }
scbase.store(); scbase.store();
} }

View File

@ -21,6 +21,9 @@
#include "ui_uiprefs.h" #include "ui_uiprefs.h"
#include <vector>
#include <QString>
class QDialog; class QDialog;
class ViewAction; class ViewAction;
class RclMain; class RclMain;
@ -86,6 +89,7 @@ private:
QString headerText; QString headerText;
ViewAction *m_viewAction; ViewAction *m_viewAction;
RclMain *m_mainWindow; RclMain *m_mainWindow;
std::vector<QString> m_scids;
}; };
#endif /* _UIPREFS_W_H_INCLUDED_ */ #endif /* _UIPREFS_W_H_INCLUDED_ */