public override void Execute(object parameter)
        {
            if (ItemSelected == null || ItemSelected.FileHandler == null)
            {
                return;
            }

            string path = Path.Combine(ItemSelected.FileHandler.Path, ItemSelected.FileHandler.Name);

            string name = ProjectItemFileSystem.GetValidFolderName(path, _newFolderName);

            ProjectItem newFolder = new ProjectItem()
            {
                DisplayName = name,
                IsFolder    = true,
                Parent      = ItemSelected,
                IsRoot      = false,
                Type        = ItemSelected.Type
            };

            ItemSelected.Items.Add(newFolder);

            SignalManager.Get <RegisterHistoryActionSignal>().Dispatch(new CreateNewElementHistoryAction(newFolder));

            SignalManager.Get <CreateNewElementSignal>().Dispatch(newFolder);

            ProjectItemFileSystem.CreateFileElement(newFolder, path, name);
        }
        public override void Execute(object parameter)
        {
            if (ItemSelected.FileHandler == null)
            {
                return;
            }

            if (ClipboardManager.GetData() is ProjectItem newItem)
            {
                string newItemPath = string.Empty;
                string name        = string.Empty;

                if (ItemSelected.IsFolder)
                {
                    newItemPath = Path.Combine(ItemSelected.FileHandler.Path, ItemSelected.FileHandler.Name);
                }
                else
                {
                    newItemPath = ItemSelected.FileHandler.Path;
                }

                if (newItem.IsFolder)
                {
                    name = ProjectItemFileSystem.GetValidFolderName(newItemPath, newItem.DisplayName);
                }
                else
                {
                    string extension = Util.GetExtensionByType(ItemSelected.Type);

                    name = ProjectItemFileSystem.GetValidFileName(newItemPath, newItem.DisplayName, extension);
                }

                newItem.RenamedFromAction = true;
                newItem.DisplayName       = name;
                newItem.IsLoaded          = true;

                SignalManager.Get <RegisterHistoryActionSignal>().Dispatch(new PasteProjectItemHistoryAction(newItem));

                SignalManager.Get <PasteElementSignal>().Dispatch(ItemSelected, newItem);

                ProjectItemFileSystem.CreateElement(newItem, newItemPath, name);
            }
        }
Example #3
0
        private void EditableTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox tb = sender as TextBox;

            if (tb.DataContext is ProjectItem item)
            {
                if (e.Key == Key.Enter)
                {
                    item.IsInEditMode = false;

                    string name = tb.Text;

                    if (name != item.DisplayName)
                    {
                        // now check if the name is not already taken
                        if (item.IsFolder)
                        {
                            name = ProjectItemFileSystem.GetValidFolderName(item.FileHandler.Path, tb.Text);
                        }
                        else
                        {
                            string extension = Util.GetExtensionByType(item.Type);

                            name = ProjectItemFileSystem.GetValidFileName(item.FileHandler.Path, tb.Text, extension);
                        }

                        tb.Text = name;
                    }
                }

                if (e.Key == Key.Escape)
                {
                    tb.Text = item.OldCaptionValue;

                    item.IsInEditMode = false;
                }
            }
        }
Example #4
0
        public override void Execute(object parameter)
        {
            DragEventArgs dragEvent = parameter as DragEventArgs;

            dragEvent.Handled = true;

            if (dragEvent.Data.GetDataPresent(typeof(ProjectItem)))
            {
                ProjectItem draggingObject = dragEvent.Data.GetData(typeof(ProjectItem)) as ProjectItem;

                TreeViewItem treeViewItem = Util.FindAncestor <TreeViewItem>((DependencyObject)dragEvent.OriginalSource);

                if (treeViewItem == null)
                {
                    return;
                }

                if (!(treeViewItem.Header is ProjectItem dropTarget) || draggingObject == null)
                {
                    return;
                }

                // It is important to deselect the dragged object to select it again when the whole process finishes
                draggingObject.IsSelected = false;

                string name;
                string destinationFolder;

                if (dropTarget.IsFolder)
                {
                    destinationFolder = Path.Combine(dropTarget.FileHandler.Path, dropTarget.FileHandler.Name);
                }
                else
                {
                    destinationFolder = dropTarget.FileHandler.Path;
                }

                if (destinationFolder == draggingObject.FileHandler.Path)
                {
                    return;
                }

                if (draggingObject.IsFolder)
                {
                    name = ProjectItemFileSystem.GetValidFolderName(destinationFolder, draggingObject.DisplayName);
                }
                else
                {
                    string extension = Util.GetExtensionByType(draggingObject.Type);

                    name = ProjectItemFileSystem.GetValidFileName(destinationFolder, draggingObject.DisplayName, extension);
                }

                string oldName = draggingObject.DisplayName;

                draggingObject.RenamedFromAction = true;
                draggingObject.DisplayName       = name;

                SignalManager.Get <RegisterHistoryActionSignal>().Dispatch(
                    new MoveProjectItemHistoryAction(dropTarget, draggingObject, draggingObject.Parent, name, oldName)
                    );

                SignalManager.Get <DropElementSignal>().Dispatch(dropTarget, draggingObject);
                SignalManager.Get <MoveElementSignal>().Dispatch(dropTarget, draggingObject);
            }

            dragEvent.Effects = DragDropEffects.None;
        }