From 7fd6f3d7199d5cca0d21de28fc5aae2e71c2f3e4 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 3 Sep 2025 13:32:41 +0200 Subject: [PATCH] Options for commit hash display --- gitfourchette/graphview/commitlogdelegate.py | 36 +++++++++++++------- gitfourchette/settings.py | 7 ++++ gitfourchette/trtables.py | 9 ++++- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/gitfourchette/graphview/commitlogdelegate.py b/gitfourchette/graphview/commitlogdelegate.py index eda845f2..0950c337 100644 --- a/gitfourchette/graphview/commitlogdelegate.py +++ b/gitfourchette/graphview/commitlogdelegate.py @@ -17,6 +17,7 @@ from gitfourchette.porcelain import * from gitfourchette.qt import * from gitfourchette.repomodel import UC_FAKEID, UC_FAKEREF, RepoModel +from gitfourchette.settings import CommitHashDisplay from gitfourchette.toolbox import * @@ -155,10 +156,16 @@ def _paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelI dateWidth = 0 elif rect.width() <= NARROW_WIDTH[1]: authorWidth = int(lerp(authorWidth/2, authorWidth, rect.width(), NARROW_WIDTH[0], NARROW_WIDTH[1])) - leftBoundHash = rect.left() - leftBoundSummary = leftBoundHash + hcw * settings.prefs.shortHashChars + XSPACING + + hashLeft = settings.prefs.commitHashDisplay == CommitHashDisplay.Left + hashRight = settings.prefs.commitHashDisplay == CommitHashDisplay.Right + hashWidth = hcw * settings.prefs.shortHashChars + XSPACING * (3 if hashRight else 1) + hashMonospace = hashLeft + + leftBoundSummary = rect.left() + (hashWidth if hashLeft else 0) leftBoundDate = rect.width() - dateWidth - leftBoundName = leftBoundDate - authorWidth + leftBoundName = leftBoundDate - authorWidth - (hashWidth if hashRight else 0) + leftBoundHash = rect.left() if hashLeft else leftBoundDate - hashWidth rightBound = rect.right() # Get the info we need about the commit @@ -190,7 +197,7 @@ def _paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelI else: commit = None oid = None - hashText = "·" * settings.prefs.shortHashChars + hashText = "·" * settings.prefs.shortHashChars if hashLeft else "" authorText = "" dateText = "" searchTerm = "" @@ -230,14 +237,19 @@ def highlight(fullText: str, needlePos: int, needleLen: int): SearchBar.highlightNeedle(painter, rect, fullText, needlePos, needleLen) # ------ Hash - charRect = QRect(leftBoundHash, rect.top(), hcw, rect.height()) - painter.save() - if not isSelected: # use muted color for hash if not selected - painter.setPen(palette.color(colorGroup, QPalette.ColorRole.PlaceholderText)) - for hashChar in hashText: - painter.drawText(charRect, Qt.AlignmentFlag.AlignCenter, hashChar) - charRect.translate(hcw, 0) - painter.restore() + if hashLeft or hashRight: + width = hcw if hashMonospace else hashWidth + charRect = QRect(leftBoundHash, rect.top(), width, rect.height()) + painter.save() + if not isSelected: # use muted color for hash if not selected + painter.setPen(palette.color(colorGroup, QPalette.ColorRole.PlaceholderText)) + if hashMonospace: + for hashChar in hashText: + painter.drawText(charRect, Qt.AlignmentFlag.AlignCenter, hashChar) + charRect.translate(hcw, 0) + else: + painter.drawText(charRect, Qt.AlignmentFlag.AlignVCenter, hashText) + painter.restore() # ------ Highlight searched hash if searchTerm and searchTermLooksLikeHash and commit and str(commit).startswith(searchTerm): diff --git a/gitfourchette/settings.py b/gitfourchette/settings.py index bc66f3a5..0afafbf3 100644 --- a/gitfourchette/settings.py +++ b/gitfourchette/settings.py @@ -50,6 +50,12 @@ class GraphRowHeight(enum.IntEnum): Spacious = 175 +class CommitHashDisplay(enum.IntEnum): + Left = 0 + Right = 1 + Hide = 2 + + class GraphRefBoxWidth(enum.IntEnum): IconsOnly = 0 Standard = 120 @@ -103,6 +109,7 @@ class Prefs(PrefsFile): graphRowHeight : GraphRowHeight = GraphRowHeight.Relaxed refBoxMaxWidth : GraphRefBoxWidth = GraphRefBoxWidth.Standard authorDisplayStyle : AuthorDisplayStyle = AuthorDisplayStyle.FullName + commitHashDisplay : CommitHashDisplay = CommitHashDisplay.Left shortTimeFormat : str = list(SHORT_DATE_PRESETS.values())[0] maxCommits : int = 10000 authorDiffAsterisk : bool = True diff --git a/gitfourchette/trtables.py b/gitfourchette/trtables.py index 2e6df761..f5949a3e 100644 --- a/gitfourchette/trtables.py +++ b/gitfourchette/trtables.py @@ -102,7 +102,7 @@ def _init_enums(): from gitfourchette.porcelain import FileMode, NameValidationError from gitfourchette.toolbox import toLengthVariants from gitfourchette.sidebar.sidebarmodel import SidebarItem - from gitfourchette.settings import GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort + from gitfourchette.settings import CommitHashDisplay, GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort from gitfourchette.toolbox import PatchPurpose, PathDisplayStyle, AuthorDisplayStyle NVERule = NameValidationError.Rule @@ -203,6 +203,12 @@ def _init_enums(): AuthorDisplayStyle.EmailUserName: _("Abbreviated email"), }, + CommitHashDisplay: { + CommitHashDisplay.Left : _p("show commit hashes", "On left"), + CommitHashDisplay.Right : _p("show commit hashes", "On right"), + CommitHashDisplay.Hide : _p("show commit hashes", "Hide"), + }, + GraphRowHeight: { GraphRowHeight.Cramped : _p("row spacing", "Cramped"), GraphRowHeight.Tight : _p("row spacing", "Tight"), @@ -349,6 +355,7 @@ def _init_prefKeys(): "shortTimeFormat_help": TrTables._timeFormatTable(), "pathDisplayStyle": _("Path display style"), "authorDisplayStyle": _("Author display style"), + "commitHashDisplay": _("Show commit hashes"), "maxRecentRepos": _("Remember up to # recent repositories"), "showStatusBar": _("Show status bar"), "showToolBar": _("Show toolbar"),