//public static void Rename(string okey, string nkey) //{ // int i = MainWindow.ListBox.Items.IndexOf(okey); // var val = Dict[okey]; // switch (val.Type) // { // case ClipboardItem.TypeEnum.Text: // break; // case ClipboardItem.TypeEnum.FileDropList: // break; // case ClipboardItem.TypeEnum.Image: // break; // case ClipboardItem.TypeEnum.Audio: // break; // case ClipboardItem.TypeEnum.Custom: // break; // } // Remove(okey, val); // Insert(nkey, val, i); //} /// <summary> /// This method clears the structures, files, and folders involved in /// the local clipboard. /// /// Note that the backup file is preserved in case the clear operation /// was accidental. /// </summary> public static void Clear() { // first, write the current clipboard contents to the backup file LocalClipboard.BackupClipboard(); // clear each data structure associated with the local clipboard LocalClipboard.MainWindow.ListBox.Items.Clear(); LocalClipboard.Keys.Clear(); LocalClipboard.Dict.Clear(); // delete the CLIPBOARD file LocalClipboard.ClipboardFile.Delete(); // recursively delete each item folder if it exists if (LocalClipboard.ImageFolder.Exists) { LocalClipboard.ImageFolder.Delete(true); } if (LocalClipboard.AudioFolder.Exists) { LocalClipboard.AudioFolder.Delete(true); } if (LocalClipboard.CustomFolder.Exists) { LocalClipboard.CustomFolder.Delete(true); } MsgLabel.Normal("All items cleared!"); }
public static void FromFile() { // if CLIPBOARD file is missing or empty if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0) { return; } // store the current contents of the clipboard file string clipboardString = LocalClipboard.GetClipboard(); // update the backup file with clipboardString LocalClipboard.BackupClipboard(clipboardString); // traverse clipboardString via StringReader using (StringReader strRead = new StringReader(clipboardString)) { // peek returns -1 if no more characters are available while (strRead.Peek() != -1) { // Type ClipboardItem.TypeEnum type = (ClipboardItem.TypeEnum)strRead.Read(); // KeyDiff ushort keyDiff = ushort.Parse(strRead.ReadLine()); // remaining operations depend on the type of item switch (type) { case ClipboardItem.TypeEnum.Text: _ = new TextItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.FileDropList: _ = new FileItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Image: _ = new ImageItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Audio: _ = new AudioItem(LocalClipboard.MainWindow, keyDiff, strRead); break; case ClipboardItem.TypeEnum.Custom: _ = new CustomItem(LocalClipboard.MainWindow, keyDiff, strRead); break; } } } }
/// <summary> /// This method writes the current contents of the clipboard file to /// the backup file. /// /// This is used when clearing the local clipboard and when reading /// from the clipboard file on program startup. /// </summary> private static void BackupClipboard() { // if CLIPBOARD file is missing or empty if (!LocalClipboard.ClipboardFile.Exists || LocalClipboard.ClipboardFile.Length == 0) { return; } // first, get contents of the clipboard file string clipboardString = LocalClipboard.GetClipboard(); // call helper with clipboardString as an arg LocalClipboard.BackupClipboard(clipboardString); }