|
| 1 | +using System; |
1 | 2 | using System.Collections.Specialized; |
2 | 3 | using System.ComponentModel; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Runtime.CompilerServices; |
5 | 6 |
|
6 | 7 | using Avalonia; |
7 | 8 | using Avalonia.Controls; |
| 9 | +using Avalonia.Controls.Primitives; |
8 | 10 | using Avalonia.Controls.Shapes; |
9 | 11 | using Avalonia.Interactivity; |
10 | 12 | using Avalonia.Layout; |
@@ -127,6 +129,8 @@ private RepositoryIntegration( |
127 | 129 | _repository.PropertyChanged += OnRepositoryPropertyChanged; |
128 | 130 | ViewModels.Preferences.Instance.PropertyChanged += OnPreferencesPropertyChanged; |
129 | 131 |
|
| 132 | + WireToolNavigation(); |
| 133 | + |
130 | 134 | if (ViewModels.Preferences.Instance.EnableDevSpaces) |
131 | 135 | AttachSpaces(); |
132 | 136 |
|
@@ -181,6 +185,55 @@ private void DetachSpaces() |
181 | 185 | UpdateNavigationLabel(); |
182 | 186 | } |
183 | 187 |
|
| 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 | + |
184 | 237 | private void Update() |
185 | 238 | { |
186 | 239 | var enabled = ViewModels.Preferences.Instance.EnableDevSpaces; |
@@ -278,22 +331,98 @@ private static ListBoxItem CreateNavigationItem( |
278 | 331 | }; |
279 | 332 | badge.Bind(Border.BackgroundProperty, view.GetResourceObservable("Brush.Badge")); |
280 | 333 |
|
281 | | - var content = new Grid |
| 334 | + var tools = new StackPanel |
282 | 335 | { |
283 | | - ColumnDefinitions = new ColumnDefinitions("4,Auto,*,Auto"), |
| 336 | + Margin = new Thickness(20, 0, 0, 2), |
| 337 | + IsVisible = true, |
284 | 338 | }; |
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); |
286 | 370 | Grid.SetColumn(icon, 1); |
287 | | - content.Children.Add(icon); |
| 371 | + header.Children.Add(icon); |
288 | 372 | Grid.SetColumn(label, 2); |
289 | | - content.Children.Add(label); |
| 373 | + header.Children.Add(label); |
290 | 374 | 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); |
292 | 382 |
|
293 | 383 | return new ListBoxItem |
294 | 384 | { |
| 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, |
295 | 422 | Content = content, |
296 | 423 | }; |
| 424 | + button.Classes.Add("flat"); |
| 425 | + return button; |
297 | 426 | } |
298 | 427 |
|
299 | 428 | private readonly ViewModels.Repository _repository; |
|
0 commit comments