Grasshopper

algorithmic modeling for Rhino

Can someone point me to where I am making a mistake in my Menu_AppendTextItem implementation. It seems to be working up to a point where I hit "Commit Changes" and at that point the value gets reset to the default value assigned to the text Box: "Custom Key". 

Ps. Is there a way to subscribe to "Commit Changes" instead? I think its not necessary to execute this even logic for every letter that user types in...am I right? This event fires multiple times when I am typing into the text box...

Ideas? 

bool hasKey = false;
string KeyValue = string.Empty;

protected override void AppendAdditionalComponentMenuItems(System.Windows.Forms.ToolStripDropDown menu)
{
GH_DocumentObject.Menu_AppendTextItem(
menu,
"Custom Key",
new GH_MenuTextBox.KeyDownEventHandler(Menu_KeyDownHandler),
new GH_MenuTextBox.TextChangedEventHandler(Menu_TextChangedEventHandler),
true);
}

private void Menu_KeyDownHandler(object sender, KeyEventArgs e) { }

private void Menu_TextChangedEventHandler(object sender, string text)
{
base.RecordUndoEvent("Custom Key Entered");
if (text != string.Empty)
{
this.hasKey = true;
this.KeyValue = text;
}
else
{
this.hasKey = false;
this.KeyValue = string.Empty;
}
this.ExpireSolution(true);
}

public override bool Write(GH_IO.Serialization.GH_IWriter writer)
{
writer.SetString("KeyValue", this.KeyValue);
return base.Write(writer);
}
public override bool Read(GH_IO.Serialization.GH_IReader reader)
{
this.KeyValue = string.Empty;
reader.TryGetString("KeyValue", ref this.KeyValue);
return base.Read(reader);
}

Views: 310

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service