mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-29 10:24:34 +00:00
PckStudio - Imporove FilterPrompt
This commit is contained in:
@@ -7,6 +7,7 @@ using PckStudio.Json;
|
||||
using PckStudio.Core.Extensions;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using PckStudio.Controls;
|
||||
|
||||
namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
{
|
||||
@@ -36,7 +37,11 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
|
||||
public DialogResult ShowDialog(IWin32Window owner)
|
||||
{
|
||||
return filterPrompt.ShowDialog(owner);
|
||||
var f = new ImmersiveForm();
|
||||
filterPrompt.Dock = DockStyle.Fill;
|
||||
filterPrompt.Update();
|
||||
f.Controls.Add(filterPrompt);
|
||||
return f.ShowDialog(owner);
|
||||
}
|
||||
|
||||
private void filterPrompt_OnSelectedItemChanged(object sender, EventArgs e)
|
||||
@@ -68,7 +73,6 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
Tag = tileData
|
||||
};
|
||||
view.Nodes.Add(tileNode);
|
||||
(view.Tag as List<TreeNode>).Add(tileNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using PckStudio.Forms.Additional_Popups.Animation;
|
||||
using PckStudio.Controls;
|
||||
using PckStudio.Core.Json;
|
||||
using PckStudio.Forms.Additional_Popups.Animation;
|
||||
using PckStudio.Json;
|
||||
|
||||
|
||||
@@ -63,8 +64,12 @@ namespace PckStudio.Forms.Additional_Popups.EntityForms
|
||||
|
||||
public DialogResult ShowDialog(IWin32Window owner)
|
||||
{
|
||||
return filterPrompt.ShowDialog(owner);
|
||||
}
|
||||
var f = new ImmersiveForm();
|
||||
filterPrompt.Dock = DockStyle.Fill;
|
||||
filterPrompt.Update();
|
||||
f.Controls.Add(filterPrompt);
|
||||
return f.ShowDialog(owner);
|
||||
}
|
||||
|
||||
private void treeViews_AfterSelect(object sender, TreeViewEventArgs e)
|
||||
{
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
MetroFramework.Controls.MetroLabel metroLabel2;
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FilterPrompt));
|
||||
this.acceptButton = new System.Windows.Forms.Button();
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.filterTextBox = new MetroFramework.Controls.MetroTextBox();
|
||||
this.tabController = new MetroFramework.Controls.MetroTabControl();
|
||||
metroLabel2 = new MetroFramework.Controls.MetroLabel();
|
||||
@@ -40,41 +37,13 @@
|
||||
// metroLabel2
|
||||
//
|
||||
metroLabel2.AutoSize = true;
|
||||
metroLabel2.Location = new System.Drawing.Point(133, 19);
|
||||
metroLabel2.Location = new System.Drawing.Point(2, 6);
|
||||
metroLabel2.Name = "metroLabel2";
|
||||
metroLabel2.Size = new System.Drawing.Size(46, 19);
|
||||
metroLabel2.TabIndex = 16;
|
||||
metroLabel2.Text = "Filter: ";
|
||||
metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark;
|
||||
//
|
||||
// acceptButton
|
||||
//
|
||||
this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
this.acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.acceptButton.ForeColor = System.Drawing.Color.White;
|
||||
this.acceptButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.acceptButton.Location = new System.Drawing.Point(92, 196);
|
||||
this.acceptButton.Name = "acceptButton";
|
||||
this.acceptButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.acceptButton.TabIndex = 7;
|
||||
this.acceptButton.Text = "Save";
|
||||
this.acceptButton.UseVisualStyleBackColor = true;
|
||||
this.acceptButton.Click += new System.EventHandler(this.AcceptBtn_Click);
|
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.cancelButton.ForeColor = System.Drawing.Color.White;
|
||||
this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.cancelButton.Location = new System.Drawing.Point(172, 196);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.cancelButton.TabIndex = 13;
|
||||
this.cancelButton.Text = "Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
this.cancelButton.Click += new System.EventHandler(this.CancelBtn_Click);
|
||||
//
|
||||
// filterTextBox
|
||||
//
|
||||
//
|
||||
@@ -90,7 +59,7 @@
|
||||
this.filterTextBox.CustomButton.UseSelectable = true;
|
||||
this.filterTextBox.CustomButton.Visible = false;
|
||||
this.filterTextBox.Lines = new string[0];
|
||||
this.filterTextBox.Location = new System.Drawing.Point(173, 18);
|
||||
this.filterTextBox.Location = new System.Drawing.Point(42, 5);
|
||||
this.filterTextBox.MaxLength = 32767;
|
||||
this.filterTextBox.Name = "filterTextBox";
|
||||
this.filterTextBox.PasswordChar = '\0';
|
||||
@@ -100,7 +69,7 @@
|
||||
this.filterTextBox.SelectionStart = 0;
|
||||
this.filterTextBox.ShortcutsEnabled = true;
|
||||
this.filterTextBox.Size = new System.Drawing.Size(156, 23);
|
||||
this.filterTextBox.TabIndex = 17;
|
||||
this.filterTextBox.TabIndex = 0;
|
||||
this.filterTextBox.Theme = MetroFramework.MetroThemeStyle.Dark;
|
||||
this.filterTextBox.UseSelectable = true;
|
||||
this.filterTextBox.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
|
||||
@@ -109,48 +78,34 @@
|
||||
//
|
||||
// tabController
|
||||
//
|
||||
this.tabController.Location = new System.Drawing.Point(6, 8);
|
||||
this.tabController.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.tabController.Location = new System.Drawing.Point(0, 34);
|
||||
this.tabController.Name = "tabController";
|
||||
this.tabController.Size = new System.Drawing.Size(326, 184);
|
||||
this.tabController.Style = MetroFramework.MetroColorStyle.White;
|
||||
this.tabController.Size = new System.Drawing.Size(360, 408);
|
||||
this.tabController.Style = MetroFramework.MetroColorStyle.Silver;
|
||||
this.tabController.TabIndex = 18;
|
||||
this.tabController.Theme = MetroFramework.MetroThemeStyle.Dark;
|
||||
this.tabController.UseSelectable = true;
|
||||
//
|
||||
// FilterPromtp
|
||||
// FilterPrompt
|
||||
//
|
||||
this.AcceptButton = this.acceptButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.cancelButton;
|
||||
this.ClientSize = new System.Drawing.Size(338, 228);
|
||||
this.ControlBox = false;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18)))));
|
||||
this.Controls.Add(this.filterTextBox);
|
||||
this.Controls.Add(metroLabel2);
|
||||
this.Controls.Add(this.tabController);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.Controls.Add(this.acceptButton);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "FilterPromtp";
|
||||
this.Resizable = false;
|
||||
this.Style = MetroFramework.MetroColorStyle.Silver;
|
||||
this.Theme = MetroFramework.MetroThemeStyle.Dark;
|
||||
this.Name = "FilterPrompt";
|
||||
this.Size = new System.Drawing.Size(360, 442);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
private void MetroTextBox1_TextChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Button acceptButton;
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private MetroFramework.Controls.MetroTextBox filterTextBox;
|
||||
private MetroFramework.Controls.MetroTabControl tabController;
|
||||
}
|
||||
|
||||
@@ -16,18 +16,14 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using MetroFramework.Forms;
|
||||
using PckStudio.Core.Extensions;
|
||||
|
||||
namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
{
|
||||
internal partial class FilterPrompt : MetroForm
|
||||
internal partial class FilterPrompt : UserControl
|
||||
{
|
||||
public string AcceptButtonText { get => acceptButton.Text; set => acceptButton.Text = value; }
|
||||
public string CancelButtonText { get => cancelButton.Text; set => cancelButton.Text = value; }
|
||||
|
||||
public Color PageBackColor { get; set; } = Color.FromArgb(64, 64, 64);
|
||||
|
||||
private object _selectedItem;
|
||||
@@ -48,10 +44,35 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public TreeView AddFilterPage(string categoryName, string key, FilterPredicate filterPredicate)
|
||||
public new void Update()
|
||||
{
|
||||
base.Update();
|
||||
foreach (TabPage tabpage in tabController.TabPages)
|
||||
{
|
||||
if (tabpage.Controls[0] is not TreeView pageView || pageView.Tag is not TreeView backingView)
|
||||
continue;
|
||||
|
||||
pageView.BeginUpdate();
|
||||
pageView.Nodes.Clear();
|
||||
FilterPredicate filerPredicate = tabpage.Tag as FilterPredicate;
|
||||
foreach (TreeNode node in backingView.Nodes.GetLeafNodes())
|
||||
{
|
||||
if (string.IsNullOrEmpty(filterTextBox.Text) ||
|
||||
node.FullPath.ToLower().Contains(filterTextBox.Text.ToLower()) ||
|
||||
(filerPredicate?.Invoke(filterTextBox.Text, node.Tag) ?? false))
|
||||
{
|
||||
pageView.Nodes.BuildNodeTreeBySeperator(node.FullPath, backingView.PathSeparator);
|
||||
}
|
||||
}
|
||||
pageView.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public TreeView AddFilterPage(string categoryName, string key, FilterPredicate filterPredicate)
|
||||
{
|
||||
_ = categoryName ?? throw new ArgumentNullException(nameof(categoryName));
|
||||
TabPage page = new TabPage(categoryName);
|
||||
page.BorderStyle = BorderStyle.None;
|
||||
page.Name = key ?? categoryName;
|
||||
page.Tag = filterPredicate;
|
||||
var pageView = new TreeView()
|
||||
@@ -64,10 +85,15 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
_selectedItem = e.Node.Tag;
|
||||
Events[nameof(OnSelectedItemChanged)]?.DynamicInvoke(this, EventArgs.Empty);
|
||||
};
|
||||
pageView.Tag = new List<TreeNode>(4);
|
||||
var backingView = new TreeView()
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
BackColor = PageBackColor,
|
||||
};
|
||||
pageView.Tag = backingView;
|
||||
page.Controls.Add(pageView);
|
||||
tabController.TabPages.Add(page);
|
||||
return pageView;
|
||||
return backingView;
|
||||
}
|
||||
|
||||
public TreeView GetByKey(string key)
|
||||
@@ -77,43 +103,7 @@ namespace PckStudio.Forms.Additional_Popups.Animation
|
||||
|
||||
private void filter_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
// Some code in this function is modified code from this StackOverflow answer - MattNL
|
||||
// https://stackoverflow.com/questions/8260322/filter-a-treeview-with-a-textbox-in-a-c-sharp-winforms-app
|
||||
|
||||
// block re-painting control until all objects are loaded
|
||||
foreach (TabPage tabpage in tabController.TabPages)
|
||||
{
|
||||
if (tabpage.Tag is not FilterPredicate filerPredicate || tabpage.Controls[0] is not TreeView pageView || pageView.Tag is not List<TreeNode> pageCache)
|
||||
continue;
|
||||
|
||||
if (string.IsNullOrEmpty(filterTextBox.Text))
|
||||
{
|
||||
pageView.Nodes.Clear();
|
||||
pageView.Nodes.AddRange(pageCache.ToArray());
|
||||
continue;
|
||||
}
|
||||
|
||||
pageView.BeginUpdate();
|
||||
pageView.Nodes.Clear();
|
||||
foreach (TreeNode _node in pageCache)
|
||||
{
|
||||
if (_node.Text.ToLower().Contains(filterTextBox.Text.ToLower()) || filerPredicate(filterTextBox.Text, _node.Tag))
|
||||
{
|
||||
pageView.Nodes.Add((TreeNode)_node.Clone());
|
||||
}
|
||||
}
|
||||
pageView.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
private void AcceptBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = _selectedItem is null ? DialogResult.Cancel : DialogResult.OK;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -117,22 +117,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<<<<<<<< HEAD:PCK-Studio/Forms/Editor/ModelEditor.resx
|
||||
<metadata name="modelContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>178, 17</value>
|
||||
</metadata>
|
||||
<metadata name="textureImageList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>293, 17</value>
|
||||
</metadata>
|
||||
========
|
||||
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="label2.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
>>>>>>>> main:PckStudio.Core/ItemSelectionPopUp.resx
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>15, 41</value>
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
<DependentUpon>PckAssetBrowserEditor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Additional-Popups\FilterPrompt.cs">
|
||||
<SubType>Form</SubType>
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Additional-Popups\FilterPrompt.Designer.cs">
|
||||
<DependentUpon>FilterPrompt.cs</DependentUpon>
|
||||
@@ -440,6 +440,7 @@
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Editor\ModelEditor.resx">
|
||||
<DependentUpon>ModelEditor.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Features\CemuPanel.resx">
|
||||
<DependentUpon>CemuPanel.cs</DependentUpon>
|
||||
|
||||
Reference in New Issue
Block a user