Exemplo n.º 1
0
        protected override MenuList OnGetMenuItems()
        {
            // intentionally dont inherit
            MenuList list = new MenuList();

            list.SetContainerTitle(MenuListContainer.CustomOne, Catalog.GetString("Restore Files"));

            FileEnumerator enumerator = OwnedFile.EnumerateChildren("standard::type,standard::name", FileQueryInfoFlags.NofollowSymlinks, null);
            List <File>    files      = new List <File> ();

            if (enumerator != null)
            {
                FileInfo info;

                while ((info = enumerator.NextFile()) != null)
                {
                    files.Add(OwnedFile.GetChild(info.Name));
                    info.Dispose();
                }

                if (info != null)
                {
                    info.Dispose();
                }
                enumerator.Close(null);
                enumerator.Dispose();
            }

            /* FIXME
             *      - this code should work, but GetFiles() currently uses .net IO instead of GIO
             *        when this starts working, the enumeration block above can go away too
             * foreach (File _f in OwnedFile.GetFiles ().OrderByDescending (f => f.QueryInfo<string> ("trash::deletion-date")).Take (5)) {
             */
            foreach (File _f in files.OrderByDescending(f => f.QueryInfo <string> ("trash::deletion-date")).Take(5))
            {
                File     f    = _f;
                MenuItem item = new IconMenuItem(f.Basename, f.Icon(), (o, a) => RestoreFile(f));
                item.Mnemonic = null;
                list[MenuListContainer.CustomOne].Add(item);
            }

            list[MenuListContainer.CustomTwo].Add(
                new MenuItem(Catalog.GetString("_Open Trash"), Icon, (o, a) => OpenTrash()));
            list[MenuListContainer.CustomTwo].Add(
                new MenuItem(Catalog.GetString("Empty _Trash"), "gtk-clear", (o, a) => EmptyTrash(), !TrashFull));

            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recursive equivalent to GLib.File.Delete () when called on a directory.
        /// Functionally equivalent to GLib.File.Delete when called on files.
        /// </summary>
        /// <param name="file">
        /// A <see cref="GLib.File"/>
        /// </param>
        public static void Delete_Recurse(this GLib.File file)
        {
            FileEnumerator enumerator = null;

            try {
                enumerator = file.EnumerateChildren("standard::type,standard::name,access::can-delete", FileQueryInfoFlags.NofollowSymlinks, null);
            } catch { }

            if (enumerator == null)
            {
                return;
            }

            FileInfo info;

            while ((info = enumerator.NextFile()) != null)
            {
                File child = file.GetChild(info.Name);

                if (info.FileType == FileType.Directory)
                {
                    Delete_Recurse(child);
                }

                try {
                    if (info.GetAttributeBoolean("access::can-delete"))
                    {
                        child.Delete(null);
                    }
                } catch {
                    // if it fails to delete, not much we can do!
                }

                info.Dispose();
            }

            if (info != null)
            {
                info.Dispose();
            }
            enumerator.Close(null);
            enumerator.Dispose();
        }