TreeViewFolderBrowserHelper is like a bridge between ITreeViewFolderBrowserDataProvider and TreeViewFolderBrowser and provides access to the needed informations to fill the tree view.
Ejemplo n.º 1
0
        public void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            AttachSystemImageList(helper);
            TreeNodeCollection rootNodeCollection;

            isRootFolder = true;
            TreeNodePath rootNode = CreateTreeNode(helper, "MediaPortal Database", "Root", false, false, true);

            helper.TreeView.Nodes.Add(rootNode);
            rootNodeCollection = helper.TreeView.Nodes[0].Nodes;

            TreeNodePath artistNode = CreateTreeNode(helper, "Artist", "Artist", true, false, true);

            artistNode.Tag = "artist";
            rootNodeCollection.Add(artistNode);

            TreeNodePath albumArtistNode = CreateTreeNode(helper, "Album Artist", "AlbumArtist", true, false, true);

            albumArtistNode.Tag = "albumartist";
            rootNodeCollection.Add(albumArtistNode);

            TreeNodePath albumNode = CreateTreeNode(helper, "Album", "Album", true, false, true);

            albumNode.Tag = "album";
            rootNodeCollection.Add(albumNode);

            TreeNodePath genreNode = CreateTreeNode(helper, "Genre", "Genre", true, false, true);

            genreNode.Tag = "genre";
            rootNodeCollection.Add(genreNode);
            isRootFolder = false;
        }
Ejemplo n.º 2
0
        public override void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
        {
            if (!EnableContextMenu)
            {
                return;
            }
            //
            FolderItem fi = node.Tag as FolderItem;

            if (fi == null)
            {
                return;
            }
            //
            foreach (FolderItemVerb verb in fi.Verbs())
            {
                if (verb.Name.Length == 0)
                {
                    continue;
                }
                //
                MenuItemShellVerb item = new MenuItemShellVerb(verb);
                helper.TreeView.ContextMenu.MenuItems.Add(item);
            }
        }
Ejemplo n.º 3
0
 public override TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
 {
     if (isNetwork)
     {
         return(_rootCollectionNetwork);
     }
     return(_rootCollection);
 }
 public virtual TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
 {
     switch (helper.TreeView.RootFolder)
       {
     case Environment.SpecialFolder.Desktop:
       return helper.TreeView.Nodes[0].Nodes[1].Nodes;
     default:
       return helper.TreeView.Nodes;
       }
 }
Ejemplo n.º 5
0
        public virtual TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
        {
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                return(helper.TreeView.Nodes[0].Nodes[1].Nodes);

            default:
                return(helper.TreeView.Nodes);
            }
        }
Ejemplo n.º 6
0
 protected virtual void AttachSystemImageList(TreeViewFolderBrowserHelper helper)
 {
     if (_checkboxMode != helper.TreeView.CheckboxBehaviorMode)
     {
         // checkboxes recreate the control internal
         if (_systemImageList != null)
         {
             SystemImageListHelper.SetTreeViewImageList(helper.TreeView, _systemImageList, false);
         }
     }
     _checkboxMode = helper.TreeView.CheckboxBehaviorMode;
 }
Ejemplo n.º 7
0
        public override void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            _helper = helper;
            AttachSystemImageList(helper);
            //
            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                Folder2 desktopFolder = (Folder2)_shell.GetDesktop();
                // create root node <Desktop>
                TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false,
                                                          true);
                helper.TreeView.Nodes.Add(desktopNode);
                desktopNode.Tag = desktopFolder;
                //
                Folder2 myComputer = (Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES);
                foreach (FolderItem fi in desktopFolder.Items())
                {
                    if (!fi.IsFolder)
                    {
                        continue;
                    }
                    //
                    TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
                    node.Tag = fi;
                    desktopNode.Nodes.Add(node);
                    //
                    if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
                    {
                        _rootCollection = node.Nodes;
                    }
                }
                break;

            case Environment.SpecialFolder.MyComputer:
                FillMyComputer(((Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES)).Self,
                               helper.TreeView.Nodes, helper);
                break;

            default:
                // create root node with specified SpecialFolder
                Folder2      root     = (Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
                TreeNodePath rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
                rootNode.Tag = root.Self;
                helper.TreeView.Nodes.Add(rootNode);
                _rootCollection = rootNode.Nodes;
                break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///   Creates a new node and assigns a icon
        /// </summary>
        /// <param name = "helper"></param>
        /// <param name = "text"></param>
        /// <param name = "path"></param>
        /// <param name = "addDummyNode"></param>
        /// <param name = "forceChecked"></param>
        /// <returns></returns>
        protected virtual TreeNodePath CreateTreeNode(TreeViewFolderBrowserHelper helper, string text, string path,
                                                      bool addDummyNode, bool forceChecked, bool isSpecialFolder)
        {
            TreeNodePath node = helper.CreateTreeNode(text, path, addDummyNode, forceChecked, isSpecialFolder);

            try
            {
                SetIcon(helper.TreeView, node);
            }
            catch
            {
                node.ImageIndex         = -1;
                node.SelectedImageIndex = -1;
            }
            return(node);
        }
Ejemplo n.º 9
0
 /// <summary>
 ///   Required designer variable.
 /// </summary>
 public TreeViewFolderBrowser()
 {
     InitializeComponent();
     // initalize a new helper instance for this tree view.
     _helper = new TreeViewFolderBrowserHelper(this);
     //
     ContextMenu        = new ContextMenu();
     ContextMenu.Popup += OnContextMenu_Popup;
     //
     _driveTypes = DriveTypes.NoRootDirectory | DriveTypes.RemovableDisk | DriveTypes.LocalDisk |
                   DriveTypes.NetworkDrive | DriveTypes.CompactDisc | DriveTypes.RAMDisk;
     RootFolder           = Environment.SpecialFolder.MyComputer;
     CheckboxBehaviorMode = CheckboxBehaviorMode.SingleChecked;
     // init bold font
     boldFont_ = new Font(Font, FontStyle.Bold);
 }
Ejemplo n.º 10
0
        public virtual void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent,
                                           TreeViewCancelEventArgs e)
        {
            if (parent.Path == null)
            {
                return;
            }
            //
            DirectoryInfo directory = new DirectoryInfo(parent.Path);

            // check persmission
            new FileIOPermission(FileIOPermissionAccess.PathDiscovery, directory.FullName).Demand();
            //

            // Sort the Directories, as Samba might return unsorted
            DirectoryInfo[] dirInfo = directory.GetDirectories();
            Array.Sort(dirInfo,
                       new Comparison <DirectoryInfo>(
                           delegate(DirectoryInfo d1, DirectoryInfo d2) { return(string.Compare(d1.Name, d2.Name)); }));


            foreach (DirectoryInfo dir in dirInfo)
            {
                if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                TreeNodePath newNode = CreateTreeNode(helper, dir.Name, dir.FullName, false,
                                                      ((helper.TreeView.CheckboxBehaviorMode != CheckboxBehaviorMode.None) &&
                                                       (parent.Checked)), false);
                parent.Nodes.Add(newNode);
                //
                try
                {
                    if (dir.GetDirectories().GetLength(0) > 0)
                    {
                        newNode.AddDummyNode();
                    }
                }
                catch {}
            }
        }
Ejemplo n.º 11
0
 protected virtual void FillMyComputer(FolderItem folderItem, TreeNodeCollection parentCollection,
                                       TreeViewFolderBrowserHelper helper)
 {
     _rootCollection = parentCollection;
     Logicaldisk.LogicaldiskCollection logicalDisks = null;
     // get wmi logical disk's if we have to
     if (helper.TreeView.DriveTypes != DriveTypes.All)
     {
         logicalDisks = Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView));
     }
     //
     foreach (FolderItem fi in ((Folder)folderItem.GetFolder).Items())
     {
         // only File System shell objects ?
         if (!_showAllShellObjects && !fi.IsFileSystem)
         {
             continue;
         }
         // check drive type
         if (fi.IsFileSystem && logicalDisks != null)
         {
             bool skipDrive = true;
             foreach (Logicaldisk lg in logicalDisks)
             {
                 if (lg.Name + "\\" == fi.Path)
                 {
                     skipDrive = false;
                     break;
                 }
             }
             if (skipDrive)
             {
                 continue;
             }
         }
         // create new node
         TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
         node.Tag = fi;
         parentCollection.Add(node);
     }
 }
Ejemplo n.º 12
0
        public override void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent,
                                            TreeViewCancelEventArgs e)
        {
            if (!parent.IsSpecialFolder)
            {
                return;
            }
            //
            FolderItem2 folderItem = ((FolderItem2)parent.Tag);

            //
            if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == folderItem.Name)
            {
                FillMyComputer(folderItem, parent.Nodes, helper);
            }
            else
            {
                List <TreeNodePath> nodes = new List <TreeNodePath>();
                foreach (FolderItem2 fi in ((Folder2)folderItem.GetFolder).Items())
                {
                    if (!_showAllShellObjects && !fi.IsFileSystem || !fi.IsFolder)
                    {
                        continue;
                    }
                    //
                    TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
                    node.Tag = fi;
                    nodes.Add(node);
                }

                // Sort the Directories, as Samba might return unsorted
                TreeNodePath[] nodesArray = nodes.ToArray();
                Array.Sort(nodesArray,
                           new Comparison <TreeNodePath>(
                               delegate(TreeNodePath p1, TreeNodePath p2) { return(string.Compare(p1.Text, p2.Text)); }));

                parent.Nodes.AddRange(nodesArray);
            }
        }
        public override void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            _helper = helper;
              AttachSystemImageList(helper);
              //
              // setup up root node collection
              switch (helper.TreeView.RootFolder)
              {
            case Environment.SpecialFolder.Desktop:
              Folder2 desktopFolder = (Folder2)_shell.GetDesktop();
              // create root node <Desktop>
              TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false,
                                                    true);
              helper.TreeView.Nodes.Add(desktopNode);
              desktopNode.Tag = desktopFolder;
              //
              foreach (FolderItem fi in desktopFolder.Items())
              {
            // Don't list Non-Folders, Control Panel and Waste BAsket
            if (!fi.IsFolder) continue;
            if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfBITBUCKET).Title == fi.Name) continue;
            if (fi.Path == "::{26EE0668-A00A-44D7-9371-BEB064C98683}") continue;

            TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
            node.Tag = fi;
            desktopNode.Nodes.Add(node);

            if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
              _rootCollection = node.Nodes;

            if (fi.Path == "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}")
            {
              _rootCollectionNetwork = node.Nodes;
            }
              }
              break;
            case Environment.SpecialFolder.MyComputer:
              FillMyComputer(((Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES)).Self,
                         helper.TreeView.Nodes, helper);
              break;
            default:
              // create root node with specified SpecialFolder
              Folder2 root = (Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
              TreeNodePath rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
              rootNode.Tag = root.Self;
              helper.TreeView.Nodes.Add(rootNode);
              _rootCollection = rootNode.Nodes;
              break;
              }
        }
 protected virtual void FillMyComputer(FolderItem folderItem, TreeNodeCollection parentCollection,
     TreeViewFolderBrowserHelper helper)
 {
     _rootCollection = parentCollection;
       Logicaldisk.LogicaldiskCollection logicalDisks = null;
       // get wmi logical disk's if we have to
       if (helper.TreeView.DriveTypes != DriveTypes.All)
     logicalDisks = Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView));
       //
       foreach (FolderItem fi in ((Folder)folderItem.GetFolder).Items())
       {
     // only File System shell objects ?
     if (!_showAllShellObjects && !fi.IsFileSystem) continue;
     // check drive type
     if (fi.IsFileSystem && logicalDisks != null)
     {
       bool skipDrive = true;
       foreach (Logicaldisk lg in logicalDisks)
       {
     if (lg.Name + "\\" == fi.Path)
     {
       skipDrive = false;
       break;
     }
       }
       if (skipDrive) continue;
     }
     // create new node
     TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
     node.Tag = fi;
     parentCollection.Add(node);
       }
 }
        public override void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent,
            TreeViewCancelEventArgs e)
        {
            if (!parent.IsSpecialFolder) return;
              //
              FolderItem2 folderItem = ((FolderItem2)parent.Tag);
              //
              if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == folderItem.Name)
              {
            FillMyComputer(folderItem, parent.Nodes, helper);
              }
              else
              {
            List<TreeNodePath> nodes = new List<TreeNodePath>();
            foreach (FolderItem2 fi in ((Folder2)folderItem.GetFolder).Items())
            {
              if (!_showAllShellObjects && !fi.IsFileSystem || !fi.IsFolder) continue;
              //
              TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
              node.Tag = fi;
              nodes.Add(node);
            }

            // Sort the Directories, as Samba might return unsorted
            TreeNodePath[] nodesArray = nodes.ToArray();
            Array.Sort(nodesArray,
                   new Comparison<TreeNodePath>(
                     delegate(TreeNodePath p1, TreeNodePath p2) { return string.Compare(p1.Text, p2.Text); }));

            parent.Nodes.AddRange(nodesArray);
              }
        }
 public override void RequestRoot(TreeViewFolderBrowserHelper helper)
 {
     _helper = helper;
       AttachSystemImageList(helper);
       //
       // setup up root node collection
       switch (helper.TreeView.RootFolder)
       {
     case Environment.SpecialFolder.Desktop:
       Folder2 desktopFolder = (Folder2)_shell.GetDesktop();
       // create root node <Desktop>
       TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false,
                                             true);
       helper.TreeView.Nodes.Add(desktopNode);
       desktopNode.Tag = desktopFolder;
       //
       Folder2 myComputer = (Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES);
       foreach (FolderItem fi in desktopFolder.Items())
       {
     if (!fi.IsFolder) continue;
     //
     TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
     node.Tag = fi;
     desktopNode.Nodes.Add(node);
     //
     if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
       _rootCollection = node.Nodes;
       }
       break;
     case Environment.SpecialFolder.MyComputer:
       FillMyComputer(((Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES)).Self,
                  helper.TreeView.Nodes, helper);
       break;
     default:
       // create root node with specified SpecialFolder
       Folder2 root = (Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
       TreeNodePath rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
       rootNode.Tag = root.Self;
       helper.TreeView.Nodes.Add(rootNode);
       _rootCollection = rootNode.Nodes;
       break;
       }
 }
 public override TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper)
 {
     return _rootCollection;
 }
 public override void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
 {
     if (!EnableContextMenu) return;
       //
       FolderItem fi = node.Tag as FolderItem;
       if (fi == null) return;
       //
       foreach (FolderItemVerb verb in fi.Verbs())
       {
     if (verb.Name.Length == 0) continue;
     //
     MenuItemShellVerb item = new MenuItemShellVerb(verb);
     helper.TreeView.ContextMenu.MenuItems.Add(item);
       }
 }
Ejemplo n.º 19
0
 public override TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper)
 {
     return(_rootCollection);
 }
Ejemplo n.º 20
0
 public virtual void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
 {
 }
 /// <summary>
 ///   Required designer variable.
 /// </summary>
 public TreeViewFolderBrowser()
 {
     InitializeComponent();
       // initalize a new helper instance for this tree view.
       _helper = new TreeViewFolderBrowserHelper(this);
       //
       ContextMenu = new ContextMenu();
       ContextMenu.Popup += OnContextMenu_Popup;
       //
       _driveTypes = DriveTypes.NoRootDirectory | DriveTypes.RemovableDisk | DriveTypes.LocalDisk |
             DriveTypes.NetworkDrive | DriveTypes.CompactDisc | DriveTypes.RAMDisk;
       RootFolder = Environment.SpecialFolder.MyComputer;
       CheckboxBehaviorMode = CheckboxBehaviorMode.SingleChecked;
       // init bold font
       boldFont_ = new Font(Font, FontStyle.Bold);
 }
 public void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
 {
 }
Ejemplo n.º 23
0
        public override void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            _helper = helper;
            AttachSystemImageList(helper);
            //
            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                Folder2 desktopFolder = (Folder2)_shell.GetDesktop();
                // create root node <Desktop>
                TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false,
                                                          true);
                helper.TreeView.Nodes.Add(desktopNode);
                desktopNode.Tag = desktopFolder;
                //
                foreach (FolderItem fi in desktopFolder.Items())
                {
                    // Don't list Non-Folders, Control Panel and Waste BAsket
                    if (!fi.IsFolder)
                    {
                        continue;
                    }
                    if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfBITBUCKET).Title == fi.Name)
                    {
                        continue;
                    }
                    if (fi.Path == "::{26EE0668-A00A-44D7-9371-BEB064C98683}")
                    {
                        continue;
                    }

                    TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
                    node.Tag = fi;
                    desktopNode.Nodes.Add(node);

                    if (_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
                    {
                        _rootCollection = node.Nodes;
                    }

                    if (fi.Path == "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}")
                    {
                        _rootCollectionNetwork = node.Nodes;
                    }
                }
                break;

            case Environment.SpecialFolder.MyComputer:
                FillMyComputer(((Folder2)_shell.Shell.NameSpace(ShellSpecialFolderConstants.ssfDRIVES)).Self,
                               helper.TreeView.Nodes, helper);
                break;

            default:
                // create root node with specified SpecialFolder
                Folder2      root     = (Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
                TreeNodePath rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
                rootNode.Tag = root.Self;
                helper.TreeView.Nodes.Add(rootNode);
                _rootCollection = rootNode.Nodes;
                break;
            }
        }
        public void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            AttachSystemImageList(helper);
              TreeNodeCollection rootNodeCollection;

              isRootFolder = true;
              TreeNodePath rootNode = CreateTreeNode(helper, "MediaPortal Database", "Root", false, false, true);
              helper.TreeView.Nodes.Add(rootNode);
              rootNodeCollection = helper.TreeView.Nodes[0].Nodes;

              TreeNodePath artistNode = CreateTreeNode(helper, "Artist", "Artist", true, false, true);
              artistNode.Tag = "artist";
              rootNodeCollection.Add(artistNode);

              TreeNodePath albumArtistNode = CreateTreeNode(helper, "Album Artist", "AlbumArtist", true, false, true);
              albumArtistNode.Tag = "albumartist";
              rootNodeCollection.Add(albumArtistNode);

              TreeNodePath albumNode = CreateTreeNode(helper, "Album", "Album", true, false, true);
              albumNode.Tag = "album";
              rootNodeCollection.Add(albumNode);

              TreeNodePath genreNode = CreateTreeNode(helper, "Genre", "Genre", true, false, true);
              genreNode.Tag = "genre";
              rootNodeCollection.Add(genreNode);
              isRootFolder = false;
        }
Ejemplo n.º 25
0
        public void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent, TreeViewCancelEventArgs e)
        {
            if (parent.Path == null)
            {
                return;
            }

            if (parent.Path == "")
            {
                rootFolder = RootFolder.None;
            }

            string sql             = string.Empty;
            bool   createDummyNode = true;
            string nodeTag;

            // We have a Special folder, when we are at the root level
            if (parent.IsSpecialFolder)
            {
                rootFolder = RootFolder.None;
            }

            if (rootFolder == RootFolder.None)
            {
                switch ((string)parent.Tag)
                {
                case "artist":
                    rootFolder = RootFolder.Artist;
                    sql        = SQL_STMT_ARTIST;
                    break;

                case "albumartist":
                    rootFolder = RootFolder.AlbumArtist;
                    sql        = SQL_STMT_ALBUMARTIST;
                    break;

                case "album":
                    rootFolder      = RootFolder.Album;
                    sql             = SQL_STMT_ALBUM;
                    createDummyNode = false;
                    break;

                case "genre":
                    rootFolder = RootFolder.Genre;
                    sql        = SQL_STMT_GENRE;
                    break;
                }
            }
            else if (rootFolder == RootFolder.Artist)
            {
                sql             = string.Format(SQL_STMT_ARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
                isRootFolder    = false;
                createDummyNode = false;
            }
            else if (rootFolder == RootFolder.AlbumArtist)
            {
                sql             = string.Format(SQL_STMT_ALBUMARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
                isRootFolder    = false;
                createDummyNode = false;
            }
            else if (rootFolder == RootFolder.Genre)
            {
                isRootFolder = false;
                string[] searchString = (parent.Tag as string).Split('\\');
                if (searchString.GetLength(0) == 2)
                {
                    sql             = string.Format(SQL_STMT_GENREARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
                    createDummyNode = true;
                }
                else
                {
                    sql = string.Format(SQL_STMT_GENREARTISTALBUMSEARCH, Util.RemoveInvalidChars(searchString[1]),
                                        Util.RemoveInvalidChars(parent.Path));
                    createDummyNode = false;
                }
            }

            string connection = string.Format(@"Data Source={0}", Options.MainSettings.MediaPortalDatabase);

            try
            {
                SQLiteConnection conn = new SQLiteConnection(connection);
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    log.Debug("TreeViewBrowser: Executing sql: {0}", sql);
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string       dbValue = reader.GetString(0);
                            TreeNodePath newNode = CreateTreeNode(helper, dbValue, dbValue, createDummyNode, false, false);
                            if (isRootFolder)
                            {
                                nodeTag = (string)parent.Tag;
                            }
                            else
                            {
                                nodeTag = string.Format(@"{0}\{1}", parent.Tag, dbValue);
                            }
                            newNode.Tag = nodeTag;
                            parent.Nodes.Add(newNode);
                        }
                    }
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                log.Error("TreeViewBrowser: Error executing sql: {0}", ex.Message);
            }
        }
 protected virtual void AttachSystemImageList(TreeViewFolderBrowserHelper helper)
 {
     if (_checkboxMode != helper.TreeView.CheckboxBehaviorMode)
       {
     // checkboxes recreate the control internal
     if (_systemImageList != null)
     {
       SystemImageListHelper.SetTreeViewImageList(helper.TreeView, _systemImageList, false);
     }
       }
       _checkboxMode = helper.TreeView.CheckboxBehaviorMode;
 }
        public virtual void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent,
            TreeViewCancelEventArgs e)
        {
            if (parent.Path == null) return;
              //
              DirectoryInfo directory = new DirectoryInfo(parent.Path);
              // check persmission
              new FileIOPermission(FileIOPermissionAccess.PathDiscovery, directory.FullName).Demand();
              //

              // Sort the Directories, as Samba might return unsorted
              DirectoryInfo[] dirInfo = directory.GetDirectories();
              Array.Sort(dirInfo,
                 new Comparison<DirectoryInfo>(
                   delegate(DirectoryInfo d1, DirectoryInfo d2) { return string.Compare(d1.Name, d2.Name); }));

              foreach (DirectoryInfo dir in dirInfo)
              {
            if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
            {
              continue;
            }
            TreeNodePath newNode = CreateTreeNode(helper, dir.Name, dir.FullName, false,
                                              ((helper.TreeView.CheckboxBehaviorMode != CheckboxBehaviorMode.None) &&
                                               (parent.Checked)), false);
            parent.Nodes.Add(newNode);
            //
            try
            {
              if (dir.GetDirectories().GetLength(0) > 0)
              {
            newNode.AddDummyNode();
              }
            }
            catch {}
              }
        }
Ejemplo n.º 28
0
 public TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
 {
     return(helper.TreeView.Nodes);
 }
 public TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
 {
     return helper.TreeView.Nodes;
 }
 public virtual void RequestRoot(TreeViewFolderBrowserHelper helper)
 {
     AttachSystemImageList(helper);
       //
       bool populateDrives = true;
       //
       TreeNodeCollection rootNodeCollection;
       TreeNodeCollection driveRootNodeCollection;
       // setup up root node collection
       switch (helper.TreeView.RootFolder)
       {
     case Environment.SpecialFolder.Desktop:
       // create root node <Desktop>
       TreeNodePath desktopNode = CreateTreeNode(helper, Environment.SpecialFolder.Desktop.ToString(), string.Empty,
                                             false, false, true);
       helper.TreeView.Nodes.Add(desktopNode);
       rootNodeCollection = helper.TreeView.Nodes[0].Nodes;
       // create child node <Personal>
       string personalDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
       rootNodeCollection.Add(CreateTreeNode(helper, Path.GetFileName(personalDirectory), personalDirectory, true,
                                         false, false));
       // create child node <MyComuter>
       TreeNodePath myComputerNode = CreateTreeNode(helper, Environment.SpecialFolder.MyComputer.ToString(),
                                                string.Empty, false, false, true);
       rootNodeCollection.Add(myComputerNode);
       driveRootNodeCollection = myComputerNode.Nodes;
       break;
     case Environment.SpecialFolder.MyComputer:
       rootNodeCollection = helper.TreeView.Nodes;
       driveRootNodeCollection = rootNodeCollection;
       break;
     default:
       rootNodeCollection = helper.TreeView.Nodes;
       driveRootNodeCollection = rootNodeCollection;
       // create root node with specified SpecialFolder
       rootNodeCollection.Add(CreateTreeNode(helper,
                                         Path.GetFileName(Environment.GetFolderPath(helper.TreeView.RootFolder)),
                                         Environment.GetFolderPath(helper.TreeView.RootFolder), true, false,
                                         false));
       populateDrives = false;
       break;
       }
       if (populateDrives)
       {
     // populate local machine drives
     foreach (Logicaldisk logicalDisk in Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView)))
     {
       try
       {
     string name = string.Empty;
     string path = logicalDisk.Name + "\\";
     name = logicalDisk.Description;
     //
     name += (name != string.Empty) ? " (" + path + ")" : path;
     // add node to root collection
     driveRootNodeCollection.Add(CreateTreeNode(helper, name, path, true, false, false));
       }
       catch (Exception doh)
       {
     throw doh;
       }
     }
       }
 }
        public void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent, TreeViewCancelEventArgs e)
        {
            if (parent.Path == null)
              {
            return;
              }

              if (parent.Path == "")
              {
            rootFolder = RootFolder.None;
              }

              string sql = string.Empty;
              bool createDummyNode = true;
              string nodeTag;

              // We have a Special folder, when we are at the root level
              if (parent.IsSpecialFolder)
              {
            rootFolder = RootFolder.None;
              }

              if (rootFolder == RootFolder.None)
              {
            switch ((string)parent.Tag)
            {
              case "artist":
            rootFolder = RootFolder.Artist;
            sql = SQL_STMT_ARTIST;
            break;

              case "albumartist":
            rootFolder = RootFolder.AlbumArtist;
            sql = SQL_STMT_ALBUMARTIST;
            break;

              case "album":
            rootFolder = RootFolder.Album;
            sql = SQL_STMT_ALBUM;
            createDummyNode = false;
            break;

              case "genre":
            rootFolder = RootFolder.Genre;
            sql = SQL_STMT_GENRE;
            break;
            }
              }
              else if (rootFolder == RootFolder.Artist)
              {
            sql = string.Format(SQL_STMT_ARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
            isRootFolder = false;
            createDummyNode = false;
              }
              else if (rootFolder == RootFolder.AlbumArtist)
              {
            sql = string.Format(SQL_STMT_ALBUMARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
            isRootFolder = false;
            createDummyNode = false;
              }
              else if (rootFolder == RootFolder.Genre)
              {
            isRootFolder = false;
            string[] searchString = (parent.Tag as string).Split('\\');
            if (searchString.GetLength(0) == 2)
            {
              sql = string.Format(SQL_STMT_GENREARTISTSEARCH, Util.RemoveInvalidChars(parent.Path));
              createDummyNode = true;
            }
            else
            {
              sql = string.Format(SQL_STMT_GENREARTISTALBUMSEARCH, Util.RemoveInvalidChars(searchString[1]),
                              Util.RemoveInvalidChars(parent.Path));
              createDummyNode = false;
            }
              }

              string connection = string.Format(@"Data Source={0}", Options.MainSettings.MediaPortalDatabase);
              try
              {
            SQLiteConnection conn = new SQLiteConnection(connection);
            conn.Open();
            using (SQLiteCommand cmd = new SQLiteCommand())
            {
              cmd.Connection = conn;
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = sql;
              log.Debug("TreeViewBrowser: Executing sql: {0}", sql);
              using (SQLiteDataReader reader = cmd.ExecuteReader())
              {
            while (reader.Read())
            {
              string dbValue = reader.GetString(0);
              TreeNodePath newNode = CreateTreeNode(helper, dbValue, dbValue, createDummyNode, false, false);
              if (isRootFolder)
              {
                nodeTag = (string)parent.Tag;
              }
              else
              {
                nodeTag = string.Format(@"{0}\{1}", parent.Tag, dbValue);
              }
              newNode.Tag = nodeTag;
              parent.Nodes.Add(newNode);
            }
              }
            }
            conn.Close();
              }
              catch (Exception ex)
              {
            log.Error("TreeViewBrowser: Error executing sql: {0}", ex.Message);
              }
        }
Ejemplo n.º 32
0
        public virtual void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            AttachSystemImageList(helper);
            //
            bool populateDrives = true;
            //
            TreeNodeCollection rootNodeCollection;
            TreeNodeCollection driveRootNodeCollection;

            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                // create root node <Desktop>
                TreeNodePath desktopNode = CreateTreeNode(helper, Environment.SpecialFolder.Desktop.ToString(), string.Empty,
                                                          false, false, true);
                helper.TreeView.Nodes.Add(desktopNode);
                rootNodeCollection = helper.TreeView.Nodes[0].Nodes;
                // create child node <Personal>
                string personalDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                rootNodeCollection.Add(CreateTreeNode(helper, Path.GetFileName(personalDirectory), personalDirectory, true,
                                                      false, false));
                // create child node <MyComuter>
                TreeNodePath myComputerNode = CreateTreeNode(helper, Environment.SpecialFolder.MyComputer.ToString(),
                                                             string.Empty, false, false, true);
                rootNodeCollection.Add(myComputerNode);
                driveRootNodeCollection = myComputerNode.Nodes;
                break;

            case Environment.SpecialFolder.MyComputer:
                rootNodeCollection      = helper.TreeView.Nodes;
                driveRootNodeCollection = rootNodeCollection;
                break;

            default:
                rootNodeCollection      = helper.TreeView.Nodes;
                driveRootNodeCollection = rootNodeCollection;
                // create root node with specified SpecialFolder
                rootNodeCollection.Add(CreateTreeNode(helper,
                                                      Path.GetFileName(Environment.GetFolderPath(helper.TreeView.RootFolder)),
                                                      Environment.GetFolderPath(helper.TreeView.RootFolder), true, false,
                                                      false));
                populateDrives = false;
                break;
            }
            if (populateDrives)
            {
                // populate local machine drives
                foreach (Logicaldisk logicalDisk in Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView)))
                {
                    try
                    {
                        string name = string.Empty;
                        string path = logicalDisk.Name + "\\";
                        name = logicalDisk.Description;
                        //
                        name += (name != string.Empty) ? " (" + path + ")" : path;
                        // add node to root collection
                        driveRootNodeCollection.Add(CreateTreeNode(helper, name, path, true, false, false));
                    }
                    catch (Exception doh)
                    {
                        throw doh;
                    }
                }
            }
        }
 /// <summary>
 ///   Creates a new node and assigns a icon
 /// </summary>
 /// <param name = "helper"></param>
 /// <param name = "text"></param>
 /// <param name = "path"></param>
 /// <param name = "addDummyNode"></param>
 /// <param name = "forceChecked"></param>
 /// <returns></returns>
 protected virtual TreeNodePath CreateTreeNode(TreeViewFolderBrowserHelper helper, string text, string path,
     bool addDummyNode, bool forceChecked, bool isSpecialFolder)
 {
     TreeNodePath node = helper.CreateTreeNode(text, path, addDummyNode, forceChecked, isSpecialFolder);
       try
       {
     SetIcon(helper.TreeView, node);
       }
       catch
       {
     node.ImageIndex = -1;
     node.SelectedImageIndex = -1;
       }
       return node;
 }
 public override TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper, bool isNetwork)
 {
     if (isNetwork)
       {
     return _rootCollectionNetwork;
       }
       return _rootCollection;
 }