forked from qt-creator/qt-creator
		
	TextEditor: Merge BaseTextEditorDocument into BaseTextDocument
That was the only user of that layer of abstraction. Change-Id: I2bdc4abb8b2b33bfb70398dd11f7ecc4745ddc43 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
		| @@ -109,7 +109,7 @@ void CMakeEditor::build() | ||||
| QString CMakeEditor::contextHelpId() const | ||||
| { | ||||
|     int pos = position(); | ||||
|     TextEditor::BaseTextEditorDocument* doc = const_cast<CMakeEditor*>(this)->textDocument(); | ||||
|     TextEditor::BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument(); | ||||
|  | ||||
|     QChar chr; | ||||
|     do { | ||||
|   | ||||
| @@ -214,7 +214,7 @@ void CodepasterPlugin::postEditor() | ||||
|     if (const BaseTextEditor *textEditor = qobject_cast<const BaseTextEditor *>(editor)) | ||||
|         data = textEditor->selectedText(); | ||||
|     if (data.isEmpty()) { | ||||
|         if (const BaseTextEditorDocument *textDocument = qobject_cast<const BaseTextEditorDocument *>(document)) | ||||
|         if (auto textDocument = qobject_cast<const BaseTextDocument *>(document)) | ||||
|             data = textDocument->plainText(); | ||||
|     } | ||||
|     post(data, mimeType); | ||||
|   | ||||
| @@ -1054,8 +1054,8 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL | ||||
|     Core::IDocument *targetDocument | ||||
|             = Core::DocumentModel::documentForFilePath( d->m_declDefLink->targetFile->fileName()); | ||||
|     if (baseTextDocument() != targetDocument) { | ||||
|         if (TextEditor::BaseTextEditorDocument *textEditorDocument = qobject_cast<TextEditor::BaseTextEditorDocument *>(targetDocument)) | ||||
|             connect(textEditorDocument, SIGNAL(contentsChanged()), | ||||
|         if (auto textDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument)) | ||||
|             connect(textDocument, SIGNAL(contentsChanged()), | ||||
|                     this, SLOT(abortDeclDefLink())); | ||||
|     } | ||||
|  | ||||
| @@ -1103,8 +1103,8 @@ void CPPEditorWidget::abortDeclDefLink() | ||||
|     Core::IDocument *targetDocument | ||||
|             = Core::DocumentModel::documentForFilePath(d->m_declDefLink->targetFile->fileName()); | ||||
|     if (baseTextDocument() != targetDocument) { | ||||
|         if (TextEditor::BaseTextEditorDocument *textEditorDocument = qobject_cast<TextEditor::BaseTextEditorDocument *>(targetDocument)) | ||||
|             disconnect(textEditorDocument, SIGNAL(contentsChanged()), | ||||
|         if (auto textDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument)) | ||||
|             disconnect(textDocument, SIGNAL(contentsChanged()), | ||||
|                     this, SLOT(abortDeclDefLink())); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1891,7 +1891,7 @@ void DebuggerPluginPrivate::requestContextMenu(BaseTextEditor *editor, | ||||
|     bool contextUsable = true; | ||||
|  | ||||
|     BreakpointModelId id = BreakpointModelId(); | ||||
|     BaseTextEditorDocument *document = editor->textDocument(); | ||||
|     BaseTextDocument *document = editor->textDocument(); | ||||
|     args.fileName = document->filePath(); | ||||
|     if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) { | ||||
|         QString line = document->plainText() | ||||
|   | ||||
| @@ -83,8 +83,7 @@ Utils::FileIterator *AllProjectsFind::filesForProjects(const QStringList &nameFi | ||||
|     foreach (const QString &filter, nameFilters) { | ||||
|         filterRegs << QRegExp(filter, Qt::CaseInsensitive, QRegExp::Wildcard); | ||||
|     } | ||||
|     QMap<QString, QTextCodec *> openEditorEncodings | ||||
|             = TextEditor::BaseTextEditorDocument::openedTextDocumentEncodings(); | ||||
|     QMap<QString, QTextCodec *> openEditorEncodings = BaseTextDocument::openedTextDocumentEncodings(); | ||||
|     QMap<QString, QTextCodec *> encodings; | ||||
|     foreach (const Project *project, projects) { | ||||
|         QStringList projectFiles = project->files(Project::AllFiles); | ||||
|   | ||||
| @@ -174,12 +174,12 @@ void BaseFileFind::runSearch(Core::SearchResult *search) | ||||
|         watcher->setFuture(Utils::findInFilesRegExp(parameters.text, | ||||
|             files(parameters.nameFilters, parameters.additionalParameters), | ||||
|             textDocumentFlagsForFindFlags(parameters.flags), | ||||
|             BaseTextEditorDocument::openedTextDocumentContents())); | ||||
|             BaseTextDocument::openedTextDocumentContents())); | ||||
|     } else { | ||||
|         watcher->setFuture(Utils::findInFiles(parameters.text, | ||||
|             files(parameters.nameFilters, parameters.additionalParameters), | ||||
|             textDocumentFlagsForFindFlags(parameters.flags), | ||||
|             BaseTextEditorDocument::openedTextDocumentContents())); | ||||
|             BaseTextDocument::openedTextDocumentContents())); | ||||
|     } | ||||
|     FutureProgress *progress = | ||||
|         ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH); | ||||
|   | ||||
| @@ -197,38 +197,15 @@ void BaseTextDocumentPrivate::onModificationChanged(bool modified) | ||||
|         updateRevisions(); | ||||
| } | ||||
|  | ||||
| BaseTextEditorDocument::BaseTextEditorDocument(QObject *parent) | ||||
|     : Core::TextDocument(parent) | ||||
| { | ||||
| } | ||||
|  | ||||
| QMap<QString, QString> BaseTextEditorDocument::openedTextDocumentContents() | ||||
| { | ||||
|     QMap<QString, QString> workingCopy; | ||||
|     foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) { | ||||
|         BaseTextEditorDocument *textEditorDocument = qobject_cast<BaseTextEditorDocument *>(document); | ||||
|         if (!textEditorDocument) | ||||
|             continue; | ||||
|         QString fileName = textEditorDocument->filePath(); | ||||
|         workingCopy[fileName] = textEditorDocument->plainText(); | ||||
|     } | ||||
|     return workingCopy; | ||||
| } | ||||
| /////////////////////////////////////////////////////////////////////// | ||||
| // | ||||
| // BaseTextDocument | ||||
| // | ||||
| /////////////////////////////////////////////////////////////////////// | ||||
|  | ||||
| QMap<QString, QTextCodec *> BaseTextEditorDocument::openedTextDocumentEncodings() | ||||
| { | ||||
|     QMap<QString, QTextCodec *> workingCopy; | ||||
|     foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) { | ||||
|         BaseTextEditorDocument *textEditorDocument = qobject_cast<BaseTextEditorDocument *>(document); | ||||
|         if (!textEditorDocument) | ||||
|             continue; | ||||
|         QString fileName = textEditorDocument->filePath(); | ||||
|         workingCopy[fileName] = const_cast<QTextCodec *>(textEditorDocument->codec()); | ||||
|     } | ||||
|     return workingCopy; | ||||
| } | ||||
|  | ||||
| BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this)) | ||||
| BaseTextDocument::BaseTextDocument() | ||||
|     : d(new BaseTextDocumentPrivate(this)) | ||||
| { | ||||
|     connect(d->m_document, SIGNAL(modificationChanged(bool)), d, SLOT(onModificationChanged(bool))); | ||||
|     connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed())); | ||||
| @@ -252,6 +229,32 @@ BaseTextDocument::~BaseTextDocument() | ||||
|     delete d; | ||||
| } | ||||
|  | ||||
| QMap<QString, QString> BaseTextDocument::openedTextDocumentContents() | ||||
| { | ||||
|     QMap<QString, QString> workingCopy; | ||||
|     foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) { | ||||
|         BaseTextDocument *textEditorDocument = qobject_cast<BaseTextDocument *>(document); | ||||
|         if (!textEditorDocument) | ||||
|             continue; | ||||
|         QString fileName = textEditorDocument->filePath(); | ||||
|         workingCopy[fileName] = textEditorDocument->plainText(); | ||||
|     } | ||||
|     return workingCopy; | ||||
| } | ||||
|  | ||||
| QMap<QString, QTextCodec *> BaseTextDocument::openedTextDocumentEncodings() | ||||
| { | ||||
|     QMap<QString, QTextCodec *> workingCopy; | ||||
|     foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) { | ||||
|         BaseTextDocument *textEditorDocument = qobject_cast<BaseTextDocument *>(document); | ||||
|         if (!textEditorDocument) | ||||
|             continue; | ||||
|         QString fileName = textEditorDocument->filePath(); | ||||
|         workingCopy[fileName] = const_cast<QTextCodec *>(textEditorDocument->codec()); | ||||
|     } | ||||
|     return workingCopy; | ||||
| } | ||||
|  | ||||
| QString BaseTextDocument::plainText() const | ||||
| { | ||||
|     return document()->toPlainText(); | ||||
|   | ||||
| @@ -58,24 +58,7 @@ class TypingSettings; | ||||
|  | ||||
| typedef QList<TextMark *> TextMarks; | ||||
|  | ||||
| class TEXTEDITOR_EXPORT BaseTextEditorDocument : public Core::TextDocument | ||||
| { | ||||
|     Q_OBJECT | ||||
| public: | ||||
|     explicit BaseTextEditorDocument(QObject *parent = 0); | ||||
|  | ||||
|     virtual QString plainText() const = 0; | ||||
|     virtual QString textAt(int pos, int length) const = 0; | ||||
|     virtual QChar characterAt(int pos) const = 0; | ||||
|  | ||||
|     static QMap<QString, QString> openedTextDocumentContents(); | ||||
|     static QMap<QString, QTextCodec *> openedTextDocumentEncodings(); | ||||
|  | ||||
| signals: | ||||
|     void contentsChanged(); | ||||
| }; | ||||
|  | ||||
| class TEXTEDITOR_EXPORT BaseTextDocument : public BaseTextEditorDocument | ||||
| class TEXTEDITOR_EXPORT BaseTextDocument : public Core::TextDocument | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
| @@ -83,10 +66,12 @@ public: | ||||
|     BaseTextDocument(); | ||||
|     virtual ~BaseTextDocument(); | ||||
|  | ||||
|     // BaseTextEditorDocument | ||||
|     QString plainText() const; | ||||
|     QString textAt(int pos, int length) const; | ||||
|     QChar characterAt(int pos) const; | ||||
|     static QMap<QString, QString> openedTextDocumentContents(); | ||||
|     static QMap<QString, QTextCodec *> openedTextDocumentEncodings(); | ||||
|  | ||||
|     virtual QString plainText() const; | ||||
|     virtual QString textAt(int pos, int length) const; | ||||
|     virtual QChar characterAt(int pos) const; | ||||
|  | ||||
|     void setTypingSettings(const TypingSettings &typingSettings); | ||||
|     void setStorageSettings(const StorageSettings &storageSettings); | ||||
| @@ -148,6 +133,7 @@ public slots: | ||||
|     void setFontSettings(const TextEditor::FontSettings &fontSettings); | ||||
|  | ||||
| signals: | ||||
|     void contentsChanged(); | ||||
|     void tabSettingsChanged(); | ||||
|     void fontSettingsChanged(); | ||||
|  | ||||
|   | ||||
| @@ -6850,12 +6850,11 @@ bool BaseTextEditor::restoreState(const QByteArray &state) | ||||
|     return m_editorWidget->restoreState(state); | ||||
| } | ||||
|  | ||||
| BaseTextEditorDocument *BaseTextEditor::textDocument() | ||||
| BaseTextDocument *BaseTextEditor::textDocument() | ||||
| { | ||||
|     return qobject_cast<BaseTextEditorDocument *>(document()); | ||||
|     return qobject_cast<BaseTextDocument *>(document()); | ||||
| } | ||||
|  | ||||
|  | ||||
| BaseTextEditor *BaseTextEditor::currentTextEditor() | ||||
| { | ||||
|     return qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()); | ||||
|   | ||||
| @@ -121,7 +121,7 @@ public: | ||||
|     BaseTextEditor(BaseTextEditorWidget *editorWidget); | ||||
|     ~BaseTextEditor(); | ||||
|  | ||||
|     virtual BaseTextEditorDocument *textDocument(); | ||||
|     virtual BaseTextDocument *textDocument(); | ||||
|  | ||||
|     enum MarkRequestKind { | ||||
|         BreakpointRequest, | ||||
|   | ||||
| @@ -63,8 +63,7 @@ Utils::FileIterator *FindInCurrentFile::files(const QStringList &nameFilters, | ||||
| { | ||||
|     Q_UNUSED(nameFilters) | ||||
|     QString fileName = additionalParameters.toString(); | ||||
|     QMap<QString, QTextCodec *> openEditorEncodings | ||||
|             = BaseTextEditorDocument::openedTextDocumentEncodings(); | ||||
|     QMap<QString, QTextCodec *> openEditorEncodings = BaseTextDocument::openedTextDocumentEncodings(); | ||||
|     QTextCodec *codec = openEditorEncodings.value(fileName); | ||||
|     if (!codec) | ||||
|         codec = Core::EditorManager::defaultTextCodec(); | ||||
|   | ||||
| @@ -65,7 +65,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters, | ||||
|     Q_UNUSED(nameFilters) | ||||
|     Q_UNUSED(additionalParameters) | ||||
|     QMap<QString, QTextCodec *> openEditorEncodings | ||||
|             = BaseTextEditorDocument::openedTextDocumentEncodings(); | ||||
|             = BaseTextDocument::openedTextDocumentEncodings(); | ||||
|     QStringList fileNames; | ||||
|     QList<QTextCodec *> codecs; | ||||
|     foreach (Core::DocumentModel::Entry *entry, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user