#
# -*- tcl -*-
# <20240426.1908.53>
#
# This module is the 'expand file name' code that expands file names from
# the list plane and the dir entry window.
# We refer to the we use Balloon.tcl to post the window and take it down.
#


proc popupDir {inst args} {
  global glob
  primeBalloonHelp 1
  balloon_help_display $glob($inst,pwd) keeplong 0
}
# This routine takes the file-display index and the 'inst' (left or right)
# and builds a line to display that file info.
#
# There are two formats:
#
# 1) The line will start with the file name with the @ or / indicator
#    and if its a link '->' the link
#
# 2) Form 1 with additional fields appended as dictated by:
#    config(singleLineDisp)    a list of fields in desired order or
#    if config(singleLineDisp) is nil, the fields in the order displayed
#                              in the given pane are used.
#
#    Optional items for config(singleLineDisp) are: ctime, atime, mtime,
#                                      size, mode, owner and links
#
proc popupListEn {inst w loc co args} {
  global glob config
  #global ::balloon_help::rtn
  primeBalloonHelp 1
  # set enable [expr {[info exists ::balloon_help::enable] &&\
  #       		$::balloon_help::enable}]
  # if {$enable && $count > 1} {
  #   return [list "$rtn\n \n[subst [dirListBalloonHelp]]" 0]
  # }
  set idx [$w index $loc]
  lassign [lindex $glob($inst,filelist) $idx] {*}$glob(fListEl)
  set rtnRaw [lindex $glob($inst,lvfile) $idx]
  set rtn [list $rtnRaw]
  frputs loc idx count rtn
  if {[string index $rtnRaw end] == "@" ||\
          [string range $rtnRaw end-1 end] == "@/"} {
    # To normalize this we may need to change the working dir
    append rtn " -> "
      frputs link glob($inst,pwd)
   if {[IsVFS $glob($inst,pwd)]} {
       append rtn [URL join $glob($inst,pwd) $link]
    } else {
      set link [file dir [file norm [file join $glob($inst,pwd) $link]/x]]
      append rtn [regsub -all {\\} $link {/}]
    }
  }

  if {$co} {
    # If we are here we are to expand the above...

    set these $config(singleLineDisp)
    if {$these == {}} {
      foreach ent $config(ListBoxColumns,$inst) {
        if {[set colId [lindex $ent 0]] ni {"file" "slink"}} {
          lappend these $colId
        }
      }
      set ffile $glob($inst,lvfile)
    }
    foreach ent $these {
      if {[info exist glob($inst,lv$ent)]} {
        append rtn " " [list [string trim [lindex $glob($inst,lv$ent) $idx]]]
      } else {
        catch {
          append rtn " " [list [string trim [eval $glob(lbscript,$ent)]]]
        }
      }
    }
  }
  balloon_help_display $rtn keeplong 0
  return
}
  
