Commit 66e89447 authored by Leandro Melo's avatar Leandro Melo
Browse files

Text editor: Progress bar for large files

Reviewed-by: mae
parent a9f6dbd8
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "storagesettings.h" #include "storagesettings.h"
#include "tabsettings.h" #include "tabsettings.h"
#include "syntaxhighlighter.h" #include "syntaxhighlighter.h"
#include "texteditorconstants.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QFile> #include <QtCore/QFile>
...@@ -45,12 +46,14 @@ ...@@ -45,12 +46,14 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QTextCodec> #include <QtCore/QTextCodec>
#include <QtCore/QFutureInterface>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
#include <QtGui/QSyntaxHighlighter> #include <QtGui/QSyntaxHighlighter>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/reloadpromptutils.h> #include <utils/reloadpromptutils.h>
...@@ -521,14 +524,22 @@ bool BaseTextDocument::open(const QString &fileName) ...@@ -521,14 +524,22 @@ bool BaseTextDocument::open(const QString &fileName)
if (d->m_isBinaryData) { if (d->m_isBinaryData) {
d->m_document->setHtml(tr("<em>Binary data</em>")); d->m_document->setHtml(tr("<em>Binary data</em>"));
} else { } else {
if (content.size() == 1) { const int chunks = content.size();
if (chunks == 1) {
d->m_document->setPlainText(content.at(0)); d->m_document->setPlainText(content.at(0));
} else { } else {
QFutureInterface<void> interface;
interface.setProgressRange(0, chunks);
Core::ICore::instance()->progressManager()->addTask(
interface.future(), tr("Opening file"), Constants::TASK_OPEN_FILE);
interface.reportStarted();
QTextCursor c(d->m_document); QTextCursor c(d->m_document);
foreach (const QString &text, content) { for (int i = 0; i < chunks; ++i) {
c.insertText(text); c.insertText(content.at(i));
interface.setProgressValue(i + 1);
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
} }
interface.reportFinished();
} }
} }
BaseTextDocumentLayout *documentLayout = BaseTextDocumentLayout *documentLayout =
......
...@@ -98,6 +98,7 @@ const char * const C_TEXTEDITOR_MIMETYPE_TEXT = "text/plain"; ...@@ -98,6 +98,7 @@ const char * const C_TEXTEDITOR_MIMETYPE_TEXT = "text/plain";
const char * const INFO_SYNTAX_DEFINITION = "TextEditor.InfoSyntaxDefinition"; const char * const INFO_SYNTAX_DEFINITION = "TextEditor.InfoSyntaxDefinition";
const char * const TASK_DOWNLOAD_DEFINITIONS = "TextEditor.Task.Download"; const char * const TASK_DOWNLOAD_DEFINITIONS = "TextEditor.Task.Download";
const char * const TASK_REGISTER_DEFINITIONS = "TextEditor.Task.Register"; const char * const TASK_REGISTER_DEFINITIONS = "TextEditor.Task.Register";
const char * const TASK_OPEN_FILE = "TextEditor.Task.OpenFile";
// Text color and style categories // Text color and style categories
const char * const C_TEXT = "Text"; const char * const C_TEXT = "Text";
......
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