// Add either new record or increment existing record counter private void addClipBoardRecord(string content) { ClipBoardRecord rec; //accept content only of not empty and not too big if (content.Length != 0 && content.Length < maxCopyTextLength) { rec = getClipBoardRecordViaContent(content); if (rec == null) // this is a new content { // add a new record to the list rec = new ClipBoardRecord(content, 1, 0); recentItems.Insert(0, rec); } else { // increment the existing matching record rec.CoppiedCount++; } //limit number of recent items if (recentItems.Count > 25) { recentItems.RemoveAt(recentItems.Count - 1); } updateList(); } }
// Add either new record or increment existing record counter public void AddClipBoardRecord(string content) { Log.Verbose().Write("Add content to clipboard."); ClipBoardRecord rec; //accept content only of not empty and not too big if (content.Length != 0 && content.Length < _maxCopyTextLength) { rec = GetClipBoardRecordViaContent(content); if (rec == null) // this is a new content { // add a new record to the list rec = new ClipBoardRecord(content, 1, 0); _recentItems.Insert(0, rec); } else { // increment the existing matching record rec.CoppiedCount++; } //limit number of recent items if (_recentItems.Count > 25) { Log.Debug().Write("Recent items exceeded max size. Remove last item."); _recentItems.RemoveAt(_recentItems.Count - 1); } } else { Log.Warn().Write("Content emtpy or longer than defined max length."); } }
// Add either new record or increment existing record counter public void AddClipBoardRecord(string content) { POINTAPI point = new POINTAPI(); // 必须用与之相兼容的结构体,类也可以 Thread.Sleep(8000); //add some wait time GetCursorPos(ref point); // 获取当前鼠标坐标 int handle = WindowFromPoint(point.X, point.Y); // 获取指定坐标处窗口的句柄 // Record the resource from the acitivated window title StringBuilder rsc = new StringBuilder(256); // int handle = GetForegroundWindow(); GetWindowText(handle, rsc, 256); string resource = rsc.ToString(); // MessageBox.Show(name.ToString()); Log.Verbose().Write("Add content to clipboard."); ClipBoardRecord rec; //accept content only of not empty and not too big if (content.Length != 0 && content.Length < _maxCopyTextLength) { rec = GetClipBoardRecordViaContent(content); if (rec == null) // this is a new content { // add a new record to the list rec = new ClipBoardRecord(content, resource, 1, 0); _recentItems.Insert(0, rec); } else { // increment the existing matching record rec.CoppiedCount++; } //limit number of recent items if (_recentItems.Count > 25) { Log.Debug().Write("Recent items exceeded max size. Remove last item."); _recentItems.RemoveAt(_recentItems.Count - 1); } } else { Log.Warn().Write("Content emtpy or longer than defined max length."); } }
public Dictionary <string, List <ClipBoardRecord> > LoadFromFile(string FileName) { char[] delimiterChars = { ',' }; string[] fileFields; string[] lines = File.Exists(FileName) ? File.ReadAllLines(FileName) : new string[] { }; string type; List <ClipBoardRecord> savedItems = new List <ClipBoardRecord>(); List <ClipBoardRecord> recentItems = new List <ClipBoardRecord>(); foreach (string s in lines) { ClipBoardRecord rec = new ClipBoardRecord(); // Find out if we have a saved file containing counts if (s.StartsWith("|")) // then new file format { fileFields = s.Split(delimiterChars, 4); rec.CoppiedCount = int.Parse(fileFields[1]); rec.PastedCount = int.Parse(fileFields[2]); rec.Content = Regex.Unescape(fileFields[3].Substring(7)); type = fileFields[3].Substring(0, 7); } else // handle previous file format { rec.Content = Regex.Unescape(s.Substring(7)); rec.CoppiedCount = 0; rec.PastedCount = 0; type = s.Substring(0, 7); } // now have have the data add it to the relevent list if (type.StartsWith("saved:")) { savedItems.Add(rec); } else if (type.StartsWith("recent:")) { recentItems.Add(rec); } } var items = new Dictionary <string, List <ClipBoardRecord> >(); items.Add("saved", savedItems); items.Add("recent", recentItems); return(items); }
private ClipBoardRecord getClipBoardRecordViaContent(string content) { ClipBoardRecord foundRecord = null; foreach (ClipBoardRecord rec in savedItems) { if (rec.Content == content) { foundRecord = rec; } } foreach (ClipBoardRecord rec in recentItems) { if (rec.Content == content) { foundRecord = rec; } } return(foundRecord); }
private void updateList() { list.Items.Clear(); ClipBoardRecord mostCoppiedRecord = new ClipBoardRecord(); ClipBoardRecord mostPastedRecord = new ClipBoardRecord(); int i = 1; // Add in saved records foreach (ClipBoardRecord s in savedItems) { ListViewItem lvi = new ListViewItem(new string[] { (i++).ToString(), s.CoppiedCount.ToString(), s.PastedCount.ToString(), s.Content }); list.Items.Add(lvi); list.Groups[0].Items.Add(lvi); } // Calcualte both the most coppied and most pasted records foreach (ClipBoardRecord s in recentItems) { // work out for use later on the most coppied record if (mostCoppiedRecord.CoppiedCount < s.CoppiedCount) { mostCoppiedRecord = s; } // work out for use later on the most pasted record if (mostPastedRecord.PastedCount < s.PastedCount) { mostPastedRecord = s; } } frequentItems.Clear(); if (mostCoppiedRecord.CoppiedCount > 0) { frequentItems.Add(mostCoppiedRecord); } // is mostCoppied is the same as mostPasted then only add one instance if (mostPastedRecord.PastedCount > 0 && mostCoppiedRecord != mostPastedRecord) { frequentItems.Add(mostPastedRecord); } foreach (ClipBoardRecord s in frequentItems) { ListViewItem lvi = new ListViewItem(new string[] { (i++).ToString(), s.CoppiedCount.ToString(), s.PastedCount.ToString(), s.Content }); list.Items.Add(lvi); list.Groups[1].Items.Add(lvi); } // finally populate the recent list foreach (ClipBoardRecord s in recentItems) { ListViewItem lvi = new ListViewItem(new string[] { (i++).ToString(), s.CoppiedCount.ToString(), s.PastedCount.ToString(), s.Content }); list.Items.Add(lvi); list.Groups[2].Items.Add(lvi); } //save to csv writeToCsv(); //resize the form to fit the number of items resizeForm(); }
public Dictionary <string, List <ClipBoardRecord> > LoadFromFile(string FileName) { char[] delimiterChars = { ',' }; string[] fileFields; string[] lines = File.Exists(FileName) ? File.ReadAllLines(FileName) : new string[] { }; string type; List <ClipBoardRecord> savedItems = new List <ClipBoardRecord>(); List <ClipBoardRecord> recentItems = new List <ClipBoardRecord>(); POINTAPI point = new POINTAPI(); // 必须用与之相兼容的结构体,类也可以 Thread.Sleep(8000); //add some wait time GetCursorPos(ref point); // 获取当前鼠标坐标 int handle = WindowFromPoint(point.X, point.Y); // 获取指定坐标处窗口的句柄 foreach (string s in lines) { // Record the resource from the acitivated window title ClipBoardRecord rec = new ClipBoardRecord(); StringBuilder name = new StringBuilder(256); // int handle = GetForegroundWindow(); GetWindowText(handle, name, 256); // MessageBox.Show(name.ToString()); // Find out if we have a saved file containing counts if (s.StartsWith("|")) // then new file format { fileFields = s.Split(delimiterChars, 5); rec.CoppiedCount = int.Parse(fileFields[1]); rec.PastedCount = int.Parse(fileFields[2]); rec.Content = Regex.Unescape(fileFields[3].Substring(7)); rec.Resource = Regex.Unescape(fileFields[4].Substring(5)); type = fileFields[3].Substring(0, 7); } else // handle previous file format { rec.Content = Regex.Unescape(s.Substring(7)); rec.Resource = Regex.Unescape(s.Substring(5)); rec.CoppiedCount = 0; rec.PastedCount = 0; type = s.Substring(0, 7); } // now have have the data add it to the relevent list if (type.StartsWith("saved:")) { savedItems.Add(rec); } else if (type.StartsWith("recent:")) { recentItems.Add(rec); } } var items = new Dictionary <string, List <ClipBoardRecord> >(); items.Add("saved", savedItems); items.Add("recent", recentItems); return(items); }
private void loadContent(string contentFileName) { char[] delimiterChars = { ',' }; string[] fileFields; string[] lines = File.ReadAllLines(contentFileName); string type; foreach (string s in lines) { ClipBoardRecord rec = new ClipBoardRecord(); // Find out if we have a saved file containing counts if (s.StartsWith("|")) // then new file format { fileFields = s.Split(delimiterChars, 4); rec.CoppiedCount = int.Parse(fileFields[1]); rec.PastedCount = int.Parse(fileFields[2]); rec.Content = Regex.Unescape(fileFields[3].Substring(7)); type = fileFields[3].Substring(0, 7); } else // handle previous file format { rec.Content = Regex.Unescape(s.Substring(7)); rec.CoppiedCount = 0; rec.PastedCount = 0; type = s.Substring(0, 7); } // now have have the data add it to the relevent list if (type.StartsWith("saved:")) { savedItems.Add(rec); } else if (type.StartsWith("recent:")) { recentItems.Add(rec); } } }