diff --git a/src/editor/editwrapper.cpp b/src/editor/editwrapper.cpp index 1f5ed004..be2a43ad 100644 --- a/src/editor/editwrapper.cpp +++ b/src/editor/editwrapper.cpp @@ -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; // 优先使用历史记录的编码 diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 46b26158..e7ecc1ec 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -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);