Share your advanced knowledge/code with the community.
User avatar
Peter
 
Posts: 479
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Closable (& disableable) PanelGadget-Items with Callback

by Peter Fri May 05, 2017 9:24 am

Hello,

here is a code for implementing a Close-Button for PanelGadget-Items:

Image

Code: Select all
EnableExplicit

Procedure PanelGadgetSetItemCloseCallback(Gadget, Position, Callback)
 
  If GadgetType(Gadget) <> #PB_GadgetType_Panel : ProcedureReturn : EndIf
  If Position < 0 : Position = 0 : EndIf
  If Position > CountGadgetItems(Gadget) - 1 : Position = CountGadgetItems(Gadget) - 1 : EndIf
 
  Protected GID = GadgetID(Gadget)
 
  ! dijit.byId(v_gid.gadget.id).getChildren()[v_position].set("onClose", function() { v_callback(v_gadget, v_position); } )
 
EndProcedure

Procedure PanelGadgetSetItemClosable(Gadget, Position, Closable)
 
  If GadgetType(Gadget) <> #PB_GadgetType_Panel : ProcedureReturn : EndIf
  If Position < 0 : Position = 0 : EndIf
  If Position > CountGadgetItems(Gadget) - 1 : Position = CountGadgetItems(Gadget) - 1 : EndIf
 
  Protected GID = GadgetID(Gadget)
 
  ! dijit.byId(v_gid.gadget.id).getChildren()[v_position].set("closable", v_closable)
 
EndProcedure

Procedure PanelGadgetSetItemDisabled(Gadget, Position, Disabled)
 
  If GadgetType(Gadget) <> #PB_GadgetType_Panel : ProcedureReturn : EndIf
  If Position < 0 : Position = 0 : EndIf
  If Position > CountGadgetItems(Gadget) - 1 : Position = CountGadgetItems(Gadget) - 1 : EndIf
 
  Protected GID = GadgetID(Gadget)
 
  ! dijit.byId(v_gid.gadget.id).getChildren()[v_position].set("disabled", v_disabled)
 
EndProcedure

; Example:

Procedure Panel_onClose(Gadget, Position)
 
  Protected PanelText.s = GetGadgetItemText(Gadget, Position)
  Protected ItemCounter

  ! if (confirm('Do you really want to close ' + v_paneltext + '?')) {
  RemoveGadgetItem(Gadget, Position)
  ; Reset the Callback with the new indices:
  For ItemCounter = 0 To CountGadgetItems(Gadget) -1
     PanelGadgetSetItemCloseCallback(Gadget, ItemCounter, @Panel_onClose())
  Next
  !  }
 
EndProcedure

Enumeration
  #myWindow
  #myPanelGadget
EndEnumeration

If OpenWindow(#myWindow, 0, 0, 600, 400, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  PanelGadget  (#myPanelGadget, 10, 10, 580, 380)
  AddGadgetItem(#myPanelGadget, -1, "Panel 1")
  AddGadgetItem(#myPanelGadget, -1, "Panel 2")
  AddGadgetItem(#myPanelGadget, -1, "Panel 3")
  AddGadgetItem(#myPanelGadget, -1, "Panel 4")
  AddGadgetItem(#myPanelGadget, -1, "Panel 5 (disabled)")
  CloseGadgetList()
 
  PanelGadgetSetItemCloseCallback(#myPanelGadget, 0, @Panel_onClose())
  PanelGadgetSetItemClosable     (#myPanelGadget, 0, #True)
 
  PanelGadgetSetItemCloseCallback(#myPanelGadget, 2, @Panel_onClose())
  PanelGadgetSetItemClosable     (#myPanelGadget, 2, #True)
 
  PanelGadgetSetItemCloseCallback(#myPanelGadget, 4, @Panel_onClose())
  PanelGadgetSetItemClosable     (#myPanelGadget, 4, #True)
 
  PanelGadgetSetItemDisabled     (#myPanelGadget, 4, #True) ; disable Panel 5
 
EndIf


v_greetings ... Peter

// Edit: Code improved
Last edited by Peter on Fri May 05, 2017 4:03 pm, edited 2 times in total.
bbanelli
 
Posts: 96
Joined: Mon Jul 13, 2015 7:40 am

Re: Closable PanelGadget-Items with Callback

by bbanelli Fri May 05, 2017 11:19 am

Fantastic, as always!

Image

Is this bug in Chrome?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
User avatar
Peter
 
Posts: 479
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Closable PanelGadget-Items with Callback

by Peter Fri May 05, 2017 3:40 pm

bbanelli wrote:Is this bug in Chrome?

i guess, this is a bug in the Dijit Flat-CSS (the Aeroglass-CSS seems to be ok).

The first posting is updated with an improved code.

Greetings ... Peter

// Edit: Ups! There is a bug in the code above. Stay tuned... :ugeek:

// Edit2: Code improved again. Should work now... :P
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 2 guests