Exemple #1
0
        public static TreeItem AddDirectory(string name, ItemType itemType, int parantId)
        {
            // Find parant
            TreeItem parant = Volume.GetTreeItem(parantId);
            // Create new TreeItem
            var child = new TreeItem(Ids++, itemType, name, parant.Tag + '\\' + name);

            // Create document if it is a file
            if (itemType == ItemType.file)
            {
                var doc = new Document(DocIds++, child);
                child.Document = doc;
                Docs.Add(doc);
            }
            else
            {
                Drive.Write(parant, child, name, true);
            }
            // Add new diractory to the parant
            parant.Childs.Add(child);
            // Return created child
            return(child);
        }
Exemple #2
0
 public MainWindow()
 {
     Drive.Format(256, 4, "Artemiy");
     InitializeComponent();
     DrawGrid();
 }
Exemple #3
0
        private void MenuItem_ClickCreateFile(object sender, RoutedEventArgs e)
        {
            string docName;

            var dialog = new EnterFolderName();

            dialog.Message.Text = "Enter document name";
            if (dialog.ShowDialog() == true)
            {
                docName = dialog.ResponseText;
                var menuItem = sender as MenuItem;

                // Find the parant from OS
                TreeItem parant = FakeOS.Volume.GetTreeItem(menuItem.Tag.ToString());
                string   newTag = parant.Tag + '\\' + dialog.ResponseText;
                if (FakeOS.Volume.GetTreeItem(newTag) != null) // So item with this name already exists in the directory
                {
                    MessageBox.Show(this, $"Item with name {dialog.ResponseText} already exists in the directory.",
                                    "Confirmation", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                // Create our new child and put it among the parants children
                TreeItem child = FakeOS.AddDirectory(docName, ItemType.file, parant.Id);

                // Find parant of item user want to delete in the Tree
                TreeViewItem parantTVI = (TreeViewItem)LogicalTreeHelper.FindLogicalNode(FolderView, "Id" + parant.Id); //FolderView.Items.GetItemAt(0);
                                                                                                                        // Exit if the item contains data
                if (parantTVI.Items.Count == 1 && parantTVI.Items[0] == null)
                {
                    // Remove the dummy child
                    parantTVI.Items.Clear();
                }

                // Create new Tree-ViewItem for our new child
                TreeViewItem childTVI = new TreeViewItem()
                {
                    // Add the title
                    Header = child.Name,
                    // Add the path
                    Tag = child.Tag,
                    // Name for image
                    Name = "Id" + child.Id.ToString()
                };

                ContextMenu contextMenu  = new ContextMenu();
                MenuItem    menuItemOpen = new MenuItem()
                {
                    Header = "Open",
                    Tag    = child.Tag
                };
                MenuItem menuItemRename = new MenuItem()
                {
                    Header = "Rename",
                    Tag    = child.Tag
                };
                menuItemRename.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickRename));
                contextMenu.Items.Add(menuItemRename);
                menuItemOpen.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickOpenFile));
                contextMenu.Items.Add(menuItemOpen);
                MenuItem menuItemDelete = new MenuItem()
                {
                    Header = "Delete",
                    Tag    = child.Tag
                };
                menuItemDelete.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickDelete));
                contextMenu.Items.Add(menuItemDelete);

                childTVI.ContextMenu = contextMenu;

                // Add new child Tree-ViewItem to the parant
                parantTVI.Items.Add(childTVI);
                FolderView.UpdateLayout();

                var notBad = new NotBad();
                notBad.Title += " " + docName;
                if (notBad.ShowDialog() == true)
                {
                    child.Document.Content = notBad.TextContent.Text;
                    Drive.Write(parant, child, child.Document.Content, false);
                    child.Document.LastModification = DateTime.UtcNow;
                }
                else
                {
                    Drive.Write(parant, child, child.Name, false);
                }
                DrawGrid();
            }
        }