Ejemplo n.º 1
0
 public void AddLastProject(string name, string projectName)
 {
     RecentItem ri = new RecentItem (new Uri (name), MimeType.GetMimeTypeForUri (name), "MonoDevelop Projects");
     ri.Private = projectName;
     recentFiles.AddWithLimit (ri, "MonoDevelop Projects", MAX_LENGTH);
     UpdateLastProject ();
 }
Ejemplo n.º 2
0
        public void AddLastFile(string name, string project)
        {
            RecentItem ri = new RecentItem (new Uri (name), MimeType.GetMimeTypeForUri (name), "MonoDevelop Files");
            if (project == null)
                ri.Private = Path.GetFileName (name);
            else
                ri.Private = String.Format ("{0} [{1}]", Path.GetFileName (name), project);

            recentFiles.AddWithLimit (ri, "MonoDevelop Files", MAX_LENGTH);
            UpdateLastFile ();
        }
Ejemplo n.º 3
0
        public void RemoveItem(RecentItem item)
        {
            if (RecentItems == null)
                return;

            ArrayList l = new ArrayList ();
            foreach (RecentItem ri in RecentItems)
            {
                if (ri == item)
                {
                    // remove the whole thing
                }
                else if (ri.Uri == item.Uri)
                {
                    if (ri.Groups != null)
                    {
                        // remove the groups
                        if (item.Groups != null)
                        {
                            foreach (string g in item.Groups)
                                ri.RemoveGroup (g);
                        }
                        l.Add (ri);
                    }
                }
                else
                {
                    // keep it
                    l.Add (ri);
                }
            }

            RecentItem[] items = new RecentItem [l.Count];
            l.CopyTo (items, 0);
            RecentItems = items;
            Save ();
        }
Ejemplo n.º 4
0
        // return the last X items in newest to oldest order
        private RecentItem[] GetMostRecent(int count, RecentItem[] items)
        {
            if (count >= items.Length)
            {
                return items;
            }
            else
            {
                RecentItem[] countedItems = new RecentItem[count];
                // get the last count items
                Array.Copy (items, items.Length - count - 1, countedItems, 0, count);

                return countedItems;
            }
        }
Ejemplo n.º 5
0
        public RecentItem[] GetItemsInGroup(string group)
        {
            if (RecentItems == null)
                return null;

            ArrayList list = new ArrayList ();
            foreach (RecentItem ri in RecentItems)
            {
                if (ri.Groups == null)
                    continue;

                if (Array.IndexOf (ri.Groups, group) != -1)
                    list.Add (ri);
            }

            RecentItem[] items = new RecentItem [list.Count];
            list.CopyTo (items, 0);
            return items;
        }
Ejemplo n.º 6
0
        public void ClearGroup(string group)
        {
            if (RecentItems == null)
                return;

            ArrayList list = new ArrayList ();
            foreach (RecentItem ri in RecentItems)
            {
                if (Array.IndexOf (ri.Groups, group) == -1)
                {
                    list.Add (ri);
                }
                else
                {
                    ri.RemoveGroup (group);

                    // it has other groups so dont delete it
                    if (ri.Groups.Length > 0)
                        list.Add (ri);
                }
            }

            RecentItem[] items = new RecentItem [list.Count];
            list.CopyTo (items, 0);
            RecentItems = items;
            Save ();
        }
Ejemplo n.º 7
0
        // ensure that that only max items are kept in group
        public void AddWithLimit(RecentItem item, string group, int max)
        {
            if (max < 1)
                throw new ArgumentException ("max must be > 0");

            // we add it first in case the Uri is already there
            AddItem (item);

            // then we adjust for the limit
            RecentItem[] inGroup = GetItemsInGroup (group);
            if (inGroup.Length > max)
            {
                while (inGroup.Length > max) {
                    RemoveItem (GetOldestItem (inGroup));
                    inGroup = GetItemsInGroup (group);
                }
            }
        }
Ejemplo n.º 8
0
        public void AddItem(RecentItem item)
        {
            if (RecentItems == null)
            {
                RecentItems = new RecentItem [] {item};
                Save ();
                return;
            }

            // check for already existing URI
            // if it does update timestamp and return unchanged;
            foreach (RecentItem ri in RecentItems)
            {
                if (ri.Uri == item.Uri)
                {
                    ri.Timestamp = item.Timestamp;
                    if (item.Groups != null)
                        ri.AddGroups (item.Groups);
                    Save ();
                    return;
                }
            }

            while (RecentItems.Length > 499)
            {
                RemoveItem (OldestItem);
            }

            int length = RecentItems.Length;
            RecentItem[] newItems = new RecentItem[length + 1];
            RecentItems.CopyTo (newItems, 0);
            newItems[length] = item;
            RecentItems = newItems;
            Save ();
        }
Ejemplo n.º 9
0
 public static RecentItem GetOldestItem(RecentItem[] items)
 {
     return items[items.Length - 1];
 }