-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathCodeViewUserControlTop.xaml.cs
79 lines (62 loc) · 2.79 KB
/
CodeViewUserControlTop.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#nullable enable
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;
using CodeNav.Helpers;
using CodeNav.Models;
using CodeNav.Models.ViewModels;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Outlining;
using Task = System.Threading.Tasks.Task;
namespace CodeNav
{
public partial class CodeViewUserControlTop : ICodeViewUserControl
{
private readonly RowDefinition? _row;
public IDisposable? CaretPositionChangedSubscription { get; set; }
public IDisposable? TextContentChangedSubscription { get; set; }
public IDisposable? UpdateWhileTypingSubscription { get; set; }
public IDisposable? FileActionOccurredSubscription { get; set; }
public CodeDocumentViewModel CodeDocumentViewModel { get; set; }
public CodeViewUserControlTop(RowDefinition? row = null)
{
InitializeComponent();
// Setup viewmodel as datacontext
CodeDocumentViewModel = new CodeDocumentViewModel();
DataContext = CodeDocumentViewModel;
_row = row;
VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;
}
private void VSColorTheme_ThemeChanged(ThemeChangedEventArgs e) => UpdateDocument();
public void FilterBookmarks()
=> VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel);
public void RegionsCollapsed(RegionsCollapsedEventArgs e) =>
OutliningHelper.RegionsCollapsed(e, CodeDocumentViewModel.CodeDocument);
public void RegionsExpanded(RegionsExpandedEventArgs e) =>
OutliningHelper.RegionsExpanded(e, CodeDocumentViewModel.CodeDocument);
public void ToggleAll(bool isExpanded, List<CodeItem>? root = null)
{
OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded);
}
/// <inheritdoc/>
public void UpdateDocument(string filePath = "", bool force = false)
=> ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel,
null, _row, filePath, force));
public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor)
{
HighlightHelper.HighlightCurrentItem(
CodeDocumentViewModel,
backgroundBrushColor,
e.NewPosition.BufferPosition.GetContainingLine().LineNumber);
// Force NotifyPropertyChanged
CodeDocumentViewModel.CodeDocumentTop = new List<CodeItem>();
}
public async Task RegisterDocumentEvents()
{
// Todo: Implement events
}
}
}