Page 1 of 1

Show file Properties/Info dialog?

Posted: Sun Aug 16, 2015 7:33 am
by Keya
Ive got this code working nicely to show the Properties dialog for a file in Windows.
Does anyone know how to do similar in Mac and Linux?

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Procedure ShowFileProperties(hWnd, sFile.s)
    pSEI.SHELLEXECUTEINFO
    pSEI\cbSize = SizeOf(pSEI)
    pSEI\fMask = #SEE_MASK_INVOKEIDLIST | #SEE_MASK_INVOKEIDLIST | #SEE_MASK_FLAG_NO_UI
    pSEI\hWnd = hWnd 
    pSEI\lpVerb = @"Properties"
    pSEI\lpFile = @sFile
    pSEI\lpParameters = 0
    pSEI\lpDirectory = 0
    pSEI\nShow = 0
    pSEI\hInstApp = 0
    pSEI\lpIDList = 0  
    ShellExecuteEx_(pSEI)
  EndProcedure
CompilerEndIf

Re: Show file Properties/Info dialog?

Posted: Sun Aug 16, 2015 10:41 am
by Shardik
Keya wrote:Does anyone know how to do similar in Mac and Linux?
For MacOS X I have demonstrated already here how to display the "Get Info" window for a specified file.

Re: Show file Properties/Info dialog?

Posted: Mon Aug 17, 2015 4:22 am
by Keya
Shardik thankyou very much! Excellent work. Well that's Mac and Windows taken care of :)

Even my googling for a Linux version only found suggestions for "ls -l" heehee. Ive got no idea if it's even possible to show a Properties dialog in Linux! but i have seen some screenshots, so... maybe

In the meantime if OS=Linux I've just created a very basic dialog of my own and fill it with the basic file info that PB native commands offer - Size, Attributes, Location, and Dates. It's not ideal but I figure it's less rude than no support :)

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Procedure ShowFileProperties(TargetFile.s, hWnd.l)
    pSEI.SHELLEXECUTEINFO
    pSEI\cbSize = SizeOf(pSEI)
    pSEI\fMask = #SEE_MASK_INVOKEIDLIST | #SEE_MASK_INVOKEIDLIST | #SEE_MASK_FLAG_NO_UI
    pSEI\hWnd = hWnd 
    pSEI\lpVerb = @"Properties"
    pSEI\lpFile = @TargetFile
    pSEI\lpParameters = 0
    pSEI\lpDirectory = 0
    pSEI\nShow = 0
    pSEI\hInstApp = 0
    pSEI\lpIDList = 0  
    ShellExecuteEx_(pSEI)
  EndProcedure
    
  
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS  ;full credit to Shardik - http://www.purebasic.fr/english/viewtopic.php?f=19&t=62606&start=7
  ImportC ""
    NSPerformService(*ItemName, *NSPasteboard)
  EndImport  
  Procedure ShowFileProperties(TargetFile.s, hWnd.l=0)   ;hWnd not used in Mac/Linux
    Pasteboard.i = CocoaMessage(0, 0, "NSPasteboard pasteboardWithUniqueName")  
    If Pasteboard
      TypeArray.i = CocoaMessage(0, 0, "NSArray arrayWithObject:$", @"NSStringPboardType")    
      If TypeArray
        CocoaMessage(0, Pasteboard, "declareTypes:", TypeArray, "owner:", 0)      
        If CocoaMessage(0, Pasteboard,"setString:$", @TargetFile,"forType:$", @"NSStringPboardType") = #YES        
          NSPerformService(CocoaMessage(0, 0,"NSString stringWithString:$", @"Finder/Show Info"), Pasteboard)
        EndIf
      EndIf
    EndIf    
  EndProcedure
    
  
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
  Procedure ShowFileProperties(TargetFile.s, hWnd.l=0)     ;hWnd not used in Mac/Linux
    OpenDlgProps()    ;TODO: Create a dialog here with controls to set text (txtFileName, txtLocation, txtSize, txtModified, txtAccessed, txtAttribs)
    SetGadgetText(txtFileName, GetFilePart(TargetFile))
    SetGadgetText(txtLocation, GetPathPart(TargetFile))
    qSize.q = FileSize(TargetFile)
    If qSize > 1024*1024*1024
      sSize.s = Str(qSize / 1024 / 1024 / 1024) + " GB  (" + Str(qSize) + " bytes)"  
    ElseIf qSize > 1024*1024
      sSize.s = Str(qSize / 1024 / 1024) + " MB  (" + Str(qSize) + " bytes)"
    ElseIf qSize > 1024
      sSize.s = Str(qSize / 1024) + " KB  (" + Str(qSize) + " bytes)"
    Else
      sSize.s = Str(qSize) + " bytes"
    EndIf    
    SetGadgetText(txtSize, sSize)
    SetGadgetText(txtModified, FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", GetFileDate(TargetFile,#PB_Date_Modified))) 
    SetGadgetText(txtAccessed, FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", GetFileDate(TargetFile,#PB_Date_Accessed)))   
    FileAttributes = GetFileAttributes(TargetFile)
    If FileAttributes & #PB_Filesystem_Link: sAttribs.s + "SymbolicLink + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ReadUser: sAttribs.s + "ReadUser + ":  EndIf   
    If FileAttributes & #PB_Filesystem_WriteUser: sAttribs.s + "WriteUser + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ExecUser: sAttribs.s + "ExecUser + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ReadGroup: sAttribs.s + "ReadGroup + ":  EndIf   
    If FileAttributes & #PB_Filesystem_WriteGroup: sAttribs.s + "WriteGroup + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ExecGroup: sAttribs.s + "ExecGroup + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ReadAll: sAttribs.s + "ReadAll + ":  EndIf   
    If FileAttributes & #PB_Filesystem_WriteAll: sAttribs.s + "WriteAll + ":  EndIf   
    If FileAttributes & #PB_Filesystem_ExecAll: sAttribs.s + "ExecAll + ":  EndIf   
    If Right(sAttribs,3) = " + ": sAttribs = Left(sAttribs, Len(sAttribs) - 3): EndIf
    SetGadgetText(txtAttribs, sAttribs)    
  EndProcedure
  
CompilerEndIf

Re: Show file Properties/Info dialog?

Posted: Mon Aug 17, 2015 11:08 am
by Shardik
I had also tried to find a solution for Linux looking into the Gtk2 reference but I didn't find one. So your solution to display a minimal self-programmed file property dialog for Linux should be the right way to go... :)