private void EditTextItem_Click(object sender, EventArgs e) { // check for valid SelectedIndex val before continuing if (listBox.SelectedIndex < 0) { MsgLabel.Normal("No text item is selected!"); return; } // check for TextItem var oitem = LocalClipboard.Dict[(string)listBox.SelectedItem]; if (oitem.Type != ClipboardItem.TypeEnum.Text) { MsgLabel.Normal("Selected item is not a text item!"); return; } // get new text string otext = ((TextItem)oitem).Text; string ntext = wnd.ShowDialog(otext); // edit item if text is valid if (ntext == null) { return; } else { int i = listBox.SelectedIndex; LocalClipboard.Remove(i); var nitem = new TextItem(this, ntext); LocalClipboard.Move(nitem.KeyText, nitem, i); MsgLabel.Normal("Text item edited!"); } }
private void OnArrowKeyDown(KeyEventArgs e) { // vars regarding listbox data int total = this.listBox.Items.Count; int current = this.listBox.SelectedIndex; // base case 1: nothing in the clipboard if (total == 0) { return; } // base case 2: no item is selected, or only one item exists if (current < 0 || total == 1) { this.listBox.SelectedIndex = 0; return; } // store the item at current index ClipboardItem clipboardItem = LocalClipboard.Dict[(string)listBox.Items[current]]; // store new index for the item and/or index to be moved int newIndex; // base case 3: current is at the last index if (current == total - 1) { // if box isn't checked, no wrapping or moving is needed if (!this.wrapKeysItem.Checked) { return; } // we will be wrapping to the top, so newIndex is set to the top index, i.e. 0 newIndex = 0; // move current item to the top index if shift is pressed if (e.Shift) { LocalClipboard.Move(clipboardItem.KeyText, clipboardItem, newIndex); // wrap selected index to the top index only if the box is checked if (this.ChangeTopBottom.Checked) { this.listBox.SelectedIndex = newIndex; } else { this.listBox.SelectedIndex = current; } } // else don't move the current item, and wrap the selected index unconditionally else { this.listBox.SelectedIndex = newIndex; } return; } // store whether the selected index should be changed bool changeIndex = true; // if ctrl is being pressed, set newIndex to the bottom index if (e.Control) { newIndex = total - 1; // selected index should be unchanged if we're moving an item // to the top/bottom, but the box is unchecked if (e.Shift && !this.ChangeTopBottom.Checked) { changeIndex = false; } } // else set newIndex to current + 1 else { newIndex = current + 1; // changeIndex is unconditionally true if ctrl isn't being pressed } // move item to new index if shift is pressed if (e.Shift) { LocalClipboard.Move(clipboardItem.KeyText, clipboardItem, newIndex); } // move selected index to new index if bool is satisfied if (changeIndex) { this.listBox.SelectedIndex = newIndex; } else { this.listBox.SelectedIndex = current; } }