From 9e6fc4ff2e657350f229b222f1e0227f5ff44f74 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 28 Nov 2018 19:52:01 +0800 Subject: [PATCH] FileList: fix shortcut to open file via default program --- src/vfilelist.cpp | 47 ++++++++++++++++++++++++----------------------- src/vfilelist.h | 2 ++ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index bd9742a5..c0f46071 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -158,6 +158,14 @@ void VFileList::initShortcuts() this, [this](){ pasteFilesFromClipboard(); }); + + QKeySequence seq(g_config->getShortcutKeySequence("OpenViaDefaultProgram")); + if (!seq.isEmpty()) { + QShortcut *defaultProgramShortcut = new QShortcut(seq, this); + defaultProgramShortcut->setContext(Qt::WidgetWithChildrenShortcut); + connect(defaultProgramShortcut, &QShortcut::activated, + this, &VFileList::openCurrentItemViaDefaultProgram); + } } void VFileList::setDirectory(VDirectory *p_directory) @@ -1279,32 +1287,10 @@ QMenu *VFileList::getOpenWithMenu() name = QString("%1\t%2").arg(name) .arg(VUtils::getShortcutText(g_config->getShortcutKeySequence("OpenViaDefaultProgram"))); } - QAction *defaultAct = new QAction(name, this); defaultAct->setToolTip(tr("Open current note with system's default program")); - if (!seq.isEmpty()) { - QShortcut *shortcut = new QShortcut(seq, this); - shortcut->setContext(Qt::WidgetWithChildrenShortcut); - connect(shortcut, &QShortcut::activated, - this, [defaultAct](){ - defaultAct->trigger(); - }); - } - connect(defaultAct, &QAction::triggered, - this, [this]() { - QListWidgetItem *item = fileList->currentItem(); - if (item) { - VNoteFile *file = getVFile(item); - if (file - && (!g_config->getCloseBeforeExternalEditor() - || !editArea->isFileOpened(file) - || editArea->closeFile(file, false))) { - QUrl url = QUrl::fromLocalFile(file->fetchPath()); - QDesktopServices::openUrl(url); - } - } - }); + this, &VFileList::openCurrentItemViaDefaultProgram); m_openWithMenu->addAction(defaultAct); @@ -1542,3 +1528,18 @@ void VFileList::setEnableSplitOut(bool p_enabled) { m_splitBtn->setChecked(p_enabled); } + +void VFileList::openCurrentItemViaDefaultProgram() +{ + QListWidgetItem *item = fileList->currentItem(); + if (item) { + VNoteFile *file = getVFile(item); + if (file + && (!g_config->getCloseBeforeExternalEditor() + || !editArea->isFileOpened(file) + || editArea->closeFile(file, false))) { + QUrl url = QUrl::fromLocalFile(file->fetchPath()); + QDesktopServices::openUrl(url); + } + } +} diff --git a/src/vfilelist.h b/src/vfilelist.h index bc131df4..6505d7a5 100644 --- a/src/vfilelist.h +++ b/src/vfilelist.h @@ -126,6 +126,8 @@ private slots: // Hanlde Open With action's triggered signal. void handleOpenWithActionTriggered(); + void openCurrentItemViaDefaultProgram(); + protected: void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;