From 78a6602ad45017ae78763d9430bc0efe14c9370f Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 25 Mar 2019 19:40:03 +0800 Subject: [PATCH] Return to select on macOS --- src/dialog/vnewfiledialog.cpp | 4 ++-- src/dialog/vselectdialog.cpp | 13 +++++++++++++ src/vdirectorytree.cpp | 2 +- src/vmdeditor.cpp | 14 +++++++------- src/vmdtab.cpp | 2 +- src/vwebview.cpp | 2 +- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/dialog/vnewfiledialog.cpp b/src/dialog/vnewfiledialog.cpp index a035ddd8..00c8f0c6 100644 --- a/src/dialog/vnewfiledialog.cpp +++ b/src/dialog/vnewfiledialog.cpp @@ -62,7 +62,7 @@ void VNewFileDialog::setupUI(const QString &p_title, templateBtn->setToolTip(tr("Manage Templates")); templateBtn->setProperty("FlatBtn", true); connect(templateBtn, &QPushButton::clicked, - this, [this]() { + this, []() { QUrl url = QUrl::fromLocalFile(g_config->getTemplateConfigFolder()); QDesktopServices::openUrl(url); }); @@ -86,7 +86,7 @@ void VNewFileDialog::setupUI(const QString &p_title, m_insertTitleCB->setToolTip(tr("Insert note name into the new note as a title")); m_insertTitleCB->setChecked(g_config->getInsertTitleFromNoteName()); connect(m_insertTitleCB, &QCheckBox::stateChanged, - this, [this](int p_state) { + this, [](int p_state) { g_config->setInsertTitleFromNoteName(p_state == Qt::Checked); }); diff --git a/src/dialog/vselectdialog.cpp b/src/dialog/vselectdialog.cpp index dffad5f4..b87690d2 100644 --- a/src/dialog/vselectdialog.cpp +++ b/src/dialog/vselectdialog.cpp @@ -92,6 +92,19 @@ void VSelectDialog::keyPressEvent(QKeyEvent *p_event) return; } + // On Mac OS X, it is `Command+O` to activate an item, instead of Return. +#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) + int key = p_event->key(); + if (key == Qt::Key_Return || key == Qt::Key_Enter) { + p_event->accept(); + if (auto item = m_list->currentItem()) { + selectionChosen(item); + } + + return; + } +#endif + QDialog::keyPressEvent(p_event); } diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp index 8abfad49..0b9ac186 100644 --- a/src/vdirectorytree.cpp +++ b/src/vdirectorytree.cpp @@ -346,7 +346,7 @@ void VDirectoryTree::contextMenuRequested(QPoint pos) VUtils::fixTextWithShortcut(newNoteAct, "NewNote"); newNoteAct->setToolTip(tr("Create a note in selected folder")); connect(newNoteAct, &QAction::triggered, - this, [this]() { + this, []() { g_mainWin->getFileList()->newFile(); }); diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index cb26bfc3..48482bad 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -411,7 +411,7 @@ void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event) toggleLivePreviewAct->setToolTip(tr("Toggle live preview panel for graphs")); VUtils::fixTextWithCaptainShortcut(toggleLivePreviewAct, "LivePreview"); connect(toggleLivePreviewAct, &QAction::triggered, - this, [this, mdtab]() { + this, [mdtab]() { mdtab->toggleLivePreview(); }); @@ -1477,14 +1477,14 @@ void VMdEditor::initLinkAndPreviewMenu(QAction *p_before, QMenu *p_menu, const Q QAction *viewImageAct = new QAction(tr("View Image"), p_menu); connect(viewImageAct, &QAction::triggered, - this, [this, imgPath]() { + this, [imgPath]() { QDesktopServices::openUrl(VUtils::pathToUrl(imgPath)); }); p_menu->insertAction(p_before, viewImageAct); QAction *copyImageLinkAct = new QAction(tr("Copy Image URL"), p_menu); connect(copyImageLinkAct, &QAction::triggered, - this, [this, imgPath]() { + this, [imgPath]() { QClipboard *clipboard = QApplication::clipboard(); VClipboardUtils::setLinkToClipboard(clipboard, imgPath, @@ -1495,7 +1495,7 @@ void VMdEditor::initLinkAndPreviewMenu(QAction *p_before, QMenu *p_menu, const Q if (isLocalFile) { QAction *copyImagePathAct = new QAction(tr("Copy Image Path"), p_menu); connect(copyImagePathAct, &QAction::triggered, - this, [this, imgPath]() { + this, [imgPath]() { QClipboard *clipboard = QApplication::clipboard(); QMimeData *data = new QMimeData(); data->setText(imgPath); @@ -1552,14 +1552,14 @@ void VMdEditor::initLinkAndPreviewMenu(QAction *p_before, QMenu *p_menu, const Q QAction *viewLinkAct = new QAction(tr("View Link"), p_menu); connect(viewLinkAct, &QAction::triggered, - this, [this, linkUrl]() { + this, [linkUrl]() { QDesktopServices::openUrl(VUtils::pathToUrl(linkUrl)); }); p_menu->insertAction(p_before, viewLinkAct); QAction *copyLinkAct = new QAction(tr("Copy Link URL"), p_menu); connect(copyLinkAct, &QAction::triggered, - this, [this, linkUrl]() { + this, [linkUrl]() { QClipboard *clipboard = QApplication::clipboard(); VClipboardUtils::setLinkToClipboard(clipboard, linkUrl, @@ -1570,7 +1570,7 @@ void VMdEditor::initLinkAndPreviewMenu(QAction *p_before, QMenu *p_menu, const Q if (isLocalFile) { QAction *copyLinkPathAct = new QAction(tr("Copy Link Path"), p_menu); connect(copyLinkPathAct, &QAction::triggered, - this, [this, linkUrl]() { + this, [linkUrl]() { QClipboard *clipboard = QApplication::clipboard(); QMimeData *data = new QMimeData(); data->setText(linkUrl); diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index e75bf7fb..0c6e3051 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -1085,7 +1085,7 @@ void VMdTab::applySnippet() QWidgetAction *act = new QWidgetAction(&menu); act->setDefaultWidget(sel); connect(sel, &VInsertSelector::accepted, - this, [this, &menu]() { + this, [&menu]() { QKeyEvent *escEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); QCoreApplication::postEvent(&menu, escEvent); diff --git a/src/vwebview.cpp b/src/vwebview.cpp index 367334a0..2524ba1e 100644 --- a/src/vwebview.cpp +++ b/src/vwebview.cpp @@ -472,7 +472,7 @@ void VWebView::initPreviewTunnelMenu(QAction *p_before, QMenu *p_menu) } connect(ag, &QActionGroup::triggered, - this, [this](QAction *p_act) { + this, [](QAction *p_act) { int data = p_act->data().toInt(); g_config->setSmartLivePreview(data); });