private static void ChangeIndexTo(tkDatabaseContext context, int index) { var metadata = fiGlobalMetadata.Get <InspectorDatabaseEditorMetadata>(context.editedList); metadata.CurrentIndex = index; TryEnsureValidIndex(context); }
private static fiGUIContent GetForwardButtonText(tkDatabaseContext context) { if (ShouldAddNextItem(context)) { return(Label_Forward_Add); } return(Label_Forward_Forward); }
private static bool CanSwapItemByOffset(tkDatabaseContext context, int offset) { int a = GetCurrentIndex(context); int b = a + offset; var list = context.editedList; return(list.Count > 0 && a >= 0 && a < list.Count && b >= 0 && b < list.Count); }
protected override IList <T> Edit(Rect region, GUIContent label, IList <T> list, InspectorDatabaseEditorAttribute attribute, fiGraphMetadata metadata) { var context = new tkDatabaseContext { editedList = (IList)list, label = label }; metadata = EnsureInitialState(context, metadata); ControlEditor.Context = context; fiEditorGUI.tkControl(region, label, context.editedList, metadata, ControlEditor); return((IList <T>)context.editedList); }
protected override float GetElementHeight(GUIContent label, IList <T> list, InspectorDatabaseEditorAttribute attribute, fiGraphMetadata metadata) { var context = new tkDatabaseContext { editedList = (IList)list, label = label }; metadata = EnsureInitialState(context, metadata); ControlEditor.Context = context; var height = fiEditorGUI.tkControlHeight(label, context.editedList, metadata, ControlEditor); return(height); }
private static fiGUIContent GetLabelText(tkDatabaseContext context) { var label = new GUIContent(context.label); if (context.editedList.Count == 0) { label.text += " (empty)"; } else { label.text += " (element " + (GetCurrentIndex(context) + 1) + " of " + context.editedList.Count + ")"; } return(label); }
private static void SwapItemByOffset(tkDatabaseContext context, int offset) { int a = GetCurrentIndex(context); int b = a + offset; // Make sure we can do the swap - we *should* be able to remove this // code var list = context.editedList; if (list.Count > 0 && a >= 0 && a < list.Count && b >= 0 && b < list.Count) { var temp = list[a]; list[a] = list[b]; list[b] = temp; } }
/// <summary> /// Attempts to ensure that the current editing index is not out of /// range. However, if the edited list is empty, then the index will /// always be out of range. /// </summary> private static void TryEnsureValidIndex(tkDatabaseContext context) { var list = context.editedList; var metadata = fiGlobalMetadata.Get <InspectorDatabaseEditorMetadata>(list); if (list.Count == 0) { metadata.CurrentIndex = -1; } else if (metadata.CurrentIndex < 0) { metadata.CurrentIndex = 0; } else if (metadata.CurrentIndex >= list.Count) { metadata.CurrentIndex = list.Count - 1; } }
private static void MoveIndexByOffset(tkDatabaseContext context, int offset) { var metadata = fiGlobalMetadata.Get <InspectorDatabaseEditorMetadata>(context.editedList); metadata.CurrentIndex += offset; if (metadata.CurrentIndex < 0) { metadata.CurrentIndex = 0; } // If we don't have enough elements inside of the list, then we'll // just add to the list until we have a valid index while (metadata.CurrentIndex >= context.editedList.Count) { fiListUtility.Add <T>(ref context.editedList); metadata.CurrentIndex = context.editedList.Count - 1; } }
private static fiGraphMetadata EnsureInitialState(tkDatabaseContext context, fiGraphMetadata metadata) { if (context.editedList == null) { context.editedList = (IList)InspectedType.Get(typeof(TDerived)).CreateInstance(); } InspectorDatabaseEditorMetadata databaseMetadata = metadata.GetMetadata <InspectorDatabaseEditorMetadata>(); // Set the global metadata to the graph metadata, as the graph // metadata is persistent but users still may want to access the // global metadata. fiGlobalMetadata.Set(context.editedList, databaseMetadata); // Disable the dropdown metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable(); TryEnsureValidIndex(context); return(metadata.Enter(databaseMetadata.CurrentIndex, context.editedList).Metadata); }
private static bool CanMoveIndexByOffset(tkDatabaseContext context, int offset) { int newIndex = GetCurrentIndex(context) + offset; return(newIndex >= 0); }
private static bool ShouldAddNextItem(tkDatabaseContext context) { var list = context.editedList; return(list.Count == 0 || GetCurrentIndex(context) == list.Count - 1); }
private static int GetCurrentIndex(tkDatabaseContext context) { var metadata = fiGlobalMetadata.Get <InspectorDatabaseEditorMetadata>(context.editedList); return(metadata.CurrentIndex); }
private static void InsertItem(tkDatabaseContext context) { fiListUtility.InsertAt <T>(ref context.editedList, GetCurrentIndex(context)); }
private static bool CanInsertItem(tkDatabaseContext context) { var list = context.editedList; return(list.Count > 0 && GetCurrentIndex(context) < list.Count - 1); }
private static void DeleteEditedItem(tkDatabaseContext context) { fiListUtility.RemoveAt <T>(ref context.editedList, GetCurrentIndex(context)); TryEnsureValidIndex(context); }
private static bool CanDeleteEditedItem(tkDatabaseContext context) { return(HasEditableItem(context)); }
/// <summary> /// Returns true if there is currently an item that is being edited. /// </summary> private static bool HasEditableItem(tkDatabaseContext context) { int index = GetCurrentIndex(context); return(index >= 0 && index < context.editedList.Count); }