Commit 060778dd authored by dt_'s avatar dt_
Browse files

Handle internally triggered deletes more gracefull

If the user has enabled "Reload unmodified" then on remove the
unmodified editors are closed. Otherwise the user is asked as before.
Also modify the message to indicate if the change was triggred
externally.
parent 2224eb70
...@@ -81,12 +81,16 @@ QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer ...@@ -81,12 +81,16 @@ QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
} }
QTCREATOR_UTILS_EXPORT Utils::FileDeletedPromptAnswer QTCREATOR_UTILS_EXPORT Utils::FileDeletedPromptAnswer
Utils::fileDeletedPrompt(const QString &fileName, QWidget *parent) Utils::fileDeletedPrompt(const QString &fileName, bool triggerExternally, QWidget *parent)
{ {
const QString title = QCoreApplication::translate("Utils::fileDeletedPrompt", "File has been removed"); const QString title = QCoreApplication::translate("Utils::fileDeletedPrompt", "File has been removed");
QString msg; QString msg;
msg = QCoreApplication::translate("Utils::fileDeletedPrompt", if (triggerExternally)
"The file %1 has been removed outside Qt Creator. Do you want to save it under a different name, or close the editor?").arg(QDir::toNativeSeparators(fileName)); msg = QCoreApplication::translate("Utils::fileDeletedPrompt",
"The file %1 has been removed outside Qt Creator. Do you want to save it under a different name, or close the editor?").arg(QDir::toNativeSeparators(fileName));
else
msg = QCoreApplication::translate("Utils::fileDeletedPrompt",
"The file %1 was removed. Do you want to save it under a different name, or close the editor?").arg(QDir::toNativeSeparators(fileName));
QMessageBox box(QMessageBox::Question, title, msg, QMessageBox::NoButton, parent); QMessageBox box(QMessageBox::Question, title, msg, QMessageBox::NoButton, parent);
QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole); QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole);
QPushButton *saveas = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save as..."), QMessageBox::ActionRole); QPushButton *saveas = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save as..."), QMessageBox::ActionRole);
......
...@@ -49,7 +49,7 @@ QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &title, con ...@@ -49,7 +49,7 @@ QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &title, con
enum FileDeletedPromptAnswer { FileDeletedClose, FileDeletedSaveAs, FileDeletedSave }; enum FileDeletedPromptAnswer { FileDeletedClose, FileDeletedSaveAs, FileDeletedSave };
QTCREATOR_UTILS_EXPORT FileDeletedPromptAnswer fileDeletedPrompt(const QString &fileName, QWidget *parent); QTCREATOR_UTILS_EXPORT FileDeletedPromptAnswer fileDeletedPrompt(const QString &fileName, bool triggerExternally, QWidget *parent);
} // namespace Utils } // namespace Utils
......
...@@ -920,7 +920,6 @@ void FileManager::checkForReload() ...@@ -920,7 +920,6 @@ void FileManager::checkForReload()
IFile::ChangeType fileChange = changeTypes.value(fileName); IFile::ChangeType fileChange = changeTypes.value(fileName);
if (fileChange == IFile::TypeRemoved) { if (fileChange == IFile::TypeRemoved) {
type = IFile::TypeRemoved; type = IFile::TypeRemoved;
trigger = IFile::TriggerExternal; // removed files always trigger externally
} else if (fileChange == IFile::TypeContents && type == IFile::TypePermissions) { } else if (fileChange == IFile::TypeContents && type == IFile::TypePermissions) {
type = IFile::TypeContents; type = IFile::TypeContents;
} }
...@@ -946,6 +945,11 @@ void FileManager::checkForReload() ...@@ -946,6 +945,11 @@ void FileManager::checkForReload()
success = file->reload(&errorString, IFile::FlagReload, type); success = file->reload(&errorString, IFile::FlagReload, type);
// file was removed or it's a content change and the default behavior for // file was removed or it's a content change and the default behavior for
// unmodified files didn't kick in // unmodified files didn't kick in
} else if (defaultBehavior == IFile::ReloadUnmodified
&& type == IFile::TypeRemoved && !file->isModified()) {
// file removed, but unmodified files should be reloaded
// so we close the file
editorsToClose << EditorManager::instance()->editorsForFile(file);
} else if (defaultBehavior == IFile::IgnoreAll) { } else if (defaultBehavior == IFile::IgnoreAll) {
// content change or removed, but settings say ignore // content change or removed, but settings say ignore
success = file->reload(&errorString, IFile::FlagIgnore, type); success = file->reload(&errorString, IFile::FlagIgnore, type);
...@@ -985,7 +989,7 @@ void FileManager::checkForReload() ...@@ -985,7 +989,7 @@ void FileManager::checkForReload()
// Ask about removed file // Ask about removed file
bool unhandled = true; bool unhandled = true;
while (unhandled) { while (unhandled) {
switch (Utils::fileDeletedPrompt(file->fileName(), QApplication::activeWindow())) { switch (Utils::fileDeletedPrompt(file->fileName(), trigger == IFile::TriggerExternal, QApplication::activeWindow())) {
case Utils::FileDeletedSave: case Utils::FileDeletedSave:
filesToSave.insert(file, file->fileName()); filesToSave.insert(file, file->fileName());
unhandled = false; unhandled = false;
......
...@@ -2435,6 +2435,7 @@ void ProjectExplorerPlugin::deleteFile() ...@@ -2435,6 +2435,7 @@ void ProjectExplorerPlugin::deleteFile()
projectNode->deleteFiles(fileNode->fileType(), QStringList(filePath)); projectNode->deleteFiles(fileNode->fileType(), QStringList(filePath));
core->fileManager()->expectFileChange(fileNode->path());
if (Core::IVersionControl *vc = if (Core::IVersionControl *vc =
core->vcsManager()->findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) { core->vcsManager()->findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
vc->vcsDelete(filePath); vc->vcsDelete(filePath);
...@@ -2445,6 +2446,7 @@ void ProjectExplorerPlugin::deleteFile() ...@@ -2445,6 +2446,7 @@ void ProjectExplorerPlugin::deleteFile()
QMessageBox::warning(core->mainWindow(), tr("Deleting File Failed"), QMessageBox::warning(core->mainWindow(), tr("Deleting File Failed"),
tr("Could not delete file %1.").arg(filePath)); tr("Could not delete file %1.").arg(filePath));
} }
core->fileManager()->unexpectFileChange(fileNode->path());
} }
void ProjectExplorerPlugin::renameFile() void ProjectExplorerPlugin::renameFile()
......
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