Exemple #1
0
        private void MenuItem_ClickOpenFile(object sender, RoutedEventArgs e)
        {
            var      menuItem = sender as MenuItem;
            TreeItem treeItem = FakeOS.Volume.GetTreeItem(menuItem.Tag.ToString());
            var      notBad   = new NotBad();

            notBad.Title           += " " + treeItem.Name;
            notBad.IsNewDoc         = false;
            notBad.TextContent.Text = treeItem.Document.Content;
            notBad.Changes          = false;
            if (notBad.ShowDialog() == true)
            {
                treeItem.Document.Content          = notBad.TextContent.Text;
                treeItem.Document.LastModification = DateTime.UtcNow;
                Drive.EditFile(treeItem, notBad.TextContent.Text);
                DrawGrid();
            }
        }
Exemple #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();
            }
        }