Skip to content

Commit

Permalink
feat: Expand any Region in Codenav Panel on Single\Double Click #141
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Sep 17, 2022
1 parent 67ae1ea commit 5235692
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CodeNav.Shared/Models/CodeClassItem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable enable

using CodeNav.Helpers;
using Microsoft.VisualStudio.PlatformUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace CodeNav.Models
Expand Down Expand Up @@ -69,5 +71,12 @@ public Visibility HasMembersVisibility
: Visibility.Collapsed;
}
}

public ICommand ToggleIsExpandedCommand => new DelegateCommand(ToggleIsExpanded);
public void ToggleIsExpanded(object args)
{
IsDoubleClicked = true;
IsExpanded = !IsExpanded;
}
}
}
17 changes: 15 additions & 2 deletions CodeNav.Shared/Models/CodeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Runtime.Serialization;
using Task = System.Threading.Tasks.Task;
using Microsoft.VisualStudio.Shell;
using System.Threading;

namespace CodeNav.Models
{
Expand Down Expand Up @@ -108,6 +109,8 @@ public bool ContextMenuIsOpen
set => SetProperty(ref _contextMenuIsOpen, value);
}

public bool IsDoubleClicked;

#region Fonts
private float _fontSize;
public float FontSize
Expand Down Expand Up @@ -199,10 +202,20 @@ public Color NameBackgroundColor

#region Commands
public ICommand ClickItemCommand => new DelegateCommand(ClickItem);
public void ClickItem(object args)
public void ClickItem() => ClickItemAsync().FireAndForget();

private async Task ClickItemAsync()
{
await Task.Delay(200);

if (IsDoubleClicked)
{
IsDoubleClicked = false;
return;
}

HistoryHelper.AddItemToHistory(this);
DocumentHelper.ScrollToLine(StartLinePosition, FilePath).FireAndForget();
await DocumentHelper.ScrollToLine(StartLinePosition, FilePath);
}

public ICommand GoToDefinitionCommand => new DelegateCommand(GoToDefinition);
Expand Down
17 changes: 13 additions & 4 deletions CodeNav.Shared/Styles/PlusMinusExpanderStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@
<GradientStop Color="Transparent" Offset="1" />
</LinearGradientBrush>
</Border.BorderBrush>
<Button Command="{Binding Path=ClickItemCommand}"
CommandParameter="{Binding StartLinePosition}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
<Button ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
Content="{TemplateBinding Header}"
Padding="{TemplateBinding Padding}"
Expand All @@ -88,7 +86,18 @@
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
DockPanel.Dock="Top"
BorderThickness="0"
Margin="4,0,0,0" />
Margin="4,0,0,0">
<Button.InputBindings>

<MouseBinding
Gesture="LeftDoubleClick"
Command="{Binding Path=ToggleIsExpandedCommand}" />
<MouseBinding
Gesture="LeftClick"
Command="{Binding Path=ClickItemCommand}"
CommandParameter="{Binding StartLinePosition}" />
</Button.InputBindings>
</Button>
</Border>

<ToggleButton
Expand Down

0 comments on commit 5235692

Please sign in to comment.