Recent Documents

Ribbon for WPF Forum

Posted 17 years ago by Bryan Livingston
Version: 1.0.0347
Avatar
I'm implementing the recent documents functionality. Are there plans by you to implement a better system for this? I'd like features like the auto numbering of the files with keyboard shortcuts, pinning, etc. I can do the saving of the list myself but would like the interface to be done for me.

Comments (2)

Posted 17 years ago by Bryan Livingston
Avatar
Here's the code that I'm using for my Recent Documents list. Feel free to use it if you'd like. Should be a good start for anyone needing to implement the recent docs.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Text;
using System.Windows.Markup;
using System.Xml.Serialization;

namespace Vector
{
    public class RecentDrawingList : List<RecentDrawing>
    {
        readonly int maxCount = 15;

        public new void Add(RecentDrawing drawing)
        {
            if (Contains(drawing))
                Remove(drawing);
            Insert(0, drawing);

            if (Count > maxCount)
                RemoveAt(Count - 1);

            RefreshList();
        }

        public void Add(FileRecord record)
        {
            Add(new RecentDrawing() { Record = record });
        }

        public void Add(string filename)
        {
            Add(new RecentDrawing() { Filename = filename });
        }

        public void RefreshList()
        {
            if (Designer.Instance != null)
            {
                Designer.Instance.Ribbon.RecentFiles.Items.Clear();
                foreach (RecentDrawing r in this)
                    Designer.Instance.Ribbon.RecentFiles.Items.Add(r);
            }
        }

        public void Save()
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForDomain())
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("RecentDrawings", FileMode.Create, store))
                {
                    XmlSerializer x = new XmlSerializer(typeof(RecentDrawingList));
                    x.Serialize(stream, this);
                }
            }
        }

        public static RecentDrawingList Load()
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForDomain())
            {
                if (store.GetFileNames("RecentDrawings").Length > 0)
                    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("RecentDrawings", FileMode.Open, store))
                    {
                        XmlSerializer x = new XmlSerializer(typeof(RecentDrawingList));
                        return (RecentDrawingList)x.Deserialize(stream);
                    }
                else
                    return new RecentDrawingList();
            }
        }
    }
}
Also, here is my click handler:

        private void OnRecentDocumentClick(object sender, RoutedEventArgs e)
        {
            // Raise a PreviewClick event (which closes the containing menus)
            Button button = (Button)e.OriginalSource;
            button.RaiseEvent(new RoutedEventArgs(RibbonControls.ControlBase.PreviewClickEvent, button));

            RecentDrawing r = (RecentDrawing)button.DataContext;
            r.Open();
        }
If Actipro decides to make a RecentDocs control, then it could use an IRecentDocument interface which could have an Open method and a Pinned flag.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bryan,

Yes this is something we are going to be working on. So if you have any more feature ideas, or if anyone else does, please email them over. Thanks!


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.