Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        void UpdateItems()
        {
            List <AbstractDockItem> old = items;

            items = new List <AbstractDockItem> ();

            Log <BookmarksItemProvider> .Debug("Updating bookmarks.");

            if (!BookmarksFile.QueryExists(null))
            {
                Log <BookmarksItemProvider> .Error("File '{0} does not exist.", BookmarksFile);

                return;
            }

            using (DataInputStream stream = new DataInputStream(BookmarksFile.Read(null))) {
                ulong  length;
                string line, name, uri;
                while ((line = stream.ReadLine(out length, null)) != null)
                {
                    uri = line.Split(' ').First();
                    File bookmark = FileFactory.NewForUri(uri);
                    name = line.Substring(uri.Length).Trim();
                    if (old.Cast <FileDockItem> ().Any(fdi => fdi.Uri == uri))
                    {
                        FileDockItem item = old.Cast <FileDockItem> ().First(fdi => fdi.Uri == uri);
                        old.Remove(item);
                        items.Add(item);
                        item.ForcedHoverText = name;
                    }
                    else if (bookmark.StringUri().StartsWith("file://") && !bookmark.Exists)
                    {
                        Log <BookmarksItemProvider> .Warn("Bookmark path '{0}' does not exist, please fix the bookmarks file", bookmark.StringUri());

                        continue;
                    }
                    else
                    {
                        FileDockItem item = FileDockItem.NewFromUri(bookmark.StringUri(), name, "folder");
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                }
            }

            Items = InnerItems;

            foreach (AbstractDockItem item in old)
            {
                item.Dispose();
            }
        }
Exemplo n.º 3
0
        public BookmarksItemProvider()
        {
            items = new List <AbstractDockItem> ();

            computer = new NonRemovableItem("computer://", Catalog.GetString("Computer"), "computer");
            home     = FileDockItem.NewFromUri(string.Format("file://{0}",
                                                             Environment.GetFolderPath(Environment.SpecialFolder.Personal)));

            UpdateItems();

            watcher = FileMonitor.File(BookmarksFile, FileMonitorFlags.None, null);

            watcher.Changed += WatcherChanged;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void RefreshRecentDocs()
        {
            List <AbstractDockItem> items = new List <AbstractDockItem> ();

            GLib.List recent_items             = new GLib.List(Gtk.RecentManager.Default.Items.Handle, typeof(Gtk.RecentInfo), false, false);
            IEnumerable <Gtk.RecentInfo> infos = recent_items.OfType <Gtk.RecentInfo> ();

            CanClear = recent_items.Count > 0;

            items.Add(emptyItem);
            items.AddRange(infos.Where(it => it.Exists())
                           .OrderByDescending(f => f.Modified)
                           .Take(NumRecentDocs)
                           .Select(f => (AbstractDockItem)FileDockItem.NewFromUri(f.Uri)));

            foreach (Gtk.RecentInfo ri in infos)
            {
                ri.Dispose();
            }
            recent_items.Dispose();

            Items = items;
        }