Browse Source

FileList: fix shortcut to open file via default program

Le Tan 7 years ago
parent
commit
9e6fc4ff2e
2 changed files with 26 additions and 23 deletions
  1. 24 23
      src/vfilelist.cpp
  2. 2 0
      src/vfilelist.h

+ 24 - 23
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);
+        }
+    }
+}

+ 2 - 0
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;