private void AddRenameOperation(RenameOperation operation) { // Construct the Rename op var renameOp = operation.Clone(); this.RenameOperationsToApply.Add(renameOp); this.SaveRenameOperationsToPreferences(); // Scroll to the bottom to focus the newly created operation. this.ScrollRenameOperationsToBottom(); this.FocusRenameOperationDeferred(renameOp); }
private void FocusRenameOperationDeferred(RenameOperation renameOperation) { this.OperationToForceFocus = renameOperation; }
private void DrawRenameOperations() { // Store the op before buttons are pressed because buttons change focus var focusedOpBeforeButtonPresses = this.FocusedRenameOp; bool saveOpsToPreferences = false; RenameOperation operationToFocus = null; for (int i = 0; i < this.RenameOperationsToApply.Count; ++i) { var currentElement = this.RenameOperationsToApply[i]; var guiOptions = new RenameOperation.GUIOptions(); guiOptions.ControlPrefix = i; guiOptions.DisableUpButton = i == 0; guiOptions.DisableDownButton = i == this.RenameOperationsToApply.Count - 1; var buttonClickEvent = currentElement.DrawGUI(guiOptions); switch (buttonClickEvent) { case RenameOperation.ListButtonEvent.MoveUp: { this.RenameOperationsToApply.MoveOperationFromIndexToIndex(i, i - 1); saveOpsToPreferences = true; // Move focus with the RenameOp. This techincally changes their focus within the // rename op, but it's better than focus getting swapped to whatever op replaces this one. operationToFocus = focusedOpBeforeButtonPresses; break; } case RenameOperation.ListButtonEvent.MoveDown: { this.RenameOperationsToApply.MoveOperationFromIndexToIndex(i, i + 1); saveOpsToPreferences = true; operationToFocus = focusedOpBeforeButtonPresses; break; } case RenameOperation.ListButtonEvent.Delete: { var removingFocusedOperation = focusedOpBeforeButtonPresses == currentElement; this.RenameOperationsToApply.RemoveAt(i); saveOpsToPreferences = true; if (removingFocusedOperation && this.RenameOperationsToApply.Count > 0) { // Focus the RenameOp that took this one's place, if there is one. var indexToFocus = Mathf.Min(this.RenameOperationsToApply.Count - 1, i); operationToFocus = this.RenameOperationsToApply[indexToFocus]; } else { operationToFocus = focusedOpBeforeButtonPresses; } break; } case RenameOperation.ListButtonEvent.None: { // Do nothing break; } default: { Debug.LogError(string.Format( "RenamerWindow found Unrecognized ListButtonEvent [{0}] in OnGUI. Add a case to handle this event.", buttonClickEvent)); return; } } if (operationToFocus != null) { this.FocusRenameOperationDeferred(operationToFocus); } if (saveOpsToPreferences) { this.SaveRenameOperationsToPreferences(); } } }