Пример #1
0
        private void MenuItem_ClickCreateFolder(object sender, RoutedEventArgs e)
        {
            var dialog = new EnterFolderName();

            if (dialog.ShowDialog() == true)
            {
                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(dialog.ResponseText, ItemType.folder, 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);

                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()
                };

                // Add a dummy child to the root Tree-View Item for ability to expand our new folder
                childTVI.Items.Add(null);

                ContextMenu contextMenu    = new ContextMenu();
                MenuItem    menuItemCreate = new MenuItem()
                {
                    Header = "Create new folder",
                    Tag    = child.Tag
                };
                menuItemCreate.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickCreateFolder));
                contextMenu.Items.Add(menuItemCreate);
                MenuItem menuItemRename = new MenuItem()
                {
                    Header = "Rename",
                    Tag    = child.Tag
                };
                menuItemRename.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickRename));
                contextMenu.Items.Add(menuItemRename);
                MenuItem menuItemDelete = new MenuItem()
                {
                    Header = "Delete",
                    Tag    = child.Tag
                };
                menuItemDelete.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickDelete));
                contextMenu.Items.Add(menuItemDelete);
                MenuItem menuItemCreateFile = new MenuItem()
                {
                    Header = "Create file",
                    Tag    = child.Tag
                };
                menuItemCreateFile.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_ClickCreateFile));
                contextMenu.Items.Add(menuItemCreateFile);

                childTVI.ContextMenu = contextMenu;
                // Listen out for item being expended
                childTVI.Expanded += TreeItem_Expanded;

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

                FolderView.UpdateLayout();
                DrawGrid();
            }
        }
Пример #2
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();
            }
        }