Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/editor/editwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ void EditWrapper::openFile(const QString &filepath, QString qstrTruePath, bool b
Settings::instance()->setSavePath(PathSettingWgt::CurFileBox, absPath);
}

// Check if there is sufficient memory to open the file.
QFileInfo memFileInfo(filepath);
if (memFileInfo.exists() && !Utils::isMemorySufficientForOperation(Utils::OperationType::RawOperation, memFileInfo.size(), 0)) {
qCWarning(appLog) << "Insufficient memory to open file:" << filepath << "size:" << memFileInfo.size();
QWidget *target = m_pTextEdit;
if (target) {
#ifdef DTKWIDGET_CLASS_DSizeMode
Utils::sendFloatMessageFixedFont(target, QIcon(":/images/warning.svg"), tr("Insufficient memory to open this file"));
#else
DMessageManager::instance()->sendMessage(target, QIcon(":/images/warning.svg"), tr("Insufficient memory to open this file"));
#endif
}
return;
}

FileLoadThread *thread = new FileLoadThread(filepath);
qCDebug(appLog) << "Created file load thread for:" << filepath;
// 优先使用历史记录的编码
Expand Down
9 changes: 9 additions & 0 deletions src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,15 @@ void Window::addTab(const QString &filepath, bool activeTab)
}
}

// Check if there is sufficient memory to open the file.
if (!Utils::isMemorySufficientForOperation(Utils::OperationType::RawOperation, fileInfo.size(), 0)) {
qCWarning(appLog) << "Insufficient memory to open file:" << filepath << "size:" << fileInfo.size();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
DMessageManager::instance()->sendMessage(msgParent, QIcon(":/images/warning.svg"),
tr("Insufficient memory to open this file"));
return;
}

if (StartManager::instance()->checkPath(filepath)) {
qCDebug(appLog) << "Path check passed, adding tab for file";
m_tabbar->addTab(filepath, tabName, filepath);
Expand Down
Loading