FileList: fix shortcut to open file via default program

This commit is contained in:
Le Tan 2018-11-28 19:52:01 +08:00
parent 70374607bb
commit 9e6fc4ff2e
2 changed files with 26 additions and 23 deletions

View File

@ -158,6 +158,14 @@ void VFileList::initShortcuts()
this, [this](){ this, [this](){
pasteFilesFromClipboard(); 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) void VFileList::setDirectory(VDirectory *p_directory)
@ -1279,32 +1287,10 @@ QMenu *VFileList::getOpenWithMenu()
name = QString("%1\t%2").arg(name) name = QString("%1\t%2").arg(name)
.arg(VUtils::getShortcutText(g_config->getShortcutKeySequence("OpenViaDefaultProgram"))); .arg(VUtils::getShortcutText(g_config->getShortcutKeySequence("OpenViaDefaultProgram")));
} }
QAction *defaultAct = new QAction(name, this); QAction *defaultAct = new QAction(name, this);
defaultAct->setToolTip(tr("Open current note with system's default program")); 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, connect(defaultAct, &QAction::triggered,
this, [this]() { this, &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);
}
}
});
m_openWithMenu->addAction(defaultAct); m_openWithMenu->addAction(defaultAct);
@ -1542,3 +1528,18 @@ void VFileList::setEnableSplitOut(bool p_enabled)
{ {
m_splitBtn->setChecked(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);
}
}
}

View File

@ -126,6 +126,8 @@ private slots:
// Hanlde Open With action's triggered signal. // Hanlde Open With action's triggered signal.
void handleOpenWithActionTriggered(); void handleOpenWithActionTriggered();
void openCurrentItemViaDefaultProgram();
protected: protected:
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;