Shortcut editor ok?

This commit is contained in:
Jean-Francois Dockes 2021-01-20 14:21:45 +01:00
parent ea9a9f511f
commit d2ce3845d0
17 changed files with 261 additions and 122 deletions

View File

@ -34,7 +34,6 @@
#include <string>
#include <map>
#include <algorithm>
using namespace std;
#include "recoll.h"
#include "rclconfig.h"
@ -42,11 +41,15 @@ using namespace std;
#include "searchdata.h"
#include "guiutils.h"
#include "rclhelp.h"
#include "scbase.h"
using namespace std;
static const int initclausetypes[] = {1, 3, 0, 2, 5};
static const unsigned int iclausescnt = sizeof(initclausetypes) / sizeof(int);
static map<QString,QString> cat_translations;
static map<QString,QString> cat_rtranslations;
static const QString scbctxt("Advanced Search");
void AdvSearch::init()
{
@ -78,8 +81,9 @@ void AdvSearch::init()
connect(addClausePB, SIGNAL(clicked()), this, SLOT(addClause()));
connect(delClausePB, SIGNAL(clicked()), this, SLOT(delClause()));
new QShortcut(QKeySequence(Qt::Key_Up), this, SLOT(slotHistoryNext()));;
new QShortcut(QKeySequence(Qt::Key_Down), this, SLOT(slotHistoryPrev()));
onNewShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()),
this, SLOT(onNewShortcuts()));
conjunctCMB->insertItem(1, tr("All clauses"));
conjunctCMB->insertItem(2, tr("Any clause"));
@ -163,6 +167,18 @@ void AdvSearch::saveCnf()
}
}
void AdvSearch::onNewShortcuts()
{
SETSHORTCUT("History Next", "Up", m_histnextsc, slotHistoryNext);
SETSHORTCUT("History Prev", "Down", m_histprevsc, slotHistoryPrev);
}
void AdvSearch::listShortcuts()
{
LISTSHORTCUT("History Next", "Up", m_histnextsc, slotHistoryNext);
LISTSHORTCUT("History Prev", "Down", m_histprevsc, slotHistoryPrev);
}
void AdvSearch::addClause(bool updsaved)
{
addClause(0, updsaved);

View File

@ -30,6 +30,7 @@
#include "advshist.h"
class QDialog;
class QShortcut;
#include "ui_advsearch.h"
@ -43,6 +44,7 @@ public:
setupUi(this);
init();
}
static void listShortcuts();
public slots:
virtual void delFiltypPB_clicked();
@ -63,7 +65,8 @@ public slots:
virtual void addClause(int, bool updsaved=true);
virtual void slotHistoryNext();
virtual void slotHistoryPrev();
virtual void onNewShortcuts();
signals:
void startSearch(std::shared_ptr<Rcl::SearchData>, bool);
void setDescription(QString);
@ -73,6 +76,9 @@ private:
std::vector<SearchClauseW *> m_clauseWins;
QStringList m_ignTypes;
bool m_ignByCats;
QShortcut *m_histnextsc{nullptr};
QShortcut *m_histprevsc{nullptr};
void saveCnf();
void fillFileTypes();
size_t stringToSize(QString);

View File

@ -60,12 +60,9 @@
#include "preview_load.h"
#include "preview_plaintorich.h"
#include "rclmain_w.h"
#include "scbase.h"
static const QKeySequence closeKS(Qt::Key_Escape);
static const QKeySequence nextDocInTabKS(Qt::ShiftModifier+Qt::Key_Down);
static const QKeySequence prevDocInTabKS(Qt::ShiftModifier+Qt::Key_Up);
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
static const QKeySequence printTabKS(Qt::ControlModifier+Qt::Key_P);
static const QString scbctxt("Preview Window");
// Make an attempt at trimming wildcard exprs at both ends of string
static void trimwildcards(string& elt)
@ -142,22 +139,38 @@ void Preview::init()
connect(pvTab, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
connect(pvTab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
this, SLOT (close()));
connect(new QShortcut(nextDocInTabKS, this), SIGNAL (activated()),
this, SLOT (emitShowNext()));
connect(nextInTabPB, SIGNAL (clicked()), this, SLOT (emitShowNext()));
connect(new QShortcut(prevDocInTabKS, this), SIGNAL (activated()),
this, SLOT (emitShowPrev()));
connect(prevInTabPB, SIGNAL (clicked()), this, SLOT (emitShowPrev()));
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
this, SLOT (closeCurrentTab()));
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
this, SIGNAL (printCurrentPreviewRequest()));
onNewShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()),
this, SLOT(onNewShortcuts()));
connect(nextInTabPB, SIGNAL (clicked()), this, SLOT (emitShowNext()));
connect(prevInTabPB, SIGNAL (clicked()), this, SLOT (emitShowPrev()));
currentChanged(pvTab->currentIndex());
}
void Preview::onNewShortcuts()
{
SETSHORTCUT("Close Window", "Esc", m_closewinsc, close);
SETSHORTCUT("Next doc in tab", "Shift+Down", m_nextdocsc, emitShowNext);
SETSHORTCUT("Previous doc in tab", "Shift+Up", m_prevdocsc,emitShowPrev);
SETSHORTCUT("Close tab", "Ctrl+W", m_closetabsc, closeCurrentTab);
QKeySequence ks = SCBase::scBase().get(scbctxt, "Print tab", "Ctrl+P");
if (!ks.isEmpty()) {
delete m_printtabsc;
m_printtabsc = new QShortcut(ks, this,
SIGNAL(printCurrentPreviewRequest()));
}
}
void Preview::listShortcuts()
{
LISTSHORTCUT("Close Window", "Esc", m_closewinsc, close);
LISTSHORTCUT("Next doc in tab", "Shift+Down", m_nextdocsc, emitShowNext);
LISTSHORTCUT("Previous doc in tab", "Shift+Up", m_prevdocsc,emitShowPrev);
LISTSHORTCUT("Close tab", "Ctrl+W", m_closetabsc, closeCurrentTab);
LISTSHORTCUT("Print tab", "Ctrl+P", m_printtabsc, print);
}
void Preview::emitShowNext()
{
if (m_loading)

View File

@ -113,6 +113,7 @@ private:
DspType m_curdsp;
};
class QShortcut;
class Preview : public QDialog, public Ui::Preview {
Q_OBJECT
@ -140,6 +141,10 @@ public:
void emitWordSelect(QString);
friend class PreviewTextEdit;
/** List shortcuts so that the prefs can be edited before any preview
is created */
static void listShortcuts();
public slots:
// Search stuff
virtual void searchTextChanged(const QString& text);
@ -158,7 +163,8 @@ public slots:
virtual void emitSaveDocToFile();
virtual void emitEditRequested();
virtual void togglePlainPre();
virtual void onNewShortcuts();
signals:
void previewClosed(Preview *);
void wordSelect(QString);
@ -184,7 +190,12 @@ private:
bool m_loading{false};
HighlightData m_hData;
bool m_justCreated{true}; // First tab create is different
QShortcut *m_closewinsc{nullptr};
QShortcut *m_nextdocsc{nullptr};
QShortcut *m_prevdocsc{nullptr};
QShortcut *m_closetabsc{nullptr};
QShortcut *m_printtabsc{nullptr};
void init();
virtual void setCurTabProps(const Rcl::Doc& doc, int docnum);
virtual PreviewTextEdit *editor(int);

View File

@ -165,9 +165,12 @@ void RclMain::init()
on_actionShowResultsAsTable_toggled(prefs.showResultsAsTable);
onNewShortcuts();
// Compat with old versions
new QShortcut(QKeySequence("Ctrl+Shift+s"), sSearch, SLOT(takeFocus()));
Preview::listShortcuts();
SnippetsW::listShortcuts();
AdvSearch::listShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()),
this, SLOT(onNewShortcuts()));
connect(&m_watcher, SIGNAL(fileChanged(QString)),
this, SLOT(updateIdxStatus()));
@ -342,14 +345,35 @@ void RclMain::onNewShortcuts()
SCBase& scb = SCBase::scBase();
QKeySequence ks;
ks = scb.get(scbctxt, "Focus to Search Entry", "Ctrl+l");
if (!ks.isEmpty())
new QShortcut(ks, sSearch, SLOT(takeFocus()));
ks = scb.get(scbctxt, "Focus to Result Table", "Ctrl+r");
ks = scb.get(scbctxt, "Focus to Search", "Ctrl+L");
if (!ks.isEmpty()) {
delete m_tablefocseq;
m_tablefocseq = new QShortcut(ks, this);
delete m_focustosearchsc;
m_focustosearchsc = new QShortcut(ks, sSearch, SLOT(takeFocus()));
}
ks = scb.get(scbctxt, "Focus to Search, alt.", "Ctrl+Shift+S");
if (!ks.isEmpty()) {
delete m_focustosearcholdsc;
m_focustosearcholdsc = new QShortcut(ks, sSearch, SLOT(takeFocus()));
}
ks = scb.get(scbctxt, "Clear Search", "Ctrl+S");
if (!ks.isEmpty()) {
delete m_clearsearchsc;
m_clearsearchsc = new QShortcut(ks, sSearch, SLOT(clearAll()));
}
ks = scb.get(scbctxt, "Focus to Result Table", "Ctrl+R");
if (!ks.isEmpty()) {
delete m_focustotablesc;
m_focustotablesc = new QShortcut(ks, this);
if (displayingTable) {
connect(m_focustotablesc, SIGNAL(activated()),
restable, SLOT(takeFocus()));
} else {
disconnect(m_focustotablesc, SIGNAL(activated()),
restable, SLOT(takeFocus()));
}
}
}
@ -1006,8 +1030,8 @@ void RclMain::on_actionShowResultsAsTable_toggled(bool on)
if (docnum >= 0) {
reslist->resultPageFor(docnum);
}
if (m_tablefocseq)
disconnect(m_tablefocseq, SIGNAL(activated()),
if (m_focustotablesc)
disconnect(m_focustotablesc, SIGNAL(activated()),
restable, SLOT(takeFocus()));
sSearch->takeFocus();
} else {
@ -1018,8 +1042,8 @@ void RclMain::on_actionShowResultsAsTable_toggled(bool on)
nextPageAction->setEnabled(false);
prevPageAction->setEnabled(false);
firstPageAction->setEnabled(false);
if (m_tablefocseq)
connect(m_tablefocseq, SIGNAL(activated()),
if (m_focustotablesc)
connect(m_focustotablesc, SIGNAL(activated()),
restable, SLOT(takeFocus()));
}
}

View File

@ -216,7 +216,10 @@ private:
QComboBox *m_filtCMB{0};
QButtonGroup *m_filtBGRP{0};
QMenu *m_filtMN{0};
QShortcut *m_tablefocseq{0};
QShortcut *m_focustotablesc{0};
QShortcut *m_focustosearchsc{0};
QShortcut *m_focustosearcholdsc{0};
QShortcut *m_clearsearchsc{0};
QFileSystemWatcher m_watcher;
vector<ExecCmd*> m_viewers;
ExecCmd *m_idxproc{0}; // Indexing process

View File

@ -43,6 +43,7 @@ HEADERS += \
reslist.h \
restable.h \
rtitool.h \
scbase.h \
searchclause_w.h \
snippets_w.h \
specialindex.h \

View File

@ -592,6 +592,8 @@ void ResTable::init()
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
onNewShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()),
this, SLOT(onNewShortcuts()));
connect(tableView, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(createPopupMenu(const QPoint&)));
@ -662,23 +664,10 @@ void ResTable::init()
void ResTable::onNewShortcuts()
{
SCBase& scb = SCBase::scBase();
QKeySequence ks;
ks = scb.get(scbctxt, "Open", "Ctrl+o");
if (!ks.isEmpty())
new QShortcut(ks, this, SLOT(menuEdit()));
ks = scb.get(scbctxt, "Open and Quit", "Ctrl+Shift+o");
if (!ks.isEmpty())
new QShortcut(ks, this, SLOT(menuEditAndQuit()));
ks = scb.get(scbctxt, "Preview", "Ctrl+d");
if (!ks.isEmpty())
new QShortcut(ks, this, SLOT(menuPreview()));
ks = scb.get(scbctxt, "Show Snippets", "Ctrl+e");
if (!ks.isEmpty())
new QShortcut(ks, this, SLOT(menuShowSnippets()));
SETSHORTCUT("Open", "Ctrl+O", m_opensc, menuEdit);
SETSHORTCUT("Open and Quit", "Ctrl+Shift+O", m_openquitsc, menuEditAndQuit);
SETSHORTCUT("Preview", "Ctrl+D", m_previewsc, menuPreview);
SETSHORTCUT("Show Snippets", "Ctrl+E", m_showsnipssc, menuShowSnippets);
}
bool ResTable::eventFilter(QObject* obj, QEvent* event)

View File

@ -111,6 +111,7 @@ private:
class ResTablePager;
class QUrl;
class RclMain;
class QShortcut;
class ResTable : public QWidget, public Ui::ResTable
{
@ -187,14 +188,18 @@ protected:
bool eventFilter(QObject* obj, QEvent* event);
private:
void init();
RecollModel *m_model;
ResTablePager *m_pager;
ResTableDetailArea *m_detail;
RecollModel *m_model{nullptr};
ResTablePager *m_pager{nullptr};
ResTableDetailArea *m_detail{nullptr};
int m_detaildocnum;
Rcl::Doc m_detaildoc;
int m_popcolumn;
RclMain *m_rclmain;
RclMain *m_rclmain{nullptr};
bool m_ismainres;
QShortcut *m_opensc{nullptr};
QShortcut *m_openquitsc{nullptr};
QShortcut *m_previewsc{nullptr};
QShortcut *m_showsnipssc{nullptr};
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2017-2019 J.F.Dockes
/* Copyright (C) 2021 J.F.Dockes
*
* License: GPL 2.1
*
@ -39,29 +39,22 @@ struct SCDef {
class SCBase::Internal {
public:
std::map<QString, SCDef> scdefs;
QString scBaseSettingsKey() {
return "/Recoll/prefs/sckeys";
}
};
static QString mapkey(const QString& ctxt, const QString& desc)
{
return ctxt + "/" + desc;
}
#if 0
static QString mapkey(const std::string& ctxt, const std::string& desc)
{
return u8s2qs(ctxt) + "/" + u8s2qs(desc);
}
#endif
QString SCBase::scBaseSettingsKey()
{
return "/Recoll/prefs/sckeys";
}
SCBase::SCBase()
{
m = new Internal();
QSettings settings;
auto sl = settings.value(scBaseSettingsKey()).toStringList();
auto sl = settings.value(m->scBaseSettingsKey()).toStringList();
for (int i = 0; i < sl.size(); ++i) {
auto ssc = qs2utf8s(sl.at(i));
@ -92,7 +85,8 @@ SCBase::~SCBase()
QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
const QString& defks)
{
std::cerr << "SCBase::get\n";
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()) {
@ -101,17 +95,32 @@ QKeySequence SCBase::get(const QString& ctxt, const QString& desc,
}
QKeySequence qks(defks);
m->scdefs[key] = SCDef{ctxt, desc, qks, qks};
std::cerr << "get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
LOGDEB0("get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
", " << qs2utf8s(defks) << ") -> " <<
qs2utf8s(qks.toString()) << "\n";
qs2utf8s(qks.toString()) << "\n");
return qks;
}
std::cerr << "get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
LOGDEB0("SCBase::get(" << qs2utf8s(ctxt) << ", " << qs2utf8s(desc) <<
", " << qs2utf8s(defks) << ") -> " <<
qs2utf8s(it->second.val.toString()) << "\n";
qs2utf8s(it->second.val.toString()) << "\n");
it->second.dflt = QKeySequence(defks);
return it->second.val;
}
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()) {
QKeySequence qks(newks);
m->scdefs[key] = SCDef{ctxt, desc, qks, QKeySequence()};
return;
}
it->second.val = newks;
}
QStringList SCBase::getAll()
{
QStringList result;
@ -124,15 +133,33 @@ QStringList SCBase::getAll()
return result;
}
void SCBase::store()
{
QStringList slout;
for (const auto& entry : m->scdefs) {
const SCDef& def = entry.second;
if (def.val != def.dflt) {
std::string e =
stringsToString(std::vector<std::string>{
qs2utf8s(def.ctxt), qs2utf8s(def.desc),
qs2utf8s(def.val.toString())});
LOGDEB0("SCBase::store: storing: [" << e << "]\n");
slout.append(u8s2qs(e));
}
}
// Note: we emit even if the non-default values are not really
// changed, just not worth the trouble doing otherwise.
emit shortcutsChanged();
QSettings settings;
settings.setValue(m->scBaseSettingsKey(), slout);
}
static SCBase *theBase;
SCBase& SCBase::scBase()
{
std::cerr << "SCBase::scBase()\n";
if (nullptr == theBase) {
std::cerr << "SCBase::scBase() creating class\n";
theBase = new SCBase();
}
std::cerr << "SCBase::scBase() returning " << theBase << "\n";
return *theBase;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2017-2019 J.F.Dockes
/* Copyright (C) 2021 J.F.Dockes
*
* License: GPL 2.1
*
@ -24,8 +24,10 @@
#include <QString>
#include <QKeySequence>
#include <QStringList>
#include <QObject>
class SCBase {
class SCBase : public QObject {
Q_OBJECT;
public:
~SCBase();
@ -34,12 +36,33 @@ public:
QKeySequence get(const QString& context, const QString& description,
const QString& defkeyseq);
QStringList getAll();
static QString scBaseSettingsKey();
void set(const QString& context, const QString& description,
const QString& keyseq);
void store();
class Internal;
signals:
void shortcutsChanged();
private:
Internal *m{nullptr};
SCBase();
};
#define SETSHORTCUT(DESCR, SEQ, FLD, SLTFUNC) \
do { \
QKeySequence ks = SCBase::scBase().get(scbctxt, DESCR, SEQ);\
if (!ks.isEmpty()) { \
delete FLD; \
FLD = new QShortcut(ks, this, SLOT(SLTFUNC())); \
} \
} while (false);
#define LISTSHORTCUT(DESCR, SEQ, FLD, SLTFUNC) \
do { \
SCBase::scBase().get(scbctxt, DESCR, SEQ); \
} while (false);
#endif /* _SCBASE_H_INCLUDED_ */

View File

@ -52,6 +52,7 @@
#include "rcldb.h"
#include "rclhelp.h"
#include "plaintorich.h"
#include "scbase.h"
using namespace std;
@ -63,6 +64,9 @@ using namespace std;
#define browser ((QTextBrowser*)browserw)
#endif
static const QString scbctxt("Snippets Window");
class PlainToRichQtSnippets : public PlainToRich {
public:
virtual string startMatch(unsigned int) {
@ -84,15 +88,9 @@ void SnippetsW::init()
// setWindowFlags(Qt::WindowStaysOnTopHint);
searchFM->hide();
new QShortcut(QKeySequence::Find, this, SLOT(slotEditFind()));
new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(slotEditFind()));
new QShortcut(QKeySequence(Qt::Key_Escape), searchFM, SLOT(hide()));
new QShortcut(QKeySequence::FindNext, this, SLOT(slotEditFindNext()));
new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext()));
new QShortcut(QKeySequence::FindPrevious, this,
SLOT(slotEditFindPrevious()));
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F3),
this, SLOT(slotEditFindPrevious()));
onNewShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()),
this, SLOT(onNewShortcuts()));
QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close);
if (closeButton)
@ -156,6 +154,24 @@ void SnippetsW::init()
#endif
}
void SnippetsW::onNewShortcuts()
{
SETSHORTCUT("Find", "Ctrl+F", m_find1sc, slotEditFind);
SETSHORTCUT("Find (alt)", "/", m_find2sc, slotEditFind);
SETSHORTCUT("Find Next", "F3", m_findnextsc, slotEditFindNext);
SETSHORTCUT("Find Previous", "Shift+F3", m_findprevsc, slotEditFindPrevious);
SETSHORTCUT("Hide", "Esc", m_hidesc, hide);
}
void SnippetsW::listShortcuts()
{
LISTSHORTCUT("Find", "Ctrl+F", m_find1sc, slotEditFind);
LISTSHORTCUT("Find (alt)", "/", m_find2sc, slotEditFind);
LISTSHORTCUT("Find Next", "F3", m_find2sc, slotEditFindNext);
LISTSHORTCUT("Find Previous", "Shift+F3", m_find2sc, slotEditFindPrevious);
LISTSHORTCUT("Hide", "Esc", m_hidesc, hide);
}
void SnippetsW::createPopupMenu(const QPoint& pos)
{
QMenu *popup = new QMenu(this);

View File

@ -41,11 +41,16 @@ public:
onSetDoc(doc, source);
}
/** List shortcuts so that the prefs can be edited before any preview
is created */
static void listShortcuts();
public slots:
virtual void onLinkClicked(const QUrl &);
virtual void onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source);
virtual void createPopupMenu(const QPoint& pos);
virtual void onNewShortcuts();
protected slots:
virtual void slotEditFind();
virtual void slotEditFindNext();
@ -62,6 +67,11 @@ private:
std::shared_ptr<DocSequence> m_source;
Rcl::Doc m_doc;
bool m_sortingByPage;
QShortcut *m_find1sc{nullptr};
QShortcut *m_find2sc{nullptr};
QShortcut *m_findnextsc{nullptr};
QShortcut *m_findprevsc{nullptr};
QShortcut *m_hidesc{nullptr};
};
#ifdef USING_WEBENGINE

View File

@ -46,7 +46,7 @@
<string>Clear</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
<string/>
</property>
</widget>
</item>

View File

@ -20,7 +20,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">

View File

@ -277,26 +277,29 @@ void UIPrefsDialog::setFromPrefs()
void UIPrefsDialog::readShortcuts()
{
shortcutsTB->setRowCount(0);
SCBase& scbase = SCBase::scBase();
shortcutsTB->setColumnCount(3);
shortcutsTB->setColumnCount(4);
shortcutsTB->setHorizontalHeaderItem(
0, new QTableWidgetItem(tr("Context")));
shortcutsTB->setHorizontalHeaderItem(
1, new QTableWidgetItem(tr("Description")));
shortcutsTB->setHorizontalHeaderItem(
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();) {
std::cerr << "Inserting row " << qs2utf8s(sl.at(i)) << " " <<
qs2utf8s(sl.at(i+1)) << " " <<
qs2utf8s(sl.at(i+2)) << "\n";
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);
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++)));
shortcutsTB->setCellWidget(row, 2, ed);
i++; // Skip dlft, not needed here.
shortcutsTB->setItem(row, 3, new QTableWidgetItem(sl.at(i++)));
row++;
}
shortcutsTB->resizeColumnsToContents();
@ -306,23 +309,15 @@ void UIPrefsDialog::readShortcuts()
void UIPrefsDialog::storeShortcuts()
{
SCBase& scbase = SCBase::scBase();
QStringList sl = scbase.getAll();
QStringList slout;
for (int row = 0; row < shortcutsTB->rowCount(); row++) {
QString dflt = shortcutsTB->item(row, 0)->text();
QString ctxt = shortcutsTB->item(row, 1)->text();
auto qsce = (QKeySequenceEdit*)(shortcutsTB->cellWidget(row, 2));
QString val = qsce->keySequence().toString();
QString dflt = sl[4 *row + 3];
if (dflt != val) {
std::cerr << "Storing changed " << qs2utf8s(dflt) << " -> " <<
qs2utf8s(val) << " at row " << row << "\n";
std::string e = stringsToString(
std::vector<std::string>{qs2utf8s(sl[4*row]),
qs2utf8s(sl[4*row+1]), qs2utf8s(val)});
slout.append(u8s2qs(e));
}
scbase.set(dflt, ctxt, val);
}
QSettings settings;
settings.setValue(SCBase::scBaseSettingsKey(), slout);
scbase.store();
}
void UIPrefsDialog::setupReslistFontPB()

View File

@ -264,20 +264,18 @@ template <class T> bool stringToStrings(const string& s, T& tokens,
template <class T> void stringsToString(const T& tokens, string& s)
{
for (auto it = tokens.begin();
it != tokens.end(); it++) {
bool hasblanks = false;
if (it->find_first_of(" \t\n") != string::npos) {
hasblanks = true;
}
if (it != tokens.begin()) {
s.append(1, ' ');
if (tokens.empty())
return;
for (const auto& tok : tokens) {
if (tok.empty()) {
s.append("\"\" ");
continue;
}
bool hasblanks = tok.find_first_of(" \t\n") != string::npos;
if (hasblanks) {
s.append(1, '"');
}
for (unsigned int i = 0; i < it->length(); i++) {
char car = it->at(i);
for (auto car : tok) {
if (car == '"') {
s.append(1, '\\');
s.append(1, car);
@ -288,7 +286,9 @@ template <class T> void stringsToString(const T& tokens, string& s)
if (hasblanks) {
s.append(1, '"');
}
s.append(1, ' ');
}
s.resize(s.size()-1);
}
template <class T> string stringsToString(const T& tokens)