private void DrawPreviewPanel(BulkRenamePreview preview) { EditorGUILayout.BeginVertical(); this.previewPanelScrollPosition = EditorGUILayout.BeginScrollView(this.previewPanelScrollPosition, this.guiStyles.PreviewScroll); bool panelIsEmpty = this.ObjectsToRename.Count == 0; if (panelIsEmpty) { this.DrawPreviewPanelContentsEmpty(); } else { var previewContents = PreviewPanelContents.CreatePreviewContentsForObjects(preview); this.DrawPreviewPanelContentsWithItems(previewContents); } EditorGUILayout.EndScrollView(); // GetLastRect only works during Repaint, so we cache it off during Repaint and use the cached value. if (Event.current.type == EventType.Repaint) { this.scrollViewClippingRect = GUILayoutUtility.GetLastRect(); } var draggedObjects = this.GetDraggedObjectsOverRect(this.scrollViewClippingRect); if (draggedObjects.Count > 0) { this.AddObjectsToRename(draggedObjects); this.ScrollPreviewPanelToBottom(); } if (!panelIsEmpty) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove All")) { this.ObjectsToRename.Clear(); } this.DrawAddSelectedObjectsButton(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
private void DrawPreviewPanelContentsWithItems() { var previewContents = PreviewPanelContents.CreatePreviewContentsForObjects(this.RenameOperationsToApply, this.ObjectsToRename); EditorGUILayout.BeginHorizontal(GUILayout.Height(18.0f)); // Space gives us a bit of padding or else we're just too bunched up to the side GUILayout.Space(42.0f); int renameStep = this.IsShowingPreviewSteps ? this.FocusedRenameOpIndex : -1; string originalNameColumnHeader = renameStep < 1 ? "Original" : "Before"; string newNameColumnHeader = "After"; EditorGUILayout.LabelField(originalNameColumnHeader, EditorStyles.boldLabel, GUILayout.Width(previewContents.LongestOriginalNameWidth)); bool shouldShowSecondColumn = this.IsPreviewStepModePreference; if (shouldShowSecondColumn) { EditorGUILayout.LabelField(newNameColumnHeader, EditorStyles.boldLabel, GUILayout.Width(previewContents.LongestNewNameWidth)); } bool shouldShowThirdColumn = !this.IsShowingPreviewSteps || this.RenameOperationsToApply.Count > 1; if (shouldShowThirdColumn) { EditorGUILayout.LabelField("Final Name", EditorStyles.boldLabel, GUILayout.Width(previewContents.LongestFinalNameWidth)); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); this.DrawPreviewRows(renameStep, previewContents, shouldShowSecondColumn, shouldShowThirdColumn); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField(this.guiContents.DropPromptHint, this.guiStyles.DropPromptHint); }
/// <summary> /// Draw the specified BulkRenamePreview in the given rect, and returns the new scroll position. /// </summary> /// <returns>The new scroll position.</returns> /// <param name="previewPanelRect">Preview panel rect.</param> /// <param name="previewPanelScrollPosition">Preview panel scroll position.</param> /// <param name="preview">Preview to draw.</param> public Vector2 Draw(Rect previewPanelRect, Vector2 previewPanelScrollPosition, BulkRenamePreview preview) { var spaceBetweenFooterAndScrollview = 2.0f; var panelFooterToolbar = new Rect(previewPanelRect); panelFooterToolbar.height = EditorGUIUtility.singleLineHeight; panelFooterToolbar.y += (previewPanelRect.height + spaceBetweenFooterAndScrollview) - panelFooterToolbar.height; var scrollViewRect = new Rect(previewPanelRect); scrollViewRect.height -= (panelFooterToolbar.height + spaceBetweenFooterAndScrollview); GUI.Box(scrollViewRect, "", this.guiStyles.PreviewScroll); var newScrollPosition = previewPanelScrollPosition; if (preview.NumObjects == 0) { this.DrawPreviewPanelContentsEmpty(scrollViewRect); } else { var scrollLayout = new PreviewPanelLayout(scrollViewRect); // Show the one that doesn't quite fit by subtracting one var firstItemIndex = Mathf.Max(Mathf.FloorToInt(previewPanelScrollPosition.y / PreviewRowHeight) - 1, 0); // Add one for the one that's off screen above, and one for the one below. I think? var numItems = Mathf.CeilToInt(scrollLayout.ScrollRect.height / PreviewRowHeight) + 2; var previewContents = PreviewPanelContents.CreatePreviewContentsForObjects( preview, firstItemIndex, numItems, this.PreviewStepIndexToShow, this.guiStyles.DeletionTextColor, this.guiStyles.InsertionTextColor); bool shouldShowSecondColumn = this.ColumnsToShow != ColumnStyle.OriginalAndFinalOnly; bool shouldShowThirdColumn = this.ColumnsToShow != ColumnStyle.StepwiseHideFinal; var contentsLayout = new PreviewPanelContentsLayout( scrollLayout.ScrollRect, previewContents, shouldShowSecondColumn, shouldShowThirdColumn); newScrollPosition = this.DrawPreviewPanelContentsWithItems( scrollLayout, contentsLayout, previewPanelScrollPosition, previewContents, this.PreviewStepIndexToShow, shouldShowSecondColumn, shouldShowThirdColumn); var buttonSpacing = 2.0f; var rightPadding = 2.0f; var addSelectedObjectsButtonRect = new Rect(panelFooterToolbar); addSelectedObjectsButtonRect.width = 150.0f; addSelectedObjectsButtonRect.x = panelFooterToolbar.xMax - rightPadding - addSelectedObjectsButtonRect.width; var removeAllButtonRect = new Rect(addSelectedObjectsButtonRect); removeAllButtonRect.width = 100.0f; removeAllButtonRect.x -= (removeAllButtonRect.width + buttonSpacing); if (GUI.Button(removeAllButtonRect, "Remove All")) { if (this.RemoveAllClicked != null) { this.RemoveAllClicked.Invoke(); } } this.DrawAddSelectedObjectsButton(addSelectedObjectsButtonRect); if (!scrollLayout.ContentsFitWithoutAnyScrolling(contentsLayout)) { var hintRect = new Rect(scrollViewRect); hintRect.height = EditorGUIUtility.singleLineHeight * 2.0f; hintRect.y += scrollViewRect.height; hintRect.width = scrollViewRect.width - addSelectedObjectsButtonRect.width - removeAllButtonRect.width - buttonSpacing; EditorGUI.LabelField(hintRect, this.guiContents.DropPromptHint, this.guiStyles.DropPromptHint); } } var draggedObjects = this.GetDraggedObjectsOverRect(scrollViewRect); if (draggedObjects.Count > 0) { if (this.ObjectsDropped != null) { this.ObjectsDropped.Invoke(draggedObjects.ToArray()); } } return(newScrollPosition); }