diff options
-rw-r--r-- | src/plugins/bazaar/bazaarplugin.cpp | 70 | ||||
-rw-r--r-- | src/plugins/clearcase/clearcaseplugin.cpp | 80 | ||||
-rw-r--r-- | src/plugins/cvs/cvsplugin.cpp | 124 | ||||
-rw-r--r-- | src/plugins/cvs/settingspage.cpp | 3 | ||||
-rw-r--r-- | src/plugins/cvs/settingspage.h | 2 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialplugin.cpp | 59 | ||||
-rw-r--r-- | src/plugins/perforce/perforceplugin.cpp | 113 | ||||
-rw-r--r-- | src/plugins/subversion/subversionplugin.cpp | 80 |
8 files changed, 301 insertions, 230 deletions
diff --git a/src/plugins/bazaar/bazaarplugin.cpp b/src/plugins/bazaar/bazaarplugin.cpp index d05fad97c92..763a3568e59 100644 --- a/src/plugins/bazaar/bazaarplugin.cpp +++ b/src/plugins/bazaar/bazaarplugin.cpp @@ -76,6 +76,7 @@ using namespace Core; using namespace Utils; using namespace VcsBase; +using namespace std::placeholders; namespace Bazaar { namespace Internal { @@ -109,24 +110,28 @@ const char COMMIT[] = "Bazaar.Action.Commit"; const char UNCOMMIT[] = "Bazaar.Action.UnCommit"; const char CREATE_REPOSITORY[] = "Bazaar.Action.CreateRepository"; -const VcsBaseEditorParameters editorParameters[] = { - { LogOutput, // type - Constants::FILELOG_ID, // id - Constants::FILELOG_DISPLAY_NAME, // display name - Constants::LOGAPP}, // mime type - - { AnnotateOutput, - Constants::ANNOTATELOG_ID, - Constants::ANNOTATELOG_DISPLAY_NAME, - Constants::ANNOTATEAPP}, - - { DiffOutput, - Constants::DIFFLOG_ID, - Constants::DIFFLOG_DISPLAY_NAME, - Constants::DIFFAPP} +const VcsBaseEditorParameters logEditorParameters { + LogOutput, // type + Constants::FILELOG_ID, // id + Constants::FILELOG_DISPLAY_NAME, // display name + Constants::LOGAPP // mime type }; -const VcsBaseSubmitEditorParameters submitEditorParameters = { +const VcsBaseEditorParameters annotateEditorParameters { + AnnotateOutput, + Constants::ANNOTATELOG_ID, + Constants::ANNOTATELOG_DISPLAY_NAME, + Constants::ANNOTATEAPP +}; + +const VcsBaseEditorParameters diffEditorParameters { + DiffOutput, + Constants::DIFFLOG_ID, + Constants::DIFFLOG_DISPLAY_NAME, + Constants::DIFFAPP +}; + +const VcsBaseSubmitEditorParameters submitEditorParameters { COMMITMIMETYPE, COMMIT_ID, COMMIT_DISPLAY_NAME, @@ -197,6 +202,8 @@ public: void createDirectoryActions(const Core::Context &context); void createRepositoryActions(const Core::Context &context); + void describe(const QString &source, const QString &id) { m_client.view(source, id); } + // Variables BazaarSettings m_settings; BazaarClient m_client{&m_settings}; @@ -226,6 +233,24 @@ public: QString m_submitRepository; bool m_submitActionTriggered = false; + + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [] { return new BazaarEditorWidget; }, + std::bind(&BazaarPluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory annotateEditorFactory { + &annotateEditorParameters, + [] { return new BazaarEditorWidget; }, + std::bind(&BazaarPluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory diffEditorFactory { + &diffEditorParameters, + [] { return new BazaarEditorWidget; }, + std::bind(&BazaarPluginPrivate::describe, this, _1, _2) + }; }; class UnCommitDialog : public QDialog @@ -294,15 +319,6 @@ BazaarPluginPrivate::BazaarPluginPrivate() connect(&m_client, &VcsBaseClient::changed, this, &BazaarPluginPrivate::changed); - const auto describeFunc = [this](const QString &source, const QString &id) { - m_client.view(source, id); - }; - - const int editorCount = sizeof(editorParameters) / sizeof(VcsBaseEditorParameters); - const auto widgetCreator = []() { return new BazaarEditorWidget; }; - for (int i = 0; i < editorCount; i++) - new VcsEditorFactory(editorParameters + i, widgetCreator, describeFunc, this); - const QString prefix = QLatin1String("bzr"); m_commandLocator = new CommandLocator("Bazaar", prefix, prefix, this); @@ -700,7 +716,7 @@ void BazaarPlugin::testDiffFileResolving_data() void BazaarPlugin::testDiffFileResolving() { - VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id); + VcsBaseEditorWidget::testDiffFileResolving(diffEditorParameters.id); } void BazaarPlugin::testLogResolving() @@ -723,7 +739,7 @@ void BazaarPlugin::testLogResolving() " (gz) Set approved revision and vote \"Approve\" when using lp-propose\n" " --approve (Jonathan Lange)\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "6572", "6571"); + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "6572", "6571"); } #endif diff --git a/src/plugins/clearcase/clearcaseplugin.cpp b/src/plugins/clearcase/clearcaseplugin.cpp index 59f221b9d5b..760dcfc02d3 100644 --- a/src/plugins/clearcase/clearcaseplugin.cpp +++ b/src/plugins/clearcase/clearcaseplugin.cpp @@ -102,6 +102,7 @@ using namespace Core; using namespace ProjectExplorer; using namespace VcsBase; using namespace Utils; +using namespace std::placeholders; namespace ClearCase { namespace Internal { @@ -132,37 +133,34 @@ public: QString message; }; -static const VcsBaseEditorParameters editorParameters[] = { -{ +const VcsBaseEditorParameters logEditorParameters { LogOutput, "ClearCase File Log Editor", // id QT_TRANSLATE_NOOP("VCS", "ClearCase File Log Editor"), // display_name - "text/vnd.qtcreator.clearcase.log"}, -{ AnnotateOutput, + "text/vnd.qtcreator.clearcase.log" +}; + +const VcsBaseEditorParameters annotateEditorParameters { + AnnotateOutput, "ClearCase Annotation Editor", // id QT_TRANSLATE_NOOP("VCS", "ClearCase Annotation Editor"), // display_name - "text/vnd.qtcreator.clearcase.annotation"}, -{ DiffOutput, + "text/vnd.qtcreator.clearcase.annotation" +}; + +const VcsBaseEditorParameters diffEditorParameters { + DiffOutput, "ClearCase Diff Editor", // id QT_TRANSLATE_NOOP("VCS", "ClearCase Diff Editor"), // display_name - "text/x-patch"} + "text/x-patch" }; -static const VcsBaseSubmitEditorParameters submitParameters = { +const VcsBaseSubmitEditorParameters submitParameters { Constants::CLEARCASE_SUBMIT_MIMETYPE, Constants::CLEARCASECHECKINEDITOR_ID, Constants::CLEARCASECHECKINEDITOR_DISPLAY_NAME, VcsBaseSubmitEditorParameters::DiffFiles }; -// Utility to find a parameter set by type -static const VcsBaseEditorParameters *findType(int ie) -{ - return VcsBaseEditor::findType(editorParameters, - sizeof(editorParameters)/sizeof(*editorParameters), - static_cast<EditorContentType>(ie)); -} - static QString debugCodec(const QTextCodec *c) { return c ? QString::fromLatin1(c->name()) : QString::fromLatin1("Null codec"); @@ -287,7 +285,7 @@ private: QString ccViewRoot(const QString &directory) const; QString findTopLevel(const QString &directory) const; Core::IEditor *showOutputInEditor(const QString& title, const QString &output, - int editorType, const QString &source, + Id id, const QString &source, QTextCodec *codec) const; QString runCleartoolSync(const QString &workingDir, const QStringList &arguments) const; ClearCaseResponse runCleartool(const QString &workingDir, const QStringList &arguments, @@ -358,6 +356,24 @@ private: this }; + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [] { return new ClearCaseEditorWidget; }, + std::bind(&ClearCasePluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory annotateEditorFactory { + &annotateEditorParameters, + [] { return new ClearCaseEditorWidget; }, + std::bind(&ClearCasePluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory diffEditorFactory { + &diffEditorParameters, + [] { return new ClearCaseEditorWidget; }, + std::bind(&ClearCasePluginPrivate::describe, this, _1, _2) + }; + friend class ClearCasePlugin; #ifdef WITH_TESTS bool m_fakeClearTool = false; @@ -637,15 +653,6 @@ ClearCasePluginPrivate::ClearCasePluginPrivate() connect(SessionManager::instance(), &SessionManager::startupProjectChanged, this, &ClearCasePluginPrivate::projectChanged); - // any editor responds to describe (when clicking a version) - const auto describeFunc = [this](const QString &source, const QString &changeNr) { - describe(source, changeNr); - }; - const int editorCount = sizeof(editorParameters)/sizeof(VcsBaseEditorParameters); - const auto widgetCreator = []() { return new ClearCaseEditorWidget; }; - for (int i = 0; i < editorCount; i++) - new VcsEditorFactory(editorParameters + i, widgetCreator, describeFunc, this); - const QString description = QLatin1String("ClearCase"); const QString prefix = QLatin1String("cc"); // register cc prefix in Locator @@ -1224,7 +1231,7 @@ void ClearCasePluginPrivate::ccDiffWithPred(const QString &workingDir, const QSt diffname = QDir::toNativeSeparators(files.first()); } const QString title = QString::fromLatin1("cc diff %1").arg(diffname); - IEditor *editor = showOutputInEditor(title, result, DiffOutput, source, codec); + IEditor *editor = showOutputInEditor(title, result, diffEditorParameters.id, source, codec); setWorkingDirectory(editor, workingDir); VcsBaseEditor::tagEditor(editor, tag); auto diffEditorWidget = qobject_cast<ClearCaseEditorWidget *>(editor->widget()); @@ -1320,7 +1327,7 @@ void ClearCasePluginPrivate::diffActivity() } m_diffPrefix.clear(); const QString title = QString::fromLatin1("%1.patch").arg(activity); - IEditor *editor = showOutputInEditor(title, result, DiffOutput, activity, nullptr); + IEditor *editor = showOutputInEditor(title, result, diffEditorParameters.id, activity, nullptr); setWorkingDirectory(editor, topLevel); } @@ -1483,7 +1490,7 @@ void ClearCasePluginPrivate::history(const QString &workingDir, } else { const QString title = QString::fromLatin1("cc history %1").arg(id); const QString source = VcsBaseEditor::getSource(workingDir, files); - IEditor *newEditor = showOutputInEditor(title, response.stdOut, LogOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, response.stdOut, logEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); if (enableAnnotationContextMenu) VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true); @@ -1588,7 +1595,7 @@ void ClearCasePluginPrivate::vcsAnnotateHelper(const QString &workingDir, const EditorManager::activateEditor(editor); } else { const QString title = QString::fromLatin1("cc annotate %1").arg(id); - IEditor *newEditor = showOutputInEditor(title, res, AnnotateOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, res, annotateEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); } @@ -1623,7 +1630,7 @@ void ClearCasePluginPrivate::describe(const QString &source, const QString &chan EditorManager::activateEditor(editor); } else { const QString title = QString::fromLatin1("cc describe %1").arg(id); - IEditor *newEditor = showOutputInEditor(title, description, DiffOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, description, diffEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); } } @@ -1671,15 +1678,12 @@ ClearCasePluginPrivate::runCleartool(const QString &workingDir, } IEditor *ClearCasePluginPrivate::showOutputInEditor(const QString& title, const QString &output, - int editorType, const QString &source, + Core::Id id, const QString &source, QTextCodec *codec) const { - const VcsBaseEditorParameters *params = findType(editorType); - QTC_ASSERT(params, return nullptr); - const Id id = params->id; if (Constants::debug) qDebug() << "ClearCasePlugin::showOutputInEditor" << title << id.name() - << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec); + << "Size= " << output.size() << debugCodec(codec); QString s = title; IEditor *editor = EditorManager::openEditorWithContents(id, &s, output.toUtf8()); auto e = qobject_cast<ClearCaseEditorWidget*>(editor->widget()); @@ -2574,7 +2578,7 @@ void ClearCasePlugin::testDiffFileResolving_data() void ClearCasePlugin::testDiffFileResolving() { - VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id); + VcsBaseEditorWidget::testDiffFileResolving(diffEditorParameters.id); } void ClearCasePlugin::testLogResolving() @@ -2583,7 +2587,7 @@ void ClearCasePlugin::testLogResolving() "13-Sep.17:41 user1 create version \"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/9\" (baseline1, baseline2, ...)\n" "22-Aug.14:13 user2 create version \"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/8\" (baseline3, baseline4, ...)\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/9", "src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/8"); } diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp index 2cefbb371b7..a39a4c5d951 100644 --- a/src/plugins/cvs/cvsplugin.cpp +++ b/src/plugins/cvs/cvsplugin.cpp @@ -80,6 +80,7 @@ using namespace Core; using namespace VcsBase; using namespace Utils; +using namespace std::placeholders; namespace Cvs { namespace Internal { @@ -125,34 +126,41 @@ public: QString message; }; -const VcsBaseEditorParameters editorParameters[] = { -{ +const VcsBaseSubmitEditorParameters submitParameters { + CVS_SUBMIT_MIMETYPE, + CVSCOMMITEDITOR_ID, + CVSCOMMITEDITOR_DISPLAY_NAME, + VcsBaseSubmitEditorParameters::DiffFiles +}; + +const VcsBaseEditorParameters commandLogEditorParameters { OtherContent, "CVS Command Log Editor", // id QT_TRANSLATE_NOOP("VCS", "CVS Command Log Editor"), // display name - "text/vnd.qtcreator.cvs.commandlog"}, -{ LogOutput, + "text/vnd.qtcreator.cvs.commandlog" +}; + +const VcsBaseEditorParameters logEditorParameters { + LogOutput, "CVS File Log Editor", // id QT_TRANSLATE_NOOP("VCS", "CVS File Log Editor"), // display name - "text/vnd.qtcreator.cvs.log"}, -{ AnnotateOutput, + "text/vnd.qtcreator.cvs.log" +}; + +const VcsBaseEditorParameters annotateEditorParameters { + AnnotateOutput, "CVS Annotation Editor", // id QT_TRANSLATE_NOOP("VCS", "CVS Annotation Editor"), // display name - "text/vnd.qtcreator.cvs.annotation"}, -{ DiffOutput, + "text/vnd.qtcreator.cvs.annotation" +}; + +const VcsBaseEditorParameters diffEditorParameters { + DiffOutput, "CVS Diff Editor", // id QT_TRANSLATE_NOOP("VCS", "CVS Diff Editor"), // display name - "text/x-patch"} + "text/x-patch" }; -// Utility to find a parameter set by type -static inline const VcsBaseEditorParameters *findType(int ie) -{ - return VcsBaseEditor::findType(editorParameters, - sizeof(editorParameters) / sizeof(*editorParameters), - static_cast<EditorContentType>(ie)); -} - static inline bool messageBoxQuestion(const QString &title, const QString &question) { return QMessageBox::question(ICore::dialogParent(), title, question, QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes; @@ -297,7 +305,7 @@ private: bool isCommitEditorOpen() const; Core::IEditor *showOutputInEditor(const QString& title, const QString &output, - int editorType, const QString &source, + Core::Id id, const QString &source, QTextCodec *codec); CvsResponse runCvs(const QString &workingDirectory, @@ -311,6 +319,7 @@ private: bool describe(const QString &source, const QString &changeNr, QString *errorMessage); bool describe(const QString &toplevel, const QString &source, const QString &changeNr, QString *errorMessage); bool describe(const QString &repository, QList<CvsLogEntry> entries, QString *errorMessage); + void describeHelper(const QString &source, const QString &changeNr); void filelog(const QString &workingDir, const QString &file = QString(), bool enableAnnotationContextMenu = false); @@ -358,9 +367,39 @@ private: QAction *m_menuAction = nullptr; bool m_submitActionTriggered = false; -}; + CvsSettingsPage m_settingsPage{[this] { configurationChanged(); }, &m_settings}; + + VcsSubmitEditorFactory submitEditorFactory { + submitParameters, + [] { return new CvsSubmitEditor; }, + this + }; + + VcsEditorFactory commandLogEditorFactory { + &commandLogEditorParameters, + [] { return new CvsEditorWidget; }, + std::bind(&CvsPluginPrivate::describeHelper, this, _1, _2) + }; + + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [] { return new CvsEditorWidget; }, + std::bind(&CvsPluginPrivate::describeHelper, this, _1, _2) + }; + + VcsEditorFactory annotateEditorFactory { + &annotateEditorParameters, + [] { return new CvsEditorWidget; }, + std::bind(&CvsPluginPrivate::describeHelper, this, _1, _2) + }; + VcsEditorFactory diffEditorFactory { + &diffEditorParameters, + [] { return new CvsEditorWidget; }, + std::bind(&CvsPluginPrivate::describeHelper, this, _1, _2) + }; +}; Core::Id CvsPluginPrivate::id() const { @@ -481,13 +520,6 @@ bool CvsPluginPrivate::isCommitEditorOpen() const return !m_commitMessageFileName.isEmpty(); } -static const VcsBaseSubmitEditorParameters submitParameters = { - CVS_SUBMIT_MIMETYPE, - CVSCOMMITEDITOR_ID, - CVSCOMMITEDITOR_DISPLAY_NAME, - VcsBaseSubmitEditorParameters::DiffFiles -}; - CvsPlugin::~CvsPlugin() { delete dd; @@ -516,20 +548,6 @@ CvsPluginPrivate::CvsPluginPrivate() Context context(CVS_CONTEXT); m_client = new CvsClient(&m_settings); - new CvsSettingsPage([this] { configurationChanged(); }, &m_settings, this); - - new VcsSubmitEditorFactory(submitParameters, [] { return new CvsSubmitEditor; }, this, this); - - const auto describeFunc = [this](const QString &source, const QString &changeNr) { - QString errorMessage; - if (!describe(source, changeNr, &errorMessage)) - VcsOutputWindow::appendError(errorMessage); - }; - const int editorCount = sizeof(editorParameters) / sizeof(editorParameters[0]); - const auto widgetCreator = []() { return new CvsEditorWidget; }; - for (int i = 0; i < editorCount; i++) - new VcsEditorFactory(editorParameters + i, widgetCreator, describeFunc, this); - const QString prefix = QLatin1String("cvs"); m_commandLocator = new CommandLocator("CVS", prefix, prefix, this); @@ -723,6 +741,13 @@ CvsPluginPrivate::CvsPluginPrivate() m_commandLocator->appendCommand(command); } +void CvsPluginPrivate::describeHelper(const QString &source, const QString &changeNr) +{ + QString errorMessage; + if (!describe(source, changeNr, &errorMessage)) + VcsOutputWindow::appendError(errorMessage); +}; + bool CvsPluginPrivate::submitEditorAboutToClose() { if (!isCommitEditorOpen()) @@ -1050,7 +1075,7 @@ void CvsPluginPrivate::filelog(const QString &workingDir, EditorManager::activateEditor(editor); } else { const QString title = QString::fromLatin1("cvs log %1").arg(id); - IEditor *newEditor = showOutputInEditor(title, response.stdOut, LogOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, response.stdOut, logEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); if (enableAnnotationContextMenu) VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true); @@ -1201,7 +1226,7 @@ void CvsPluginPrivate::annotate(const QString &workingDir, const QString &file, EditorManager::activateEditor(editor); } else { const QString title = QString::fromLatin1("cvs annotate %1").arg(id); - IEditor *newEditor = showOutputInEditor(title, response.stdOut, AnnotateOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, response.stdOut, annotateEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); } @@ -1216,7 +1241,7 @@ bool CvsPluginPrivate::status(const QString &topLevel, const QString &file, cons runCvs(topLevel, args, m_settings.vcsTimeoutS(), 0); const bool ok = response.result == CvsResponse::Ok; if (ok) - showOutputInEditor(title, response.stdOut, OtherContent, topLevel, nullptr); + showOutputInEditor(title, response.stdOut, commandLogEditorParameters.id, topLevel, nullptr); return ok; } @@ -1390,7 +1415,7 @@ bool CvsPluginPrivate::describe(const QString &repositoryPath, setDiffBaseDirectory(editor, repositoryPath); } else { const QString title = QString::fromLatin1("cvs describe %1").arg(commitId); - IEditor *newEditor = showOutputInEditor(title, output, DiffOutput, entries.front().file, codec); + IEditor *newEditor = showOutputInEditor(title, output, diffEditorParameters.id, entries.front().file, codec); VcsBaseEditor::tagEditor(newEditor, commitId); setDiffBaseDirectory(newEditor, repositoryPath); } @@ -1447,12 +1472,9 @@ CvsResponse CvsPluginPrivate::runCvs(const QString &workingDirectory, } IEditor *CvsPluginPrivate::showOutputInEditor(const QString& title, const QString &output, - int editorType, const QString &source, - QTextCodec *codec) + Core::Id id, const QString &source, + QTextCodec *codec) { - const VcsBaseEditorParameters *params = findType(editorType); - QTC_ASSERT(params, return nullptr); - const Id id = params->id; QString s = title; IEditor *editor = EditorManager::openEditorWithContents(id, &s, output.toUtf8()); auto e = qobject_cast<CvsEditorWidget*>(editor->widget()); @@ -1554,7 +1576,7 @@ void CvsPlugin::testDiffFileResolving_data() void CvsPlugin::testDiffFileResolving() { - VcsBaseEditorWidget::testDiffFileResolving(editorParameters[3].id); + VcsBaseEditorWidget::testDiffFileResolving(diffEditorParameters.id); } void CvsPlugin::testLogResolving() @@ -1580,7 +1602,7 @@ void CvsPlugin::testLogResolving() "added latest commentary\n" "----------------------------\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[1].id, data, "1.3", "1.2"); + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "1.3", "1.2"); } #endif diff --git a/src/plugins/cvs/settingspage.cpp b/src/plugins/cvs/settingspage.cpp index dc1bac27316..8aae51fa590 100644 --- a/src/plugins/cvs/settingspage.cpp +++ b/src/plugins/cvs/settingspage.cpp @@ -89,8 +89,7 @@ void CvsSettingsPageWidget::apply() m_onApply(); } -CvsSettingsPage::CvsSettingsPage(const std::function<void()> &onApply, CvsSettings *settings, QObject *parent) : - Core::IOptionsPage( parent) +CvsSettingsPage::CvsSettingsPage(const std::function<void()> &onApply, CvsSettings *settings) { setId(VcsBase::Constants::VCS_ID_CVS); setDisplayName(CvsSettingsPageWidget::tr("CVS")); diff --git a/src/plugins/cvs/settingspage.h b/src/plugins/cvs/settingspage.h index 8a817b52c2b..8e64ec7841d 100644 --- a/src/plugins/cvs/settingspage.h +++ b/src/plugins/cvs/settingspage.h @@ -35,7 +35,7 @@ class CvsSettings; class CvsSettingsPage final : public Core::IOptionsPage { public: - CvsSettingsPage(const std::function<void()> &onApply, CvsSettings *settings, QObject *parent); + CvsSettingsPage(const std::function<void()> &onApply, CvsSettings *settings); }; } // namespace Cvs diff --git a/src/plugins/mercurial/mercurialplugin.cpp b/src/plugins/mercurial/mercurialplugin.cpp index a6efdd7e6f3..c48a2c21565 100644 --- a/src/plugins/mercurial/mercurialplugin.cpp +++ b/src/plugins/mercurial/mercurialplugin.cpp @@ -71,6 +71,7 @@ using namespace VcsBase; using namespace Utils; +using namespace std::placeholders; namespace Mercurial { namespace Internal { @@ -95,25 +96,28 @@ private: MercurialClient *m_client; }; -static const VcsBaseEditorParameters editorParameters[] = { -{ +const VcsBaseEditorParameters logEditorParameters { LogOutput, Constants::FILELOG_ID, Constants::FILELOG_DISPLAY_NAME, - Constants::LOGAPP}, + Constants::LOGAPP +}; -{ AnnotateOutput, +const VcsBaseEditorParameters annotateEditorParameters { + AnnotateOutput, Constants::ANNOTATELOG_ID, Constants::ANNOTATELOG_DISPLAY_NAME, - Constants::ANNOTATEAPP}, + Constants::ANNOTATEAPP +}; -{ DiffOutput, +const VcsBaseEditorParameters diffEditorParameters { + DiffOutput, Constants::DIFFLOG_ID, Constants::DIFFLOG_DISPLAY_NAME, - Constants::DIFFAPP} + Constants::DIFFAPP }; -static const VcsBaseSubmitEditorParameters submitEditorParameters = { +const VcsBaseSubmitEditorParameters submitEditorParameters { Constants::COMMITMIMETYPE, Constants::COMMIT_ID, Constants::COMMIT_DISPLAY_NAME, @@ -190,6 +194,8 @@ private: void createDirectoryActions(const Core::Context &context); void createRepositoryActions(const Core::Context &context); + void describe(const QString &source, const QString &id) { m_client.view(source, id); } + // Variables MercurialSettings m_settings; MercurialClient m_client{&m_settings}; @@ -216,6 +222,30 @@ private: QString m_submitRepository; bool m_submitActionTriggered = false; + + VcsSubmitEditorFactory submitEditorFactory { + submitEditorParameters, + [] { return new CommitEditor; }, + this + }; + + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [this] { return new MercurialEditorWidget(&m_client); }, + std::bind(&MercurialPluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory annotateEditorFactory { + &annotateEditorParameters, + [this] { return new MercurialEditorWidget(&m_client); }, + std::bind(&MercurialPluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory diffEditorFactory { + &diffEditorParameters, + [this] { return new MercurialEditorWidget(&m_client); }, + std::bind(&MercurialPluginPrivate::describe, this, _1, _2) + }; }; static MercurialPluginPrivate *dd = nullptr; @@ -249,15 +279,6 @@ MercurialPluginPrivate::MercurialPluginPrivate() connect(&m_client, &VcsBaseClient::changed, this, &MercurialPluginPrivate::changed); connect(&m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update); - const auto describeFunc = [this](const QString &source, const QString &id) { - m_client.view(source, id); - }; - const auto widgetCreator = [this] { return new MercurialEditorWidget(&m_client); }; - for (auto &editor : editorParameters) - new VcsEditorFactory(&editor, widgetCreator, describeFunc, this); - - new VcsSubmitEditorFactory(submitEditorParameters, [] { return new CommitEditor; }, this, this); - const QString prefix = QLatin1String("hg"); m_commandLocator = new Core::CommandLocator("Mercurial", prefix, prefix, this); @@ -881,7 +902,7 @@ void MercurialPlugin::testDiffFileResolving_data() void MercurialPlugin::testDiffFileResolving() { - VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id); + VcsBaseEditorWidget::testDiffFileResolving(diffEditorParameters.id); } void MercurialPlugin::testLogResolving() @@ -901,7 +922,7 @@ void MercurialPlugin::testLogResolving() "date: Sat Jan 19 04:08:16 2013 +0100\n" "summary: test-rebase: add another test for rebase with multiple roots\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "18473:692cbda1eb50", "18472:37100f30590f"); + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "18473:692cbda1eb50", "18472:37100f30590f"); } #endif diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 4f641107637..082788f9cab 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -73,6 +73,7 @@ using namespace Core; using namespace Utils; using namespace VcsBase; +using namespace std::placeholders; namespace Perforce { namespace Internal { @@ -92,30 +93,6 @@ const char PERFORCE_DIFF_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Perfo const char PERFORCE_ANNOTATION_EDITOR_ID[] = "Perforce.AnnotationEditor"; const char PERFORCE_ANNOTATION_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Perforce Annotation Editor"); -const VcsBaseEditorParameters editorParameters[] = { -{ - LogOutput, - PERFORCE_LOG_EDITOR_ID, - PERFORCE_LOG_EDITOR_DISPLAY_NAME, - "text/vnd.qtcreator.p4.log"}, -{ AnnotateOutput, - PERFORCE_ANNOTATION_EDITOR_ID, - PERFORCE_ANNOTATION_EDITOR_DISPLAY_NAME, - "text/vnd.qtcreator.p4.annotation"}, -{ DiffOutput, - PERFORCE_DIFF_EDITOR_ID, - PERFORCE_DIFF_EDITOR_DISPLAY_NAME, - "text/x-patch"} -}; - -// Utility to find a parameter set by type -static inline const VcsBaseEditorParameters *findType(int ie) -{ - return VcsBaseEditor::findType(editorParameters, - sizeof(editorParameters)/sizeof(*editorParameters), - static_cast<EditorContentType>(ie)); -} - // Ensure adding "..." to relative paths which is p4's convention // for the current directory static inline QString perforceRelativeFileArguments(const QString &args) @@ -172,13 +149,34 @@ struct PerforceResponse QString message; }; -static const VcsBaseSubmitEditorParameters submitParameters = { +const VcsBaseSubmitEditorParameters submitEditorParameters { SUBMIT_MIMETYPE, PERFORCE_SUBMIT_EDITOR_ID, PERFORCE_SUBMIT_EDITOR_DISPLAY_NAME, VcsBaseSubmitEditorParameters::DiffFiles }; +const VcsBaseEditorParameters logEditorParameters { + LogOutput, + PERFORCE_LOG_EDITOR_ID, + PERFORCE_LOG_EDITOR_DISPLAY_NAME, + "text/vnd.qtcreator.p4.log" +}; + +const VcsBaseEditorParameters annotateEditorParameters { + AnnotateOutput, + PERFORCE_ANNOTATION_EDITOR_ID, + PERFORCE_ANNOTATION_EDITOR_DISPLAY_NAME, + "text/vnd.qtcreator.p4.annotation" +}; + +const VcsBaseEditorParameters diffEditorParameters { + DiffOutput, + PERFORCE_DIFF_EDITOR_ID, + PERFORCE_DIFF_EDITOR_DISPLAY_NAME, + "text/x-patch" +}; + // Flags for runP4Cmd. enum RunFlags { @@ -292,8 +290,8 @@ public: typedef QHash<QString, DirectoryCacheEntry> ManagedDirectoryCache; IEditor *showOutputInEditor(const QString &title, const QString &output, - int editorType, const QString &source, - QTextCodec *codec = nullptr); + Id id, const QString &source, + QTextCodec *codec = nullptr); // args are passed as command line arguments // extra args via a tempfile and the option -x "temp-filename" @@ -367,6 +365,30 @@ public: SettingsPage m_settingsPage{&m_settings, [this] { applySettings(); }}; ManagedDirectoryCache m_managedDirectoryCache; + + VcsSubmitEditorFactory submitEditorFactory { + submitEditorParameters, + [] { return new PerforceSubmitEditor; }, + this + }; + + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [] { return new PerforceEditorWidget; }, + std::bind(&PerforcePluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory annotateEditorFactory { + &annotateEditorParameters, + [] { return new PerforceEditorWidget; }, + std::bind(&PerforcePluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory diffEditorFactory { + &diffEditorParameters, + [] { return new PerforceEditorWidget; }, + std::bind(&PerforcePluginPrivate::describe, this, _1, _2) + }; }; static PerforcePluginPrivate *dd = nullptr; @@ -380,17 +402,6 @@ PerforcePluginPrivate::PerforcePluginPrivate() m_settings.fromSettings(ICore::settings()); - // Editor factories - new VcsSubmitEditorFactory(submitParameters, [] { return new PerforceSubmitEditor; }, this, this); - - const auto describeFunc = [this](const QString &source, const QString &n) { - describe(source, n); - }; - const int editorCount = sizeof(editorParameters) / sizeof(editorParameters[0]); - const auto widgetCreator = []() { return new PerforceEditorWidget; }; - for (int i = 0; i < editorCount; i++) - new VcsEditorFactory(editorParameters + i, widgetCreator, describeFunc, this); - const QString prefix = QLatin1String("p4"); m_commandLocator = new CommandLocator("Perforce", prefix, prefix, this); @@ -864,7 +875,7 @@ void PerforcePluginPrivate::annotate(const QString &workingDir, if (lineNumber < 1) lineNumber = VcsBaseEditor::lineNumberOfCurrentEditor(); IEditor *ed = showOutputInEditor(tr("p4 annotate %1").arg(id), - result.stdOut, AnnotateOutput, + result.stdOut, annotateEditorParameters.id, source, codec); VcsBaseEditor::gotoLineOfEditor(ed, lineNumber); } @@ -917,7 +928,7 @@ void PerforcePluginPrivate::filelog(const QString &workingDir, const QString &fi if (!result.error) { const QString source = VcsBaseEditor::getSource(workingDir, fileName); IEditor *editor = showOutputInEditor(tr("p4 filelog %1").arg(id), result.stdOut, - LogOutput, source, codec); + logEditorParameters.id, source, codec); if (enableAnnotationContextMenu) VcsBaseEditor::getVcsBaseEditor(editor)->setFileLogAnnotateEnabled(true); } @@ -939,7 +950,7 @@ void PerforcePluginPrivate::changelists(const QString &workingDir, const QString if (!result.error) { const QString source = VcsBaseEditor::getSource(workingDir, fileName); IEditor *editor = showOutputInEditor(tr("p4 changelists %1").arg(id), result.stdOut, - LogOutput, source, codec); + logEditorParameters.id, source, codec); VcsBaseEditor::gotoLineOfEditor(editor, 1); } } @@ -1417,14 +1428,11 @@ PerforceResponse PerforcePluginPrivate::runP4Cmd(const QString &workingDir, } IEditor *PerforcePluginPrivate::showOutputInEditor(const QString &title, - const QString &output, - int editorType, - const QString &source, - QTextCodec *codec) -{ - const VcsBaseEditorParameters *params = findType(editorType); - QTC_ASSERT(params, return nullptr); - const Id id = params->id; + const QString &output, + Core::Id id, + const QString &source, + QTextCodec *codec) +{ QString s = title; QString content = output; const int maxSize = int(EditorManager::maxTextFileSize() / 2 - 1000L); // ~25 MB, 600000 lines @@ -1526,7 +1534,8 @@ void PerforcePluginPrivate::p4Diff(const PerforceDiffParameters &p) return; } // Create new editor - IEditor *editor = showOutputInEditor(tr("p4 diff %1").arg(id), result.stdOut, DiffOutput, + IEditor *editor = showOutputInEditor(tr("p4 diff %1").arg(id), result.stdOut, + diffEditorParameters.id, VcsBaseEditor::getSource(p.workingDir, p.files), codec); VcsBaseEditor::tagEditor(editor, tag); @@ -1550,7 +1559,7 @@ void PerforcePluginPrivate::describe(const QString & source, const QString &n) const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args, CommandToWindow|StdErrToWindow|ErrorToWindow, QStringList(), QByteArray(), codec); if (!result.error) - showOutputInEditor(tr("p4 describe %1").arg(n), result.stdOut, DiffOutput, source, codec); + showOutputInEditor(tr("p4 describe %1").arg(n), result.stdOut, diffEditorParameters.id, source, codec); } void PerforcePluginPrivate::commitFromEditor() @@ -1775,7 +1784,7 @@ void PerforcePlugin::testLogResolving() "\n" " Comment\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "12345", "12344"); + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "12345", "12344"); } #endif diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index eeebf960ee1..f6b28f51e96 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -84,6 +84,7 @@ using namespace Core; using namespace Utils; using namespace VcsBase; +using namespace std::placeholders; namespace Subversion { namespace Internal { @@ -117,25 +118,26 @@ struct SubversionResponse QString message; }; -const VcsBaseEditorParameters editorParameters[] = { -{ +const VcsBaseSubmitEditorParameters submitParameters { + Constants::SUBVERSION_SUBMIT_MIMETYPE, + Constants::SUBVERSION_COMMIT_EDITOR_ID, + Constants::SUBVERSION_COMMIT_EDITOR_DISPLAY_NAME, + VcsBaseSubmitEditorParameters::DiffFiles +}; + +const VcsBaseEditorParameters logEditorParameters { LogOutput, Constants::SUBVERSION_LOG_EDITOR_ID, Constants::SUBVERSION_LOG_EDITOR_DISPLAY_NAME, - Constants::SUBVERSION_LOG_MIMETYPE}, -{ AnnotateOutput, - Constants::SUBVERSION_BLAME_EDITOR_ID, - Constants::SUBVERSION_BLAME_EDITOR_DISPLAY_NAME, - Constants::SUBVERSION_BLAME_MIMETYPE} + Constants::SUBVERSION_LOG_MIMETYPE }; -// Utility to find a parameter set by type -static const VcsBaseEditorParameters *findType(int ie) -{ - return VcsBaseEditor::findType(editorParameters, - sizeof(editorParameters)/sizeof(*editorParameters), - static_cast<EditorContentType>(ie)); -} +const VcsBaseEditorParameters blameEditorParameters { + AnnotateOutput, + Constants::SUBVERSION_BLAME_EDITOR_ID, + Constants::SUBVERSION_BLAME_EDITOR_DISPLAY_NAME, + Constants::SUBVERSION_BLAME_MIMETYPE +}; static inline QString debugCodec(const QTextCodec *c) { @@ -279,7 +281,7 @@ private: inline bool isCommitEditorOpen() const; Core::IEditor *showOutputInEditor(const QString &title, const QString &output, - int editorType, const QString &source, + Core::Id id, const QString &source, QTextCodec *codec); void filelog(const QString &workingDir, @@ -322,6 +324,24 @@ private: bool m_submitActionTriggered = false; SubversionSettingsPage m_settingsPage{[this] { configurationChanged(); }, &m_settings}; + + VcsSubmitEditorFactory submitEditorFactory { + submitParameters, + [] { return new SubversionSubmitEditor; }, + this + }; + + VcsEditorFactory logEditorFactory { + &logEditorParameters, + [] { return new SubversionEditorWidget; }, + std::bind(&SubversionPluginPrivate::describe, this, _1, _2) + }; + + VcsEditorFactory blameEditorFactory { + &blameEditorParameters, + [] { return new SubversionEditorWidget; }, + std::bind(&SubversionPluginPrivate::describe, this, _1, _2) + }; }; @@ -355,13 +375,6 @@ bool SubversionPluginPrivate::isCommitEditorOpen() const return !m_commitMessageFileName.isEmpty(); } -const VcsBaseSubmitEditorParameters submitParameters = { - Constants::SUBVERSION_SUBMIT_MIMETYPE, - Constants::SUBVERSION_COMMIT_EDITOR_ID, - Constants::SUBVERSION_COMMIT_EDITOR_DISPLAY_NAME, - VcsBaseSubmitEditorParameters::DiffFiles -}; - bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage) { Q_UNUSED(errorMessage) @@ -388,16 +401,6 @@ SubversionPluginPrivate::SubversionPluginPrivate() using namespace Core::Constants; Context context(SUBVERSION_CONTEXT); - new VcsSubmitEditorFactory(submitParameters, [] { return new SubversionSubmitEditor; }, this, this); - - const auto describeFunc = [this](const QString &source, const QString &id) { - describe(source, id); - }; - const int editorCount = sizeof(editorParameters) / sizeof(editorParameters[0]); - const auto widgetCreator = []() { return new SubversionEditorWidget; }; - for (int i = 0; i < editorCount; i++) - new VcsEditorFactory(editorParameters + i, widgetCreator, describeFunc, this); - const QString prefix = QLatin1String("svn"); m_commandLocator = new CommandLocator("Subversion", prefix, prefix, this); @@ -950,7 +953,7 @@ void SubversionPluginPrivate::vcsAnnotateHelper(const QString &workingDir, const EditorManager::activateEditor(editor); } else { const QString title = QString::fromLatin1("svn annotate %1").arg(id); - IEditor *newEditor = showOutputInEditor(title, response.stdOut, AnnotateOutput, source, codec); + IEditor *newEditor = showOutputInEditor(title, response.stdOut, blameEditorParameters.id, source, codec); VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); } @@ -1035,15 +1038,12 @@ SubversionResponse SubversionPluginPrivate::runSvn(const QString &workingDir, } IEditor *SubversionPluginPrivate::showOutputInEditor(const QString &title, const QString &output, - int editorType, const QString &source, + Id id, const QString &source, QTextCodec *codec) { - const VcsBaseEditorParameters *params = findType(editorType); - QTC_ASSERT(params, return nullptr); - const Id id = params->id; if (Subversion::Constants::debug) - qDebug() << "SubversionPlugin::showOutputInEditor" << title << id.name() - << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec); + qDebug() << "SubversionPlugin::showOutputInEditor" << title << id.toString() + << "Size= " << output.size() << " Type=" << id << debugCodec(codec); QString s = title; IEditor *editor = EditorManager::openEditorWithContents(id, &s, output.toUtf8()); auto e = qobject_cast<SubversionEditorWidget*>(editor->widget()); @@ -1329,7 +1329,7 @@ void SubversionPlugin::testLogResolving() " expectations, remove XFail.\n" "\n" ); - VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "r1439551", "r1439540"); + VcsBaseEditorWidget::testLogResolving(logEditorParameters.id, data, "r1439551", "r1439540"); } #endif |