Page 1 of 1

Hidden Files in ExplorerListGadget

Posted: Thu Dec 12, 2013 10:57 pm
by offsides
Back in 2007 apparently ExplorerListGadget, or at least the Linux version, wouldn't display hidden files. Now it does and I can't find a way to turn that off. Is it possible?

Thanks,
Bill

Re: Hidden Files in ExplorerListGadget

Posted: Fri Dec 13, 2013 12:23 am
by IdeasVacuum
I think that maybe an OS setting - If the OS is set to hide the files, Explorer will not display them. Seems logical that would be the case cross-platform, though perhaps Apple have a different way of thinking.

Re: Hidden Files in ExplorerListGadget

Posted: Fri Dec 13, 2013 12:38 am
by offsides
IdeasVacuum,
Thanks, but I have file managers (ie. Total Commander) that can be switched either way. If it's an OS setting, mine must be set to show hidden files.

What I'm trying to do is NOT show hidden files in the ExplorerListGadget. In this case, I have a configuration (.cfg) file that I don't want listed. I can set its attribute to hidden, but ExplorerListGadget shows it anyway.

Bill

Re: Hidden Files in ExplorerListGadget

Posted: Fri Dec 13, 2013 7:23 am
by davido
If you know all the file-types you wish to use then you could use a pattern:
Manual wrote:Directory$ The initial displayed directory, it can include one or multiple patterns, like "C:\*.pb;*.pbi". If no pattern is included, the directory must end with a '\'. Including no directory will display the root containing the drives. Including no pattern defaults to '*.*'. So a Directory$ of "" will display the root and set '*.*' as pattern.

Re: Hidden Files in ExplorerListGadget

Posted: Fri Dec 13, 2013 12:33 pm
by Shardik
The easiest way to suppress the listing of hidden files in Windows is to simply catch the event #PB_EventType_Change, check each file in a loop for the hidden attribute and remove the entry from the gadget list:

Code: Select all

OpenWindow(0, 0, 0, 492, 400, "ExplorerList", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ExplorerListGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "C:\Windows\")
SetGadgetItemAttribute(0, 0, #PB_Explorer_ColumnWidth, 150, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0 And EventType() = #PB_EventType_Change
        FilePath$ = GetGadgetText(0)

        For i = CountGadgetItems(0) - 1 To 0 Step -1
          Filename$ = GetGadgetItemText(0, i, 0)

          If GetFileAttributes(FilePath$ + Filename$) & #PB_FileSystem_Hidden
            RemoveGadgetItem(0, i)
          EndIf
        Next i
      EndIf
  EndSelect
ForEver

Re: Hidden Files in ExplorerListGadget

Posted: Fri Dec 13, 2013 10:04 pm
by offsides
Ah, Shardik, you crafty devil you...

Since RemoveGadgetItem() isn't listed in the help as applying to the ExplorerListGadget, I never gave it a thought.
But it works! You can even see it work as the hidden files appear, then disappear in the blink of an eye.

Good enough. Thank you ever so much!

Bill

PS. Seems like keeping hidden and system files from application users would be a good thing. Seems like there should be a #PB_Explorer_NoHiddenFiles and #PB_Explorer_NoSystemFiles flags

Re: Hidden Files in ExplorerListGadget

Posted: Sat Dec 14, 2013 4:31 am
by PB
> RemoveGadgetItem() isn't listed in the help as applying to the ExplorerListGadget

That means it's unofficial, so use it at your own risk; as it may not work in future.

Re: Hidden Files in ExplorerListGadget

Posted: Sat Dec 14, 2013 9:00 am
by Shardik
PB wrote:> RemoveGadgetItem() isn't listed in the help as applying to the ExplorerListGadget

That means it's unofficial, so use it at your own risk; as it may not work in future.
I would say that it is fairly safe to use RemoveGadgetItem() for the ExplorerListGadget because according to freak's blog entry the underlying control for the ExplorerListGadget in Windows is the same as for the ListIconGadget: a WC_LISTVIEW.

Re: Hidden Files in ExplorerListGadget

Posted: Sat Dec 14, 2013 9:06 am
by RASHAD
Modified version for Shardik approach
Windows only

Code: Select all

Global oldCallback
Procedure ExplorerCallback(hwnd, msg, wParam, lParam)
  result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
  Select msg
    Case #WM_LBUTTONDBLCLK
             For x = CountGadgetItems(2) To 1 Step -1
                If (GetFileAttributes(GetGadgetText(2) + GetGadgetItemText(2,x)) & #PB_FileSystem_Hidden) And FindString(GetGadgetItemText(2,x,0),"\") <> 3
                   RemoveGadgetItem(2,x)
                EndIf
             Next
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 700, 540,"Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ExplorerListGadget(2, 10, 10, 680, 520, "*.*", #PB_Explorer_GridLines|#PB_Explorer_FullRowSelect)
  SetGadgetItemAttribute(2, -1, #PB_Explorer_ColumnWidth , 200 , 0)
  RemoveGadgetColumn(2,3)
  AddGadgetColumn(2, 3, #PB_Explorer_Attributes , 120)  
  SetGadgetItemText(2,-1,"Attributes",3)
  oldCallback = SetWindowLong_(GadgetID(2), #GWL_WNDPROC, @ExplorerCallback())
  Repeat
    event = WaitWindowEvent()

  Until event = #PB_Event_CloseWindow
EndIf
End

Re: Hidden Files in ExplorerListGadget

Posted: Tue Dec 17, 2013 1:11 am
by offsides
Thanks, Rashad, this goes into my snippets folder, too.
PB, I know, undocumented is always a risk. But Sardik's comment is persuasive. Perhaps the PB crew will replace RemoveGadgetItem() with a couple of useful flags for ExplorerListGadget() that will accomplish the same thing.

Thanks to all who commented.
Bill

Re: Hidden Files in ExplorerListGadget

Posted: Tue Aug 04, 2015 5:51 pm
by kenmo
Nice tips here! A clever and surprisingly-simple way to hide Hidden files on (Windows) ExplorerListGadgets.

Thanks Shardik and Rashad!

Re: Hidden Files in ExplorerListGadget

Posted: Sun Aug 16, 2015 9:01 pm
by Shardik
Since PB 5.30 it has actually become very easy in Linux and MacOS X to display or suppress hidden files in the ExplorerListGadget with the new flag #PB_Explorer_HiddenFile:
PureBasic [url=http://www.purebasic.com/news69.php][color=#0040FF]news[/color][/url] for 5.30 wrote:Added: #PB_Explorer_HiddenFiles to show hidden files in the explorer gadgets
An example (tested successfully with PB 5.31 on Kubuntu 14.04 x64 with KDE and MacOS X Snow Leopard):

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  MessageRequester("Info", "The flag #PB_Explorer_HiddenFiles is not " +
    "supported in Windows!", #MB_ICONINFORMATION)
CompilerElse
  If CreateFile(0, GetTemporaryDirectory() + ".TestFile")
    OpenWindow(0, 100, 100, 400, 300,
      "ExplorerListGadget without hidden files (default)")
    ExplorerListGadget(0, 10, 10, 380, 280, GetTemporaryDirectory(),
      #PB_Explorer_NoFolders)

    OpenWindow(1, 520, 100, 400, 300, "ExplorerListGadget with hidden files")
    ExplorerListGadget(1, 10, 10, 380, 280, GetTemporaryDirectory(),
      #PB_Explorer_NoFolders | #PB_Explorer_HiddenFiles)
  
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow

    DeleteFile(GetTemporaryDirectory() + ".TestFile")
  EndIf
CompilerEndIf

Re: Hidden Files in ExplorerListGadget

Posted: Mon Aug 17, 2015 1:57 am
by offsides
All things come to those who wait ... :)

Thanks, Shardik, missed that one.
Bill