Пример #1
0
 private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Node is FileExplorerItem)
     {
         FileExplorerItem item = e.Node as FileExplorerItem;
         if (File.Exists(item.FileInfo.FullName))
         {
             if (item.FileInfo.Extension.Equals(".lua") || item.FileInfo.Extension.Equals(".txt"))
             {
                 this.mainForm.cgEeditor1.OpenFileInEditor(item.FileInfo.FullName);
             }
             else
             {
                 try
                 {
                     System.Diagnostics.Process.Start(item.FileInfo.FullName);
                 }
                 catch (Exception ex)
                 {
                     this.mainForm.cgEeditor1.OpenFileInEditor(item.FileInfo.FullName);
                 }
             }
         }
         else
         {
             e.Node.Remove();
         }
     }
 }
Пример #2
0
        private FileExplorerItem createFileNode(FileInfo info)
        {
            FileExplorerItem itemExisting = getFileNode(info.FullName);

            if (itemExisting != null)
            {
                itemExisting.FileInfo = info;
                itemExisting.Text     = info.Name;
                this.treeView1.Sort();

                return(itemExisting);
            }
            else
            {
                FolderExplorerItem folderParent = this.getFolderNode(this.rootNode, info.DirectoryName);
                if (folderParent != null)
                {
                    FileExplorerItem item = new FileExplorerItem(info);
                    folderParent.Nodes.Add(item);
                    this.treeView1.Sort();
                    return(item);
                }

                return(null);
            }
        }
Пример #3
0
        private FileExplorerItem directoryHasNode(FolderExplorerItem dir, string path)
        {
            if (dir != null)
            {
                for (int i = 0; i < dir.Nodes.Count; i++)
                {
                    if (dir.Nodes[i] is FileExplorerItem)
                    {
                        FileExplorerItem item = dir.Nodes[i] as FileExplorerItem;
                        if (item.FileInfo.FullName.Equals(path))
                        {
                            return(item);
                        }
                    }
                    else if (dir.Nodes[i] is FolderExplorerItem)
                    {
                        FolderExplorerItem item      = dir.Nodes[i] as FolderExplorerItem;
                        FileExplorerItem   itemFound = directoryHasNode(item, path);
                        if (itemFound != null)
                        {
                            return(itemFound);
                        }
                    }
                }
            }


            return(null);
        }
        async private void FileExplorerItemSelect(object sender, System.Windows.Input.GestureEventArgs e)
        {
            FileExplorerItem item = ((FrameworkElement)sender).Tag as FileExplorerItem;

            if (item.IsFolder)
            {
                if (StorageTarget == Interop.StorageTarget.ExternalStorage)
                {
                    GetTreeForExternalFolder(await _externalFolderTree.First().GetFolderAsync(item.Name));
                }
                else
                {
                    GetTreeForInternalFolder(await _internalFolderTree.First().GetFolderAsync(item.Name));
                }
            }
            else
            {
                if (SelectionMode == Interop.SelectionMode.File)
                {
                    if (StorageTarget == Interop.StorageTarget.ExternalStorage)
                    {
                        ExternalStorageFile file = await _currentStorageDevice.GetFileAsync(item.Path);

                        Dismiss(file);
                    }
                    else
                    {
                        StorageFolder folder = _internalFolderTree.Pop();
                        StorageFile   file   = await folder.GetFileAsync(item.Name);

                        Dismiss(file);
                    }
                }
            }
        }
Пример #5
0
        private async Task SelectedSingleItem(FileExplorerItem selectedItem)
        {
            foreach (FileExplorerItem item in CurrentItems)
            {
                if (item != selectedItem)
                {
                    item.Selected = false;
                }
                else
                {
                    item.Selected = true;

                    if (SelectionMode == SelectionMode.FileWithOpen)
                    {
                        try
                        {
                            IStorageFolderEx folder = FolderTree.First();
                            IStorageFileEx   file   = await folder.GetFileAsync(item.Name);

                            if (_player != null)
                            {
                                _player.Dispose();
                            }

                            if (file != null)
                            {
                                _player = new SamplePlayer();

                                _player.WithVoicePool(AudioDefines.VoicePool)
                                .WithXAudio(AudioDefines.XAudio)
                                .WithWaveFormat(AudioDefines.WaveFormat)
                                .WithChannelVolume(0.8)
                                .WithInput(file)
                                .BuildAsync().ContinueWith(task => task.Result.Play(), TaskScheduler.Default);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }

                FileExplorerItem targetItem = GetItemFromPath(item.Path);
                if (item.Selected && targetItem == null)
                {
                    SelectedItems.Add(item);
                }
                else if (!item.Selected && targetItem != null)
                {
                    SelectedItems.Remove(GetItemFromPath(item.Path));
                }
            }
        }
Пример #6
0
 public DirectoryEntry(FileExplorerItem item)
 {
     CanCopyMove  = item.CanCopyMove;
     DateCreated  = item.DateCreated ?? DateTimeOffset.UtcNow;
     DateModified = item.DateModified ?? DateTimeOffset.UtcNow;
     IsHidden     = item.IsHidden;
     IsReadOnly   = item.IsReadOnly;
     IsSystem     = item.IsSystem;
     Name         = item.Name;
     Size         = item.FileSize;
     Type         = item.EntryType;
 }
Пример #7
0
        private bool removeFileNode(string path)
        {
            FileExplorerItem itemExisting = getFileNode(path);

            if (itemExisting != null)
            {
                itemExisting.Remove();
                return(true);
            }

            return(false);
        }
        private string GetNodeIconCssClass(FileExplorerItem _, int level)
        {
            var levelText = (level) switch
            {
                1 => "one",
                2 => "two",
                3 => "three",
                4 => "four",
                5 => "five",
                _ => "six",
            };

            return($"fas fw fa-dice-{levelText}");
        }
Пример #9
0
        private bool renameFileNode(string oldfullName, FileInfo info)
        {
            FileExplorerItem itemExisting = getFileNode(oldfullName);

            if (itemExisting != null)
            {
                itemExisting.FileInfo = info;
                itemExisting.Text     = info.Name;
                this.treeView1.Sort();
                return(true);
            }

            return(false);
        }
Пример #10
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter.ToString() == "selector")
            {
                FileExplorerItem item = (FileExplorerItem)value;

                if (ParentSelectionMode == SelectionMode.MultipleFiles)
                {
                    if (item.IsFolder)
                    {
                        return(Visibility.Collapsed);
                    }
                    else
                    {
                        return(Visibility.Visible);
                    }
                }
                else if (ParentSelectionMode == SelectionMode.MultipleFolders)
                {
                    if (item.IsFolder)
                    {
                        return(Visibility.Visible);
                    }
                    else
                    {
                        return(Visibility.Collapsed);
                    }
                }
                else
                {
                    return(Visibility.Collapsed);
                }
            }
            else if (parameter.ToString() == "opener")
            {
                if (ParentSelectionMode != SelectionMode.File)
                {
                    return(Visibility.Visible);
                }
                else
                {
                    return(Visibility.Collapsed);
                }
            }
            else
            {
                return(Visibility.Collapsed);
            }
        }
Пример #11
0
 private void ProcessSelectedItems()
 {
     foreach (FileExplorerItem item in CurrentItems)
     {
         FileExplorerItem targetItem = GetItemFromPath(item.Path);
         if (item.Selected && targetItem == null)
         {
             SelectedItems.Add(item);
         }
         else if (!item.Selected && targetItem != null)
         {
             SelectedItems.Remove(GetItemFromPath(item.Path));
         }
     }
 }
Пример #12
0
 private string GetIconCssClass(FileExplorerItem item)
 {
     if (item.EntryType == FileExplorerItemType.Directory)
     {
         if (item.Path == "/")
         {
             return("fas fa-server");
         }
         if (item.ParentPath == "/")
         {
             return("fas fa-hdd");
         }
     }
     return(TestFileSystemDataProvider.GetIconClass(item));
 }
Пример #13
0
        private void addFilesBt_Click_1(object sender, EventArgs e)
        {
            if (this.mainForm.CurrentProject != null && this.treeView1.SelectedNode != null && this.treeView1.SelectedNode is FolderExplorerItem)
            {
                try
                {
                    FolderExplorerItem currentFolder = this.treeView1.SelectedNode as FolderExplorerItem;
                    OpenFileDialog     openF         = new OpenFileDialog();
                    openF.Multiselect = true;
                    openF.Filter      = "All files type (*.*)|*.*";
                    if (openF.ShowDialog() == DialogResult.OK)
                    {
                        int count = 0;
                        for (int i = 0; i < openF.FileNames.Length; i++)
                        {
                            string filename = openF.FileNames[i];
                            if (File.Exists(filename))
                            {
                                File.Copy(filename, currentFolder.FolderInfo.FullName + "\\" + openF.SafeFileNames[i], true);

                                FileExplorerItem newItem = new FileExplorerItem(new FileInfo(currentFolder.FolderInfo.FullName + "\\" + openF.SafeFileNames[i]));
                                currentFolder.Nodes.Add(newItem);

                                count++;
                            }
                            else
                            {
                                MessageBox.Show("The file " + filename + " does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        this.treeView1.Sort();
                        if (count > 1)
                        {
                            MessageBox.Show(count + " files have been successfully imported!", "Importation succeed!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show(count + " file has been successfully imported!", "Importation succeed!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during file importation!\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #14
0
        private void getFiles(DirectoryInfo parentDir, FolderExplorerItem nodeToAddTo)
        {
            FileExplorerItem aNode;

            FileInfo[] files = parentDir.GetFiles();


            foreach (FileInfo file in files)
            {
                aNode = this.getFileNode(file.FullName);
                if (aNode == null)
                {
                    aNode = new FileExplorerItem(file);
                    nodeToAddTo.Nodes.Add(aNode);
                }
            }
        }
Пример #15
0
        private void removeFileBt_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.SelectedNodes.Count; i++)
            {
                if (this.SelectedNodes[i] is FileExplorerItem)
                {
                    try
                    {
                        FileExplorerItem item = this.SelectedNodes[i] as FileExplorerItem;
                        if (File.Exists(item.FileInfo.FullName))
                        {
                            File.Delete(item.FileInfo.FullName);
                        }

                        item.Remove();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        async void GetTreeForExternalFolder(ExternalStorageFolder folder)
        {
            if (!_externalFolderTree.Contains(folder))
            {
                _externalFolderTree.Push(folder);
            }

            ProcessSelectedItems();

            CurrentItems.Clear();

            var folderList = await folder.GetFoldersAsync();

            foreach (ExternalStorageFolder _folder in folderList)
            {
                FileExplorerItem item = (from c in _selectedItems where c.Path == _folder.Path select c).FirstOrDefault();

                FileExplorerItem _addItem = new FileExplorerItem()
                {
                    IsFolder = true,
                    Name     = _folder.Name,
                    Path     = _folder.Path,
                    Selected = item != null ? true : false
                };

                CurrentItems.Add(_addItem);
            }

            var fileList = await folder.GetFilesAsync();

            if (fileList != null)
            {
                foreach (ExternalStorageFile _file in fileList)
                {
                    FileExplorerItem item = GetItemFromPath(_file.Path);

                    if (((ExtensionRestrictions & (Interop.ExtensionRestrictions.Custom | Interop.ExtensionRestrictions.InheritManifest)) != 0) && (Extensions.Count != 0))
                    {
                        string extension = Path.GetExtension(_file.Name);
                        if (Extensions.FindIndex(x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)) != -1)
                        {
                            CurrentItems.Add(new FileExplorerItem()
                            {
                                IsFolder = false,
                                Name     = _file.Name,
                                Path     = _file.Path,
                                Selected = item != null ? true : false
                            });
                        }
                    }
                    else
                    {
                        CurrentItems.Add(new FileExplorerItem()
                        {
                            IsFolder = false,
                            Name     = _file.Name,
                            Path     = _file.Path,
                            Selected = item != null ? true : false
                        });
                    }
                }
            }

            CurrentPath = _externalFolderTree.First().Path;
        }
Пример #17
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // e.Node is the current node exposed by the base TreeView control

            bool bControl = (ModifierKeys == Keys.Control);
            bool bShift   = (ModifierKeys == Keys.Shift);

            removePaintFromNodes();

            if (e.Node is FileExplorerItem)
            {
                FileExplorerItem elem            = e.Node as FileExplorerItem;
                bool             isFirstFileItem = true;
                for (int i = 0; i < this.SelectedNodes.Count; i++)
                {
                    if (this.SelectedNodes[i] is FileExplorerItem)
                    {
                    }
                    else
                    {
                        isFirstFileItem = false;
                        break;
                    }
                }

                if (isFirstFileItem == true)
                {
                    if (bControl)
                    {
                        if (!this.SelectedNodes.Contains(e.Node)) // new node ?
                        {
                            this.SelectedNodes.Add(e.Node);
                        }
                    }
                    else
                    {
                        if (bShift)
                        {
                            Queue myQueue = new Queue();

                            TreeNode uppernode  = m_firstNode;
                            TreeNode bottomnode = e.Node;

                            // case 1 : begin and end nodes are parent
                            bool bParent = isParent(m_firstNode, e.Node);
                            if (!bParent)
                            {
                                bParent = isParent(bottomnode, uppernode);
                                if (bParent) // swap nodes
                                {
                                    TreeNode t = uppernode;
                                    uppernode  = bottomnode;
                                    bottomnode = t;
                                }
                            }
                            if (bParent)
                            {
                                TreeNode n = bottomnode;
                                while (n != uppernode.Parent)
                                {
                                    if (!this.SelectedNodes.Contains(n)) // new node ?
                                    {
                                        myQueue.Enqueue(n);
                                    }

                                    n = n.Parent;
                                }
                            }
                            // case 2 : nor the begin nor the
                            // end node are descendant one another
                            else
                            {
                                // are they siblings ?

                                if ((uppernode.Parent == null && bottomnode.Parent == null) ||
                                    (uppernode.Parent != null &&
                                     uppernode.Parent.Nodes.Contains(bottomnode)))
                                {
                                    int nIndexUpper  = uppernode.Index;
                                    int nIndexBottom = bottomnode.Index;
                                    if (nIndexBottom < nIndexUpper) // reversed?
                                    {
                                        TreeNode t = uppernode;
                                        uppernode    = bottomnode;
                                        bottomnode   = t;
                                        nIndexUpper  = uppernode.Index;
                                        nIndexBottom = bottomnode.Index;
                                    }

                                    TreeNode n = uppernode;
                                    while (nIndexUpper <= nIndexBottom)
                                    {
                                        if (!this.SelectedNodes.Contains(n)) // new node ?
                                        {
                                            myQueue.Enqueue(n);
                                        }

                                        n = n.NextNode;

                                        nIndexUpper++;
                                    } // end while
                                }
                                else
                                {
                                    if (!this.SelectedNodes.Contains(uppernode))
                                    {
                                        myQueue.Enqueue(uppernode);
                                    }
                                    if (!this.SelectedNodes.Contains(bottomnode))
                                    {
                                        myQueue.Enqueue(bottomnode);
                                    }
                                }
                            }

                            foreach (object objQueue in myQueue)
                            {
                                TreeNode node = objQueue as TreeNode;
                                this.SelectedNodes.Add(node);
                            }



                            // let us chain several SHIFTs if we like it
                            m_firstNode = e.Node;
                        } // end if m_bShift
                        else
                        {
                            // in the case of a simple click, just add this item
                            if (this.SelectedNodes != null && this.SelectedNodes.Count > 0)
                            {
                                removePaintFromNodes();
                                this.SelectedNodes.Clear();
                            }
                            this.SelectedNodes.Add(e.Node);
                        }
                    }
                }
                else
                {
                    this.SelectedNodes.Clear();
                    this.SelectedNodes.Add(e.Node);
                }
            }
            else
            {
                this.SelectedNodes.Clear();
                this.SelectedNodes.Add(e.Node);
            }



            paintSelectedNodes();
        }
 private int ReverseSort(FileExplorerItem a, FileExplorerItem b)
 {
     return(a.Path.CompareTo(b.Path) * -1);
 }
Пример #19
0
        /// <summary>
        ///     Will retrieve the full folder and file tree for a folder from the internal storage.
        /// </summary>
        /// <param name="folder">The instance of the folder for which the tree will be retrieved.</param>
        private async void GetTreeForFolder(IStorageFolderEx folder)
        {
            if (!FolderTree.Contains(folder))
            {
                FolderTree.Push(folder);
            }

            ProcessSelectedItems();

            CurrentItems.Clear();

            IEnumerable <IStorageFolderEx> folderList = await folder.GetFoldersAsync();

            foreach (IStorageFolderEx _folder in folderList)
            {
                FileExplorerItem item =
                    (from c in SelectedItems where c.Path == _folder.Path select c).FirstOrDefault();

                var _addItem = new FileExplorerItem
                {
                    IsFolder    = true,
                    Name        = _folder.Name,
                    DisplayName = _folder.DisplayName,
                    Path        = _folder.Path,
                    Selected    = false
                };

                CurrentItems.Add(_addItem);
            }

            IEnumerable <IStorageFileEx> fileList = await folder.GetFilesAsync();

            if (fileList != null)
            {
                foreach (IStorageFileEx _file in fileList)
                {
                    //FileExplorerItem item = GetItemFromPath(_file.Path);

                    if (((ExtensionRestrictions & (ExtensionRestrictions.Custom | ExtensionRestrictions.InheritManifest)) !=
                         0) && (Extensions.Count != 0))
                    {
                        string extension = Path.GetExtension(_file.Name);
                        if (Extensions.FindIndex(x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)) != -1)
                        {
                            CurrentItems.Add(new FileExplorerItem
                            {
                                IsFolder    = false,
                                Name        = _file.Name,
                                DisplayName = _file.Name,
                                Path        = _file.Path,
                                Selected    = false
                            });
                        }
                    }
                    else
                    {
                        CurrentItems.Add(new FileExplorerItem
                        {
                            IsFolder    = false,
                            Name        = _file.Name,
                            Path        = _file.Path,
                            DisplayName = _file.Name,
                            Selected    = false
                        });
                    }
                }
            }

            CurrentPath = FolderTree.First()
                          .Path;
        }