Commit 36f5545f authored by Friedemann Kleint's avatar Friedemann Kleint

VCS[git]: Limit text size to be displayed.

in VCSBaseEditor  and BaseTextEditor::createNew to the size
used for limiting file size.
Reviewed-by: default avatarRobert Loehning <robert.loehning@nokia.com>
Task-number: QTCREATORBUG-1847
parent ab8a8c01
......@@ -1080,7 +1080,7 @@ IEditor *EditorManager::createEditor(const QString &editorId,
mimeType = m_d->m_core->mimeDatabase()->findByType(QLatin1String("text/plain"));
}
// open text files > 48 MB in binary editor
if (fileInfo.size() > qint64(3) << 24 && mimeType.type().startsWith(QLatin1String("text")))
if (fileInfo.size() > maxTextFileSize() && mimeType.type().startsWith(QLatin1String("text")))
mimeType = m_d->m_core->mimeDatabase()->findByType(QLatin1String("application/octet-stream"));
factories = editorFactories(mimeType, true);
} else {
......@@ -2013,5 +2013,10 @@ void EditorManager::gotoOtherSplit()
}
}
}
qint64 EditorManager::maxTextFileSize()
{
return (qint64(3) << 24);
}
//===================EditorClosingCoreListener======================
......@@ -199,6 +199,8 @@ public:
QWidget *parent,
bool displaySaveAsButton = false);
static qint64 maxTextFileSize();
signals:
void currentEditorChanged(Core::IEditor *editor);
void editorCreated(Core::IEditor *editor, const QString &fileName);
......
......@@ -573,8 +573,19 @@ void BaseTextEditor::triggerQuickFix()
emit requestQuickFix(editableInterface());
}
QString BaseTextEditor::msgTextTooLarge(quint64 size)
{
return tr("The text is too large to be displayed (%1 MB).").
arg(size >> 20);
}
bool BaseTextEditor::createNew(const QString &contents)
{
if (contents.size() > Core::EditorManager::maxTextFileSize()) {
setPlainText(msgTextTooLarge(contents.size()));
document()->setModified(false);
return false;
}
setPlainText(contents);
document()->setModified(false);
return true;
......
......@@ -294,6 +294,8 @@ protected:
bool canInsertFromMimeData(const QMimeData *source) const;
void insertFromMimeData(const QMimeData *source);
static QString msgTextTooLarge(quint64 size);
private:
void maybeSelectLine();
......
......@@ -627,7 +627,11 @@ void VCSBaseEditor::jumpToChangeFromDiff(QTextCursor cursor)
void VCSBaseEditor::setPlainTextData(const QByteArray &data)
{
setPlainText(codec()->toUnicode(data));
if (data.size() > Core::EditorManager::maxTextFileSize()) {
setPlainText(msgTextTooLarge(data.size()));
} else {
setPlainText(codec()->toUnicode(data));
}
}
void VCSBaseEditor::setFontSettings(const TextEditor::FontSettings &fs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment