コード例 #1
0
        public FileSlice(String _path, int _sliceHeight, MainWindow parent)
            : base()
        {
            path         = _path;
            sliceHeight  = _sliceHeight;
            parentWindow = parent;

            LinkedList <String> files   = new LinkedList <String>();
            LinkedList <String> folders = new LinkedList <String>();

            // prune hidden files
            if (!showHidden)
            {
                String[] rawFiles   = Directory.GetFiles(path);
                String[] rawFolders = Directory.GetDirectories(path);
                Array.Sort(rawFiles);
                Array.Sort(rawFolders);

                foreach (var file in rawFiles)
                {
                    if (!file.Replace(path, "").StartsWith("/."))
                    {
                        files.AddLast(file);
                    }
                }
                foreach (var file in rawFolders)
                {
                    if (!file.Replace(path, "").StartsWith("/."))
                    {
                        folders.AddLast(file);
                    }
                }
            }
            else
            {
                files   = new LinkedList <String>(Directory.GetFiles(path));
                folders = new LinkedList <String>(Directory.GetDirectories(path));
            }

            // set up storage
            fileNodes = new FileNode[files.Count + folders.Count];
            numFiles  = fileNodes.Length;

            // decide if we will show all the labels, or just the ones near us
            if (fileNodes.Length < SHOW_ALL_LIMIT)
            {
                showAllText = true;
            }

            int nodeCount = 0;

            if (numFiles > 0)
            {
                // set up width and height in boxes
                gridWidth  = (int)Math.Round(Math.Sqrt(fileNodes.Length) / ASPECT_COEFF, 0);
                gridHeight = fileNodes.Length / gridWidth;
                if (fileNodes.Length % gridHeight > 0)
                {
                    gridHeight += 1;
                }

                // generate the nodes
                foreach (var folder in folders)
                {
                    FileNode node      = NodeManager.GetFileNode(NodeManager.DIR_NODE, folder, this);
                    float    xPosition = STARTX - ((nodeCount % gridWidth) * BOX_SPACING);
                    float    zPosition = STARTZ + ((nodeCount / gridWidth) * BOX_SPACING);
                    node.Position = new Vector3(xPosition, STARTY, zPosition);
                    if (nodeCount == 0)
                    {
                        node.Active = true;
                    }
                    fileNodes[nodeCount] = node;
                    nodeCount++;
                }

                foreach (var file in files)
                {
                    FileNode node      = NodeManager.GetFileNode(NodeManager.FILE_NODE, file, this);
                    float    xPosition = STARTX - ((nodeCount % gridWidth) * BOX_SPACING);
                    float    zPosition = STARTZ + ((nodeCount / gridWidth) * BOX_SPACING);

                    node.Position = new Vector3(xPosition, STARTY, zPosition);
                    if (nodeCount == 0)
                    {
                        node.Active = true;
                    }
                    fileNodes[nodeCount] = node;
                    nodeCount++;
                }
            }
            if (showAllText)
            {
                GenerateAllTextures();
            }
            else
            {
                ResetVisible();
            }
        }
コード例 #2
0
ファイル: NodeManager.cs プロジェクト: dardevelin/Glomp
        public static FileNode GetFileNode(int nodeType, String fileName, FileSlice owner)
        {
            int fileDisplayList;

            if (listGenerated[nodeType])
            {
                fileDisplayList = displayLists[nodeType];
            }
            else
            {
                fileDisplayList = displayLists[nodeType] = GenerateDisplayList(nodeType);
            }


            GLib.File fi = GLib.FileFactory.NewForPath(fileName);

            FileNode node = new FileNode(fi.Basename);

            node.File = fileName;
            //node.NumChildren = fi.
            GLib.FileInfo info = fi.QueryInfo("access::can-execute,thumbnail::path,filesystem::readonly,time::modified", GLib.FileQueryInfoFlags.None, null);
            node.SetDisplayList(fileDisplayList);

            node.SetParent(owner);

            if (nodeType == DIR_NODE)
            {
                node.IsDirectory = true;
                try {
                    node.NumDirs     = Directory.GetDirectories(fileName).Length;
                    node.NumFiles    = Directory.GetFiles(fileName).Length;
                    node.NumChildren = node.NumDirs + node.NumFiles;
                    node.DirHeight   = GetHeightForFolder(node.NumChildren);
                } catch {
                    node.NumChildren = 0;
                    node.DirHeight   = 1f;
                }
            }
            else
            {
                String description = Gnome.Vfs.Mime.GetDescription(fi.QueryInfo("standard::content-type", GLib.FileQueryInfoFlags.None, null).ContentType);
                if (description == null)
                {
                    // use the extension
                    String[] split = node.FileName.Split('.');
                    if (split.Length > 1)
                    {
                        description = split[split.Length - 1] + " file";
                    }
                    else
                    {
                        // no extension either
                        description = "unknown";
                    }
                }
                node.Description = description;

                if (info.GetAttributeBoolean("filesystem::readonly"))
                {
                    node.IsReadOnly = true;
                }
                else if (info.GetAttributeBoolean("access::can-execute"))
                {
                    node.IsExecutable = true;
                }
                else
                {
                    node.TypeColour = NodeManager.GetColourForNode(node);
                }
            }


            node.ModifyTime = ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified")));
            //Console.WriteLine(node.File + " : " + node.ModifyTime.ToString("MMMM dd, yyyy"));

            string previewPath = info.GetAttributeByteString("thumbnail::path");

            if (previewPath != null)
            {
                node.ThumbFileName = previewPath;
            }

            return(node);
        }