public void PopulateMenuStrip() { mMenuStrip.Items.Clear(); if (SelectedNode != null) { // InstanceSave selected if (SelectedState.Self.SelectedInstance != null) { mMenuStrip.Items.Add(mGoToDefinition); } // ScreenSave or ComponentSave else if (SelectedState.Self.SelectedScreen != null || SelectedState.Self.SelectedComponent != null) { mMenuStrip.Items.Add("View in explorer", null, HandleViewInExplorer); mAddInstance.Text = "Add object to " + SelectedState.Self.SelectedElement.Name; mMenuStrip.Items.Add(mAddInstance); mMenuStrip.Items.Add(mSaveObject); mDeleteObject.Text = "Delete " + SelectedState.Self.SelectedElement.ToString(); mMenuStrip.Items.Add(mDeleteObject); } else if (SelectedState.Self.SelectedStandardElement != null) { mMenuStrip.Items.Add(mSaveObject); } else if (SelectedNode.IsTopScreenContainerTreeNode() || SelectedNode.IsScreensFolderTreeNode()) { mMenuStrip.Items.Add(mAddScreen); mMenuStrip.Items.Add(mImportScreen); mMenuStrip.Items.Add(mAddFolder); mMenuStrip.Items.Add("View in explorer", null, HandleViewInExplorer); if (SelectedNode.IsScreensFolderTreeNode()) { mMenuStrip.Items.Add("Delete Folder", null, HandleDeleteFolder); } } else if (SelectedNode.IsTopComponentContainerTreeNode() || SelectedNode.IsComponentsFolderTreeNode()) { mMenuStrip.Items.Add(mAddComponent); mMenuStrip.Items.Add(mImportComponent); mMenuStrip.Items.Add(mAddFolder); mMenuStrip.Items.Add("View in explorer", null, HandleViewInExplorer); if (SelectedNode.IsScreensFolderTreeNode()) { mMenuStrip.Items.Add("Delete Folder", null, HandleDeleteFolder); } } } }
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(); } } } }