Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace clipKeep
- {
- public partial class mainForm : Form
- {
- public mainForm()
- {
- InitializeComponent();
- }
- //Holds all of the strings, allows for a search function with one listbox
- List<string> allItems = new List<string>();
- //Where the save file is stored
- string listLocation = Directory.GetCurrentDirectory() + "/savedList.ini";
- //How the strings are split. Not reading line by line because some C&P's may have multiple lines
- string splitVar = "[][][][][]";
- //Base variable for the saving
- string doBuild = "";
- private void mainForm_Load(object sender, EventArgs e)
- {
- //If the file doesn't exist; then create one
- if (!File.Exists(listLocation))
- {
- var tempOpen = File.Create(listLocation);
- tempOpen.Close();
- MessageBox.Show("Couldn't find a saved list; created new one!", "MultiClip");
- allItems.Add("Created by vRice");
- allItems.Add("http://www.youtube.com/vintagerice");
- updateProgram();
- }
- else
- {
- //Splits with a string rather than a char
- string[] splitText = File.ReadAllText(listLocation).Split(new string[] { splitVar }, StringSplitOptions.None);
- //Adds all items to the listbox
- foreach (string newItem in splitText)
- {
- if(newItem != "")
- {
- allItems.Add(newItem);
- updateProgram();
- }
- }
- }
- }
- //'Brain' of the program, monitors all clipboard content
- private void checkTimer_Tick(object sender, EventArgs e)
- {
- string newText = Clipboard.GetText();
- if (!itemList.Items.Contains(newText))
- {
- if (newText != "")
- {
- allItems.Add(newText);
- updateProgram();
- }
- }
- }
- public void updateProgram()
- {
- itemList.Items.Clear();
- Clipboard.Clear();
- doBuild = "";
- foreach (string newItem in allItems)
- {
- //Adds each string to the variable with a split between them
- itemList.Items.Add(newItem);
- doBuild += (newItem + splitVar);
- }
- // Writes the string to the save file
- if (File.Exists(listLocation))
- File.WriteAllText(listLocation, doBuild);
- }
- private void delButton_Click(object sender, EventArgs e)
- {
- if (itemList.SelectedIndex >= 0)
- {
- allItems.RemoveAt(itemList.SelectedIndex);
- updateProgram();
- }
- }
- private void clearButton_Click(object sender, EventArgs e)
- {
- DialogResult userConfirm = MessageBox.Show("Are you sure you want to delete all items?", "multiClip", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- //If user selects yes then delete everything
- if(userConfirm == DialogResult.Yes)
- {
- allItems.Clear();
- updateProgram();
- }
- }
- private void searchBox_TextChanged(object sender, EventArgs e)
- {
- if(searchBox.Text!= "Search")
- {
- itemList.Items.Clear();
- //If the search box contains anything that's in the item list; show the items
- foreach(string toFind in allItems)
- if (toFind.ToLower().Contains(searchBox.Text.ToLower()))
- if (!itemList.Items.Contains(toFind))
- itemList.Items.Add(toFind);
- }
- }
- private void expandButton_Click(object sender, EventArgs e)
- {
- if(itemList.SelectedIndex >= 0)
- {
- //Open a new form that passes on the selected item string
- expandForm openForm = new expandForm(this.itemList.SelectedItem.ToString());
- openForm.ShowDialog();
- //Return the data from the other form if it isn't empty
- if(openForm.textData() != "")
- {
- allItems.Remove(itemList.SelectedItem.ToString());
- allItems.Add(openForm.textData());
- updateProgram();
- }
- }
- }
- private void mainForm_Resize(object sender, EventArgs e)
- {
- //Make the program responsive
- itemList.Height = this.Height - 70;
- itemList.Width = this.Width - 180;
- }
- private void clearBox(object sender, EventArgs e)
- {
- searchBox.Text = "";
- }
- private void itemList_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- Uri uriResult;
- bool urlCheck = Uri.TryCreate(itemList.SelectedItem.ToString(), UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;
- //If the item is a link; launch it
- if (urlCheck)
- System.Diagnostics.Process.Start(itemList.SelectedItem.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment