Skip to content

Commit 5235692

Browse files
committed
feat: Expand any Region in Codenav Panel on Single\Double Click #141
1 parent 67ae1ea commit 5235692

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

CodeNav.Shared/Models/CodeClassItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable enable
22

33
using CodeNav.Helpers;
4+
using Microsoft.VisualStudio.PlatformUI;
45
using System;
56
using System.Collections.Generic;
67
using System.Linq;
78
using System.Windows;
9+
using System.Windows.Input;
810
using System.Windows.Media;
911

1012
namespace CodeNav.Models
@@ -69,5 +71,12 @@ public Visibility HasMembersVisibility
6971
: Visibility.Collapsed;
7072
}
7173
}
74+
75+
public ICommand ToggleIsExpandedCommand => new DelegateCommand(ToggleIsExpanded);
76+
public void ToggleIsExpanded(object args)
77+
{
78+
IsDoubleClicked = true;
79+
IsExpanded = !IsExpanded;
80+
}
7281
}
7382
}

CodeNav.Shared/Models/CodeItem.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Runtime.Serialization;
1515
using Task = System.Threading.Tasks.Task;
1616
using Microsoft.VisualStudio.Shell;
17+
using System.Threading;
1718

1819
namespace CodeNav.Models
1920
{
@@ -108,6 +109,8 @@ public bool ContextMenuIsOpen
108109
set => SetProperty(ref _contextMenuIsOpen, value);
109110
}
110111

112+
public bool IsDoubleClicked;
113+
111114
#region Fonts
112115
private float _fontSize;
113116
public float FontSize
@@ -199,10 +202,20 @@ public Color NameBackgroundColor
199202

200203
#region Commands
201204
public ICommand ClickItemCommand => new DelegateCommand(ClickItem);
202-
public void ClickItem(object args)
205+
public void ClickItem() => ClickItemAsync().FireAndForget();
206+
207+
private async Task ClickItemAsync()
203208
{
209+
await Task.Delay(200);
210+
211+
if (IsDoubleClicked)
212+
{
213+
IsDoubleClicked = false;
214+
return;
215+
}
216+
204217
HistoryHelper.AddItemToHistory(this);
205-
DocumentHelper.ScrollToLine(StartLinePosition, FilePath).FireAndForget();
218+
await DocumentHelper.ScrollToLine(StartLinePosition, FilePath);
206219
}
207220

208221
public ICommand GoToDefinitionCommand => new DelegateCommand(GoToDefinition);

CodeNav.Shared/Styles/PlusMinusExpanderStyles.xaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@
6969
<GradientStop Color="Transparent" Offset="1" />
7070
</LinearGradientBrush>
7171
</Border.BorderBrush>
72-
<Button Command="{Binding Path=ClickItemCommand}"
73-
CommandParameter="{Binding StartLinePosition}"
74-
ContentTemplate="{TemplateBinding HeaderTemplate}"
72+
<Button ContentTemplate="{TemplateBinding HeaderTemplate}"
7573
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
7674
Content="{TemplateBinding Header}"
7775
Padding="{TemplateBinding Padding}"
@@ -88,7 +86,18 @@
8886
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
8987
DockPanel.Dock="Top"
9088
BorderThickness="0"
91-
Margin="4,0,0,0" />
89+
Margin="4,0,0,0">
90+
<Button.InputBindings>
91+
92+
<MouseBinding
93+
Gesture="LeftDoubleClick"
94+
Command="{Binding Path=ToggleIsExpandedCommand}" />
95+
<MouseBinding
96+
Gesture="LeftClick"
97+
Command="{Binding Path=ClickItemCommand}"
98+
CommandParameter="{Binding StartLinePosition}" />
99+
</Button.InputBindings>
100+
</Button>
92101
</Border>
93102

94103
<ToggleButton

0 commit comments

Comments
 (0)