private void CreateFolder(string arg) { bool currentFolder = !string.IsNullOrEmpty(arg); ProjectItem parentFolder = currentFolder ? m_folders.FirstOrDefault() : (ProjectItem)m_listBox.SelectedItem; if (parentFolder == null) { return; } ProjectItem folder = new ProjectItem(); string[] existingNames = parentFolder.Children.Where(c => c.IsFolder).Select(c => c.Name).ToArray(); folder.Name = m_project.GetUniqueName("Folder", parentFolder.Children == null ? new string[0] : existingNames); folder.Children = new List <ProjectItem>(); parentFolder.AddChild(folder); if (currentFolder) { InsertItems(new[] { folder }, true); } Editor.IsBusy = true; m_project.CreateFolder(folder, (error, projectItem) => Editor.IsBusy = false); }
private void InsertOrdered(ProjectItem parent, ProjectItem item) { parent.AddChild(item); m_treeView.RemoveChild(parent, item, parent.Children.Count == 1); VirtualizingTreeViewItem treeViewItem = m_treeView.GetTreeViewItem(item); if (treeViewItem == null) { m_treeView.AddChild(parent, item); } ProjectItem[] orderedChildren = parent.Children.OrderBy(projectItem => projectItem.NameExt).ToArray(); int index = Array.IndexOf(orderedChildren, item); item.SetSiblingIndex(index); if (item.IsFolder) { if (index > 0) { object prevSibling = parent.Children[index - 1]; m_treeView.SetNextSibling(prevSibling, item); } else { if (parent.Children.Count > 1) { object nextSibling = parent.Children[1]; m_treeView.SetPrevSibling(nextSibling, item); } } } }
private void SaveSceneToFolder(PopupWindowArgs args, ProjectItem folder) { if (folder.Children != null && folder.Children.Any(p => p.Name.ToLower() == Input.text.ToLower() && p.IsScene)) { PopupWindow.Show("Scene with same name already exits", "Do you want to override it?", "Yes", yes => { RuntimeUndo.Purge(); ShowProgress = true; m_projectManager.SaveScene(folder.Children.Where(p => p.Name.ToLower() == Input.text.ToLower() && p.IsScene).First(), () => { ShowProgress = false; m_parentPopup.Close(false); }); }, "No", no => Input.ActivateInputField()); args.Cancel = true; } else { ProjectItem newScene = ProjectItem.CreateScene(Input.text); folder.AddChild(newScene); RuntimeUndo.Purge(); ShowProgress = true; m_projectManager.SaveScene(newScene, () => { ShowProgress = false; m_parentPopup.Close(false); }); } }
protected virtual void CreateFolderContextMenuCmd(string arg) { if (m_folders == null) { return; } bool currentFolder = !string.IsNullOrEmpty(arg); ProjectItem parentFolder = currentFolder ? m_folders.FirstOrDefault() : (ProjectItem)m_listBox.SelectedItem; if (parentFolder == null) { return; } ProjectItem folder = new ProjectItem(); string[] existingNames = parentFolder.Children.Where(c => c.IsFolder).Select(c => c.Name).ToArray(); folder.Name = m_project.GetUniqueName(m_localization.GetString("ID_RTEditor_ProjectFolderView_Folder", "Folder"), parentFolder.Children == null ? new string[0] : existingNames); folder.Children = new List <ProjectItem>(); parentFolder.AddChild(folder); if (currentFolder) { InsertItems(new[] { folder }, true); } Editor.IsBusy = true; m_project.CreateFolder(folder, (error, projectItem) => Editor.IsBusy = false); }
private async Task AddExistingFile(ProjectItem parent) { // show dialog to open files var dialog = new OpenFileDialog { Multiselect = true, CheckFileExists = true, CheckPathExists = true }; var result = dialog.ShowDialog() ?? false; if (!result) { return; } // first file added to open ProjectItem firstItem = null; // add all selected files foreach (var fileName in dialog.FileNames) { if (string.IsNullOrWhiteSpace(fileName)) { continue; } // check duplicated name if (TravAllItems(fileName) != null) { MessageBox.Show(Resources.TheSameNameItemExistText, "Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } // create and add new item var newItem = new ProjectItem <FileProjectItemDefinition> { Text = Path.GetFileName(fileName), Tag = fileName }; parent.AddChild(newItem); _projectIsDirty = true; if (firstItem == null) { firstItem = newItem; } } if (firstItem != null) { parent.IsOpen = true; SelectedItem = firstItem; var editor = IoC.Get <ICodeEditor>(); await editor.Load(firstItem.Tag as string); var shell = IoC.Get <IShell>(); shell.OpenDocument(editor); } }
private async Task AddNewFile(ProjectItem parent, string extension) { // show dialog for new name var dialog = IoC.Get <NewItemViewModel>(); var windowManager = IoC.Get <IWindowManager>(); var result = windowManager.ShowDialog(dialog) ?? false; if (!result) { return; } // check duplicated name var newItemName = dialog.Name.Trim(); if (!newItemName.EndsWith(extension, StringComparison.OrdinalIgnoreCase)) { newItemName += extension; } var newItemPath = Path.GetDirectoryName(CurrentProjectInfo.Path) + "\\" + newItemName; if (parent.Children.Any(p => string.Equals(p.Text, newItemName, StringComparison.OrdinalIgnoreCase)) || File.Exists(newItemPath)) { MessageBox.Show(Resources.TheSameNameItemExistText, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // create new file var newFile = File.Create(newItemPath); newFile?.Close(); // create new item var newItem = new ProjectItem <FileProjectItemDefinition> { Text = newItemName, Tag = newItemPath }; parent.AddChild(newItem); _projectIsDirty = true; parent.IsOpen = true; SelectedItem = newItem; // open document var editor = IoC.Get <ICodeEditor>(); await editor.Load(newItemPath); var shell = IoC.Get <IShell>(); shell.OpenDocument(editor); }
private void DuplicateProjectResources() { ProjectItemObjectPair[] selection = GetSelection(true); if (selection.Length == 0) { return; } ShowProgress = true; m_projectManager.SaveObjects(selection.Where(iop => iop.IsResource).ToArray(), () => { m_projectManager.Duplicate(selection.Select(p => p.ProjectItem).ToArray(), duplicatedItems => { ProjectItem parent = null; for (int i = 0; i < selection.Length; ++i) { parent = selection[i].ProjectItem.Parent; if (parent != null) { ProjectItem duplicatedItem = duplicatedItems[i]; if (duplicatedItem.IsFolder) { m_projectTree.AddProjectItem(duplicatedItem, parent); m_projectTree.DropProjectItem(duplicatedItem, parent); } else { parent.AddChild(duplicatedItem); } } } if (parent != null) { m_projectTree.SelectedFolder = parent; } m_projectManager.GetOrCreateObjects(m_projectTree.SelectedFolder, objects => { ShowProgress = false; m_projectResources.SetSelectedItems(objects, duplicatedItems); m_projectResources.SetObjects(objects, false); if (m_projectResources.SelectedItems != null) { RuntimeSelection.objects = m_projectResources.SelectedItems.Where(o => o != null).ToArray(); } }); }); }); }
private void CreateFolder(string arg) { ProjectItem parentFolder = (ProjectItem)m_treeView.SelectedItem; ProjectItem folder = new ProjectItem(); string[] existingNames = parentFolder.Children.Where(c => c.IsFolder).Select(c => c.Name).ToArray(); folder.Name = m_project.GetUniqueName(m_localization.GetString("ID_RTEditor_ProjectTreeView_Folder", "Folder"), parentFolder.Children == null ? new string[0] : existingNames); folder.Children = new List <ProjectItem>(); parentFolder.AddChild(folder); AddItem(parentFolder, folder, existingNames); Editor.IsBusy = true; m_project.CreateFolder(folder, (error, projectItem) => Editor.IsBusy = false); }
private void OnItemDrop(object sender, ItemDropArgs e) { DragDrop.RaiseDrop(e.PointerEventData); ProjectItem parent = (ProjectItem)e.DropTarget; foreach (ProjectItem item in e.DragItems) { if (item.Parent != parent) { m_listBox.RemoveChild(item.Parent, item, item.Parent.Children.Count == 1); parent.AddChild(item); } } }
private void OnItemDrop(object sender, ItemDropArgs e) { Editor.DragDrop.RaiseDrop(e.PointerEventData); if (!(e.DropTarget is AssetItem) && (e.DragItems == null || !e.DragItems.Contains(e.DropTarget))) { ProjectItem parent = (ProjectItem)e.DropTarget; foreach (ProjectItem item in e.DragItems) { if (item.Parent != parent) { m_listBox.RemoveChild(item.Parent, item, item.Parent.Children.Count == 1); parent.AddChild(item); } } } }
public override void Drop(object[] dragObjects, PointerEventData pointerEventData) { base.Drop(dragObjects, pointerEventData); ProjectItem dropTarget = (ProjectItem)m_treeView.DropTarget; if (CanDrop(dropTarget, dragObjects)) { for (int i = 0; i < dragObjects.Length; ++i) { object dragObject = dragObjects[i]; ProjectItem projectItem = dragObject as ProjectItem; dropTarget.AddChild(projectItem); if (!(projectItem is AssetItem)) { m_treeView.ChangeParent(dropTarget, projectItem); } } } m_treeView.ExternalItemDrop(); }