shortcuts prefs: use an arbitrary string as key instead of the textual description
This commit is contained in:
parent
88239c2ddd
commit
4814d57a85
@ -168,17 +168,21 @@ void AdvSearch::saveCnf()
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -148,16 +148,19 @@ void Preview::init()
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
SETSHORTCUT(this, tr("Preview Window"), tr("Close tab"),
|
||||
SETSHORTCUT(this, "preview:159", tr("Preview Window"), tr("Close tab"),
|
||||
"Ctrl+W", m_closetabsc, closeCurrentTab);
|
||||
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()) {
|
||||
delete m_printtabsc;
|
||||
m_printtabsc = new QShortcut(
|
||||
@ -167,16 +170,20 @@ void Preview::onNewShortcuts()
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
LISTSHORTCUT(null, tr("Preview Window"), tr("Close tab"), "Ctrl+W",
|
||||
m_closetabsc, closeCurrentTab);
|
||||
LISTSHORTCUT(null, tr("Preview Window"), tr("Print"), "Ctrl+P",
|
||||
m_printtabsc, print);
|
||||
LISTSHORTCUT(null, "preview:159",
|
||||
tr("Preview Window"), tr("Close tab"),
|
||||
"Ctrl+W", m_closetabsc, closeCurrentTab);
|
||||
LISTSHORTCUT(null, "preview:162", tr("Preview Window"),
|
||||
tr("Print"), "Ctrl+P", m_printtabsc, print);
|
||||
}
|
||||
|
||||
void Preview::emitShowNext()
|
||||
|
||||
@ -344,20 +344,22 @@ void RclMain::onNewShortcuts()
|
||||
SCBase& scb = SCBase::scBase();
|
||||
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);
|
||||
SETSHORTCUT(sSearch, tr("Main Window"),
|
||||
SETSHORTCUT(sSearch, "main:349", tr("Main Window"),
|
||||
tr("Move keyboard focus to search entry"),
|
||||
"Ctrl+L", m_focustosearchsc, takeFocus);
|
||||
SETSHORTCUT(sSearch, tr("Main Window"),
|
||||
SETSHORTCUT(sSearch, "main:352", tr("Main Window"),
|
||||
tr("Move keyboard focus to search, alt."),
|
||||
"Ctrl+Shift+S", m_focustosearcholdsc, takeFocus);
|
||||
// We could set this as an action shortcut, but then, it would not
|
||||
// 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);
|
||||
|
||||
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()) {
|
||||
delete m_focustotablesc;
|
||||
m_focustotablesc = new QShortcut(ks, this);
|
||||
|
||||
@ -701,19 +701,21 @@ void ResTable::onNewShortcuts()
|
||||
connect(sc, SIGNAL(activated()),m_rowlinks.back(),SLOT(activate()));
|
||||
}
|
||||
}
|
||||
SETSHORTCUT(this, tr("Result Table"), tr("Open current result document"),
|
||||
"Ctrl+O", m_opensc, menuEdit);
|
||||
SETSHORTCUT(this, tr("Result Table"), tr("Open current result and quit"),
|
||||
SETSHORTCUT(this, "restable:704", tr("Result Table"),
|
||||
tr("Open current result document"),"Ctrl+O", m_opensc, menuEdit);
|
||||
SETSHORTCUT(this, "restable:706", tr("Result Table"),
|
||||
tr("Open current result and quit"),
|
||||
"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);
|
||||
SETSHORTCUT(this, tr("Result Table"), tr("Show snippets"),
|
||||
SETSHORTCUT(this, "restable:711", tr("Result Table"), tr("Show snippets"),
|
||||
"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);
|
||||
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);
|
||||
SETSHORTCUT(this, tr("Result Table"),
|
||||
SETSHORTCUT(this, "restable:718", tr("Result Table"),
|
||||
tr("Copy current result text to clipboard"),
|
||||
"Ctrl+G", m_copycurtextsc, copyCurrentRowText);
|
||||
std::vector<QShortcut*> scps={
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "log.h"
|
||||
|
||||
struct SCDef {
|
||||
QString id;
|
||||
QString ctxt;
|
||||
QString desc;
|
||||
QKeySequence val;
|
||||
@ -46,11 +47,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static QString mapkey(const QString& ctxt, const QString& desc)
|
||||
{
|
||||
return ctxt + "/" + desc;
|
||||
}
|
||||
|
||||
SCBase::SCBase()
|
||||
{
|
||||
m = new Internal();
|
||||
@ -66,14 +62,14 @@ SCBase::SCBase()
|
||||
LOGERR("Bad shortcut def in prefs: [" << ssc << "]\n");
|
||||
continue;
|
||||
}
|
||||
QString ctxt = u8s2qs(co_des_val[0]);
|
||||
QString desc = u8s2qs(co_des_val[1]);
|
||||
QString val = u8s2qs(co_des_val[2]);
|
||||
QString key = mapkey(ctxt, desc);
|
||||
auto it = m->scvalues.find(key);
|
||||
QString id = u8s2qs(co_des_val[0]);
|
||||
QString ctxt = u8s2qs(co_des_val[1]);
|
||||
QString desc = u8s2qs(co_des_val[2]);
|
||||
QString val = u8s2qs(co_des_val[3]);
|
||||
auto it = m->scvalues.find(id);
|
||||
if (it == m->scvalues.end()) {
|
||||
m->scvalues[key] =
|
||||
SCDef{ctxt, desc, QKeySequence(val), QKeySequence()};
|
||||
m->scvalues[id] =
|
||||
SCDef{id, ctxt, desc, QKeySequence(val), QKeySequence()};
|
||||
} else {
|
||||
it->second.val = QKeySequence(val);
|
||||
}
|
||||
@ -85,20 +81,20 @@ SCBase::~SCBase()
|
||||
delete m;
|
||||
}
|
||||
|
||||
QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
|
||||
const QString& defks)
|
||||
QKeySequence SCBase::get(const QString& id, const QString& ctxt,
|
||||
const QString& desc, const QString& defks)
|
||||
{
|
||||
LOGDEB0("SCBase::get: [" << qs2utf8s(ctxt) << "]/[" <<
|
||||
LOGDEB0("SCBase::get: id "<< qs2utf8s(id) << " ["<<qs2utf8s(ctxt) << "]/[" <<
|
||||
qs2utf8s(desc) << "], [" << qs2utf8s(defks) << "]\n");
|
||||
QString key = mapkey(ctxt, desc);
|
||||
m->scdefs[key] = SCDef{ctxt, desc, QKeySequence(defks),QKeySequence(defks)};
|
||||
auto it = m->scvalues.find(key);
|
||||
m->scdefs[id] = SCDef{id, ctxt, desc, QKeySequence(defks),
|
||||
QKeySequence(defks)};
|
||||
auto it = m->scvalues.find(id);
|
||||
if (it == m->scvalues.end()) {
|
||||
if (defks.isEmpty()) {
|
||||
return QKeySequence();
|
||||
}
|
||||
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) <<
|
||||
", " << qs2utf8s(defks) << ") -> " <<
|
||||
qs2utf8s(qks.toString()) << "\n");
|
||||
@ -111,15 +107,15 @@ QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
|
||||
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");
|
||||
QString key = mapkey(ctxt, desc);
|
||||
auto it = m->scvalues.find(key);
|
||||
auto it = m->scvalues.find(id);
|
||||
if (it == m->scvalues.end()) {
|
||||
QKeySequence qks(newks);
|
||||
m->scvalues[key] = SCDef{ctxt, desc, qks, QKeySequence()};
|
||||
m->scvalues[id] = SCDef{id, ctxt, desc, qks, QKeySequence()};
|
||||
return;
|
||||
}
|
||||
it->second.val = newks;
|
||||
@ -129,6 +125,7 @@ QStringList SCBase::Internal::getAll(const std::map<QString, SCDef>& mp)
|
||||
{
|
||||
QStringList result;
|
||||
for (const auto& entry : mp) {
|
||||
result.push_back(entry.second.id);
|
||||
result.push_back(entry.second.ctxt);
|
||||
result.push_back(entry.second.desc);
|
||||
result.push_back(entry.second.val.toString());
|
||||
@ -155,7 +152,7 @@ void SCBase::store()
|
||||
if (def.val != def.dflt) {
|
||||
std::string e =
|
||||
stringsToString(std::vector<std::string>{
|
||||
qs2utf8s(def.ctxt), qs2utf8s(def.desc),
|
||||
qs2utf8s(def.id), qs2utf8s(def.ctxt), qs2utf8s(def.desc),
|
||||
qs2utf8s(def.val.toString())});
|
||||
LOGDEB0("SCBase::store: storing: [" << e << "]\n");
|
||||
slout.append(u8s2qs(e));
|
||||
|
||||
@ -57,17 +57,17 @@ public:
|
||||
* created from the settings, create it with the default
|
||||
* sequence. This is called from the context classes and returns
|
||||
* either the default or the customised sequence. */
|
||||
QKeySequence get(const QString& context, const QString& description,
|
||||
const QString& defkeyseq);
|
||||
QKeySequence get(const QString& id, const QString& context,
|
||||
const QString& description, const QString& defkeyseq);
|
||||
|
||||
/** Set a customised value for the designated shortcut. Called
|
||||
* from the preference code. */
|
||||
void set(const QString& context, const QString& description,
|
||||
const QString& keyseq);
|
||||
void set(const QString& id, const QString& context,
|
||||
const QString& description, const QString& keyseq);
|
||||
|
||||
/** Return a list of all shortcuts. This is used to create the
|
||||
* preferences table. Each entry in the list is a string
|
||||
* quadruplet: context, description, value, default */
|
||||
* tuple: id, context, description, value, default */
|
||||
QStringList getAll();
|
||||
|
||||
/** 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
|
||||
* create and connect the shortcuts. */
|
||||
#define SETSHORTCUT(OBJ, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
|
||||
#define SETSHORTCUT(OBJ, ID, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
|
||||
do { \
|
||||
QKeySequence ks = SCBase::scBase().get(CTXT, DESCR, SEQ); \
|
||||
QKeySequence ks = SCBase::scBase().get(ID, CTXT, DESCR, SEQ); \
|
||||
if (!ks.isEmpty()) { \
|
||||
delete FLD; \
|
||||
FLD = new QShortcut(ks, OBJ, SLOT(SLTFUNC())); \
|
||||
@ -109,9 +109,9 @@ private:
|
||||
* customisation screen. Same param list as SETSHORTCUT to make it
|
||||
* easy to duplicate a list of ones into the other, even if some
|
||||
* parameters are not used here. */
|
||||
#define LISTSHORTCUT(OBJ, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
|
||||
#define LISTSHORTCUT(OBJ, ID, CTXT, DESCR, SEQ, FLD, SLTFUNC) \
|
||||
do { \
|
||||
SCBase::scBase().get(CTXT, DESCR, SEQ); \
|
||||
SCBase::scBase().get(ID, CTXT, DESCR, SEQ); \
|
||||
} while (false);
|
||||
|
||||
|
||||
|
||||
@ -153,29 +153,29 @@ void SnippetsW::init()
|
||||
|
||||
void SnippetsW::onNewShortcuts()
|
||||
{
|
||||
SETSHORTCUT(this, tr("Snippets Window"), tr("Find"),
|
||||
SETSHORTCUT(this, "snippets:156", tr("Snippets Window"), tr("Find"),
|
||||
"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);
|
||||
SETSHORTCUT(this, tr("Snippets Window"), tr("Find next"),
|
||||
SETSHORTCUT(this, "snippets:160", tr("Snippets Window"), tr("Find next"),
|
||||
"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);
|
||||
SETSHORTCUT(this, tr("Snippets Window"), tr("Close window"),
|
||||
SETSHORTCUT(this, "snippets:164", tr("Snippets Window"), tr("Close window"),
|
||||
"Esc", m_hidesc, hide);
|
||||
}
|
||||
|
||||
void SnippetsW::listShortcuts()
|
||||
{
|
||||
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find"), "Ctrl+F",
|
||||
m_find1sc, slotEditFind);
|
||||
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find (alt)"), "/",
|
||||
m_find2sc, slotEditFind);
|
||||
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find next"), "F3",
|
||||
m_find2sc, slotEditFindNext);
|
||||
LISTSHORTCUT(this, tr("Snippets Window"), tr("Find previous"),
|
||||
LISTSHORTCUT(this, "snippets:156", tr("Snippets Window"), tr("Find"),
|
||||
"Ctrl+F", m_find1sc, slotEditFind);
|
||||
LISTSHORTCUT(this, "snippets:158", tr("Snippets Window"), tr("Find (alt)"),
|
||||
"/", m_find2sc, slotEditFind);
|
||||
LISTSHORTCUT(this, "snippets:160",tr("Snippets Window"), tr("Find next"),
|
||||
"F3", m_find2sc, slotEditFindNext);
|
||||
LISTSHORTCUT(this, "snippets:162",tr("Snippets Window"), tr("Find previous"),
|
||||
"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);
|
||||
}
|
||||
|
||||
|
||||
@ -304,11 +304,13 @@ void UIPrefsDialog::readShortcutsInternal(const QStringList& sl)
|
||||
shortcutsTB->setHorizontalHeaderItem(
|
||||
3, new QTableWidgetItem(tr("Default")));
|
||||
int row = 0;
|
||||
m_scids.clear();
|
||||
for (int i = 0; i < sl.size();) {
|
||||
LOGDEB0("UIPrefsDialog::readShortcuts: inserting row " <<
|
||||
qs2utf8s(sl.at(i)) << " " << qs2utf8s(sl.at(i+1)) << " " <<
|
||||
qs2utf8s(sl.at(i+2)) << " " << qs2utf8s(sl.at(i+3)) << "\n");
|
||||
shortcutsTB->insertRow(row);
|
||||
m_scids.push_back(sl.at(i++));
|
||||
shortcutsTB->setItem(row, 0, new QTableWidgetItem(sl.at(i++)));
|
||||
shortcutsTB->setItem(row, 1, new QTableWidgetItem(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();
|
||||
auto qsce = (QKeySequenceEdit*)(shortcutsTB->cellWidget(row, 2));
|
||||
QString val = qsce->keySequence().toString();
|
||||
scbase.set(dflt, ctxt, val);
|
||||
scbase.set(m_scids[row], dflt, ctxt, val);
|
||||
}
|
||||
scbase.store();
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
|
||||
#include "ui_uiprefs.h"
|
||||
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
|
||||
class QDialog;
|
||||
class ViewAction;
|
||||
class RclMain;
|
||||
@ -86,6 +89,7 @@ private:
|
||||
QString headerText;
|
||||
ViewAction *m_viewAction;
|
||||
RclMain *m_mainWindow;
|
||||
std::vector<QString> m_scids;
|
||||
};
|
||||
|
||||
#endif /* _UIPREFS_W_H_INCLUDED_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user