VCS: Simplify VcsEditor setup

Create the editor parameter structures in-place, and also
include the other two parameters in the struct to simplify
the signature of the c'tor.

Change-Id: Iff7d5ddf3096f4a3ed18e53265ae74806823af32
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2024-02-07 10:33:46 +01:00
parent be33c807a6
commit 2d37a7421f
10 changed files with 198 additions and 302 deletions

View File

@@ -89,27 +89,6 @@ const char COMMIT[] = "Bazaar.Action.Commit";
const char UNCOMMIT[] = "Bazaar.Action.UnCommit"; const char UNCOMMIT[] = "Bazaar.Action.UnCommit";
const char CREATE_REPOSITORY[] = "Bazaar.Action.CreateRepository"; const char CREATE_REPOSITORY[] = "Bazaar.Action.CreateRepository";
const VcsBaseEditorParameters logEditorParameters {
LogOutput, // type
Constants::FILELOG_ID, // id
Constants::FILELOG_DISPLAY_NAME, // display name
Constants::LOGAPP // mime type
};
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
};
class RevertDialog : public QDialog class RevertDialog : public QDialog
{ {
public: public:
@@ -220,23 +199,32 @@ public:
FilePath m_submitRepository; FilePath m_submitRepository;
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput, // type
Constants::FILELOG_ID, // id
Constants::FILELOG_DISPLAY_NAME, // display name
Constants::LOGAPP,// mime type
[] { return new BazaarEditorWidget; }, [] { return new BazaarEditorWidget; },
std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateEditorFactory { VcsEditorFactory annotateEditorFactory {{
&annotateEditorParameters, AnnotateOutput,
Constants::ANNOTATELOG_ID,
Constants::ANNOTATELOG_DISPLAY_NAME,
Constants::ANNOTATEAPP,
[] { return new BazaarEditorWidget; }, [] { return new BazaarEditorWidget; },
std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffEditorFactory { VcsEditorFactory diffEditorFactory {{
&diffEditorParameters, DiffOutput,
Constants::DIFFLOG_ID,
Constants::DIFFLOG_DISPLAY_NAME,
Constants::DIFFAPP,
[] { return new BazaarEditorWidget; }, [] { return new BazaarEditorWidget; },
std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&BazaarPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
class UnCommitDialog : public QDialog class UnCommitDialog : public QDialog

View File

@@ -99,26 +99,9 @@ const char CMD_ID_UPDATE_VIEW[] = "ClearCase.UpdateView";
const char CMD_ID_CHECKIN_ALL[] = "ClearCase.CheckInAll"; const char CMD_ID_CHECKIN_ALL[] = "ClearCase.CheckInAll";
const char CMD_ID_STATUS[] = "ClearCase.Status"; const char CMD_ID_STATUS[] = "ClearCase.Status";
const VcsBaseEditorParameters logEditorParameters { const char LOG_EDITOR_ID[] = "ClearCase File Log Editor";
LogOutput, const char ANNOTATION_EDITOR_ID[] = "ClearCase Annotation Editor";
"ClearCase File Log Editor", // id const char DIFF_EDITOR_ID[] = "ClearCase Diff Editor";
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase File Log Editor"), // display_name
"text/vnd.qtcreator.clearcase.log"
};
const VcsBaseEditorParameters annotateEditorParameters {
AnnotateOutput,
"ClearCase Annotation Editor", // id
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase Annotation Editor"), // display_name
"text/vnd.qtcreator.clearcase.annotation"
};
const VcsBaseEditorParameters diffEditorParameters {
DiffOutput,
"ClearCase Diff Editor", // id
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase Diff Editor"), // display_name
"text/x-patch"
};
static QString debugCodec(const QTextCodec *c) static QString debugCodec(const QTextCodec *c)
{ {
@@ -311,23 +294,32 @@ public:
ClearCaseSettingsPage m_settingsPage; ClearCaseSettingsPage m_settingsPage;
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
LOG_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase File Log Editor"), // display_name
"text/vnd.qtcreator.clearcase.log",
[] { return new ClearCaseEditorWidget; }, [] { return new ClearCaseEditorWidget; },
std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateEditorFactory { VcsEditorFactory annotateEditorFactory {{
&annotateEditorParameters, AnnotateOutput,
ANNOTATION_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase Annotation Editor"), // display_name
"text/vnd.qtcreator.clearcase.annotation",
[] { return new ClearCaseEditorWidget; }, [] { return new ClearCaseEditorWidget; },
std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffEditorFactory { VcsEditorFactory diffEditorFactory {{
&diffEditorParameters, DiffOutput,
DIFF_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "ClearCase Diff Editor"), // display_name
"text/x-patch",
[] { return new ClearCaseEditorWidget; }, [] { return new ClearCaseEditorWidget; },
std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&ClearCasePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
#ifdef WITH_TESTS #ifdef WITH_TESTS
bool m_fakeClearTool = false; bool m_fakeClearTool = false;
@@ -1218,7 +1210,7 @@ void ClearCasePluginPrivate::ccDiffWithPred(const FilePath &workingDir, const QS
diffname = QDir::toNativeSeparators(files.first()); diffname = QDir::toNativeSeparators(files.first());
} }
const QString title = QString::fromLatin1("cc diff %1").arg(diffname); const QString title = QString::fromLatin1("cc diff %1").arg(diffname);
IEditor *editor = showOutputInEditor(title, result, diffEditorParameters.id, source, codec); IEditor *editor = showOutputInEditor(title, result, DIFF_EDITOR_ID, source, codec);
setWorkingDirectory(editor, workingDir); setWorkingDirectory(editor, workingDir);
VcsBaseEditor::tagEditor(editor, tag); VcsBaseEditor::tagEditor(editor, tag);
auto diffEditorWidget = qobject_cast<ClearCaseEditorWidget *>(editor->widget()); auto diffEditorWidget = qobject_cast<ClearCaseEditorWidget *>(editor->widget());
@@ -1299,7 +1291,7 @@ void ClearCasePluginPrivate::diffActivity()
} }
m_diffPrefix.clear(); m_diffPrefix.clear();
const QString title = QString::fromLatin1("%1.patch").arg(activity); const QString title = QString::fromLatin1("%1.patch").arg(activity);
IEditor *editor = showOutputInEditor(title, result, diffEditorParameters.id, IEditor *editor = showOutputInEditor(title, result, DIFF_EDITOR_ID,
FilePath::fromString(activity), nullptr); FilePath::fromString(activity), nullptr);
setWorkingDirectory(editor, topLevel); setWorkingDirectory(editor, topLevel);
} }
@@ -1461,7 +1453,7 @@ void ClearCasePluginPrivate::history(const FilePath &workingDir,
const QString title = QString::fromLatin1("cc history %1").arg(id); const QString title = QString::fromLatin1("cc history %1").arg(id);
const FilePath source = VcsBaseEditor::getSource(workingDir, files); const FilePath source = VcsBaseEditor::getSource(workingDir, files);
IEditor *newEditor = showOutputInEditor(title, result.cleanedStdOut(), IEditor *newEditor = showOutputInEditor(title, result.cleanedStdOut(),
logEditorParameters.id, source, codec); LOG_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
if (enableAnnotationContextMenu) if (enableAnnotationContextMenu)
VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true); VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
@@ -1564,7 +1556,7 @@ void ClearCasePluginPrivate::vcsAnnotateHelper(const FilePath &workingDir, const
EditorManager::activateEditor(editor); EditorManager::activateEditor(editor);
} else { } else {
const QString title = QString::fromLatin1("cc annotate %1").arg(id); const QString title = QString::fromLatin1("cc annotate %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, res, annotateEditorParameters.id, source, codec); IEditor *newEditor = showOutputInEditor(title, res, ANNOTATION_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
} }
@@ -1598,7 +1590,7 @@ void ClearCasePluginPrivate::vcsDescribe(const FilePath &source, const QString &
EditorManager::activateEditor(editor); EditorManager::activateEditor(editor);
} else { } else {
const QString title = QString::fromLatin1("cc describe %1").arg(id); const QString title = QString::fromLatin1("cc describe %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, description, diffEditorParameters.id, source, codec); IEditor *newEditor = showOutputInEditor(title, description, DIFF_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
} }
} }

View File

@@ -90,33 +90,10 @@ const char CVS_SUBMIT_MIMETYPE[] = "text/vnd.qtcreator.cvs.submit";
const char CVSCOMMITEDITOR_ID[] = "CVS Commit Editor"; const char CVSCOMMITEDITOR_ID[] = "CVS Commit Editor";
const char CVSCOMMITEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Commit Editor"); const char CVSCOMMITEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Commit Editor");
const VcsBaseEditorParameters commandLogEditorParameters { const char CVS_COMMANDLOG_EDITOR_ID[] = "CVS Command Log Editor";
OtherContent, const char CVS_FILELOG_EDITOR_ID[] = "CVS File Log Editor";
"CVS Command Log Editor", // id const char CVS_ANNOTATION_EDITOR_ID[] = "CVS Annotation Editor";
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Command Log Editor"), // display name const char CVS_DIFF_EDITOR_ID[] = "CVS Diff Editor";
"text/vnd.qtcreator.cvs.commandlog"
};
const VcsBaseEditorParameters logEditorParameters {
LogOutput,
"CVS File Log Editor", // id
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS File Log Editor"), // display name
"text/vnd.qtcreator.cvs.log"
};
const VcsBaseEditorParameters annotateEditorParameters {
AnnotateOutput,
"CVS Annotation Editor", // id
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Annotation Editor"), // display name
"text/vnd.qtcreator.cvs.annotation"
};
const VcsBaseEditorParameters diffEditorParameters {
DiffOutput,
"CVS Diff Editor", // id
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Diff Editor"), // display name
"text/x-patch"
};
static inline bool messageBoxQuestion(const QString &title, const QString &question) static inline bool messageBoxQuestion(const QString &title, const QString &question)
{ {
@@ -312,29 +289,41 @@ private:
QAction *m_menuAction = nullptr; QAction *m_menuAction = nullptr;
public: public:
VcsEditorFactory commandLogEditorFactory { VcsEditorFactory commandLogEditorFactory {{
&commandLogEditorParameters, OtherContent,
CVS_COMMANDLOG_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Command Log Editor"), // display name
"text/vnd.qtcreator.cvs.commandlog",
[] { return new CvsEditorWidget; }, [] { return new CvsEditorWidget; },
std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
CVS_FILELOG_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS File Log Editor"), // display name
"text/vnd.qtcreator.cvs.log",
[] { return new CvsEditorWidget; }, [] { return new CvsEditorWidget; },
std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateEditorFactory { VcsEditorFactory annotateEditorFactory {{
&annotateEditorParameters, AnnotateOutput,
CVS_ANNOTATION_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Annotation Editor"), // display name
"text/vnd.qtcreator.cvs.annotation",
[] { return new CvsEditorWidget; }, [] { return new CvsEditorWidget; },
std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffEditorFactory { VcsEditorFactory diffEditorFactory {{
&diffEditorParameters, DiffOutput,
CVS_DIFF_EDITOR_ID,
QT_TRANSLATE_NOOP("QtC::VcsBase", "CVS Diff Editor"), // display name
"text/x-patch",
[] { return new CvsEditorWidget; }, [] { return new CvsEditorWidget; },
std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&CvsPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
Utils::Id CvsPluginPrivate::id() const Utils::Id CvsPluginPrivate::id() const
@@ -965,7 +954,7 @@ void CvsPluginPrivate::filelog(const FilePath &workingDir,
} else { } else {
const QString title = QString::fromLatin1("cvs log %1").arg(id); const QString title = QString::fromLatin1("cvs log %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(), IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(),
logEditorParameters.id, source, codec); CVS_FILELOG_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
if (enableAnnotationContextMenu) if (enableAnnotationContextMenu)
VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true); VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
@@ -1105,7 +1094,7 @@ void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file,
} else { } else {
const QString title = QString::fromLatin1("cvs annotate %1").arg(id); const QString title = QString::fromLatin1("cvs annotate %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(), IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(),
annotateEditorParameters.id, source, codec); CVS_ANNOTATION_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
} }
@@ -1119,7 +1108,7 @@ bool CvsPluginPrivate::status(const FilePath &topLevel, const QString &file, con
const auto response = runCvs(topLevel, args); const auto response = runCvs(topLevel, args);
const bool ok = response.result() == ProcessResult::FinishedWithSuccess; const bool ok = response.result() == ProcessResult::FinishedWithSuccess;
if (ok) { if (ok) {
showOutputInEditor(title, response.cleanedStdOut(), commandLogEditorParameters.id, showOutputInEditor(title, response.cleanedStdOut(), CVS_COMMANDLOG_EDITOR_ID,
topLevel, nullptr); topLevel, nullptr);
} }
return ok; return ok;
@@ -1284,7 +1273,7 @@ bool CvsPluginPrivate::describe(const FilePath &repositoryPath,
setDiffBaseDirectory(editor, repositoryPath); setDiffBaseDirectory(editor, repositoryPath);
} else { } else {
const QString title = QString::fromLatin1("cvs describe %1").arg(commitId); const QString title = QString::fromLatin1("cvs describe %1").arg(commitId);
IEditor *newEditor = showOutputInEditor(title, output, diffEditorParameters.id, IEditor *newEditor = showOutputInEditor(title, output, CVS_DIFF_EDITOR_ID,
FilePath::fromString(entries.front().file), codec); FilePath::fromString(entries.front().file), codec);
VcsBaseEditor::tagEditor(newEditor, commitId); VcsBaseEditor::tagEditor(newEditor, commitId);
setDiffBaseDirectory(newEditor, repositoryPath); setDiffBaseDirectory(newEditor, repositoryPath);

View File

@@ -77,28 +77,6 @@ protected:
} }
}; };
const VcsBaseEditorParameters fileLogParameters {
LogOutput,
Constants::FILELOG_ID,
Constants::FILELOG_DISPLAY_NAME,
Constants::LOGAPP
};
const VcsBaseEditorParameters annotateLogParameters {
AnnotateOutput,
Constants::ANNOTATELOG_ID,
Constants::ANNOTATELOG_DISPLAY_NAME,
Constants::ANNOTATEAPP
};
const VcsBaseEditorParameters diffParameters {
DiffOutput,
Constants::DIFFLOG_ID,
Constants::DIFFLOG_DISPLAY_NAME,
Constants::DIFFAPP
};
class FossilPluginPrivate final : public VersionControlBase class FossilPluginPrivate final : public VersionControlBase
{ {
public: public:
@@ -171,23 +149,32 @@ public:
bool pullOrPush(SyncMode mode); bool pullOrPush(SyncMode mode);
// Variables // Variables
VcsEditorFactory fileLogFactory { VcsEditorFactory fileLogFactory {{
&fileLogParameters, LogOutput,
Constants::FILELOG_ID,
Constants::FILELOG_DISPLAY_NAME,
Constants::LOGAPP,
[] { return new FossilEditorWidget; }, [] { return new FossilEditorWidget; },
std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateLogFactory { VcsEditorFactory annotateLogFactory {{
&annotateLogParameters, AnnotateOutput,
Constants::ANNOTATELOG_ID,
Constants::ANNOTATELOG_DISPLAY_NAME,
Constants::ANNOTATEAPP,
[] { return new FossilEditorWidget; }, [] { return new FossilEditorWidget; },
std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffFactory { VcsEditorFactory diffFactory {{
&diffParameters, DiffOutput,
Constants::DIFFLOG_ID,
Constants::DIFFLOG_DISPLAY_NAME,
Constants::DIFFAPP,
[] { return new FossilEditorWidget; }, [] { return new FossilEditorWidget; },
std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&FossilPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
CommandLocator *m_commandLocator = nullptr; CommandLocator *m_commandLocator = nullptr;
ActionContainer *m_fossilContainer = nullptr; ActionContainer *m_fossilContainer = nullptr;

View File

@@ -132,48 +132,6 @@ public:
static const QVersionNumber minimumRequiredVersion{1, 9}; static const QVersionNumber minimumRequiredVersion{1, 9};
const VcsBaseEditorParameters svnLogEditorParameters {
OtherContent,
Git::Constants::GIT_SVN_LOG_EDITOR_ID,
Git::Constants::GIT_SVN_LOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.svnlog"
};
const VcsBaseEditorParameters logEditorParameters {
LogOutput,
Git::Constants::GIT_LOG_EDITOR_ID,
Git::Constants::GIT_LOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.log"
};
const VcsBaseEditorParameters reflogEditorParameters {
LogOutput,
Git::Constants::GIT_REFLOG_EDITOR_ID,
Git::Constants::GIT_REFLOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.reflog"
};
const VcsBaseEditorParameters blameEditorParameters {
AnnotateOutput,
Git::Constants::GIT_BLAME_EDITOR_ID,
Git::Constants::GIT_BLAME_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.annotation"
};
const VcsBaseEditorParameters commitTextEditorParameters {
OtherContent,
Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID,
Git::Constants::GIT_COMMIT_TEXT_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.commit"
};
const VcsBaseEditorParameters rebaseEditorParameters {
OtherContent,
Git::Constants::GIT_REBASE_EDITOR_ID,
Git::Constants::GIT_REBASE_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.rebase"
};
// GitPlugin // GitPlugin
class GitPluginPrivate final : public VersionControlBase class GitPluginPrivate final : public VersionControlBase
@@ -366,41 +324,59 @@ public:
GitGrep gitGrep; GitGrep gitGrep;
VcsEditorFactory svnLogEditorFactory { VcsEditorFactory svnLogEditorFactory {{
&svnLogEditorParameters, OtherContent,
Git::Constants::GIT_SVN_LOG_EDITOR_ID,
Git::Constants::GIT_SVN_LOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.svnlog",
[] { return new GitEditorWidget; }, [] { return new GitEditorWidget; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
Git::Constants::GIT_LOG_EDITOR_ID,
Git::Constants::GIT_LOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.log",
[] { return new GitLogEditorWidgetT<GitEditorWidget>; }, [] { return new GitLogEditorWidgetT<GitEditorWidget>; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory reflogEditorFactory { VcsEditorFactory reflogEditorFactory {{
&reflogEditorParameters, LogOutput,
[] { return new GitLogEditorWidgetT<GitReflogEditorWidget>; }, Git::Constants::GIT_REFLOG_EDITOR_ID,
Git::Constants::GIT_REFLOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.reflog",
[] { return new GitLogEditorWidgetT<GitReflogEditorWidget>; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory blameEditorFactory { VcsEditorFactory blameEditorFactory {{
&blameEditorParameters, AnnotateOutput,
Git::Constants::GIT_BLAME_EDITOR_ID,
Git::Constants::GIT_BLAME_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.annotation",
[] { return new GitEditorWidget; }, [] { return new GitEditorWidget; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory commitTextEditorFactory { VcsEditorFactory commitTextEditorFactory {{
&commitTextEditorParameters, OtherContent,
Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID,
Git::Constants::GIT_COMMIT_TEXT_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.commit",
[] { return new GitEditorWidget; }, [] { return new GitEditorWidget; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory rebaseEditorFactory { VcsEditorFactory rebaseEditorFactory {{
&rebaseEditorParameters, OtherContent,
Git::Constants::GIT_REBASE_EDITOR_ID,
Git::Constants::GIT_REBASE_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.git.rebase",
[] { return new GitEditorWidget; }, [] { return new GitEditorWidget; },
std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&GitPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
static GitPluginPrivate *dd = nullptr; static GitPluginPrivate *dd = nullptr;

View File

@@ -67,27 +67,6 @@ protected:
} }
}; };
const VcsBaseEditorParameters logEditorParameters {
LogOutput,
Constants::FILELOG_ID,
Constants::FILELOG_DISPLAY_NAME,
Constants::LOGAPP
};
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
};
class MercurialPluginPrivate final : public VcsBase::VersionControlBase class MercurialPluginPrivate final : public VcsBase::VersionControlBase
{ {
public: public:
@@ -180,23 +159,32 @@ private:
FilePath m_submitRepository; FilePath m_submitRepository;
public: public:
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
Constants::FILELOG_ID,
Constants::FILELOG_DISPLAY_NAME,
Constants::LOGAPP,
[this] { return new MercurialEditorWidget; }, [this] { return new MercurialEditorWidget; },
std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateEditorFactory { VcsEditorFactory annotateEditorFactory {{
&annotateEditorParameters, AnnotateOutput,
Constants::ANNOTATELOG_ID,
Constants::ANNOTATELOG_DISPLAY_NAME,
Constants::ANNOTATEAPP,
[this] { return new MercurialEditorWidget; }, [this] { return new MercurialEditorWidget; },
std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffEditorFactory { VcsEditorFactory diffEditorFactory {{
&diffEditorParameters, DiffOutput,
Constants::DIFFLOG_ID,
Constants::DIFFLOG_DISPLAY_NAME,
Constants::DIFFAPP,
[this] { return new MercurialEditorWidget; }, [this] { return new MercurialEditorWidget; },
std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
static MercurialPluginPrivate *dd = nullptr; static MercurialPluginPrivate *dd = nullptr;

View File

@@ -128,27 +128,6 @@ struct PerforceResponse
QString stdErr; QString stdErr;
}; };
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. // Flags for runP4Cmd.
enum RunFlags enum RunFlags
{ {
@@ -324,23 +303,32 @@ public:
ManagedDirectoryCache m_managedDirectoryCache; ManagedDirectoryCache m_managedDirectoryCache;
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
PERFORCE_LOG_EDITOR_ID,
PERFORCE_LOG_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.p4.log",
[] { return new PerforceEditorWidget; }, [] { return new PerforceEditorWidget; },
std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory annotateEditorFactory { VcsEditorFactory annotateEditorFactory {{
&annotateEditorParameters, AnnotateOutput,
PERFORCE_ANNOTATION_EDITOR_ID,
PERFORCE_ANNOTATION_EDITOR_DISPLAY_NAME,
"text/vnd.qtcreator.p4.annotation",
[] { return new PerforceEditorWidget; }, [] { return new PerforceEditorWidget; },
std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory diffEditorFactory { VcsEditorFactory diffEditorFactory {{
&diffEditorParameters, DiffOutput,
PERFORCE_DIFF_EDITOR_ID,
PERFORCE_DIFF_EDITOR_DISPLAY_NAME,
"text/x-patch",
[] { return new PerforceEditorWidget; }, [] { return new PerforceEditorWidget; },
std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2) std::bind(&PerforcePluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
static PerforcePluginPrivate *dd = nullptr; static PerforcePluginPrivate *dd = nullptr;
@@ -827,7 +815,7 @@ void PerforcePluginPrivate::annotate(const FilePath &workingDir,
if (lineNumber < 1) if (lineNumber < 1)
lineNumber = VcsBaseEditor::lineNumberOfCurrentEditor(); lineNumber = VcsBaseEditor::lineNumberOfCurrentEditor();
IEditor *ed = showOutputInEditor(Tr::tr("p4 annotate %1").arg(id), IEditor *ed = showOutputInEditor(Tr::tr("p4 annotate %1").arg(id),
result.stdOut, annotateEditorParameters.id, result.stdOut, PERFORCE_ANNOTATION_EDITOR_ID,
source, codec); source, codec);
VcsBaseEditor::gotoLineOfEditor(ed, lineNumber); VcsBaseEditor::gotoLineOfEditor(ed, lineNumber);
} }
@@ -878,7 +866,7 @@ void PerforcePluginPrivate::filelog(const FilePath &workingDir, const QString &f
if (!result.error) { if (!result.error) {
const FilePath source = VcsBaseEditor::getSource(workingDir, fileName); const FilePath source = VcsBaseEditor::getSource(workingDir, fileName);
IEditor *editor = showOutputInEditor(Tr::tr("p4 filelog %1").arg(id), result.stdOut, IEditor *editor = showOutputInEditor(Tr::tr("p4 filelog %1").arg(id), result.stdOut,
logEditorParameters.id, source, codec); PERFORCE_LOG_EDITOR_ID, source, codec);
if (enableAnnotationContextMenu) if (enableAnnotationContextMenu)
VcsBaseEditor::getVcsBaseEditor(editor)->setFileLogAnnotateEnabled(true); VcsBaseEditor::getVcsBaseEditor(editor)->setFileLogAnnotateEnabled(true);
} }
@@ -900,7 +888,7 @@ void PerforcePluginPrivate::changelists(const FilePath &workingDir, const QStrin
if (!result.error) { if (!result.error) {
const FilePath source = VcsBaseEditor::getSource(workingDir, fileName); const FilePath source = VcsBaseEditor::getSource(workingDir, fileName);
IEditor *editor = showOutputInEditor(Tr::tr("p4 changelists %1").arg(id), result.stdOut, IEditor *editor = showOutputInEditor(Tr::tr("p4 changelists %1").arg(id), result.stdOut,
logEditorParameters.id, source, codec); PERFORCE_LOG_EDITOR_ID, source, codec);
VcsBaseEditor::gotoLineOfEditor(editor, 1); VcsBaseEditor::gotoLineOfEditor(editor, 1);
} }
} }
@@ -1376,7 +1364,7 @@ void PerforcePluginPrivate::p4Diff(const PerforceDiffParameters &p)
} }
// Create new editor // Create new editor
IEditor *editor = showOutputInEditor(Tr::tr("p4 diff %1").arg(id), result.stdOut, IEditor *editor = showOutputInEditor(Tr::tr("p4 diff %1").arg(id), result.stdOut,
diffEditorParameters.id, PERFORCE_DIFF_EDITOR_ID,
VcsBaseEditor::getSource(p.workingDir, p.files), VcsBaseEditor::getSource(p.workingDir, p.files),
codec); codec);
VcsBaseEditor::tagEditor(editor, tag); VcsBaseEditor::tagEditor(editor, tag);
@@ -1400,7 +1388,7 @@ void PerforcePluginPrivate::vcsDescribe(const FilePath &source, const QString &n
const PerforceResponse result = runP4Cmd(settings().topLevel(), args, CommandToWindow|StdErrToWindow|ErrorToWindow, const PerforceResponse result = runP4Cmd(settings().topLevel(), args, CommandToWindow|StdErrToWindow|ErrorToWindow,
{}, {}, codec); {}, {}, codec);
if (!result.error) if (!result.error)
showOutputInEditor(Tr::tr("p4 describe %1").arg(n), result.stdOut, diffEditorParameters.id, source, codec); showOutputInEditor(Tr::tr("p4 describe %1").arg(n), result.stdOut, PERFORCE_DIFF_EDITOR_ID, source, codec);
} }
void PerforcePluginPrivate::cleanCommitMessageFile() void PerforcePluginPrivate::cleanCommitMessageFile()

View File

@@ -85,20 +85,6 @@ const char CMD_ID_UPDATE[] = "Subversion.Update";
const char CMD_ID_COMMIT_PROJECT[] = "Subversion.CommitProject"; const char CMD_ID_COMMIT_PROJECT[] = "Subversion.CommitProject";
const char CMD_ID_DESCRIBE[] = "Subversion.Describe"; const char CMD_ID_DESCRIBE[] = "Subversion.Describe";
const VcsBaseEditorParameters logEditorParameters {
LogOutput,
Constants::SUBVERSION_LOG_EDITOR_ID,
Constants::SUBVERSION_LOG_EDITOR_DISPLAY_NAME,
Constants::SUBVERSION_LOG_MIMETYPE
};
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) static inline QString debugCodec(const QTextCodec *c)
{ {
return c ? QString::fromLatin1(c->name()) : QString::fromLatin1("Null codec"); return c ? QString::fromLatin1(c->name()) : QString::fromLatin1("Null codec");
@@ -276,17 +262,23 @@ private:
QAction *m_menuAction = nullptr; QAction *m_menuAction = nullptr;
public: public:
VcsEditorFactory logEditorFactory { VcsEditorFactory logEditorFactory {{
&logEditorParameters, LogOutput,
Constants::SUBVERSION_LOG_EDITOR_ID,
Constants::SUBVERSION_LOG_EDITOR_DISPLAY_NAME,
Constants::SUBVERSION_LOG_MIMETYPE,
[] { return new SubversionEditorWidget; }, [] { return new SubversionEditorWidget; },
std::bind(&SubversionPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&SubversionPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
VcsEditorFactory blameEditorFactory { VcsEditorFactory blameEditorFactory {{
&blameEditorParameters, AnnotateOutput,
Constants::SUBVERSION_BLAME_EDITOR_ID,
Constants::SUBVERSION_BLAME_EDITOR_DISPLAY_NAME,
Constants::SUBVERSION_BLAME_MIMETYPE,
[] { return new SubversionEditorWidget; }, [] { return new SubversionEditorWidget; },
std::bind(&SubversionPluginPrivate::vcsDescribe, this, _1, _2) std::bind(&SubversionPluginPrivate::vcsDescribe, this, _1, _2)
}; }};
}; };
@@ -853,7 +845,7 @@ void SubversionPluginPrivate::vcsAnnotateHelper(const FilePath &workingDir, cons
} else { } else {
const QString title = QString::fromLatin1("svn annotate %1").arg(id); const QString title = QString::fromLatin1("svn annotate %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(), IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(),
blameEditorParameters.id, source, codec); Constants::SUBVERSION_BLAME_EDITOR_ID, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
} }

View File

@@ -1653,30 +1653,27 @@ IEditor *VcsBaseEditor::locateEditorByTag(const QString &tag)
\sa VcsBase::VcsBaseEditorWidget \sa VcsBase::VcsBaseEditorWidget
*/ */
VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters, VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters &parameters)
// Force copy, see QTCREATORBUG-13218
const EditorWidgetCreator editorWidgetCreator,
std::function<void (const Utils::FilePath &, const QString &)> describeFunc)
{ {
setId(parameters->id); setId(parameters.id);
setDisplayName(Tr::tr(parameters->displayName)); setDisplayName(Tr::tr(parameters.displayName));
if (QLatin1String(parameters->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE)) if (QLatin1String(parameters.mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
addMimeType(QLatin1String(parameters->mimeType)); addMimeType(QLatin1String(parameters.mimeType));
setEditorActionHandlers(TextEditorActionHandler::None); setEditorActionHandlers(TextEditorActionHandler::None);
setDuplicatedSupported(false); setDuplicatedSupported(false);
setDocumentCreator([parameters] { setDocumentCreator([parameters] {
auto document = new TextDocument(parameters->id); auto document = new TextDocument(parameters.id);
document->setMimeType(QLatin1String(parameters->mimeType)); document->setMimeType(QLatin1String(parameters.mimeType));
document->setSuspendAllowed(false); document->setSuspendAllowed(false);
return document; return document;
}); });
setEditorWidgetCreator([parameters=*parameters, editorWidgetCreator, describeFunc] { setEditorWidgetCreator([parameters] {
auto widget = editorWidgetCreator(); auto widget = parameters.editorWidgetCreator();
auto editorWidget = Aggregation::query<VcsBaseEditorWidget>(widget); auto editorWidget = Aggregation::query<VcsBaseEditorWidget>(widget);
editorWidget->setDescribeFunc(describeFunc); editorWidget->setDescribeFunc(parameters.describeFunc);
editorWidget->setParameters(parameters); editorWidget->setParameters(parameters);
return widget; return widget;
}); });

View File

@@ -45,6 +45,8 @@ public:
const char *id; const char *id;
const char *displayName; const char *displayName;
const char *mimeType; const char *mimeType;
std::function<QWidget *()> editorWidgetCreator;
std::function<void (const Utils::FilePath &, const QString &)> describeFunc;
}; };
class VCSBASE_EXPORT DiffChunk class VCSBASE_EXPORT DiffChunk
@@ -289,10 +291,7 @@ public:
class VCSBASE_EXPORT VcsEditorFactory : public TextEditor::TextEditorFactory class VCSBASE_EXPORT VcsEditorFactory : public TextEditor::TextEditorFactory
{ {
public: public:
VcsEditorFactory(const VcsBaseEditorParameters *parameters, explicit VcsEditorFactory(const VcsBaseEditorParameters &parameters);
const EditorWidgetCreator editorWidgetCreator,
std::function<void(const Utils::FilePath &, const QString &)> describeFunc);
~VcsEditorFactory(); ~VcsEditorFactory();
}; };