private void DefaultConfigItem_Click(object sender, EventArgs e) { // load default config Config.LoadDefaults(); MsgLabel.Normal("Default config loaded!"); }
private void HelpItem_Click(object sender, EventArgs e) { // notify the user that we're attempting to open the help file MsgLabel.Normal("Opening help.txt..."); // create or open help.txt and overwrite its contents File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "help.txt"), "QUICK HELP:\n" + "Q: How do I add items to MultiPaste?\n" + "A: Copy like you normally would (e.g. Ctrl + C). MultiPaste also supports drag-and-drop on most items!\n\n" + "Q: How do I exit the program?\n" + "A: Click on File->Exit, or right click MultiPaste from the system tray and click Exit.\n\n" + "Q: How do I minimize MultiPaste to the taskbar?\n" + "A: Press the Esc key or the minimize button at the top right.\n\n" + "Q: How do I minimize to the system tray so that it doesn't show up in the taskbar?\n" + "A: Click on the X button, or press Alt + F4.\n\n" + "Q: Is there a global hotkey I can use to show/hide MultiPaste?\n" + "A: Yes there is! Ctrl + Alt + V is registered as a global show/hide hotkey for MultiPaste.\n\n" + "Q: How do I paste the thing that I copied?\n" + "A: Double-click the item to copy it to the Windows clipboard. You can also press the Enter key.\n\n" + "Q: How do I delete one of the things that I've copied?\n" + "A: Click on the Remove button. You can also press the Delete key.\n\n" + "Q: What if I want to clear all the items that I've copied without individually deleting all of them?\n" + "A: Click on File->Clear All Copied Items. You can also press Ctrl + K.\n\n" + "Q: How do I relocate a copied item to a different index?\n" + "A: When the item is selected, hold the Shift key while pressing the up or down arrow key.\n\n" + "Q: Is there a way to quickly relocate an item to the top/bottom?\n" + "A: Yes there is! Hold the Ctrl key along with the above relocating instructions."); // open the file Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "help.txt")); // notify the user of the successful operation for 3 seconds MsgLabel.Normal("help.txt is open!"); }
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 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 TextItem(MainWindow mainWindow, string text) : base(mainWindow, TypeEnum.Text) { // ensure param str is valid before continuing if (text == null || text.Length == 0) { return; } // store param str this.Text = text; // set beginning part of KeyText base.KeyText = "Text: "; // append to KeyText given Text if (this.Text.Length > LocalClipboard.CHAR_LIMIT - base.KeyText.Length) { base.KeyText += Text.Substring(0, LocalClipboard.CHAR_LIMIT - base.KeyText.Length) + "..."; } else { base.KeyText += Text; } // if setting KeyDiff returns false, then there is an equivalent item at index 0 if (!base.SetKeyDiff()) { return; } // add KeyDiff to KeyText if needed if (base.KeyDiff != 0) { base.KeyText += base.KeyDiff; } /// Char order: /// /// 1. Type /// 2. KeyDiff /// 3. Text.Length /// 4. Text /// string keyDiffStr = base.KeyDiff.ToString(); string textLenStr = this.Text.Length.ToString(); base.FileChars = (char)base.Type + keyDiffStr + Environment.NewLine + textLenStr + Environment.NewLine + this.Text; // add to local clipboard with CLIPBOARD file LocalClipboard.AddWithFile(base.KeyText, this); // move selected index to that of this instance if box is checked if (base.mainWindow.MoveToCopied.Checked) { base.mainWindow.ListBox.SelectedIndex = LocalClipboard.Keys.IndexOf(base.KeyText); } MsgLabel.Normal("Text item added!"); }
private void ShowCustomItem_Click(object sender, EventArgs e) { this.RestrictTypes(); // notify the user of the change if (showCustomItem.Checked) { MsgLabel.Normal("Custom items displayed!"); } else { MsgLabel.Normal("Custom items hidden!"); } }
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> /// This method communicates to the user that a fatal error occurred. /// /// First, it displays msg param to the user via the msg label, /// followed by directing the user to err.log to view the details /// of the error. /// /// This method also writes to the err.log file in the program's /// directory, and then terminates the process after sleeping for /// the duration of the message being displayed to the user. /// </summary> /// <param name="msg">brief explanation of the fatal error</param> /// <param name="msgExtended">error msg explained in more detail</param> /// <param name="solutions">possible solution(s) that the user could implement</param> public static void Fatal(string msg, string msgExtended, string solutions) { // set string that will be written to err.log string log = "Date: " + DateTime.Now.ToString() + Environment.NewLine + "Abstract: " + msg + Environment.NewLine + "Log: " + msgExtended + Environment.NewLine + "Possible solution(s): " + solutions + Environment.NewLine; // append log string to err.log, creating the file if it doesn't exist using (StreamWriter sw = MsgLabel.errLogFile.AppendText()) { sw.WriteLine(log); } // send fatal error message to user MsgLabel.SendMsg("***FATAL*** " + msg + "; see err.log for details."); // sleep for the duration of msg being displayed Thread.Sleep(MsgLabel.timer.Interval); // terminate the process Application.Exit(); }
public static void Warn(string msg) { // send warning message to user MsgLabel.SendMsg("***WARNING*** " + msg); }
public static void Normal(string msg) { // send normal message to user MsgLabel.SendMsg(msg); }
public static void Copy() { // check for valid SelectedIndex val before continuing if (LocalClipboard.MainWindow.ListBox.SelectedIndex < 0) { return; } // Windows clipboard will be changed in this method; we don't want it to be handled LocalClipboard.HandleClipboard = false; // store the selected item string key = (string)MainWindow.ListBox.SelectedItem; ClipboardItem clipboardItem = LocalClipboard.Dict[key]; // store an error msg string that will notify the user if an error occurred string errMsg = null; // what's copied to the clipboard depends on the item's type switch (clipboardItem.Type) { case ClipboardItem.TypeEnum.Text: // copy the item's text to the Windows clipboard Clipboard.SetText((clipboardItem as TextItem).Text); break; case ClipboardItem.TypeEnum.FileDropList: // copy the item's files to the Windows clipboard Clipboard.SetFileDropList((clipboardItem as FileItem).FileDropList); break; case ClipboardItem.TypeEnum.Image: // make sure the image file exists FileInfo imageFile = new FileInfo(Path.Combine(LocalClipboard.ImageFolder.FullName, clipboardItem.KeyText)); if (imageFile.Exists) { // get image from the file using (Image image = Image.FromFile(imageFile.FullName)) { // set image to the Windows clipboard Clipboard.SetImage(image); } } // else set errMsg to be reported else { errMsg = "Image file is missing!"; } break; case ClipboardItem.TypeEnum.Audio: // make sure the audio file exists FileInfo audioFile = new FileInfo(Path.Combine(LocalClipboard.AudioFolder.FullName, clipboardItem.KeyText)); if (audioFile.Exists) { // get audio stream from the file Stream audioStream = new MemoryStream(); using (FileStream fs = audioFile.OpenRead()) { fs.CopyTo(audioStream); } using (audioStream) { // set audio to the Windows clipboard Clipboard.SetAudio(audioStream); } } // else set errMsg to be reported else { errMsg = "Audio file is missing!"; } break; case ClipboardItem.TypeEnum.Custom: // make sure the custom file exists FileInfo customFile = new FileInfo(Path.Combine(LocalClipboard.CustomFolder.FullName, clipboardItem.KeyText)); if (customFile.Exists) { // store custom data from the serializable file object data; using (FileStream customStream = customFile.Open(FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); data = formatter.Deserialize(customStream); } // set custom data to the Windows clipboard Clipboard.SetData((clipboardItem as CustomItem).WritableFormat, data); } // else set errMsg to be reported else { errMsg = "Custom file is missing!"; } break; } // flip to true after algorithm is finished LocalClipboard.HandleClipboard = true; // notify to the user the results of the operation attempt if (errMsg == null) { MsgLabel.Normal("Copied to clipboard!"); } else { MsgLabel.Warn(errMsg); } }
public CustomItem(MainWindow mainWindow, IDataObject dataObject) : base(mainWindow, TypeEnum.Custom) { // ensure dataObject is valid before continuing if (dataObject == null) { return; } // set to null before doing checks this.WritableFormat = null; // store supported formats of dataObject string[] formats = dataObject.GetFormats(); // ensure formats is a valid array before continuing if (formats == null || formats.Length == 0) { return; } // check for a format with writable data and return true if there is one foreach (string format in formats) { // store the first format whose data is serializable, then break if (dataObject.GetData(format).GetType().IsSerializable) { this.WritableFormat = format; break; } } // if no formats are writable, then we can't add this item if (this.WritableFormat == null) { return; } // set KeyText using WritableFormat base.KeyText = "Custom (" + this.WritableFormat + ")"; // if setting KeyDiff returns false, then there is an equivalent item at index 0 if (!base.SetKeyDiff()) { return; } // add KeyDiff to KeyText if needed if (base.KeyDiff != 0) { base.KeyText += base.KeyDiff; } // create Custom folder if it's missing if (!LocalClipboard.CustomFolder.Exists) { LocalClipboard.CustomFolder.Create(); } // create file in Custom folder with dataObject FileInfo customFile = new FileInfo(Path.Combine(LocalClipboard.CustomFolder.FullName, base.KeyText)); object data = dataObject.GetData(this.WritableFormat); BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fileStream = customFile.Create()) { formatter.Serialize(fileStream, data); } /// Char order: /// /// 1. Type /// 2. KeyDiff /// 3. WritableFormat /// base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine + this.WritableFormat + Environment.NewLine; // add to local clipboard with CLIPBOARD file LocalClipboard.AddWithFile(base.KeyText, this); // move selected index to that of this instance if box is checked if (base.mainWindow.MoveToCopied.Checked) { base.mainWindow.ListBox.SelectedIndex = LocalClipboard.Keys.IndexOf(base.KeyText); } MsgLabel.Normal("Custom item added!"); }
public AudioItem(MainWindow mainWindow, Stream audioStream) : base(mainWindow, TypeEnum.Audio) { using (audioStream) { // ensure the stream is not null before continuing if (audioStream == null) { return; } // store length in bytes of the stream this.ByteLength = audioStream.Length; // byteRate is stored at byte offset 28 of the WAVE file byte[] byteRateBuffer = new byte[4]; audioStream.Read(byteRateBuffer, 28, 4); int byteRate = BitConverter.ToInt32(byteRateBuffer, 0); // subchunk2Size, i.e. byte length of the audio data, is stored at byte offset 40 (28 + 4 + 8) of the WAVE file byte[] subchunk2SizeBuffer = new byte[4]; audioStream.Read(subchunk2SizeBuffer, 8, 4); int subchunk2Size = BitConverter.ToInt32(subchunk2SizeBuffer, 0); // compute the total length of the audio file in hours int fileLengthSeconds = subchunk2Size / byteRate; int fileLengthMinutes = fileLengthSeconds / 60; int fileLengthHours = fileLengthMinutes / 60; // modify to split correct time in hours, minutes, and seconds fileLengthMinutes %= 60; fileLengthSeconds %= 60; // calculate KeyText given the data base.KeyText = "Audio (" + (fileLengthHours == 0 ? "" : fileLengthHours + "h:") + (fileLengthMinutes == 0 ? "" : fileLengthMinutes + "m:") + fileLengthSeconds + "s)"; // if setting KeyDiff returns false, then there is an equivalent item at index 0 if (!base.SetKeyDiff()) { return; } // add KeyDiff to KeyText if needed if (base.KeyDiff != 0) { base.KeyText += base.KeyDiff; } // create Audio folder if it's missing if (!LocalClipboard.AudioFolder.Exists) { LocalClipboard.AudioFolder.Create(); } // create audio file in the Audio folder FileInfo audioFile = new FileInfo(Path.Combine(LocalClipboard.AudioFolder.FullName, base.KeyText)); audioStream.Seek(0, SeekOrigin.Begin); using (FileStream fileStream = audioFile.Create()) { audioStream.CopyTo(fileStream); } } /// Char order: /// /// 1. Type /// 2. KeyDiff /// 3. ByteLength /// 4. KeyText /// base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine + this.ByteLength.ToString() + Environment.NewLine + base.KeyText + Environment.NewLine; // add to local clipboard with CLIPBOARD file LocalClipboard.AddWithFile(base.KeyText, this); // move selected index to that of this instance if box is checked if (base.mainWindow.MoveToCopied.Checked) { base.mainWindow.ListBox.SelectedIndex = LocalClipboard.Keys.IndexOf(base.KeyText); } MsgLabel.Normal("Audio item added!"); }
public ImageItem(MainWindow mainWindow, Image image) : base(mainWindow, TypeEnum.Image) { using (image) { // ensure image isn't null before continuing if (image == null) { return; } // copy size struct of the image this.Size = image.Size; // set KeyText using image dimensions base.KeyText = "Image (" + this.Size.Width + " x " + this.Size.Height + ")"; // if setting KeyDiff returns false, then there is an equivalent item at index 0 if (!base.SetKeyDiff()) { return; } // add KeyDiff to KeyText if needed if (base.KeyDiff != 0) { base.KeyText += base.KeyDiff; } // create Images folder if it's missing if (!LocalClipboard.ImageFolder.Exists) { LocalClipboard.ImageFolder.Create(); } // create image file in the Images folder image.Save(Path.Combine(LocalClipboard.ImageFolder.FullName, base.KeyText)); } /// Char order: /// /// 1. Type /// 2. KeyDiff /// 3. Size.Width /// 4. Size.Height /// base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine + this.Size.Width.ToString() + Environment.NewLine + this.Size.Height.ToString() + Environment.NewLine; // add to local clipboard with CLIPBOARD file LocalClipboard.AddWithFile(base.KeyText, this); // move selected index to that of this instance if box is checked if (base.mainWindow.MoveToCopied.Checked) { base.mainWindow.ListBox.SelectedIndex = LocalClipboard.Keys.IndexOf(base.KeyText); } MsgLabel.Normal("Image item added!"); }
public FileItem(MainWindow mainWindow, StringCollection fileDropList) : base(mainWindow, TypeEnum.FileDropList) { // ensure param is valid before continuing if (fileDropList == null || fileDropList.Count == 0) { return; } // get file drop list from param this.FileDropList = fileDropList; // if 1 file was copied, KeyText will store FileDropList[0]'s filename if (this.FileDropList.Count == 1) { base.KeyText = "File: " + Path.GetFileName(this.FileDropList[0]); } // else KeyText will store FileDropList[0]'s filename + how many more files there are else { base.KeyText = "Files: " + Path.GetFileName(this.FileDropList[0]) + " + " + (this.FileDropList.Count - 1) + " more"; } // shorten KeyText to fit the character limit if needed if (base.KeyText.Length > LocalClipboard.CHAR_LIMIT) { base.KeyText = base.KeyText.Substring(0, LocalClipboard.CHAR_LIMIT) + "..."; } // if setting KeyDiff returns false, then there is an equivalent item at index 0 if (!base.SetKeyDiff()) { return; } // add KeyDiff to KeyText if needed if (base.KeyDiff != 0) { base.KeyText += base.KeyDiff; } /// Char order: /// /// 1. Type /// 2. KeyDiff /// 3. # strings in FileDropList /// 4. FileDropList /// base.FileChars = (char)base.Type + base.KeyDiff.ToString() + Environment.NewLine + this.FileDropList.Count.ToString() + Environment.NewLine; foreach (string fileDir in this.FileDropList) { base.FileChars += fileDir + Environment.NewLine; } // add to local clipboard with CLIPBOARD file LocalClipboard.AddWithFile(base.KeyText, this); // move selected index to that of this instance if box is checked if (base.mainWindow.MoveToCopied.Checked) { base.mainWindow.ListBox.SelectedIndex = LocalClipboard.Keys.IndexOf(base.KeyText); } MsgLabel.Normal("File item added!"); }