forked from qt-creator/qt-creator
ClangTools: Reflect state of fixits
...in the fixit column to avoid confusion. As a side effect, add some error handling. Change-Id: Ia30e9c9782f3c8021aedd2be7c682853a26d3f39 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -321,7 +321,7 @@ void RefactoringFile::setOpenEditor(bool activate, int pos)
|
||||
m_editorCursorPosition = pos;
|
||||
}
|
||||
|
||||
void RefactoringFile::apply()
|
||||
bool RefactoringFile::apply()
|
||||
{
|
||||
// test file permissions
|
||||
if (!QFileInfo(fileName()).isWritable()) {
|
||||
@@ -331,7 +331,7 @@ void RefactoringFile::apply()
|
||||
"Refactoring cannot be applied.");
|
||||
roDialog.setShowFailWarning(true, failDetailText);
|
||||
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// open / activate / goto position
|
||||
@@ -345,6 +345,8 @@ void RefactoringFile::apply()
|
||||
m_editorCursorPosition = -1;
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
||||
// apply changes, if any
|
||||
if (m_data && !(m_indentRanges.isEmpty() && m_changes.isEmpty())) {
|
||||
QTextDocument *doc = mutableDocument();
|
||||
@@ -374,10 +376,12 @@ void RefactoringFile::apply()
|
||||
|
||||
// if this document doesn't have an editor, write the result to a file
|
||||
if (!m_editor && m_textFileFormat.codec) {
|
||||
QTC_ASSERT(!m_fileName.isEmpty(), return);
|
||||
QTC_ASSERT(!m_fileName.isEmpty(), return false);
|
||||
QString error;
|
||||
if (!m_textFileFormat.writeFile(m_fileName, doc->toPlainText(), &error))
|
||||
if (!m_textFileFormat.writeFile(m_fileName, doc->toPlainText(), &error)) {
|
||||
qWarning() << "Could not apply changes to" << m_fileName << ". Error: " << error;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
fileChanged();
|
||||
@@ -385,6 +389,7 @@ void RefactoringFile::apply()
|
||||
}
|
||||
|
||||
m_appliedOnce = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
void RefactoringFile::indentOrReindent(void (RefactoringChangesData::*mf)(const QTextCursor &,
|
||||
|
||||
Reference in New Issue
Block a user