SetGadgetState not implemented for ExplorerListGadget?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

SetGadgetState not implemented for ExplorerListGadget?

Post by Rescator »

SetGadgetState() seems not to work with ExplorerListGadget()
SetGadgetState() is also not listed in ExplorerListGadget() part of the manual.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

What do you want to Set? What should this command do?
Tranquil
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

ExplorerListGadget:
GetGadgetState(): Get the first selected item (-1 if none selected).

Guess what SetGadgetState() would do :P

SetGadgetState would be very important after i.e. the ExplorerList being updated, so that the selection can remain the same.
i.e: after a file/folder has been deleted or removed.
(esp. as the ExplorerList automaticaly refreshes if a folder is updated).
MuuSer
User
User
Posts: 14
Joined: Sat Feb 06, 2010 8:24 pm
Location: Estonia

Re: SetGadgetState not implemented for ExplorerListGadget?

Post by MuuSer »

Wow! So old wish and no one had wished it again!

I have three ExplorerList boxes – two of them are disabled and are for indicating purposes only. If I select file from one enabled listbox, then two others are showing corresponding file – if they exist. If not, then disabled listboxes items must be deselected. For that reason SetGadgetState() is must be for ExplorerListGadget. I have implemented this feature now by Windows API, but this means, that it’s not crossportable. :(
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: SetGadgetState not implemented for ExplorerListGadget?

Post by Shardik »

MuuSer wrote:I have implemented this feature now by Windows API, but this means, that it’s not crossportable. :(
You may use the following cross-platform procedure SelectExplorerListRow() which uses the appropriate API functions of MacOS, Linux and Windows to select a row in an ExplorerListGadget:

Code: Select all

EnableExplicit

Procedure SelectExplorerListRow(ExplorerListID.I, RowIndex.I)
  If RowIndex < CountGadgetItems(ExplorerListID)
    SetActiveGadget(ExplorerListID)

    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Linux
        Protected TreePath.I = gtk_tree_path_new_from_indices_(RowIndex, -1)
        gtk_tree_view_set_cursor_(GadgetID(ExplorerListID), TreePath, 0, #False)
      CompilerCase #PB_OS_MacOS
        Protected IndexSet.I
        IndexSet = CocoaMessage(0, CocoaMessage(0, 0, "NSIndexSet alloc"),
          "initWithIndex:", RowIndex)
        CocoaMessage(0, GadgetID(ExplorerListID),
          "selectRowIndexes:", IndexSet,
          "byExtendingSelection:", #NO)
        CocoaMessage(0, IndexSet, "release")
      CompilerCase #PB_OS_Windows
        Protected Item.LVITEM
        Item\mask = #LVIF_STATE
        Item\state = #LVIS_SELECTED
        Item\stateMask = #LVIS_SELECTED
        SendMessage_(GadgetID(ExplorerListID), #LVM_SETITEMSTATE, RowIndex, @Item)
    CompilerEndSelect
  EndIf
EndProcedure

OpenWindow(0, 270, 100, 400, 200, "ExplorerListGadget")
; ---- Attention: The flag #PB_Explorer_AlwaysShowSelection is necessary to
;      see a selected entry in Windows OS
ExplorerListGadget(0, 10, 10, 380, 180, "/", #PB_Explorer_AlwaysShowSelection)
SelectExplorerListRow(0, 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: SetGadgetState not implemented for ExplorerListGadget?

Post by Shardik »

Sorry, it's much easier because PB has a native command to select and unselect a row in an ExplorerListGadget, so there is no need to use platform-specific API functions:

Code: Select all

SetGadgetItemState(#Gadget, Item, State)
Use State = #PB_Explorer_Selected to select a row
and State = 0 to unselect a row (this is currently only documented for the ListViewGadget, but seems to work even cross-plattform for the ExplorerListGadget as demonstrated in this example)
Post Reply