コード例 #1
0
 private static FolderStruct LoadSubDirs(FolderStruct FolderTree)
 {
     try
     {
         string[] subdirectories = Directory.GetDirectories(FolderTree.FolderName);
         if (subdirectories != null)
         {
             foreach (string subdir in subdirectories)
             {
                 var newFolder = new FolderStruct()
                 {
                     FolderName     = subdir,
                     FolderChildren = new List <FolderStruct>()
                 };
                 var ret = LoadSubDirs(newFolder);
                 if (ret != null)
                 {
                     FolderTree.FolderChildren.Add(ret);
                 }
             }
             return(FolderTree);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
     return(null);
 }
コード例 #2
0
    static void Main(string[] args)
    {
        FolderStruct FolderTree = new FolderStruct
        {
            FolderName     = @"D:\",
            FolderChildren = new List <FolderStruct>()
        };

        LoadSubDirs(FolderTree);
        Console.ReadKey();
    }
コード例 #3
0
        private List <FolderStruct> GetFolderList()
        {
            var folders = new List <FolderStruct>();

            try
            {
                XmlDocument reports = new XmlDocument();
                reports.Load(Path.Combine(reportsFolder, "reports.xml"));

                for (int i = 0; i < reports.Root.Count; i++)
                {
                    FolderStruct folder = new FolderStruct();

                    XmlItem folderItem = reports.Root[i];
                    if (folderItem.GetProp("WinDemo") == "false")
                    {
                        continue;
                    }

                    string text = folderItem.GetProp("Name");

                    folder.FolderName  = text;
                    folder.Description = folderItem.GetProp("Description");
                    for (int j = 0; j < folderItem.Count; j++)
                    {
                        ReportStruct report = new ReportStruct();

                        XmlItem reportItem = folderItem[j];
                        //if (reportItem.GetProp("WinDemo") == "false")
                        //    continue;

                        string file = reportItem.GetProp("File");

                        if (!File.Exists(Path.Combine(reportsFolder, file)))
                        {
                            continue;
                        }

                        string fileName = Path.GetFileNameWithoutExtension(file);

                        report.FileName = fileName;
                        report.File     = file;
                        folder.Reports.Add(report);
                    }

                    folders.Add(folder);
                }
            }
            catch
            {
            }
            return(folders);
        }
コード例 #4
0
        private void tree_MouseMove(object sender, MouseEventArgs e)
        {
            Point mpos = e.GetPosition(null);

            if (this.start == null)
            {
                return;
            }

            Vector diff = (Vector)(this.start - mpos);

            if (sender is ListBox)
            {
                if (((ListBox)sender).SelectedItem == null)
                {
                    return;
                }
            }
            else if (sender is TreeView)
            {
                if (((TreeView)sender).SelectedItem == null)
                {
                    return;
                }
            }
            else
            {
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed &&
                Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
                Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
            {
                Console.WriteLine("Started Drag-Drop Operation");
                Dictionary <string, FileEntry> fileList = new Dictionary <string, FileEntry>();

                if (sender is TreeView)
                {
                    FolderStruct folder = (FolderStruct)((TreeViewItem)((TreeView)sender).SelectedItem).Tag;
                    folder.GetSubFileEntries(fileList, folder.Name);
                }
                else if (sender is ListView)
                {
                    if (((ListBox)sender).SelectedItem != null)
                    {
                        foreach (object selected_item in ((ListBox)sender).SelectedItems)
                        {
                            if (selected_item is FileEntry)
                            {
                                FileEntry file = selected_item as FileEntry;
                                fileList.Add(System.IO.Path.GetFileName(file.Path), file);
                            }
                            else if (selected_item is FolderStruct)
                            {
                                FolderStruct folder = selected_item as FolderStruct;
                                folder.GetSubFileEntries(fileList, folder.Name == "assets" ? "" : folder.Name);
                            }
                        }
                    }
                }

                this.InitiateDragDrop(fileList);
                this.start = null;
            }
        }
コード例 #5
0
 private void FolderClick(FolderStruct folder)
 {
     folder.Hiden = !folder.Hiden;
 }