Commit 79733e56 authored by Eike Ziller's avatar Eike Ziller Committed by Eike Ziller

Remove a few TextDocument subclasses

Which only differed in some property settings.

Change-Id: Ie844c32709ebe719a5b749fd2ef828b64086ba9a
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 74558e85
......@@ -44,22 +44,13 @@
namespace Android {
namespace Internal {
//
// JavaDocument
//
class JavaDocument : public TextEditor::TextDocument
static TextEditor::TextDocument *createJavaDocument()
{
public:
JavaDocument();
};
JavaDocument::JavaDocument()
{
setId(Constants::JAVA_EDITOR_ID);
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
setIndenter(new JavaIndenter);
auto doc = new TextEditor::TextDocument;
doc->setId(Constants::JAVA_EDITOR_ID);
doc->setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
doc->setIndenter(new JavaIndenter);
return doc;
}
//
......@@ -72,7 +63,7 @@ JavaEditorFactory::JavaEditorFactory()
setDisplayName(tr("Java Editor"));
addMimeType(Constants::JAVA_MIMETYPE);
setDocumentCreator([]() { return new JavaDocument; });
setDocumentCreator(createJavaDocument);
setUseGenericHighlighter(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
......
......@@ -196,20 +196,12 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
return link;
}
//
// CMakeDocument
//
class CMakeDocument : public TextDocument
{
public:
CMakeDocument();
};
CMakeDocument::CMakeDocument()
static TextDocument *createCMakeDocument()
{
setId(Constants::CMAKE_EDITOR_ID);
setMimeType(QLatin1String(Constants::CMAKEMIMETYPE));
auto doc = new TextDocument;
doc->setId(Constants::CMAKE_EDITOR_ID);
doc->setMimeType(QLatin1String(Constants::CMAKEMIMETYPE));
return doc;
}
//
......@@ -225,7 +217,7 @@ CMakeEditorFactory::CMakeEditorFactory()
setEditorCreator([]() { return new CMakeEditor; });
setEditorWidgetCreator([]() { return new CMakeEditorWidget; });
setDocumentCreator([]() { return new CMakeDocument; });
setDocumentCreator(createCMakeDocument);
setIndenterCreator([]() { return new CMakeIndenter; });
setUseGenericHighlighter(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
......
......@@ -47,11 +47,10 @@ namespace Internal {
class TextDocumentPrivate
{
public:
TextDocumentPrivate() : m_readResult(Utils::TextFileFormat::ReadSuccess) {}
Utils::TextFileFormat m_format;
Utils::TextFileFormat::ReadResult m_readResult;
Utils::TextFileFormat::ReadResult m_readResult = Utils::TextFileFormat::ReadSuccess;
QByteArray m_decodingErrorSample;
bool m_supportsUtf8Bom = true;
};
} // namespace Internal
......@@ -97,6 +96,11 @@ bool BaseTextDocument::write(const QString &fileName, const Utils::TextFileForma
return format.writeFile(fileName, data, errorMessage);
}
void BaseTextDocument::setSupportsUtf8Bom(bool value)
{
d->m_supportsUtf8Bom = value;
}
/*!
Autodetects format and reads in the text file specified by \a fileName.
*/
......@@ -140,6 +144,11 @@ void BaseTextDocument::switchUtf8Bom()
d->m_format.hasUtf8Bom = !d->m_format.hasUtf8Bom;
}
bool BaseTextDocument::supportsUtf8Bom() const
{
return d->m_supportsUtf8Bom;
}
/*!
Returns the format obtained from the last call to \c read().
*/
......
......@@ -47,7 +47,7 @@ public:
const QTextCodec *codec() const;
void setCodec(const QTextCodec *);
void switchUtf8Bom();
virtual bool supportsUtf8Bom() { return true; }
bool supportsUtf8Bom() const;
ReadResult read(const QString &fileName, QStringList *plainTextList, QString *errorString);
ReadResult read(const QString &fileName, QString *plainText, QString *errorString);
......@@ -58,6 +58,8 @@ public:
bool write(const QString &fileName, const QString &data, QString *errorMessage) const;
bool write(const QString &fileName, const Utils::TextFileFormat &format, const QString &data, QString *errorMessage) const;
void setSupportsUtf8Bom(bool value);
private:
Internal::TextDocumentPrivate *d;
};
......
......@@ -153,24 +153,15 @@ void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
showDefaultContextMenu(e, Constants::M_CONTEXT);
}
//
// ProFileDocument
//
class ProFileDocument : public TextDocument
{
public:
ProFileDocument();
// qmake project files doesn't support UTF8-BOM
// If the BOM would be added qmake would fail and QtCreator couldn't parse the project file
bool supportsUtf8Bom() override { return false; }
};
ProFileDocument::ProFileDocument()
static TextDocument *createProFileDocument()
{
setId(Constants::PROFILE_EDITOR_ID);
setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
auto doc = new TextDocument;
doc->setId(Constants::PROFILE_EDITOR_ID);
doc->setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
// qmake project files do not support UTF8-BOM
// If the BOM would be added qmake would fail and Qt Creator couldn't parse the project file
doc->setSupportsUtf8Bom(false);
return doc;
}
//
......@@ -188,7 +179,7 @@ ProFileEditorFactory::ProFileEditorFactory()
addMimeType(Constants::PROCACHEFILE_MIMETYPE);
addMimeType(Constants::PROSTASHFILE_MIMETYPE);
setDocumentCreator([]() { return new ProFileDocument; });
setDocumentCreator(createProFileDocument);
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
......
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