Esempio n. 1
0
        private void HandleDroppedElementOnFolder(ElementSave draggedAsElementSave, TreeNode treeNodeDroppedOn, out bool handled)
        {
            if (draggedAsElementSave is StandardElementSave)
            {
                MessageBox.Show("Cannot move standard elements to different folders");
                handled = true;
            }
            else
            {
                var fullFolderPath = treeNodeDroppedOn.GetFullFilePath();

                var fullElementFilePath = FileManager.GetDirectory(draggedAsElementSave.GetFullPathXmlFile());

                handled = false;

                if (FileManager.Standardize(fullFolderPath) != FileManager.Standardize(fullElementFilePath))
                {
                    var projectFolder = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName);

                    string nodeRelativeToProject = FileManager.MakeRelative(fullFolderPath, projectFolder + draggedAsElementSave.Subfolder + "\\", preserveCase: true);

                    string oldName = draggedAsElementSave.Name;
                    draggedAsElementSave.Name = nodeRelativeToProject + FileManager.RemovePath(draggedAsElementSave.Name);
                    RenameLogic.HandleRename(draggedAsElementSave, (InstanceSave)null, oldName, NameChangeAction.Move);

                    handled = true;
                }
            }
        }
Esempio n. 2
0
 private static void ReactIfChangedMemberIsName(ElementSave container, InstanceSave instance, string changedMember, object oldValue)
 {
     if (changedMember == "Name")
     {
         RenameLogic.HandleRename(container, instance, (string)oldValue, NameChangeAction.Rename);
     }
 }
Esempio n. 3
0
        private void HandleDroppedElementOnTopComponentTreeNode(ElementSave draggedAsElementSave, out bool handled)
        {
            handled = false;
            string name = draggedAsElementSave.Name;

            string currentDirectory = FileManager.GetDirectory(draggedAsElementSave.Name);

            if (!string.IsNullOrEmpty(currentDirectory))
            {
                // It's in a directory, we're going to move it out
                draggedAsElementSave.Name = FileManager.RemovePath(name);
                RenameLogic.HandleRename(draggedAsElementSave, (InstanceSave)null, name, NameChangeAction.Move);

                handled = true;
            }
        }
Esempio n. 4
0
        public void PerformUndo()
        {
            Stack <UndoSnapshot> stack = null;

            if (SelectedState.Self.SelectedElement != null && mUndos.ContainsKey(SelectedState.Self.SelectedElement))
            {
                stack = mUndos[SelectedState.Self.SelectedElement];
            }

            if (stack != null && stack.Count != 0)
            {
                ElementSave lastSelectedElementSave = SelectedState.Self.SelectedElement;

                var undoSnapshot  = stack.Pop();
                var elementToUndo = undoSnapshot.Element;

                ElementSave toApplyTo = SelectedState.Self.SelectedElement;

                bool shouldRefreshWireframe = false;

                if (elementToUndo.States != null)
                {
                    foreach (var state in elementToUndo.States)
                    {
                        var matchingState = toApplyTo.States.Find(item => item.Name == state.Name);
                        if (matchingState != null)
                        {
                            Apply(state, matchingState, toApplyTo);
                        }
                    }
                }

                if (elementToUndo.Categories != null)
                {
                    foreach (var category in elementToUndo.Categories)
                    {
                        foreach (var state in category.States)
                        {
                            var matchingCategory = toApplyTo.Categories.Find(item => item.Name == category.Name);
                            var matchingState    = matchingCategory?.States.Find(item => item.Name == state.Name);
                            if (matchingState != null)
                            {
                                Apply(state, matchingState, toApplyTo);
                            }
                        }
                    }
                }
                if (elementToUndo.Instances != null)
                {
                    Apply(elementToUndo.Instances, toApplyTo.Instances, toApplyTo);
                    shouldRefreshWireframe = true;
                }
                if (elementToUndo.Name != null)
                {
                    string oldName = toApplyTo.Name;
                    toApplyTo.Name = elementToUndo.Name;
                    RenameLogic.HandleRename(toApplyTo, (InstanceSave)null, oldName, NameChangeAction.Rename, askAboutRename: false);
                }

                if (undoSnapshot.CategoryName != SelectedState.Self.SelectedStateCategorySave?.Name ||
                    undoSnapshot.StateName != SelectedState.Self.SelectedStateSave?.Name)
                {
                    var listOfStates = lastSelectedElementSave.States;
                    if (!string.IsNullOrEmpty(undoSnapshot.CategoryName))
                    {
                        listOfStates = lastSelectedElementSave.Categories
                                       .FirstOrDefault(item => item.Name == undoSnapshot.CategoryName)?.States;
                    }

                    var state = listOfStates?.FirstOrDefault(item => item.Name == undoSnapshot.StateName);

                    isRecordingUndos = false;
                    SelectedState.Self.SelectedStateSave = state;

                    isRecordingUndos = true;
                }

                //if (undoObject.BaseType != null)
                //{
                //    string oldBaseType = toApplyTo.BaseType;
                //    toApplyTo.BaseType = undoObject.BaseType;

                //    toApplyTo.ReactToChangedBaseType(null, oldBaseType);
                //}

                RecordState();


                UndosChanged?.Invoke(this, null);

                GumCommands.Self.GuiCommands.RefreshElementTreeView();
                SelectedState.Self.UpdateToSelectedStateSave();

                // The instances may have changed.  We will want
                // to refresh the wireframe since the IPSOs in the
                // wireframe have tags.
                if (shouldRefreshWireframe)
                {
                    WireframeObjectManager.Self.RefreshAll(true);
                }

                //PrintStatus("PerformUndo");

                // If an instance is removed
                // through an undo and if that
                // instance is the selected instance
                // then we want to refresh that.
                if (lastSelectedElementSave != null && SelectedState.Self.SelectedElement == null)
                {
                    SelectedState.Self.SelectedElement = lastSelectedElementSave;
                }

                GumCommands.Self.FileCommands.TryAutoSaveProject();
                GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();

                ElementTreeViewManager.Self.VerifyComponentsAreInTreeView(ProjectManager.Self.GumProjectSave);
            }
        }
        private void HandleRenameFolder(object sender, EventArgs e)
        {
            var tiw = new TextInputWindow();

            tiw.Message = "Enter new folder name";
            tiw.Result  = SelectedNode.Text;
            var dialogResult = tiw.ShowDialog();

            if (dialogResult == DialogResult.OK && tiw.Result != SelectedNode.Text)
            {
                bool   isValid = true;
                string whyNotValid;
                if (!NameVerifier.Self.IsFolderNameValid(tiw.Result, out whyNotValid))
                {
                    isValid = false;
                }


                // see if it already exists:
                string fullFilePath = FileManager.GetDirectory(SelectedNode.GetFullFilePath().FullPath) + tiw.Result + "\\";

                if (System.IO.Directory.Exists(fullFilePath))
                {
                    whyNotValid = $"Folder {tiw.Result} already exists.";
                    isValid     = false;
                }

                if (!isValid)
                {
                    MessageBox.Show(whyNotValid);
                }
                else
                {
                    string rootForElement;
                    if (SelectedNode.IsScreensFolderTreeNode())
                    {
                        rootForElement = FileLocations.Self.ScreensFolder;
                    }
                    else if (SelectedNode.IsComponentsFolderTreeNode())
                    {
                        rootForElement = FileLocations.Self.ComponentsFolder;
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }

                    var oldFullPath = SelectedNode.GetFullFilePath();

                    string oldPathRelativeToElementsRoot = FileManager.MakeRelative(SelectedNode.GetFullFilePath().FullPath, rootForElement, preserveCase: true);
                    SelectedNode.Text = tiw.Result;
                    string newPathRelativeToElementsRoot = FileManager.MakeRelative(SelectedNode.GetFullFilePath().FullPath, rootForElement, preserveCase: true);

                    if (SelectedNode.IsScreensFolderTreeNode())
                    {
                        foreach (var screen in ProjectState.Self.GumProjectSave.Screens)
                        {
                            if (screen.Name.StartsWith(oldPathRelativeToElementsRoot))
                            {
                                string oldVaue = screen.Name;
                                string newName = newPathRelativeToElementsRoot + screen.Name.Substring(oldPathRelativeToElementsRoot.Length);

                                screen.Name = newName;
                                RenameLogic.HandleRename(screen, (InstanceSave)null, oldVaue, NameChangeAction.Move, askAboutRename: false);
                            }
                        }
                    }
                    else if (SelectedNode.IsComponentsFolderTreeNode())
                    {
                        foreach (var component in ProjectState.Self.GumProjectSave.Components)
                        {
                            if (component.Name.ToLowerInvariant().StartsWith(oldPathRelativeToElementsRoot.ToLowerInvariant()))
                            {
                                string oldVaue = component.Name;
                                string newName = newPathRelativeToElementsRoot + component.Name.Substring(oldPathRelativeToElementsRoot.Length);
                                component.Name = newName;

                                RenameLogic.HandleRename(component, (InstanceSave)null, oldVaue, NameChangeAction.Move, askAboutRename: false);
                            }
                        }
                    }

                    bool isNowEmpty = Directory.GetFiles(oldFullPath.FullPath).Length == 0;
                    if (isNowEmpty)
                    {
                        Directory.Delete(oldFullPath.FullPath);
                        GumCommands.Self.GuiCommands.RefreshElementTreeView();
                    }
                }
            }
        }