コード例 #1
0
		public void AddLastFile (string name, string project)
		{
			RecentItem recentItem = new RecentItem (RecentFileStorage.ToUri (name), DesktopService.GetMimeTypeForUri (name), fileGroup);
			recentItem.Private = project != null ? string.Format ("{0} [{1}]", Path.GetFileName (name), project) : Path.GetFileName (name);
			recentFiles.AddWithLimit (recentItem, fileGroup, ItemLimit);
			OnRecentFileChange();
		}
コード例 #2
0
        static List <RecentItem> ReadStore(FileStream file)
        {
            var result = new List <RecentItem> ();

            if (file.Length == 0)
            {
                return(result);
            }

            try {
                using (var reader = XmlReader.Create(file, new XmlReaderSettings {
                    CloseInput = false
                })) {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement() && reader.LocalName == RecentItem.Node)
                        {
                            result.Add(RecentItem.Read(reader));
                        }
                    }
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while reading recent file store.", e);
            }

            return(result);
        }
コード例 #3
0
        public void AddLastProject(string name, string projectName)
        {
            RecentItem recentItem = new RecentItem(RecentFileStorage.ToUri(name), DesktopService.GetMimeTypeForUri(name), projectGroup);

            recentItem.Private = projectName;
            recentFiles.AddWithLimit(recentItem, projectGroup, ItemLimit);
            OnRecentProjectChange();
        }
コード例 #4
0
        public void AddLastFile(string name, string project)
        {
            RecentItem recentItem = new RecentItem(RecentFileStorage.ToUri(name), DesktopService.GetMimeTypeForUri(name), fileGroup);

            recentItem.Private = project != null?string.Format("{0} [{1}]", Path.GetFileName(name), project) : Path.GetFileName(name);

            recentFiles.AddWithLimit(recentItem, fileGroup, ItemLimit);
            OnRecentFileChange();
        }
コード例 #5
0
 public void AddWithLimit(RecentItem item, string group, int limit)
 {
     ModifyStore(list => {
         RemoveMatches(list, i => i.Uri == item.Uri);
         list.Add(item);
         CheckLimit(list, group, limit);
         return(true);
     });
 }
コード例 #6
0
        public override bool Equals(object obj)
        {
            RecentItem item = obj as RecentItem;

            if (item == null)
            {
                return(false);
            }
            return(uri == item.uri);
        }
コード例 #7
0
        public int CompareTo(object o)
        {
            RecentItem item = o as RecentItem;

            if (item == null)
            {
                throw new ArgumentException("Can only compare items of " + typeof(RecentItem) + " item was: " + o);
            }
            return(item.Timestamp.CompareTo(this.Timestamp));
        }
コード例 #8
0
ファイル: RecentOpen.cs プロジェクト: yayanyang/monodevelop
        void Add(string grp, string fileName, string displayName)
        {
            var mime       = DesktopService.GetMimeTypeForUri(fileName);
            var uri        = RecentFileStorage.ToUri(fileName);
            var recentItem = new RecentItem(uri, mime, grp)
            {
                Private = displayName
            };

            recentFiles.AddWithLimit(recentItem, grp, ItemLimit);
        }
コード例 #9
0
 public void AddWithLimit(RecentItem item, string group, int limit)
 {
     lock (writerLock) {
         RemoveItem(item.Uri);
         List <RecentItem> store = ReadStore(0);
         if (store != null)
         {
             store.Add(item);
             WriteStore(store);
             CheckLimit(group, limit);
         }
     }
 }
コード例 #10
0
        void Add(string grp, string fileName, string displayName)
        {
            var mime = DesktopService.GetMimeTypeForUri(fileName);

            try {
                var uri        = RecentFileStorage.ToUri(fileName);
                var recentItem = new RecentItem(uri, mime, grp)
                {
                    Private = displayName
                };
                recentFiles.AddWithLimit(recentItem, grp, ItemLimit);
            } catch (Exception e) {
                LoggingService.LogError("Failed to add item to recent files list.", e);
            }
        }
コード例 #11
0
        List <RecentItem> ReadStore(int numberOfTry)
        {
            //Debug.Assert (IsLocked);
            List <RecentItem> result = new List <RecentItem> ();

            if (!File.Exists(RecentFileStorage.RecentFileFullPath))
            {
                return(result);
            }
            XmlTextReader reader = new XmlTextReader(RecentFileStorage.RecentFileFullPath);

            try {
                while (true)
                {
                    bool read = false;
                    try {
                        // seems to crash on empty files ?
                        read = reader.Read();
                    } catch (Exception) {
                        read = false;
                    }
                    if (!read)
                    {
                        break;
                    }
                    if (reader.IsStartElement() && reader.LocalName == RecentItem.Node)
                    {
                        result.Add(RecentItem.Read(reader));
                    }
                }
            }  catch(Exception e)
            {
                MonoDevelop.Core.LoggingService.LogError("Exception while reading the store", e);
                if (numberOfTry < MAX_TRIES)
                {
                    Thread.Sleep(200);
                    return(ReadStore(numberOfTry + 1));
                }
                return(null);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(result);
        }
コード例 #12
0
        public void AddWithLimit(RecentItem item, string group, int limit)
        {
            lock (writerLock) {
                /*ObtainLock ();
                 * try {*/
                RemoveItem(item.Uri);
                List <RecentItem> store = ReadStore(0);
                if (store != null)
                {
                    store.Add(item);
                    WriteStore(store);
                    CheckLimit(group, limit);
                }

                /*} finally {
                 *      ReleaseLock ();
                 * }*/
            }
        }
コード例 #13
0
        static List <RecentItem> ReadStore(FileStream file)
        {
            var result = new List <RecentItem> ();

            if (file.Length == 0)
            {
                return(result);
            }

            using (var reader = XmlReader.Create(file, new XmlReaderSettings {
                CloseInput = false
            })) {
                while (reader.Read())
                {
                    if (reader.IsStartElement() && reader.LocalName == RecentItem.Node)
                    {
                        result.Add(RecentItem.Read(reader));
                    }
                }
            }

            return(result);
        }
コード例 #14
0
ファイル: RecentItem.cs プロジェクト: yayanyang/monodevelop
		public static RecentItem Read (XmlReader reader)
		{
			Debug.Assert (reader.LocalName == Node);
			RecentItem result = new RecentItem ();
			bool readGroup = false;
			while (reader.Read ()) {
				switch (reader.NodeType) {
				case XmlNodeType.EndElement:
					if (reader.LocalName == GroupsNode) {
						readGroup = false;
						break;
					}
					if (reader.LocalName == Node)
						return result;
					throw new XmlException ("Found unknown end element:" + reader.LocalName);
				case XmlNodeType.Element:
					if (readGroup) {
						result.AddGroup (reader.ReadElementString ());
						break;
					}
					switch (reader.LocalName) {
					case "Uri":
					case UriNode:
						result.uri = reader.ReadElementString ();
						break;
					case "MimeType":
					case MimeTypeNode:
						result.mimeType = reader.ReadElementString ();
						break;
					case TimestampNode:
						result.timestamp = ToDateTime (Int32.Parse (reader.ReadElementString ()));
						break;
					case PrivateNode:
						result.privateData = reader.ReadElementString ();
						break;
					case GroupsNode:
						readGroup = true;
						break;
					default:
						throw new XmlException ("Found unknown start element:" + reader.LocalName);
					}
					break;
				}
			}
			return null;
		}
コード例 #15
0
		public void RemoveItem (RecentItem item)
		{
			if (item != null)
				RemoveItem (item.Uri);
		}
コード例 #16
0
		public void AddLastProject (string name, string projectName)
		{
			RecentItem recentItem = new RecentItem (RecentFileStorage.ToUri (name), DesktopService.GetMimeTypeForUri (name), projectGroup);
			recentItem.Private = projectName;
			recentFiles.AddWithLimit (recentItem, projectGroup, ItemLimit);
			OnRecentProjectChange();
		}
コード例 #17
0
		public void AddWithLimit (RecentItem item, string group, int limit)
		{
			lock (writerLock) {
				RemoveItem (item.Uri);
				List<RecentItem> store = ReadStore (0);
				if (store != null) {
					store.Add (item);
					WriteStore (store);
					CheckLimit (group, limit);
				}
			}
		}
コード例 #18
0
		public bool RemoveItem (RecentItem item)
		{
			return item != null && RemoveItem (item.Uri);
		}
コード例 #19
0
ファイル: RecentOpen.cs プロジェクト: yayanyang/monodevelop
		void Add (string grp, string fileName, string displayName)
		{
			var mime = DesktopService.GetMimeTypeForUri (fileName);
			var uri = RecentFileStorage.ToUri (fileName);
			var recentItem = new RecentItem (uri, mime, grp) { Private = displayName };
			recentFiles.AddWithLimit (recentItem, grp, ItemLimit);
		}
コード例 #20
0
 public bool RemoveItem(RecentItem item)
 {
     return(item != null && RemoveItem(item.Uri));
 }
コード例 #21
0
ファイル: RecentOpen.cs プロジェクト: nocache/monodevelop
		void Add (string grp, string fileName, string displayName)
		{
			var mime = DesktopService.GetMimeTypeForUri (fileName);
			System.Threading.ThreadPool.QueueUserWorkItem (_ => {
				try {
					var uri = RecentFileStorage.ToUri (fileName);
					var recentItem = new RecentItem (uri, mime, grp) { Private = displayName };
					recentFiles.AddWithLimit (recentItem, grp, ItemLimit);
				} catch (Exception e) {
					LoggingService.LogError ("Failed to add item to recent files list.", e);
				}
			});
		}
コード例 #22
0
		public void AddWithLimit (RecentItem item, string group, int limit)
		{
			lock (writerLock) {
			/*ObtainLock ();
			try {*/
				RemoveItem (item.Uri);
				List<RecentItem> store = ReadStore (0);
				if (store != null) {
					store.Add (item);
					WriteStore (store);
					CheckLimit (group, limit);
				}
			/*} finally {
				ReleaseLock ();
			}*/
			}
		}