Skip to content

Commit e1c1664

Browse files
committed
Allow customizing indentation width
1 parent bdc9005 commit e1c1664

File tree

5 files changed

+133
-52
lines changed

5 files changed

+133
-52
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="100"
6+
VerticalAlignment="Center"
7+
x:Class="Syndiesis.Controls.Settings.LabelledSlider"
8+
xmlns:sc="using:Syndiesis.Controls.Settings"
9+
>
10+
11+
<Grid>
12+
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="120" />
15+
<ColumnDefinition Width="*" />
16+
</Grid.ColumnDefinitions>
17+
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="Auto"/>
20+
</Grid.RowDefinitions>
21+
22+
<Slider
23+
Name="ValueSliderField"
24+
Minimum="10"
25+
Maximum="1000"
26+
Value="100"
27+
Grid.Column="1"
28+
Grid.RowSpan="2"
29+
Margin="15 0 0 0"
30+
Foreground="#009099"
31+
Background="#00232E"
32+
/>
33+
<TextBlock
34+
HorizontalAlignment="Right"
35+
VerticalAlignment="Center"
36+
FontFamily="{StaticResource AptosDisplayFontFamily}"
37+
FontSize="16"
38+
Name="NameTextBlock"
39+
Text="Typing delay wait"
40+
/>
41+
42+
<TextBlock
43+
HorizontalAlignment="Right"
44+
VerticalAlignment="Bottom"
45+
FontFamily="{StaticResource AptosDisplayFontFamily}"
46+
FontSize="14"
47+
Grid.RowSpan="2"
48+
Name="ValueTextBlock"
49+
Text="600 ms"
50+
/>
51+
52+
</Grid>
53+
54+
</UserControl>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Avalonia.Controls;
2+
3+
namespace Syndiesis.Controls.Settings;
4+
5+
public partial class LabelledSlider : UserControl
6+
{
7+
public string ValueText
8+
{
9+
get => ValueTextBlock.Text!;
10+
set => ValueTextBlock.Text = value;
11+
}
12+
13+
public string NameText
14+
{
15+
get => NameTextBlock.Text!;
16+
set => NameTextBlock.Text = value;
17+
}
18+
19+
public Slider ValueSlider => ValueSliderField;
20+
21+
public LabelledSlider()
22+
{
23+
InitializeComponent();
24+
}
25+
}

Syndiesis/Views/MainView.axaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private void TriggerPipeline()
138138
public void ApplyCurrentSettings()
139139
{
140140
ApplyCurrentSettingsWithoutAnalysis();
141+
ViewModel.Editor.IndentationOptions = AppSettings.Instance.IndentationOptions;
141142
ForceRedoAnalysis();
142143
}
143144

Syndiesis/Views/SettingsView.axaml

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="400"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="500"
66
x:Class="Syndiesis.Views.SettingsView"
7+
xmlns:sc="using:Syndiesis.Controls.Settings"
78
>
89

910
<Grid
@@ -169,52 +170,17 @@
169170
/>
170171
</CheckBox>
171172

172-
<Grid>
173-
174-
<Grid.ColumnDefinitions>
175-
<ColumnDefinition Width="120" />
176-
<ColumnDefinition Width="*" />
177-
</Grid.ColumnDefinitions>
178-
179-
<Grid.RowDefinitions>
180-
<RowDefinition Height="Auto"/>
181-
</Grid.RowDefinitions>
182-
183-
<Slider
184-
Name="typingDelaySlider"
185-
Value="150"
186-
Minimum="50"
187-
Maximum="1000"
188-
SmallChange="50"
189-
LargeChange="100"
190-
Grid.Column="1"
191-
Grid.RowSpan="2"
192-
Margin="15 0 0 0"
193-
Foreground="#009099"
194-
Background="#00232E"
195-
/>
196-
<TextBlock
197-
HorizontalAlignment="Right"
198-
VerticalAlignment="Center"
199-
FontFamily="{StaticResource AptosDisplayFontFamily}"
200-
FontSize="16"
201-
Text="Typing delay wait"
202-
/>
203-
204-
<TextBlock
205-
HorizontalAlignment="Right"
206-
VerticalAlignment="Bottom"
207-
FontFamily="{StaticResource AptosDisplayFontFamily}"
208-
FontSize="14"
209-
Grid.RowSpan="2"
173+
<sc:LabelledSlider
174+
Name="typingDelaySlider"
175+
NameText="Typing delay wait"
210176
>
211-
<TextBlock.Inlines>
212-
<Run Text="1000" Name="sliderValueDisplay" />
213-
<Run Text="ms" />
214-
</TextBlock.Inlines>
215-
</TextBlock>
177+
</sc:LabelledSlider>
216178

217-
</Grid>
179+
<sc:LabelledSlider
180+
Name="indentationWidthSlider"
181+
NameText="Indentation width"
182+
>
183+
</sc:LabelledSlider>
218184

219185
</StackPanel>
220186

Syndiesis/Views/SettingsView.axaml.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Avalonia.Controls;
22
using Avalonia.Controls.Primitives;
33
using Avalonia.Interactivity;
4-
using Microsoft.CodeAnalysis;
54
using System;
65

76
namespace Syndiesis.Views;
87

98
public partial class SettingsView : UserControl
109
{
11-
private int TypingDelayMilliseconds => (int)typingDelaySlider.Value;
10+
private int TypingDelayMilliseconds => (int)typingDelaySlider.ValueSlider.Value;
11+
private int IndentationWidth => (int)indentationWidthSlider.ValueSlider.Value;
1212

1313
private TimeSpan TypingDelay => TimeSpan.FromMilliseconds(TypingDelayMilliseconds);
1414

@@ -18,11 +18,13 @@ public SettingsView()
1818
{
1919
InitializeComponent();
2020
InitializeEvents();
21+
InitializeSliders();
2122
}
2223

2324
private void InitializeEvents()
2425
{
25-
typingDelaySlider.ValueChanged += OnDelaySliderValueChanged;
26+
typingDelaySlider.ValueSlider.ValueChanged += OnDelaySliderValueChanged;
27+
indentationWidthSlider.ValueSlider.ValueChanged += OnIndentationSliderValueChanged;
2628
saveButton.Click += OnSaveClicked;
2729
}
2830

@@ -31,7 +33,8 @@ public void LoadFromSettings()
3133
var settings = AppSettings.Instance;
3234
showTriviaCheck.IsChecked = settings.NodeLineOptions.ShowTrivia;
3335
enableExpandAllButtonCheck.IsChecked = settings.EnableExpandingAllNodes;
34-
typingDelaySlider.Value = settings.UserInputDelay.TotalMilliseconds;
36+
typingDelaySlider.ValueSlider.Value = settings.UserInputDelay.TotalMilliseconds;
37+
indentationWidthSlider.ValueSlider.Value = settings.IndentationOptions.IndentationWidth;
3538
}
3639

3740
protected override void OnLoaded(RoutedEventArgs e)
@@ -49,19 +52,51 @@ private void SaveSettings()
4952
{
5053
var settings = AppSettings.Instance;
5154
settings.UserInputDelay = TypingDelay;
55+
settings.IndentationOptions.IndentationWidth = IndentationWidth;
5256
settings.EnableExpandingAllNodes = enableExpandAllButtonCheck.IsChecked is true;
5357
settings.NodeLineOptions.ShowTrivia = showTriviaCheck.IsChecked is true;
5458
AppSettings.TrySave();
5559
SettingsSaved?.Invoke();
5660
}
5761

62+
private void OnIndentationSliderValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
63+
{
64+
UpdateIndentationValue();
65+
}
66+
67+
private void UpdateIndentationValue()
68+
{
69+
indentationWidthSlider.ValueText = $"{IndentationWidth}x space";
70+
}
71+
5872
private void OnDelaySliderValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
5973
{
60-
UpdateSliderValueDisplay();
74+
UpdateTypingDelayValue();
6175
}
6276

63-
private void UpdateSliderValueDisplay()
77+
private void UpdateTypingDelayValue()
6478
{
65-
sliderValueDisplay.Text = TypingDelayMilliseconds.ToString();
79+
typingDelaySlider.ValueText = $"{TypingDelayMilliseconds} ms";
80+
}
81+
82+
private void InitializeSliders()
83+
{
84+
{
85+
var valueSlider = typingDelaySlider.ValueSlider;
86+
valueSlider.Minimum = 50;
87+
valueSlider.Maximum = 1000;
88+
valueSlider.Value = 600;
89+
valueSlider.SmallChange = 50;
90+
valueSlider.LargeChange = 100;
91+
}
92+
93+
{
94+
var valueSlider = indentationWidthSlider.ValueSlider;
95+
valueSlider.Minimum = 1;
96+
valueSlider.Maximum = 12;
97+
valueSlider.Value = 4;
98+
valueSlider.SmallChange = 1;
99+
valueSlider.LargeChange = 2;
100+
}
66101
}
67102
}

0 commit comments

Comments
 (0)