@@ -4912,6 +4912,45 @@ class KeyboardManager {
49124912 }
49134913}
49144914
4915+ // Function to open the mask editor
4916+ function openMaskEditor ( ) : void {
4917+ const useNewEditor = app . extensionManager . setting . get (
4918+ 'Comfy.MaskEditor.UseNewEditor'
4919+ )
4920+ if ( useNewEditor ) {
4921+ const dlg = MaskEditorDialog . getInstance ( ) as any
4922+ if ( dlg ?. isOpened && ! dlg . isOpened ( ) ) {
4923+ dlg . show ( )
4924+ }
4925+ } else {
4926+ const dlg = MaskEditorDialogOld . getInstance ( ) as any
4927+ if ( dlg ?. isOpened && ! dlg . isOpened ( ) ) {
4928+ dlg . show ( )
4929+ }
4930+ }
4931+ }
4932+
4933+ // Check if the dialog is already opened
4934+ function isOpened ( ) : boolean {
4935+ const useNewEditor = app . extensionManager . setting . get (
4936+ 'Comfy.MaskEditor.UseNewEditor'
4937+ )
4938+ if ( useNewEditor ) {
4939+ return MaskEditorDialog . instance ?. isOpened ?.( ) ?? false
4940+ } else {
4941+ return ( MaskEditorDialogOld . instance as any ) ?. isOpened ?.( ) ?? false
4942+ }
4943+ }
4944+
4945+ // Ensure boolean return type for context predicate
4946+ const context_predicate = ( ) : boolean => {
4947+ return ! ! (
4948+ ComfyApp . clipspace &&
4949+ ComfyApp . clipspace . imgs &&
4950+ ComfyApp . clipspace . imgs . length > 0
4951+ )
4952+ }
4953+
49154954app . registerExtension ( {
49164955 name : 'Comfy.MaskEditor' ,
49174956 settings : [
@@ -4951,50 +4990,33 @@ app.registerExtension({
49514990 experimental : true
49524991 }
49534992 ] ,
4954- init ( app ) {
4955- // Create function before assignment
4956- function openMaskEditor ( ) : void {
4957- const useNewEditor = app . extensionManager . setting . get (
4958- 'Comfy.MaskEditor.UseNewEditor'
4959- )
4960- if ( useNewEditor ) {
4961- const dlg = MaskEditorDialog . getInstance ( ) as any
4962- if ( dlg ?. isOpened && ! dlg . isOpened ( ) ) {
4963- dlg . show ( )
4964- }
4965- } else {
4966- const dlg = MaskEditorDialogOld . getInstance ( ) as any
4967- if ( dlg ?. isOpened && ! dlg . isOpened ( ) ) {
4968- dlg . show ( )
4969- }
4970- }
4971- }
4993+ commands : [
4994+ {
4995+ id : 'Comfy.MaskEditor.OpenMaskEditor' ,
4996+ icon : 'pi pi-pencil' ,
4997+ label : 'Open Mask Editor for Selected Node' ,
4998+ function : ( ) => {
4999+ const selectedNodes = app . canvas . selected_nodes
5000+ if ( ! selectedNodes || Object . keys ( selectedNodes ) . length !== 1 ) return
5001+
5002+ const selectedNode = selectedNodes [ Object . keys ( selectedNodes ) [ 0 ] ]
5003+ if (
5004+ ! selectedNode . imgs ?. length &&
5005+ selectedNode . previewMediaType !== 'image'
5006+ )
5007+ return
49725008
4973- // Check if the dialog is already opened
4974- function isOpened ( ) : boolean {
4975- const useNewEditor = app . extensionManager . setting . get (
4976- 'Comfy.MaskEditor.UseNewEditor'
4977- )
4978- if ( useNewEditor ) {
4979- return MaskEditorDialog . instance ?. isOpened ?.( ) ?? false
4980- } else {
4981- return ( MaskEditorDialogOld . instance as any ) ?. isOpened ?.( ) ?? false
5009+ ComfyApp . copyToClipspace ( selectedNode )
5010+ // @ts -expect-error clipspace_return_node is an extension property added at runtime
5011+ ComfyApp . clipspace_return_node = selectedNode
5012+ openMaskEditor ( )
49825013 }
49835014 }
4984-
4985- // Assign the created function
5015+ ] ,
5016+ init ( ) {
49865017 ComfyApp . open_maskeditor = openMaskEditor
49875018 ComfyApp . maskeditor_is_opended = isOpened
49885019
4989- // Ensure boolean return type
4990- const context_predicate = ( ) : boolean => {
4991- return ! ! (
4992- ComfyApp . clipspace &&
4993- ComfyApp . clipspace . imgs &&
4994- ComfyApp . clipspace . imgs . length > 0
4995- )
4996- }
4997-
49985020 ClipspaceDialog . registerButton (
49995021 'MaskEditor' ,
50005022 context_predicate ,
0 commit comments