コード例 #1
0
		public override bool RemoveItem (AbstractDockItem item)
		{
			if (!ItemCanBeRemoved (item))
				return false;
			
			FileDockItem bookmark = item as FileDockItem;
			
			if (!bookmark.OwnedFile.Exists)
				return false;
			
			File tempFile = FileFactory.NewForPath (System.IO.Path.GetTempFileName ());
			
			using (DataInputStream reader = new DataInputStream (BookmarksFile.Read (null))) {
				using (DataOutputStream writer = new DataOutputStream (tempFile.AppendTo (FileCreateFlags.None, null))) {
					string line;
					ulong length;
					while ((line = reader.ReadLine (out length, null)) != null) {
						if (line.Split (' ')[0] != bookmark.Uri) {
							writer.PutString (string.Format ("{0}{1}", line, reader.NewLineString ()), null);
						} else {
							items.Remove (bookmark);
							Items = InnerItems;
							Log<BookmarksItemProvider>.Debug ("Removing '{0}'", bookmark.HoverText);
						}
					}
				}
			}
			
			if (tempFile.Exists)
				tempFile.Move (BookmarksFile, FileCopyFlags.Overwrite, null, null);

			return true;
		}
コード例 #2
0
		protected override AbstractDockItem OnAcceptDrop (string uri)
		{
			File tempFile = FileFactory.NewForPath (System.IO.Path.GetTempFileName ());
			FileDockItem bookmark = FileDockItem.NewFromUri (uri);
			
			// make sure the bookmarked location actually exists
			if (!bookmark.OwnedFile.Exists)
				return null;
			
			using (DataInputStream reader = new DataInputStream (BookmarksFile.Read (null))) {
				using (DataOutputStream writer = new DataOutputStream (tempFile.AppendTo (FileCreateFlags.None, null))) {
					string line;
					ulong length;
					while ((line = reader.ReadLine (out length, null)) != null)
						writer.PutString (string.Format ("{0}{1}", line, reader.NewLineString ()), null);
					
					writer.PutString (string.Format ("{0}{1}", bookmark.Uri, reader.NewLineString ()), null);
				}
			}
			
			items.Add (bookmark);
			Items = InnerItems;
			
			if (tempFile.Exists)
				tempFile.Move (BookmarksFile, FileCopyFlags.Overwrite, null, null);
			
			return bookmark;
		}