// private void PasteSpecial(object sender, System.EventArgs e) { // PasteOptionsForm pof = new PasteOptionsForm(pos); // if (pof.ShowDialog(this) == DialogResult.OK) { // this.pos = pos; // usemine = true; // } else { // usemine = false; // } // Paste(sender, e); // } private void Paste() { string fullinput = Clipboard.GetDataObject().GetData(typeof(string)).ToString(); if (!usemine) { PasteOptions sep = GuessSeperator(fullinput); if (sep.SeperationString.Length > 0) { pos = sep; } } string input = fullinput.Replace("\r", ""); string[] lines = input.Split('\n'); foreach (string line in lines) { if (line.Trim().Length == 0) { continue; } int ndx = line.IndexOf(pos.SeperationString); Cheat cc = new Cheat(); if (ndx > -1) { if (pos.CodeFirst) { cc.Code = line.Substring(0, ndx).Trim(); if (ndx < line.Length) { cc.Description = line.Substring(ndx).Replace(pos.SeperationString, "").Trim(); } } else { cc.Description = line.Substring(0, ndx).Trim(); cc.Code = line.Substring(ndx).Replace(pos.SeperationString, "").Trim(); } } else { cc.Code = line; } if (cc.Code != null && cc.Code.Trim().Length > 0) { // AddCode(cc); ListViewItem lvi = new ListViewItem(new string[] { cc.Code, cc.Description }); lvi.Tag = cc; cheatbox.Items.Add(lvi); } } }
// Paste special private void menuItem6_Click(object sender, System.EventArgs e) { if (Clipboard.GetDataObject().GetDataPresent(typeof(string))) { PasteOptionsForm pof = new PasteOptionsForm(pos); if (pof.ShowDialog(this) == DialogResult.OK) { usemine = true; pos = pof.PasteOptions; string fullinput = Clipboard.GetDataObject().GetData(typeof(string)).ToString(); Paste(); } else { usemine = false; } } }
public PasteOptionsForm(PasteOptions pos) { InitializeComponent(); this.pos = pos; UpdateUI(); }
public PasteOptionsForm() { InitializeComponent(); pos = new PasteOptions(); UpdateUI(); }
private bool usemine = false; // false: defaults to guessing private PasteOptions GuessSeperator(string input) { string sep = string.Empty; input = input.Trim().Replace("\r", ""); string[] lines = input.Split('\n'); int sp = 0; int spsp = 0; int tab = 0; int spcolsp = 0; int spcol = 0; int spdashsp = 0; int spdash = 0; int speqsp = 0; int speq = 0; int linecount = 0; int startlength = 0; int endlength = 0; foreach (string line in lines) { if (line.Length < 1) { continue; } linecount++; string linet = line.Trim(); string tempsep = ""; string[] chunks = linet.Split(' '); if (chunks.Length == 2) { sp++; tempsep = " "; } else { if (linet.IndexOf(" ") > -1) { tab++; tempsep = "\t"; } else if (linet.IndexOf(" ") > -1) { spsp++; tempsep = " "; } if (linet.IndexOf(" : ") > -1) { spcolsp++; tempsep = " : "; } else if (linet.IndexOf(" :") > -1) { spcol++; tempsep = " :"; } if (linet.IndexOf(" - ") > -1) { spdashsp++; tempsep = " - "; } else if (linet.IndexOf(" -") > -1) { spdash++; tempsep = " -"; } if (linet.IndexOf(" = ") > -1) { speqsp++; tempsep = " = "; } else if (linet.IndexOf(" =") > -1) { speq++; tempsep = " ="; } } try { int pos = linet.IndexOf(tempsep); if (pos > startlength) { startlength = pos; } if ((line.Length - pos) > endlength) { endlength = line.Length - pos; } } catch {} } if (sp == linecount) { sep = " "; } else if (spsp == linecount) { sep = " "; } else if (tab == linecount) { sep = " "; } else if (spcolsp == linecount) { sep = " : "; } else if (spcol == linecount) { sep = " :"; } else if (spdashsp == linecount) { sep = " - "; } else if (spdash == linecount) { sep = " -"; } else if (speqsp == linecount) { sep = " = "; } else if (speq == linecount) { sep = " ="; } PasteOptions p = new PasteOptions(); p.SeperationString = sep; //p.CodeFirst = endlength > startlength; return(p); }