forked from qt-creator/qt-creator
file manager: introduce saveFile() and remove blockFileChange() & unblockFileChange()
this replaces the ever-repeating idiom block/save/unblock with a single call.
This commit is contained in:
@@ -630,9 +630,7 @@ bool BazaarPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submit
|
||||
QStringList files = commitEditor->checkedFiles();
|
||||
if (!files.empty()) {
|
||||
//save the commit message
|
||||
m_core->fileManager()->blockFileChange(editorFile);
|
||||
editorFile->save();
|
||||
m_core->fileManager()->unblockFileChange(editorFile);
|
||||
m_core->fileManager()->saveFile(editorFile);
|
||||
|
||||
//rewrite entries of the form 'file => newfile' to 'newfile' because
|
||||
//this would mess the commit command
|
||||
|
||||
@@ -1375,9 +1375,7 @@ bool EditorManager::saveFile(IFile *fileParam)
|
||||
bool success = false;
|
||||
|
||||
// try saving, no matter what isReadOnly tells us
|
||||
m_d->m_core->fileManager()->blockFileChange(file);
|
||||
success = file->save(fileName);
|
||||
m_d->m_core->fileManager()->unblockFileChange(file);
|
||||
success = m_d->m_core->fileManager()->saveFile(file);
|
||||
|
||||
if (!success) {
|
||||
MakeWritableResult answer =
|
||||
@@ -1389,9 +1387,7 @@ bool EditorManager::saveFile(IFile *fileParam)
|
||||
|
||||
file->checkPermissions();
|
||||
|
||||
m_d->m_core->fileManager()->blockFileChange(file);
|
||||
success = file->save(fileName);
|
||||
m_d->m_core->fileManager()->unblockFileChange(file);
|
||||
success = m_d->m_core->fileManager()->saveFile(file);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
@@ -1460,9 +1456,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
|
||||
}
|
||||
}
|
||||
|
||||
m_d->m_core->fileManager()->blockFileChange(file);
|
||||
const bool success = file->save(absoluteFilePath);
|
||||
m_d->m_core->fileManager()->unblockFileChange(file);
|
||||
const bool success = m_d->m_core->fileManager()->saveFile(file, absoluteFilePath);
|
||||
file->checkPermissions();
|
||||
|
||||
// @todo: There is an issue to be treated here. The new file might be of a different mime
|
||||
|
||||
@@ -496,39 +496,6 @@ QList<IFile *> FileManager::modifiedFiles() const
|
||||
return modifiedFiles;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void FileManager::blockFileChange(IFile *file)
|
||||
|
||||
Blocks the monitoring of the file the \a file argument points to.
|
||||
*/
|
||||
void FileManager::blockFileChange(IFile *file)
|
||||
{
|
||||
// Nothing to do
|
||||
Q_UNUSED(file);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void FileManager::unblockFileChange(IFile *file)
|
||||
|
||||
Enables the monitoring of the file the \a file argument points to, and update the status of the corresponding IFile's.
|
||||
*/
|
||||
void FileManager::unblockFileChange(IFile *file)
|
||||
{
|
||||
// We are updating the lastUpdated time to the current modification time
|
||||
// in changedFile we'll compare the modification time with the last updated
|
||||
// time, and if they are the same, then we don't deliver that notification
|
||||
// to corresponding IFile
|
||||
//
|
||||
// Also we are updating the expected time of the file
|
||||
// in changedFile we'll check if the modification time
|
||||
// is the same as the saved one here
|
||||
// If so then it's a expected change
|
||||
|
||||
updateFileInfo(file);
|
||||
foreach (const QString &fileName, d->m_filesWithWatch.value(file))
|
||||
updateExpectedState(fileName);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void FileManager::expectFileChange(const QString &fileName)
|
||||
|
||||
@@ -671,6 +638,26 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
|
||||
return notSaved;
|
||||
}
|
||||
|
||||
bool FileManager::saveFile(IFile *file, const QString &fileName)
|
||||
{
|
||||
const bool success = file->save(fileName);
|
||||
|
||||
// We are updating the lastUpdated time to the current modification time
|
||||
// in changedFile we'll compare the modification time with the last updated
|
||||
// time, and if they are the same, then we don't deliver that notification
|
||||
// to corresponding IFile
|
||||
//
|
||||
// Also we are updating the expected time of the file
|
||||
// in changedFile we'll check if the modification time
|
||||
// is the same as the saved one here
|
||||
// If so then it's a expected change
|
||||
updateFileInfo(file);
|
||||
foreach (const QString &fileName, d->m_filesWithWatch.value(file))
|
||||
updateExpectedState(fileName);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
QString FileManager::getSaveFileName(const QString &title, const QString &pathIn,
|
||||
const QString &filter, QString *selectedFilter)
|
||||
{
|
||||
@@ -1041,9 +1028,7 @@ void FileManager::checkForReload()
|
||||
QMapIterator<IFile *, QString> it(filesToSave);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
blockFileChange(it.key());
|
||||
it.key()->save(it.value());
|
||||
unblockFileChange(it.key());
|
||||
saveFile(it.key(), it.value());
|
||||
it.key()->checkPermissions();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,6 @@ public:
|
||||
|
||||
void renamedFile(const QString &from, const QString &to);
|
||||
|
||||
void blockFileChange(IFile *file);
|
||||
void unblockFileChange(IFile *file);
|
||||
|
||||
void expectFileChange(const QString &fileName);
|
||||
void unexpectFileChange(const QString &fileName);
|
||||
|
||||
@@ -97,6 +94,8 @@ public:
|
||||
// helper methods
|
||||
static QString fixFileName(const QString &fileName, FixMode fixmode);
|
||||
|
||||
bool saveFile(IFile *file, const QString &fileName = QString());
|
||||
|
||||
QStringList getOpenFileNames(const QString &filters,
|
||||
const QString path = QString(),
|
||||
QString *selectedFilter = 0);
|
||||
|
||||
@@ -501,9 +501,7 @@ bool CVSPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEdi
|
||||
bool closeEditor = true;
|
||||
if (!fileList.empty()) {
|
||||
// get message & commit
|
||||
Core::ICore::instance()->fileManager()->blockFileChange(fileIFace);
|
||||
fileIFace->save();
|
||||
Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace);
|
||||
Core::ICore::instance()->fileManager()->saveFile(fileIFace);
|
||||
closeEditor= commit(m_commitMessageFileName, fileList);
|
||||
}
|
||||
if (closeEditor)
|
||||
|
||||
@@ -1466,10 +1466,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
|
||||
const QString fileName = handler->currentFileName();
|
||||
if (editor && editor->file()->fileName() == fileName) {
|
||||
// Handle that as a special case for nicer interaction with core
|
||||
Core::IFile *file = editor->file();
|
||||
Core::ICore::instance()->fileManager()->blockFileChange(file);
|
||||
file->save(fileName);
|
||||
Core::ICore::instance()->fileManager()->unblockFileChange(file);
|
||||
Core::ICore::instance()->fileManager()->saveFile(editor->file(), fileName);
|
||||
// Check result by reading back.
|
||||
QFile file3(fileName);
|
||||
file3.open(QIODevice::ReadOnly);
|
||||
|
||||
@@ -781,9 +781,7 @@ bool GitPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEdi
|
||||
bool closeEditor = true;
|
||||
if (!fileList.empty() || !m_commitAmendSHA1.isEmpty()) {
|
||||
// get message & commit
|
||||
m_core->fileManager()->blockFileChange(fileIFace);
|
||||
fileIFace->save();
|
||||
m_core->fileManager()->unblockFileChange(fileIFace);
|
||||
m_core->fileManager()->saveFile(fileIFace);
|
||||
|
||||
closeEditor = m_gitClient->addAndCommit(m_submitRepository,
|
||||
editor->panelData(),
|
||||
|
||||
@@ -664,9 +664,7 @@ bool MercurialPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *sub
|
||||
const QStringList files = commitEditor->checkedFiles();
|
||||
if (!files.empty()) {
|
||||
//save the commit message
|
||||
core->fileManager()->blockFileChange(editorFile);
|
||||
editorFile->save();
|
||||
core->fileManager()->unblockFileChange(editorFile);
|
||||
core->fileManager()->saveFile(editorFile);
|
||||
|
||||
QHash<int, QVariant> extraOptions;
|
||||
extraOptions[MercurialClient::AuthorCommitOptionId] = commitEditor->committerInfo();
|
||||
|
||||
@@ -1365,10 +1365,7 @@ bool PerforcePlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *subm
|
||||
m_settings.setPromptToSubmit(wantsPrompt);
|
||||
m_settings.toSettings(Core::ICore::instance()->settings());
|
||||
}
|
||||
Core::FileManager *fileManager = Core::ICore::instance()->fileManager();
|
||||
fileManager->blockFileChange(fileIFace);
|
||||
fileIFace->save();
|
||||
fileManager->unblockFileChange(fileIFace);
|
||||
Core::ICore::instance()->fileManager()->saveFile(fileIFace);
|
||||
if (answer == VCSBase::VCSBaseSubmitEditor::SubmitDiscarded) {
|
||||
cleanCommitMessageFile();
|
||||
return true;
|
||||
|
||||
@@ -512,9 +512,7 @@ bool SubversionPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *su
|
||||
bool closeEditor = true;
|
||||
if (!fileList.empty()) {
|
||||
// get message & commit
|
||||
Core::ICore::instance()->fileManager()->blockFileChange(fileIFace);
|
||||
fileIFace->save();
|
||||
Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace);
|
||||
Core::ICore::instance()->fileManager()->saveFile(fileIFace);
|
||||
closeEditor= commit(m_commitMessageFileName, fileList);
|
||||
}
|
||||
if (closeEditor)
|
||||
|
||||
Reference in New Issue
Block a user