forked from qt-creator/qt-creator
Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline
Conflicts: src/plugins/perforce/perforceplugin.cpp
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <vcsbase/basevcseditorfactory.h>
|
||||
@@ -144,7 +145,6 @@ bool CoreListener::editorAboutToClose(Core::IEditor *editor)
|
||||
// PerforcePlugin
|
||||
////
|
||||
|
||||
Core::ICore *PerforcePlugin::m_coreInstance = NULL;
|
||||
PerforcePlugin *PerforcePlugin::m_perforcePluginInstance = NULL;
|
||||
|
||||
PerforcePlugin::PerforcePlugin() :
|
||||
@@ -182,17 +182,20 @@ static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
|
||||
Perforce::Constants::C_PERFORCESUBMITEDITOR
|
||||
};
|
||||
|
||||
bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
||||
bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorMessage);
|
||||
|
||||
typedef VCSBase::VCSEditorFactory<PerforceEditor> PerforceEditorFactory;
|
||||
typedef VCSBase::VCSSubmitEditorFactory<PerforceSubmitEditor> PerforceSubmitEditorFactory;
|
||||
|
||||
m_coreInstance = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
|
||||
if (!m_coreInstance->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.perforce/Perforce.mimetypes.xml"), errorMessage))
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.perforce/Perforce.mimetypes.xml"), errorMessage))
|
||||
return false;
|
||||
m_perforcePluginInstance = this;
|
||||
|
||||
if (QSettings *settings = m_coreInstance->settings())
|
||||
if (QSettings *settings = core->settings())
|
||||
m_settings.fromSettings(settings);
|
||||
|
||||
m_perforceOutputWindow = new PerforceOutputWindow(this);
|
||||
@@ -208,24 +211,19 @@ bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *erro
|
||||
static const char *describeSlot = SLOT(describe(QString,QString));
|
||||
const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
|
||||
for (int i = 0; i < editorCount; i++) {
|
||||
m_editorFactories.push_back(new PerforceEditorFactory(editorParameters + i, m_coreInstance, this, describeSlot));
|
||||
m_editorFactories.push_back(new PerforceEditorFactory(editorParameters + i, this, describeSlot));
|
||||
addObject(m_editorFactories.back());
|
||||
}
|
||||
|
||||
m_versionControl = new PerforceVersionControl(this);
|
||||
addObject(m_versionControl);
|
||||
|
||||
#ifdef USE_P4_API
|
||||
m_workbenchClientUser = new WorkbenchClientUser(m_perforceOutputWindow, this);
|
||||
m_enableP4APIActions = true;
|
||||
#endif
|
||||
|
||||
m_coreListener = new CoreListener(this);
|
||||
addObject(m_coreListener);
|
||||
|
||||
|
||||
//register actions
|
||||
Core::ActionManager *am = m_coreInstance->actionManager();
|
||||
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
||||
|
||||
Core::ActionContainer *mtools =
|
||||
am->actionContainer(Core::Constants::M_TOOLS);
|
||||
@@ -244,7 +242,7 @@ bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *erro
|
||||
|
||||
QList<int> perforcesubmitcontext;
|
||||
perforcesubmitcontext <<
|
||||
m_coreInstance->uniqueIDManager()->uniqueIdentifier(Constants::C_PERFORCESUBMITEDITOR);
|
||||
Core::ICore::instance()->uniqueIDManager()->uniqueIdentifier(Constants::C_PERFORCESUBMITEDITOR);
|
||||
|
||||
Core::Command *command;
|
||||
QAction *tmpaction;
|
||||
@@ -382,10 +380,10 @@ bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *erro
|
||||
m_redoAction = new QAction(tr("&Redo"), this);
|
||||
command = am->registerAction(m_redoAction, Core::Constants::REDO, perforcesubmitcontext);
|
||||
|
||||
connect(m_coreInstance, SIGNAL(contextChanged(Core::IContext *)),
|
||||
connect(core, SIGNAL(contextChanged(Core::IContext *)),
|
||||
this, SLOT(updateActions()));
|
||||
|
||||
connect(m_coreInstance->fileManager(), SIGNAL(currentFileChanged(const QString &)),
|
||||
connect(core->fileManager(), SIGNAL(currentFileChanged(const QString &)),
|
||||
this, SLOT(updateActions()));
|
||||
|
||||
return true;
|
||||
@@ -419,10 +417,8 @@ void PerforcePlugin::deleteCurrentFile()
|
||||
|
||||
void PerforcePlugin::revertCurrentFile()
|
||||
{
|
||||
QTC_ASSERT(m_coreInstance, return);
|
||||
|
||||
const QString fileName = currentFileName();
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, fileName);
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(fileName);
|
||||
QStringList args;
|
||||
args << QLatin1String("diff") << QLatin1String("-sa");
|
||||
PerforceResponse result = runP4Cmd(args, QStringList(), CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
||||
@@ -438,7 +434,7 @@ void PerforcePlugin::revertCurrentFile()
|
||||
return;
|
||||
}
|
||||
|
||||
Core::FileManager *fm = m_coreInstance->fileManager();
|
||||
Core::FileManager *fm = Core::ICore::instance()->fileManager();
|
||||
QList<Core::IFile *> files = fm->managedFiles(fileName);
|
||||
foreach (Core::IFile *file, files) {
|
||||
fm->blockFileChange(file);
|
||||
@@ -471,7 +467,7 @@ void PerforcePlugin::diffAllOpened()
|
||||
|
||||
void PerforcePlugin::printOpenedFileList()
|
||||
{
|
||||
Core::IEditor *e = m_coreInstance->editorManager()->currentEditor();
|
||||
Core::IEditor *e = Core::ICore::instance()->editorManager()->currentEditor();
|
||||
if (e)
|
||||
e->widget()->setFocus();
|
||||
PerforceResponse result = runP4Cmd(QStringList() << QLatin1String("opened"), QStringList(), CommandToWindow|StdOutToWindow|StdErrToWindow|ErrorToWindow);
|
||||
@@ -487,8 +483,6 @@ void PerforcePlugin::resolve()
|
||||
|
||||
void PerforcePlugin::submit()
|
||||
{
|
||||
QTC_ASSERT(m_coreInstance, return);
|
||||
|
||||
if (!checkP4Command()) {
|
||||
showOutput(tr("No p4 executable specified!"), true);
|
||||
return;
|
||||
@@ -549,8 +543,8 @@ void PerforcePlugin::submit()
|
||||
Core::IEditor *PerforcePlugin::openPerforceSubmitEditor(const QString &fileName, const QStringList &depotFileNames)
|
||||
{
|
||||
Core::IEditor *editor =
|
||||
m_coreInstance->editorManager()->openEditor(fileName, Constants::PERFORCESUBMITEDITOR_KIND);
|
||||
m_coreInstance->editorManager()->ensureEditorManagerVisible();
|
||||
Core::ICore::instance()->editorManager()->openEditor(fileName, Constants::PERFORCESUBMITEDITOR_KIND);
|
||||
Core::ICore::instance()->editorManager()->ensureEditorManagerVisible();
|
||||
PerforceSubmitEditor *submitEditor = dynamic_cast<PerforceSubmitEditor*>(editor);
|
||||
QTC_ASSERT(submitEditor, return 0);
|
||||
submitEditor->restrictToProjectFiles(depotFileNames);
|
||||
@@ -562,7 +556,7 @@ Core::IEditor *PerforcePlugin::openPerforceSubmitEditor(const QString &fileName,
|
||||
void PerforcePlugin::printPendingChanges()
|
||||
{
|
||||
qApp->setOverrideCursor(Qt::WaitCursor);
|
||||
PendingChangesDialog dia(pendingChangesData(), m_coreInstance->mainWindow());
|
||||
PendingChangesDialog dia(pendingChangesData(), Core::ICore::instance()->mainWindow());
|
||||
qApp->restoreOverrideCursor();
|
||||
if (dia.exec() == QDialog::Accepted) {
|
||||
const int i = dia.changeNumber();
|
||||
@@ -595,14 +589,15 @@ void PerforcePlugin::annotate()
|
||||
|
||||
void PerforcePlugin::annotate(const QString &fileName)
|
||||
{
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, fileName);
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(fileName);
|
||||
QStringList args;
|
||||
args << QLatin1String("annotate") << QLatin1String("-cqi") << fileName;
|
||||
const PerforceResponse result = runP4Cmd(args, QStringList(),
|
||||
CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
||||
if (!result.error) {
|
||||
const QFileInfo fi(fileName);
|
||||
showOutputInEditor(tr("p4 annotate %1").arg(fi.fileName()), result.stdOut, VCSBase::AnnotateOutput, codec);
|
||||
showOutputInEditor(tr("p4 annotate %1").arg(fi.fileName()),
|
||||
result.stdOut, VCSBase::AnnotateOutput, codec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,14 +617,15 @@ void PerforcePlugin::filelog()
|
||||
|
||||
void PerforcePlugin::filelog(const QString &fileName)
|
||||
{
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, fileName);
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(fileName);
|
||||
QStringList args;
|
||||
args << QLatin1String("filelog") << QLatin1String("-li") << fileName;
|
||||
const PerforceResponse result = runP4Cmd(args, QStringList(),
|
||||
CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
||||
if (!result.error) {
|
||||
const QFileInfo fi(fileName);
|
||||
showOutputInEditor(tr("p4 filelog %1").arg(fi.fileName()), result.stdOut, VCSBase::LogOutput, codec);
|
||||
showOutputInEditor(tr("p4 filelog %1").arg(fi.fileName()),
|
||||
result.stdOut, VCSBase::LogOutput, codec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +747,6 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args,
|
||||
qDebug() << "PerforcePlugin::runP4Cmd" << args << extraArgs << debugCodec(outputCodec);
|
||||
PerforceResponse response;
|
||||
response.error = true;
|
||||
QTC_ASSERT(m_coreInstance, return response);
|
||||
if (!checkP4Command()) {
|
||||
response.message = tr("No p4 executable specified!");
|
||||
m_perforceOutputWindow->append(response.message, true);
|
||||
@@ -846,7 +841,7 @@ Core::IEditor * PerforcePlugin::showOutputInEditor(const QString& title, const Q
|
||||
if (Perforce::Constants::debug)
|
||||
qDebug() << "PerforcePlugin::showOutputInEditor" << title << kind << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
|
||||
QString s = title;
|
||||
Core::IEditor *ediface = m_coreInstance->editorManager()->
|
||||
Core::IEditor *ediface = Core::ICore::instance()->editorManager()->
|
||||
newFile(kind, &s, output.toLocal8Bit());
|
||||
PerforceEditor *e = qobject_cast<PerforceEditor*>(ediface->widget());
|
||||
if (!e)
|
||||
@@ -881,7 +876,7 @@ void PerforcePlugin::p4Diff(const QStringList &files, QString diffname)
|
||||
Core::IEditor *editor = 0;
|
||||
bool displayInEditor = true;
|
||||
Core::IEditor *existingEditor = 0;
|
||||
QTextCodec *codec = files.empty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(m_coreInstance, files.front());
|
||||
QTextCodec *codec = files.empty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(files.front());
|
||||
if (Perforce::Constants::debug)
|
||||
qDebug() << Q_FUNC_INFO << files << debugCodec(codec);
|
||||
|
||||
@@ -894,7 +889,7 @@ void PerforcePlugin::p4Diff(const QStringList &files, QString diffname)
|
||||
diffname = fi.fileName();
|
||||
}
|
||||
|
||||
foreach (Core::IEditor *ed, m_coreInstance->editorManager()->openedEditors()) {
|
||||
foreach (Core::IEditor *ed, Core::ICore::instance()->editorManager()->openedEditors()) {
|
||||
if (ed->file()->property("originalFileName").toString() == fileName) {
|
||||
existingEditor = ed;
|
||||
displayInEditor = false;
|
||||
@@ -917,7 +912,7 @@ void PerforcePlugin::p4Diff(const QStringList &files, QString diffname)
|
||||
} else if (!displayInEditor && existingEditor) {
|
||||
if (existingEditor) {
|
||||
existingEditor->createNew(result.stdOut);
|
||||
m_coreInstance->editorManager()->setCurrentEditor(existingEditor);
|
||||
Core::ICore::instance()->editorManager()->setCurrentEditor(existingEditor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -925,7 +920,7 @@ void PerforcePlugin::p4Diff(const QStringList &files, QString diffname)
|
||||
|
||||
void PerforcePlugin::describe(const QString & source, const QString &n)
|
||||
{
|
||||
QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(m_coreInstance, source);
|
||||
QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(source);
|
||||
QStringList args;
|
||||
args << QLatin1String("describe") << QLatin1String("-du") << n;
|
||||
const PerforceResponse result = runP4Cmd(args, QStringList(), CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
||||
@@ -935,29 +930,32 @@ void PerforcePlugin::describe(const QString & source, const QString &n)
|
||||
|
||||
void PerforcePlugin::submitCurrentLog()
|
||||
{
|
||||
m_coreInstance->editorManager()->closeEditors(QList<Core::IEditor*>()
|
||||
<< m_coreInstance->editorManager()->currentEditor());
|
||||
Core::EditorManager *em = Core::ICore::instance()->editorManager();
|
||||
em->closeEditors(QList<Core::IEditor*>() << em->currentEditor());
|
||||
}
|
||||
|
||||
bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
|
||||
{
|
||||
if (!m_changeTmpFile || !editor)
|
||||
return true;
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
Core::IFile *fileIFace = editor->file();
|
||||
if (!fileIFace)
|
||||
return true;
|
||||
QFileInfo editorFile(fileIFace->fileName());
|
||||
QFileInfo changeFile(m_changeTmpFile->fileName());
|
||||
if (editorFile.absoluteFilePath() == changeFile.absoluteFilePath()) {
|
||||
const QMessageBox::StandardButton answer = QMessageBox::question(m_coreInstance->mainWindow(), tr("Closing p4 Editor"), tr("Do you want to submit this change list?"),
|
||||
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes);
|
||||
if (answer == QMessageBox::Cancel) {
|
||||
const QMessageBox::StandardButton answer =
|
||||
QMessageBox::question(core->mainWindow(),
|
||||
tr("Closing p4 Editor"),
|
||||
tr("Do you want to submit this change list?"),
|
||||
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes);
|
||||
if (answer == QMessageBox::Cancel)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_coreInstance->fileManager()->blockFileChange(fileIFace);
|
||||
core->fileManager()->blockFileChange(fileIFace);
|
||||
fileIFace->save();
|
||||
m_coreInstance->fileManager()->unblockFileChange(fileIFace);
|
||||
core->fileManager()->unblockFileChange(fileIFace);
|
||||
if (answer == QMessageBox::Yes) {
|
||||
QByteArray change = m_changeTmpFile->readAll();
|
||||
m_changeTmpFile->close();
|
||||
@@ -1006,15 +1004,14 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
|
||||
|
||||
void PerforcePlugin::openFiles(const QStringList &files)
|
||||
{
|
||||
foreach (QString s, files) {
|
||||
m_coreInstance->editorManager()->openEditor(clientFilePath(s));
|
||||
}
|
||||
m_coreInstance->editorManager()->ensureEditorManagerVisible();
|
||||
Core::EditorManager *em = Core::ICore::instance()->editorManager();
|
||||
foreach (QString s, files)
|
||||
em->openEditor(clientFilePath(s));
|
||||
em->ensureEditorManagerVisible();
|
||||
}
|
||||
|
||||
QString PerforcePlugin::clientFilePath(const QString &serverFilePath)
|
||||
{
|
||||
QTC_ASSERT(m_coreInstance, return QString());
|
||||
if (!checkP4Command())
|
||||
return QString();
|
||||
|
||||
@@ -1040,7 +1037,7 @@ QString PerforcePlugin::clientFilePath(const QString &serverFilePath)
|
||||
|
||||
QString PerforcePlugin::currentFileName()
|
||||
{
|
||||
QString fileName = m_coreInstance->fileManager()->currentFile();
|
||||
QString fileName = Core::ICore::instance()->fileManager()->currentFile();
|
||||
|
||||
// TODO: Use FileManager::fixPath
|
||||
const QFileInfo fileInfo(fileName);
|
||||
@@ -1068,67 +1065,9 @@ bool PerforcePlugin::checkP4Command() const
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef USE_P4_API
|
||||
void PerforcePlugin::runP4APICmd(const QString &cmd, const QStringList &args)
|
||||
{
|
||||
m_enableP4APIActions = false;
|
||||
updateActions();
|
||||
|
||||
ClientApi client;
|
||||
if (!m_settings.defaultEnv) {
|
||||
client.SetClient(m_settings.p4Client.toLatin1().constData());
|
||||
client.SetPort(m_settings.p4Port.toLatin1().constData());
|
||||
client.SetUser(m_settings.p4User.toLatin1().constData());
|
||||
}
|
||||
|
||||
Error err;
|
||||
m_coreInstance->messageManager()->displayStatusBarMessage(tr("Connecting to p4 server..."));
|
||||
client.SetProtocol("api", "56");
|
||||
client.Init(&err);
|
||||
if (err.Test()) {
|
||||
StrBuf msg;
|
||||
err.Fmt(&msg);
|
||||
QMessageBox::critical(m_coreInstance->mainWindow(), tr("Perforce Plugin"), tr("Failed to connect to p4 server <b>%1</b>!").arg(msg.Text()));
|
||||
client.Final(&err);
|
||||
m_coreInstance->messageManager()->displayStatusBarMessage(tr("Connection to p4 server failed!"), 3000);
|
||||
return;
|
||||
}
|
||||
m_coreInstance->messageManager()->displayStatusBarMessage(tr("Connection to p4 server established."), 3000);
|
||||
|
||||
// ????
|
||||
//client.SetCwd("c:\\depot\\research\\qworkbench\\src");
|
||||
|
||||
int argc = args.count();
|
||||
char **argv = (char**)malloc(argc*sizeof(char*));
|
||||
int i = 0;
|
||||
foreach (QString s, args)
|
||||
argv[i++] = qstrdup(s.toLatin1().constData());
|
||||
|
||||
client.SetArgv( argc, argv );
|
||||
try {
|
||||
client.Run(cmd.toLatin1().constData(), m_workbenchClientUser);
|
||||
} catch (...) {
|
||||
QMessageBox::critical(m_coreInstance->mainWindow(), tr("Perforce Plugin"), tr("Failed to run command <b>%1</b>!").arg(cmd));
|
||||
}
|
||||
client.Final(&err);
|
||||
i = 0;
|
||||
while (i<argc)
|
||||
free(argv[i++]);
|
||||
free(argv);
|
||||
|
||||
m_enableP4APIActions = true;
|
||||
updateActions();
|
||||
|
||||
Core::IEditor *edt = m_coreInstance->editorManager()->currentEditor();
|
||||
if (edt && edt->widget())
|
||||
edt->widget()->setFocus();
|
||||
}
|
||||
#endif
|
||||
|
||||
QString PerforcePlugin::pendingChangesData()
|
||||
{
|
||||
QString data;
|
||||
Q_ASSERT(m_coreInstance);
|
||||
if (!checkP4Command())
|
||||
return data;
|
||||
|
||||
@@ -1168,22 +1107,18 @@ PerforcePlugin::~PerforcePlugin()
|
||||
m_settingsPage = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_P4_API
|
||||
if (m_workbenchClientUser) {
|
||||
delete m_workbenchClientUser;
|
||||
m_workbenchClientUser = 0;
|
||||
}
|
||||
#endif
|
||||
if (m_perforceOutputWindow) {
|
||||
removeObject(m_perforceOutputWindow);
|
||||
delete m_perforceOutputWindow;
|
||||
m_perforceOutputWindow = 0;
|
||||
}
|
||||
|
||||
if (m_submitEditorFactory) {
|
||||
removeObject(m_submitEditorFactory);
|
||||
delete m_submitEditorFactory;
|
||||
m_submitEditorFactory = 0;
|
||||
}
|
||||
|
||||
if (m_versionControl) {
|
||||
removeObject(m_versionControl);
|
||||
delete m_versionControl;
|
||||
@@ -1213,7 +1148,7 @@ void PerforcePlugin::setSettings(const PerforceSettings &s)
|
||||
{
|
||||
if (s != m_settings) {
|
||||
m_settings = s;
|
||||
if (QSettings *settings = m_coreInstance->settings())
|
||||
if (QSettings *settings = Core::ICore::instance()->settings())
|
||||
m_settings.toSettings(settings);
|
||||
}
|
||||
}
|
||||
@@ -1251,12 +1186,6 @@ QString PerforcePlugin::fileNameFromPerforceName(const QString& perforceName,
|
||||
return rc;
|
||||
}
|
||||
|
||||
Core::ICore *PerforcePlugin::coreInstance()
|
||||
{
|
||||
QTC_ASSERT(m_coreInstance, return 0);
|
||||
return m_coreInstance;
|
||||
}
|
||||
|
||||
PerforcePlugin *PerforcePlugin::perforcePluginInstance()
|
||||
{
|
||||
QTC_ASSERT(m_perforcePluginInstance, return 0);
|
||||
|
||||
Reference in New Issue
Block a user