public static void Remove(int index) { // return if index is invalid if (index < 0) { return; } // remove the item at the index string key = (string)MainWindow.ListBox.Items[index]; ClipboardItem clipboardItem = LocalClipboard.Dict[key]; LocalClipboard.Remove(clipboardItem.KeyText, clipboardItem); // if there was an item located after the removed item, select that item if (LocalClipboard.MainWindow.ListBox.Items.Count > index) { LocalClipboard.MainWindow.ListBox.SelectedIndex = index; } // else select the item located before the removed item else { LocalClipboard.MainWindow.ListBox.SelectedIndex = index - 1; } // notify the user of the successful operation for 3 seconds MsgLabel.Normal("Item removed!"); }
public static void Add(string key, ClipboardItem value) { try { // add to the back-end dictionary LocalClipboard.Dict.Add(key, value); } // exception thrown on attempt to add a duplicate key to the dict catch (ArgumentException) { // store item with the same key ClipboardItem duplicateKeyItem = LocalClipboard.Dict[key]; // remove old item and prepare to replace with new item LocalClipboard.Remove(duplicateKeyItem.KeyText, duplicateKeyItem); // add new item LocalClipboard.Dict.Add(key, value); } // add to back-end string collection of keys LocalClipboard.Keys.Insert(0, key); // add to visual clipboard last LocalClipboard.MainWindow.ListBox.Items.Insert(0, key); }
protected bool SetKeyDiff() { // calculate KeyDiff so that we can differentiate the items with duplicate key text for (string key = this.KeyText; LocalClipboard.Dict.ContainsKey(key); key = this.KeyText + this.KeyDiff) { // store item with the same key ClipboardItem duplicateKeyItem = LocalClipboard.Dict[key]; // if keys are equivalent but the items are not, increment KeyDiff and continue loop if (!this.IsEquivalent(duplicateKeyItem)) { this.KeyDiff++; continue; } // if old item is at the target index, then there is no need to add this item if (LocalClipboard.Keys.IndexOf(key) == 0) { return(false); } // if this point is reached, remove the old item and break from the loop LocalClipboard.Remove(duplicateKeyItem.KeyText, duplicateKeyItem); break; } return(true); }
private void RemoveBtn_Click(object sender, EventArgs e) { // set focus back to the local clipboard LocalClipboard.Focus(); // remove the current index of the local clipboard LocalClipboard.Remove(); }
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!"); } }
/// <summary> /// Moves item to new index /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="index"></param> public static void Move(string key, ClipboardItem value, int index) { LocalClipboard.Remove(key, value); LocalClipboard.Insert(key, value, index); }
public static void Remove() { LocalClipboard.Remove(MainWindow.ListBox.SelectedIndex); }