mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
FileAssociations: add System for system default program
This commit is contained in:
parent
dba9fb30e8
commit
cadbab25bb
@ -20,6 +20,8 @@ bool FileType::isMarkdown() const
|
|||||||
return m_type == Type::Markdown;
|
return m_type == Type::Markdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FileTypeHelper::s_systemDefaultProgram = QStringLiteral("System");
|
||||||
|
|
||||||
FileTypeHelper::FileTypeHelper()
|
FileTypeHelper::FileTypeHelper()
|
||||||
{
|
{
|
||||||
reload();
|
reload();
|
||||||
|
@ -52,6 +52,8 @@ namespace vnotex
|
|||||||
|
|
||||||
static FileTypeHelper &getInst();
|
static FileTypeHelper &getInst();
|
||||||
|
|
||||||
|
static QString s_systemDefaultProgram;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileTypeHelper();
|
FileTypeHelper();
|
||||||
|
|
||||||
|
@ -234,6 +234,13 @@ bool BufferMgr::openWithExternalProgram(const QString &p_filePath, const QString
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_name == FileTypeHelper::s_systemDefaultProgram) {
|
||||||
|
// Open it by system default program.
|
||||||
|
qInfo() << "file will be opened by default program" << p_filePath;
|
||||||
|
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(p_filePath));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (auto pro = ConfigMgr::getInst().getSessionConfig().findExternalProgram(p_name)) {
|
if (auto pro = ConfigMgr::getInst().getSessionConfig().findExternalProgram(p_name)) {
|
||||||
const auto command = pro->fetchCommand(p_filePath);
|
const auto command = pro->fetchCommand(p_filePath);
|
||||||
if (!command.isEmpty()) {
|
if (!command.isEmpty()) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
#include <utils/utils.h>
|
#include <utils/utils.h>
|
||||||
|
#include <buffer/filetypehelper.h>
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
@ -274,18 +275,26 @@ void CoreConfig::loadFileTypeSuffixes(const QJsonObject &p_app, const QJsonObjec
|
|||||||
|
|
||||||
m_fileTypeSuffixes.reserve(arr.size());
|
m_fileTypeSuffixes.reserve(arr.size());
|
||||||
|
|
||||||
|
bool hasSystemDefined = false;
|
||||||
|
|
||||||
for (int i = 0; i < arr.size(); ++i) {
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
const auto obj = arr[i].toObject();
|
const auto obj = arr[i].toObject();
|
||||||
const auto name = obj[QStringLiteral("name")].toString();
|
const auto name = obj[QStringLiteral("name")].toString();
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto suffixes = readStringList(obj, QStringLiteral("suffixes"));
|
|
||||||
if (suffixes.isEmpty()) {
|
if (!hasSystemDefined && name == FileTypeHelper::s_systemDefaultProgram) {
|
||||||
continue;
|
hasSystemDefined = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto suffixes = readStringList(obj, QStringLiteral("suffixes"));
|
||||||
m_fileTypeSuffixes.push_back(FileTypeSuffix(name, Utils::toLower(suffixes)));
|
m_fileTypeSuffixes.push_back(FileTypeSuffix(name, Utils::toLower(suffixes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasSystemDefined) {
|
||||||
|
m_fileTypeSuffixes.push_back(FileTypeSuffix(FileTypeHelper::s_systemDefaultProgram, QStringList()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray CoreConfig::saveFileTypeSuffixes() const
|
QJsonArray CoreConfig::saveFileTypeSuffixes() const
|
||||||
|
@ -63,9 +63,6 @@ bool FileAssociationPage::saveInternal()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto suffixes = lineEdit->text().split(c_suffixSeparator, Qt::SkipEmptyParts);
|
auto suffixes = lineEdit->text().split(c_suffixSeparator, Qt::SkipEmptyParts);
|
||||||
if (suffixes.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fileTypeSuffixes.push_back(CoreConfig::FileTypeSuffix(name, Utils::toLower(suffixes)));
|
fileTypeSuffixes.push_back(CoreConfig::FileTypeSuffix(name, Utils::toLower(suffixes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,17 +111,25 @@ void FileAssociationPage::loadExternalProgramsGroup(QGroupBox *p_box)
|
|||||||
|
|
||||||
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
||||||
const auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
|
const auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
|
||||||
|
|
||||||
|
QStringList names;
|
||||||
for (const auto &pro : sessionConfig.getExternalPrograms()) {
|
for (const auto &pro : sessionConfig.getExternalPrograms()) {
|
||||||
|
names.push_back(pro.m_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
names << FileTypeHelper::s_systemDefaultProgram;
|
||||||
|
|
||||||
|
for (const auto &name : names) {
|
||||||
auto lineEdit = WidgetsFactory::createLineEdit(p_box);
|
auto lineEdit = WidgetsFactory::createLineEdit(p_box);
|
||||||
layout->addRow(pro.m_name, lineEdit);
|
layout->addRow(name, lineEdit);
|
||||||
connect(lineEdit, &QLineEdit::textChanged,
|
connect(lineEdit, &QLineEdit::textChanged,
|
||||||
this, &FileAssociationPage::pageIsChanged);
|
this, &FileAssociationPage::pageIsChanged);
|
||||||
|
|
||||||
lineEdit->setPlaceholderText(tr("Suffixes separated by ;"));
|
lineEdit->setPlaceholderText(tr("Suffixes separated by ;"));
|
||||||
lineEdit->setToolTip(tr("List of suffixes to open with external program"));
|
lineEdit->setToolTip(tr("List of suffixes to open with external program (or system default program)"));
|
||||||
lineEdit->setProperty(c_nameProperty, pro.m_name);
|
lineEdit->setProperty(c_nameProperty, name);
|
||||||
|
|
||||||
auto suffixes = coreConfig.findFileTypeSuffix(pro.m_name);
|
auto suffixes = coreConfig.findFileTypeSuffix(name);
|
||||||
if (suffixes) {
|
if (suffixes) {
|
||||||
lineEdit->setText(suffixes->join(c_suffixSeparator));
|
lineEdit->setText(suffixes->join(c_suffixSeparator));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user