Add search files popup

This commit is contained in:
Matt Parker
2025-10-13 19:41:56 +10:00
parent 4e1f682764
commit 207b8fe3c8
15 changed files with 294 additions and 9 deletions

View File

@@ -0,0 +1,43 @@
using Godot;
using SharpIDE.Application.Features.Analysis;
using SharpIDE.Application.Features.Search;
namespace SharpIDE.Godot.Features.Search.SearchAllFiles;
public partial class SearchAllFilesResultComponent : MarginContainer
{
private TextureRect _textureRect = null!;
private Label _fileNameLabel = null!;
private Label _filePathLabel = null!;
private Button _button = null!;
private Texture2D _csharpFileIcon = ResourceLoader.Load<Texture2D>("uid://do0edciarrnp0");
private Texture2D _folderIcon = ResourceLoader.Load<Texture2D>("uid://xc8srvqwlwng");
public SearchAllFilesWindow ParentSearchAllFilesWindow { get; set; } = null!;
public FindFilesSearchResult Result { get; set; } = null!;
public override void _Ready()
{
_button = GetNode<Button>("Button");
_textureRect = GetNode<TextureRect>("%IconTextureRect");
_fileNameLabel = GetNode<Label>("%FileNameLabel");
_filePathLabel = GetNode<Label>("%FilePathLabel");
SetValue(Result);
_button.Pressed += OnButtonPressed;
}
private void OnButtonPressed()
{
GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(Result.File, null);
ParentSearchAllFilesWindow.Hide();
}
private void SetValue(FindFilesSearchResult result)
{
if (result is null) return;
_textureRect.Texture = _csharpFileIcon;
_fileNameLabel.Text = result.File.Name;
_filePathLabel.Text = result.File.Path;
}
}

View File

@@ -0,0 +1 @@
uid://dx53kr0ffp0n8

View File

@@ -0,0 +1,60 @@
[gd_scene load_steps=4 format=3 uid="uid://cactda5eiy55"]
[ext_resource type="Script" uid="uid://dx53kr0ffp0n8" path="res://Features/Search/SearchAllFiles/SearchAllFilesResultComponent.cs" id="1_fmccx"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6ov2c"]
draw_center = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dtmd4"]
bg_color = Color(0.18039216, 0.2627451, 0.43137255, 1)
corner_radius_top_left = 3
corner_radius_top_right = 3
corner_radius_bottom_right = 3
corner_radius_bottom_left = 3
[node name="SearchAllFilesResultComponent" type="MarginContainer"]
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_top = -4.0
offset_bottom = 4.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_fmccx")
[node name="Button" type="Button" parent="."]
custom_minimum_size = Vector2(0, 26)
layout_mode = 2
theme_override_styles/normal = SubResource("StyleBoxFlat_6ov2c")
theme_override_styles/focus = SubResource("StyleBoxFlat_dtmd4")
[node name="MarginContainer" type="MarginContainer" parent="Button"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_right = 5
[node name="HBoxContainer" type="HBoxContainer" parent="Button/MarginContainer"]
layout_mode = 2
[node name="IconTextureRect" type="TextureRect" parent="Button/MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
[node name="FileNameLabel" type="Label" parent="Button/MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "FileName.cs"
[node name="FilePathLabel" type="Label" parent="Button/MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_colors/font_color = Color(1, 1, 1, 0.7411765)
text = "/File/Path/FileName.cs"
text_overrun_behavior = 3

View File

@@ -0,0 +1,56 @@
using Godot;
using SharpIDE.Application.Features.Search;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Godot.Features.Search.SearchAllFiles;
public partial class SearchAllFilesWindow : PopupPanel
{
private LineEdit _lineEdit = null!;
private VBoxContainer _searchResultsContainer = null!;
public SharpIdeSolutionModel Solution { get; set; } = null!;
private readonly PackedScene _searchResultEntryScene = ResourceLoader.Load<PackedScene>("res://Features/Search/SearchAllFiles/SearchAllFilesResultComponent.tscn");
private CancellationTokenSource _cancellationTokenSource = new();
public override void _Ready()
{
_lineEdit = GetNode<LineEdit>("%SearchLineEdit");
_lineEdit.Text = "";
_searchResultsContainer = GetNode<VBoxContainer>("%SearchResultsVBoxContainer");
_searchResultsContainer.GetChildren().ToList().ForEach(s => s.QueueFree());
_lineEdit.TextChanged += OnTextChanged;
AboutToPopup += OnAboutToPopup;
}
private void OnAboutToPopup()
{
_lineEdit.SelectAll();
Callable.From(_lineEdit.GrabFocus).CallDeferred();
}
private async void OnTextChanged(string newText)
{
await _cancellationTokenSource.CancelAsync();
// TODO: Investigate allocations
_cancellationTokenSource = new CancellationTokenSource();
var token = _cancellationTokenSource.Token;
await Task.GodotRun(() => Search(newText, token));
}
private async Task Search(string text, CancellationToken cancellationToken)
{
var result = await SearchService.FindFiles(Solution, text, cancellationToken);
await this.InvokeAsync(() =>
{
_searchResultsContainer.GetChildren().ToList().ForEach(s => s.QueueFree());
foreach (var searchResult in result)
{
var resultNode = _searchResultEntryScene.Instantiate<SearchAllFilesResultComponent>();
resultNode.Result = searchResult;
resultNode.ParentSearchAllFilesWindow = this;
_searchResultsContainer.AddChild(resultNode);
}
});
}
}

View File

@@ -0,0 +1 @@
uid://dbbjoiur46dhq

View File

@@ -0,0 +1,69 @@
[gd_scene load_steps=4 format=3 uid="uid://b8kytk23cfo4x"]
[ext_resource type="Script" uid="uid://dbbjoiur46dhq" path="res://Features/Search/SearchAllFiles/SearchAllFilesWindow.cs" id="1_opko0"]
[ext_resource type="PackedScene" uid="uid://d358tex0duum8" path="res://Features/Search/SearchInFiles/SearchResultComponent.tscn" id="2_ss4mx"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cuaw5"]
bg_color = Color(0.1764706, 0.1764706, 0.1764706, 1)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
shadow_color = Color(0, 0, 0, 0.11764706)
shadow_size = 4
[node name="SearchAllFilesWindow" type="PopupPanel"]
oversampling_override = 1.0
initial_position = 5
size = Vector2i(1200, 800)
visible = true
theme_override_styles/panel = SubResource("StyleBoxFlat_cuaw5")
script = ExtResource("1_opko0")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 4.0
offset_top = 4.0
offset_right = -4.0
offset_bottom = -4.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 15
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 15
theme_override_constants/margin_bottom = 5
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 43.615)
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Find Files"
[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 14
text = " 30 matching files"
[node name="SearchLineEdit" type="LineEdit" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Test"
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="SearchResultsVBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[node name="SearchAllFilesResultComponent" parent="MarginContainer/VBoxContainer/ScrollContainer/SearchResultsVBoxContainer" instance=ExtResource("2_ss4mx")]
layout_mode = 2

View File

@@ -12,7 +12,7 @@ public partial class SearchResultComponent : MarginContainer
private Button _button = null!;
public SearchWindow ParentSearchWindow { get; set; } = null!;
public SearchResult Result { get; set; } = null!;
public FindInFilesSearchResult Result { get; set; } = null!;
public override void _Ready()
{
@@ -31,7 +31,7 @@ public partial class SearchResultComponent : MarginContainer
ParentSearchWindow.Hide();
}
private void SetValue(SearchResult result)
private void SetValue(FindInFilesSearchResult result)
{
if (result is null) return;
_matchingLineLabel.Text = result.LineText;

View File

@@ -44,7 +44,7 @@ layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Find in Files"
text = "Find Text in Files"
[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2