Commit 0a941005 authored by Henrik Abelsson's avatar Henrik Abelsson Committed by Thorbjørn Lindeijer

Add option to select behavior on externally changed files.

Merge-request: 840
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent e38cec51
......@@ -36,11 +36,18 @@ using namespace Core;
using namespace Core::Utils;
QTCREATOR_UTILS_EXPORT Core::Utils::ReloadPromptAnswer
Core::Utils::reloadPrompt(const QString &fileName, QWidget *parent)
Core::Utils::reloadPrompt(const QString &fileName, bool modified, QWidget *parent)
{
const QString title = QCoreApplication::translate("Core::Utils::reloadPrompt", "File Changed");
const QString msg = QCoreApplication::translate("Core::Utils::reloadPrompt",
"The file %1 has changed outside Qt Creator. Do you want to reload it?").arg(fileName);
QString msg;
if (modified)
msg = QCoreApplication::translate("Core::Utils::reloadPrompt",
"The unsaved file %1 has been changed outside Qt Creator. Do you want to reload it and discard your changes?").arg(fileName);
else
msg = QCoreApplication::translate("Core::Utils::reloadPrompt",
"The file %1 has changed outside Qt Creator. Do you want to reload it?").arg(fileName);
return reloadPrompt(title, msg, parent);
}
......
......@@ -42,7 +42,7 @@ namespace Utils {
enum ReloadPromptAnswer { ReloadCurrent, ReloadAll, ReloadSkipCurrent, ReloadNone };
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &fileName, QWidget *parent);
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &fileName, bool modified, QWidget *parent);
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &title, const QString &prompt, QWidget *parent);
} // namespace Utils
......
......@@ -196,6 +196,12 @@ public:
switch (*behavior) {
case Core::IFile::ReloadNone:
return;
case Core::IFile::ReloadUnmodified:
if (!isModified()) {
open(fileName);
return;
}
break;
case Core::IFile::ReloadAll:
open(fileName);
return;
......@@ -206,7 +212,7 @@ public:
break;
}
switch (Core::Utils::reloadPrompt(fileName, Core::ICore::instance()->mainWindow())) {
switch (Core::Utils::reloadPrompt(fileName, isModified(), Core::ICore::instance()->mainWindow())) {
case Core::Utils::ReloadCurrent:
open(fileName);
break;
......
......@@ -186,6 +186,8 @@ struct EditorManagerPrivate {
OpenEditorsModel *m_editorModel;
QString m_externalEditor;
IFile::ReloadBehavior m_reloadBehavior;
};
}
......@@ -206,7 +208,8 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
m_openInExternalEditorAction(new QAction(EditorManager::tr("Open in External Editor"), parent)),
currentNavigationHistoryPosition(0),
m_windowPopup(0),
m_coreListener(0)
m_coreListener(0),
m_reloadBehavior(IFile::AskForReload)
{
m_editorModel = new OpenEditorsModel(parent);
}
......@@ -1717,12 +1720,14 @@ bool EditorManager::restoreState(const QByteArray &state)
static const char * const documentStatesKey = "EditorManager/DocumentStates";
static const char * const externalEditorKey = "EditorManager/ExternalEditorCommand";
static const char * const reloadBehaviorKey = "EditorManager/ReloadBehavior";
void EditorManager::saveSettings()
{
SettingsDatabase *settings = m_d->m_core->settingsDatabase();
settings->setValue(QLatin1String(documentStatesKey), m_d->m_editorStates);
settings->setValue(QLatin1String(externalEditorKey), m_d->m_externalEditor);
settings->setValue(QLatin1String(reloadBehaviorKey), m_d->m_reloadBehavior);
}
void EditorManager::readSettings()
......@@ -1745,6 +1750,9 @@ void EditorManager::readSettings()
.value<QMap<QString, QVariant> >();
if (settings->contains(QLatin1String(externalEditorKey)))
m_d->m_externalEditor = settings->value(QLatin1String(externalEditorKey)).toString();
if (settings->contains(QLatin1String(reloadBehaviorKey)))
m_d->m_reloadBehavior = (IFile::ReloadBehavior)settings->value(QLatin1String(reloadBehaviorKey)).toInt();
}
......@@ -1913,6 +1921,15 @@ QString EditorManager::externalEditor() const
return m_d->m_externalEditor;
}
void EditorManager::setReloadBehavior(IFile::ReloadBehavior behavior)
{
m_d->m_reloadBehavior = behavior;
}
IFile::ReloadBehavior EditorManager::reloadBehavior() const
{
return m_d->m_reloadBehavior;
}
Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
{
......
......@@ -177,6 +177,8 @@ public:
QString defaultExternalEditor() const;
QString externalEditorHelpText() const;
void setReloadBehavior(IFile::ReloadBehavior behavior);
IFile::ReloadBehavior reloadBehavior() const;
// Helper to display a message dialog when encountering a read-only
// file, prompting the user about how to make it writeable.
......
......@@ -484,8 +484,7 @@ void FileManager::checkForReload()
m_blockActivated = true;
const QList<QPointer<IFile> > changed = m_changedFiles;
m_changedFiles.clear();
IFile::ReloadBehavior behavior =
IFile::AskForReload;
IFile::ReloadBehavior behavior = EditorManager::instance()->reloadBehavior();
foreach (IFile *f, changed) {
if (!f)
continue;
......
......@@ -74,6 +74,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
m_page->colorButton->setColor(StyleHelper::baseColor());
m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor());
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadBehavior());
#ifdef Q_OS_UNIX
m_page->terminalEdit->setText(ConsoleProcess::terminalEmulator(Core::ICore::instance()->settings()));
#else
......@@ -101,6 +102,7 @@ void GeneralSettings::apply()
// Apply the new base color if accepted
StyleHelper::setBaseColor(m_page->colorButton->color());
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
EditorManager::instance()->setReloadBehavior(IFile::ReloadBehavior(m_page->reloadBehavior->currentIndex()));
#ifdef Q_OS_UNIX
ConsoleProcess::setTerminalEmulator(Core::ICore::instance()->settings(),
m_page->terminalEdit->text());
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>236</height>
<width>536</width>
<height>233</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -59,7 +59,7 @@
<height>0</height>
</size>
</property>
<property name="alphaAllowed">
<property name="alphaAllowed" stdset="0">
<bool>false</bool>
</property>
</widget>
......@@ -156,6 +156,58 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>When files are externally modified:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="reloadBehavior">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Always ask</string>
</property>
</item>
<item>
<property name="text">
<string>Reload all unmodified files</string>
</property>
</item>
<item>
<property name="text">
<string>Ignore modifications</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
......
......@@ -42,7 +42,15 @@ class CORE_EXPORT IFile : public QObject
Q_OBJECT
public:
enum ReloadBehavior { AskForReload, ReloadAll, ReloadPermissions, ReloadNone };
// This enum must match the indexes of the reloadBehavior widget
// in generalsettings.ui
enum ReloadBehavior {
AskForReload = 0,
ReloadUnmodified = 1,
ReloadNone = 2,
ReloadAll,
ReloadPermissions
};
IFile(QObject *parent = 0) : QObject(parent) {}
virtual ~IFile() {}
......
......@@ -31,6 +31,7 @@
#include "designerconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/reloadpromptutils.h>
#include <QtDesigner/QDesignerFormWindowInterface>
......@@ -117,6 +118,12 @@ void FormWindowFile::modified(Core::IFile::ReloadBehavior *behavior)
switch (*behavior) {
case Core::IFile::ReloadNone:
return;
case Core::IFile::ReloadUnmodified:
if (!isModified()) {
reload(m_fileName);
return;
}
break;
case Core::IFile::ReloadAll:
emit reload(m_fileName);
return;
......@@ -127,7 +134,7 @@ void FormWindowFile::modified(Core::IFile::ReloadBehavior *behavior)
break;
}
switch (Core::Utils::reloadPrompt(m_fileName, Core::ICore::instance()->mainWindow())) {
switch (Core::Utils::reloadPrompt(m_fileName, isModified(), Core::ICore::instance()->mainWindow())) {
case Core::Utils::ReloadCurrent:
emit reload(m_fileName);
break;
......
......@@ -34,6 +34,7 @@
#include <qrceditor.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/reloadpromptutils.h>
#include <QtCore/QTemporaryFile>
......@@ -189,8 +190,14 @@ void ResourceEditorFile::modified(Core::IFile::ReloadBehavior *behavior)
const QString fileName = m_parent->m_resourceEditor->fileName();
switch (*behavior) {
case Core::IFile::ReloadNone:
case Core::IFile::ReloadNone:
return;
case Core::IFile::ReloadUnmodified:
if (!isModified()) {
m_parent->open(fileName);
return;
}
break;
case Core::IFile::ReloadAll:
m_parent->open(fileName);
return;
......@@ -201,7 +208,7 @@ void ResourceEditorFile::modified(Core::IFile::ReloadBehavior *behavior)
break;
}
switch (Core::Utils::reloadPrompt(fileName, Core::ICore::instance()->mainWindow())) {
switch (Core::Utils::reloadPrompt(fileName, isModified(), Core::ICore::instance()->mainWindow())) {
case Core::Utils::ReloadCurrent:
m_parent->open(fileName);
break;
......
......@@ -31,6 +31,7 @@
#include "basetexteditor.h"
#include "storagesettings.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
......@@ -42,6 +43,7 @@
#ifndef TEXTEDITOR_STANDALONE
#include <utils/reloadpromptutils.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#endif
#include <utils/qtcassert.h>
......@@ -256,6 +258,12 @@ void BaseTextDocument::modified(Core::IFile::ReloadBehavior *behavior)
switch (*behavior) {
case Core::IFile::ReloadNone:
return;
case Core::IFile::ReloadUnmodified:
if (!isModified()) {
reload();
return;
}
break;
case Core::IFile::ReloadAll:
reload();
return;
......@@ -267,7 +275,8 @@ void BaseTextDocument::modified(Core::IFile::ReloadBehavior *behavior)
}
#ifndef TEXTEDITOR_STANDALONE
switch (Core::Utils::reloadPrompt(m_fileName, QApplication::activeWindow())) {
switch (Core::Utils::reloadPrompt(m_fileName, isModified(), QApplication::activeWindow())) {
case Core::Utils::ReloadCurrent:
reload();
break;
......
......@@ -46,7 +46,6 @@
#include <extensionsystem/pluginmanager.h>
#include <find/basetextfind.h>
#include <utils/reloadpromptutils.h>
#include <aggregation/aggregate.h>
#endif
#include <utils/linecolumnlabel.h>
......
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