Пример #1
0
        static int CompareItems(RecentFile recent_a, RecentFile recent_b)
        {
            int rslt = DateTime.Compare (recent_a.timestamp, recent_b.timestamp);

            if (rslt == 0)
                return rslt;

            return rslt > 0 ? -1 : 0;
        }
Пример #2
0
        // Adds a recently opened file
        public void Add(string filename)
        {
            RecentFile item;

            Logger.Debug ("RecentFilesStorage.Add {0}, count {1}", filename, items.Count);

            // If the file was already in the list, just update the timestamp
            for (int i = 0; i < Items.Count; i++)
            {
                if (items[i].filename == filename) {
                    item = items[i];
                    item.UpdateTimeStamp ();
                    Logger.Debug ("RecentFilesStorage.Add has updated {0} (prev {1})", item, items[i]);
                    items[i] = item;
                    Write ();
                    return;
                }
            }

            item = new RecentFile (filename);

            if (items.Count >= MAX_ITEMS) {
                DateTime timestamp = items[0].timestamp;
                int older = 0;

                // Remove the older item
                for (int i = 1; i < Items.Count; i++)
                {
                    if (items[i].timestamp < timestamp) {
                        timestamp = items[i].timestamp;
                        older = i;
                    }
                }

                Logger.Debug ("RecentFilesStorage.Add. Count > MAX_ITEMS. Older item {0}", items [older]);
                items.Remove (items[older]);
            }

            items.Add (item);
            Write ();
        }
Пример #3
0
        public void Read()
        {
            if (File.Exists (filename) == false)
                return;

            XmlStorage ps = new XmlStorage ();
            XmlNode root;
            ps.Load (filename);

            if ((ps.xml_document.ChildNodes.Count > 0) == false)
                return;

            root = ps.xml_document.ChildNodes [1];

            RecentFile item = new RecentFile ();
            foreach (XmlNode node in root.ChildNodes)
            {
                XmlSerializer serializer = new XmlSerializer (typeof (RecentFile));
                StringReader reader = new StringReader (node.OuterXml);
                item = (RecentFile) serializer.Deserialize (reader);
                reader.Close ();
                items.Add (item);
            }
        }