Add folder selection
This commit is contained in:
parent
7593828ca7
commit
80f121bfde
|
@ -24,6 +24,8 @@ public partial class TextureBrowser : Node
|
||||||
private TextureRect _previewTexture;
|
private TextureRect _previewTexture;
|
||||||
private LineEdit _texturePath;
|
private LineEdit _texturePath;
|
||||||
|
|
||||||
|
private string _searchFilterPrefix = "";
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
// !HACK TEMP
|
// !HACK TEMP
|
||||||
|
@ -41,6 +43,7 @@ public partial class TextureBrowser : Node
|
||||||
|
|
||||||
_searchBar.TextChanged += ApplySearchFilter;
|
_searchBar.TextChanged += ApplySearchFilter;
|
||||||
_sortMenu.GetPopup().IdPressed += ApplySortMode;
|
_sortMenu.GetPopup().IdPressed += ApplySortMode;
|
||||||
|
_folderTree.ItemSelected += SetActiveFolder;
|
||||||
|
|
||||||
BuildFolderTree();
|
BuildFolderTree();
|
||||||
BuildTextureList(); // TODO: This should be triggered on folder change
|
BuildTextureList(); // TODO: This should be triggered on folder change
|
||||||
|
@ -95,8 +98,10 @@ public partial class TextureBrowser : Node
|
||||||
textureRect.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
|
textureRect.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
|
||||||
textureRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
textureRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
||||||
|
|
||||||
|
// We use meta here rather than just Name because Name replaces / with _ so
|
||||||
|
// we can't reliably construct it (the path can have natural _)
|
||||||
var slot = new Panel();
|
var slot = new Panel();
|
||||||
slot.Name = name;
|
slot.SetMeta("TexPath", name);
|
||||||
slot.CustomMinimumSize = new Vector2(128, 128);
|
slot.CustomMinimumSize = new Vector2(128, 128);
|
||||||
slot.AddChild(textureRect);
|
slot.AddChild(textureRect);
|
||||||
slot.GuiInput += (input) =>
|
slot.GuiInput += (input) =>
|
||||||
|
@ -121,11 +126,12 @@ public partial class TextureBrowser : Node
|
||||||
|
|
||||||
private void ApplySearchFilter(string filter)
|
private void ApplySearchFilter(string filter)
|
||||||
{
|
{
|
||||||
var regexString = "^.*" + Regex.Escape(filter).Replace("\\*", ".*") + ".*$";
|
var regex = $"^{_searchFilterPrefix}.*{Regex.Escape(filter).Replace("\\*", ".*")}.*$";
|
||||||
foreach (var node in _textureList.GetChildren())
|
foreach (var node in _textureList.GetChildren())
|
||||||
{
|
{
|
||||||
var panel = (Panel)node;
|
var panel = (Panel)node;
|
||||||
panel.Visible = Regex.IsMatch(panel.Name.ToString(), regexString);
|
var name = panel.GetMeta("TexPath").ToString();
|
||||||
|
panel.Visible = Regex.IsMatch(name, regex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,4 +145,25 @@ public partial class TextureBrowser : Node
|
||||||
|
|
||||||
// TODO: Actualy sort
|
// TODO: Actualy sort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetActiveFolder()
|
||||||
|
{
|
||||||
|
var selected = _folderTree.GetSelected();
|
||||||
|
var selectedFolder = selected.GetText(0) + "/";
|
||||||
|
var parent = selected.GetParent();
|
||||||
|
while (parent != null)
|
||||||
|
{
|
||||||
|
var text = parent.GetText(0);
|
||||||
|
if (text != "")
|
||||||
|
{
|
||||||
|
selectedFolder = text + "/" + selectedFolder;
|
||||||
|
}
|
||||||
|
parent = parent.GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This prefix is used in a regex, so we escape it here. The additional
|
||||||
|
// replace is because C# Regex doesn't escape /
|
||||||
|
_searchFilterPrefix = Regex.Escape(selectedFolder).Replace("/", "\\/");
|
||||||
|
ApplySearchFilter(_searchBar.Text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue