Esempio n. 1
0
        public void AddRecentFile(Document document)
        {
            var fileName = document.OriginalFileName;
            int index    = RecentFiles.IndexOfFirst(i => i.FileName.Equals(fileName, StringComparison.OrdinalIgnoreCase));

            if (index != -1)
            {
                RecentFiles.RemoveAt(index);
            }

            var record = new RecentFileRecord
            {
                FileName     = fileName,
                Title        = document.Title,
                LastAccessed = DateTime.Now
            };

            if (RecentFiles.Count == 0)
            {
                RecentFiles.Add(record);
            }
            else
            {
                RecentFiles.Insert(0, record);
            }

            string json = JsonConvert.SerializeObject(RecentFiles.ToArray());

            File.WriteAllText(FilePath, json);
            OnRecentFilesChanged();
        }
Esempio n. 2
0
        private void lbRecent_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            using Brush b = new SolidBrush(e.ForeColor);
            RecentFileRecord record    = (RecentFileRecord)recentFileRecordBindingSource[e.Index];
            SizeF            titleSize = e.Graphics.MeasureString(record.Title, titleFont);

            e.Graphics.DrawString(record.Title, titleFont, b, e.Bounds.X, e.Bounds.Y + 3);
            e.Graphics.DrawString(record.FileName, lbRecent.Font, b, e.Bounds.X, e.Bounds.Y + titleSize.Height + 3);
        }