Skip to content

Commit

Permalink
InspectorColumn : Allow toggling of edit enabled state
Browse files Browse the repository at this point in the history
  • Loading branch information
murraystevenson committed Sep 6, 2024
1 parent 8ee485e commit ee99422
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Improvements
- Improved formatting of column headers containing whitespace.
- The "Double-click to toggle" tooltip is no longer displayed while hovering over non-editable cells, and a "Double-click to edit" tooltip is now displayed while hovering over other non-toggleable but editable cells.
- Spreadsheet : Added yellow underlining to the currently active row.
- LightEditor, RenderPassEditor : The "Disable Edit" right-click menu item and <kdb>D</kdb> shortcut now act as a toggle, where edits disabled in the current session via these actions can be re-enabled with <kbd>D</kbd> or by selecting "Enable Edit" from the right-click menu.

Fixes
-----
Expand Down
69 changes: 55 additions & 14 deletions python/GafferSceneUI/_InspectorColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def __editSelectedCells( pathListing, quickBoolean = True ) :

__inspectorColumnPopup.popup( parent = pathListing )

def __disablableInspectionTweaks( pathListing ) :
def __toggleableInspectionTweaks( pathListing ) :

tweaks = []
enabledTweaks = []
disabledTweaks = []

path = pathListing.getPath().copy()
for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) :
Expand All @@ -176,18 +177,57 @@ def __disablableInspectionTweaks( pathListing ) :

with inspectionContext :
inspection = column.inspector().inspect()
if inspection is not None and inspection.canDisableEdit() :
tweaks.append( inspection )
if inspection is None :
return [], True

if inspection.canDisableEdit() :
enabledTweaks.append( inspection )
else :
return []
edit = inspection.acquireEdit( createIfNecessary = False )
if isinstance( edit, ( Gaffer.NameValuePlug, Gaffer.OptionalValuePlug, Gaffer.TweakPlug ) ) and Gaffer.Metadata.value( edit, "inspector:disabledEdit" ) :
disabledTweaks.append( inspection )
else :
# The selection includes a cell that is not viable candidate for enabling or disabling,
# we don't allow toggling of any of the selected cells in this case.
return [], True

if len( enabledTweaks ) > 0 :
return enabledTweaks, True

return disabledTweaks, False

return tweaks
def __toggleEditEnabled( pathListing ) :

def __disableEdits( pathListing ) :
global __inspectorColumnPopup

inspections, tweaksEnabled = __toggleableInspectionTweaks( pathListing )

nonEditable = [ i for i in inspections if not i.editable() ]

if len( nonEditable ) > 0 :
with GafferUI.PopupWindow() as __inspectorColumnPopup :
with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing = 4 ) :
GafferUI.Image( "warningSmall.png" )
GafferUI.Label( "<h4>{}</h4>".format( nonEditable[0].nonEditableReason() ) )

__inspectorColumnPopup.popup( parent = pathListing )

return

with Gaffer.UndoScope( pathListing.ancestor( GafferUI.Editor ).scriptNode() ) :
for inspection in __disablableInspectionTweaks( pathListing ) :
inspection.disableEdit()
for inspection in inspections :
if tweaksEnabled :
inspection.disableEdit()
# We register non-persistent metadata on disabled edits to later determine
# whether the disabled edit is a suitable candidate for enabling. This allows
# investigative toggling of edits in the current session while avoiding enabling
# edits the user may not expect to exist, such as previously unedited spreadsheet
# cells in EditScope processors.
Gaffer.Metadata.registerValue( inspection.source(), "inspector:disabledEdit", True, persistent = False )
else :
edit = inspection.acquireEdit( createIfNecessary = False )
edit["enabled"].setValue( True )
Gaffer.Metadata.deregisterValue( edit, "inspector:disabledEdit" )

def __removableAttributeInspections( pathListing ) :

Expand Down Expand Up @@ -360,11 +400,12 @@ def __contextMenu( column, pathListing, menuDefinition ) :
"command" : functools.partial( __editSelectedCells, pathListing, toggleOnly ),
}
)
tweaks, tweaksEnabled = __toggleableInspectionTweaks( pathListing )
menuDefinition.append(
"Disable Edit",
"{} Edit{}".format( "Disable" if tweaksEnabled else "Enable", "s" if len( tweaks ) > 1 else "" ),
{
"command" : functools.partial( __disableEdits, pathListing ),
"active" : len( __disablableInspectionTweaks( pathListing ) ) > 0,
"command" : functools.partial( __toggleEditEnabled, pathListing ),
"active" : len( tweaks ) > 0,
"shortCut" : "D",
}
)
Expand Down Expand Up @@ -402,8 +443,8 @@ def __keyPress( column, pathListing, event ) :
return True

if event.key == "D" :
if len( __disablableInspectionTweaks( pathListing ) ) > 0 :
__disableEdits( pathListing )
if len( __toggleableInspectionTweaks( pathListing )[0] ) > 0 :
__toggleEditEnabled( pathListing )
return True

if event.key in ( "Backspace", "Delete" ) :
Expand Down

0 comments on commit ee99422

Please sign in to comment.