diff --git a/Controllers/RuleTreeController.cs b/Controllers/RuleTreeController.cs index 10f439a..5edb8e8 100644 --- a/Controllers/RuleTreeController.cs +++ b/Controllers/RuleTreeController.cs @@ -5,6 +5,8 @@ using System.Windows.Forms; using NBTExplorer.Windows; using NBTExplorer.Model.Search; using Substrate.Nbt; +using NBTExplorer.Windows.Search; +using System.Drawing; namespace NBTExplorer.Controllers { @@ -99,40 +101,127 @@ namespace NBTExplorer.Controllers } } + private TreeNode CreateIntegralNode (string typeName) + where K : TagNode + where T : IntegralTagRule, new() + { + T rule = new T(); + + using (ValueRuleForm form = new ValueRuleForm(SearchRule.NumericOpStrings) { + Text = "Edit " + typeName + " Tag Rule", + }) { + if (form.ShowDialog() == DialogResult.OK) { + rule.Name = form.TagName; + rule.Value = form.TagValueAsLong; + rule.Operator = form.Operator; + } + else + return null; + } + + TreeNode node = CreateNode(rule); + node.Text = rule.NodeDisplay; + + return node; + } + + private TreeNode CreateFloatNode (string typeName) + where K : TagNode + where T : FloatTagRule, new() + { + T rule = new T(); + + using (ValueRuleForm form = new ValueRuleForm(SearchRule.NumericOpStrings) { + Text = "Edit " + typeName + " Tag Rule", + }) { + if (form.ShowDialog() == DialogResult.OK) { + rule.Name = form.TagName; + rule.Value = form.TagValueAsDouble; + rule.Operator = form.Operator; + } + else + return null; + } + + TreeNode node = CreateNode(rule); + node.Text = rule.NodeDisplay; + + return node; + } + + private TreeNode CreateStringNode (string typeName) + { + StringTagRule rule = new StringTagRule(); + + using (StringRuleForm form = new StringRuleForm(SearchRule.StringOpStrings) { + Text = "Edit " + typeName + " Tag Rule", + }) { + if (form.ShowDialog() == DialogResult.OK) { + rule.Name = form.TagName; + rule.Value = form.TagValue; + rule.Operator = form.Operator; + } + else + return null; + } + + TreeNode node = CreateNode(rule); + node.Text = rule.NodeDisplay; + + return node; + } + + private TreeNode CreateWildcardNode (string typeName) + { + WildcardRule rule = new WildcardRule(); + + using (WildcardRuleForm form = new WildcardRuleForm(SearchRule.WildcardOpStrings) { + Text = "Edit " + typeName + " Rule", + }) { + if (form.ShowDialog() == DialogResult.OK) { + rule.Name = form.TagName; + rule.Value = form.TagValue; + rule.Operator = form.Operator; + } + else + return null; + } + + TreeNode node = CreateNode(rule); + node.Text = rule.NodeDisplay; + + return node; + } + public void CreateNode (TreeNode node, TagType type) { if (node == null || !(node.Tag is GroupRule)) return; GroupRule dataNode = node.Tag as GroupRule; - //if (!dataNode.CanCreateTag(type)) - // return; - TreeNode newNode = null; switch (type) { case TagType.TAG_BYTE: - newNode = CreateNode(new ByteTagRule()); - (newNode.Tag as ByteTagRule).Name = "raining"; - newNode.Text = (newNode.Tag as SearchRule).NodeDisplay; + newNode = CreateIntegralNode("Byte"); break; case TagType.TAG_SHORT: - newNode = CreateNode(new ShortTagRule()); + newNode = CreateIntegralNode("Short"); break; case TagType.TAG_INT: - newNode = CreateNode(new IntTagRule()); + newNode = CreateIntegralNode("Int"); break; case TagType.TAG_LONG: - newNode = CreateNode(new LongTagRule()); + newNode = CreateIntegralNode("Long"); break; case TagType.TAG_FLOAT: - newNode = CreateNode(new FloatTagRule()); + newNode = CreateFloatNode("Float"); break; case TagType.TAG_DOUBLE: - newNode = CreateNode(new DoubleTagRule()); + newNode = CreateFloatNode("Double"); break; case TagType.TAG_STRING: - newNode = CreateNode(new StringTagRule()); + newNode = CreateStringNode("String"); break; } @@ -157,11 +246,14 @@ namespace NBTExplorer.Controllers GroupRule dataNode = node.Tag as GroupRule; - TreeNode newNode = CreateNode(new WildcardRule()); - node.Nodes.Add(newNode); - dataNode.Rules.Add(newNode.Tag as SearchRule); + TreeNode newNode = CreateWildcardNode("Wildcard"); - node.Expand(); + if (newNode != null) { + node.Nodes.Add(newNode); + dataNode.Rules.Add(newNode.Tag as SearchRule); + + node.Expand(); + } } public void CreateWildcardNode () diff --git a/Model/Search/SearchRule.cs b/Model/Search/SearchRule.cs index a617c41..c6bc915 100644 --- a/Model/Search/SearchRule.cs +++ b/Model/Search/SearchRule.cs @@ -34,7 +34,7 @@ namespace NBTExplorer.Model.Search public abstract class SearchRule { - protected static readonly Dictionary NumericOpStrings = new Dictionary() { + public static readonly Dictionary NumericOpStrings = new Dictionary() { { NumericOperator.Equals, "=" }, { NumericOperator.NotEquals, "!=" }, { NumericOperator.GreaterThan, ">" }, @@ -42,7 +42,7 @@ namespace NBTExplorer.Model.Search { NumericOperator.Any, "ANY" }, }; - protected static readonly Dictionary StringOpStrings = new Dictionary() { + public static readonly Dictionary StringOpStrings = new Dictionary() { { StringOperator.Equals, "=" }, { StringOperator.NotEquals, "!=" }, { StringOperator.Contains, "Contains" }, @@ -52,7 +52,7 @@ namespace NBTExplorer.Model.Search { StringOperator.Any, "ANY" }, }; - protected static readonly Dictionary WildcardOpStrings = new Dictionary() { + public static readonly Dictionary WildcardOpStrings = new Dictionary() { { WildcardOperator.Equals, "=" }, { WildcardOperator.NotEquals, "!=" }, { WildcardOperator.Any, "ANY" }, @@ -189,7 +189,7 @@ namespace NBTExplorer.Model.Search public class IntTagRule : IntegralTagRule { } - public class LongTagRule : IntegralTagRule + public class LongTagRule : IntegralTagRule { } public abstract class FloatTagRule : TagRule diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index bc9ecd2..3008101 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -208,6 +208,24 @@ + + Form + + + WildcardRuleForm.cs + + + Form + + + StringRuleForm.cs + + + Form + + + ValueRuleForm.cs + CancelSearchForm.cs @@ -252,6 +270,15 @@ HexBox.cs + + WildcardRuleForm.cs + + + StringRuleForm.cs + + + ValueRuleForm.cs + Designer diff --git a/Windows/IconRegistry.cs b/Windows/IconRegistry.cs index 27712db..a63260c 100644 --- a/Windows/IconRegistry.cs +++ b/Windows/IconRegistry.cs @@ -22,6 +22,11 @@ namespace NBTExplorer.Windows return DefaultIcon; } + public int Lookup () + { + return Lookup(typeof(T)); + } + public void Register (Type type, int iconIndex) { _iconRegistry[type] = iconIndex; diff --git a/Windows/Search/StringRuleForm.Designer.cs b/Windows/Search/StringRuleForm.Designer.cs new file mode 100644 index 0000000..9249209 --- /dev/null +++ b/Windows/Search/StringRuleForm.Designer.cs @@ -0,0 +1,150 @@ +namespace NBTExplorer.Windows.Search +{ + partial class StringRuleForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose (bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent () + { + this.label1 = new System.Windows.Forms.Label(); + this._textName = new System.Windows.Forms.TextBox(); + this._textValue = new System.Windows.Forms.TextBox(); + this._selectOperator = new System.Windows.Forms.ComboBox(); + this._ruleGroup = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this._buttonOK = new System.Windows.Forms.Button(); + this._buttonCancel = new System.Windows.Forms.Button(); + this._ruleGroup.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(60, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Tag Name:"; + // + // _textName + // + this._textName.Location = new System.Drawing.Point(102, 19); + this._textName.Name = "_textName"; + this._textName.Size = new System.Drawing.Size(142, 20); + this._textName.TabIndex = 1; + // + // _textValue + // + this._textValue.Location = new System.Drawing.Point(102, 72); + this._textValue.Name = "_textValue"; + this._textValue.Size = new System.Drawing.Size(142, 20); + this._textValue.TabIndex = 2; + // + // _selectOperator + // + this._selectOperator.FormattingEnabled = true; + this._selectOperator.Location = new System.Drawing.Point(102, 45); + this._selectOperator.Name = "_selectOperator"; + this._selectOperator.Size = new System.Drawing.Size(142, 21); + this._selectOperator.TabIndex = 3; + // + // _ruleGroup + // + this._ruleGroup.Controls.Add(this.label2); + this._ruleGroup.Controls.Add(this._textName); + this._ruleGroup.Controls.Add(this._selectOperator); + this._ruleGroup.Controls.Add(this.label1); + this._ruleGroup.Controls.Add(this._textValue); + this._ruleGroup.Location = new System.Drawing.Point(12, 12); + this._ruleGroup.Name = "_ruleGroup"; + this._ruleGroup.Size = new System.Drawing.Size(250, 98); + this._ruleGroup.TabIndex = 4; + this._ruleGroup.TabStop = false; + this._ruleGroup.Text = "Rule"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(59, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Tag Value:"; + // + // _buttonOK + // + this._buttonOK.Location = new System.Drawing.Point(186, 116); + this._buttonOK.Name = "_buttonOK"; + this._buttonOK.Size = new System.Drawing.Size(75, 23); + this._buttonOK.TabIndex = 5; + this._buttonOK.Text = "OK"; + this._buttonOK.UseVisualStyleBackColor = true; + this._buttonOK.Click += new System.EventHandler(this._buttonOK_Click); + // + // _buttonCancel + // + this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this._buttonCancel.Location = new System.Drawing.Point(105, 116); + this._buttonCancel.Name = "_buttonCancel"; + this._buttonCancel.Size = new System.Drawing.Size(75, 23); + this._buttonCancel.TabIndex = 6; + this._buttonCancel.Text = "Cancel"; + this._buttonCancel.UseVisualStyleBackColor = true; + // + // ValueRuleForm + // + this.AcceptButton = this._buttonOK; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this._buttonCancel; + this.ClientSize = new System.Drawing.Size(273, 151); + this.Controls.Add(this._buttonCancel); + this.Controls.Add(this._buttonOK); + this.Controls.Add(this._ruleGroup); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ValueRuleForm"; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Text = "Edit Value Rule"; + this.TopMost = true; + this._ruleGroup.ResumeLayout(false); + this._ruleGroup.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox _textName; + private System.Windows.Forms.TextBox _textValue; + private System.Windows.Forms.ComboBox _selectOperator; + private System.Windows.Forms.GroupBox _ruleGroup; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button _buttonOK; + private System.Windows.Forms.Button _buttonCancel; + } +} \ No newline at end of file diff --git a/Windows/Search/StringRuleForm.cs b/Windows/Search/StringRuleForm.cs new file mode 100644 index 0000000..cec9a25 --- /dev/null +++ b/Windows/Search/StringRuleForm.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using NBTExplorer.Model.Search; + +namespace NBTExplorer.Windows.Search +{ + public partial class StringRuleForm : Form + { + public StringRuleForm (Dictionary operators) + { + InitializeComponent(); + + foreach (var op in operators) + _selectOperator.Items.Add(op.Key); + + _selectOperator.SelectedIndex = 0; + } + + public string RuleGroupName + { + get { return _ruleGroup.Text; } + set { _ruleGroup.Text = value; } + } + + public string TagName + { + get { return _textName.Text; } + set { _textName.Text = value; } + } + + public string TagValue + { + get { return _textValue.Text; } + set { _textValue.Text = value; } + } + + public StringOperator Operator + { + get { return (StringOperator)_selectOperator.SelectedItem; } + set { _selectOperator.SelectedItem = value; } + } + + private void _buttonOK_Click (object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TagName)) { + MessageBox.Show(this, "Rule missing name"); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/Windows/Search/StringRuleForm.resx b/Windows/Search/StringRuleForm.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Windows/Search/StringRuleForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Windows/Search/ValueRuleForm.Designer.cs b/Windows/Search/ValueRuleForm.Designer.cs new file mode 100644 index 0000000..26782ed --- /dev/null +++ b/Windows/Search/ValueRuleForm.Designer.cs @@ -0,0 +1,150 @@ +namespace NBTExplorer.Windows.Search +{ + partial class ValueRuleForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose (bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent () + { + this.label1 = new System.Windows.Forms.Label(); + this._textName = new System.Windows.Forms.TextBox(); + this._textValue = new System.Windows.Forms.TextBox(); + this._selectOperator = new System.Windows.Forms.ComboBox(); + this._ruleGroup = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this._buttonOK = new System.Windows.Forms.Button(); + this._buttonCancel = new System.Windows.Forms.Button(); + this._ruleGroup.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(60, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Tag Name:"; + // + // _textName + // + this._textName.Location = new System.Drawing.Point(102, 19); + this._textName.Name = "_textName"; + this._textName.Size = new System.Drawing.Size(142, 20); + this._textName.TabIndex = 1; + // + // _textValue + // + this._textValue.Location = new System.Drawing.Point(102, 72); + this._textValue.Name = "_textValue"; + this._textValue.Size = new System.Drawing.Size(142, 20); + this._textValue.TabIndex = 2; + // + // _selectOperator + // + this._selectOperator.FormattingEnabled = true; + this._selectOperator.Location = new System.Drawing.Point(102, 45); + this._selectOperator.Name = "_selectOperator"; + this._selectOperator.Size = new System.Drawing.Size(142, 21); + this._selectOperator.TabIndex = 3; + // + // _ruleGroup + // + this._ruleGroup.Controls.Add(this.label2); + this._ruleGroup.Controls.Add(this._textName); + this._ruleGroup.Controls.Add(this._selectOperator); + this._ruleGroup.Controls.Add(this.label1); + this._ruleGroup.Controls.Add(this._textValue); + this._ruleGroup.Location = new System.Drawing.Point(12, 12); + this._ruleGroup.Name = "_ruleGroup"; + this._ruleGroup.Size = new System.Drawing.Size(250, 98); + this._ruleGroup.TabIndex = 4; + this._ruleGroup.TabStop = false; + this._ruleGroup.Text = "Rule"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(59, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Tag Value:"; + // + // _buttonOK + // + this._buttonOK.Location = new System.Drawing.Point(186, 116); + this._buttonOK.Name = "_buttonOK"; + this._buttonOK.Size = new System.Drawing.Size(75, 23); + this._buttonOK.TabIndex = 5; + this._buttonOK.Text = "OK"; + this._buttonOK.UseVisualStyleBackColor = true; + this._buttonOK.Click += new System.EventHandler(this._buttonOK_Click); + // + // _buttonCancel + // + this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this._buttonCancel.Location = new System.Drawing.Point(105, 116); + this._buttonCancel.Name = "_buttonCancel"; + this._buttonCancel.Size = new System.Drawing.Size(75, 23); + this._buttonCancel.TabIndex = 6; + this._buttonCancel.Text = "Cancel"; + this._buttonCancel.UseVisualStyleBackColor = true; + // + // ValueRuleForm + // + this.AcceptButton = this._buttonOK; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this._buttonCancel; + this.ClientSize = new System.Drawing.Size(273, 151); + this.Controls.Add(this._buttonCancel); + this.Controls.Add(this._buttonOK); + this.Controls.Add(this._ruleGroup); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ValueRuleForm"; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Text = "Edit Value Rule"; + this.TopMost = true; + this._ruleGroup.ResumeLayout(false); + this._ruleGroup.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox _textName; + private System.Windows.Forms.TextBox _textValue; + private System.Windows.Forms.ComboBox _selectOperator; + private System.Windows.Forms.GroupBox _ruleGroup; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button _buttonOK; + private System.Windows.Forms.Button _buttonCancel; + } +} \ No newline at end of file diff --git a/Windows/Search/ValueRuleForm.cs b/Windows/Search/ValueRuleForm.cs new file mode 100644 index 0000000..e618f42 --- /dev/null +++ b/Windows/Search/ValueRuleForm.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using NBTExplorer.Model.Search; + +namespace NBTExplorer.Windows.Search +{ + public partial class ValueRuleForm : Form + { + public ValueRuleForm (Dictionary operators) + { + InitializeComponent(); + + foreach (var op in operators) + _selectOperator.Items.Add(op.Key); + + _selectOperator.SelectedIndex = 0; + } + + public string RuleGroupName + { + get { return _ruleGroup.Text; } + set { _ruleGroup.Text = value; } + } + + public string TagName + { + get { return _textName.Text; } + set { _textName.Text = value; } + } + + public string TagValue + { + get { return _textValue.Text; } + set { _textValue.Text = value; } + } + + public long TagValueAsLong + { + get + { + long lvalue; + if (long.TryParse(TagValue, out lvalue)) + return lvalue; + + double fvalue; + if (double.TryParse(TagValue, out fvalue)) + return (long)fvalue; + + return 0; + } + } + + public double TagValueAsDouble + { + get + { + double fvalue; + if (double.TryParse(TagValue, out fvalue)) + return fvalue; + + return 0; + } + } + + public NumericOperator Operator + { + get { return (NumericOperator)_selectOperator.SelectedItem; } + set { _selectOperator.SelectedItem = value; } + } + + private void _buttonOK_Click (object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TagName) || !TryParseValue()) { + MessageBox.Show(this, "Rule missing name or value"); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private bool TryParseValue () + { + if (Operator == NumericOperator.Any) + return true; + + long lvalue; + double fvalue; + if (long.TryParse(TagValue, out lvalue) || double.TryParse(TagValue, out fvalue)) + return true; + + return false; + } + } +} diff --git a/Windows/Search/ValueRuleForm.resx b/Windows/Search/ValueRuleForm.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Windows/Search/ValueRuleForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Windows/Search/WildcardRuleForm.Designer.cs b/Windows/Search/WildcardRuleForm.Designer.cs new file mode 100644 index 0000000..bc64604 --- /dev/null +++ b/Windows/Search/WildcardRuleForm.Designer.cs @@ -0,0 +1,150 @@ +namespace NBTExplorer.Windows.Search +{ + partial class WildcardRuleForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose (bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent () + { + this.label1 = new System.Windows.Forms.Label(); + this._textName = new System.Windows.Forms.TextBox(); + this._textValue = new System.Windows.Forms.TextBox(); + this._selectOperator = new System.Windows.Forms.ComboBox(); + this._ruleGroup = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this._buttonOK = new System.Windows.Forms.Button(); + this._buttonCancel = new System.Windows.Forms.Button(); + this._ruleGroup.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(60, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Tag Name:"; + // + // _textName + // + this._textName.Location = new System.Drawing.Point(102, 19); + this._textName.Name = "_textName"; + this._textName.Size = new System.Drawing.Size(142, 20); + this._textName.TabIndex = 1; + // + // _textValue + // + this._textValue.Location = new System.Drawing.Point(102, 72); + this._textValue.Name = "_textValue"; + this._textValue.Size = new System.Drawing.Size(142, 20); + this._textValue.TabIndex = 2; + // + // _selectOperator + // + this._selectOperator.FormattingEnabled = true; + this._selectOperator.Location = new System.Drawing.Point(102, 45); + this._selectOperator.Name = "_selectOperator"; + this._selectOperator.Size = new System.Drawing.Size(142, 21); + this._selectOperator.TabIndex = 3; + // + // _ruleGroup + // + this._ruleGroup.Controls.Add(this.label2); + this._ruleGroup.Controls.Add(this._textName); + this._ruleGroup.Controls.Add(this._selectOperator); + this._ruleGroup.Controls.Add(this.label1); + this._ruleGroup.Controls.Add(this._textValue); + this._ruleGroup.Location = new System.Drawing.Point(12, 12); + this._ruleGroup.Name = "_ruleGroup"; + this._ruleGroup.Size = new System.Drawing.Size(250, 98); + this._ruleGroup.TabIndex = 4; + this._ruleGroup.TabStop = false; + this._ruleGroup.Text = "Rule"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(59, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Tag Value:"; + // + // _buttonOK + // + this._buttonOK.Location = new System.Drawing.Point(186, 116); + this._buttonOK.Name = "_buttonOK"; + this._buttonOK.Size = new System.Drawing.Size(75, 23); + this._buttonOK.TabIndex = 5; + this._buttonOK.Text = "OK"; + this._buttonOK.UseVisualStyleBackColor = true; + this._buttonOK.Click += new System.EventHandler(this._buttonOK_Click); + // + // _buttonCancel + // + this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this._buttonCancel.Location = new System.Drawing.Point(105, 116); + this._buttonCancel.Name = "_buttonCancel"; + this._buttonCancel.Size = new System.Drawing.Size(75, 23); + this._buttonCancel.TabIndex = 6; + this._buttonCancel.Text = "Cancel"; + this._buttonCancel.UseVisualStyleBackColor = true; + // + // ValueRuleForm + // + this.AcceptButton = this._buttonOK; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this._buttonCancel; + this.ClientSize = new System.Drawing.Size(273, 151); + this.Controls.Add(this._buttonCancel); + this.Controls.Add(this._buttonOK); + this.Controls.Add(this._ruleGroup); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ValueRuleForm"; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Text = "Edit Value Rule"; + this.TopMost = true; + this._ruleGroup.ResumeLayout(false); + this._ruleGroup.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox _textName; + private System.Windows.Forms.TextBox _textValue; + private System.Windows.Forms.ComboBox _selectOperator; + private System.Windows.Forms.GroupBox _ruleGroup; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button _buttonOK; + private System.Windows.Forms.Button _buttonCancel; + } +} \ No newline at end of file diff --git a/Windows/Search/WildcardRuleForm.cs b/Windows/Search/WildcardRuleForm.cs new file mode 100644 index 0000000..71e152d --- /dev/null +++ b/Windows/Search/WildcardRuleForm.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using NBTExplorer.Model.Search; + +namespace NBTExplorer.Windows.Search +{ + public partial class WildcardRuleForm : Form + { + public WildcardRuleForm (Dictionary operators) + { + InitializeComponent(); + + foreach (var op in operators) + _selectOperator.Items.Add(op.Key); + + _selectOperator.SelectedIndex = 0; + } + + public string RuleGroupName + { + get { return _ruleGroup.Text; } + set { _ruleGroup.Text = value; } + } + + public string TagName + { + get { return _textName.Text; } + set { _textName.Text = value; } + } + + public string TagValue + { + get { return _textValue.Text; } + set { _textValue.Text = value; } + } + + public WildcardOperator Operator + { + get { return (WildcardOperator)_selectOperator.SelectedItem; } + set { _selectOperator.SelectedItem = value; } + } + + private void _buttonOK_Click (object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TagName)) { + MessageBox.Show(this, "Rule missing name"); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/Windows/Search/WildcardRuleForm.resx b/Windows/Search/WildcardRuleForm.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Windows/Search/WildcardRuleForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file