public void Edit(List<Snippet> editingTheseSnippets) { if (comboBox1.Items.Contains(PropertyValue.MULTIPLE_VALUES)) comboBox1.Items.Remove(PropertyValue.MULTIPLE_VALUES); // if there's no change, don't redo this processing if (this.propertySnippet == null || editingTheseSnippets.Equals(this.editingTheseSnippets)) return; this.editingTheseSnippets = editingTheseSnippets; UpdatePropertyList(); // cycle through the currentSnippets // to make sure that each one shares the propertyValue PropertyValue hopingFor = null; // the first propertyValue we find. The other // ones should match hopingFor bool areAllTheSame = true; foreach (Snippet snippet in editingTheseSnippets) { Snippet propertyRaw = null; PropertyValue property = null; try { propertyRaw = snippet.GetPropertyValue(propertySnippet); } catch (MultiplePropertiesSelectedException) { // this is only ONE type of multiple properties, when the // snippet sits under multiple children of the property property = PropertyValue.MULTIPLE_VALUES; areAllTheSame = false; break; } // translate the null to an undefined prop if (propertyRaw == null) property = PropertyValue.UNDEFINED_PROPERTY; else property = new PropertyValue(propertyRaw); // if it's the first time around if (hopingFor == null) hopingFor = property; else { if (!hopingFor.Equals(property)) { // this is the OTHER type of multiple properties, // when several snippets in the selection group have // different values of the property. areAllTheSame = false; break; } } } try { // we're selecting, so we have to shut off the events that // are for user selection suspendAfterSelected = true; if (!areAllTheSame) { comboBox1.Items.Add(PropertyValue.MULTIPLE_VALUES); comboBox1.SelectedItem = PropertyValue.MULTIPLE_VALUES; } else { if (comboBox1.Items.Contains(PropertyValue.MULTIPLE_VALUES)) comboBox1.Items.Remove(PropertyValue.MULTIPLE_VALUES); foreach (PropertyValue val in comboBox1.Items) { if (val.Equals(hopingFor)) { comboBox1.SelectedItem = val; break; } } } } finally { // turn events back on suspendAfterSelected = false; } }
void SelectProperty(PropertyValue selectedVal, Snippet snippet, Snippet currentValue) { if (selectedVal == PropertyValue.UNDEFINED_PROPERTY) { DialogResult okay = DialogResult.Yes; if (snippet.ParentCount == 1) { okay = MessageBox.Show( "You are about to permanently delete " + snippet.Title + ". " + "Are you sure?", MainForm.DialogCaption, MessageBoxButtons.YesNo); } if (okay == DialogResult.Yes) currentValue.RemoveChildSnippet(snippet); } else { if (currentValue != selectedVal.Snippet) snippet.MoveSnippet(currentValue, selectedVal.Snippet); } }
void comboBox1_OnKeyUpEnter() { string newText = comboBox1.Text; if (newText.Equals(PropertyValue.MULTIPLE_VALUES.ToString()) || newText.Equals(PropertyValue.UNDEFINED_PROPERTY.ToString())) return; bool isNew = true; foreach (PropertyValue value in comboBox1.Items) { if (value.ToString().Equals(newText)) { isNew = false; comboBox1.SelectedItem = value; break; } } if (isNew) { DialogResult result = MessageBox.Show("Property value " + newText + " does not exist. Create snippet?", MainForm.DialogCaption, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Snippet newValue = propertySnippet.AddChildSnippet(); newValue.Title = newText; PropertyValue value = new PropertyValue(newValue); comboBox1.Items.Add(value); comboBox1.SelectedItem = value; } } else { } }
void SelectProperty(PropertyValue selectedVal, Snippet snippet, List<Snippet> currentValues) { DialogResult okay = DialogResult.Yes; if (selectedVal == PropertyValue.UNDEFINED_PROPERTY) { if (currentValues.Count == snippet.ParentCount) { okay = MessageBox.Show( "You are about to permanently delete " + snippet.Title + ". " + "Are you sure?", MainForm.DialogCaption, MessageBoxButtons.YesNo); } if (okay == DialogResult.Yes) { foreach (Snippet currentValue in currentValues) { currentValue.RemoveChildSnippet(snippet); } } } // if it's already got this value, then just remove all the other ones else if (currentValues.Contains(selectedVal.Snippet)) { foreach (Snippet currentValue in currentValues) { if (currentValue != selectedVal.Snippet) { currentValue.RemoveChildSnippet(snippet); } } } else { // first add it to the new value selectedVal.Snippet.AddChildSnippet(snippet); // and now delete the old ones foreach (Snippet currentValue in currentValues) { currentValue.RemoveChildSnippet(snippet); } } }
public void UpdatePropertyList() { comboBox1.Items.Clear(); comboBox1.Items.Add(PropertyValue.UNDEFINED_PROPERTY); //if (editingTheseSnippets != null) // comboBox1.Items.Add(PropertyValue.MULTIPLE_VALUES); foreach (Snippet child in propertySnippet.Children) { PropertyValue value = new PropertyValue(child); comboBox1.Items.Add(value); } label1.Text = propertySnippet.Title; }