public void SetSelectedItem(int setIndex, ReasonSelectionChanged reason) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(setIndex >= -1); Debug.Assert(setIndex < items.Length); #endif #if DEV_MODE && DEBUG_SET_SELECTED_ITEM Debug.Log(StringUtils.ToColorizedString("SetSelectedItem(", setIndex, "), was: ", selectedItemIndex)); #endif if (setIndex != selectedItemIndex) { if (selectedItemIndex != -1) { items[selectedItemIndex].OnDeselected(reason); } selectedItemIndex = setIndex; if (setIndex != -1) { var select = items[setIndex]; if (!select.Selectable) { #if DEV_MODE Debug.LogWarning("SetSelectedItem called for item that was not selectable: " + select.GetType().Name); #endif SetSelectedItem(-1, reason); return; } items[setIndex].OnSelected(reason); } } }
/// <inheritdoc /> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { if (!isMultiSelection) { FocusControlField(); } }
/// <inheritdoc /> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { if (!ReadOnly && DrawGUI.EditingTextField && !isMultiSelection) { editField = true; } base.OnSelectedInternal(reason, previous, isMultiSelection); }
/// <inheritdoc/> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { InspectorUtility.ActiveInspector.ScrollToShow(this); if (!isMultiSelection) { FocusControlField(); } }
/// <inheritdoc/> public virtual void OnSelected(ReasonSelectionChanged reason) { #if DEV_MODE && DEBUG_SELECTED Debug.Log(StringUtils.ToColorizedString(ToString() + "OnSelected(", reason, ")")); #endif KeyboardControlUtility.SetKeyboardControl(0, 3); }
/// <inheritdoc/> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { #if DEV_MODE && DEBUG_ON_SELECTED Debug.Log(ToString() + ".OnSelectedInternal(" + reason + "," + StringUtils.ToString(previous) + ")"); #endif bool wasUnfolded = false; bool isClick = false; switch (reason) { case ReasonSelectionChanged.PrefixClicked: isClick = true; if (DrawGUI.LastInputEvent().control) { ComponentDrawerUtility.singleInspectedInstance = this; } break; case ReasonSelectionChanged.ControlClicked: if (DrawGUI.LastInputEvent().control) { ComponentDrawerUtility.singleInspectedInstance = this; } return; case ReasonSelectionChanged.ThisClicked: isClick = true; break; } #if UNFOLD_ON_SELECT_IN_SINGLE_ACTIVE_MODE if (UserSettings.EditComponentsOneAtATime && !inspector.HasFilter) { if (ComponentDrawerUtility.singleInspectedInstance != null && ComponentDrawerUtility.singleInspectedInstance != this) { ComponentDrawerUtility.singleInspectedInstance.SetUnfolded(false); } ComponentDrawerUtility.singleInspectedInstance = this; // if Component was clicked, let the click event handle the unfolding if (!Unfolded && (!isClick || (MouseoveredHeaderPart != HeaderPart.FoldoutArrow && !inspector.Preferences.changeFoldedStateOnFirstClick))) { wasUnfolded = true; // allow bypassing EditComponentsOneAtATime functionality by holding down control when clicking the Component header bool collapseAllOthers = !Event.current.control || reason != ReasonSelectionChanged.PrefixClicked; SetUnfolded(true, collapseAllOthers, false); } } #endif base.OnSelectedInternal(reason, previous, isMultiSelection); if (wasUnfolded) { ExitGUIUtility.ExitGUI(); } }
/// <inheritdoc /> protected override void OnDeselectedInternal(ReasonSelectionChanged reason, IDrawer losingFocusTo) { if (DrawGUI.EditingTextField) { OnStoppedFieldEditing(); } base.OnDeselectedInternal(reason, losingFocusTo); editField = false; }
/// <inheritdoc/> public virtual void OnDeselected(ReasonSelectionChanged reason) { if (selectedItemIndex != -1) { items[selectedItemIndex].OnDeselected(reason); } selectedItemIndex = -1; GUI.changed = true; }
/// <inheritdoc /> protected override void OnDeselectedInternal(ReasonSelectionChanged reason, IDrawer losingFocusTo) { #if DEV_MODE && DEBUG_APPLY_VALUE Debug.Log(GetType().Name + " - Applying valueUnapplied " + valueUnapplied + " over " + Value + " because selection changed"); #endif base.DoSetValue(valueUnapplied, true, true); base.OnDeselectedInternal(reason, losingFocusTo); }
private void ClearSelectedDrawers(ReasonSelectionChanged reason, [CanBeNull] IDrawer losingFocusTo) { if (isMultiSelection) { ClearMultiSelection(reason, losingFocusTo); } else { ClearFocusedDrawer(reason, losingFocusTo); } }
public void Clear(ReasonSelectionChanged reason, [CanBeNull] IDrawer losingFocusTo) { bool suppressed = suppressOnSelectionChangedEvents; suppressOnSelectionChangedEvents = true; ClearSelectedDrawers(reason, losingFocusTo); Inspector = null; suppressOnSelectionChangedEvents = suppressed; HandleOnSelectionEvent(); }
/// <summary> /// Selects left-most selectable item on the toolbar. /// If toolbar has no selectable items, then sets selected item to null. /// </summary> protected void SelectFirstSelectableItem(ReasonSelectionChanged reason) { for (int n = 0, count = visibleItems.Length; n < count; n++) { var item = visibleItems[n]; if (item.Selectable) { SetSelectedItem(item, reason); return; } } SetSelectedItem(-1, reason); }
/// <summary> /// Selects right-most selectable item on the toolbar. /// If toolbar has no selectable items, then sets selected item to null. /// </summary> private void SelectLastSelectableItem(ReasonSelectionChanged reason) { for (int n = visibleItems.Length - 1; n >= 0; n--) { var item = visibleItems[n]; if (item.Selectable) { SetSelectedItem(item, reason); return; } } SetSelectedItem(-1, reason); }
public void SetSelectedItem(IInspectorToolbarItem item, ReasonSelectionChanged reason) { #if DEV_MODE && DEBUG_SET_SELECTED_ITEM Debug.Log(StringUtils.ToColorizedString("SetSelectedItem(", item, "), was: ", SelectedItem)); #endif #if DEV_MODE && PI_ASSERTATIONS if (item != null && inspector.Manager.SelectedInspectorPart != InspectorPart.Toolbar) { Debug.LogError(GetType().Name + ".SetSelectedItem(" + item.GetType().Name + ") called but SelectedInspectorPart was " + inspector.Manager.SelectedInspectorPart); } #endif if (item == null) { if (selectedItemIndex != -1) { items[selectedItemIndex].OnDeselected(reason); selectedItemIndex = -1; } return; } int setIndex = Array.IndexOf(items, item); #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(setIndex != -1); #endif if (selectedItemIndex != setIndex) { if (selectedItemIndex != -1) { items[selectedItemIndex].OnDeselected(reason); } selectedItemIndex = setIndex; var select = items[setIndex]; var documentationUrl = select.DocumentationPageUrl; if (documentationUrl.Length > 0) { PowerInspectorDocumentation.ShowFeatureIfWindowOpen(documentationUrl); } select.OnSelected(reason); } }
/// <summary> Attempts to select search box, if toolbar has one that is currently selectable. </summary> /// <param name="reason"> The reason. </param> /// <returns> True if it succeeds, false if it fails. </returns> protected bool TrySelectSearchBox(ReasonSelectionChanged reason) { if (inspector.State.WantsSearchBoxDisabled) { return(false); } var searchBox = GetSelectableItem <ISearchBoxToolbarItem>(); if (searchBox != null) { SetSelectedItem(searchBox, reason); return(true); } return(false); }
/// <summary> Calls OnDeselected in focused drawer, removes is from multi-selection if it's there, sets it to null. </summary> /// <param name="reason"> The reason why drawer is losing focus. </param> /// <param name="losingFocusTo"> The drawer to which focus is moving to. This may be null. </param> private void ClearFocusedDrawer(ReasonSelectionChanged reason, [CanBeNull] IDrawer losingFocusTo) { if (focusedDrawer != null) { var focusedDrawerWas = focusedDrawer; focusedDrawer = null; if (isMultiSelection && multiSelection.Remove(focusedDrawer)) { if (multiSelection.Count == 0) { isMultiSelection = false; } } if (!focusedDrawerWas.Inactive) { focusedDrawerWas.OnDeselected(reason, losingFocusTo); } } }
/// <inheritdoc /> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { base.OnSelectedInternal(reason, previous, isMultiSelection); if (previous != null) { switch (reason) { case ReasonSelectionChanged.SelectControlDown: case ReasonSelectionChanged.SelectControlUp: var previousParent = previous.Parent; if (previousParent != null) { int index = previousParent.GetMemberRowIndex(previous); firstButtonSelected = index < 2; } break; } } }
/// <inheritdoc /> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { bool isClick = false; switch (reason) { case ReasonSelectionChanged.PrefixClicked: isClick = true; if (DrawGUI.LastInputEvent().control) { ComponentDrawerUtility.singleInspectedInstance = this; } break; case ReasonSelectionChanged.ControlClicked: if (DrawGUI.LastInputEvent().control) { ComponentDrawerUtility.singleInspectedInstance = this; } return; } #if UNFOLD_ON_SELECT_IN_SINGLE_ACTIVE_MODE if (UserSettings.EditComponentsOneAtATime && !InspectorUtility.ActiveInspector.HasFilter) { if (ComponentDrawerUtility.singleInspectedInstance != null && ComponentDrawerUtility.singleInspectedInstance != this) { ComponentDrawerUtility.singleInspectedInstance.SetUnfolded(false); } ComponentDrawerUtility.singleInspectedInstance = this; // if Component was clicked, let the click event handle the unfolding if (!Unfolded && (!isClick || (MouseoveredHeaderPart != HeaderPart.FoldoutArrow && !inspector.Preferences.changeFoldedStateOnFirstClick))) { SetUnfolded(true, Event.current.alt); } } #endif base.OnSelectedInternal(reason, previous, isMultiSelection); }
/// <inheritdoc/> protected override void OnDeselectedInternal(ReasonSelectionChanged reason, IDrawer losingFocusTo) { #if DEV_MODE && DEBUG_ON_DESELECTED Debug.Log(ToString() + ".OnDeselectedInternal(" + reason + "," + StringUtils.ToString(losingFocusTo) + ")"); #endif bool unfoldIfLostFocus = UserSettings.EditComponentsOneAtATime; switch (reason) { case ReasonSelectionChanged.PrefixClicked: case ReasonSelectionChanged.ControlClicked: if (DrawGUI.LastInputEvent().control) { unfoldIfLostFocus = false; } break; } if (unfoldIfLostFocus) { var test = losingFocusTo; while (test != null) { var component = test as IComponentDrawer; if (component != null) { if (component != this) { SetUnfolded(false, false); } break; } test = test.Parent; } } base.OnDeselectedInternal(reason, losingFocusTo); }
/// <summary> Clears all multi-selected drawers and calls OnDeselected on all of them EXCEPT for the focused drawer. </summary> /// <param name="reason"> The reason why selection is cleared. </param> /// <param name="losingFocusTo"> The drawer to which focus is moving to. This may be null. </param> private void ClearMultiSelection(ReasonSelectionChanged reason, [CanBeNull] IDrawer losingFocusTo) { if (isMultiSelection) { // Broadcasting OnDeselected to focused drawer is handled by ClearFocusedDrawer // so we remove it from the list before the for loop. if (focusedDrawer != null) { multiSelection.Remove(focusedDrawer); } for (int n = multiSelection.Count - 1; n >= 0; n--) { var deselect = multiSelection[n]; if (deselect != null && !deselect.Inactive) { deselect.OnDeselected(reason, losingFocusTo); } } multiSelection.Clear(); isMultiSelection = false; } }
/// <inheritdoc/> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { //TO DO: do something similar to CustomEditorBaseDrawer to handle selecting of first or last control switch (reason) { case ReasonSelectionChanged.PrefixClicked: return; case ReasonSelectionChanged.SelectControlUp: case ReasonSelectionChanged.SelectPrevControl: if (IsTextField) { StartEditingField(); } else { FocusControlField(); } return; case ReasonSelectionChanged.SelectControlLeft: case ReasonSelectionChanged.SelectControlDown: case ReasonSelectionChanged.SelectControlRight: case ReasonSelectionChanged.SelectNextControl: case ReasonSelectionChanged.KeyPressOther: if (IsTextField) { StartEditingField(); } else { FocusControlField(); } return; } }
/// <inheritdoc /> protected sealed override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { switch (reason) { case ReasonSelectionChanged.PrefixClicked: return; case ReasonSelectionChanged.SelectPrevControl: FocusControlField(); return; case ReasonSelectionChanged.SelectControlUp: FocusSlider(); return; case ReasonSelectionChanged.SelectControlLeft: case ReasonSelectionChanged.SelectControlDown: case ReasonSelectionChanged.SelectControlRight: case ReasonSelectionChanged.SelectNextControl: case ReasonSelectionChanged.KeyPressOther: FocusSlider(); return; } }
/// <summary> /// Sets focused drawer and handles calling OnDeselected (first) and OnSelected (second) for setDrawer /// and any previously focused drawer that is no longer selected. Also makes sure that selected inspector /// and inspector part are valid. /// </summary> /// <param name="setDrawer"> The drawer to set as the focused drawer. Can be null if focused drawer should be set to none. </param> /// <param name="multiSelect"> If 0 this is not a multi selection, if -1 remove from multi-selection, and if 1 add to multi-selection. </param> /// <param name="reason">Reason why focus is changing.</param> private void SetFocusedDrawer([CanBeNull] IDrawer setDrawer, int multiSelect, ReasonSelectionChanged reason) { var focusedDrawerWas = focusedDrawer; #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer != null); //multi-selecting doesn't make sense for a null drawer UnityEngine.Debug.Assert(multiSelect == 0 || setDrawer.Parent is ICollectionDrawer); //for now multi-selection is only supported for collection members UnityEngine.Debug.Assert(multiSelect != -1 || isMultiSelection); //can't remove from multi-selection if there is no multi-selection UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2); //multi-selection requires at least two selected drawers #endif #if SAFE_MODE || DEV_MODE if (setDrawer != null && !setDrawer.Selectable) { #if DEV_MODE UnityEngine.Debug.LogError("SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False); #endif for (setDrawer = setDrawer.Parent; setDrawer != null && !setDrawer.Selectable; setDrawer = setDrawer.Parent) { ; } } #endif #if SAFE_MODE || DEV_MODE if (setDrawer != null) { #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(setDrawer.Selectable, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Selectable was " + StringUtils.False); UnityEngine.Debug.Assert(!setDrawer.Inactive, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").Inactive was " + StringUtils.True); UnityEngine.Debug.Assert(setDrawer.ShouldShowInInspector, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ").ShowInInspector was " + StringUtils.False); UnityEngine.Debug.Assert(inspector != null, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspector was " + StringUtils.Null); UnityEngine.Debug.Assert(inspectorPart == InspectorPart.Viewport, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") inspectorPart was " + inspectorPart); UnityEngine.Debug.Assert(!ObjectPicker.IsOpen, "SetFocusedDrawer(" + StringUtils.ToString(setDrawer) + ") ObjectPicker.IsOpen was " + StringUtils.True); //UnityEngine.Debug.Assert(inspector.InspectorDrawer.HasFocus); //this can be true if an item is right cicked #endif if (inspector == null) { Inspector = InspectorUtility.ActiveInspector; } inspectorPart = InspectorPart.Viewport; //this can be true if an item was just right-clicked if (!inspector.InspectorDrawer.HasFocus) { #if DEV_MODE UnityEngine.Debug.Log("Manually focusing window! Event=" + StringUtils.ToString(UnityEngine.Event.current)); #endif inspector.InspectorDrawer.FocusWindow(); } } #endif #if DEV_MODE && DEBUG_SET_DRAWER UnityEngine.Debug.Log(StringUtils.ToColorizedString("Selected.SetFocusedDrawer(", setDrawer, ", multiSelect=", multiSelect, ", reason=", reason, ")")); #endif switch (multiSelect) { case 0: focusedDrawer = setDrawer; ClearMultiSelection(reason, setDrawer); if (setDrawer != focusedDrawerWas) { if (focusedDrawerWas != null && !focusedDrawerWas.Inactive) { focusedDrawerWas.OnDeselected(reason, setDrawer); } if (setDrawer != null) { if (!(setDrawer is ITextFieldDrawer) && !(setDrawer is ICustomEditorDrawer)) { DrawGUI.EditingTextField = false; } setDrawer.OnSelected(reason, focusedDrawerWas, false); } else { DrawGUI.EditingTextField = false; } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } } break; case 1: DrawGUI.EditingTextField = false; bool wasSelected = IsSelected(setDrawer); focusedDrawer = setDrawer; multiSelection.AddIfDoesNotContain(focusedDrawerWas); multiSelection.AddIfDoesNotContain(setDrawer); UpdateMultiSelection(); if (!wasSelected) { setDrawer.OnSelected(reason, focusedDrawerWas, isMultiSelection); } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } break; case -1: multiSelection.Remove(setDrawer); if (setDrawer == focusedDrawer) { int selectedCount = multiSelection.Count; focusedDrawer = selectedCount == 0 ? setDrawer : multiSelection[selectedCount - 1]; } UpdateMultiSelection(); if (setDrawer != focusedDrawer && !setDrawer.Inactive) { setDrawer.OnDeselected(reason, focusedDrawer); } if (!isMultiSelection) { DrawGUI.EditingTextField = false; } else if (focusedDrawer != null) { if (!(setDrawer is ITextFieldDrawer)) { DrawGUI.EditingTextField = false; } } else { DrawGUI.EditingTextField = false; } if (inspector != null) { // This can possibly help in ensuring that selection rects are drawn in the right place // and in ensuring that the inspector feels very responsive. inspector.OnNextLayout(inspector.RefreshView); } break; } if (focusedDrawer != null) { rowIndex = focusedDrawer.GetSelectedRowIndex(); rowElementCount = setDrawer.GetRowSelectableCount(); } #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(multiSelect != 0 || !isMultiSelection); UnityEngine.Debug.Assert(!isMultiSelection || multiSelection.Count >= 2); #endif }
/// <inheritdoc /> protected override void OnDeselectedInternal(ReasonSelectionChanged reason, IDrawer losingFocusTo) { editField = false; base.OnDeselectedInternal(reason, losingFocusTo); }
public void Set([CanBeNull] IInspector setInspector, InspectorPart setPart, [CanBeNull] IDrawer setDrawer, int multiSelect, ReasonSelectionChanged reason) { bool suppressed = suppressOnSelectionChangedEvents; suppressOnSelectionChangedEvents = true; SetInspectorAndPart(setInspector, setPart, reason); SetFocusedDrawer(setDrawer, multiSelect, reason); suppressOnSelectionChangedEvents = suppressed; HandleOnSelectionEvent(); }
/// <inheritdoc/> protected override void OnDeselectedInternal(ReasonSelectionChanged reason, [CanBeNull] IDrawer losingFocusTo) { base.OnDeselectedInternal(reason, losingFocusTo); UpdatePrefixDrawer(); GUI.changed = true; }
/// <inheritdoc/> protected override void OnSelectedInternal(ReasonSelectionChanged reason, IDrawer previous, bool isMultiSelection) { base.OnSelectedInternal(reason, previous, isMultiSelection); UpdatePrefixDrawer(); GUI.changed = true; }
/// <inheritdoc/> public virtual void OnDeselected(ReasonSelectionChanged reason) { #if DEV_MODE && DEBUG_DESELECTED Debug.Log(StringUtils.ToColorizedString(ToString() + "OnDeselected(", reason, ")")); #endif }
public void SetInspectorAndPart(IInspector setInspector, InspectorPart setPart, ReasonSelectionChanged reason) { bool suppressed = suppressOnSelectionChangedEvents; suppressOnSelectionChangedEvents = true; var fromInspector = inspector; var fromPart = inspectorPart; bool inspectorChanged = fromInspector != setInspector; bool partChanged = inspectorChanged || fromPart != setPart; #if DEV_MODE && DEBUG_SET_INSPECTOR UnityEngine.Debug.Log(StringUtils.ToColorizedString("Selected.SetInspectorAndPart(", setInspector, ", part=", setPart, ", reason=", reason, ") with inspectorChanged=", inspectorChanged, ", partChanged=", partChanged)); #endif if (partChanged) { if (setPart != InspectorPart.Viewport) { ClearSelectedDrawers(reason, null); } InspectorPart = setPart; SetInspectorOnly(setInspector); if (!inspectorChanged) { if (setInspector != null) { setInspector.OnSelectedPartChanged(fromPart, setPart, reason); } } else { if (fromInspector != null) { fromInspector.OnSelectedPartChanged(fromPart, InspectorPart.None, reason); } if (setInspector != null) { setInspector.OnSelectedPartChanged(InspectorPart.None, setPart, reason); } } } suppressOnSelectionChangedEvents = suppressed; HandleOnSelectionEvent(); }
/// <inheritdoc/> public override void OnSelected(ReasonSelectionChanged reason) { StartEditing(); }