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
}
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");
QString msg;
if (triggerExternally)
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);
QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole);
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
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
......
......@@ -920,7 +920,6 @@ void FileManager::checkForReload()
IFile::ChangeType fileChange = changeTypes.value(fileName);
if (fileChange == IFile::TypeRemoved) {
type = IFile::TypeRemoved;
trigger = IFile::TriggerExternal; // removed files always trigger externally
} else if (fileChange == IFile::TypeContents && type == IFile::TypePermissions) {
type = IFile::TypeContents;
}
......@@ -946,6 +945,11 @@ void FileManager::checkForReload()
success = file->reload(&errorString, IFile::FlagReload, type);
// file was removed or it's a content change and the default behavior for
// 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) {
// content change or removed, but settings say ignore
success = file->reload(&errorString, IFile::FlagIgnore, type);
......@@ -985,7 +989,7 @@ void FileManager::checkForReload()
// Ask about removed file
bool unhandled = true;
while (unhandled) {
switch (Utils::fileDeletedPrompt(file->fileName(), QApplication::activeWindow())) {
switch (Utils::fileDeletedPrompt(file->fileName(), trigger == IFile::TriggerExternal, QApplication::activeWindow())) {
case Utils::FileDeletedSave:
filesToSave.insert(file, file->fileName());
unhandled = false;
......
......@@ -2435,6 +2435,7 @@ void ProjectExplorerPlugin::deleteFile()
projectNode->deleteFiles(fileNode->fileType(), QStringList(filePath));
core->fileManager()->expectFileChange(fileNode->path());
if (Core::IVersionControl *vc =
core->vcsManager()->findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
vc->vcsDelete(filePath);
......@@ -2445,6 +2446,7 @@ void ProjectExplorerPlugin::deleteFile()
QMessageBox::warning(core->mainWindow(), tr("Deleting File Failed"),
tr("Could not delete file %1.").arg(filePath));
}
core->fileManager()->unexpectFileChange(fileNode->path());
}
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