forked from qt-creator/qt-creator
VCS[Perforce]: Add a setting to automatically open files
when attempting to save a file under Perforce. Reviewed-by: con Task-number: QTCREATORBUG-1823
This commit is contained in:
@@ -1389,13 +1389,22 @@ EditorManager::ReadOnlyAction
|
|||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
bool displaySaveAsButton)
|
bool displaySaveAsButton)
|
||||||
{
|
{
|
||||||
|
// Version Control: If automatic open is desired, open right away.
|
||||||
|
bool promptVCS = false;
|
||||||
|
if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation)) {
|
||||||
|
if (versionControl->settingsFlags() & IVersionControl::AutoOpen)
|
||||||
|
return RO_OpenVCS;
|
||||||
|
promptVCS = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create message box.
|
||||||
QMessageBox msgBox(QMessageBox::Question, tr("File is Read Only"),
|
QMessageBox msgBox(QMessageBox::Question, tr("File is Read Only"),
|
||||||
tr("The file %1 is read only.").arg(QDir::toNativeSeparators(fileName)),
|
tr("The file <i>%1</i> is read only.").arg(QDir::toNativeSeparators(fileName)),
|
||||||
QMessageBox::Cancel, parent);
|
QMessageBox::Cancel, parent);
|
||||||
|
|
||||||
QPushButton *sccButton = 0;
|
QPushButton *vcsButton = 0;
|
||||||
if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation))
|
if (promptVCS)
|
||||||
sccButton = msgBox.addButton(tr("Open with VCS (%1)").arg(versionControl->displayName()), QMessageBox::AcceptRole);
|
vcsButton = msgBox.addButton(tr("Open with VCS (%1)").arg(versionControl->displayName()), QMessageBox::AcceptRole);
|
||||||
|
|
||||||
QPushButton *makeWritableButton = msgBox.addButton(tr("Make writable"), QMessageBox::AcceptRole);
|
QPushButton *makeWritableButton = msgBox.addButton(tr("Make writable"), QMessageBox::AcceptRole);
|
||||||
|
|
||||||
@@ -1403,11 +1412,11 @@ EditorManager::ReadOnlyAction
|
|||||||
if (displaySaveAsButton)
|
if (displaySaveAsButton)
|
||||||
saveAsButton = msgBox.addButton(tr("Save as ..."), QMessageBox::ActionRole);
|
saveAsButton = msgBox.addButton(tr("Save as ..."), QMessageBox::ActionRole);
|
||||||
|
|
||||||
msgBox.setDefaultButton(sccButton ? sccButton : makeWritableButton);
|
msgBox.setDefaultButton(vcsButton ? vcsButton : makeWritableButton);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
QAbstractButton *clickedButton = msgBox.clickedButton();
|
QAbstractButton *clickedButton = msgBox.clickedButton();
|
||||||
if (clickedButton == sccButton)
|
if (clickedButton == vcsButton)
|
||||||
return RO_OpenVCS;
|
return RO_OpenVCS;
|
||||||
if (clickedButton == makeWritableButton)
|
if (clickedButton == makeWritableButton)
|
||||||
return RO_MakeWriteable;
|
return RO_MakeWriteable;
|
||||||
|
|||||||
@@ -34,13 +34,20 @@
|
|||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
#include <QtCore/QFlags>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class CORE_EXPORT IVersionControl : public QObject
|
class CORE_EXPORT IVersionControl : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_ENUMS(SettingsFlag Operation)
|
||||||
public:
|
public:
|
||||||
|
enum SettingsFlag {
|
||||||
|
AutoOpen = 0x1
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(SettingsFlags, SettingsFlag)
|
||||||
|
|
||||||
enum Operation {
|
enum Operation {
|
||||||
AddOperation, DeleteOperation, OpenOperation, MoveOperation,
|
AddOperation, DeleteOperation, OpenOperation, MoveOperation,
|
||||||
CreateRepositoryOperation,
|
CreateRepositoryOperation,
|
||||||
@@ -76,6 +83,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool vcsOpen(const QString &fileName) = 0;
|
virtual bool vcsOpen(const QString &fileName) = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns settings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual SettingsFlags settingsFlags() const { return 0; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Called after a file has been added to a project If the version control
|
* Called after a file has been added to a project If the version control
|
||||||
* needs to know which files it needs to track you should reimplement this
|
* needs to know which files it needs to track you should reimplement this
|
||||||
@@ -137,6 +150,8 @@ signals:
|
|||||||
// virtual bool sccManaged(const QString &filename) = 0;
|
// virtual bool sccManaged(const QString &filename) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IVersionControl::SettingsFlags)
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
#endif // IVERSIONCONTROL_H
|
#endif // IVERSIONCONTROL_H
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ static const char *portKeyC = "Port";
|
|||||||
static const char *clientKeyC = "Client";
|
static const char *clientKeyC = "Client";
|
||||||
static const char *userKeyC = "User";
|
static const char *userKeyC = "User";
|
||||||
static const char *promptToSubmitKeyC = "PromptForSubmit";
|
static const char *promptToSubmitKeyC = "PromptForSubmit";
|
||||||
|
static const char *autoOpenKeyC = "PromptToOpen";
|
||||||
static const char *timeOutKeyC = "TimeOut";
|
static const char *timeOutKeyC = "TimeOut";
|
||||||
static const char *logCountKeyC = "LogCount";
|
static const char *logCountKeyC = "LogCount";
|
||||||
|
|
||||||
@@ -68,7 +69,8 @@ Settings::Settings() :
|
|||||||
logCount(defaultLogCount),
|
logCount(defaultLogCount),
|
||||||
defaultEnv(true),
|
defaultEnv(true),
|
||||||
timeOutS(defaultTimeOutS),
|
timeOutS(defaultTimeOutS),
|
||||||
promptToSubmit(true)
|
promptToSubmit(true),
|
||||||
|
autoOpen(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,8 @@ bool Settings::equals(const Settings &rhs) const
|
|||||||
&& logCount == rhs.logCount
|
&& logCount == rhs.logCount
|
||||||
&& p4Command == rhs.p4Command && p4Port == rhs.p4Port
|
&& p4Command == rhs.p4Command && p4Port == rhs.p4Port
|
||||||
&& p4Client == rhs.p4Client && p4User == rhs.p4User
|
&& p4Client == rhs.p4Client && p4User == rhs.p4User
|
||||||
&& timeOutS == rhs.timeOutS && promptToSubmit == rhs.promptToSubmit;
|
&& timeOutS == rhs.timeOutS && promptToSubmit == rhs.promptToSubmit
|
||||||
|
&& autoOpen == rhs.autoOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
QStringList Settings::commonP4Arguments() const
|
QStringList Settings::commonP4Arguments() const
|
||||||
@@ -115,6 +118,7 @@ void PerforceSettings::fromSettings(QSettings *settings)
|
|||||||
m_settings.timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
|
m_settings.timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
|
||||||
m_settings.promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
m_settings.promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
||||||
m_settings.logCount = settings->value(QLatin1String(logCountKeyC), int(defaultLogCount)).toInt();
|
m_settings.logCount = settings->value(QLatin1String(logCountKeyC), int(defaultLogCount)).toInt();
|
||||||
|
m_settings.autoOpen = settings->value(QLatin1String(autoOpenKeyC), true).toBool();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +133,7 @@ void PerforceSettings::toSettings(QSettings *settings) const
|
|||||||
settings->setValue(QLatin1String(timeOutKeyC), m_settings.timeOutS);
|
settings->setValue(QLatin1String(timeOutKeyC), m_settings.timeOutS);
|
||||||
settings->setValue(QLatin1String(promptToSubmitKeyC), m_settings.promptToSubmit);
|
settings->setValue(QLatin1String(promptToSubmitKeyC), m_settings.promptToSubmit);
|
||||||
settings->setValue(QLatin1String(logCountKeyC), m_settings.logCount);
|
settings->setValue(QLatin1String(logCountKeyC), m_settings.logCount);
|
||||||
|
settings->setValue(QLatin1String(autoOpenKeyC), m_settings.autoOpen);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +185,16 @@ void PerforceSettings::setPromptToSubmit(bool p)
|
|||||||
m_settings.promptToSubmit = p;
|
m_settings.promptToSubmit = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PerforceSettings::autoOpen() const
|
||||||
|
{
|
||||||
|
return m_settings.autoOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerforceSettings::setAutoOpen(bool b)
|
||||||
|
{
|
||||||
|
m_settings.autoOpen = b;
|
||||||
|
}
|
||||||
|
|
||||||
QString PerforceSettings::topLevel() const
|
QString PerforceSettings::topLevel() const
|
||||||
{
|
{
|
||||||
return m_topLevel;
|
return m_topLevel;
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ struct Settings {
|
|||||||
bool defaultEnv;
|
bool defaultEnv;
|
||||||
int timeOutS;
|
int timeOutS;
|
||||||
bool promptToSubmit;
|
bool promptToSubmit;
|
||||||
|
bool autoOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
|
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
|
||||||
@@ -122,6 +123,8 @@ public:
|
|||||||
bool defaultEnv() const;
|
bool defaultEnv() const;
|
||||||
bool promptToSubmit() const;
|
bool promptToSubmit() const;
|
||||||
void setPromptToSubmit(bool p);
|
void setPromptToSubmit(bool p);
|
||||||
|
bool autoOpen() const;
|
||||||
|
void setAutoOpen(bool p);
|
||||||
|
|
||||||
// Return basic arguments, including -d and server connection parameters.
|
// Return basic arguments, including -d and server connection parameters.
|
||||||
QStringList commonP4Arguments(const QString &workingDir) const;
|
QStringList commonP4Arguments(const QString &workingDir) const;
|
||||||
|
|||||||
@@ -70,6 +70,14 @@ bool PerforceVersionControl::vcsOpen(const QString &fileName)
|
|||||||
return m_plugin->vcsOpen(fi.absolutePath(), fi.fileName());
|
return m_plugin->vcsOpen(fi.absolutePath(), fi.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Core::IVersionControl::SettingsFlags PerforceVersionControl::settingsFlags() const
|
||||||
|
{
|
||||||
|
SettingsFlags rc;
|
||||||
|
if (m_plugin->settings().autoOpen())
|
||||||
|
rc|= AutoOpen;
|
||||||
|
return rc;
|
||||||
|
};
|
||||||
|
|
||||||
bool PerforceVersionControl::vcsAdd(const QString &fileName)
|
bool PerforceVersionControl::vcsAdd(const QString &fileName)
|
||||||
{
|
{
|
||||||
const QFileInfo fi(fileName);
|
const QFileInfo fi(fileName);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
|
|
||||||
virtual bool supportsOperation(Operation operation) const;
|
virtual bool supportsOperation(Operation operation) const;
|
||||||
virtual bool vcsOpen(const QString &fileName);
|
virtual bool vcsOpen(const QString &fileName);
|
||||||
|
virtual SettingsFlags settingsFlags() const;
|
||||||
virtual bool vcsAdd(const QString &fileName);
|
virtual bool vcsAdd(const QString &fileName);
|
||||||
virtual bool vcsDelete(const QString &filename);
|
virtual bool vcsDelete(const QString &filename);
|
||||||
virtual bool vcsMove(const QString &from, const QString &to);
|
virtual bool vcsMove(const QString &from, const QString &to);
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ Settings SettingsPageWidget::settings() const
|
|||||||
settings.timeOutS = m_ui.timeOutSpinBox->value();
|
settings.timeOutS = m_ui.timeOutSpinBox->value();
|
||||||
settings.logCount = m_ui.logCountSpinBox->value();
|
settings.logCount = m_ui.logCountSpinBox->value();
|
||||||
settings.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
settings.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
||||||
|
settings.autoOpen = m_ui.autoOpenCheckBox->isChecked();
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +99,7 @@ void SettingsPageWidget::setSettings(const PerforceSettings &s)
|
|||||||
m_ui.logCountSpinBox->setValue(s.logCount());
|
m_ui.logCountSpinBox->setValue(s.logCount());
|
||||||
m_ui.timeOutSpinBox->setValue(s.timeOutS());
|
m_ui.timeOutSpinBox->setValue(s.timeOutS());
|
||||||
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit());
|
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit());
|
||||||
|
m_ui.autoOpenCheckBox->setChecked(s.autoOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPageWidget::setStatusText(const QString &t)
|
void SettingsPageWidget::setStatusText(const QString &t)
|
||||||
|
|||||||
@@ -2,14 +2,6 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>Perforce::Internal::SettingsPage</class>
|
<class>Perforce::Internal::SettingsPage</class>
|
||||||
<widget class="QWidget" name="Perforce::Internal::SettingsPage">
|
<widget class="QWidget" name="Perforce::Internal::SettingsPage">
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>437</width>
|
|
||||||
<height>407</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="configGroupBox">
|
<widget class="QGroupBox" name="configGroupBox">
|
||||||
@@ -25,7 +17,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="Utils::PathChooser" name="pathChooser"/>
|
<widget class="Utils::PathChooser" name="pathChooser" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -134,6 +126,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="autoOpenCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Automatically open files when editing</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -674,7 +674,7 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
|
|||||||
switch (Core::EditorManager::promptReadOnlyFile(path, versionControl, core->mainWindow(), false)) {
|
switch (Core::EditorManager::promptReadOnlyFile(path, versionControl, core->mainWindow(), false)) {
|
||||||
case Core::EditorManager::RO_OpenVCS:
|
case Core::EditorManager::RO_OpenVCS:
|
||||||
if (!versionControl->vcsOpen(path)) {
|
if (!versionControl->vcsOpen(path)) {
|
||||||
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC."));
|
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with VCS."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user