Skip to content

Commit e103101

Browse files
committed
- new settings options
- bug fixes - general ui improvements
1 parent 8e6965c commit e103101

File tree

10 files changed

+323
-21
lines changed

10 files changed

+323
-21
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "CI / Debug Builds"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
Debug-Builds:
12+
runs-on: windows-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: microsoft/setup-msbuild@v1.3.1
17+
- uses: nuget/setup-nuget@v1.1.1
18+
19+
- name: Restore NuGet Packages
20+
run: nuget restore ./VSGitBlame.sln
21+
22+
- name: Build VSIX (Debug)
23+
run: msbuild './VSGitBlame/VSGitBlame.csproj' /p:Configuration=Debug /p:Platform=AnyCPU /p:DeployExtension=false
24+
25+
- name: Publish VSIX Artifact
26+
uses: actions/upload-artifact@v4
27+
with:
28+
path: ./VSGitBlame/bin/x64/Debug/VSGitBlame.vsix
29+
name: latest-x64

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "Release Builds and Publish"
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
Release-Builds:
9+
runs-on: windows-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: microsoft/setup-msbuild@v1.3.1
14+
- uses: nuget/setup-nuget@v1.1.1
15+
16+
- name: Restore NuGet Packages
17+
run: nuget restore ./VSGitBlame.sln
18+
19+
- name: Build VSIX (Release)
20+
run: msbuild './VSGitBlame/VSGitBlame.csproj' /p:Configuration=Release /p:Platform=AnyCPU /p:DeployExtension=false
21+
22+
- name: Publish VSIX Artifact
23+
uses: actions/upload-artifact@v4
24+
with:
25+
path: ./VSGitBlame/bin/x64/Release/VSGitBlame.vsix
26+
name: latest-x64
27+
28+
- name: Publish x64 to Marketplace
29+
uses: CalvinAllen/action-vs-marketplace-publish@v1
30+
with:
31+
marketplace-pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
32+
publish-manifest-path: ./VSGitBlame/extension.manifest.json
33+
vsix-path: ./VSGitBlame/bin/x64/Release/VSGitBlame.vsix

VSGitBlame/CommitInfoAdornment.cs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,68 @@ public class CommitInfoAdornment
1212
readonly IWpfTextView _view;
1313
readonly IAdornmentLayer _adornmentLayer;
1414
readonly ITextDocument _textDocument;
15+
int _lastCaretLine = -1;
1516

1617
public CommitInfoAdornment(IWpfTextView view)
1718
{
1819
_view = view;
1920
_adornmentLayer = view.GetAdornmentLayer("CommitInfoAdornment");
20-
_view.LayoutChanged += OnLayoutChanged;
21-
_view.VisualElement.MouseLeftButtonUp += VisualElement_MouseLeftButtonUp;
2221
_textDocument = _view.TextBuffer.Properties.GetProperty<ITextDocument>(typeof(ITextDocument));
22+
23+
// Event Subscriptions
24+
_view.LayoutChanged += OnLayoutChanged;
2325
_textDocument.FileActionOccurred += TextDocument_FileActionOccurred;
26+
_view.Caret.PositionChanged += Caret_PositionChanged;
27+
//_view.VisualElement.MouseLeftButtonUp += VisualElement_MouseLeftButtonUp;
28+
}
29+
30+
private void Caret_PositionChanged(object sender, CaretPositionChangedEventArgs e)
31+
{
32+
int currentLine = e.NewPosition.BufferPosition.GetContainingLine().LineNumber;
33+
if (currentLine != _lastCaretLine)
34+
{
35+
_lastCaretLine = currentLine;
36+
OnCaretLineChanged(currentLine, e);
37+
}
2438
}
2539

40+
2641
private void TextDocument_FileActionOccurred(object sender, TextDocumentFileActionEventArgs e)
2742
{
2843
GitBlamer.InvalidateCache(_textDocument.FilePath);
2944
}
3045

46+
private void OnCaretLineChanged(int lineNumber, CaretPositionChangedEventArgs e)
47+
{
48+
_adornmentLayer.RemoveAllAdornments();
49+
50+
// Only show commit info if the document is not dirty (no unsaved changes)
51+
if (_textDocument.IsDirty)
52+
return;
53+
54+
// Get the caret position in the view
55+
var caretPosition = e.NewPosition.BufferPosition;
56+
var textViewLine = _view.GetTextViewLineContainingBufferPosition(caretPosition);
57+
58+
if (textViewLine == null)
59+
return;
60+
61+
var commitInfo = GitBlamer.GetBlame(_textDocument.FilePath, lineNumber + 1);
62+
63+
if (commitInfo == null)
64+
return;
65+
66+
ShowCommitInfo(commitInfo, textViewLine);
67+
}
68+
3169
private void VisualElement_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
3270
{
3371
_adornmentLayer.RemoveAllAdornments();
3472

73+
// Only show commit info if the document is not dirty (no unsaved changes)
74+
if (_textDocument.IsDirty)
75+
return;
76+
3577
var mousePosition = e.GetPosition(_view.VisualElement);
3678

3779
// Get the scroll offset
@@ -80,11 +122,10 @@ void CreateVisuals(ITextViewLine line)
80122

81123
void ShowCommitInfo(CommitInfo commitInfo, ITextViewLine line)
82124
{
83-
double top = line.Top - 52 < 0 ? 0 : line.Top - 52;
84125
var container = CommitInfoViewFactory.Get(commitInfo, _adornmentLayer);
85126

86127
Canvas.SetLeft(container, line.Right);
87-
Canvas.SetTop(container, top);
128+
Canvas.SetTop(container, line.Top);
88129

89130
_adornmentLayer.RemoveAllAdornments();
90131
SnapshotSpan span = new SnapshotSpan(_adornmentLayer.TextView.TextSnapshot, Span.FromBounds(line.Start, line.End));

VSGitBlame/CommitInfoViewFactory.cs

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using VSGitBlame.Core;
88
using System.Linq;
99
using Microsoft.VisualStudio.Text.Editor;
10+
using Color = System.Drawing.Color;
1011

1112
namespace VSGitBlame;
1213

@@ -16,30 +17,96 @@ public static class CommitInfoViewFactory
1617
static TextBlock _summaryView;
1718
static TextBlock _commitDetailsView;
1819
static Image _profileIcon;
20+
static StackPanel _detailsView;
21+
static Border _detailsViewContainer;
1922

2023
static bool _firstMouseMoveFired = false;
2124
static bool _isDetailsVisible = false;
2225
static IAdornmentLayer _adornmentLayer;
26+
27+
private static VSGitBlamePackage _package;
28+
private static CommitInfoViewOptions _options;
2329

30+
public static void InitializeSettings(VSGitBlamePackage package)
31+
{
32+
_package = package;
33+
LoadSettings();
34+
}
35+
36+
private static void LoadSettings()
37+
{
38+
if (_package != null)
39+
{
40+
_options = _package.GetDialogPage(typeof(CommitInfoViewOptions)) as CommitInfoViewOptions;
41+
}
42+
}
43+
44+
public static void RefreshSettings()
45+
{
46+
LoadSettings();
47+
if (_options != null)
48+
{
49+
ApplySettings();
50+
}
51+
}
52+
53+
private static void ApplySettings()
54+
{
55+
if (_summaryView != null && _options != null)
56+
{
57+
// Apply summary view settings
58+
_summaryView.FontSize = _options.SummaryFontSize;
59+
60+
// Override the foreground color if specified, otherwise use theme detection
61+
if (_options.SummaryFontColor != Color.Transparent)
62+
{
63+
_summaryView.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(
64+
_options.SummaryFontColor.A,
65+
_options.SummaryFontColor.R,
66+
_options.SummaryFontColor.G,
67+
_options.SummaryFontColor.B));
68+
}
69+
else
70+
{
71+
// Use theme detection if no specific color is set
72+
var backgroundColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
73+
_summaryView.Foreground = backgroundColor.GetBrightness() > 0.5 ?
74+
Brushes.DarkBlue :
75+
Brushes.LightGray;
76+
}
77+
}
78+
79+
if (_commitDetailsView != null && _options != null)
80+
{
81+
// Apply details view settings
82+
_commitDetailsView.FontSize = _options.DetailsFontSize;
83+
_commitDetailsView.Foreground = _options.GetDetailsFontBrush();
84+
}
85+
86+
if (_detailsView != null && _options != null)
87+
{
88+
// Apply background color setting
89+
_detailsViewContainer.Background = _options.GetDetailsBackgroundBrush();
90+
}
91+
}
2492

2593
static CommitInfoViewFactory()
2694
{
2795
#region Summary View
2896
var backgroundColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
2997
_summaryView = new TextBlock
3098
{
31-
Opacity = 0.6,
99+
Opacity = 0.5,
32100
Background = Brushes.Transparent,
33101
Foreground = backgroundColor.GetBrightness() > 0.5 ? Brushes.DarkBlue : Brushes.LightGray,
34102
FontStyle = FontStyles.Italic,
35-
FontWeight = FontWeights.Bold,
103+
FontWeight = FontWeights.Normal,
36104
};
37105
#endregion
38106

39-
#region Info View
40-
var infoView = new StackPanel
107+
#region Details View
108+
_detailsView = new StackPanel
41109
{
42-
Background = new SolidColorBrush(Colors.DarkBlue),
43110
Orientation = Orientation.Horizontal,
44111
};
45112

@@ -49,33 +116,34 @@ static CommitInfoViewFactory()
49116
Height = 50,
50117
Margin = new Thickness(0, 0, 3, 0),
51118
};
52-
infoView.Children.Add(_profileIcon);
119+
_detailsView.Children.Add(_profileIcon);
53120

54121
_commitDetailsView = new TextBlock
55122
{
56123
Foreground = new SolidColorBrush(Colors.White),
57124
FontWeight = FontWeights.Bold,
58125
};
59-
infoView.Children.Add(_commitDetailsView);
126+
_detailsView.Children.Add(_commitDetailsView);
60127

61-
var infoViewContainer = new Border
128+
_detailsViewContainer = new Border
62129
{
63130
BorderThickness = new Thickness(1),
131+
Background = new SolidColorBrush(Colors.DarkBlue),
64132
BorderBrush = Brushes.Transparent,
65133
Visibility = Visibility.Hidden,
66-
Padding = new Thickness(2)
134+
Padding = new Thickness(5),
67135
};
68-
infoViewContainer.Child = infoView;
136+
_detailsViewContainer.Child = _detailsView;
69137
#endregion
70138

71139
#region Container
72140
var rootPanel = new StackPanel
73141
{
74142
Orientation = Orientation.Vertical,
75-
Background = Brushes.Transparent
143+
Background = Brushes.Transparent,
76144
};
77-
rootPanel.Children.Add(infoViewContainer);
78145
rootPanel.Children.Add(_summaryView);
146+
rootPanel.Children.Add(_detailsViewContainer);
79147

80148
rootPanel.MouseMove += (sender, e) =>
81149
{
@@ -88,16 +156,15 @@ static CommitInfoViewFactory()
88156
if (_isDetailsVisible)
89157
return;
90158

91-
infoViewContainer.Visibility = Visibility.Visible;
159+
_detailsViewContainer.Visibility = Visibility.Visible;
92160
_isDetailsVisible = true;
93161
};
94162

95163
rootPanel.MouseLeave += (sender, e) =>
96164
{
97165
_firstMouseMoveFired = false;
98166
_isDetailsVisible = false;
99-
infoViewContainer.Visibility = Visibility.Hidden;
100-
_container.Visibility = Visibility.Hidden;
167+
_detailsViewContainer.Visibility = Visibility.Hidden;
101168
};
102169

103170
_container = new Border

0 commit comments

Comments
 (0)