mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +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;
|
||||
}
|
||||
|
||||
QString FileTypeHelper::s_systemDefaultProgram = QStringLiteral("System");
|
||||
|
||||
FileTypeHelper::FileTypeHelper()
|
||||
{
|
||||
reload();
|
||||
|
@ -52,6 +52,8 @@ namespace vnotex
|
||||
|
||||
static FileTypeHelper &getInst();
|
||||
|
||||
static QString s_systemDefaultProgram;
|
||||
|
||||
private:
|
||||
FileTypeHelper();
|
||||
|
||||
|
@ -234,6 +234,13 @@ bool BufferMgr::openWithExternalProgram(const QString &p_filePath, const QString
|
||||
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)) {
|
||||
const auto command = pro->fetchCommand(p_filePath);
|
||||
if (!command.isEmpty()) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QLocale>
|
||||
|
||||
#include <utils/utils.h>
|
||||
#include <buffer/filetypehelper.h>
|
||||
|
||||
using namespace vnotex;
|
||||
|
||||
@ -274,18 +275,26 @@ void CoreConfig::loadFileTypeSuffixes(const QJsonObject &p_app, const QJsonObjec
|
||||
|
||||
m_fileTypeSuffixes.reserve(arr.size());
|
||||
|
||||
bool hasSystemDefined = false;
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
const auto obj = arr[i].toObject();
|
||||
const auto name = obj[QStringLiteral("name")].toString();
|
||||
if (name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
const auto suffixes = readStringList(obj, QStringLiteral("suffixes"));
|
||||
if (suffixes.isEmpty()) {
|
||||
continue;
|
||||
|
||||
if (!hasSystemDefined && name == FileTypeHelper::s_systemDefaultProgram) {
|
||||
hasSystemDefined = true;
|
||||
}
|
||||
|
||||
const auto suffixes = readStringList(obj, QStringLiteral("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
|
||||
|
@ -63,9 +63,6 @@ bool FileAssociationPage::saveInternal()
|
||||
continue;
|
||||
}
|
||||
auto suffixes = lineEdit->text().split(c_suffixSeparator, Qt::SkipEmptyParts);
|
||||
if (suffixes.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
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 &sessionConfig = ConfigMgr::getInst().getSessionConfig();
|
||||
|
||||
QStringList names;
|
||||
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);
|
||||
layout->addRow(pro.m_name, lineEdit);
|
||||
layout->addRow(name, lineEdit);
|
||||
connect(lineEdit, &QLineEdit::textChanged,
|
||||
this, &FileAssociationPage::pageIsChanged);
|
||||
|
||||
lineEdit->setPlaceholderText(tr("Suffixes separated by ;"));
|
||||
lineEdit->setToolTip(tr("List of suffixes to open with external program"));
|
||||
lineEdit->setProperty(c_nameProperty, pro.m_name);
|
||||
lineEdit->setToolTip(tr("List of suffixes to open with external program (or system default program)"));
|
||||
lineEdit->setProperty(c_nameProperty, name);
|
||||
|
||||
auto suffixes = coreConfig.findFileTypeSuffix(pro.m_name);
|
||||
auto suffixes = coreConfig.findFileTypeSuffix(name);
|
||||
if (suffixes) {
|
||||
lineEdit->setText(suffixes->join(c_suffixSeparator));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user