aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/refactoringchanges.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2012-01-18 16:31:16 +0100
committerErik Verbruggen <erik.verbruggen@nokia.com>2012-01-19 13:59:46 +0100
commitea27d72d19296831ed068d05dac541dda7c47def (patch)
tree3827720e9684314e61b18253605eb69c43b15a6b /src/plugins/texteditor/refactoringchanges.cpp
parent6efd36a7901016c874a1db44e86ed9d01277cecf (diff)
Fix crash when doing "Move into file" refacoring action.
Change-Id: I0b42953b7bce6b594387777691aca4c2683a5828 Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Diffstat (limited to 'src/plugins/texteditor/refactoringchanges.cpp')
-rw-r--r--src/plugins/texteditor/refactoringchanges.cpp62
1 files changed, 28 insertions, 34 deletions
diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp
index 42baa54829e..23d00697996 100644
--- a/src/plugins/texteditor/refactoringchanges.cpp
+++ b/src/plugins/texteditor/refactoringchanges.cpp
@@ -96,43 +96,33 @@ bool RefactoringChanges::createFile(const QString &fileName, const QString &cont
if (QFile::exists(fileName))
return false;
- BaseTextEditorWidget *editor = editorForFile(fileName);
- if (!editor && openEditor) {
- editor = this->openEditor(fileName, false, -1, -1);
- }
-
- QTextDocument *document;
- if (editor)
- document = editor->document();
- else
- document = new QTextDocument;
-
- {
- QTextCursor cursor(document);
- cursor.beginEditBlock();
-
- cursor.insertText(contents);
-
- if (reindent) {
- cursor.select(QTextCursor::Document);
- m_data->indentSelection(cursor, fileName, editor);
- }
-
- cursor.endEditBlock();
- }
-
- if (!editor) {
- Utils::TextFileFormat format;
- format.codec = Core::EditorManager::instance()->defaultTextCodec();
- QString error;
- bool saveOk = format.writeFile(fileName, document->toPlainText(), &error);
- delete document;
- if (!saveOk)
- return false;
+ // Create a text document for the new file:
+ QTextDocument *document = new QTextDocument;
+ QTextCursor cursor(document);
+ cursor.beginEditBlock();
+ cursor.insertText(contents);
+
+ // Reindent the contents:
+ if (reindent) {
+ cursor.select(QTextCursor::Document);
+ m_data->indentSelection(cursor, fileName, 0);
}
+ cursor.endEditBlock();
+
+ // Write the file to disk:
+ Utils::TextFileFormat format;
+ format.codec = Core::EditorManager::instance()->defaultTextCodec();
+ QString error;
+ bool saveOk = format.writeFile(fileName, document->toPlainText(), &error);
+ delete document;
+ if (!saveOk)
+ return false;
m_data->fileChanged(fileName);
+ if (openEditor)
+ this->openEditor(fileName, /*bool activate =*/ false, -1, -1);
+
return true;
}
@@ -157,7 +147,11 @@ BaseTextEditorWidget *RefactoringChanges::openEditor(const QString &fileName, bo
}
Core::IEditor *editor = BaseTextEditorWidget::openEditorAt(
fileName, line, column, Core::Id(), flags);
- return qobject_cast<BaseTextEditorWidget *>(editor->widget());
+
+ if (editor)
+ return qobject_cast<BaseTextEditorWidget *>(editor->widget());
+ else
+ return 0;
}
RefactoringFilePtr RefactoringChanges::file(BaseTextEditorWidget *editor)