From bcf0335b900b215757b12afb58f604b79ce17640 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 7 Aug 2024 12:28:21 +0200 Subject: [PATCH] GitClient: Make styleColorName() a public function To reuse it in other Git source files. Change-Id: I3303a7f2b70a0e8b6752ef9933eb381795031a07 Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 54 +++++++++++++++++------------------ src/plugins/git/gitclient.h | 4 +++ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 4a2b56a8c27..3e4796b81b2 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -103,17 +103,6 @@ static QString branchesDisplay(const QString &prefix, QStringList *branches, boo return output; } -static QString logColorName(TextEditor::TextStyle style) -{ - using namespace TextEditor; - - const ColorScheme &scheme = TextEditorSettings::fontSettings().colorScheme(); - QColor color = scheme.formatFor(style).foreground(); - if (!color.isValid()) - color = scheme.formatFor(C_TEXT).foreground(); - return color.name(); -}; - /////////////////////////////// static void stage(DiffEditorController *diffController, const QString &patch, bool revert) @@ -365,7 +354,7 @@ ShowController::ShowController(IDocument *document, const QString &id) setDisplayName("Git Show"); setAnsiEnabled(true); static const QString busyMessage = Tr::tr(""); - const QColor color = QColor::fromString(logColorName(TextEditor::C_LOG_DECORATION)); + const QColor color = QColor::fromString(GitClient::styleColorName(TextEditor::C_LOG_DECORATION)); const QString decorateColor = AnsiEscapeCodeHandler::ansiFromColor(color); const QString noColor = AnsiEscapeCodeHandler::noColor(); @@ -401,11 +390,11 @@ ShowController::ShowController(IDocument *document, const QString &id) const auto onDescriptionSetup = [this, id](Process &process) { process.setCodec(gitClient().encoding(GitClient::EncodingCommit, workingDirectory())); - const QString authorName = logColorName(TextEditor::C_LOG_AUTHOR_NAME); - const QString commitDate = logColorName(TextEditor::C_LOG_COMMIT_DATE); - const QString commitHash = logColorName(TextEditor::C_LOG_COMMIT_HASH); - const QString commitSubject = logColorName(TextEditor::C_LOG_COMMIT_SUBJECT); - const QString decoration = logColorName(TextEditor::C_LOG_DECORATION); + const QString authorName = GitClient::styleColorName(TextEditor::C_LOG_AUTHOR_NAME); + const QString commitDate = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_DATE); + const QString commitHash = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_HASH); + const QString commitSubject = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_SUBJECT); + const QString decoration = GitClient::styleColorName(TextEditor::C_LOG_DECORATION); const QString showFormat = QStringLiteral( "--pretty=format:" @@ -699,11 +688,11 @@ public: QStringList graphArguments() const { - const QString authorName = logColorName(TextEditor::C_LOG_AUTHOR_NAME); - const QString commitDate = logColorName(TextEditor::C_LOG_COMMIT_DATE); - const QString commitHash = logColorName(TextEditor::C_LOG_COMMIT_HASH); - const QString commitSubject = logColorName(TextEditor::C_LOG_COMMIT_SUBJECT); - const QString decoration = logColorName(TextEditor::C_LOG_DECORATION); + const QString authorName = GitClient::styleColorName(TextEditor::C_LOG_AUTHOR_NAME); + const QString commitDate = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_DATE); + const QString commitHash = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_HASH); + const QString commitSubject = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_SUBJECT); + const QString decoration = GitClient::styleColorName(TextEditor::C_LOG_DECORATION); const QString formatArg = QStringLiteral( "--pretty=format:" @@ -1035,11 +1024,11 @@ static QStringList normalLogArguments() if (!gitHasRgbColors()) return {}; - const QString authorName = logColorName(TextEditor::C_LOG_AUTHOR_NAME); - const QString commitDate = logColorName(TextEditor::C_LOG_COMMIT_DATE); - const QString commitHash = logColorName(TextEditor::C_LOG_COMMIT_HASH); - const QString commitSubject = logColorName(TextEditor::C_LOG_COMMIT_SUBJECT); - const QString decoration = logColorName(TextEditor::C_LOG_DECORATION); + const QString authorName = GitClient::styleColorName(TextEditor::C_LOG_AUTHOR_NAME); + const QString commitDate = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_DATE); + const QString commitHash = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_HASH); + const QString commitSubject = GitClient::styleColorName(TextEditor::C_LOG_COMMIT_SUBJECT); + const QString decoration = GitClient::styleColorName(TextEditor::C_LOG_DECORATION); const QString logArgs = QStringLiteral( "--pretty=format:" @@ -3472,6 +3461,17 @@ void GitClient::readConfigAsync(const FilePath &workingDirectory, const QStringL configFileCodec()); } +QString GitClient::styleColorName(TextEditor::TextStyle style) +{ + using namespace TextEditor; + + const ColorScheme &scheme = TextEditorSettings::fontSettings().colorScheme(); + QColor color = scheme.formatFor(style).foreground(); + if (!color.isValid()) + color = scheme.formatFor(C_TEXT).foreground(); + return color.name(); +} + static QVersionNumber parseGitVersion(const QString &output) { // cut 'git version 1.6.5.1.sha' diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index ff915feb53f..b08e45da63e 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -340,6 +342,8 @@ public: void readConfigAsync(const Utils::FilePath &workingDirectory, const QStringList &arguments, const VcsBase::CommandHandler &handler) const; + static QString styleColorName(TextEditor::TextStyle style); + private: static GitSettings &settings();