Ejemplo n.º 1
0
        public static void CreateNewElement(StructureItem structureItem, string name, ElementType createElementType)
        {
            string path = String.Empty;

            if (structureItem is FileItem)
            {
                // TODO: Get directory
            }
            else if (structureItem is DirectoryItem)
            {
                path = $"{structureItem.Path}\\{name}";
            }

            if (!String.IsNullOrEmpty(path))
            {
                if (createElementType == ElementType.DIRECTORY)
                {
                    Directory.CreateDirectory(path);
                }
                else if (createElementType == ElementType.FILE)
                {
                    File.Create(path);
                }
            }
        }
        private void MenuDriveSelectorClick(object sender, RoutedEventArgs e)
        {
            if (sender is MenuItem)
            {
                MenuItem clickedMenuItem = sender as MenuItem;

                Structure.Items.Clear();

                if (clickedMenuItem.IsChecked)
                {
                    try
                    {
                        _structureItem = _filesManagement.GetDiskTreeStructure(clickedMenuItem.Header.ToString());
                        Structure.Items.Add(_structureItem);
                        StatusText.Text = "Expand the tree...";
                    }
                    catch (Exception ex)
                    {
                        StatusText.Text = ex.Message;
                    }
                }
                else
                {
                    StatusText.Text = "SELECT DRIVE FIRST";
                }
            }
        }
        private async void StructureTreeExpanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem treeViewItem = (TreeViewItem)e.OriginalSource;

            if (treeViewItem.Header is StructureItem)
            {
                StructureItem currentStructureItem = treeViewItem.Header as StructureItem;

                if (currentStructureItem != null)
                {
                    if (currentStructureItem is DirectoryItem)
                    {
                        await ChangeStatusText("Loading data...");

                        DirectoryItem directoryItem = currentStructureItem as DirectoryItem;

                        directoryItem.IsChanged = true;

                        foreach (StructureItem childStructureItem in directoryItem.Items)
                        {
                            if (childStructureItem is DirectoryItem)
                            {
                                (childStructureItem as DirectoryItem).IsChanged = true;
                            }
                        }

                        await ChangeStatusText("Ready.");
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public static void RemoveElement(StructureItem structureItem)
 {
     if (structureItem is FileItem)
     {
         File.Delete(structureItem.Path);
     }
     else if (structureItem is DirectoryItem)
     {
         Directory.Delete(structureItem.Path);
     }
 }
        private async void StructureSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (e.OriginalSource is TreeView)
            {
                StructureItem si = ((TreeView)e.OriginalSource).SelectedItem as StructureItem;

                if (si != null)
                {
                    await ChangeStatusText(si.Attributes.ToString());
                }
            }
        }
        private void MenuItemCreateNewClick(object sender, RoutedEventArgs e)
        {
            try
            {
                MenuItem clickedMenuItem = sender as MenuItem;

                StructureItem structureItem = clickedMenuItem.DataContext as StructureItem;

                // TODO: Delete mock and add window creator
                FilesManagement.CreateNewElement(structureItem, "TESTOWY", ElementType.DIRECTORY);
                FilesManagement.CreateNewElement(structureItem, "TESTOWY.txt", ElementType.FILE);
                (structureItem as DirectoryItem).IsChanged = true;
            }
            catch (Exception ex)
            {
                StatusText.Text = $"Problem while creating element. {ex.Message}";
            }
        }
        private void MenuItemDeleteClick(object sender, RoutedEventArgs e)
        {
            try
            {
                MenuItem clickedMenuItem = sender as MenuItem;

                StructureItem structureItem   = clickedMenuItem.DataContext as StructureItem;
                DirectoryItem parentDirectory = structureItem.Parent;
                FilesManagement.RemoveElement(structureItem);
                if (parentDirectory != null)
                {
                    parentDirectory.IsChanged = true;
                }
            }
            catch (Exception ex)
            {
                StatusText.Text = $"Problem while deleting. {ex.Message}";
            }
        }
Ejemplo n.º 8
0
 public void AddNewItem(StructureItem item)
 {
     Items.Add(item);
 }