-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
118 lines (100 loc) · 3.42 KB
/
MainWindow.xaml.cs
File metadata and controls
118 lines (100 loc) · 3.42 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Input;
using System.Windows.Threading;
using CSharpCodeAnalyst.Features.Graph;
using CSharpCodeAnalyst.Shared.Contracts;
using CSharpCodeAnalyst.Shared.Messages;
using CSharpCodeAnalyst.Shared.UI;
namespace CSharpCodeAnalyst;
public partial class MainWindow
{
public const double TreeMinWidthCollapsed = 24;
public const double TreeMinWidthExpanded = 400;
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
LeftExpander.Expanded += LeftExpander_Expanded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Set a fixed width for the left column on first load to prevent jumping
EnsureLeftColumnWidth();
}
private void EnsureLeftColumnWidth()
{
// Use Dispatcher to ensure this runs after all layout updates
Dispatcher.BeginInvoke(new Action(() =>
{
// Always ensure we have a fixed width to prevent jumping
if (SplitterColumn.Width.IsAuto || SplitterColumn.Width.Value < TreeMinWidthExpanded)
{
SplitterColumn.Width = new GridLength(TreeMinWidthExpanded);
}
}), DispatcherPriority.Loaded);
}
private void Exit_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void LeftExpander_Collapsed(object sender, RoutedEventArgs e)
{
// When collapsed, set to auto but ensure it gets fixed when expanded again
SplitterColumn.Width = GridLength.Auto;
}
private void LeftExpander_Expanded(object sender, RoutedEventArgs e)
{
// When expanded, ensure we have a proper fixed width to prevent jumping
EnsureLeftColumnWidth();
}
private void GridSplitter_DragDelta(object sender, DragDeltaEventArgs e)
{
var expander = LeftExpander;
// Calculate the new width
var newWidth = SplitterColumn.ActualWidth + e.HorizontalChange;
// Set a minimum width (adjust as needed)
var minWidth = expander.IsExpanded ? TreeMinWidthExpanded : TreeMinWidthCollapsed;
if (newWidth < minWidth)
{
e.Handled = true;
SplitterColumn.Width = new GridLength(minWidth);
}
else
{
SplitterColumn.Width = new GridLength(newWidth);
}
}
public void HandleLocateInTreeRequest(LocateInTreeRequest request)
{
CodeStructureTab.SelectedIndex = 0;
TreeControl.HandleLocateInTreeRequest(request);
}
private void RootWindow_Closing(object sender, CancelEventArgs e)
{
if (DataContext is MainViewModel mainVm)
{
e.Cancel = !mainVm.OnClosing();
}
}
public void SetViewer(GraphViewer explorationGraphViewer, IPublisher publisher)
{
ExplorationControl.SetViewer(explorationGraphViewer, publisher);
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (WorkingArea.SelectedIndex == 0)
{
// Code explorer
var mainVm = ExplorationControl.DataContext as MainViewModel;
var graphVm = mainVm?.GraphViewModel;
if (graphVm != null && graphVm.TryHandleKeyDown(e))
{
e.Handled = true;
}
}
}
}