Skip to content

Commit 7d36407

Browse files
authored
Merge pull request #42 from dhhieu113pro/feat/devspaces-sidebar-tools
feat: move Files and AI Router under DevSpaces
2 parents af2b1cf + f532544 commit 7d36407

3 files changed

Lines changed: 174 additions & 8 deletions

File tree

‎src/DevSpaces/DevSpacesBootstrap.cs‎

Lines changed: 135 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using System;
12
using System.Collections.Specialized;
23
using System.ComponentModel;
34
using System.Linq;
45
using System.Runtime.CompilerServices;
56

67
using Avalonia;
78
using Avalonia.Controls;
9+
using Avalonia.Controls.Primitives;
810
using Avalonia.Controls.Shapes;
911
using Avalonia.Interactivity;
1012
using Avalonia.Layout;
@@ -127,6 +129,8 @@ private RepositoryIntegration(
127129
_repository.PropertyChanged += OnRepositoryPropertyChanged;
128130
ViewModels.Preferences.Instance.PropertyChanged += OnPreferencesPropertyChanged;
129131

132+
WireToolNavigation();
133+
130134
if (ViewModels.Preferences.Instance.EnableDevSpaces)
131135
AttachSpaces();
132136

@@ -181,6 +185,55 @@ private void DetachSpaces()
181185
UpdateNavigationLabel();
182186
}
183187

188+
private void ActivateFiles()
189+
{
190+
ActivateTool(spaces => spaces.ActivateFiles());
191+
}
192+
193+
private void ActivateAIRouter()
194+
{
195+
ActivateTool(spaces => spaces.ActivateAIRouter());
196+
}
197+
198+
private void ActivateTool(Action<ViewModels.DevSpaces> activate)
199+
{
200+
if (!ViewModels.Preferences.Instance.EnableDevSpaces)
201+
return;
202+
203+
AttachSpaces();
204+
_repository.SelectedViewIndex = 3;
205+
206+
if (_spaces != null)
207+
activate(_spaces);
208+
209+
Update();
210+
}
211+
212+
private void WireToolNavigation()
213+
{
214+
if (_navigationItem.Content is not StackPanel root || root.Children.Count < 2 || root.Children[1] is not StackPanel tools)
215+
return;
216+
217+
foreach (var button in tools.Children.OfType<Button>())
218+
{
219+
if (button.Tag is not string target)
220+
continue;
221+
222+
if (target == "Files")
223+
button.Click += (_, e) =>
224+
{
225+
ActivateFiles();
226+
e.Handled = true;
227+
};
228+
else if (target == "AIRouter")
229+
button.Click += (_, e) =>
230+
{
231+
ActivateAIRouter();
232+
e.Handled = true;
233+
};
234+
}
235+
}
236+
184237
private void Update()
185238
{
186239
var enabled = ViewModels.Preferences.Instance.EnableDevSpaces;
@@ -278,22 +331,98 @@ private static ListBoxItem CreateNavigationItem(
278331
};
279332
badge.Bind(Border.BackgroundProperty, view.GetResourceObservable("Brush.Badge"));
280333

281-
var content = new Grid
334+
var tools = new StackPanel
282335
{
283-
ColumnDefinitions = new ColumnDefinitions("4,Auto,*,Auto"),
336+
Margin = new Thickness(20, 0, 0, 2),
337+
IsVisible = true,
284338
};
285-
content.Children.Add(indicator);
339+
tools.Children.Add(CreateToolButton(view, "Icons.Folder", App.Text("DevSpaces.Files"), "Files"));
340+
tools.Children.Add(CreateToolButton(view, "Icons.AIAssist", "AI Router", "AIRouter"));
341+
342+
var expanderLabel = new TextBlock
343+
{
344+
Text = "▾",
345+
VerticalAlignment = VerticalAlignment.Center,
346+
HorizontalAlignment = HorizontalAlignment.Center,
347+
};
348+
var expander = new ToggleButton
349+
{
350+
Width = 24,
351+
Height = 24,
352+
Margin = new Thickness(2, 0, 2, 0),
353+
IsChecked = true,
354+
Content = expanderLabel,
355+
};
356+
expander.Classes.Add("icon_button");
357+
ToolTip.SetTip(expander, App.Text("DevSpaces"));
358+
expander.Click += (_, _) =>
359+
{
360+
tools.IsVisible = expander.IsChecked != false;
361+
expanderLabel.Text = tools.IsVisible ? "▾" : "▸";
362+
};
363+
364+
var header = new Grid
365+
{
366+
Height = 28,
367+
ColumnDefinitions = new ColumnDefinitions("4,Auto,*,Auto,Auto"),
368+
};
369+
header.Children.Add(indicator);
286370
Grid.SetColumn(icon, 1);
287-
content.Children.Add(icon);
371+
header.Children.Add(icon);
288372
Grid.SetColumn(label, 2);
289-
content.Children.Add(label);
373+
header.Children.Add(label);
290374
Grid.SetColumn(badge, 3);
291-
content.Children.Add(badge);
375+
header.Children.Add(badge);
376+
Grid.SetColumn(expander, 4);
377+
header.Children.Add(expander);
378+
379+
var content = new StackPanel();
380+
content.Children.Add(header);
381+
content.Children.Add(tools);
292382

293383
return new ListBoxItem
294384
{
385+
Height = double.NaN,
386+
Content = content,
387+
};
388+
}
389+
390+
private static Button CreateToolButton(Views.Repository view, string iconKey, string text, string tag)
391+
{
392+
var icon = new Path
393+
{
394+
Width = 12,
395+
Height = 12,
396+
Margin = new Thickness(6, 0, 8, 0),
397+
VerticalAlignment = VerticalAlignment.Center,
398+
};
399+
if (view.TryFindResource(iconKey, out var iconResource) && iconResource is Geometry geometry)
400+
icon.Data = geometry;
401+
402+
var label = new TextBlock
403+
{
404+
Text = text,
405+
VerticalAlignment = VerticalAlignment.Center,
406+
};
407+
408+
var content = new StackPanel
409+
{
410+
Orientation = Orientation.Horizontal,
411+
};
412+
content.Children.Add(icon);
413+
content.Children.Add(label);
414+
415+
var button = new Button
416+
{
417+
Height = 26,
418+
Padding = new Thickness(0),
419+
HorizontalAlignment = HorizontalAlignment.Stretch,
420+
HorizontalContentAlignment = HorizontalAlignment.Left,
421+
Tag = tag,
295422
Content = content,
296423
};
424+
button.Classes.Add("flat");
425+
return button;
297426
}
298427

299428
private readonly ViewModels.Repository _repository;

‎src/Views/DevSpaces.axaml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
1111
<StackPanel Orientation="Horizontal">
1212
<Border Height="32" Margin="2,2,0,2" Padding="10,0" CornerRadius="4" Background="{DynamicResource Brush.Contents}" PointerPressed="OnDashboardTabPressed"><TextBlock VerticalAlignment="Center" Text="{DynamicResource Text.DevSpaces.Dashboard}"/></Border>
13-
<Border Height="32" Margin="2,2,0,2" Padding="10,0" CornerRadius="4" Background="{DynamicResource Brush.Contents}" PointerPressed="OnFilesTabPressed"><StackPanel Orientation="Horizontal" Spacing="6"><Path Width="13" Height="13" VerticalAlignment="Center" Data="{StaticResource Icons.Folder}"/><TextBlock VerticalAlignment="Center" Text="{DynamicResource Text.DevSpaces.Files}"/></StackPanel></Border>
14-
<Border Height="32" Margin="2,2,0,2" Padding="10,0" CornerRadius="4" Background="{DynamicResource Brush.Contents}" PointerPressed="OnAIRouterTabPressed"><StackPanel Orientation="Horizontal" Spacing="6"><Path Width="13" Height="13" VerticalAlignment="Center" Data="{StaticResource Icons.AIAssist}"/><TextBlock VerticalAlignment="Center" Text="AI Router"/></StackPanel></Border>
1513
<Border Height="32" Margin="2,2,0,2" Padding="10,0" CornerRadius="4" Background="{DynamicResource Brush.Contents}" PointerPressed="OnTerminalsTabPressed"><StackPanel Orientation="Horizontal" Spacing="6"><Path Width="13" Height="13" VerticalAlignment="Center" Data="{StaticResource Icons.Terminal}"/><TextBlock VerticalAlignment="Center" Text="{DynamicResource Text.DevSpaces.Terminals}"/></StackPanel></Border>
1614
<ItemsControl ItemsSource="{Binding Sessions}" IsVisible="{Binding IsTerminalsActive}">
1715
<ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel Orientation="Horizontal"/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Linq;
2+
using System.Reflection;
3+
4+
using Avalonia.Controls;
5+
using Avalonia.Headless.XUnit;
6+
7+
using Xunit;
8+
9+
namespace DevBoard.Tests
10+
{
11+
[Trait("Category", "UIIntegration")]
12+
public sealed class DevSpacesNavigationTests
13+
{
14+
[AvaloniaFact]
15+
public void RepositoryDevSpacesNavigationContainsFilesAndAIRouterChildren()
16+
{
17+
var assembly = typeof(Views.Repository).Assembly;
18+
var integrationType = assembly.GetType("DevBoard.DevSpaces.DevSpacesBootstrap+RepositoryIntegration");
19+
Assert.NotNull(integrationType);
20+
21+
var factory = integrationType.GetMethod("CreateNavigationItem", BindingFlags.Static | BindingFlags.NonPublic);
22+
Assert.NotNull(factory);
23+
24+
var arguments = new object[] { new Views.Repository(), null, null, null };
25+
var item = Assert.IsType<ListBoxItem>(factory.Invoke(null, arguments));
26+
var root = Assert.IsType<StackPanel>(item.Content);
27+
var tools = Assert.IsType<StackPanel>(root.Children[1]);
28+
var labels = tools.Children
29+
.OfType<Button>()
30+
.Select(x => Assert.IsType<StackPanel>(x.Content))
31+
.SelectMany(x => x.Children.OfType<TextBlock>())
32+
.Select(x => x.Text)
33+
.ToArray();
34+
35+
Assert.Contains(App.Text("DevSpaces.Files"), labels);
36+
Assert.Contains("AI Router", labels);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)